Skip to content

Commit 22919cd

Browse files
committed
rand_bn_range(): count bits once
1 parent 8167b4d commit 22919cd

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/math/rand_bn.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng)
5555
*/
5656
int rand_bn_range(void *N, void *limit, prng_state *prng, int wprng)
5757
{
58-
int res;
58+
int res, bits;
5959

6060
LTC_ARGCHK(N != NULL);
6161
LTC_ARGCHK(limit != NULL);
6262

63+
bits = mp_count_bits(limit);
6364
do {
64-
res = rand_bn_bits(N, mp_count_bits(limit), prng, wprng);
65+
res = rand_bn_bits(N, bits, prng, wprng);
6566
if (res != CRYPT_OK) return res;
6667
} while (mp_cmp_d(N, 0) != LTC_MP_GT || mp_cmp(N, limit) != LTC_MP_LT);
6768

0 commit comments

Comments
 (0)