Skip to content

Commit 9a0993b

Browse files
Pairwise check for EC keys import as part of FIPS
the self_test_digest_sig() test fails when EC PCT is enabled because ossl_ec_key_pairwise_check() consumes entropy when generator * priv_key = pub_key is calculated in EC_POINT_mul(). #0 RAND_priv_bytes_ex openssl#1 bnrand openssl#2 BN_priv_rand_ex openssl#3 ec_GF2m_simple_ladder_pre openssl#4 ec_point_ladder_pre openssl#5 ossl_ec_scalar_mul_ladder openssl#6 ec_GF2m_simple_points_mul openssl#7 EC_POINT_mul openssl#8 ossl_ec_key_pairwise_check which led to the different signature then expected in the ecdsa_prime_expected_sig. Moving set_kat_drbg() after the EVP_PKEY_fromdata() fixed the problem. Fixes openssl/project#1302 Signed-off-by: Nikola Pajkovsky <[email protected]>
1 parent 1a1c10f commit 9a0993b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

crypto/ec/ec_backend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ int ossl_ec_key_fromdata(EC_KEY *ec, const OSSL_PARAM params[], int include_priv
486486
&& !EC_KEY_set_public_key(ec, pub_point))
487487
goto err;
488488

489+
#ifdef FIPS_MODULE
490+
if (priv_key != NULL && pub_key != NULL)
491+
if (ossl_ec_key_pairwise_check(ec, ctx) == 0)
492+
goto err;
493+
#endif
494+
489495
ok = 1;
490496

491497
err:

providers/fips/self_test_kats.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,6 @@ static int self_test_digest_sign(const ST_KAT_SIGN *t,
548548

549549
OSSL_SELF_TEST_onbegin(st, typ, t->desc);
550550

551-
if (t->entropy != NULL) {
552-
if (!set_kat_drbg(libctx, t->entropy, t->entropy_len,
553-
t->nonce, t->nonce_len, t->persstr, t->persstr_len))
554-
goto err;
555-
}
556-
557551
paramskey = kat_params_to_ossl_params(libctx, t->key, NULL);
558552
paramsinit = kat_params_to_ossl_params(libctx, t->init, NULL);
559553
paramsverify = kat_params_to_ossl_params(libctx, t->verify, NULL);
@@ -577,6 +571,12 @@ static int self_test_digest_sign(const ST_KAT_SIGN *t,
577571

578572
digested = ((t->mode & SIGNATURE_MODE_DIGESTED) != 0);
579573

574+
if (t->entropy != NULL) {
575+
if (!set_kat_drbg(libctx, t->entropy, t->entropy_len,
576+
t->nonce, t->nonce_len, t->persstr, t->persstr_len))
577+
goto err;
578+
}
579+
580580
if ((t->mode & SIGNATURE_MODE_VERIFY_ONLY) != 0) {
581581
siglen = t->sig_expected_len;
582582
memcpy(psig, t->sig_expected, siglen);

0 commit comments

Comments
 (0)