source: trunk/src-cryptopp/randpool.h

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 2.8 KB
Line 
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
37NAMESPACE_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)
49class CRYPTOPP_DLL RandomPool : public RandomNumberGenerator, public NotCopyable
50{
51public:
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
62private:
63        FixedSizeAlignedSecBlock<byte, 16, true> m_seed;
64        FixedSizeAlignedSecBlock<byte, 32> m_key;
65        member_ptr<BlockCipher> m_pCipher;
66        bool m_keySet;
67};
68
69NAMESPACE_END
70
71#endif
Note: See TracBrowser for help on using the repository browser.