]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Correct top for EC/DSA nonces if BN_DEBUG is on
authorTomas Mraz <tomas@openssl.org>
Tue, 30 Apr 2024 09:46:26 +0000 (11:46 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 9 May 2024 07:32:02 +0000 (09:32 +0200)
Otherwise following operations would bail out in bn_check_top().

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(cherry picked from commit a380ae85be287045b1eaa64d23942101a426c080)

(Merged from https://github.com/openssl/openssl/pull/24317)

crypto/bn/bn_rand.c

index 420909e09401c5dea0206448e66d2e6848132727..7fcd03a3cbadbbd4160a77cf093b9fe73e433d4f 100644 (file)
@@ -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;
         }
     }