Crypto++
5.6.4
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
6 #ifndef CRYPTOPP_OSRNG_H
7 #define CRYPTOPP_OSRNG_H
11 #if !defined(OS_NO_DEPENDENCE) && defined(OS_RNG_AVAILABLE)
33 #ifdef NONBLOCKING_RNG_AVAILABLE
35 #ifdef CRYPTOPP_WIN32_AVAILABLE
47 #if defined(USE_MS_CRYPTOAPI)
48 # if defined(__CYGWIN__) && defined(__x86_64__)
49 typedef unsigned long long ProviderHandle;
50 # elif defined(WIN64) || defined(_WIN64)
51 typedef unsigned __int64 ProviderHandle;
53 typedef unsigned long ProviderHandle;
55 #elif defined(USE_MS_CNGAPI)
57 typedef PVOID ProviderHandle;
58 #endif // USE_MS_CRYPTOAPI or USE_MS_CNGAPI
70 ProviderHandle m_hProvider;
73 #if defined(_MSC_VER) && defined(USE_MS_CRYPTOAPI)
74 # pragma comment(lib, "advapi32.lib")
77 #if defined(_MSC_VER) && defined(USE_MS_CNGAPI)
78 # pragma comment(lib, "bcrypt.lib")
81 #endif //CRYPTOPP_WIN32_AVAILABLE
101 #ifdef CRYPTOPP_WIN32_AVAILABLE
110 #if defined(BLOCKING_RNG_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
160 {Reseed(blocking, seedSize);}
165 void Reseed(
bool blocking =
false,
unsigned int seedSize = 32);
177 template <
class BLOCK_CIPHER>
188 {
if (autoSeed)
Reseed(blocking);}
197 void Reseed(
bool blocking =
false,
const byte *additionalEntropy = NULL,
size_t length = 0);
206 void Reseed(
const byte *key,
size_t keylength,
const byte *seed,
const byte *timeVector);
217 template <
class BLOCK_CIPHER>
220 m_rng.reset(
new X917RNG(
new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector));
223 template <
class BLOCK_CIPHER>
226 SecByteBlock seed(BLOCK_CIPHER::BLOCKSIZE + BLOCK_CIPHER::DEFAULT_KEYLENGTH);
234 hash.Update(seed, seed.
size());
235 hash.Update(input, length);
238 key = seed + BLOCK_CIPHER::BLOCKSIZE;
240 while (memcmp(key, seed,
STDMIN((
unsigned int)BLOCK_CIPHER::BLOCKSIZE, (
unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0);
242 Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, NULL);
247 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
256 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
261 #endif // CRYPTOPP_DOXYGEN_PROCESSING
virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
Generate random bytes into a BufferedTransformation.
AutoSeededRandomPool(bool blocking=false, unsigned int seedSize=32)
Construct an AutoSeededRandomPool.
bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
void OS_GenerateRandomBlock(bool blocking, byte *output, size_t size)
OS_GenerateRandomBlock.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
Classes for automatic resource management.
A typedef providing a default generator.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Interface for random number generators.
Miscellaneous classes for RNGs.
void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
Generate random bytes into a BufferedTransformation.
Wrapper class for /dev/random and /dev/srandom.
Class file for Randomness Pool.
Classes and functions for the FIPS 140-2 validated library.
Base class for all exceptions thrown by the library.
Class file for the AES cipher (Rijndael)
ProviderHandle GetProviderHandle() const
Retrieves the provider handle.
Classes for SHA-1 and SHA-2 family of message digests.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
Ensures an object is not copyable.
Wrapper class for /dev/random and /dev/srandom.
Automatically Seeded Randomness Pool.
size_type size() const
Provides the count of elements in the SecBlock.
AutoSeededX917RNG(bool blocking=false, bool autoSeed=true)
Construct an AutoSeededX917RNG.
Exception thrown when an operating system error is encountered.
Wrapper for Microsoft crypto service provider.
Crypto++ library namespace.
void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Library configuration file.
Automatically Seeded X9.17 RNG.
implements the SHA-256 standard
Abstract base classes that provide a uniform interface to this library.
void Reseed(bool blocking=false, const byte *additionalEntropy=NULL, size_t length=0)
Reseed an AutoSeededX917RNG.