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
base class for all exceptions thrown by Crypto++
AutoSeededRandomPool(bool blocking=false, unsigned int seedSize=32)
use blocking to choose seeding with BlockingRng or NonblockingRng. the parameter is ignored if only o...
implements the SHA-256 standard
encapsulate CryptoAPI's CryptGenRandom or /dev/urandom
virtual void GenerateBlock(byte *output, size_t size)
generate random array of bytes
RNG derived from ANSI X9.17 Appendix C.
a block of memory allocated using A
interface for random number generators
void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
generate random bytes as input to a BufferedTransformation
Exception class for Operating-System Random Number Generator.
Automaticly Seeded Randomness Pool.
AutoSeededRandomPool DefaultAutoSeededRNG
this is AutoSeededX917RNG
in FIPS mode, otherwise it's AutoSeededRandomPool
RNG from ANSI X9.17 Appendix C, seeded using an OS provided RNG.
encapsulate /dev/random, or /dev/srandom on OpenBSD
bool CanIncorporateEntropy() const
returns true if IncorporateEntropy is implemented
AutoSeededX917RNG(bool blocking=false, bool autoSeed=true)
use blocking to choose seeding with BlockingRng or NonblockingRng. the parameter is ignored if only o...
virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
generate random bytes as input to a BufferedTransformation
void IncorporateEntropy(const byte *input, size_t length)
update RNG state with additional unpredictable values