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

ANSI X9.17 RNG. More...

#include <rng.h>

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

Public Member Functions

 X917RNG (BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector=0)
 Construct a X917RNG. More...
 
void GenerateIntoBufferedTransformation (BufferedTransformation &target, const std::string &channel, lword size)
 Generate random bytes into a BufferedTransformation. More...
 
- Public Member Functions inherited from RandomNumberGenerator
virtual ~RandomNumberGenerator ()
 
virtual void IncorporateEntropy (const byte *input, size_t length)
 Update RNG state with additional unpredictable values. More...
 
virtual bool CanIncorporateEntropy () const
 Determines if a generator can accept additional entropy. More...
 
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

member_ptr< BlockTransformationm_cipher
 
const unsigned int m_size
 
SecByteBlock m_datetime
 
SecByteBlock m_randseed
 
SecByteBlock m_lastBlock
 
SecByteBlock m_deterministicTimeVector
 

Detailed Description

ANSI X9.17 RNG.

X917RNG is from ANSI X9.17 Appendix C, and it uses a 64-bit block cipher, like TripleDES. If you use a 128-bit block cipher, like AES, then you are effectively using an ANSI X9.31 generator.

See also
AutoSeededX917RNG, DefaultAutoSeededRNG

Definition at line 48 of file rng.h.

Constructor & Destructor Documentation

X917RNG::X917RNG ( BlockTransformation cipher,
const byte seed,
const byte deterministicTimeVector = 0 
)

Construct a X917RNG.

Parameters
cipherthe block cipher to use for the generator
seeda byte buffer to use as a seed
deterministicTimeVectoradditional entropy

cipher will be deleted by the destructor. seed must be at least BlockSize() in length. deterministicTimeVector = 0 means obtain time vector from the system.

When constructing a X917RNG, the generator must be keyed or an access violation will occur because the time vector is encrypted using the block cipher. To key the generator during constructions, perform the following:

  SecByteBlock key(AES::DEFAULT_KEYLENGTH), seed(AES::BLOCKSIZE);
  OS_GenerateRandomBlock(false, key, key.size());
  OS_GenerateRandomBlock(false, seed, seed.size());
  X917RNG prng(new AES::Encryption(key, AES::DEFAULT_KEYLENGTH), seed, NULL);
See also
AutoSeededX917RNG

Definition at line 61 of file rng.cpp.

Here is the call graph for this function:

Member Function Documentation

void X917RNG::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 91 of file rng.cpp.

Here is the call graph for this function:

Member Data Documentation

member_ptr<BlockTransformation> X917RNG::m_cipher
private

Definition at line 72 of file rng.h.

SecByteBlock X917RNG::m_datetime
private

Definition at line 74 of file rng.h.

SecByteBlock X917RNG::m_deterministicTimeVector
private

Definition at line 75 of file rng.h.

SecByteBlock X917RNG::m_lastBlock
private

Definition at line 75 of file rng.h.

SecByteBlock X917RNG::m_randseed
private

Definition at line 75 of file rng.h.

const unsigned int X917RNG::m_size
private

Definition at line 73 of file rng.h.


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