Blame SOURCES/openssl-1.1.1-rewire-fips-drbg.patch

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