aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy
diff options
context:
space:
mode:
Diffstat (limited to 'src/entropy')
-rw-r--r--src/entropy/buf_es/buf_es.h2
-rw-r--r--src/entropy/cryptoapi_rng/es_capi.h2
-rw-r--r--src/entropy/dev_random/es_dev.cpp14
-rw-r--r--src/entropy/dev_random/es_dev.h8
-rw-r--r--src/entropy/egd/es_egd.cpp9
-rw-r--r--src/entropy/egd/es_egd.h4
-rw-r--r--src/entropy/entropy_src.h26
-rw-r--r--src/entropy/info.txt7
8 files changed, 64 insertions, 8 deletions
diff --git a/src/entropy/buf_es/buf_es.h b/src/entropy/buf_es/buf_es.h
index 5748613da..f8ec9991c 100644
--- a/src/entropy/buf_es/buf_es.h
+++ b/src/entropy/buf_es/buf_es.h
@@ -6,7 +6,7 @@
#ifndef BOTAN_BUFFERED_ES_H__
#define BOTAN_BUFFERED_ES_H__
-#include <botan/rng.h>
+#include <botan/entropy_src.h>
#include <botan/secmem.h>
namespace Botan {
diff --git a/src/entropy/cryptoapi_rng/es_capi.h b/src/entropy/cryptoapi_rng/es_capi.h
index db4e19271..73d9ae1c2 100644
--- a/src/entropy/cryptoapi_rng/es_capi.h
+++ b/src/entropy/cryptoapi_rng/es_capi.h
@@ -6,7 +6,7 @@
#ifndef BOTAN_ENTROPY_SRC_WIN32_CAPI_H__
#define BOTAN_ENTROPY_SRC_WIN32_CAPI_H__
-#include <botan/rng.h>
+#include <botan/entropy_src.h>
#include <vector>
namespace Botan {
diff --git a/src/entropy/dev_random/es_dev.cpp b/src/entropy/dev_random/es_dev.cpp
index 310620716..426ef8443 100644
--- a/src/entropy/dev_random/es_dev.cpp
+++ b/src/entropy/dev_random/es_dev.cpp
@@ -89,9 +89,9 @@ int Device_Reader::open(const std::string& pathname)
}
-/*************************************************
-* Gather entropy from a RNG device *
-*************************************************/
+/**
+* Gather entropy from a RNG device
+*/
u32bit Device_EntropySource::slow_poll(byte output[], u32bit length)
{
u32bit read = 0;
@@ -109,4 +109,12 @@ u32bit Device_EntropySource::slow_poll(byte output[], u32bit length)
return read;
}
+/**
+* Fast /dev/random and co poll: limit output to 64 bytes
+*/
+u32bit Device_EntropySource::fast_poll(byte output[], u32bit length)
+ {
+ return slow_poll(output, std::max<u32bit>(length, 64));
+ }
+
}
diff --git a/src/entropy/dev_random/es_dev.h b/src/entropy/dev_random/es_dev.h
index 91f08ad4c..024afbdb4 100644
--- a/src/entropy/dev_random/es_dev.h
+++ b/src/entropy/dev_random/es_dev.h
@@ -6,8 +6,9 @@
#ifndef BOTAN_ENTROPY_SRC_DEVICE_H__
#define BOTAN_ENTROPY_SRC_DEVICE_H__
-#include <botan/rng.h>
+#include <botan/entropy_src.h>
#include <vector>
+#include <string>
namespace Botan {
@@ -17,8 +18,11 @@ namespace Botan {
class BOTAN_DLL Device_EntropySource : public EntropySource
{
public:
- Device_EntropySource(const std::vector<std::string>& fs) : fsnames(fs) {}
+ Device_EntropySource(const std::vector<std::string>& fs) :
+ fsnames(fs) {}
+
u32bit slow_poll(byte[], u32bit);
+ u32bit fast_poll(byte[], u32bit);
private:
std::vector<std::string> fsnames;
};
diff --git a/src/entropy/egd/es_egd.cpp b/src/entropy/egd/es_egd.cpp
index da4aaf847..8390552c6 100644
--- a/src/entropy/egd/es_egd.cpp
+++ b/src/entropy/egd/es_egd.cpp
@@ -6,6 +6,7 @@
#include <botan/es_egd.h>
#include <botan/bit_ops.h>
#include <botan/parsing.h>
+#include <botan/exceptn.h>
#include <cstring>
#include <sys/types.h>
@@ -73,4 +74,12 @@ u32bit EGD_EntropySource::slow_poll(byte output[], u32bit length)
return 0;
}
+/**
+* Gather Entropy from EGD, limiting to 32 bytes
+*/
+u32bit EGD_EntropySource::fast_poll(byte output[], u32bit length)
+ {
+ return slow_poll(output, std::max<u32bit>(length, 64));
+ }
+
}
diff --git a/src/entropy/egd/es_egd.h b/src/entropy/egd/es_egd.h
index 6f5cae1b3..4f1eb9127 100644
--- a/src/entropy/egd/es_egd.h
+++ b/src/entropy/egd/es_egd.h
@@ -6,7 +6,7 @@
#ifndef BOTAN_ENTROPY_SRC_EGD_H__
#define BOTAN_ENTROPY_SRC_EGD_H__
-#include <botan/rng.h>
+#include <botan/entropy_src.h>
#include <string>
#include <vector>
@@ -18,7 +18,9 @@ namespace Botan {
class BOTAN_DLL EGD_EntropySource : public EntropySource
{
public:
+ u32bit fast_poll(byte[], u32bit);
u32bit slow_poll(byte[], u32bit);
+
EGD_EntropySource(const std::vector<std::string>& p) : paths(p) {}
private:
u32bit do_poll(byte[], u32bit, const std::string&) const;
diff --git a/src/entropy/entropy_src.h b/src/entropy/entropy_src.h
new file mode 100644
index 000000000..4ee24ce4a
--- /dev/null
+++ b/src/entropy/entropy_src.h
@@ -0,0 +1,26 @@
+/*************************************************
+* EntropySource Header File *
+* (C) 2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_ENTROPY_SOURCE_BASE_H__
+#define BOTAN_ENTROPY_SOURCE_BASE_H__
+
+#include <botan/types.h>
+
+namespace Botan {
+
+/**
+* Abstract interface to a source of (hopefully unpredictable) system entropy
+*/
+class BOTAN_DLL EntropySource
+ {
+ public:
+ virtual u32bit slow_poll(byte buf[], u32bit len) = 0;
+ virtual u32bit fast_poll(byte buf[], u32bit len) = 0;
+ virtual ~EntropySource() {}
+ };
+
+}
+
+#endif
diff --git a/src/entropy/info.txt b/src/entropy/info.txt
new file mode 100644
index 000000000..bac1d593f
--- /dev/null
+++ b/src/entropy/info.txt
@@ -0,0 +1,7 @@
+realname "Entropy Sources"
+
+load_on auto
+
+<add>
+entropy_src.h
+</add>