Use _rdrand32_step for X32. Whitespace
parent
8576762836
commit
d21248b995
100
rdrand.cpp
100
rdrand.cpp
|
|
@ -179,39 +179,39 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||||
static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
{
|
{
|
||||||
assert((output && size) || !(output || size));
|
assert((output && size) || !(output || size));
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
word64 val;
|
|
||||||
#else
|
|
||||||
word32 val;
|
word32 val;
|
||||||
|
#else
|
||||||
|
word64 val;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (size >= sizeof(val))
|
while (size >= sizeof(val))
|
||||||
{
|
{
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
if (_rdrand64_step((word64*)output))
|
|
||||||
#else
|
|
||||||
if (_rdrand32_step((word32*)output))
|
if (_rdrand32_step((word32*)output))
|
||||||
|
#else
|
||||||
|
if (_rdrand64_step((word64*)output))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
output += sizeof(val);
|
output += sizeof(val);
|
||||||
size -= sizeof(val);
|
size -= sizeof(val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!safety--)
|
if (!safety--)
|
||||||
{
|
{
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
if (_rdrand64_step(&val))
|
|
||||||
#else
|
|
||||||
if (_rdrand32_step(&val))
|
if (_rdrand32_step(&val))
|
||||||
|
#else
|
||||||
|
if (_rdrand64_step(&val))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
memcpy(output, &val, size);
|
memcpy(output, &val, size);
|
||||||
|
|
@ -225,12 +225,12 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYTPOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
*((volatile word64*)&val) = 0;
|
|
||||||
#else
|
|
||||||
*((volatile word32*)&val) = 0;
|
*((volatile word32*)&val) = 0;
|
||||||
|
#else
|
||||||
|
*((volatile word64*)&val) = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return int(size == 0);
|
return int(size == 0);
|
||||||
|
|
@ -249,7 +249,7 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
char rc;
|
char rc;
|
||||||
while (size)
|
while (size)
|
||||||
{
|
{
|
||||||
__asm__ volatile(
|
__asm__ volatile(
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
||||||
".byte 0x48, 0x0f, 0xc7, 0xf0;\n" // rdrand rax
|
".byte 0x48, 0x0f, 0xc7, 0xf0;\n" // rdrand rax
|
||||||
#else
|
#else
|
||||||
|
|
@ -259,10 +259,10 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
: "=a" (val), "=qm" (rc)
|
: "=a" (val), "=qm" (rc)
|
||||||
:
|
:
|
||||||
: "cc"
|
: "cc"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
if (size >= sizeof(val))
|
if (size >= sizeof(val))
|
||||||
{
|
{
|
||||||
#if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32)
|
#if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32)
|
||||||
|
|
@ -280,15 +280,15 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
memcpy(output, &val, size);
|
memcpy(output, &val, size);
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!safety--)
|
if (!safety--)
|
||||||
{
|
{
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
||||||
|
|
@ -360,39 +360,39 @@ void RDRAND::DiscardBytes(size_t n)
|
||||||
static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
{
|
{
|
||||||
assert((output && size) || !(output || size));
|
assert((output && size) || !(output || size));
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
word64 val;
|
|
||||||
#else
|
|
||||||
word32 val;
|
word32 val;
|
||||||
|
#else
|
||||||
|
word64 val;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (size >= sizeof(val))
|
while (size >= sizeof(val))
|
||||||
{
|
{
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
if (_rdseed64_step((word64*)output))
|
|
||||||
#else
|
|
||||||
if (_rdseed32_step((word32*)output))
|
if (_rdseed32_step((word32*)output))
|
||||||
|
#else
|
||||||
|
if (_rdseed64_step((word64*)output))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
output += sizeof(val);
|
output += sizeof(val);
|
||||||
size -= sizeof(val);
|
size -= sizeof(val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!safety--)
|
if (!safety--)
|
||||||
{
|
{
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
if (_rdseed64_step(&val))
|
|
||||||
#else
|
|
||||||
if (_rdseed32_step(&val))
|
if (_rdseed32_step(&val))
|
||||||
|
#else
|
||||||
|
if (_rdseed64_step(&val))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
memcpy(output, &val, size);
|
memcpy(output, &val, size);
|
||||||
|
|
@ -406,12 +406,12 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
|
||||||
*((volatile word64*)&val) = 0;
|
|
||||||
#else
|
|
||||||
*((volatile word32*)&val) = 0;
|
*((volatile word32*)&val) = 0;
|
||||||
|
#else
|
||||||
|
*((volatile word64*)&val) = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return int(size == 0);
|
return int(size == 0);
|
||||||
|
|
@ -430,7 +430,7 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
char rc;
|
char rc;
|
||||||
while (size)
|
while (size)
|
||||||
{
|
{
|
||||||
__asm__ volatile(
|
__asm__ volatile(
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
||||||
".byte 0x48, 0x0f, 0xc7, 0xf8;\n" // rdseed rax
|
".byte 0x48, 0x0f, 0xc7, 0xf8;\n" // rdseed rax
|
||||||
#else
|
#else
|
||||||
|
|
@ -440,10 +440,10 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
: "=a" (val), "=qm" (rc)
|
: "=a" (val), "=qm" (rc)
|
||||||
:
|
:
|
||||||
: "cc"
|
: "cc"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
if (size >= sizeof(val))
|
if (size >= sizeof(val))
|
||||||
{
|
{
|
||||||
#if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32)
|
#if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32)
|
||||||
|
|
@ -461,15 +461,15 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
|
||||||
memcpy(output, &val, size);
|
memcpy(output, &val, size);
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!safety--)
|
if (!safety--)
|
||||||
{
|
{
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue