27 #if CRYPTOPP_MSC_VERSION 28 # pragma warning(disable: 4702) 31 #if defined(CRYPTOPP_RDRAND_AVAILABLE) 32 # if defined(CRYPTOPP_MSC_VERSION) 33 # define MASM_RDRAND_ASM_AVAILABLE 1 35 # if (__SUNPRO_CC >= 0x5100) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000) || \ 36 (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || (CRYPTOPP_GCC_VERSION >= 30200) 37 # define GCC_RDRAND_ASM_AVAILABLE 1 39 #endif // CRYPTOPP_RDRAND_AVAILABLE 41 #if defined(CRYPTOPP_RDSEED_AVAILABLE) 42 # if defined(CRYPTOPP_MSC_VERSION) 43 # define MASM_RDSEED_ASM_AVAILABLE 1 45 # if (__SUNPRO_CC >= 0x5100) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000) || \ 46 (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || (CRYPTOPP_GCC_VERSION >= 30200) 47 # define GCC_RDSEED_ASM_AVAILABLE 1 49 #endif // CRYPTOPP_RDSEED_AVAILABLE 51 typedef unsigned char byte;
53 #if MASM_RDRAND_ASM_AVAILABLE 54 extern "C" void CRYPTOPP_FASTCALL MASM_RDRAND_GenerateBlock(
byte*,
size_t);
57 #if MASM_RDSEED_ASM_AVAILABLE 58 extern "C" void CRYPTOPP_FASTCALL MASM_RDSEED_GenerateBlock(
byte*,
size_t);
66 #if defined(CRYPTOPP_RDRAND_AVAILABLE) 69 inline void RDRAND32(
void* output)
71 CRYPTOPP_UNUSED(output);
72 # if defined(GCC_RDRAND_ASM_AVAILABLE) 76 ".byte 0x0f, 0xc7, 0xf0;\n" 78 :
"=a" (*reinterpret_cast<word32*>(output))
84 # if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 86 inline void RDRAND64(
void* output)
88 CRYPTOPP_UNUSED(output);
89 # if defined(GCC_RDRAND_ASM_AVAILABLE) 93 ".byte 0x48, 0x0f, 0xc7, 0xf0;\n" 95 :
"=a" (*reinterpret_cast<word64*>(output))
111 if (size == 0)
return;
113 # if defined(MASM_RDRAND_ASM_AVAILABLE) 115 MASM_RDRAND_GenerateBlock(output, size);
117 # elif defined(GCC_RDRAND_ASM_AVAILABLE) 119 # if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 121 for (i = 0; i < size/8; i++)
122 RDRAND64(output+i*8);
131 std::memcpy(output, &val, size);
135 for (i = 0; i < size/4; i++)
136 RDRAND32(output+i*4);
145 std::memcpy(output, &val, size);
150 CRYPTOPP_UNUSED(output);
151 throw NotImplemented(
"RDRAND: failed to find a suitable implementation");
171 #endif // CRYPTOPP_RDRAND_AVAILABLE 176 #if defined(CRYPTOPP_RDSEED_AVAILABLE) 179 inline void RDSEED32(
void* output)
181 CRYPTOPP_UNUSED(output);
182 # if defined(GCC_RDSEED_ASM_AVAILABLE) 186 ".byte 0x0f, 0xc7, 0xf8;\n" 188 :
"=a" (*reinterpret_cast<word32*>(output))
194 # if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 196 inline void RDSEED64(
void* output)
198 CRYPTOPP_UNUSED(output);
199 # if defined(GCC_RDSEED_ASM_AVAILABLE) 203 ".byte 0x48, 0x0f, 0xc7, 0xf8;\n" 205 :
"=a" (*reinterpret_cast<word64*>(output))
221 if (size == 0)
return;
223 # if defined(MASM_RDSEED_ASM_AVAILABLE) 225 MASM_RDSEED_GenerateBlock(output, size);
227 # elif defined(GCC_RDSEED_ASM_AVAILABLE) 228 # if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32) 230 for (i = 0; i < size/8; i++)
231 RDSEED64(output+i*8);
240 std::memcpy(output, &val, size);
244 for (i = 0; i < size/4; i++)
245 RDSEED32(output+i*4);
254 std::memcpy(output, &val, size);
259 CRYPTOPP_UNUSED(output);
260 throw NotImplemented(
"RDSEED: failed to find a suitable implementation");
280 #endif // CRYPTOPP_RDSEED_AVAILABLE 285 #if !defined(CRYPTOPP_RDRAND_AVAILABLE) 295 CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
304 #endif // CRYPTOPP_RDRAND_AVAILABLE 306 #if !defined(CRYPTOPP_RDSEED_AVAILABLE) 316 CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
325 #endif // CRYPTOPP_RDSEED_AVAILABLE virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
unsigned int word32
32-bit unsigned datatype
Abstract base classes that provide a uniform interface to this library.
Library configuration file.
Classes for RDRAND and RDSEED.
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.
unsigned long long word64
64-bit unsigned datatype
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.
unsigned char byte
8-bit unsigned datatype
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.