Kaynağa Gözat

rand_bn_range(): count bits once

Steffen Jaeckel 8 yıl önce
ebeveyn
işleme
22919cd4f2
1 değiştirilmiş dosya ile 3 ekleme ve 2 silme
  1. 3 2
      src/math/rand_bn.c

+ 3 - 2
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);