diff options
author | Matt Caswell <matt@openssl.org> | 2015-11-24 11:09:00 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-11-26 10:20:36 +0000 |
commit | fd7d252060c427b2e567295845a61d824539443b (patch) | |
tree | 42197df9569504eb2512394e59bde093c18e94a0 /crypto/dsa | |
parent | 6938c954b072c1ddddeb0ec9f6a151df0d2cd925 (diff) | |
download | openssl-fd7d252060c427b2e567295845a61d824539443b.zip openssl-fd7d252060c427b2e567295845a61d824539443b.tar.gz openssl-fd7d252060c427b2e567295845a61d824539443b.tar.bz2 |
Tighten up BN_with_flags usage and avoid a reachable assert
The function rsa_ossl_mod_exp uses the function BN_with_flags to create a
temporary copy (local_r1) of a BIGNUM (r1) with modified flags. This
temporary copy shares some state with the original r1. If the state of r1
gets updated then local_r1's state will be stale. This was occurring in the
function so that when local_r1 was freed a call to bn_check_top was made
which failed an assert due to the stale state. To resolve this we must free
local_r1 immediately after we have finished using it and not wait until the
end of the function.
This problem prompted a review of all BN_with_flag usage within the
codebase. All other usage appears to be correct, although often not
obviously so. This commit refactors things to make it much clearer for
these other uses.
Reviewed-by: Emilia Käsper <emilia@openssl.org>
Diffstat (limited to 'crypto/dsa')
-rw-r--r-- | crypto/dsa/dsa_key.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/crypto/dsa/dsa_key.c b/crypto/dsa/dsa_key.c index d27d47a..0cde6d1 100644 --- a/crypto/dsa/dsa_key.c +++ b/crypto/dsa/dsa_key.c @@ -107,13 +107,15 @@ static int dsa_builtin_keygen(DSA *dsa) if (local_prk == NULL) goto err; BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); - } else + } else { prk = priv_key; + } if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) { BN_free(local_prk); goto err; } + /* We MUST free local_prk before any further use of priv_key */ BN_free(local_prk); } |