Crypto++  5.6.3
Free C++ class library of cryptographic schemes
randpool.h
Go to the documentation of this file.
1 // randpool.h - written and placed in the public domain by Wei Dai
2 
3 //! \file randpool.h
4 //! \brief Class file for Randomness Pool
5 
6 #ifndef CRYPTOPP_RANDPOOL_H
7 #define CRYPTOPP_RANDPOOL_H
8 
9 #include "cryptlib.h"
10 #include "filters.h"
11 #include "secblock.h"
12 #include "smartptr.h"
13 #include "aes.h"
14 
15 NAMESPACE_BEGIN(CryptoPP)
16 
17 //! \brief Randomness Pool
18 //! \details RandomPool can be used to generate cryptographic quality pseudorandom bytes
19 //! after seeding the pool with IncorporateEntropy(). Internally, the generator uses
20 //! AES-256 to produce the stream. Entropy is stirred in using SHA-256.
21 //! \details RandomPool used to follow the design of randpool in PGP 2.6.x,
22 //! but as of version 5.5 it has been redesigned to reduce the risk
23 //! of reusing random numbers after state rollback (which may occur
24 //! when running in a virtual machine like VMware).
25 class CRYPTOPP_DLL RandomPool : public RandomNumberGenerator, public NotCopyable
26 {
27 public:
28  //! \brief Construct a RandomPool
29  RandomPool();
30 
31  bool CanIncorporateEntropy() const {return true;}
32  void IncorporateEntropy(const byte *input, size_t length);
33  void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size);
34 
35  // for backwards compatibility. use RandomNumberSource, RandomNumberStore, and RandomNumberSink for other BufferTransformation functionality
36  void Put(const byte *input, size_t length) {IncorporateEntropy(input, length);}
37 
38 private:
41  member_ptr<BlockCipher> m_pCipher;
42  bool m_keySet;
43 };
44 
45 NAMESPACE_END
46 
47 #endif
Randomness Pool.
Definition: randpool.h:25
bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
Definition: randpool.h:31
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
Interface for random number generators.
Definition: cryptlib.h:1186
Interface for buffered transformations.
Definition: cryptlib.h:1352
Classes and functions for secure memory allocations.
Class file for the AES cipher (Rijndael)
Implementation of BufferedTransformation's attachment interface.
Crypto++ library namespace.
Ensures an object is not copyable.
Definition: misc.h:189