6#ifndef CRYPTOPP_OSRNG_H
7#define CRYPTOPP_OSRNG_H
11#if !defined(NO_OS_DEPENDENCE) && defined(OS_RNG_AVAILABLE)
32#ifdef NONBLOCKING_RNG_AVAILABLE
34#ifdef CRYPTOPP_WIN32_AVAILABLE
45#if defined(USE_MS_CRYPTOAPI)
46# if defined(__CYGWIN__) && defined(__x86_64__)
47 typedef unsigned long long ProviderHandle;
48# elif defined(WIN64) || defined(_WIN64)
49 typedef unsigned __int64 ProviderHandle;
51 typedef unsigned long ProviderHandle;
53#elif defined(USE_MS_CNGAPI)
55 typedef PVOID ProviderHandle;
68 ProviderHandle m_hProvider;
71#if defined(_MSC_VER) && defined(USE_MS_CRYPTOAPI)
72# pragma comment(lib, "advapi32.lib")
75#if defined(_MSC_VER) && defined(USE_MS_CNGAPI)
76# pragma comment(lib, "bcrypt.lib")
87 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "NonblockingRng"; }
98 void GenerateBlock(
byte *output,
size_t size);
101#ifdef CRYPTOPP_WIN32_AVAILABLE
110#if defined(BLOCKING_RNG_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
121 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "BlockingRng"; }
132 void GenerateBlock(
byte *output,
size_t size);
158 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "AutoSeededRandomPool"; }
168 {Reseed(blocking, seedSize);}
173 void Reseed(
bool blocking =
false,
unsigned int seedSize = 32);
184template <
class BLOCK_CIPHER>
188 static std::string StaticAlgorithmName() {
return std::string(
"AutoSeededX917RNG(") + BLOCK_CIPHER::StaticAlgorithmName() + std::string(
")"); }
199 {
if (autoSeed)
Reseed(blocking);}
208 void Reseed(
bool blocking =
false,
const byte *additionalEntropy = NULLPTR,
size_t length = 0);
217 void Reseed(
const byte *key,
size_t keylength,
const byte *seed,
const byte *timeVector);
230template <
class BLOCK_CIPHER>
233 m_rng.reset(
new X917RNG(
new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector));
236template <
class BLOCK_CIPHER>
239 SecByteBlock seed(BLOCK_CIPHER::BLOCKSIZE + BLOCK_CIPHER::DEFAULT_KEYLENGTH);
247 hash.Update(seed, seed.
size());
248 hash.Update(input, length);
251 key = seed + BLOCK_CIPHER::BLOCKSIZE;
253 while (memcmp(key, seed,
STDMIN((
unsigned int)BLOCK_CIPHER::BLOCKSIZE, (
unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0);
255 Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, NULLPTR);
258template <
class BLOCK_CIPHER>
262 typename BLOCK_CIPHER::Encryption bc;
263 return bc.AlgorithmProvider();
268#if defined(CRYPTOPP_DOXYGEN_PROCESSING)
276#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
Class file for the AES cipher (Rijndael)
Automatically Seeded Randomness Pool.
AutoSeededRandomPool(bool blocking=false, unsigned int seedSize=32)
Construct an AutoSeededRandomPool.
Automatically Seeded X9.17 RNG.
bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
Generate random bytes into a BufferedTransformation.
AutoSeededX917RNG(bool blocking=false, bool autoSeed=true)
Construct an AutoSeededX917RNG.
void Reseed(bool blocking=false, const byte *additionalEntropy=NULL, size_t length=0)
Reseed an AutoSeededX917RNG.
Wrapper class for /dev/random and /dev/srandom.
A typedef providing a default generator.
Base class for all exceptions thrown by the library.
ProviderHandle GetProviderHandle() const
Retrieves the provider handle.
Wrapper class for /dev/random and /dev/srandom.
Ensures an object is not copyable.
Exception thrown when an operating system error is encountered.
Interface for random number generators.
virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
Generate random bytes into a BufferedTransformation.
Randomness Pool based on AES-256.
size_type size() const
Provides the count of elements in the SecBlock.
Pointer that overloads operator ->
Library configuration file.
Abstract base classes that provide a uniform interface to this library.
Classes and functions for the FIPS 140-2 validated library.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
Crypto++ library namespace.
void OS_GenerateRandomBlock(bool blocking, byte *output, size_t size)
OS_GenerateRandomBlock.
Class file for Randomness Pool.
Miscellaneous classes for RNGs.
Classes for SHA-1 and SHA-2 family of message digests.
Classes for automatic resource management.