Botan 1.10.17
Botan::ANSI_X931_RNG Class Reference

#include <x931_rng.h>

Inheritance diagram for Botan::ANSI_X931_RNG:
Botan::RandomNumberGenerator

Public Member Functions

void add_entropy (const byte[], size_t)
void add_entropy_source (EntropySource *)
 ANSI_X931_RNG (BlockCipher *cipher, RandomNumberGenerator *rng)
void clear ()
bool is_seeded () const
std::string name () const
byte next_byte ()
SecureVector< byterandom_vec (size_t bytes)
void randomize (byte[], size_t)
void reseed (size_t poll_bits)
 ~ANSI_X931_RNG ()

Static Public Member Functions

static RandomNumberGeneratormake_rng ()

Detailed Description

ANSI X9.31 RNG

Definition at line 19 of file x931_rng.h.

Constructor & Destructor Documentation

◆ ANSI_X931_RNG()

Botan::ANSI_X931_RNG::ANSI_X931_RNG ( BlockCipher * cipher,
RandomNumberGenerator * rng )
Parameters
cipherthe block cipher to use in this PRNG
rngthe underlying PRNG for generating inputs (eg, an HMAC_RNG)

Definition at line 132 of file x931_rng.cpp.

134 {
135 if(!prng_in || !cipher_in)
136 throw Invalid_Argument("ANSI_X931_RNG constructor: NULL arguments");
137
138 cipher = cipher_in;
139 prng = prng_in;
140
141 R.resize(cipher->block_size());
142 position = 0;
143 }
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References Botan::RandomNumberGenerator::RandomNumberGenerator().

◆ ~ANSI_X931_RNG()

Botan::ANSI_X931_RNG::~ANSI_X931_RNG ( )

Definition at line 148 of file x931_rng.cpp.

149 {
150 delete cipher;
151 delete prng;
152 }

Member Function Documentation

◆ add_entropy()

void Botan::ANSI_X931_RNG::add_entropy ( const byte in[],
size_t length )
virtual

Add entropy to this RNG.

Parameters
ina byte array containg the entropy to be added
lengththe length of the byte array in

Implements Botan::RandomNumberGenerator.

Definition at line 94 of file x931_rng.cpp.

95 {
96 prng->add_entropy(input, length);
97 rekey();
98 }

◆ add_entropy_source()

void Botan::ANSI_X931_RNG::add_entropy_source ( EntropySource * source)
virtual

Add this entropy source to the RNG object

Parameters
sourcethe entropy source which will be retained and used by RNG

Implements Botan::RandomNumberGenerator.

Definition at line 86 of file x931_rng.cpp.

87 {
88 prng->add_entropy_source(src);
89 }

◆ clear()

void Botan::ANSI_X931_RNG::clear ( )
virtual

Clear all internally held values of this RNG.

Implements Botan::RandomNumberGenerator.

Definition at line 111 of file x931_rng.cpp.

112 {
113 cipher->clear();
114 prng->clear();
115 zeroise(R);
116 V.clear();
117
118 position = 0;
119 }
void zeroise(MemoryRegion< T > &vec)
Definition secmem.h:428

References Botan::zeroise().

◆ is_seeded()

bool Botan::ANSI_X931_RNG::is_seeded ( ) const
virtual

Check whether this RNG is seeded.

Returns
true if this RNG was already seeded, false otherwise.

Reimplemented from Botan::RandomNumberGenerator.

Definition at line 103 of file x931_rng.cpp.

104 {
105 return (V.size() > 0);
106 }

Referenced by randomize().

◆ make_rng()

RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng ( )
staticinherited

Create a seeded and active RNG object for general application use

Definition at line 29 of file rng.cpp.

30 {
31#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
32 return new AutoSeeded_RNG;
33#endif
34
35 throw Algorithm_Not_Found("RandomNumberGenerator::make_rng - no RNG found");
36 }
Algorithm_Not_Found(const std::string &name)
Definition exceptn.h:111

References Botan::Algorithm_Not_Found::Algorithm_Not_Found(), and RandomNumberGenerator().

◆ name()

std::string Botan::ANSI_X931_RNG::name ( ) const
virtual

Return the name of this object

Implements Botan::RandomNumberGenerator.

Definition at line 124 of file x931_rng.cpp.

125 {
126 return "X9.31(" + cipher->name() + ")";
127 }

Referenced by randomize().

◆ next_byte()

byte Botan::RandomNumberGenerator::next_byte ( )
inherited

Return a random byte

Returns
random byte

Definition at line 19 of file rng.cpp.

20 {
21 byte out;
22 this->randomize(&out, 1);
23 return out;
24 }
virtual void randomize(byte output[], size_t length)=0

References randomize().

Referenced by Botan::random_prime().

◆ random_vec()

SecureVector< byte > Botan::RandomNumberGenerator::random_vec ( size_t bytes)
inlineinherited

Return a random vector

Parameters
bytesnumber of bytes in the result
Returns
randomized vector of length bytes

Definition at line 40 of file rng.h.

41 {
42 SecureVector<byte> output(bytes);
43 randomize(&output[0], output.size());
44 return output;
45 }

References randomize(), and Botan::MemoryRegion< T >::size().

Referenced by Botan::Client_Hello::Client_Hello(), Botan::Client_Key_Exchange::Client_Key_Exchange(), Botan::KeyPair::encryption_consistency_check(), Botan::generate_bcrypt(), Botan::generate_dsa_primes(), Botan::OctetString::OctetString(), Botan::Client_Key_Exchange::pre_master_secret(), Botan::BigInt::randomize(), Botan::Server_Hello::Server_Hello(), and Botan::KeyPair::signature_consistency_check().

◆ randomize()

void Botan::ANSI_X931_RNG::randomize ( byte output[],
size_t length )
virtual

Randomize a byte array.

Parameters
outputthe byte array to hold the random output.
lengththe length of the byte array output.

Implements Botan::RandomNumberGenerator.

Definition at line 17 of file x931_rng.cpp.

18 {
19 if(!is_seeded())
20 throw PRNG_Unseeded(name());
21
22 while(length)
23 {
24 if(position == R.size())
25 update_buffer();
26
27 const size_t copied = std::min<size_t>(length, R.size() - position);
28
29 copy_mem(out, &R[position], copied);
30 out += copied;
31 length -= copied;
32 position += copied;
33 }
34 }
bool is_seeded() const
Definition x931_rng.cpp:103
std::string name() const
Definition x931_rng.cpp:124
void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:22
PRNG_Unseeded(const std::string &algo)
Definition exceptn.h:91

References Botan::copy_mem(), is_seeded(), name(), and Botan::PRNG_Unseeded::PRNG_Unseeded().

◆ reseed()

void Botan::ANSI_X931_RNG::reseed ( size_t bits_to_collect)
virtual

Seed this RNG using the entropy sources it contains.

Parameters
bits_to_collectis the number of bits of entropy to attempt to gather from the entropy sources

Implements Botan::RandomNumberGenerator.

Definition at line 77 of file x931_rng.cpp.

78 {
79 prng->reseed(poll_bits);
80 rekey();
81 }

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