forked from wolfSSL/wolfssl
FIPS Revalidation
1. Update the GenerateSeed() function for RDSEED on Windows to use the intrinsic function instead of inline assembly.
This commit is contained in:
@@ -163,6 +163,10 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
|
|||||||
#ifdef HAVE_INTEL_RDRAND
|
#ifdef HAVE_INTEL_RDRAND
|
||||||
static int wc_GenerateRand_IntelRD(OS_Seed* os, byte* output, word32 sz);
|
static int wc_GenerateRand_IntelRD(OS_Seed* os, byte* output, word32 sz);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_API
|
||||||
|
#include <immintrin.h>
|
||||||
|
#endif /* USE_WINDOWS_API */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Start NIST DRBG code */
|
/* Start NIST DRBG code */
|
||||||
@@ -1019,14 +1023,31 @@ int wc_FreeNetRandom(void)
|
|||||||
|
|
||||||
#ifdef HAVE_INTEL_RDSEED
|
#ifdef HAVE_INTEL_RDSEED
|
||||||
|
|
||||||
/* return 0 on success */
|
#ifndef USE_WINDOWS_API
|
||||||
static INLINE int IntelRDseed64(word64* seed)
|
|
||||||
{
|
|
||||||
unsigned char ok;
|
|
||||||
|
|
||||||
__asm__ volatile("rdseed %0; setc %1":"=r"(*seed), "=qm"(ok));
|
/* return 0 on success */
|
||||||
return (ok) ? 0 : -1;
|
static INLINE int IntelRDseed64(word64* seed)
|
||||||
}
|
{
|
||||||
|
unsigned char ok;
|
||||||
|
|
||||||
|
__asm__ volatile("rdseed %0; setc %1":"=r"(*seed), "=qm"(ok));
|
||||||
|
return (ok) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* USE_WINDOWS_API */
|
||||||
|
/* The compiler Visual Studio uses does not allow inline assembly.
|
||||||
|
* It does allow for Intel intrinsic functions. */
|
||||||
|
|
||||||
|
/* return 0 on success */
|
||||||
|
static INLINE int IntelRDseed64(word64* seed)
|
||||||
|
{
|
||||||
|
int ok;
|
||||||
|
|
||||||
|
ok = _rdseed64_step(seed);
|
||||||
|
return (ok) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* USE_WINDOWS_API */
|
||||||
|
|
||||||
/* return 0 on success */
|
/* return 0 on success */
|
||||||
static INLINE int IntelRDseed64_r(word64* rnd)
|
static INLINE int IntelRDseed64_r(word64* rnd)
|
||||||
@@ -1073,6 +1094,8 @@ static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz)
|
|||||||
|
|
||||||
#ifdef HAVE_INTEL_RDRAND
|
#ifdef HAVE_INTEL_RDRAND
|
||||||
|
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
|
||||||
/* return 0 on success */
|
/* return 0 on success */
|
||||||
static INLINE int IntelRDrand64(word64 *rnd)
|
static INLINE int IntelRDrand64(word64 *rnd)
|
||||||
{
|
{
|
||||||
@@ -1083,6 +1106,22 @@ static INLINE int IntelRDrand64(word64 *rnd)
|
|||||||
return (ok) ? 0 : -1;
|
return (ok) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* USE_WINDOWS_API */
|
||||||
|
/* The compiler Visual Studio uses does not allow inline assembly.
|
||||||
|
* It does allow for Intel intrinsic functions. */
|
||||||
|
|
||||||
|
/* return 0 on success */
|
||||||
|
static INLINE int IntelRDrand64(word64 *rnd)
|
||||||
|
{
|
||||||
|
int ok;
|
||||||
|
|
||||||
|
ok = _rdrand64_step(rnd);
|
||||||
|
|
||||||
|
return (ok) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* USE_WINDOWS_API */
|
||||||
|
|
||||||
/* return 0 on success */
|
/* return 0 on success */
|
||||||
static INLINE int IntelRDrand64_r(word64 *rnd)
|
static INLINE int IntelRDrand64_r(word64 *rnd)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user