Botan  1.10.9
Public Member Functions | Static Public Member Functions | List of all members
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

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.

References Botan::BlockCipher::block_size(), and Botan::MemoryRegion< T >::resize().

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  }
void resize(size_t n)
Definition: secmem.h:211
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
virtual size_t block_size() const =0
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

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.

References Botan::RandomNumberGenerator::add_entropy().

95  {
96  prng->add_entropy(input, length);
97  rekey();
98  }
virtual void add_entropy(const byte in[], size_t length)=0
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.

References Botan::RandomNumberGenerator::add_entropy_source().

87  {
88  prng->add_entropy_source(src);
89  }
virtual void add_entropy_source(EntropySource *source)=0
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.

References Botan::Algorithm::clear(), Botan::RandomNumberGenerator::clear(), Botan::MemoryRegion< T >::clear(), and Botan::zeroise().

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

References Botan::MemoryRegion< T >::size().

Referenced by randomize().

104  {
105  return (V.size() > 0);
106  }
size_t size() const
Definition: secmem.h:29
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  }
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.

References Botan::Algorithm::name().

Referenced by randomize().

125  {
126  return "X9.31(" + cipher->name() + ")";
127  }
virtual std::string name() const =0
byte Botan::RandomNumberGenerator::next_byte ( )
inherited

Return a random byte

Returns
random byte

Definition at line 19 of file rng.cpp.

References Botan::RandomNumberGenerator::randomize().

Referenced by Botan::random_prime().

20  {
21  byte out;
22  this->randomize(&out, 1);
23  return out;
24  }
virtual void randomize(byte output[], size_t length)=0
unsigned char byte
Definition: types.h:22
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.

References 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().

41  {
42  SecureVector<byte> output(bytes);
43  randomize(&output[0], output.size());
44  return output;
45  }
virtual void randomize(byte output[], size_t length)=0
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.

References Botan::copy_mem(), is_seeded(), name(), and Botan::MemoryRegion< T >::size().

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
size_t size() const
Definition: secmem.h:29
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:22
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.

References Botan::RandomNumberGenerator::reseed().

78  {
79  prng->reseed(poll_bits);
80  rekey();
81  }
virtual void reseed(size_t bits_to_collect)=0

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