From 22919cd4f2d4aaa80ace75ae92b682f5ff426ec8 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 4 Jul 2017 10:58:10 +0200 Subject: [PATCH] rand_bn_range(): count bits once --- src/math/rand_bn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/math/rand_bn.c b/src/math/rand_bn.c index a85a965..3d4f10c 100755 --- a/src/math/rand_bn.c +++ b/src/math/rand_bn.c @@ -55,13 +55,14 @@ cleanup: */ int rand_bn_range(void *N, void *limit, prng_state *prng, int wprng) { - int res; + int res, bits; LTC_ARGCHK(N != NULL); LTC_ARGCHK(limit != NULL); + bits = mp_count_bits(limit); do { - res = rand_bn_bits(N, mp_count_bits(limit), prng, wprng); + res = rand_bn_bits(N, bits, prng, wprng); if (res != CRYPT_OK) return res; } while (mp_cmp_d(N, 0) != LTC_MP_GT || mp_cmp(N, limit) != LTC_MP_LT);