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