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
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");
277 CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
294 CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
Fixed size stack-based SecBlock.
A method was called which was not implemented.
Exception thrown when a RDRAND generator encounters a generator related error.
RDRAND()
Construct a RDRAND generator.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Exception thrown when a RDSEED generator encounters a generator related error.
RDSEED()
Construct a RDSEED generator.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
byte * BytePtr()
Provides a byte pointer to the first element in the memory block.
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
Library configuration file.
Functions for CPU features and intrinsics.
bool HasRDRAND()
Determines RDRAND availability.
bool HasRDSEED()
Determines RDSEED availability.
Abstract base classes that provide a uniform interface to this library.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
Crypto++ library namespace.
Classes for RDRAND and RDSEED.
Classes and functions for secure memory allocations.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.