Botan  1.11.30
Public Member Functions | Static Public Member Functions | List of all members
Botan::RandomNumberGenerator Class Referenceabstract

#include <rng.h>

Inheritance diagram for Botan::RandomNumberGenerator:
Botan::ANSI_X931_RNG Botan::AutoSeeded_RNG Botan::HMAC_DRBG Botan::HMAC_RNG Botan::Null_RNG Botan::Serialized_RNG Botan::System_RNG Botan::TPM_RNG

Public Member Functions

virtual void add_entropy (const byte in[], size_t length)=0
virtual void clear ()=0
template<typename T >
get_random ()
virtual bool is_seeded () const =0
virtual std::string name () const =0
byte next_byte ()
byte next_nonzero_byte ()
RandomNumberGeneratoroperator= (const RandomNumberGenerator &rng)=delete
virtual secure_vector< byterandom_vec (size_t bytes)
virtual void randomize (byte output[], size_t length)=0
 RandomNumberGenerator (const RandomNumberGenerator &rng)=delete
 RandomNumberGenerator ()
size_t reseed (size_t bits_to_collect)
virtual size_t reseed_with_sources (Entropy_Sources &srcs, size_t poll_bits, std::chrono::milliseconds poll_timeout)=0
size_t reseed_with_timeout (size_t bits_to_collect, std::chrono::milliseconds poll_timeout)
virtual ~RandomNumberGenerator ()

Static Public Member Functions

static RandomNumberGeneratormake_rng ()

Detailed Description

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

Definition at line 24 of file rng.h.

Constructor & Destructor Documentation

Botan::RandomNumberGenerator::RandomNumberGenerator ( const RandomNumberGenerator rng)
Botan::RandomNumberGenerator::RandomNumberGenerator ( )

Definition at line 131 of file rng.h.

131 {}
virtual Botan::RandomNumberGenerator::~RandomNumberGenerator ( )

Definition at line 132 of file rng.h.

132 {}

Member Function Documentation

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

Add entropy to this RNG.

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

Implemented in Botan::Serialized_RNG, Botan::Null_RNG, Botan::TPM_RNG, Botan::System_RNG, Botan::HMAC_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_DRBG, and Botan::ANSI_X931_RNG.

Referenced by Botan::NR_PrivateKey::check_key().

virtual void Botan::RandomNumberGenerator::clear ( )
pure virtual
template<typename T >
T Botan::RandomNumberGenerator::get_random ( )

Only usable with POD types, only useful with integers get_random<u64bit>()

Definition at line 56 of file rng.h.

57  {
58  T r;
59  this->randomize(reinterpret_cast<byte*>(&r), sizeof(r));
60  return r;
61  }
virtual void randomize(byte output[], size_t length)=0
virtual bool Botan::RandomNumberGenerator::is_seeded ( ) const
pure virtual

Check whether this RNG is seeded.

true if this RNG was already seeded, false otherwise.

Implemented in Botan::Serialized_RNG, Botan::Null_RNG, Botan::TPM_RNG, Botan::System_RNG, Botan::HMAC_RNG, Botan::HMAC_DRBG, Botan::ANSI_X931_RNG, and Botan::AutoSeeded_RNG.

RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng ( )

Create a seeded and active RNG object for general application use Added in 1.8.0

Definition at line 28 of file rng.cpp.

References Botan::MessageAuthenticationCode::create().

29  {
30  std::unique_ptr<MessageAuthenticationCode> h1(MessageAuthenticationCode::create("HMAC(SHA-512)"));
31  std::unique_ptr<MessageAuthenticationCode> h2(MessageAuthenticationCode::create("HMAC(SHA-512)"));
33  if(!h1 || !h2)
34  throw Algorithm_Not_Found("HMAC_RNG HMACs");
35  std::unique_ptr<RandomNumberGenerator> rng(new HMAC_RNG(h1.release(), h2.release()));
37  rng->reseed(256);
39  return rng.release();
40  }
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:38
virtual std::string Botan::RandomNumberGenerator::name ( ) const
pure virtual
byte Botan::RandomNumberGenerator::next_byte ( )

Return a random byte

random byte

Definition at line 67 of file rng.h.

Referenced by Botan::Blinded_Point_Multiply::blinded_multiply(), and Botan::random_prime().

67 { return get_random<byte>(); }
byte Botan::RandomNumberGenerator::next_nonzero_byte ( )

Definition at line 69 of file rng.h.

70  {
71  byte b = next_byte();
72  while(b == 0)
73  b = next_byte();
74  return b;
75  }
std::uint8_t byte
Definition: types.h:31
RandomNumberGenerator& Botan::RandomNumberGenerator::operator= ( const RandomNumberGenerator rng)
virtual secure_vector<byte> Botan::RandomNumberGenerator::random_vec ( size_t  bytes)
virtual void Botan::RandomNumberGenerator::randomize ( byte  output[],
size_t  length 
pure virtual
size_t Botan::RandomNumberGenerator::reseed ( size_t  bits_to_collect)

Seed this RNG using the global entropy sources and default timeout

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

Definition at line 14 of file rng.cpp.

References reseed_with_timeout().

Referenced by botan_rng_reseed(), Botan::ANSI_X931_RNG::randomize(), Botan::HMAC_DRBG::randomize(), and Botan::HMAC_RNG::randomize().

15  {
16  return this->reseed_with_timeout(bits_to_collect,
18  }
size_t reseed_with_timeout(size_t bits_to_collect, std::chrono::milliseconds poll_timeout)
Definition: rng.cpp:20
virtual size_t Botan::RandomNumberGenerator::reseed_with_sources ( Entropy_Sources srcs,
size_t  poll_bits,
std::chrono::milliseconds  poll_timeout 
pure virtual

Poll provided sources for up to poll_bits bits of entropy or until the timeout expires. Returns estimate of the number of bits collected.

Implemented in Botan::Serialized_RNG, Botan::Null_RNG, Botan::TPM_RNG, Botan::System_RNG, Botan::HMAC_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_DRBG, and Botan::ANSI_X931_RNG.

Referenced by reseed_with_timeout().

size_t Botan::RandomNumberGenerator::reseed_with_timeout ( size_t  bits_to_collect,
std::chrono::milliseconds  poll_timeout 

Seed this RNG using the global entropy sources

bits_to_collectis the number of bits of entropy to attempt to gather from the entropy sources
poll_timeouttry not to run longer than this, no matter what

Definition at line 20 of file rng.cpp.

References Botan::Entropy_Sources::global_sources(), and reseed_with_sources().

Referenced by reseed().

22  {
24  bits_to_collect,
25  timeout);
26  }
virtual size_t reseed_with_sources(Entropy_Sources &srcs, size_t poll_bits, std::chrono::milliseconds poll_timeout)=0
static Entropy_Sources & global_sources()

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