Commit e3068929 authored by Bodo Möller's avatar Bodo Möller
Browse files

Simplify BN_rand_range

parent 836f9960
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -329,7 +329,7 @@ BIGNUM *BN_CTX_get(BN_CTX *ctx);
void	BN_CTX_end(BN_CTX *ctx);
void	BN_CTX_end(BN_CTX *ctx);
int     BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
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_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(const BIGNUM *a);
int	BN_num_bits_word(BN_ULONG);
int	BN_num_bits_word(BN_ULONG);
BIGNUM *BN_new(void);
BIGNUM *BN_new(void);
+3 −7
Original line number Original line Diff line number Diff line
@@ -169,8 +169,9 @@ int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
	}
	}
#endif
#endif


/* 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;
	int n;


@@ -217,10 +218,5 @@ int BN_rand_range(BIGNUM *r, BIGNUM *min, BIGNUM *range)
		while (BN_cmp(r, range) >= 0);
		while (BN_cmp(r, range) >= 0);
		}
		}


	if (min != NULL)
		{
		if (!BN_add(r, r, min)) return 0;
		}
	
	return 1;
	return 1;
	}
	}
+1 −1
Original line number Original line Diff line number Diff line
@@ -181,7 +181,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)


	/* Get random k */
	/* Get random k */
	do
	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));
	while (BN_is_zero(&k));


	if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
	if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
+2 −3
Original line number Original line Diff line number Diff line
@@ -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_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
=head1 DESCRIPTION


@@ -28,8 +28,7 @@ non-cryptographic purposes and for certain purposes in cryptographic
protocols, but usually not for key generation etc.
protocols, but usually not for key generation etc.


BN_rand_range() generates a cryptographically strong pseudo-random
BN_rand_range() generates a cryptographically strong pseudo-random
number B<rnd> in the range B<min> E<lt>= B<rnd> E<lt> B<min> + B<range>.
number B<rnd> in the range 0 <lt>= B<rnd> E<lt> B<range>.
B<min> may be NULL, in that case 0 E<lt>= B<rnd> E<lt> B<range>.


The PRNG must be seeded prior to calling BN_rand() or BN_rand_range().
The PRNG must be seeded prior to calling BN_rand() or BN_rand_range().


+1 −1
Original line number Original line Diff line number Diff line
@@ -68,7 +68,7 @@ bn - multiprecision integer arithmetics


 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
 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_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 *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
         BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
         BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);