aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy
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
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')
-rw-r--r--src/entropy/beos_stats/es_beos.h2
-rw-r--r--src/entropy/buf_es/buf_es.cpp6
-rw-r--r--src/entropy/cryptoapi_rng/es_capi.h2
-rw-r--r--src/entropy/dev_random/es_dev.cpp2
-rw-r--r--src/entropy/dev_random/es_dev.h2
-rw-r--r--src/entropy/egd/es_egd.cpp4
-rw-r--r--src/entropy/egd/es_egd.h2
-rw-r--r--src/entropy/entropy_src.h3
-rw-r--r--src/entropy/proc_walk/es_ftw.cpp32
-rw-r--r--src/entropy/proc_walk/es_ftw.h11
-rw-r--r--src/entropy/unix_procs/es_unix.cpp2
-rw-r--r--src/entropy/unix_procs/es_unix.h2
-rw-r--r--src/entropy/win32_stats/es_win32.h1
13 files changed, 55 insertions, 16 deletions
diff --git a/src/entropy/beos_stats/es_beos.h b/src/entropy/beos_stats/es_beos.h
index 57e15c9d9..ec461780d 100644
--- a/src/entropy/beos_stats/es_beos.h
+++ b/src/entropy/beos_stats/es_beos.h
@@ -16,6 +16,8 @@ namespace Botan {
class BOTAN_DLL BeOS_EntropySource : public Buffered_EntropySource
{
private:
+ std::string name() const { return "BeOS Statistics"; }
+
void do_fast_poll();
void do_slow_poll();
};
diff --git a/src/entropy/buf_es/buf_es.cpp b/src/entropy/buf_es/buf_es.cpp
index 19f30e22c..4a88d67bd 100644
--- a/src/entropy/buf_es/buf_es.cpp
+++ b/src/entropy/buf_es/buf_es.cpp
@@ -13,10 +13,9 @@ namespace Botan {
/*************************************************
* Buffered_EntropySource Constructor *
*************************************************/
-Buffered_EntropySource::Buffered_EntropySource() : buffer(256)
+Buffered_EntropySource::Buffered_EntropySource() : buffer(128)
{
read_pos = write_pos = 0;
- done_slow_poll = false;
}
/*************************************************
@@ -24,8 +23,6 @@ Buffered_EntropySource::Buffered_EntropySource() : buffer(256)
*************************************************/
u32bit Buffered_EntropySource::fast_poll(byte out[], u32bit length)
{
- if(!done_slow_poll) { do_slow_poll(); done_slow_poll = true; }
-
do_fast_poll();
return copy_out(out, length, buffer.size() / 4);
}
@@ -36,7 +33,6 @@ u32bit Buffered_EntropySource::fast_poll(byte out[], u32bit length)
u32bit Buffered_EntropySource::slow_poll(byte out[], u32bit length)
{
do_slow_poll();
- done_slow_poll = true;
return copy_out(out, length, buffer.size());
}
diff --git a/src/entropy/cryptoapi_rng/es_capi.h b/src/entropy/cryptoapi_rng/es_capi.h
index 73d9ae1c2..c8f83427c 100644
--- a/src/entropy/cryptoapi_rng/es_capi.h
+++ b/src/entropy/cryptoapi_rng/es_capi.h
@@ -17,6 +17,8 @@ namespace Botan {
class BOTAN_DLL Win32_CAPI_EntropySource : public EntropySource
{
public:
+ std::string name() const { return "Win32 CryptoGenRandom"; }
+
u32bit slow_poll(byte[], u32bit);
Win32_CAPI_EntropySource(const std::string& = "");
private:
diff --git a/src/entropy/dev_random/es_dev.cpp b/src/entropy/dev_random/es_dev.cpp
index 426ef8443..04b3a90ee 100644
--- a/src/entropy/dev_random/es_dev.cpp
+++ b/src/entropy/dev_random/es_dev.cpp
@@ -114,7 +114,7 @@ u32bit Device_EntropySource::slow_poll(byte output[], u32bit length)
*/
u32bit Device_EntropySource::fast_poll(byte output[], u32bit length)
{
- return slow_poll(output, std::max<u32bit>(length, 64));
+ return slow_poll(output, std::min<u32bit>(length, 64));
}
}
diff --git a/src/entropy/dev_random/es_dev.h b/src/entropy/dev_random/es_dev.h
index 024afbdb4..2c9d93369 100644
--- a/src/entropy/dev_random/es_dev.h
+++ b/src/entropy/dev_random/es_dev.h
@@ -18,6 +18,8 @@ namespace Botan {
class BOTAN_DLL Device_EntropySource : public EntropySource
{
public:
+ std::string name() const { return "RNG Device Reader"; }
+
Device_EntropySource(const std::vector<std::string>& fs) :
fsnames(fs) {}
diff --git a/src/entropy/egd/es_egd.cpp b/src/entropy/egd/es_egd.cpp
index 8390552c6..41c7d29f2 100644
--- a/src/entropy/egd/es_egd.cpp
+++ b/src/entropy/egd/es_egd.cpp
@@ -75,11 +75,11 @@ u32bit EGD_EntropySource::slow_poll(byte output[], u32bit length)
}
/**
-* Gather Entropy from EGD, limiting to 32 bytes
+* Gather Entropy from EGD, limiting to 64 bytes
*/
u32bit EGD_EntropySource::fast_poll(byte output[], u32bit length)
{
- return slow_poll(output, std::max<u32bit>(length, 64));
+ return slow_poll(output, std::min<u32bit>(length, 64));
}
}
diff --git a/src/entropy/egd/es_egd.h b/src/entropy/egd/es_egd.h
index 4f1eb9127..ca2e97349 100644
--- a/src/entropy/egd/es_egd.h
+++ b/src/entropy/egd/es_egd.h
@@ -18,6 +18,8 @@ namespace Botan {
class BOTAN_DLL EGD_EntropySource : public EntropySource
{
public:
+ std::string name() const { return "EGD/PRNGD"; }
+
u32bit fast_poll(byte[], u32bit);
u32bit slow_poll(byte[], u32bit);
diff --git a/src/entropy/entropy_src.h b/src/entropy/entropy_src.h
index 4ee24ce4a..0891e393f 100644
--- a/src/entropy/entropy_src.h
+++ b/src/entropy/entropy_src.h
@@ -7,6 +7,7 @@
#define BOTAN_ENTROPY_SOURCE_BASE_H__
#include <botan/types.h>
+#include <string>
namespace Botan {
@@ -16,6 +17,8 @@ namespace Botan {
class BOTAN_DLL EntropySource
{
public:
+ virtual std::string name() const = 0;
+
virtual u32bit slow_poll(byte buf[], u32bit len) = 0;
virtual u32bit fast_poll(byte buf[], u32bit len) = 0;
virtual ~EntropySource() {}
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());
diff --git a/src/entropy/proc_walk/es_ftw.h b/src/entropy/proc_walk/es_ftw.h
index e0d266141..a0d480aae 100644
--- a/src/entropy/proc_walk/es_ftw.h
+++ b/src/entropy/proc_walk/es_ftw.h
@@ -16,7 +16,17 @@ namespace Botan {
class BOTAN_DLL FTW_EntropySource : public Buffered_EntropySource
{
public:
+ std::string name() const { return "Proc Walker"; }
+
FTW_EntropySource(const std::string& root_dir);
+ ~FTW_EntropySource();
+
+ class File_Descriptor_Source
+ {
+ public:
+ virtual int next_fd() = 0;
+ virtual ~File_Descriptor_Source() {}
+ };
private:
void do_fast_poll();
void do_slow_poll();
@@ -24,6 +34,7 @@ class BOTAN_DLL FTW_EntropySource : public Buffered_EntropySource
void poll(u32bit max_read);
const std::string path;
+ File_Descriptor_Source* dir;
};
}
diff --git a/src/entropy/unix_procs/es_unix.cpp b/src/entropy/unix_procs/es_unix.cpp
index c503c20ae..012a38ce0 100644
--- a/src/entropy/unix_procs/es_unix.cpp
+++ b/src/entropy/unix_procs/es_unix.cpp
@@ -47,7 +47,7 @@ void Unix_EntropySource::add_sources(const Unix_Program srcs[], u32bit count)
*************************************************/
void Unix_EntropySource::do_fast_poll()
{
- const char* STAT_TARGETS[] = { "/", "/tmp", ".", "..", 0 };
+ const char* STAT_TARGETS[] = { "/", "/tmp", "/etc/passwd", ".", "..", 0 };
for(u32bit j = 0; STAT_TARGETS[j]; j++)
{
diff --git a/src/entropy/unix_procs/es_unix.h b/src/entropy/unix_procs/es_unix.h
index 4925fd4e1..907ebbc3a 100644
--- a/src/entropy/unix_procs/es_unix.h
+++ b/src/entropy/unix_procs/es_unix.h
@@ -18,6 +18,8 @@ namespace Botan {
class BOTAN_DLL Unix_EntropySource : public Buffered_EntropySource
{
public:
+ std::string name() const { return "Unix Entropy Source"; }
+
void add_sources(const Unix_Program[], u32bit);
Unix_EntropySource(const std::vector<std::string>& path);
private:
diff --git a/src/entropy/win32_stats/es_win32.h b/src/entropy/win32_stats/es_win32.h
index f2314ab0c..1fd07df1d 100644
--- a/src/entropy/win32_stats/es_win32.h
+++ b/src/entropy/win32_stats/es_win32.h
@@ -16,6 +16,7 @@ namespace Botan {
class BOTAN_DLL Win32_EntropySource : public Buffered_EntropySource
{
private:
+ std::string name() const { return "Win32 Statistics"; }
void do_fast_poll();
void do_slow_poll();
};