]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/bn/bn_rand.c
Bleichenbacher's DSA attack
[thirdparty/openssl.git] / crypto / bn / bn_rand.c
index bab4510345090374089fd7d66d1313b88a29b6ed..f2c79b5e319f537ddcf3d205155ee8c5e4f43c67 100644 (file)
@@ -168,3 +168,14 @@ int     BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
        return bnrand(2, rnd, bits, top, bottom);
        }
 #endif
+
+/* random number r: min <= r < max */
+int    BN_rand_range(BIGNUM *r, BIGNUM *min, BIGNUM *max)
+       {
+       int n = BN_num_bits(max);
+       do
+               {
+               if (!BN_rand(r, n, 0, 0)) return 0;
+               } while ((min && BN_cmp(r, min) < 0) || BN_cmp(r, max) >= 0);
+       return 1;
+       }