6#ifndef CRYPTOPP_OSRNG_H
7#define CRYPTOPP_OSRNG_H
11#if !defined(NO_OS_DEPENDENCE) && defined(OS_RNG_AVAILABLE)
33#ifdef NONBLOCKING_RNG_AVAILABLE
35#ifdef CRYPTOPP_WIN32_AVAILABLE
46#if defined(USE_MS_CRYPTOAPI)
47# if defined(__CYGWIN__) && defined(__x86_64__)
48 typedef unsigned long long ProviderHandle;
49# elif defined(WIN64) || defined(_WIN64)
50 typedef unsigned __int64 ProviderHandle;
52 typedef unsigned long ProviderHandle;
54#elif defined(USE_MS_CNGAPI)
56 typedef PVOID ProviderHandle;
69 ProviderHandle m_hProvider;
72#if defined(CRYPTOPP_MSC_VERSION) && defined(USE_MS_CRYPTOAPI)
73# pragma comment(lib, "advapi32.lib")
76#if defined(CRYPTOPP_MSC_VERSION) && defined(USE_MS_CNGAPI)
77# pragma comment(lib, "bcrypt.lib")
88 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "NonblockingRng"; }
102#ifdef CRYPTOPP_WIN32_AVAILABLE
111#if defined(BLOCKING_RNG_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
122 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "BlockingRng"; }
161 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "AutoSeededRandomPool"; }
171 {Reseed(blocking, seedSize);}
176 void Reseed(
bool blocking =
false,
unsigned int seedSize = 32);
189template <
class BLOCK_CIPHER>
193 static std::string StaticAlgorithmName() {
194 return std::string(
"AutoSeededX917RNG(") + BLOCK_CIPHER::StaticAlgorithmName() + std::string(
")");
206 {
if (autoSeed)
Reseed(blocking);}
215 void Reseed(
bool blocking =
false,
const byte *input = NULLPTR,
size_t length = 0);
224 void Reseed(
const byte *key,
size_t keylength,
const byte *seed,
const byte *timeVector);
237template <
class BLOCK_CIPHER>
240 m_rng.reset(
new X917RNG(
new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector));
243template <
class BLOCK_CIPHER>
246 enum {BlockSize=BLOCK_CIPHER::BLOCKSIZE};
247 enum {KeyLength=BLOCK_CIPHER::DEFAULT_KEYLENGTH};
251 const byte label[] =
"X9.17 key generation";
252 const byte *key=NULLPTR;
266 key = seed + BlockSize;
268 while (std::memcmp(key, seed,
STDMIN((
size_t)BlockSize, (
size_t)KeyLength)) == 0);
270 Reseed(key, KeyLength, seed, NULLPTR);
273template <
class BLOCK_CIPHER>
277 typename BLOCK_CIPHER::Encryption bc;
278 return bc.AlgorithmProvider();
283#if defined(CRYPTOPP_DOXYGEN_PROCESSING)
293#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
Class file for the AES cipher (Rijndael)
Automatically Seeded Randomness Pool.
void Reseed(bool blocking=false, unsigned int seedSize=32)
Reseed an AutoSeededRandomPool.
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 Reseed(bool blocking=false, const byte *input=NULL, size_t length=0)
Reseed an AutoSeededX917RNG.
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.
Wrapper class for /dev/random and /dev/srandom.
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
BlockingRng()
Construct a BlockingRng.
A typedef providing a default generator.
Base class for all exceptions thrown by the library.
Extract-and-Expand Key Derivation Function (HKDF)
size_t DeriveKey(byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const NameValuePairs ¶ms) const
Derive a key from a seed.
MicrosoftCryptoProvider()
Construct a MicrosoftCryptoProvider.
ProviderHandle GetProviderHandle() const
Retrieves the provider handle.
Wrapper class for /dev/random and /dev/srandom.
NonblockingRng()
Construct a NonblockingRng.
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Ensures an object is not copyable.
Exception thrown when an operating system error is encountered.
OS_RNG_Err(const std::string &operation)
Constructs an OS_RNG_Err.
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.
#define CRYPTOPP_API
Win32 calling convention.
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Instantiate templates in a dynamic library.
word64 lword
Large word type.
Abstract base classes that provide a uniform interface to this library.
Classes and functions for the FIPS 140-2 validated library.
Classes for HKDF from RFC 5869.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define EnumToInt(v)
Integer value.
Crypto++ library namespace.
CRYPTOPP_DLL 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.