aboutsummaryrefslogtreecommitdiffstats
path: root/src/rng/randpool
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-01-31 12:24:50 +0000
committerlloyd <[email protected]>2009-01-31 12:24:50 +0000
commitf985e438ca768e59626ff08b143a6c80cf671b9e (patch)
treec5d85e1f997dc8178878ea3d3d45bdafa4316c91 /src/rng/randpool
parent2ceccebc5ee5ccc1f30ea57584479e638e6e38d4 (diff)
Remove the notion of counting entropy bits in HMAC_RNG or Randpool.
Instead simply consider the PRNG seeded if a poll kicked off from reseed met its goal, or if the user adds data. Doing anything else prevents creating (for instance) a PRNG seeded with 64 bits of entropy, which is unsafe for some purposes (key generation) but quite possibly safe enough for others (generating salts and such).
Diffstat (limited to 'src/rng/randpool')
-rw-r--r--src/rng/randpool/randpool.cpp22
-rw-r--r--src/rng/randpool/randpool.h4
2 files changed, 8 insertions, 18 deletions
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index 98b088808..af36c335f 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -116,8 +116,8 @@ void Randpool::reseed(u32bit poll_bits)
xor_buf(pool, mac_val, mac_val.size());
mix_pool();
- entropy = std::min<u32bit>(entropy + accum.bits_collected(),
- 8 * mac_val.size());
+ if(accum.bits_collected() >= poll_bits)
+ seeded = true;
}
/**
@@ -129,8 +129,8 @@ void Randpool::add_entropy(const byte input[], u32bit length)
xor_buf(pool, mac_val, mac_val.size());
mix_pool();
- // Assume 1 bit conditional entropy per byte of input
- entropy = std::min<u32bit>(entropy + length, 8 * mac_val.size());
+ if(length)
+ seeded = true;
}
/**
@@ -142,14 +142,6 @@ void Randpool::add_entropy_source(EntropySource* src)
}
/**
-* Check if the the pool is seeded
-*/
-bool Randpool::is_seeded() const
- {
- return (entropy >= 7 * mac->OUTPUT_LENGTH);
- }
-
-/**
* Clear memory of sensitive data
*/
void Randpool::clear() throw()
@@ -159,7 +151,7 @@ void Randpool::clear() throw()
pool.clear();
buffer.clear();
counter.clear();
- entropy = 0;
+ seeded = false;
}
/**
@@ -198,7 +190,7 @@ Randpool::Randpool(BlockCipher* cipher_in,
buffer.create(BLOCK_SIZE);
pool.create(POOL_BLOCKS * BLOCK_SIZE);
counter.create(12);
- entropy = 0;
+ seeded = false;
}
/**
@@ -211,8 +203,6 @@ Randpool::~Randpool()
std::for_each(entropy_sources.begin(), entropy_sources.end(),
del_fun<EntropySource>());
-
- entropy = 0;
}
}
diff --git a/src/rng/randpool/randpool.h b/src/rng/randpool/randpool.h
index 46683934e..f44527609 100644
--- a/src/rng/randpool/randpool.h
+++ b/src/rng/randpool/randpool.h
@@ -20,7 +20,7 @@ class BOTAN_DLL Randpool : public RandomNumberGenerator
{
public:
void randomize(byte[], u32bit);
- bool is_seeded() const;
+ bool is_seeded() const { return seeded; }
void clear() throw();
std::string name() const;
@@ -43,7 +43,7 @@ class BOTAN_DLL Randpool : public RandomNumberGenerator
std::vector<EntropySource*> entropy_sources;
SecureVector<byte> pool, buffer, counter;
- u32bit entropy;
+ bool seeded;
};
}