Blame SOURCES/openssl-1.0.2k-fips-randlock.patch

96a864
diff -up openssl-1.0.2k/crypto/fips/fips_drbg_lib.c.fips-randlock openssl-1.0.2k/crypto/fips/fips_drbg_lib.c
96a864
--- openssl-1.0.2k/crypto/fips/fips_drbg_lib.c.fips-randlock	2017-03-09 17:59:26.249231181 +0100
96a864
+++ openssl-1.0.2k/crypto/fips/fips_drbg_lib.c	2017-11-16 09:16:06.188098078 +0100
96a864
@@ -338,6 +338,12 @@ int FIPS_drbg_reseed(DRBG_CTX *dctx,
96a864
     return drbg_reseed(dctx, adin, adinlen, 1);
96a864
 }
96a864
 
96a864
+void FIPS_drbg_set_reseed(DRBG_CTX *dctx)
96a864
+{
96a864
+    if (dctx->status == DRBG_STATUS_READY)
96a864
+        dctx->reseed_counter = dctx->reseed_interval;
96a864
+}
96a864
+
96a864
 static int fips_drbg_check(DRBG_CTX *dctx)
96a864
 {
96a864
     if (dctx->xflags & DRBG_FLAG_TEST)
96a864
diff -up openssl-1.0.2k/crypto/fips/fips_rand.h.fips-randlock openssl-1.0.2k/crypto/fips/fips_rand.h
96a864
--- openssl-1.0.2k/crypto/fips/fips_rand.h.fips-randlock	2017-03-09 17:59:26.252231250 +0100
96a864
+++ openssl-1.0.2k/crypto/fips/fips_rand.h	2017-11-07 10:06:40.241450151 +0100
96a864
@@ -86,6 +86,7 @@ extern "C" {
96a864
                               const unsigned char *pers, size_t perslen);
96a864
     int FIPS_drbg_reseed(DRBG_CTX *dctx, const unsigned char *adin,
96a864
                          size_t adinlen);
96a864
+    void FIPS_drbg_set_reseed(DRBG_CTX *dctx);
96a864
     int FIPS_drbg_generate(DRBG_CTX *dctx, unsigned char *out, size_t outlen,
96a864
                            int prediction_resistance,
96a864
                            const unsigned char *adin, size_t adinlen);
96a864
diff -up openssl-1.0.2k/crypto/rand/md_rand.c.fips-randlock openssl-1.0.2k/crypto/rand/md_rand.c
96a864
--- openssl-1.0.2k/crypto/rand/md_rand.c.fips-randlock	2017-03-09 17:59:26.255231320 +0100
96a864
+++ openssl-1.0.2k/crypto/rand/md_rand.c	2017-12-06 09:20:23.615879425 +0100
96a864
@@ -391,10 +391,10 @@ int ssleay_rand_bytes(unsigned char *buf
96a864
     CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
96a864
     crypto_lock_rand = 1;
96a864
 
96a864
-    /* always poll for external entropy in FIPS mode, drbg provides the 
96a864
-     * expansion
96a864
+    /* always poll for external entropy in FIPS mode, if run as seed
96a864
+     * source, drbg provides the expansion
96a864
      */
96a864
-    if (!initialized || FIPS_module_mode()) {
96a864
+    if (!initialized || (!lock && FIPS_module_mode())) {
96a864
         RAND_poll();
96a864
         initialized = 1;
96a864
     }
96a864
diff -up openssl-1.0.2k/crypto/rand/rand_lib.c.fips-randlock openssl-1.0.2k/crypto/rand/rand_lib.c
96a864
--- openssl-1.0.2k/crypto/rand/rand_lib.c.fips-randlock	2017-03-09 17:59:26.292232183 +0100
96a864
+++ openssl-1.0.2k/crypto/rand/rand_lib.c	2017-11-07 10:20:08.050403861 +0100
96a864
@@ -238,7 +238,7 @@ static int drbg_rand_add(DRBG_CTX *ctx,
96a864
     RAND_SSLeay()->add(in, inlen, entropy);
96a864
     if (FIPS_rand_status()) {
96a864
         CRYPTO_w_lock(CRYPTO_LOCK_RAND);
96a864
-        FIPS_drbg_reseed(ctx, NULL, 0);
96a864
+        FIPS_drbg_set_reseed(ctx);
96a864
         CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
96a864
     }
96a864
     return 1;
96a864
@@ -249,7 +249,7 @@ static int drbg_rand_seed(DRBG_CTX *ctx,
96a864
     RAND_SSLeay()->seed(in, inlen);
96a864
     if (FIPS_rand_status()) {
96a864
         CRYPTO_w_lock(CRYPTO_LOCK_RAND);
96a864
-        FIPS_drbg_reseed(ctx, NULL, 0);
96a864
+        FIPS_drbg_set_reseed(ctx);
96a864
         CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
96a864
     }
96a864
     return 1;