Botan  1.11.15
Public Member Functions | Static Public Member Functions
Botan::HMAC_DRBG Class Reference

#include <hmac_drbg.h>

Inheritance diagram for Botan::HMAC_DRBG:
Botan::RandomNumberGenerator

List of all members.

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< byterandom_vec (size_t bytes)
void randomize (byte buf[], size_t buf_len)
void reseed (size_t poll_bits)

Static Public Member Functions

static RandomNumberGeneratormake_rng ()

Detailed Description

HMAC_DRBG (SP800-90A)

Definition at line 19 of file hmac_drbg.h.


Constructor & Destructor Documentation

Parameters:
macthe underlying mac function (eg HMAC(SHA-512))
underlying_rngRNG 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));
   }

Member Function Documentation

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

Add entropy to this RNG.

Parameters:
ina byte array containg the entropy to be added
lengththe 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.

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

Implements Botan::RandomNumberGenerator.

Definition at line 90 of file hmac_drbg.cpp.

Referenced by randomize().

   {
   return m_reseed_counter > 0;
   }

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() + ")";
   }

Return a random byte

Returns:
random byte

Definition at line 53 of file rng.h.

Referenced by Botan::random_prime().

         {
         byte out;
         this->randomize(&out, 1);
         return out;
         }
virtual secure_vector<byte> Botan::RandomNumberGenerator::random_vec ( size_t  bytes) [inline, virtual, inherited]
void Botan::HMAC_DRBG::randomize ( byte  output[],
size_t  length 
) [virtual]

Randomize a byte array.

Parameters:
outputthe byte array to hold the random output.
lengththe 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.

Parameters:
bits_to_collectis 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;
         }
      }
   }

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