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