Botan  1.11.21
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

Public Member Functions

virtual void add_entropy (const byte in[], size_t length)=0
virtual void clear ()=0
u64bit gen_mask (size_t bits)
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 ()
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 21 of file rng.h.

Constructor & Destructor Documentation

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

Definition at line 122 of file rng.h.

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

Definition at line 123 of file rng.h.

123 {}

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::System_RNG, Botan::HMAC_RNG, Botan::AutoSeeded_RNG, Botan::HMAC_DRBG, and Botan::ANSI_X931_RNG.

virtual void Botan::RandomNumberGenerator::clear ( )
pure virtual
u64bit Botan::RandomNumberGenerator::gen_mask ( size_t  bits)

Return a value in range [0,2^bits)

Definition at line 63 of file rng.h.

64  {
65  if(bits == 0 || bits > 64)
66  throw std::invalid_argument("RandomNumberGenerator::gen_mask invalid argument");
68  const u64bit mask = ((1 << bits) - 1);
69  return this->get_random<u64bit>() & mask;
70  }
std::uint64_t u64bit
Definition: types.h:34
template<typename T >
T Botan::RandomNumberGenerator::get_random ( )

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

Definition at line 53 of file rng.h.

54  {
55  T r;
56  this->randomize(reinterpret_cast<byte*>(&r), sizeof(r));
57  return r;
58  }
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::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 13 of file rng.cpp.

References Botan::MessageAuthenticationCode::create().

14  {
15  std::unique_ptr<MessageAuthenticationCode> h1(MessageAuthenticationCode::create("HMAC(SHA-512)"));
16  std::unique_ptr<MessageAuthenticationCode> h2(MessageAuthenticationCode::create("HMAC(SHA-512)"));
18  if(!h1 || !h2)
19  throw Algorithm_Not_Found("HMAC_RNG HMACs");
20  std::unique_ptr<RandomNumberGenerator> rng(new HMAC_RNG(h1.release(), h2.release()));
22  rng->reseed(256);
24  return rng.release();
25  }
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 76 of file rng.h.

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

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

Definition at line 78 of file rng.h.

79  {
80  byte b = next_byte();
81  while(b == 0)
82  b = next_byte();
83  return b;
84  }
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)

Return a random vector

bytesnumber of bytes in the result
randomized vector of length bytes

Definition at line 42 of file rng.h.

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::TLS::Session::encrypt(), Botan::KeyPair::encryption_consistency_check(), Botan::generate_bcrypt(), Botan::mceies_encrypt(), Botan::OctetString::OctetString(), Botan::pbes2_encrypt(), Botan::BigInt::randomize(), Botan::TLS::Session_Manager_SQL::Session_Manager_SQL(), and Botan::KeyPair::signature_consistency_check().

43  {
44  secure_vector<byte> output(bytes);
45  randomize(, output.size());
46  return output;
47  }
virtual void randomize(byte output[], size_t length)=0
virtual void Botan::RandomNumberGenerator::randomize ( byte  output[],
size_t  length 
pure virtual
virtual void Botan::RandomNumberGenerator::reseed ( size_t  bits_to_collect)
pure virtual

Seed this RNG using the entropy sources it contains.

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

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

Referenced by botan_rng_reseed().

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