diff options
author | lloyd <[email protected]> | 2009-01-31 10:50:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-01-31 10:50:19 +0000 |
commit | 0a9152898efe593bb96a619caf9d74f0bc7f75e4 (patch) | |
tree | dcc3810882b88dabab42613ba7b5e7cf8f89ffc6 /src/entropy/entropy_src.h | |
parent | 716176904747020267858f4b8b2c04675d76c873 (diff) |
Make Entropy_Accumulator a pure virtual to allow other accumulation
techniques, with the one using BufferedComputation being the new
subclass with the charming name Entropy_Accumulator_BufferedComputation.
Diffstat (limited to 'src/entropy/entropy_src.h')
-rw-r--r-- | src/entropy/entropy_src.h | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/entropy/entropy_src.h b/src/entropy/entropy_src.h index 96ffcad0b..c294ca6ac 100644 --- a/src/entropy/entropy_src.h +++ b/src/entropy/entropy_src.h @@ -18,8 +18,10 @@ namespace Botan { class Entropy_Accumulator { public: - Entropy_Accumulator(BufferedComputation& sink, u32bit goal) : - entropy_sink(sink), entropy_goal(goal), collected_bits(0) {} + Entropy_Accumulator(u32bit goal) : + entropy_goal(goal), collected_bits(0) {} + + virtual ~Entropy_Accumulator() {} /** @return cached I/O buffer for repeated polls @@ -34,12 +36,14 @@ class Entropy_Accumulator u32bit desired_remaining_bits() const { - return (collected_bits >= entropy_goal) ? 0 : (entropy_goal - collected_bits); + if(collected_bits >= entropy_goal) + return 0; + return (entropy_goal - collected_bits); } void add(const void* bytes, u32bit length, double entropy_bits_per_byte) { - entropy_sink.update(reinterpret_cast<const byte*>(bytes), length); + add_bytes(bytes, length); collected_bits += std::min<u32bit>(8, entropy_bits_per_byte) * length; } @@ -49,11 +53,28 @@ class Entropy_Accumulator add(&v, sizeof(T), entropy_bits_per_byte); } private: - BufferedComputation& entropy_sink; + virtual void add_bytes(const void* bytes, u32bit length) = 0; + SecureVector<byte> io_buffer; u32bit entropy_goal, collected_bits; }; +class Entropy_Accumulator_BufferedComputation : public Entropy_Accumulator + { + public: + Entropy_Accumulator_BufferedComputation(BufferedComputation& sink, + u32bit goal) : + Entropy_Accumulator(goal), entropy_sink(sink) {} + + private: + virtual void add_bytes(const void* bytes, u32bit length) + { + entropy_sink.update(reinterpret_cast<const byte*>(bytes), length); + } + + BufferedComputation& entropy_sink; + }; + /** * Abstract interface to a source of (hopefully unpredictable) system entropy */ |