Botan::ANSI_X931_RNG Class Reference

#include <x931_rng.h>

Inheritance diagram for Botan::ANSI_X931_RNG:

Botan::RandomNumberGenerator

List of all members.

Public Member Functions

void add_entropy (const byte[], u32bit)
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 ()
void randomize (byte[], u32bit)
void reseed (u32bit 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:
cipher the block cipher to use in this PRNG
rng the 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().

00134    {
00135    if(!prng_in || !cipher_in)
00136       throw Invalid_Argument("ANSI_X931_RNG constructor: NULL arguments");
00137 
00138    cipher = cipher_in;
00139    prng = prng_in;
00140 
00141    R.resize(cipher->BLOCK_SIZE);
00142    position = 0;
00143    }

Botan::ANSI_X931_RNG::~ANSI_X931_RNG (  ) 

Definition at line 148 of file x931_rng.cpp.

00149    {
00150    delete cipher;
00151    delete prng;
00152    }


Member Function Documentation

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

Add entropy to this RNG.

Parameters:
in a byte array containg the entropy to be added
length the length of the byte array in

Implements Botan::RandomNumberGenerator.

Definition at line 94 of file x931_rng.cpp.

References Botan::RandomNumberGenerator::add_entropy().

00095    {
00096    prng->add_entropy(input, length);
00097    rekey();
00098    }

void Botan::ANSI_X931_RNG::add_entropy_source ( EntropySource source  )  [virtual]

Add this entropy source to the RNG object

Parameters:
source the 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().

00087    {
00088    prng->add_entropy_source(src);
00089    }

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::MemoryRegion< T >::clear(), Botan::RandomNumberGenerator::clear(), Botan::BlockCipher::clear(), and Botan::MemoryRegion< T >::destroy().

00112    {
00113    cipher->clear();
00114    prng->clear();
00115    R.clear();
00116    V.destroy();
00117 
00118    position = 0;
00119    }

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

00104    {
00105    return (V.size() > 0);
00106    }

RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng (  )  [static, inherited]

Create a seeded and active RNG object for general application use

Definition at line 29 of file rng.cpp.

00030    {
00031 #if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
00032    return new AutoSeeded_RNG;
00033 #endif
00034 
00035    throw Algorithm_Not_Found("RandomNumberGenerator::make_rng - no RNG found");
00036    }

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::SymmetricAlgorithm::name().

Referenced by randomize().

00125    {
00126    return "X9.31(" + cipher->name() + ")";
00127    }

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

00020    {
00021    byte out;
00022    this->randomize(&out, 1);
00023    return out;
00024    }

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

Randomize a byte array.

Parameters:
output the byte array to hold the random output.
length the 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().

00018    {
00019    if(!is_seeded())
00020       throw PRNG_Unseeded(name());
00021 
00022    while(length)
00023       {
00024       if(position == R.size())
00025          update_buffer();
00026 
00027       const u32bit copied = std::min(length, R.size() - position);
00028 
00029       copy_mem(out, R + position, copied);
00030       out += copied;
00031       length -= copied;
00032       position += copied;
00033       }
00034    }

void Botan::ANSI_X931_RNG::reseed ( u32bit  bits_to_collect  )  [virtual]

Seed this RNG using the entropy sources it contains.

Parameters:
bits_to_collect is 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().

00078    {
00079    prng->reseed(poll_bits);
00080    rekey();
00081    }


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

Generated on Tue Jun 29 08:56:41 2010 for Botan by  doxygen 1.5.8