Skip to content

Commit

Permalink
Correct top for EC/DSA nonces if BN_DEBUG is on
Browse files Browse the repository at this point in the history
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 a380ae8)

(Merged from #24317)
  • Loading branch information
t8m committed May 9, 2024
1 parent 7ecd90a commit 549208d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crypto/bn/bn_rand.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 549208d

Please sign in to comment.