Crypto++  5.6.5
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 //! \details RandomPool can be used to generate cryptographic quality pseudorandom bytes
6 //! after seeding the pool with IncorporateEntropy(). Internally, the generator uses
7 //! AES-256 to produce the stream. Entropy is stirred in using SHA-256.
8 //! \details RandomPool used to follow the design of randpool in PGP 2.6.x. At version 5.5
9 //! RandomPool was redesigned to reduce the risk of reusing random numbers after state
10 //! rollback (which may occur when running in a virtual machine like VMware or a hosted
11 //! environment).
12 //! \details If you need the pre-Crypto++ 5.5 generator then you can find it with:
13 //! <pre>
14 //! $ git clone https://github.com/weidai11/cryptopp cryptopp-ancient
15 //! $ cryptopp-ancient
16 //!
17 //! # Checkout the RandomPool change
18 //! $ git checkout f41245df6fb9b85574260eca9cd32777e8ab5136
19 //!
20 //! # Go back one more
21 //! git checkout HEAD~1
22 //!
23 //! $ grep 'MDC<SHA>' *.h *.cpp
24 //! randpool.cpp:typedef MDC<SHA> RandomPoolCipher;
25 //! </pre>
26 //! \since Crypto++ 4.0 (PGP 2.6.x style), Crypto++ 5.5 (AES-256 based)
27 
28 #ifndef CRYPTOPP_RANDPOOL_H
29 #define CRYPTOPP_RANDPOOL_H
30 
31 #include "cryptlib.h"
32 #include "filters.h"
33 #include "secblock.h"
34 #include "smartptr.h"
35 #include "aes.h"
36 
37 NAMESPACE_BEGIN(CryptoPP)
38 
39 //! \class RandomPool
40 //! \brief Randomness Pool based on AES-256
41 //! \details RandomPool can be used to generate cryptographic quality pseudorandom bytes
42 //! after seeding the pool with IncorporateEntropy(). Internally, the generator uses
43 //! AES-256 to produce the stream. Entropy is stirred in using SHA-256.
44 //! \details RandomPool used to follow the design of randpool in PGP 2.6.x. At version 5.5
45 //! RandomPool was redesigned to reduce the risk of reusing random numbers after state
46 //! rollback (which may occur when running in a virtual machine like VMware or a hosted
47 //! environment).
48 //! \since Crypto++ 4.0 (PGP 2.6.x style), Crypto++ 5.5 (AES-256 based)
49 class CRYPTOPP_DLL RandomPool : public RandomNumberGenerator, public NotCopyable
50 {
51 public:
52  //! \brief Construct a RandomPool
53  RandomPool();
54 
55  bool CanIncorporateEntropy() const {return true;}
56  void IncorporateEntropy(const byte *input, size_t length);
57  void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size);
58 
59  // for backwards compatibility. use RandomNumberSource, RandomNumberStore, and RandomNumberSink for other BufferTransformation functionality
60  void Put(const byte *input, size_t length) {IncorporateEntropy(input, length);}
61 
62 private:
65  member_ptr<BlockCipher> m_pCipher;
66  bool m_keySet;
67 };
68 
69 NAMESPACE_END
70 
71 #endif
Randomness Pool based on AES-256.
Definition: randpool.h:49
bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
Definition: randpool.h:55
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
Interface for random number generators.
Definition: cryptlib.h:1188
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:217