7 #ifndef CRYPTOPP_IMPORTS 11 #ifdef OS_RNG_AVAILABLE 15 #ifdef CRYPTOPP_WIN32_AVAILABLE 17 #define _WIN32_WINNT 0x0400 23 #ifdef CRYPTOPP_UNIX_AVAILABLE 31 #if defined(NONBLOCKING_RNG_AVAILABLE) || defined(BLOCKING_RNG_AVAILABLE) 33 :
Exception(OTHER_ERROR,
"OS_Rng: " + operation +
" operation failed with error " +
34 #ifdef CRYPTOPP_WIN32_AVAILABLE
44 #ifdef NONBLOCKING_RNG_AVAILABLE 46 #ifdef CRYPTOPP_WIN32_AVAILABLE 50 if (!CryptAcquireContext(&m_hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
54 MicrosoftCryptoProvider::~MicrosoftCryptoProvider()
56 CryptReleaseContext(m_hProvider, 0);
63 #ifndef CRYPTOPP_WIN32_AVAILABLE 64 m_fd = open(
"/dev/urandom",O_RDONLY);
70 NonblockingRng::~NonblockingRng()
72 #ifndef CRYPTOPP_WIN32_AVAILABLE 79 #ifdef CRYPTOPP_WIN32_AVAILABLE 80 # ifdef WORKAROUND_MS_BUG_Q258000 88 ssize_t len = read(m_fd, output, size);
93 if (errno != EINTR && errno != EAGAIN)
109 #ifdef BLOCKING_RNG_AVAILABLE 111 #ifndef CRYPTOPP_BLOCKING_RNG_FILENAME 113 #define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/srandom" 115 #define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/random" 121 m_fd = open(CRYPTOPP_BLOCKING_RNG_FILENAME,O_RDONLY);
123 throw OS_RNG_Err(
"open " CRYPTOPP_BLOCKING_RNG_FILENAME);
126 BlockingRng::~BlockingRng()
137 ssize_t len = read(m_fd, output, size);
141 if (errno != EINTR && errno != EAGAIN)
142 throw OS_RNG_Err(
"read " CRYPTOPP_BLOCKING_RNG_FILENAME);
160 #ifdef NONBLOCKING_RNG_AVAILABLE 164 #ifdef BLOCKING_RNG_AVAILABLE 170 #ifdef BLOCKING_RNG_AVAILABLE 174 #ifdef NONBLOCKING_RNG_AVAILABLE 185 IncorporateEntropy(seed, seedSize);
Base class for all exceptions thrown by Crypto++.
Wrapper for Microsoft crypto service provider.
BlockingRng()
Construct a BlockingRng.
OS_RNG_Err(const std::string &operation)
Constructs an OS_RNG_Err.
Restricts the instantiation of a class to one static object without locks.
Wrapper class for /dev/random and /dev/srandom.
void Reseed(bool blocking=false, unsigned int seedSize=32)
Reseed an AutoSeededRandomPool.
SecByteBlock is a SecBlock<byte> typedef.
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
NonblockingRng()
Construct a NonblockingRng.
Miscellaneous classes for RNGs.
MicrosoftCryptoProvider()
Construct a MicrosoftCryptoProvider.
Wrapper class for /dev/random and /dev/srandom.
void OS_GenerateRandomBlock(bool blocking, byte *output, size_t size)
OS_GenerateRandomBlock.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
ProviderHandle GetProviderHandle() const
Retrieves the CryptoAPI provider handle.
Crypto++ library namespace.
Classes for access to the operating system's random number generators.