From 6b043baa4f421e9d00272f3e0d93b7e40cac6b77 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 22 Mar 2014 14:16:19 +0000 Subject: Add RFC 6979 nonce generator. Also some HMAC_DRBG cleanups. --- src/lib/rng/hmac_drbg/hmac_drbg.cpp | 25 +++++++++++++++---------- src/lib/rng/hmac_drbg/hmac_drbg.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/lib/rng/hmac_drbg') diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.cpp b/src/lib/rng/hmac_drbg/hmac_drbg.cpp index 3227841f0..96bd791ee 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.cpp +++ b/src/lib/rng/hmac_drbg/hmac_drbg.cpp @@ -66,20 +66,23 @@ void HMAC_DRBG::update(const byte input[], size_t input_len) void HMAC_DRBG::reseed(size_t poll_bits) { - m_prng->reseed(poll_bits); - - if(m_prng->is_seeded()) + if(m_prng) { - secure_vector input = m_prng->random_vec(m_mac->output_length()); - update(&input[0], input.size()); - m_reseed_counter = 1; + m_prng->reseed(poll_bits); + + if(m_prng->is_seeded()) + { + secure_vector input = m_prng->random_vec(m_mac->output_length()); + update(&input[0], input.size()); + m_reseed_counter = 1; + } } } void HMAC_DRBG::add_entropy(const byte input[], size_t length) { - // Should we also poll the underlying PRNG here? update(input, length); + m_reseed_counter = 1; } bool HMAC_DRBG::is_seeded() const @@ -89,10 +92,12 @@ bool HMAC_DRBG::is_seeded() const void HMAC_DRBG::clear() { - m_mac->clear(); - m_prng->clear(); zeroise(m_V); - zeroise(m_K); + + m_mac->clear(); + + if(m_prng) + m_prng->clear(); } std::string HMAC_DRBG::name() const diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.h b/src/lib/rng/hmac_drbg/hmac_drbg.h index 43729c7fa..c3629aa15 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.h +++ b/src/lib/rng/hmac_drbg/hmac_drbg.h @@ -41,7 +41,7 @@ class BOTAN_DLL HMAC_DRBG : public RandomNumberGenerator std::unique_ptr m_mac; std::unique_ptr m_prng; - secure_vector m_K, m_V; + secure_vector m_V; size_t m_reseed_counter; }; -- cgit v1.2.3