Crypto++ 8.9
Free C++ class library of cryptographic schemes
Public Member Functions | List of all members
X917RNG Class Reference

ANSI X9.17 RNG. More...

#include <rng.h>

+ Inheritance diagram for X917RNG:

Public Member Functions

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

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.

You should reseed the generator after a fork() to avoid multiple generators with the same internal state.

See also
AutoSeededX917RNG, DefaultAutoSeededRNG

Definition at line 49 of file rng.h.

Constructor & Destructor Documentation

◆ X917RNG()

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

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, NULLPTR);
See also
AutoSeededX917RNG

Member Function Documentation

◆ GenerateIntoBufferedTransformation()

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.


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