Botan 1.10.17
Botan::RandomNumberGenerator Class Referenceabstract

#include <rng.h>

Inheritance diagram for Botan::RandomNumberGenerator:
Botan::ANSI_X931_RNG Botan::AutoSeeded_RNG Botan::HMAC_RNG Botan::Null_RNG Botan::Randpool

Public Member Functions

virtual void add_entropy (const byte in[], size_t length)=0
virtual void add_entropy_source (EntropySource *source)=0
virtual void clear ()=0
virtual bool is_seeded () const
virtual std::string name () const =0
byte next_byte ()
SecureVector< byterandom_vec (size_t bytes)
virtual void randomize (byte output[], size_t length)=0
 RandomNumberGenerator ()
virtual void reseed (size_t bits_to_collect)=0
virtual ~RandomNumberGenerator ()

Static Public Member Functions

static RandomNumberGeneratormake_rng ()

Detailed Description

This class represents a random number (RNG) generator object.

Definition at line 20 of file rng.h.

Constructor & Destructor Documentation

◆ RandomNumberGenerator()

Botan::RandomNumberGenerator::RandomNumberGenerator ( )
inline

Definition at line 89 of file rng.h.

89{}

Referenced by Botan::ANSI_X931_RNG::ANSI_X931_RNG(), and make_rng().

◆ ~RandomNumberGenerator()

virtual Botan::RandomNumberGenerator::~RandomNumberGenerator ( )
inlinevirtual

Definition at line 90 of file rng.h.

90{}

Member Function Documentation

◆ add_entropy()

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

Add entropy to this RNG.

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

Implemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.

Referenced by Botan::DSA_Signature_Operation::sign(), Botan::ECDSA_Signature_Operation::sign(), and Botan::NR_Signature_Operation::sign().

◆ add_entropy_source()

virtual void Botan::RandomNumberGenerator::add_entropy_source ( EntropySource * source)
pure virtual

Add this entropy source to the RNG object

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

Implemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.

◆ clear()

virtual void Botan::RandomNumberGenerator::clear ( )
pure virtual

Clear all internally held values of this RNG.

Implemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.

◆ is_seeded()

virtual bool Botan::RandomNumberGenerator::is_seeded ( ) const
inlinevirtual

Check whether this RNG is seeded.

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

Reimplemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.

Definition at line 57 of file rng.h.

57{ return true; }

◆ make_rng()

RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng ( )
static

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

virtual std::string Botan::RandomNumberGenerator::name ( ) const
pure virtual

Return the name of this object

Implemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.

◆ next_byte()

byte Botan::RandomNumberGenerator::next_byte ( )

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)
inline

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

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

Randomize a byte array.

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

Implemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.

Referenced by Botan::algorithm_benchmark(), Botan::CryptoBox::encrypt(), Botan::generate_passhash9(), next_byte(), random_vec(), and Botan::RTSS_Share::split().

◆ reseed()

virtual void Botan::RandomNumberGenerator::reseed ( size_t bits_to_collect)
pure 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

Implemented in Botan::ANSI_X931_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_RNG, Botan::Null_RNG, and Botan::Randpool.


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