aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-01-31 10:50:19 +0000
committerlloyd <[email protected]>2009-01-31 10:50:19 +0000
commit0a9152898efe593bb96a619caf9d74f0bc7f75e4 (patch)
treedcc3810882b88dabab42613ba7b5e7cf8f89ffc6 /src
parent716176904747020267858f4b8b2c04675d76c873 (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')
-rw-r--r--src/entropy/entropy_src.h31
-rw-r--r--src/rng/hmac_rng/hmac_rng.cpp2
-rw-r--r--src/rng/randpool/randpool.cpp2
3 files changed, 28 insertions, 7 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
*/
diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp
index ffdfdc60d..ede2b5a08 100644
--- a/src/rng/hmac_rng/hmac_rng.cpp
+++ b/src/rng/hmac_rng/hmac_rng.cpp
@@ -69,7 +69,7 @@ void HMAC_RNG::reseed_with_input(u32bit poll_bits,
feedback of the current PRK value, into the extractor function.
*/
- Entropy_Accumulator accum(*extractor, poll_bits);
+ Entropy_Accumulator_BufferedComputation accum(*extractor, poll_bits);
for(u32bit i = 0; i < entropy_sources.size(); ++i)
{
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index 41a8ca23a..98b088808 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -101,7 +101,7 @@ void Randpool::mix_pool()
*/
void Randpool::reseed(u32bit poll_bits)
{
- Entropy_Accumulator accum(*mac, poll_bits);
+ Entropy_Accumulator_BufferedComputation accum(*mac, poll_bits);
for(u32bit i = 0; i != entropy_sources.size(); ++i)
{