rand_bn_range(): count bits once

This commit is contained in:
Steffen Jaeckel 2017-07-04 10:58:10 +02:00
parent 8167b4d1cc
commit 22919cd4f2

View File

@ -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);