From ff26efb1c4b8530024dc9b42d75e39536ece6e11 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 12 Mar 2015 11:48:27 +0000 Subject: Externalize the state of a RFC 6979 nonce computation. This lets you amortize quite a few memory allocations (RNG, various BigInts, etc) over many nonce generations. Change generate_rfc6979_nonce to just instantiate one of these states, call the function once, and return. This doesn't have any additional overhead versus the previous implementation of this function. Fix HMAC_DRBG to correctly reset its state to its starting position when you call clear() on it. --- src/lib/rng/hmac_drbg/hmac_drbg.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib/rng/hmac_drbg/hmac_drbg.cpp') diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.cpp b/src/lib/rng/hmac_drbg/hmac_drbg.cpp index 064088c59..dc0d18afe 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.cpp +++ b/src/lib/rng/hmac_drbg/hmac_drbg.cpp @@ -1,6 +1,6 @@ /* * HMAC_DRBG -* (C) 2014 Jack Lloyd +* (C) 2014,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -17,7 +17,7 @@ HMAC_DRBG::HMAC_DRBG(MessageAuthenticationCode* mac, m_V(m_mac->output_length(), 0x01), m_reseed_counter(0) { - m_mac->set_key(secure_vector(m_mac->output_length(), 0x00)); + m_mac->set_key(std::vector(m_mac->output_length(), 0x00)); } void HMAC_DRBG::randomize(byte out[], size_t length) @@ -94,9 +94,11 @@ bool HMAC_DRBG::is_seeded() const void HMAC_DRBG::clear() { - zeroise(m_V); + m_reseed_counter = 0; + for(size_t i = 0; i != m_V.size(); ++i) + m_V[i] = 0x01; - m_mac->clear(); + m_mac->set_key(std::vector(m_mac->output_length(), 0x00)); if(m_prng) m_prng->clear(); -- cgit v1.2.3