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