Add check for buggy RDRAND (AMD Ryzen CPU case) even if we always use RDSEED instead of RDRAND when RDSEED is available (which is the case on modern CPUs)

This commit is contained in:
Mounir IDRASSI 2019-10-30 08:45:01 +01:00
parent 7a35ecb154
commit 5ecff99edc
No known key found for this signature in database
GPG Key ID: 02C30AE90FAE4A6F
1 changed files with 13 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "cpu.h"
#include "misc.h"
#include "rdrand.h"
#ifndef EXCEPTION_EXECUTE_HANDLER
#define EXCEPTION_EXECUTE_HANDLER 1
@ -387,6 +388,18 @@ void DetectX86Features()
}
}
/* Add check fur buggy RDRAND (AMD Ryzen case) even if we always use RDSEED instead of RDRAND when RDSEED available */
if (g_hasRDRAND)
{
if ( RDRAND_getBytes ((unsigned char*) cpuid, sizeof (cpuid))
&& (cpuid[0] == 0xFFFFFFFF) && (cpuid[1] == 0xFFFFFFFF)
&& (cpuid[2] == 0xFFFFFFFF) && (cpuid[3] == 0xFFFFFFFF)
)
{
g_hasRDRAND = 0;
}
}
if (!g_cacheLineSize)
g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;