diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index c71f2366b..9088d8977 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -246,11 +246,29 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b) #define RESEED_INTERVAL WC_RESEED_INTERVAL +/* For FIPS builds, the user should not be adjusting the values. */ +#if defined(HAVE_FIPS) && \ + defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2) + #if defined(RNG_SECURITY_STRENGTH) \ + || defined(ENTROPY_SCALE_FACTOR) \ + || defined(SEED_BLOCK_SZ) + + #error "Do not change the RNG parameters for FIPS builds." + #endif +#endif /* The security strength for the RNG is the target number of bits of * entropy you are looking for in a seed. */ #ifndef RNG_SECURITY_STRENGTH - /* SHA-256 requires a minimum of 256-bits of entropy. */ - #define RNG_SECURITY_STRENGTH (256) + #if defined(HAVE_FIPS) && \ + defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2) + /* SHA-256 requires a minimum of 256-bits of entropy. The goal + * of 1024 will provide 4 times that. */ + #define RNG_SECURITY_STRENGTH (1024) + #else + /* If not using FIPS or using old FIPS, set the number down a bit. + * More is better, but more is also slower. */ + #define RNG_SECURITY_STRENGTH (256) + #endif #endif #ifndef ENTROPY_SCALE_FACTOR