27 #if defined(CRYPTOPP_CPUID_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) 29 # if defined(CRYPTOPP_MSC_VERSION) 30 # define MASM_RDRAND_ASM_AVAILABLE 1 31 # define MASM_RDSEED_ASM_AVAILABLE 1 34 # if (__SUNPRO_CC >= 0x5100) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000) || \ 35 (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_GCC_VERSION >= 30200) 36 # define GCC_RDRAND_ASM_AVAILABLE 1 37 # define GCC_RDSEED_ASM_AVAILABLE 1 40 #endif // CRYPTOPP_CPUID_AVAILABLE 42 typedef unsigned char byte;
44 #if MASM_RDRAND_ASM_AVAILABLE 45 extern "C" void CRYPTOPP_FASTCALL MASM_RDRAND_GenerateBlock(byte*,
size_t);
48 #if MASM_RDSEED_ASM_AVAILABLE 49 extern "C" void CRYPTOPP_FASTCALL MASM_RDSEED_GenerateBlock(byte*,
size_t);
57 #if defined(CRYPTOPP_CPUID_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) 60 inline void RDRAND32(
void* output)
62 CRYPTOPP_UNUSED(output);
63 #if defined(GCC_RDRAND_ASM_AVAILABLE) 67 ".byte 0x0f, 0xc7, 0xf0;\n" 69 :
"=a" (*reinterpret_cast<word32*>(output))
75 #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 77 inline void RDRAND64(
void* output)
79 CRYPTOPP_UNUSED(output);
80 #if defined(GCC_RDRAND_ASM_AVAILABLE) 84 ".byte 0x48, 0x0f, 0xc7, 0xf0;\n" 86 :
"=a" (*reinterpret_cast<word64*>(output))
102 if (size == 0)
return;
104 #if defined(MASM_RDRAND_ASM_AVAILABLE) 106 MASM_RDRAND_GenerateBlock(output, size);
108 #elif defined(GCC_RDRAND_ASM_AVAILABLE) 110 # if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 112 for (i = 0; i < size/8; i++)
113 RDRAND64(output+i*8);
122 std::memcpy(output, &val, size);
126 for (i = 0; i < size/4; i++)
127 RDRAND32(output+i*4);
136 std::memcpy(output, &val, size);
141 CRYPTOPP_UNUSED(output);
142 throw NotImplemented(
"RDRAND: failed to find a suitable implementation");
166 inline void RDSEED32(
void* output)
168 CRYPTOPP_UNUSED(output);
169 #if defined(GCC_RDSEED_ASM_AVAILABLE) 173 ".byte 0x0f, 0xc7, 0xf8;\n" 175 :
"=a" (*reinterpret_cast<word32*>(output))
181 #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 183 inline void RDSEED64(
void* output)
185 CRYPTOPP_UNUSED(output);
186 #if defined(GCC_RDSEED_ASM_AVAILABLE) 190 ".byte 0x48, 0x0f, 0xc7, 0xf8;\n" 192 :
"=a" (*reinterpret_cast<word64*>(output))
208 if (size == 0)
return;
210 #if defined(MASM_RDSEED_ASM_AVAILABLE) 212 MASM_RDSEED_GenerateBlock(output, size);
214 #elif defined(GCC_RDSEED_ASM_AVAILABLE) 215 # if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 217 for (i = 0; i < size/8; i++)
218 RDSEED64(output+i*8);
227 std::memcpy(output, &val, size);
231 for (i = 0; i < size/4; i++)
232 RDSEED32(output+i*4);
241 std::memcpy(output, &val, size);
246 CRYPTOPP_UNUSED(output);
247 throw NotImplemented(
"RDSEED: failed to find a suitable implementation");
267 #else // not CRYPTOPP_CPUID_AVAILABLE 277 CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
294 CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
303 #endif // CRYPTOPP_CPUID_AVAILABLE virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
Abstract base classes that provide a uniform interface to this library.
Library configuration file.
Classes for RDRAND and RDSEED.
bool HasRDRAND()
Determines RDRAND availability.
RDSEED()
Construct a RDSEED generator.
Classes and functions for secure memory allocations.
Exception thrown when a RDRAND generator encounters a generator related error.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
A method was called which was not implemented.
bool HasRDSEED()
Determines RDSEED availability.
Fixed size stack-based SecBlock.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Functions for CPU features and intrinsics.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
Crypto++ library namespace.
Exception thrown when a RDSEED generator encounters a generator related error.
RDRAND()
Construct a RDRAND generator.
byte * BytePtr()
Provides a byte pointer to the first element in the memory block.