cf3dd1
diff -up openssl-1.1.1g/crypto/fips/fips_drbg_lib.c.rewire-fips-drbg openssl-1.1.1g/crypto/fips/fips_drbg_lib.c
cf3dd1
--- openssl-1.1.1g/crypto/fips/fips_drbg_lib.c.rewire-fips-drbg	2020-06-22 13:32:47.611852927 +0200
cf3dd1
+++ openssl-1.1.1g/crypto/fips/fips_drbg_lib.c	2020-06-22 13:32:47.675852917 +0200
cf3dd1
@@ -337,6 +337,19 @@ static int drbg_reseed(DRBG_CTX *dctx,
cf3dd1
 int FIPS_drbg_reseed(DRBG_CTX *dctx,
cf3dd1
                      const unsigned char *adin, size_t adinlen)
cf3dd1
 {
cf3dd1
+    int len = (int)adinlen;
cf3dd1
+
cf3dd1
+    if (len < 0 || (size_t)len != adinlen) {
cf3dd1
+        FIPSerr(FIPS_F_DRBG_RESEED, FIPS_R_ADDITIONAL_INPUT_TOO_LONG);
cf3dd1
+        return 0;
cf3dd1
+    }
cf3dd1
+    RAND_seed(adin, len);
cf3dd1
+    return 1;
cf3dd1
+}
cf3dd1
+
cf3dd1
+int FIPS_drbg_reseed_internal(DRBG_CTX *dctx,
cf3dd1
+                     const unsigned char *adin, size_t adinlen)
cf3dd1
+{
cf3dd1
     return drbg_reseed(dctx, adin, adinlen, 1);
cf3dd1
 }
cf3dd1
 
cf3dd1
@@ -358,6 +371,19 @@ int FIPS_drbg_generate(DRBG_CTX *dctx, u
cf3dd1
                        int prediction_resistance,
cf3dd1
                        const unsigned char *adin, size_t adinlen)
cf3dd1
 {
cf3dd1
+    int len = (int)outlen;
cf3dd1
+
cf3dd1
+    if (len < 0 || (size_t)len != outlen) {
cf3dd1
+        FIPSerr(FIPS_F_FIPS_DRBG_GENERATE, FIPS_R_REQUEST_TOO_LARGE_FOR_DRBG);
cf3dd1
+        return 0;
cf3dd1
+    }
cf3dd1
+    return RAND_bytes(out, len);
cf3dd1
+}
cf3dd1
+
cf3dd1
+int FIPS_drbg_generate_internal(DRBG_CTX *dctx, unsigned char *out, size_t outlen,
cf3dd1
+                       int prediction_resistance,
cf3dd1
+                       const unsigned char *adin, size_t adinlen)
cf3dd1
+{
cf3dd1
     int r = 0;
cf3dd1
 
cf3dd1
     if (FIPS_selftest_failed()) {
cf3dd1
diff -up openssl-1.1.1g/crypto/fips/fips_drbg_rand.c.rewire-fips-drbg openssl-1.1.1g/crypto/fips/fips_drbg_rand.c
cf3dd1
--- openssl-1.1.1g/crypto/fips/fips_drbg_rand.c.rewire-fips-drbg	2020-06-22 13:32:47.611852927 +0200
cf3dd1
+++ openssl-1.1.1g/crypto/fips/fips_drbg_rand.c	2020-06-22 13:32:47.675852917 +0200
cf3dd1
@@ -57,6 +57,8 @@
cf3dd1
 #include <openssl/err.h>
cf3dd1
 #include <openssl/rand.h>
cf3dd1
 #include <openssl/fips.h>
cf3dd1
+#define FIPS_DRBG_generate FIPS_DRBG_generate_internal
cf3dd1
+#define FIPS_DRBG_reseed FIPS_DRBG_reseed_internal
cf3dd1
 #include <openssl/fips_rand.h>
cf3dd1
 #include "fips_rand_lcl.h"
cf3dd1
 
cf3dd1
diff -up openssl-1.1.1g/crypto/fips/fips_drbg_selftest.c.rewire-fips-drbg openssl-1.1.1g/crypto/fips/fips_drbg_selftest.c
cf3dd1
--- openssl-1.1.1g/crypto/fips/fips_drbg_selftest.c.rewire-fips-drbg	2020-06-22 13:32:47.612852927 +0200
cf3dd1
+++ openssl-1.1.1g/crypto/fips/fips_drbg_selftest.c	2020-06-22 13:32:47.675852917 +0200
cf3dd1
@@ -55,6 +55,8 @@
cf3dd1
 #include <openssl/crypto.h>
cf3dd1
 #include <openssl/err.h>
cf3dd1
 #include <openssl/fips.h>
cf3dd1
+#define FIPS_DRBG_generate FIPS_DRBG_generate_internal
cf3dd1
+#define FIPS_DRBG_reseed FIPS_DRBG_reseed_internal
cf3dd1
 #include <openssl/fips_rand.h>
cf3dd1
 #include "fips_rand_lcl.h"
cf3dd1
 #include "fips_locl.h"
cf3dd1
diff -up openssl-1.1.1g/crypto/fips/fips_post.c.rewire-fips-drbg openssl-1.1.1g/crypto/fips/fips_post.c
cf3dd1
--- openssl-1.1.1g/crypto/fips/fips_post.c.rewire-fips-drbg	2020-06-22 13:32:47.672852918 +0200
cf3dd1
+++ openssl-1.1.1g/crypto/fips/fips_post.c	2020-06-22 13:32:47.675852917 +0200
cf3dd1
@@ -79,8 +79,6 @@ int FIPS_selftest(void)
cf3dd1
         ERR_add_error_data(2, "Type=", "rand_drbg_selftest");
cf3dd1
         rv = 0;
cf3dd1
     }
cf3dd1
-    if (!FIPS_selftest_drbg())
cf3dd1
-        rv = 0;
cf3dd1
     if (!FIPS_selftest_sha1())
cf3dd1
         rv = 0;
cf3dd1
     if (!FIPS_selftest_sha2())
cf3dd1
diff -up openssl-1.1.1g/crypto/fips/fips_rand_lib.c.rewire-fips-drbg openssl-1.1.1g/crypto/fips/fips_rand_lib.c
cf3dd1
--- openssl-1.1.1g/crypto/fips/fips_rand_lib.c.rewire-fips-drbg	2020-06-22 13:32:47.613852927 +0200
cf3dd1
+++ openssl-1.1.1g/crypto/fips/fips_rand_lib.c	2020-06-22 13:36:28.722817967 +0200
cf3dd1
@@ -120,6 +120,7 @@ void FIPS_rand_reset(void)
cf3dd1
 
cf3dd1
 int FIPS_rand_seed(const void *buf, int num)
cf3dd1
 {
cf3dd1
+#if 0
cf3dd1
     if (!fips_approved_rand_meth && FIPS_module_mode()) {
cf3dd1
         FIPSerr(FIPS_F_FIPS_RAND_SEED, FIPS_R_NON_FIPS_METHOD);
cf3dd1
         return 0;
cf3dd1
@@ -127,10 +128,15 @@ int FIPS_rand_seed(const void *buf, int
cf3dd1
     if (fips_rand_meth && fips_rand_meth->seed)
cf3dd1
         fips_rand_meth->seed(buf, num);
cf3dd1
     return 1;
cf3dd1
+#else
cf3dd1
+    RAND_seed(buf, num);
cf3dd1
+    return 1;
cf3dd1
+#endif
cf3dd1
 }
cf3dd1
 
cf3dd1
 int FIPS_rand_bytes(unsigned char *buf, int num)
cf3dd1
 {
cf3dd1
+#if 0
cf3dd1
     if (!fips_approved_rand_meth && FIPS_module_mode()) {
cf3dd1
         FIPSerr(FIPS_F_FIPS_RAND_BYTES, FIPS_R_NON_FIPS_METHOD);
cf3dd1
         return 0;
cf3dd1
@@ -138,10 +144,14 @@ int FIPS_rand_bytes(unsigned char *buf,
cf3dd1
     if (fips_rand_meth && fips_rand_meth->bytes)
cf3dd1
         return fips_rand_meth->bytes(buf, num);
cf3dd1
     return 0;
cf3dd1
+#else
cf3dd1
+    return RAND_bytes(buf, num);
cf3dd1
+#endif
cf3dd1
 }
cf3dd1
 
cf3dd1
 int FIPS_rand_status(void)
cf3dd1
 {
cf3dd1
+#if 0
cf3dd1
     if (!fips_approved_rand_meth && FIPS_module_mode()) {
cf3dd1
         FIPSerr(FIPS_F_FIPS_RAND_STATUS, FIPS_R_NON_FIPS_METHOD);
cf3dd1
         return 0;
cf3dd1
@@ -149,6 +159,9 @@ int FIPS_rand_status(void)
cf3dd1
     if (fips_rand_meth && fips_rand_meth->status)
cf3dd1
         return fips_rand_meth->status();
cf3dd1
     return 0;
cf3dd1
+#else
cf3dd1
+    return RAND_status();
cf3dd1
+#endif
cf3dd1
 }
cf3dd1
 
cf3dd1
 /* Return instantiated strength of PRNG. For DRBG this is an internal
cf3dd1
diff -up openssl-1.1.1g/include/openssl/fips.h.rewire-fips-drbg openssl-1.1.1g/include/openssl/fips.h
cf3dd1
--- openssl-1.1.1g/include/openssl/fips.h.rewire-fips-drbg	2020-06-22 13:32:47.672852918 +0200
cf3dd1
+++ openssl-1.1.1g/include/openssl/fips.h	2020-06-22 13:32:47.675852917 +0200
cf3dd1
@@ -64,6 +64,11 @@ extern "C" {
cf3dd1
 
cf3dd1
     int FIPS_selftest(void);
cf3dd1
     int FIPS_selftest_failed(void);
cf3dd1
+
cf3dd1
+    /*
cf3dd1
+     * This function is deprecated as it performs selftest of the old FIPS drbg
cf3dd1
+     * implementation that is not validated.
cf3dd1
+     */
cf3dd1
     int FIPS_selftest_drbg_all(void);
cf3dd1
 
cf3dd1
     int FIPS_dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,
cf3dd1
diff -up openssl-1.1.1g/include/openssl/fips_rand.h.rewire-fips-drbg openssl-1.1.1g/include/openssl/fips_rand.h
cf3dd1
--- openssl-1.1.1g/include/openssl/fips_rand.h.rewire-fips-drbg	2020-06-22 13:32:47.617852926 +0200
cf3dd1
+++ openssl-1.1.1g/include/openssl/fips_rand.h	2020-06-22 13:32:47.675852917 +0200
cf3dd1
@@ -60,6 +60,20 @@
cf3dd1
 #  ifdef  __cplusplus
cf3dd1
 extern "C" {
cf3dd1
 #  endif
cf3dd1
+
cf3dd1
+/*
cf3dd1
+ * IMPORTANT NOTE:
cf3dd1
+ * All functions in this header file are deprecated and should not be used
cf3dd1
+ * as they use the old FIPS_drbg implementation that is not FIPS validated
cf3dd1
+ * anymore.
cf3dd1
+ * To provide backwards compatibility for applications that need FIPS compliant
cf3dd1
+ * RNG number generation and use FIPS_drbg_generate, this function was
cf3dd1
+ * re-wired to call the FIPS validated DRBG instance instead through
cf3dd1
+ * the RAND_bytes() call.
cf3dd1
+ *
cf3dd1
+ * All these functions will be removed in future.
cf3dd1
+ */
cf3dd1
+
cf3dd1
     typedef struct drbg_ctx_st DRBG_CTX;
cf3dd1
 /* DRBG external flags */
cf3dd1
 /* Flag for CTR mode only: use derivation function ctr_df */