From 3ffd54c46e26f6dee1771129913e5d3509582dc7 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 30 Apr 2024 11:46:26 +0200 Subject: [PATCH] Correct top for EC/DSA nonces if BN_DEBUG is on Otherwise following operations would bail out in bn_check_top(). Reviewed-by: Paul Dale Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/24265) (cherry picked from commit a380ae85be287045b1eaa64d23942101a426c080) --- crypto/bn/bn_rand.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crypto/bn/bn_rand.c b/crypto/bn/bn_rand.c index 420909e09401c5..7fcd03a3cbadbb 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -276,6 +276,10 @@ int ossl_bn_priv_rand_range_fixed_top(BIGNUM *r, const BIGNUM *range, ossl_bn_mask_bits_fixed_top(r, n); } while (BN_ucmp(r, range) >= 0); +#ifdef BN_DEBUG + /* With BN_DEBUG on a fixed top number cannot be returned */ + bn_correct_top(r); +#endif } return 1; @@ -372,6 +376,10 @@ int ossl_bn_gen_dsa_nonce_fixed_top(BIGNUM *out, const BIGNUM *range, if (BN_ucmp(out, range) < 0) { ret = 1; +#ifdef BN_DEBUG + /* With BN_DEBUG on a fixed top number cannot be returned */ + bn_correct_top(out); +#endif goto end; } }