From 418a0d151e7cce11c45c8076b5fadee9a97b4d55 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bodo=20M=C3=B6ller?= Date: Sat, 10 Feb 2001 00:34:20 +0000 Subject: [PATCH] Simplify BN_rand_range --- crypto/bn/bn.h | 2 +- crypto/bn/bn_rand.c | 9 ++------- crypto/dsa/dsa_ossl.c | 2 +- doc/crypto/BN_rand.pod | 5 ++--- doc/crypto/bn.pod | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h index 9a40276a45..ef1cfb0259 100644 --- a/crypto/bn/bn.h +++ b/crypto/bn/bn.h @@ -328,7 +328,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 *range); +int BN_rand_range(BIGNUM *rnd, BIGNUM *range); 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 046c21d95a..224a0ff7a2 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -141,8 +141,8 @@ int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom) return bnrand(1, rnd, bits, top, bottom); } -/* random number r: min <= r < min+range */ -int BN_rand_range(BIGNUM *r, BIGNUM *min, BIGNUM *range) +/* random number r: 0 <= r < range */ +int BN_rand_range(BIGNUM *r, BIGNUM *range) { int n; @@ -189,11 +189,6 @@ int BN_rand_range(BIGNUM *r, BIGNUM *min, BIGNUM *range) while (BN_cmp(r, range) >= 0); } - if (min != NULL) - { - if (!BN_add(r, r, min)) return 0; - } - return 1; } diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index a26b47ed5a..4283572330 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -180,7 +180,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) /* Get random k */ do - if (!BN_rand_range(&k, NULL, dsa->q)) goto err; + if (!BN_rand_range(&k, dsa->q)) goto err; while (BN_is_zero(&k)); if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) diff --git a/doc/crypto/BN_rand.pod b/doc/crypto/BN_rand.pod index e4c94e3d12..2a8bed5fed 100644 --- a/doc/crypto/BN_rand.pod +++ b/doc/crypto/BN_rand.pod @@ -12,7 +12,7 @@ BN_rand, BN_pseudo_rand - generate pseudo-random number int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); - int BN_rand_range(BIGNUM *rnd, BIGNUM *min, BIGNUM *range); + int BN_rand_range(BIGNUM *rnd, BIGNUM *range); =head1 DESCRIPTION @@ -28,8 +28,7 @@ non-cryptographic purposes and for certain purposes in cryptographic protocols, but usually not for key generation etc. BN_rand_range() generates a cryptographically strong pseudo-random -number B in the range B E= B E B + B. -B may be NULL, in that case 0 E= B E B. +number B in the range 0 = B E B. The PRNG must be seeded prior to calling BN_rand() or BN_rand_range(). diff --git a/doc/crypto/bn.pod b/doc/crypto/bn.pod index b0492c634a..d183028d61 100644 --- a/doc/crypto/bn.pod +++ b/doc/crypto/bn.pod @@ -60,7 +60,7 @@ bn - multiprecision integer arithmetics 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_rand_range(BIGNUM *rnd, BIGNUM *range); BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add, BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg); -- 2.25.1