Lines Matching refs:eckey
30 static int ecdsa_keygen_pairwise_test(EC_KEY *eckey, OSSL_CALLBACK *cb,
205 ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey) in EC_KEY_get0_engine() argument
207 return eckey->engine; in EC_KEY_get0_engine()
210 int EC_KEY_generate_key(EC_KEY *eckey) in EC_KEY_generate_key() argument
212 if (eckey == NULL || eckey->group == NULL) { in EC_KEY_generate_key()
216 if (eckey->meth->keygen != NULL) { in EC_KEY_generate_key()
219 ret = eckey->meth->keygen(eckey); in EC_KEY_generate_key()
221 eckey->dirty_cnt++; in EC_KEY_generate_key()
229 int ossl_ec_key_gen(EC_KEY *eckey) in ossl_ec_key_gen() argument
233 ret = eckey->group->meth->keygen(eckey); in ossl_ec_key_gen()
236 eckey->dirty_cnt++; in ossl_ec_key_gen()
253 static int ecdsa_keygen_knownanswer_test(EC_KEY *eckey, BN_CTX *ctx, in ecdsa_keygen_knownanswer_test() argument
259 EC_POINT *pub_key2 = EC_POINT_new(eckey->group); in ecdsa_keygen_knownanswer_test()
272 if (!EC_POINT_mul(eckey->group, pub_key2, eckey->priv_key, NULL, NULL, ctx)) in ecdsa_keygen_knownanswer_test()
281 ret = !EC_POINT_cmp(eckey->group, eckey->pub_key, pub_key2, ctx); in ecdsa_keygen_knownanswer_test()
302 static int ec_generate_key(EC_KEY *eckey, int pairwise_test) in ec_generate_key() argument
309 const EC_GROUP *group = eckey->group; in ec_generate_key()
310 BN_CTX *ctx = BN_CTX_secure_new_ex(eckey->libctx); in ec_generate_key()
311 int sm2 = EC_KEY_get_flags(eckey) & EC_FLAG_SM2_RANGE ? 1 : 0; in ec_generate_key()
316 if (eckey->priv_key == NULL) { in ec_generate_key()
321 priv_key = eckey->priv_key; in ec_generate_key()
358 if (eckey->pub_key == NULL) { in ec_generate_key()
363 pub_key = eckey->pub_key; in ec_generate_key()
369 eckey->priv_key = priv_key; in ec_generate_key()
370 eckey->pub_key = pub_key; in ec_generate_key()
374 eckey->dirty_cnt++; in ec_generate_key()
385 OSSL_SELF_TEST_get_callback(eckey->libctx, &cb, &cbarg); in ec_generate_key()
386 ok = ecdsa_keygen_pairwise_test(eckey, cb, cbarg) in ec_generate_key()
387 && ecdsa_keygen_knownanswer_test(eckey, ctx, cb, cbarg); in ec_generate_key()
393 BN_clear(eckey->priv_key); in ec_generate_key()
394 if (eckey->pub_key != NULL) in ec_generate_key()
395 EC_POINT_set_to_infinity(group, eckey->pub_key); in ec_generate_key()
410 int ossl_ec_generate_key_dhkem(EC_KEY *eckey, in ossl_ec_generate_key_dhkem() argument
415 if (eckey->priv_key == NULL) { in ossl_ec_generate_key_dhkem()
416 eckey->priv_key = BN_secure_new(); in ossl_ec_generate_key_dhkem()
417 if (eckey->priv_key == NULL) in ossl_ec_generate_key_dhkem()
420 if (ossl_ec_dhkem_derive_private(eckey, eckey->priv_key, ikm, ikmlen) <= 0) in ossl_ec_generate_key_dhkem()
422 if (eckey->pub_key == NULL) { in ossl_ec_generate_key_dhkem()
423 eckey->pub_key = EC_POINT_new(eckey->group); in ossl_ec_generate_key_dhkem()
424 if (eckey->pub_key == NULL) in ossl_ec_generate_key_dhkem()
427 if (!ossl_ec_key_simple_generate_public_key(eckey)) in ossl_ec_generate_key_dhkem()
433 BN_clear_free(eckey->priv_key); in ossl_ec_generate_key_dhkem()
434 eckey->priv_key = NULL; in ossl_ec_generate_key_dhkem()
435 if (eckey->pub_key != NULL) in ossl_ec_generate_key_dhkem()
436 EC_POINT_set_to_infinity(eckey->group, eckey->pub_key); in ossl_ec_generate_key_dhkem()
442 int ossl_ec_key_simple_generate_key(EC_KEY *eckey) in ossl_ec_key_simple_generate_key() argument
444 return ec_generate_key(eckey, 0); in ossl_ec_key_simple_generate_key()
447 int ossl_ec_key_simple_generate_public_key(EC_KEY *eckey) in ossl_ec_key_simple_generate_public_key() argument
450 BN_CTX *ctx = BN_CTX_new_ex(eckey->libctx); in ossl_ec_key_simple_generate_public_key()
459 ret = EC_POINT_mul(eckey->group, eckey->pub_key, eckey->priv_key, NULL, in ossl_ec_key_simple_generate_public_key()
464 eckey->dirty_cnt++; in ossl_ec_key_simple_generate_public_key()
469 int EC_KEY_check_key(const EC_KEY *eckey) in EC_KEY_check_key() argument
471 if (eckey == NULL || eckey->group == NULL || eckey->pub_key == NULL) { in EC_KEY_check_key()
476 if (eckey->group->meth->keycheck == NULL) { in EC_KEY_check_key()
481 return eckey->group->meth->keycheck(eckey); in EC_KEY_check_key()
530 int ossl_ec_key_public_check_quick(const EC_KEY *eckey, BN_CTX *ctx) in ossl_ec_key_public_check_quick() argument
532 if (eckey == NULL || eckey->group == NULL || eckey->pub_key == NULL) { in ossl_ec_key_public_check_quick()
538 if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key)) { in ossl_ec_key_public_check_quick()
544 if (!ec_key_public_range_check(ctx, eckey)) { in ossl_ec_key_public_check_quick()
550 if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) { in ossl_ec_key_public_check_quick()
561 int ossl_ec_key_public_check(const EC_KEY *eckey, BN_CTX *ctx) in ossl_ec_key_public_check() argument
566 const BIGNUM *cofactor = EC_GROUP_get0_cofactor(eckey->group); in ossl_ec_key_public_check()
568 if (!ossl_ec_key_public_check_quick(eckey, ctx)) in ossl_ec_key_public_check()
576 point = EC_POINT_new(eckey->group); in ossl_ec_key_public_check()
580 order = eckey->group->order; in ossl_ec_key_public_check()
586 if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) { in ossl_ec_key_public_check()
590 if (!EC_POINT_is_at_infinity(eckey->group, point)) { in ossl_ec_key_public_check()
605 int ossl_ec_key_private_check(const EC_KEY *eckey) in ossl_ec_key_private_check() argument
607 if (eckey == NULL || eckey->group == NULL || eckey->priv_key == NULL) { in ossl_ec_key_private_check()
611 if (BN_cmp(eckey->priv_key, BN_value_one()) < 0 in ossl_ec_key_private_check()
612 || BN_cmp(eckey->priv_key, eckey->group->order) >= 0) { in ossl_ec_key_private_check()
624 int ossl_ec_key_pairwise_check(const EC_KEY *eckey, BN_CTX *ctx) in ossl_ec_key_pairwise_check() argument
629 if (eckey == NULL in ossl_ec_key_pairwise_check()
630 || eckey->group == NULL in ossl_ec_key_pairwise_check()
631 || eckey->pub_key == NULL in ossl_ec_key_pairwise_check()
632 || eckey->priv_key == NULL) { in ossl_ec_key_pairwise_check()
637 point = EC_POINT_new(eckey->group); in ossl_ec_key_pairwise_check()
642 if (!EC_POINT_mul(eckey->group, point, eckey->priv_key, NULL, NULL, ctx)) { in ossl_ec_key_pairwise_check()
646 if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, ctx) != 0) { in ossl_ec_key_pairwise_check()
667 int ossl_ec_key_simple_check_key(const EC_KEY *eckey) in ossl_ec_key_simple_check_key() argument
672 if (eckey == NULL) { in ossl_ec_key_simple_check_key()
676 if ((ctx = BN_CTX_new_ex(eckey->libctx)) == NULL) in ossl_ec_key_simple_check_key()
679 if (!ossl_ec_key_public_check(eckey, ctx)) in ossl_ec_key_simple_check_key()
682 if (eckey->priv_key != NULL) { in ossl_ec_key_simple_check_key()
683 if (!ossl_ec_key_private_check(eckey) in ossl_ec_key_simple_check_key()
684 || !ossl_ec_key_pairwise_check(eckey, ctx)) in ossl_ec_key_simple_check_key()
994 size_t EC_KEY_priv2oct(const EC_KEY *eckey, in EC_KEY_priv2oct() argument
997 if (eckey->group == NULL || eckey->group->meth == NULL) in EC_KEY_priv2oct()
999 if (eckey->group->meth->priv2oct == NULL) { in EC_KEY_priv2oct()
1004 return eckey->group->meth->priv2oct(eckey, buf, len); in EC_KEY_priv2oct()
1007 size_t ossl_ec_key_simple_priv2oct(const EC_KEY *eckey, in ossl_ec_key_simple_priv2oct() argument
1012 buf_len = (EC_GROUP_order_bits(eckey->group) + 7) / 8; in ossl_ec_key_simple_priv2oct()
1013 if (eckey->priv_key == NULL) in ossl_ec_key_simple_priv2oct()
1022 if (BN_bn2binpad(eckey->priv_key, buf, buf_len) == -1) { in ossl_ec_key_simple_priv2oct()
1030 int EC_KEY_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len) in EC_KEY_oct2priv() argument
1034 if (eckey->group == NULL || eckey->group->meth == NULL) in EC_KEY_oct2priv()
1036 if (eckey->group->meth->oct2priv == NULL) { in EC_KEY_oct2priv()
1040 ret = eckey->group->meth->oct2priv(eckey, buf, len); in EC_KEY_oct2priv()
1042 eckey->dirty_cnt++; in EC_KEY_oct2priv()
1046 int ossl_ec_key_simple_oct2priv(EC_KEY *eckey, const unsigned char *buf, in ossl_ec_key_simple_oct2priv() argument
1049 if (eckey->priv_key == NULL) in ossl_ec_key_simple_oct2priv()
1050 eckey->priv_key = BN_secure_new(); in ossl_ec_key_simple_oct2priv()
1051 if (eckey->priv_key == NULL) { in ossl_ec_key_simple_oct2priv()
1055 if (BN_bin2bn(buf, len, eckey->priv_key) == NULL) { in ossl_ec_key_simple_oct2priv()
1059 eckey->dirty_cnt++; in ossl_ec_key_simple_oct2priv()
1063 size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf) in EC_KEY_priv2buf() argument
1068 len = EC_KEY_priv2oct(eckey, NULL, 0); in EC_KEY_priv2buf()
1073 len = EC_KEY_priv2oct(eckey, buf, len); in EC_KEY_priv2buf()
1082 int EC_KEY_can_sign(const EC_KEY *eckey) in EC_KEY_can_sign() argument
1084 if (eckey->group == NULL || eckey->group->meth == NULL in EC_KEY_can_sign()
1085 || (eckey->group->meth->flags & EC_FLAGS_NO_SIGN)) in EC_KEY_can_sign()
1099 static int ecdsa_keygen_pairwise_test(EC_KEY *eckey, OSSL_CALLBACK *cb, in ecdsa_keygen_pairwise_test() argument
1115 sig = ECDSA_do_sign(dgst, dgst_len, eckey); in ecdsa_keygen_pairwise_test()
1121 if (ECDSA_do_verify(dgst, dgst_len, sig, eckey) != 1) in ecdsa_keygen_pairwise_test()