diff options
author | Jack Lloyd <[email protected]> | 2017-08-04 12:01:08 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-08-04 12:01:08 -0400 |
commit | 58b1f7cc90b3e5c8a4bbff7adf2c001db0ef4d21 (patch) | |
tree | 27e2fcd7fd61c362218dd0c0948844a5c92a5ee2 /src/lib/rng/chacha_rng | |
parent | 8a29dc8209c6e93581075bbc4c39ff5bf0cdace5 (diff) | |
parent | 71d8bfac34acbab87a2319a8581b0aefbe762672 (diff) |
Complete merge of #1137 ChaCha_RNG
For whatever reason only the first commit in that branch got
merged to master. Not sure what happened.
Diffstat (limited to 'src/lib/rng/chacha_rng')
-rw-r--r-- | src/lib/rng/chacha_rng/chacha_rng.cpp | 32 | ||||
-rw-r--r-- | src/lib/rng/chacha_rng/chacha_rng.h | 2 |
2 files changed, 21 insertions, 13 deletions
diff --git a/src/lib/rng/chacha_rng/chacha_rng.cpp b/src/lib/rng/chacha_rng/chacha_rng.cpp index 86c71f9fe..ad8ee9ba8 100644 --- a/src/lib/rng/chacha_rng/chacha_rng.cpp +++ b/src/lib/rng/chacha_rng/chacha_rng.cpp @@ -68,28 +68,34 @@ void ChaCha_RNG::randomize(uint8_t output[], size_t output_len) void ChaCha_RNG::randomize_with_input(uint8_t output[], size_t output_len, const uint8_t input[], size_t input_len) { - add_entropy(input, input_len); reseed_check(); + if(input_len > 0) + { + update(input, input_len); + } + clear_mem(output, output_len); m_chacha->cipher1(output, output_len); } -void ChaCha_RNG::add_entropy(const uint8_t input[], size_t input_len) +void ChaCha_RNG::update(const uint8_t input[], size_t input_len) { - if(input_len > 0) - { - m_hmac->update(input, input_len); - m_chacha->set_key(m_hmac->final()); + m_hmac->update(input, input_len); + m_chacha->set_key(m_hmac->final()); + + secure_vector<uint8_t> mac_key(m_hmac->output_length()); + m_chacha->cipher1(mac_key.data(), mac_key.size()); + m_hmac->set_key(mac_key); + } - secure_vector<uint8_t> mac_key(m_hmac->output_length()); - m_chacha->cipher1(mac_key.data(), mac_key.size()); - m_hmac->set_key(mac_key); +void ChaCha_RNG::add_entropy(const uint8_t input[], size_t input_len) + { + update(input, input_len); - if(8*input_len >= security_level()) - { - m_reseed_counter = 1; - } + if(8*input_len >= security_level()) + { + reset_reseed_counter(); } } diff --git a/src/lib/rng/chacha_rng/chacha_rng.h b/src/lib/rng/chacha_rng/chacha_rng.h index b6a763f62..7deaa2d89 100644 --- a/src/lib/rng/chacha_rng/chacha_rng.h +++ b/src/lib/rng/chacha_rng/chacha_rng.h @@ -115,6 +115,8 @@ class BOTAN_DLL ChaCha_RNG final : public Stateful_RNG size_t security_level() const override; + size_t max_number_of_bytes_per_request() const override { return 0; } + private: void update(const uint8_t input[], size_t input_len); |