Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion linuxkm/linuxkm_wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
#endif
#endif

#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(5, 2, 4)
#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(7, 0, 0)
#if defined(HAVE_HASHDRBG) && \
defined(HAVE_ENTROPY_MEMUSE) && \
!defined(WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER)
Expand All @@ -227,6 +227,11 @@
!defined(HAVE_ENTROPY_MEMUSE) && \
!defined(WC_LINUXKM_RDSEED_IN_GLUE_LAYER)
#define WC_LINUXKM_RDSEED_IN_GLUE_LAYER
/* Work around -Wmaybe-uninitialized in old FIPS random.c.
* Glue-layer wc_linuxkm_GenerateSeed_IntelRD() always forces
* failure if RDSEED is missing or fails.
*/
#undef FORCE_FAILURE_RDSEED
#endif
#endif
#if defined(WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER)
Expand Down
26 changes: 22 additions & 4 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -3934,7 +3934,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
}
#endif

#ifdef HAVE_INTEL_RDSEED
#if defined(HAVE_INTEL_RDSEED) || defined(HAVE_AMD_RDSEED)
if (IS_INTEL_RDSEED(intel_flags)) {
if (!wc_GenerateSeed_IntelRD(NULL, output, sz)) {
/* success, we're done */
Expand All @@ -3945,7 +3945,13 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return READ_RAN_E;
#endif
}
#endif /* HAVE_INTEL_RDSEED */
#ifdef FORCE_FAILURE_RDSEED
else {
/* Don't fall back to system randomness */
return MISSING_RNG_E;
}
#endif
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */

#ifdef WIN_REUSE_CRYPT_HANDLE
/* Check that handle was initialized.
Expand Down Expand Up @@ -4914,7 +4920,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
(void)os;
int ret;
int ret = WC_NO_ERR_TRACE(RNG_FAILURE_E);

#ifdef HAVE_ENTROPY_MEMUSE
ret = wc_Entropy_Get(MAX_ENTROPY_BITS, output, sz);
Expand All @@ -4934,6 +4940,12 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return ret;
#endif
}
#ifdef FORCE_FAILURE_RDSEED
else {
/* Don't fall back to get_random_bytes() */
return MISSING_RNG_E;
}
#endif
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */

#ifdef LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT
Expand All @@ -4957,7 +4969,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
(void)os;
int ret;
int ret = WC_NO_ERR_TRACE(RNG_FAILURE_E);

#ifdef HAVE_ENTROPY_MEMUSE
ret = wc_Entropy_Get(MAX_ENTROPY_BITS, output, sz);
Expand All @@ -4980,6 +4992,12 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return ret;
}
}
#ifdef FORCE_FAILURE_RDSEED
else {
/* Don't fall back to arc4random_buf() */
return MISSING_RNG_E;
}
#endif
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */

(void)ret;
Expand Down
Loading