Skip to content

Commit

Permalink
zeroize rsa->p,rsa->q on error
Browse files Browse the repository at this point in the history
this is rquired by fipd-186-5 section A.1.6, step 7:
	Zeroize the internally generated values that are not returned

In OpenSSL code we need to zero p, q members of rsa structure. The rsa
structure is provided by ossl_rsa_fips186_4_gen_prob_primes() caller.

The remaining values (variables) mentioned by standard are zeroed
already in functions we call from ossl_rsa_fips186_4_gen_prob_primes().

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #24358)
  • Loading branch information
Sashan authored and t8m committed May 14, 2024
1 parent b6a5e80 commit fb323b2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crypto/rsa/rsa_sp800_56b_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,15 @@ int ossl_rsa_fips186_4_gen_prob_primes(RSA *rsa, RSA_ACVP_TEST *test,
ret = 1;
err:
/* Zeroize any internally generated values that are not returned */
if (Xpo != NULL)
BN_clear(Xpo);
if (Xqo != NULL)
BN_clear(Xqo);
BN_clear(Xpo);
BN_clear(Xqo);
BN_clear(tmp);
if (ret != 1) {
BN_clear_free(rsa->p);
rsa->p = NULL;
BN_clear_free(rsa->q);
rsa->q = NULL;
}

BN_CTX_end(ctx);
return ret;
Expand Down

0 comments on commit fb323b2

Please sign in to comment.