Botan  1.11.20
Public Member Functions | Static Public Member Functions | List of all members
Botan::Null_RNG Class Reference

#include <rng.h>

Inheritance diagram for Botan::Null_RNG:

Public Member Functions

void add_entropy (const byte[], size_t) override
void clear () override
u64bit gen_mask (size_t bits)
template<typename T >
get_random ()
bool is_seeded () const override
std::string name () const override
byte next_byte ()
virtual secure_vector< byterandom_vec (size_t bytes)
void randomize (byte[], size_t) override
void reseed (size_t) override

Static Public Member Functions

static RandomNumberGeneratormake_rng ()

Detailed Description

Null/stub RNG - fails if you try to use it for anything

Definition at line 121 of file rng.h.

Member Function Documentation

void Botan::Null_RNG::add_entropy ( const byte  in[],
size_t  length 

Add entropy to this RNG.

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

Implements Botan::RandomNumberGenerator.

Definition at line 132 of file rng.h.

132 {}
void Botan::Null_RNG::clear ( )

Clear all internally held values of this RNG.

Implements Botan::RandomNumberGenerator.

Definition at line 126 of file rng.h.

126 {}
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
bool Botan::Null_RNG::is_seeded ( ) const

Check whether this RNG is seeded.

true if this RNG was already seeded, false otherwise.

Implements Botan::RandomNumberGenerator.

Definition at line 131 of file rng.h.

131 { return false; }
RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng ( )

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

Definition at line 14 of file rng.cpp.

References Botan::make_message_auth().

15  {
16  std::unique_ptr<MessageAuthenticationCode> h1(make_message_auth("HMAC(SHA-512)"));
17  std::unique_ptr<MessageAuthenticationCode> h2(h1->clone());
18  std::unique_ptr<RandomNumberGenerator> rng(new HMAC_RNG(h1.release(), h2.release()));
20  rng->reseed(256);
22  return rng.release();
23  }
std::unique_ptr< MessageAuthenticationCode > make_message_auth(const std::string &algo_spec, const std::string &provider)
Definition: lookup.cpp:71
std::string Botan::Null_RNG::name ( ) const

Return the name of this object

Implements Botan::RandomNumberGenerator.

Definition at line 128 of file rng.h.

128 { return "Null_RNG"; }
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>(); }
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
void Botan::Null_RNG::randomize ( byte  output[],
size_t  length 

Randomize a byte array.

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

Implements Botan::RandomNumberGenerator.

Definition at line 124 of file rng.h.

124 { throw PRNG_Unseeded("Null_RNG"); }
void Botan::Null_RNG::reseed ( size_t  bits_to_collect)

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

Implements Botan::RandomNumberGenerator.

Definition at line 130 of file rng.h.

130 {}

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