diff options
author | lloyd <[email protected]> | 2015-03-18 10:10:09 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-03-18 10:10:09 +0000 |
commit | 1c5c28f2e8a605c0429bacd49fc8cacbbb50377a (patch) | |
tree | cd955920104c7d1d3db0cd56af7d350a04124de9 /src/lib/entropy/entropy_src.h | |
parent | 827080864508e03d796c5138b34d563977d693bb (diff) |
Remove the shared IO buffer from EntropySource_Accumulator.
Instead each source that needs a buffer maintains their own.
Diffstat (limited to 'src/lib/entropy/entropy_src.h')
-rw-r--r-- | src/lib/entropy/entropy_src.h | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/lib/entropy/entropy_src.h b/src/lib/entropy/entropy_src.h index 2bd7d42e5..c635b8756 100644 --- a/src/lib/entropy/entropy_src.h +++ b/src/lib/entropy/entropy_src.h @@ -1,12 +1,12 @@ /* * EntropySource -* (C) 2008-2009,2014 Jack Lloyd +* (C) 2008,2009,2014,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ -#ifndef BOTAN_ENTROPY_SOURCE_BASE_H__ -#define BOTAN_ENTROPY_SOURCE_BASE_H__ +#ifndef BOTAN_ENTROPY_H__ +#define BOTAN_ENTROPY_H__ #include <botan/secmem.h> #include <string> @@ -22,32 +22,26 @@ class BOTAN_DLL Entropy_Accumulator public: /** * Initialize an Entropy_Accumulator - * @param goal is how many bits we would like to collect + * + * @param accum will be called with poll results, first params the data and + * length, the second a best estimate of min-entropy for the entire buffer; + * out of an abundance of caution this will be zero for many sources. + * accum should return true if it wants the polling to stop, though it may + * still be called again a few more times, and should be careful to return + * true then as well. */ Entropy_Accumulator(std::function<bool (const byte[], size_t, double)> accum) : - m_accum_fn(accum), m_done(false) {} + m_accum_fn(accum) {} virtual ~Entropy_Accumulator() {} /** - * Get a cached I/O buffer (purely for minimizing allocation - * overhead to polls) - * - * @param size requested size for the I/O buffer - * @return cached I/O buffer for repeated polls - */ - secure_vector<byte>& get_io_buffer(size_t size) - { - m_io_buffer.clear(); - m_io_buffer.resize(size); - return m_io_buffer; - } - - /** * @return if our polling goal has been achieved */ bool polling_goal_achieved() const { return m_done; } + bool polling_finished() const { return m_done; } + /** * Add entropy to the accumulator * @param bytes the input bytes @@ -58,7 +52,7 @@ class BOTAN_DLL Entropy_Accumulator void add(const void* bytes, size_t length, double entropy_bits_per_byte) { m_done = m_accum_fn(reinterpret_cast<const byte*>(bytes), - length, entropy_bits_per_byte * length); + length, entropy_bits_per_byte * length) || m_done; } /** @@ -74,8 +68,7 @@ class BOTAN_DLL Entropy_Accumulator } private: std::function<bool (const byte[], size_t, double)> m_accum_fn; - bool m_done; - secure_vector<byte> m_io_buffer; + bool m_done = false; }; /** |