|
Security Scol plugin
|
ANSI X9.17 RNG. More...
#include <rng.h>
Public Member Functions | |
| X917RNG (BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector=NULLPTR) | |
| 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 Clonable * | Clone () const |
| Copies this object. | |
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.
| X917RNG::X917RNG | ( | BlockTransformation * | cipher, |
| const byte * | seed, | ||
| const byte * | deterministicTimeVector = NULLPTR |
||
| ) |
Construct a X917RNG.
| cipher | the block cipher to use for the generator |
| seed | a byte buffer to use as a seed |
| deterministicTimeVector | additional 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);
|
virtual |
Generate random bytes into a BufferedTransformation.
| target | the BufferedTransformation object which receives the bytes |
| channel | the channel on which the bytes should be pumped |
| length | the 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.
Reimplemented from RandomNumberGenerator.