Botan
1.11.15
|
#include <hmac_drbg.h>
Public Member Functions | |
void | add_entropy (const byte input[], size_t input_len) |
void | clear () |
HMAC_DRBG (MessageAuthenticationCode *mac, RandomNumberGenerator *underlying_rng) | |
bool | is_seeded () const |
std::string | name () const |
byte | next_byte () |
virtual secure_vector< byte > | random_vec (size_t bytes) |
void | randomize (byte buf[], size_t buf_len) |
void | reseed (size_t poll_bits) |
Static Public Member Functions | |
static RandomNumberGenerator * | make_rng () |
HMAC_DRBG (SP800-90A)
Definition at line 19 of file hmac_drbg.h.
Botan::HMAC_DRBG::HMAC_DRBG | ( | MessageAuthenticationCode * | mac, |
RandomNumberGenerator * | underlying_rng | ||
) |
mac | the underlying mac function (eg HMAC(SHA-512)) |
underlying_rng | RNG used generating inputs (eg HMAC_RNG) |
Definition at line 13 of file hmac_drbg.cpp.
: m_mac(mac), m_prng(prng), m_V(m_mac->output_length(), 0x01), m_reseed_counter(0) { m_mac->set_key(secure_vector<byte>(m_mac->output_length(), 0x00)); }
void Botan::HMAC_DRBG::add_entropy | ( | const byte | in[], |
size_t | length | ||
) | [virtual] |
Add entropy to this RNG.
in | a byte array containg the entropy to be added |
length | the length of the byte array in |
Implements Botan::RandomNumberGenerator.
Definition at line 84 of file hmac_drbg.cpp.
{ update(input, length); m_reseed_counter = 1; }
void Botan::HMAC_DRBG::clear | ( | ) | [virtual] |
Clear all internally held values of this RNG.
Implements Botan::RandomNumberGenerator.
Definition at line 95 of file hmac_drbg.cpp.
References Botan::zeroise().
{ zeroise(m_V); m_mac->clear(); if(m_prng) m_prng->clear(); }
bool Botan::HMAC_DRBG::is_seeded | ( | ) | const [virtual] |
Check whether this RNG is seeded.
Implements Botan::RandomNumberGenerator.
Definition at line 90 of file hmac_drbg.cpp.
Referenced by randomize().
{
return m_reseed_counter > 0;
}
RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng | ( | ) | [static, inherited] |
Create a seeded and active RNG object for general application use Added in 1.8.0
Definition at line 14 of file rng.cpp.
{ std::unique_ptr<RandomNumberGenerator> rng( new HMAC_RNG(make_a<MessageAuthenticationCode>("HMAC(SHA-512)"), make_a<MessageAuthenticationCode>("HMAC(SHA-256)")) ); rng->reseed(256); return rng.release(); }
std::string Botan::HMAC_DRBG::name | ( | ) | const [virtual] |
Return the name of this object
Implements Botan::RandomNumberGenerator.
Definition at line 105 of file hmac_drbg.cpp.
Referenced by randomize().
{ return "HMAC_DRBG(" + m_mac->name() + ")"; }
byte Botan::RandomNumberGenerator::next_byte | ( | ) | [inline, inherited] |
Return a random byte
Definition at line 53 of file rng.h.
Referenced by Botan::random_prime().
virtual secure_vector<byte> Botan::RandomNumberGenerator::random_vec | ( | size_t | bytes | ) | [inline, virtual, inherited] |
Return a random vector
bytes | number of bytes in the result |
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().
{ secure_vector<byte> output(bytes); randomize(&output[0], output.size()); return output; }
void Botan::HMAC_DRBG::randomize | ( | byte | output[], |
size_t | length | ||
) | [virtual] |
Randomize a byte array.
output | the byte array to hold the random output. |
length | the length of the byte array output. |
Implements Botan::RandomNumberGenerator.
Definition at line 23 of file hmac_drbg.cpp.
References Botan::copy_mem(), is_seeded(), name(), and reseed().
{ if(!is_seeded() || m_reseed_counter > BOTAN_RNG_MAX_OUTPUT_BEFORE_RESEED) reseed(m_mac->output_length() * 8); if(!is_seeded()) throw PRNG_Unseeded(name()); while(length) { const size_t to_copy = std::min(length, m_V.size()); m_V = m_mac->process(m_V); copy_mem(&out[0], &m_V[0], to_copy); length -= to_copy; out += to_copy; } m_reseed_counter += length; update(nullptr, 0); // additional_data is always empty }
void Botan::HMAC_DRBG::reseed | ( | size_t | bits_to_collect | ) | [virtual] |
Seed this RNG using the entropy sources it contains.
bits_to_collect | is the number of bits of entropy to attempt to gather from the entropy sources |
Implements Botan::RandomNumberGenerator.
Definition at line 69 of file hmac_drbg.cpp.
Referenced by randomize().
{ if(m_prng) { m_prng->reseed(poll_bits); if(m_prng->is_seeded()) { secure_vector<byte> input = m_prng->random_vec(m_mac->output_length()); update(&input[0], input.size()); m_reseed_counter = 1; } } }