From 57e7d3ce1546fc6026ffe3f1f243c54d0bb59d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulf=20M=C3=B6ller?= Date: Wed, 7 Feb 2001 22:24:35 +0000 Subject: Bleichenbacher's DSA attack --- crypto/bn/bn.h | 1 + crypto/bn/bn_rand.c | 11 +++++++++++ 2 files changed, 12 insertions(+) (limited to 'crypto/bn') diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h index 47e355ea9d..be4e7ae2ba 100644 --- a/crypto/bn/bn.h +++ b/crypto/bn/bn.h @@ -329,6 +329,7 @@ BIGNUM *BN_CTX_get(BN_CTX *ctx); void BN_CTX_end(BN_CTX *ctx); int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom); +int BN_rand_range(BIGNUM *rnd, BIGNUM *min, BIGNUM *max); int BN_num_bits(const BIGNUM *a); int BN_num_bits_word(BN_ULONG); BIGNUM *BN_new(void); diff --git a/crypto/bn/bn_rand.c b/crypto/bn/bn_rand.c index bab4510345..f2c79b5e31 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -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; + } -- cgit v1.2.3