Fabcoin Core  0.16.2
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
RandomPool Class Reference

Randomness Pool based on AES-256. More...

#include <randpool.h>

Inheritance diagram for RandomPool:
[legend]
Collaboration diagram for RandomPool:
[legend]

Public Member Functions

 RandomPool ()
 Construct a RandomPool. More...
 
bool CanIncorporateEntropy () const
 Determines if a generator can accept additional entropy. More...
 
void IncorporateEntropy (const byte *input, size_t length)
 Update RNG state with additional unpredictable values. More...
 
void GenerateIntoBufferedTransformation (BufferedTransformation &target, const std::string &channel, lword size)
 Generate random bytes into a BufferedTransformation. More...
 
void Put (const byte *input, size_t length)
 
- Public Member Functions inherited from RandomNumberGenerator
virtual ~RandomNumberGenerator ()
 
virtual byte GenerateByte ()
 Generate new random byte and return it. More...
 
virtual unsigned int GenerateBit ()
 Generate new random bit and return it. More...
 
virtual word32 GenerateWord32 (word32 min=0, word32 max=0xffffffffUL)
 Generate a random 32 bit word in the range min to max, inclusive. More...
 
virtual void GenerateBlock (byte *output, size_t size)
 Generate random array of bytes. More...
 
virtual void DiscardBytes (size_t n)
 Generate and discard n bytes. More...
 
template<class IT >
void Shuffle (IT begin, IT end)
 Randomly shuffle the specified array. More...
 
- Public Member Functions inherited from Algorithm
virtual ~Algorithm ()
 
 Algorithm (bool checkSelfTestStatus=true)
 Interface for all crypto algorithms. More...
 
virtual std::string AlgorithmName () const
 Provides the name of this algorithm. More...
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()
 
virtual ClonableClone () const
 Copies this object. More...
 
- Public Member Functions inherited from NotCopyable
 NotCopyable ()
 

Private Attributes

FixedSizeAlignedSecBlock< byte, 16, true > m_seed
 
FixedSizeAlignedSecBlock< byte, 32 > m_key
 
member_ptr< BlockCipherm_pCipher
 
bool m_keySet
 

Detailed Description

Randomness Pool based on AES-256.

RandomPool can be used to generate cryptographic quality pseudorandom bytes after seeding the pool with IncorporateEntropy(). Internally, the generator uses AES-256 to produce the stream. Entropy is stirred in using SHA-256.

RandomPool used to follow the design of randpool in PGP 2.6.x. At version 5.5 RandomPool was redesigned to reduce the risk of reusing random numbers after state rollback (which may occur when running in a virtual machine like VMware or a hosted environment).

Since
Crypto++ 4.0 (PGP 2.6.x style), Crypto++ 5.5 (AES-256 based)

Definition at line 49 of file randpool.h.

Constructor & Destructor Documentation

RandomPool::RandomPool ( )

Construct a RandomPool.

Definition at line 19 of file randpool.cpp.

Member Function Documentation

bool RandomPool::CanIncorporateEntropy ( ) const
inlinevirtual

Determines if a generator can accept additional entropy.

Returns
true if IncorporateEntropy() is implemented

Reimplemented from RandomNumberGenerator.

Definition at line 55 of file randpool.h.

void RandomPool::GenerateIntoBufferedTransformation ( BufferedTransformation target,
const std::string &  channel,
lword  length 
)
virtual

Generate random bytes into a BufferedTransformation.

Parameters
targetthe BufferedTransformation object which receives the bytes
channelthe channel on which the bytes should be pumped
lengththe number of bytes to generate

The default implementation calls GenerateBlock() and pumps the result into the DEFAULT_CHANNEL of the target.

All generated values are uniformly distributed over the range specified within the the constraints of a particular generator.

Note
A derived generator must override either GenerateBlock() or GenerateIntoBufferedTransformation(). They can override both, or have one call the other.

Reimplemented from RandomNumberGenerator.

Definition at line 35 of file randpool.cpp.

Here is the call graph for this function:

void RandomPool::IncorporateEntropy ( const byte input,
size_t  length 
)
virtual

Update RNG state with additional unpredictable values.

Parameters
inputthe entropy to add to the generator
lengththe size of the input buffer
Exceptions
NotImplemented

A generator may or may not accept additional entropy. Call CanIncorporateEntropy() to test for the ability to use additional entropy.

If a derived class does not override IncorporateEntropy(), then the base class throws NotImplemented.

Reimplemented from RandomNumberGenerator.

Definition at line 26 of file randpool.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void RandomPool::Put ( const byte input,
size_t  length 
)
inline

Definition at line 60 of file randpool.h.

Member Data Documentation

FixedSizeAlignedSecBlock<byte, 32> RandomPool::m_key
private

Definition at line 64 of file randpool.h.

bool RandomPool::m_keySet
private

Definition at line 66 of file randpool.h.

member_ptr<BlockCipher> RandomPool::m_pCipher
private

Definition at line 65 of file randpool.h.

FixedSizeAlignedSecBlock<byte, 16, true> RandomPool::m_seed
private

Definition at line 63 of file randpool.h.


The documentation for this class was generated from the following files: