X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fbn%2Fbn_rand.c;h=8d74895dedde6eebda62be5d9abb1164019e6409;hb=4568182a8b8cbfd15cbc175189029ac547bd1762;hp=df45575f9a7d0142683fd8c56dbe01fbdab22f31;hpb=b6358c89a10128692875fb92921b663c4d079a1e;p=oweals%2Fopenssl.git diff --git a/crypto/bn/bn_rand.c b/crypto/bn/bn_rand.c index df45575f9a..8d74895ded 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -109,6 +109,8 @@ * */ +#define OPENSSL_FIPSAPI + #include #include #include "cryptlib.h" @@ -134,13 +136,13 @@ static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) buf=(unsigned char *)OPENSSL_malloc(bytes); if (buf == NULL) { - BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE); + BNerr(BN_F_BNRAND,ERR_R_MALLOC_FAILURE); goto err; } /* make a random number and set the top and bottom bits */ time(&tim); - RAND_add(&tim,sizeof(tim),0); + RAND_add(&tim,sizeof(tim),0.0); if (pseudorand) { @@ -227,7 +229,7 @@ int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom) /* random number r: 0 <= r < range */ -static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range) +static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range) { int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand; int n; @@ -245,7 +247,15 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range) if (n == 1) BN_zero(r); +#ifdef OPENSSL_FIPS + /* FIPS 186-3 is picky about how random numbers for keys etc are + * generated. So we just use the second case which is equivalent to + * "Generation by Testing Candidates" mentioned in B.1.2 et al. + */ + else if (!FIPS_module_mode() && !BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) +#else else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) +#endif { /* range = 100..._2, * so 3*range (= 11..._2) is exactly one bit longer than range */ @@ -294,12 +304,12 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range) } -int BN_rand_range(BIGNUM *r, BIGNUM *range) +int BN_rand_range(BIGNUM *r, const BIGNUM *range) { return bn_rand_range(0, r, range); } -int BN_pseudo_rand_range(BIGNUM *r, BIGNUM *range) +int BN_pseudo_rand_range(BIGNUM *r, const BIGNUM *range) { return bn_rand_range(1, r, range); }