1 #ifndef CRYPTOPP_OSRNG_H
2 #define CRYPTOPP_OSRNG_H
8 #ifdef OS_RNG_AVAILABLE
16 NAMESPACE_BEGIN(CryptoPP)
25 #ifdef NONBLOCKING_RNG_AVAILABLE
27 #ifdef CRYPTOPP_WIN32_AVAILABLE
34 typedef unsigned __int64 ProviderHandle;
36 typedef unsigned long ProviderHandle;
38 ProviderHandle GetProviderHandle()
const {
return m_hProvider;}
40 ProviderHandle m_hProvider;
43 #pragma comment(lib, "advapi32.lib")
55 #ifdef CRYPTOPP_WIN32_AVAILABLE
56 # ifndef WORKAROUND_MS_BUG_Q258000
66 #ifdef BLOCKING_RNG_AVAILABLE
82 CRYPTOPP_DLL
void CRYPTOPP_API OS_GenerateRandomBlock(
bool blocking, byte *output,
size_t size);
91 {Reseed(blocking, seedSize);}
92 void Reseed(
bool blocking =
false,
unsigned int seedSize = 32);
96 template <
class BLOCK_CIPHER>
102 {
if (autoSeed) Reseed(blocking);}
103 void Reseed(
bool blocking =
false,
const byte *additionalEntropy = NULL,
size_t length = 0);
105 void Reseed(
const byte *key,
size_t keylength,
const byte *seed,
const byte *timeVector);
115 template <
class BLOCK_CIPHER>
118 m_rng.reset(
new X917RNG(
new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector));
121 template <
class BLOCK_CIPHER>
124 SecByteBlock seed(BLOCK_CIPHER::BLOCKSIZE + BLOCK_CIPHER::DEFAULT_KEYLENGTH);
128 OS_GenerateRandomBlock(blocking, seed, seed.size());
132 hash.Update(seed, seed.size());
133 hash.Update(input, length);
134 hash.TruncatedFinal(seed, UnsignedMin(hash.
DigestSize(), seed.size()));
136 key = seed + BLOCK_CIPHER::BLOCKSIZE;
138 while (memcmp(key, seed, STDMIN((
unsigned int)BLOCK_CIPHER::BLOCKSIZE, (
unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0);
140 Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, NULL);
146 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2