aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy/proc_walk/es_ftw.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-27 17:05:12 +0000
committerlloyd <[email protected]>2008-10-27 17:05:12 +0000
commitd0c2f90af8df600204636a701f8f279c17d6959c (patch)
tree62d9006f758b6429ed3f2ccc964892196223e05f /src/entropy/proc_walk/es_ftw.cpp
parentb33e8dec240005c50e8be3818d2ec250da8eeb17 (diff)
Substantially change Randpool's reseed logic. Now when a reseed
is requested, Randpool will first do a fast poll on each entropy source that has been registered. It will count these poll results towards the collected entropy count, with a maximum of 96 contributed bits of entropy per poll (only /dev/random reaches this, others measure at 50-60 bits typically), and a maximum of 256 for sum contribution of the fast polls. Then it will attempt slow polls of all devices until it thinks enough entropy has been collected (using the rather naive entropy_estimate function). It will count any slow poll for no more than 256 bits (100 or so is typical for every poll but /dev/random), and will attempt to collect at least 512 bits of (estimated/guessed) entropy. This tends to cause Randpool to use significantly more sources. Previously it was common, especially on systems with a /dev/random, for only one or a few sources to be used. This change helps assure that even if /dev/random and company are broken or compromised the RNG output remains secure (assuming at least some amount of entropy unguessable by the attacker can be collected via other sources). Also change AutoSeeded_RNG do an automatic poll/seed when it is created.
Diffstat (limited to 'src/entropy/proc_walk/es_ftw.cpp')
-rw-r--r--src/entropy/proc_walk/es_ftw.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/es_ftw.cpp
index ec11378f8..f90d422a5 100644
--- a/src/entropy/proc_walk/es_ftw.cpp
+++ b/src/entropy/proc_walk/es_ftw.cpp
@@ -22,7 +22,7 @@ namespace Botan {
namespace {
-class Directory_Walker
+class Directory_Walker : public FTW_EntropySource::File_Descriptor_Source
{
public:
Directory_Walker(const std::string& root) { add_directory(root); }
@@ -93,11 +93,20 @@ int Directory_Walker::next_fd()
}
-/*************************************************
-* FTW_EntropySource Constructor *
-*************************************************/
+/**
+* FTW_EntropySource Constructor
+*/
FTW_EntropySource::FTW_EntropySource(const std::string& p) : path(p)
{
+ dir = 0;
+ }
+
+/**
+* FTW_EntropySource Destructor
+*/
+FTW_EntropySource::~FTW_EntropySource()
+ {
+ delete dir;
}
/*************************************************
@@ -121,16 +130,25 @@ void FTW_EntropySource::do_slow_poll()
*************************************************/
void FTW_EntropySource::poll(u32bit max_read)
{
- Directory_Walker dir(path);
+ if(!dir)
+ dir = new Directory_Walker(path);
+
SecureVector<byte> read_buf(1024);
u32bit read_so_far = 0;
while(read_so_far < max_read)
{
- int fd = dir.next_fd();
+ int fd = dir->next_fd();
if(fd == -1)
- break;
+ {
+ delete dir;
+ dir = new Directory_Walker(path);
+ fd = dir->next_fd();
+
+ if(fd == -1) // still fails (directory not mounted, etc) -> exit
+ break;
+ }
ssize_t got = ::read(fd, read_buf.begin(), read_buf.size());