int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { #ifndef OPENSSL_NO_DSA if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) { if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) || BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) || BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g)) return(0); else return(1); } #endif #ifndef OPENSSL_NO_EC if (a->type == EVP_PKEY_EC && b->type == EVP_PKEY_EC) { const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec), *group_b = EC_KEY_get0_group(b->pkey.ec); if (EC_GROUP_cmp(group_a, group_b, NULL)) return 0; else return 1; } #endif return(-1); }
static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec), *group_b = EC_KEY_get0_group(b->pkey.ec); if (EC_GROUP_cmp(group_a, group_b, NULL)) return 0; else return 1; }
static void search_ec_oid(EC_KEY *ec) { const EC_GROUP *ec_group = EC_KEY_get0_group(ec); EC_GROUP *builtin; if (!ec_group) return; if (EC_GROUP_get_curve_name(ec_group)) return; /* There is an EC_GROUP with a missing OID * because of explicit parameters */ for (size_t i=0; i<pki_evp::num_curves; i++) { int nid = pki_evp::curves[i].nid; builtin = EC_GROUP_new_by_curve_name(nid); if (EC_GROUP_cmp(builtin, ec_group, NULL) == 0) { EC_GROUP_set_curve_name((EC_GROUP *)ec_group, nid); EC_GROUP_set_asn1_flag((EC_GROUP *)ec_group, 1); EC_GROUP_free(builtin); break; } else { EC_GROUP_free(builtin); } } }
static json_t * alg_exch_exc(const jose_hook_alg_t *alg, jose_cfg_t *cfg, const json_t *prv, const json_t *pub) { openssl_auto(EC_KEY) *lcl = NULL; openssl_auto(EC_KEY) *rem = NULL; openssl_auto(BN_CTX) *bnc = NULL; openssl_auto(EC_POINT) *p = NULL; const EC_GROUP *grp = NULL; bnc = BN_CTX_new(); if (!bnc) return NULL; lcl = jose_openssl_jwk_to_EC_KEY(cfg, prv); if (!lcl) return NULL; rem = jose_openssl_jwk_to_EC_KEY(cfg, pub); if (!rem) return NULL; grp = EC_KEY_get0_group(lcl); if (EC_GROUP_cmp(grp, EC_KEY_get0_group(rem), bnc) != 0) return NULL; p = EC_POINT_new(grp); if (!p) return NULL; if (EC_POINT_mul(grp, p, NULL, EC_KEY_get0_public_key(rem), EC_KEY_get0_private_key(lcl), bnc) <= 0) return NULL; return jose_openssl_jwk_from_EC_POINT(cfg, EC_KEY_get0_group(rem), p, NULL); }