aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/entropy/entropy_src.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/entropy/entropy_src.h')
-rw-r--r--src/lib/entropy/entropy_src.h73
1 files changed, 8 insertions, 65 deletions
diff --git a/src/lib/entropy/entropy_src.h b/src/lib/entropy/entropy_src.h
index 1726d05b8..64d988e7c 100644
--- a/src/lib/entropy/entropy_src.h
+++ b/src/lib/entropy/entropy_src.h
@@ -8,73 +8,12 @@
#ifndef BOTAN_ENTROPY_H__
#define BOTAN_ENTROPY_H__
-#include <botan/secmem.h>
+#include <botan/rng.h>
#include <string>
#include <chrono>
-#include <functional>
namespace Botan {
-class RandomNumberGenerator;
-
-/**
-* Class used to accumulate the poll results of EntropySources
-*/
-class BOTAN_DLL Entropy_Accumulator final
- {
- public:
- /**
- * Initialize an Entropy_Accumulator
- *
- * @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.
- */
- explicit Entropy_Accumulator(std::function<bool (const byte[], size_t, double)> accum) :
- m_accum_fn(accum) {}
-
- /**
- * @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
- * @param length specifies how many bytes the input is
- * @param entropy_bits_per_byte is a best guess at how much
- * entropy per byte is in this input
- */
- 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) || m_done;
- }
-
- /**
- * Add entropy to the accumulator
- * @param v is some value
- * @param entropy_bits_per_byte is a best guess at how much
- * entropy per byte is in this input
- */
- template<typename T>
- void add(const T& v, double entropy_bits_per_byte)
- {
- add(&v, sizeof(T), entropy_bits_per_byte);
- }
-
- secure_vector<byte>& get_io_buf(size_t sz) { m_io_buf.resize(sz); return m_io_buf; }
- private:
- std::function<bool (const byte[], size_t, double)> m_accum_fn;
- secure_vector<byte> m_io_buf;
- bool m_done = false;
- };
-
/**
* Abstract interface to a source of entropy
*/
@@ -96,9 +35,10 @@ class BOTAN_DLL Entropy_Source
/**
* Perform an entropy gathering poll
- * @param accum is an accumulator object that will be given entropy
+ * @param rng will be provided with entropy via calls to add_entropy
+ @ @return conservative estimate of actual entropy added to rng during poll
*/
- virtual void poll(Entropy_Accumulator& accum) = 0;
+ virtual size_t poll(RandomNumberGenerator& rng) = 0;
virtual ~Entropy_Source() {}
};
@@ -116,7 +56,10 @@ class BOTAN_DLL Entropy_Sources final
size_t bits,
std::chrono::milliseconds timeout);
- bool poll_just(Entropy_Accumulator& accum, const std::string& src);
+ /**
+ * Poll just a single named source. Ordinally only used for testing
+ */
+ size_t poll_just(RandomNumberGenerator& rng, const std::string& src);
Entropy_Sources() {}
explicit Entropy_Sources(const std::vector<std::string>& sources);