In FIPS mode only use "Generation by Testing Candidates" equivalent.
authorDr. Stephen Henson <steve@openssl.org>
Fri, 11 Feb 2011 15:19:54 +0000 (15:19 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 11 Feb 2011 15:19:54 +0000 (15:19 +0000)
crypto/bn/bn_rand.c

index 215285b90ff405d7218ec3f4c96df1c5a1e99968..30cc929ff6978135fa60d627a013820eccef8fad 100644 (file)
@@ -247,7 +247,15 @@ static int bn_rand_range(int pseudo, BIGNUM *r, const 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_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 */