本文整理匯總了C++中EC_KEY_set_private_key函數的典型用法代碼示例。如果您正苦於以下問題:C++ EC_KEY_set_private_key函數的具體用法?C++ EC_KEY_set_private_key怎麽用?C++ EC_KEY_set_private_key使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EC_KEY_set_private_key函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: EC_KEY_new
static EC_KEY *pkcs11_get_ec(PKCS11_KEY *key)
{
EC_KEY *ec;
int no_params, no_point;
ec = EC_KEY_new();
if (ec == NULL)
return NULL;
/* For OpenSSL req we need at least the
* EC_KEY_get0_group(ec_key)) to return the group.
* Continue even if it fails, as the sign operation does not need
* it if the PKCS#11 module or the hardware can figure this out
*/
no_params = pkcs11_get_params(ec, key);
no_point = pkcs11_get_point_key(ec, key);
if (no_point && key->isPrivate) /* Retry with the public key */
no_point = pkcs11_get_point_key(ec, pkcs11_find_key_from_key(key));
if (no_point && key->isPrivate) /* Retry with the certificate */
no_point = pkcs11_get_point_cert(ec, pkcs11_find_certificate(key));
if (key->isPrivate && EC_KEY_get0_private_key(ec) == NULL) {
BIGNUM *bn = BN_new();
EC_KEY_set_private_key(ec, bn);
BN_free(bn);
}
/* A public keys requires both the params and the point to be present */
if (!key->isPrivate && (no_params || no_point)) {
EC_KEY_free(ec);
return NULL;
}
return ec;
}
示例2: EVP_PKEY_get0
// Setters for the GOST private key components
void OSSLGOSTPrivateKey::setD(const ByteString& d)
{
GOSTPrivateKey::setD(d);
EC_KEY* ec = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
if (ec == NULL)
{
ByteString der = dummyKey;
const unsigned char *p = &der[0];
if (d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p, (long) der.size()) == NULL)
{
ERROR_MSG("d2i_PrivateKey failed");
return;
}
ec = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
}
const BIGNUM* priv = OSSL::byteString2bn(d);
if (EC_KEY_set_private_key(ec, priv) <= 0)
{
ERROR_MSG("EC_KEY_set_private_key failed");
return;
}
#ifdef notyet
if (gost2001_compute_public(ec) <= 0)
ERROR_MSG("gost2001_compute_public failed");
#endif
}
示例3: ecdsa_create_pkey
/*!
* \brief Create ECDSA private key from key parameters.
* \see rsa_create_pkey
*/
static int ecdsa_create_pkey(const knot_key_params_t *params, EVP_PKEY *key)
{
assert(key);
int curve;
if (params->algorithm == KNOT_DNSSEC_ALG_ECDSAP256SHA256) {
curve = NID_X9_62_prime256v1; // == secp256r1
} else if (params->algorithm == KNOT_DNSSEC_ALG_ECDSAP384SHA384) {
curve = NID_secp384r1;
} else {
return KNOT_DNSSEC_ENOTSUP;
}
EC_KEY *ec_key = EC_KEY_new_by_curve_name(curve);
if (ec_key == NULL)
return KNOT_ENOMEM;
EC_KEY_set_private_key(ec_key, knot_b64_to_bignum(params->private_key));
// EC_KEY_check_key() could be added, but fails without public key
if (!EVP_PKEY_assign_EC_KEY(key, ec_key)) {
EC_KEY_free(ec_key);
return KNOT_DNSSEC_EASSIGN_KEY;
}
return KNOT_EOK;
}
示例4: EC_KEY_new_by_curve_name
static EC_KEY *self_test_ecdsa_key(void) {
static const uint8_t kQx[] = {
0xc8, 0x15, 0x61, 0xec, 0xf2, 0xe5, 0x4e, 0xde, 0xfe, 0x66, 0x17,
0xdb, 0x1c, 0x7a, 0x34, 0xa7, 0x07, 0x44, 0xdd, 0xb2, 0x61, 0xf2,
0x69, 0xb8, 0x3d, 0xac, 0xfc, 0xd2, 0xad, 0xe5, 0xa6, 0x81,
};
static const uint8_t kQy[] = {
0xe0, 0xe2, 0xaf, 0xa3, 0xf9, 0xb6, 0xab, 0xe4, 0xc6, 0x98, 0xef,
0x64, 0x95, 0xf1, 0xbe, 0x49, 0xa3, 0x19, 0x6c, 0x50, 0x56, 0xac,
0xb3, 0x76, 0x3f, 0xe4, 0x50, 0x7e, 0xec, 0x59, 0x6e, 0x88,
};
static const uint8_t kD[] = {
0xc6, 0xc1, 0xaa, 0xda, 0x15, 0xb0, 0x76, 0x61, 0xf8, 0x14, 0x2c,
0x6c, 0xaf, 0x0f, 0xdb, 0x24, 0x1a, 0xff, 0x2e, 0xfe, 0x46, 0xc0,
0x93, 0x8b, 0x74, 0xf2, 0xbc, 0xc5, 0x30, 0x52, 0xb0, 0x77,
};
EC_KEY *ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
BIGNUM *qx = BN_bin2bn(kQx, sizeof(kQx), NULL);
BIGNUM *qy = BN_bin2bn(kQy, sizeof(kQy), NULL);
BIGNUM *d = BN_bin2bn(kD, sizeof(kD), NULL);
if (ec_key == NULL || qx == NULL || qy == NULL || d == NULL ||
!EC_KEY_set_public_key_affine_coordinates(ec_key, qx, qy) ||
!EC_KEY_set_private_key(ec_key, d)) {
EC_KEY_free(ec_key);
ec_key = NULL;
}
BN_free(qx);
BN_free(qy);
BN_free(d);
return ec_key;
}
示例5: EVP_PKEY_get0
// Setters for the GOST private key components
void OSSLGOSTPrivateKey::setD(const ByteString& inD)
{
GOSTPrivateKey::setD(inD);
EC_KEY* inEC = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
if (inEC == NULL)
{
const unsigned char* p = dummyKey;
if (d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p, (long) sizeof(dummyKey)) == NULL)
{
ERROR_MSG("d2i_PrivateKey failed");
return;
}
inEC = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
}
const BIGNUM* priv = OSSL::byteString2bn(inD);
if (EC_KEY_set_private_key(inEC, priv) <= 0)
{
ERROR_MSG("EC_KEY_set_private_key failed");
return;
}
BN_clear_free((BIGNUM*)priv);
#ifdef notyet
if (gost2001_compute_public(inEC) <= 0)
ERROR_MSG("gost2001_compute_public failed");
#endif
}
示例6: key_regenerate
static int key_regenerate(struct key *k, const BIGNUM *bn) {
const EC_GROUP *grp;
EC_KEY *key = k->key;
EC_POINT *pub_key;
BN_CTX *ctx;
int res;
ASSERT(key);
grp = EC_KEY_get0_group(key);
ctx = BN_CTX_new();
ASSERT(grp);
ASSERT(ctx);
pub_key = EC_POINT_new(grp);
ASSERT(pub_key);
res = EC_POINT_mul(grp, pub_key, bn, NULL, NULL, ctx);
ASSERT(res == 1);
res = EC_KEY_set_private_key(key, bn);
ASSERT(res == 1);
res = EC_KEY_set_public_key(key, pub_key);
ASSERT(res == 1);
EC_POINT_free(pub_key);
BN_CTX_free(ctx);
return EC_KEY_check_key(k->key);
}
示例7: EC_KEY_new_by_curve_name
static EC_KEY *mk_eckey(int nid, const unsigned char *p, size_t plen)
{
int ok = 0;
EC_KEY *k = NULL;
BIGNUM *priv = NULL;
EC_POINT *pub = NULL;
const EC_GROUP *grp;
k = EC_KEY_new_by_curve_name(nid);
if (!k)
goto err;
priv = BN_bin2bn(p, plen, NULL);
if (!priv)
goto err;
if (!EC_KEY_set_private_key(k, priv))
goto err;
grp = EC_KEY_get0_group(k);
pub = EC_POINT_new(grp);
if (!pub)
goto err;
if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))
goto err;
if (!EC_KEY_set_public_key(k, pub))
goto err;
ok = 1;
err:
if (priv)
BN_clear_free(priv);
if (pub)
EC_POINT_free(pub);
if (ok)
return k;
else if (k)
EC_KEY_free(k);
return NULL;
}
示例8: EC_KEY_new_by_curve_name
static EC_KEY *mk_eckey(int nid, const char *str)
{
int ok = 0;
EC_KEY *k = NULL;
BIGNUM *priv = NULL;
EC_POINT *pub = NULL;
const EC_GROUP *grp;
k = EC_KEY_new_by_curve_name(nid);
if (!k)
goto err;
if(!BN_hex2bn(&priv, str))
goto err;
if (!priv)
goto err;
if (!EC_KEY_set_private_key(k, priv))
goto err;
grp = EC_KEY_get0_group(k);
pub = EC_POINT_new(grp);
if (!pub)
goto err;
if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))
goto err;
if (!EC_KEY_set_public_key(k, pub))
goto err;
ok = 1;
err:
BN_clear_free(priv);
EC_POINT_free(pub);
if (ok)
return k;
EC_KEY_free(k);
return NULL;
}
示例9: EC_KEY_regenerate_key
// Generate a private key from just the secret parameter
bool EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
{
bool success = false;
BN_CTX *ctx = nullptr;
EC_POINT *pub_key = nullptr;
if (!eckey)
return 0;
const EC_GROUP *group = EC_KEY_get0_group(eckey);
ctx = BN_CTX_new();
if (!ctx)
goto error;
pub_key = EC_POINT_new(group);
if (!pub_key)
goto error;
if (!EC_POINT_mul(group, pub_key, priv_key, nullptr, nullptr, ctx))
goto error;
EC_KEY_set_private_key(eckey, priv_key);
EC_KEY_set_public_key(eckey, pub_key);
success = true;
error:
if (pub_key)
EC_POINT_free(pub_key);
if (ctx)
BN_CTX_free(ctx);
return success;
}
示例10: gost_set_priv_key
static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv)
{
switch (EVP_PKEY_base_id(pkey))
{
case NID_id_GostR3410_94:
{
DSA *dsa = EVP_PKEY_get0(pkey);
if (!dsa)
{
dsa = DSA_new();
EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
}
dsa->priv_key = BN_dup(priv);
if (!EVP_PKEY_missing_parameters(pkey))
gost94_compute_public(dsa);
break;
}
case NID_id_GostR3410_2001:
{
EC_KEY *ec = EVP_PKEY_get0(pkey);
if (!ec)
{
ec = EC_KEY_new();
EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
}
if (!EC_KEY_set_private_key(ec,priv)) return 0;
if (!EVP_PKEY_missing_parameters(pkey))
gost2001_compute_public(ec);
break;
}
}
return 1;
}
示例11: EC_KEY_regenerate_key
// Generate a private key from just the secret parameter
int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
{
int ok = 0;
BN_CTX *ctx = NULL;
EC_POINT *pub_key = NULL;
if (!eckey) return 0;
const EC_GROUP *group = EC_KEY_get0_group(eckey);
if ((ctx = BN_CTX_new()) == NULL)
goto err;
pub_key = EC_POINT_new(group);
if (pub_key == NULL)
goto err;
if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
goto err;
EC_KEY_set_private_key(eckey,priv_key);
EC_KEY_set_public_key(eckey,pub_key);
ok = 1;
err:
if (pub_key)
EC_POINT_free(pub_key);
if (ctx != NULL)
BN_CTX_free(ctx);
return(ok);
}
示例12: gost2001_keygen
/*
*
* Generates GOST R 34.10-2001 keypair
*
*
*/
int gost2001_keygen(EC_KEY *ec)
{
BIGNUM *order = BN_new(), *d = BN_new();
const EC_GROUP *group = EC_KEY_get0_group(ec);
if (!group || !EC_GROUP_get_order(group, order, NULL)) {
GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);
BN_free(d);
BN_free(order);
return 0;
}
do {
if (!BN_rand_range(d, order)) {
GOSTerr(GOST_F_GOST2001_KEYGEN,
GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
BN_free(d);
BN_free(order);
return 0;
}
}
while (BN_is_zero(d));
if (!EC_KEY_set_private_key(ec, d)) {
GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);
BN_free(d);
BN_free(order);
return 0;
}
BN_free(d);
BN_free(order);
return gost2001_compute_public(ec);
}
示例13: EC_KEY_new_by_curve_name
/* Interpret the 256 bits in buf as a private key and return an EC_KEY *. */
static EC_KEY *generate_key_from_buffer(const unsigned char buf[32])
{
EC_KEY *key;
BIGNUM *bn;
int rc;
key = NULL;
bn = NULL;
key = EC_KEY_new_by_curve_name(EC_GROUP_NID);
if (key == NULL)
goto err;
bn = BN_bin2bn(buf, 32, NULL);
if (bn == NULL)
goto err;
rc = EC_KEY_set_private_key(key, bn);
if (rc != 1)
goto err;
BN_free(bn);
return key;
err:
if (key != NULL)
EC_KEY_free(key);
if (bn != NULL)
BN_free(bn);
return NULL;
}
示例14: EC_KEY_set_private_key
// Setters for the EC private key components
void OSSLECPrivateKey::setD(const ByteString& inD)
{
ECPrivateKey::setD(inD);
BIGNUM* pk = OSSL::byteString2bn(inD);
EC_KEY_set_private_key(eckey, pk);
BN_clear_free(pk);
}
示例15: EC_KEY_generate_key_part
static int EC_KEY_generate_key_part(EC_KEY *eckey)
{
int ok = 0;
BN_CTX *ctx = NULL;
BIGNUM *priv_key = NULL, *order = NULL;
EC_POINT *pub_key = NULL;
const EC_GROUP *group;
if (!eckey)
{
return 0;
}
group = EC_KEY_get0_group(eckey);
if ((order = BN_new()) == NULL) goto err;
if ((ctx = BN_CTX_new()) == NULL) goto err;
priv_key = (BIGNUM*)EC_KEY_get0_private_key(eckey);
if (priv_key == NULL)
{
goto err;
}
if (!EC_GROUP_get_order(group, order, ctx))
goto err;
if (BN_is_zero(priv_key))
goto err;
pub_key = (EC_POINT *)EC_KEY_get0_public_key(eckey);
if (pub_key == NULL)
{
pub_key = EC_POINT_new(group);
if (pub_key == NULL)
goto err;
}
if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
goto err;
{
EC_POINT_make_affine(EC_KEY_get0_group(eckey),
(EC_POINT *)EC_KEY_get0_public_key(eckey),
NULL);
}
EC_KEY_set_private_key(eckey, priv_key);
EC_KEY_set_public_key(eckey, pub_key);
ok = 1;
err:
if (order)
BN_free(order);
if (ctx != NULL)
BN_CTX_free(ctx);
return (ok);
}