Merge pull request #9691 from douzzer/20260120-linuxkm-RHEL9v6-and-RDSEED-sanity-check
20260120-linuxkm-RHEL9v6-and-RDSEED-sanity-check
This commit is contained in:
@@ -1935,12 +1935,49 @@ static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
int ret;
|
||||
word64 rndTmp;
|
||||
static int rdseed_sanity_status = 0;
|
||||
|
||||
(void)os;
|
||||
|
||||
if (!IS_INTEL_RDSEED(intel_flags))
|
||||
return -1;
|
||||
|
||||
/* Note, access to rdseed_sanity_status is benignly racey on multithreaded
|
||||
* targets.
|
||||
*/
|
||||
if (rdseed_sanity_status == 0) {
|
||||
word64 sanity_word1 = 0, sanity_word2 = 0;
|
||||
|
||||
ret = IntelRDseed64_r(&sanity_word1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = IntelRDseed64_r(&sanity_word2);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (sanity_word1 == sanity_word2) {
|
||||
ret = IntelRDseed64_r(&sanity_word1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (sanity_word1 == sanity_word2) {
|
||||
#ifdef WC_VERBOSE_RNG
|
||||
WOLFSSL_DEBUG_PRINTF(
|
||||
"WARNING: disabling RDSEED due to repeating word 0x%lx -- "
|
||||
"check CPU microcode version.", sanity_word2);
|
||||
#endif
|
||||
rdseed_sanity_status = -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
rdseed_sanity_status = 1;
|
||||
}
|
||||
else if (rdseed_sanity_status < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; (sz / sizeof(word64)) > 0; sz -= sizeof(word64),
|
||||
output += sizeof(word64)) {
|
||||
ret = IntelRDseed64_r((word64*)output);
|
||||
|
||||
Reference in New Issue
Block a user