本文整理匯總了C++中EC_GROUP_get_curve_name函數的典型用法代碼示例。如果您正苦於以下問題:C++ EC_GROUP_get_curve_name函數的具體用法?C++ EC_GROUP_get_curve_name怎麽用?C++ EC_GROUP_get_curve_name使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EC_GROUP_get_curve_name函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: pkey_gost_init
/* Allocates new gost_pmeth_data structure and assigns it as data */
static int pkey_gost_init(EVP_PKEY_CTX *ctx)
{
struct gost_pmeth_data *data;
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
data = OPENSSL_malloc(sizeof(struct gost_pmeth_data));
if (!data)
return 0;
memset(data, 0, sizeof(struct gost_pmeth_data));
if (pkey && EVP_PKEY_get0(pkey)) {
switch (EVP_PKEY_base_id(pkey)) {
case NID_id_GostR3410_94:
data->sign_param_nid = gost94_nid_by_params(EVP_PKEY_get0(pkey));
break;
case NID_id_GostR3410_2001:
data->sign_param_nid =
EC_GROUP_get_curve_name(EC_KEY_get0_group
(EVP_PKEY_get0((EVP_PKEY *)pkey)));
break;
default:
return 0;
}
}
EVP_PKEY_CTX_set_data(ctx, data);
return 1;
}
示例2: eckey_param2type
static int
eckey_param2type(int *pptype, void **ppval, EC_KEY * ec_key)
{
const EC_GROUP *group;
int nid;
if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) {
ECerr(EC_F_ECKEY_PARAM2TYPE, EC_R_MISSING_PARAMETERS);
return 0;
}
if (EC_GROUP_get_asn1_flag(group) &&
(nid = EC_GROUP_get_curve_name(group))) {
/* we have a 'named curve' => just set the OID */
*ppval = OBJ_nid2obj(nid);
*pptype = V_ASN1_OBJECT;
} else {
/* explicit parameters */
ASN1_STRING *pstr = NULL;
pstr = ASN1_STRING_new();
if (!pstr)
return 0;
pstr->length = i2d_ECParameters(ec_key, &pstr->data);
if (pstr->length <= 0) {
ASN1_STRING_free(pstr);
ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB);
return 0;
}
*ppval = pstr;
*pptype = V_ASN1_SEQUENCE;
}
return 1;
}
示例3: encode_gost01_algor_params
static ASN1_STRING *
encode_gost01_algor_params(const EVP_PKEY *key)
{
ASN1_STRING *params = ASN1_STRING_new();
GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new();
int pkey_param_nid = NID_undef;
if (params == NULL || gkp == NULL) {
GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS,
ERR_R_MALLOC_FAILURE);
ASN1_STRING_free(params);
params = NULL;
goto err;
}
pkey_param_nid =
EC_GROUP_get_curve_name(GOST_KEY_get0_group(key->pkey.gost));
gkp->key_params = OBJ_nid2obj(pkey_param_nid);
gkp->hash_params = OBJ_nid2obj(GOST_KEY_get_digest(key->pkey.gost));
/*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */
params->length = i2d_GOST_KEY_PARAMS(gkp, ¶ms->data);
if (params->length <= 0) {
GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS,
ERR_R_MALLOC_FAILURE);
ASN1_STRING_free(params);
params = NULL;
goto err;
}
params->type = V_ASN1_SEQUENCE;
err:
GOST_KEY_PARAMS_free(gkp);
return params;
}
示例4: ssl_verify_ecdsa
static int ssl_verify_ecdsa(SSL *ssl, const uint8_t *signature,
size_t signature_len, int curve, const EVP_MD *md,
EVP_PKEY *pkey, const uint8_t *in, size_t in_len) {
EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(pkey);
if (ec_key == NULL) {
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SIGNATURE_TYPE);
return 0;
}
/* In TLS 1.3, the curve is also specified by the signature algorithm. */
if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION &&
(curve == NID_undef ||
EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key)) != curve)) {
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SIGNATURE_TYPE);
return 0;
}
EVP_MD_CTX md_ctx;
EVP_MD_CTX_init(&md_ctx);
int ret = EVP_DigestVerifyInit(&md_ctx, NULL, md, NULL, pkey) &&
EVP_DigestVerifyUpdate(&md_ctx, in, in_len) &&
EVP_DigestVerifyFinal(&md_ctx, signature, signature_len);
EVP_MD_CTX_cleanup(&md_ctx);
return ret;
}
示例5: ssl_sign_ecdsa
static int ssl_sign_ecdsa(SSL *ssl, uint8_t *out, size_t *out_len,
size_t max_out, int curve, const EVP_MD *md,
const uint8_t *in, size_t in_len) {
EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(ssl->cert->privatekey);
if (ec_key == NULL) {
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SIGNATURE_TYPE);
return 0;
}
/* In TLS 1.3, the curve is also specified by the signature algorithm. */
if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION &&
(curve == NID_undef ||
EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key)) != curve)) {
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SIGNATURE_TYPE);
return 0;
}
EVP_MD_CTX ctx;
EVP_MD_CTX_init(&ctx);
*out_len = max_out;
int ret = EVP_DigestSignInit(&ctx, NULL, md, NULL, ssl->cert->privatekey) &&
EVP_DigestSignUpdate(&ctx, in, in_len) &&
EVP_DigestSignFinal(&ctx, out, out_len);
EVP_MD_CTX_cleanup(&ctx);
return ret;
}
示例6: gost2001_param_encode
static int gost2001_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
{
int nid =
EC_GROUP_get_curve_name(EC_KEY_get0_group
(EVP_PKEY_get0((EVP_PKEY *)pkey)));
return i2d_ASN1_OBJECT(OBJ_nid2obj(nid), pder);
}
示例7: keygen
static EC_KEY *
keygen(const char *dbdir, const char *name,
const char *grpname, const char *use, bool adv,
const char *file, int line)
{
char fname[PATH_MAX];
char cmd[PATH_MAX*2];
EC_GROUP *grp = NULL;
EC_KEY *key = NULL;
FILE *f = NULL;
test(snprintf(fname, sizeof(fname), "%s/%s", dbdir, name) > 0);
test(snprintf(cmd, sizeof(cmd),
"../progs/tang-gen -%c %s %s %s >/dev/null",
adv ? 'A' : 'a', grpname, use, fname) > 1);
test(system(cmd) == 0);
test(f = fopen(fname, "r"));
test(grp = PEM_read_ECPKParameters(f, NULL, NULL, NULL));
test(EC_GROUP_get_curve_name(grp) != NID_undef);
test(key = PEM_read_ECPrivateKey(f, NULL, NULL, NULL));
test(EC_KEY_set_group(key, grp) > 0);
EC_GROUP_free(grp);
fclose(f);
return key;
}
示例8: get_algorithm
unsigned char get_algorithm(EVP_PKEY *key) {
int type = EVP_PKEY_type(key->type);
switch(type) {
case EVP_PKEY_RSA:
{
RSA *rsa = EVP_PKEY_get1_RSA(key);
int size = RSA_size(rsa);
if(size == 256) {
return YKPIV_ALGO_RSA2048;
} else if(size == 128) {
return YKPIV_ALGO_RSA1024;
} else {
fprintf(stderr, "Unusable key of %d bits, only 1024 and 2048 are supported.\n", size * 8);
return 0;
}
}
case EVP_PKEY_EC:
{
EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key);
const EC_GROUP *group = EC_KEY_get0_group(ec);
int curve = EC_GROUP_get_curve_name(group);
if(curve == NID_X9_62_prime256v1) {
return YKPIV_ALGO_ECCP256;
} else if(curve == NID_secp384r1) {
return YKPIV_ALGO_ECCP384;
} else {
fprintf(stderr, "Unknown EC curve %d\n", curve);
return 0;
}
}
default:
fprintf(stderr, "Unknown algorithm %d.\n", type);
return 0;
}
}
示例9: print_gost_01
static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent,
ASN1_PCTX *pctx, int type)
{
int param_nid = NID_undef;
if (type == 2)
{
BIGNUM *key;
if (!BIO_indent(out,indent,128)) return 0;
BIO_printf(out,"Private key: ");
key = gost_get0_priv_key(pkey);
if (!key)
BIO_printf(out,"<undefined)");
else
BN_print(out,key);
BIO_printf(out,"\n");
}
if (type >= 1)
{
BN_CTX *ctx = BN_CTX_new();
BIGNUM *X,*Y;
const EC_POINT *pubkey;
const EC_GROUP *group;
if (!ctx)
{
GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE);
return 0;
}
BN_CTX_start(ctx);
X = BN_CTX_get(ctx);
Y = BN_CTX_get(ctx);
pubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
group = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
if (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx))
{
GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB);
BN_CTX_free(ctx);
return 0;
}
if (!BIO_indent(out,indent,128)) return 0;
BIO_printf(out,"Public key:\n");
if (!BIO_indent(out,indent+3,128)) return 0;
BIO_printf(out,"X:");
BN_print(out,X);
BIO_printf(out,"\n");
BIO_indent(out,indent+3,128);
BIO_printf(out,"Y:");
BN_print(out,Y);
BIO_printf(out,"\n");
BN_CTX_end(ctx);
BN_CTX_free(ctx);
}
param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));
if (!BIO_indent(out,indent,128)) return 0;
BIO_printf(out,"Parameter set: %s\n",OBJ_nid2ln(param_nid));
return 1;
}
示例10: SSL_set_tmp_ecdh
int SSL_set_tmp_ecdh(SSL *ssl, const EC_KEY *ec_key) {
if (ec_key == NULL || EC_KEY_get0_group(ec_key) == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
ssl->cert->ecdh_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key));
return 1;
}
示例11: SSL_set_tmp_ecdh
int SSL_set_tmp_ecdh(SSL *ssl, const EC_KEY *ec_key) {
if (ec_key == NULL || EC_KEY_get0_group(ec_key) == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key));
return SSL_set1_curves(ssl, &nid, 1);
}
示例12: param_cmp_gost_ec
static int param_cmp_gost_ec(const EVP_PKEY *a, const EVP_PKEY *b)
{
const EC_GROUP *group_a, *group_b;
EC_KEY *ec_a = EVP_PKEY_get0((EVP_PKEY *)a);
EC_KEY *ec_b = EVP_PKEY_get0((EVP_PKEY *)b);
if (!ec_a || !ec_b)
return 0;
group_a = EC_KEY_get0_group(ec_a);
group_b = EC_KEY_get0_group(ec_b);
if (!group_a || !group_b)
return 0;
if (EC_GROUP_get_curve_name(group_a) == EC_GROUP_get_curve_name(group_b)) {
return 1;
}
return 0;
}
示例13: LOG_FUNC
Handle<JwkEc> JwkEc::From(Handle<ScopedEVP_PKEY> pkey, int &key_type) {
LOG_FUNC();
LOG_INFO("Check key_type");
if (!(key_type == NODESSL_KT_PRIVATE || key_type == NODESSL_KT_PUBLIC)) {
THROW_ERROR("Wrong value of key_type");
}
LOG_INFO("Check pkey");
if (pkey == nullptr) {
THROW_ERROR("Key value is nullptr");
}
if (pkey->Get()->type != EVP_PKEY_EC) {
THROW_ERROR("Key is not EC type");
}
LOG_INFO("Create JWK Object");
Handle<JwkEc> jwk(new JwkEc());
EC_KEY *ec = nullptr;
const EC_POINT *point = nullptr;
ScopedBN_CTX ctx(nullptr);
const EC_GROUP *group = nullptr;
LOG_INFO("Convert EC to JWK");
ec = pkey->Get()->pkey.ec;
point = EC_KEY_get0_public_key(const_cast<const EC_KEY*>(ec));
group = EC_KEY_get0_group(ec);
ctx = BN_CTX_new();
LOG_INFO("Get curve name");
jwk->crv = EC_GROUP_get_curve_name(group);
ScopedBIGNUM x, y;
x = BN_CTX_get(ctx.Get());
y = BN_CTX_get(ctx.Get());
LOG_INFO("Get public key");
if (1 != EC_POINT_get_affine_coordinates_GF2m(group, point, x.Get(), y.Get(), ctx.Get())) {
THROW_OPENSSL("EC_POINT_get_affine_coordinates_GF2m");
}
jwk->x = BN_dup(x.Get());
jwk->y = BN_dup(y.Get());
if (key_type == NODESSL_KT_PRIVATE) {
const BIGNUM *d = EC_KEY_get0_private_key(const_cast<const EC_KEY*>(ec));
jwk->d = BN_dup(d);
if (jwk->d.isEmpty()) {
THROW_OPENSSL("EC_KEY_get0_private_key");
}
}
return jwk;
}
示例14: pkey_type
static int pkey_type(EVP_PKEY *pkey)
{
int nid = EVP_PKEY_id(pkey);
#ifndef OPENSSL_NO_EC
if (nid == EVP_PKEY_EC) {
const EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
return EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
}
#endif
return nid;
}
示例15: pki_key_ecdsa_to_nid
static int pki_key_ecdsa_to_nid(EC_KEY *k)
{
const EC_GROUP *g = EC_KEY_get0_group(k);
int nid;
nid = EC_GROUP_get_curve_name(g);
if (nid) {
return nid;
}
return -1;
}