diff options
-rw-r--r-- | doc/log.txt | 1 | ||||
-rw-r--r-- | src/entropy/buf_es/buf_es.h | 2 | ||||
-rw-r--r-- | src/entropy/cryptoapi_rng/es_capi.h | 2 | ||||
-rw-r--r-- | src/entropy/dev_random/es_dev.cpp | 14 | ||||
-rw-r--r-- | src/entropy/dev_random/es_dev.h | 8 | ||||
-rw-r--r-- | src/entropy/egd/es_egd.cpp | 9 | ||||
-rw-r--r-- | src/entropy/egd/es_egd.h | 4 | ||||
-rw-r--r-- | src/entropy/entropy_src.h | 26 | ||||
-rw-r--r-- | src/entropy/info.txt | 7 | ||||
-rw-r--r-- | src/math/bigint/info.txt | 1 | ||||
-rw-r--r-- | src/pubkey/pubkey/info.txt | 1 | ||||
-rw-r--r-- | src/rng/rng.cpp | 8 | ||||
-rw-r--r-- | src/rng/rng.h | 13 | ||||
-rw-r--r-- | src/s2k/info.txt | 1 | ||||
-rw-r--r-- | src/utils/timer/timers.cpp | 7 | ||||
-rw-r--r-- | src/utils/timer/timers.h | 1 |
16 files changed, 77 insertions, 28 deletions
diff --git a/doc/log.txt b/doc/log.txt index 606fe9576..9ade4603f 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -1,5 +1,6 @@ * 1.7.19, ????-??-?? + - Add a new AutoSeeded_RNG in auto_rng.h - Add automatic identification for Intel's Prescott processors * 1.7.18, 2008-10-22 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> diff --git a/src/math/bigint/info.txt b/src/math/bigint/info.txt index d6c5df763..908304c9f 100644 --- a/src/math/bigint/info.txt +++ b/src/math/bigint/info.txt @@ -6,6 +6,7 @@ define BIGINT <requires> hex +rng mp_amd64|mp_asm64|mp_ia32|mp_ia32_msvc|mp_generic monty_generic mulop_generic diff --git a/src/pubkey/pubkey/info.txt b/src/pubkey/pubkey/info.txt index e6017810e..9a8766790 100644 --- a/src/pubkey/pubkey/info.txt +++ b/src/pubkey/pubkey/info.txt @@ -11,6 +11,7 @@ numbertheory pbe oid_lookup pk_pad +rng </requires> <add> diff --git a/src/rng/rng.cpp b/src/rng/rng.cpp index 01e909610..fe3c4e10c 100644 --- a/src/rng/rng.cpp +++ b/src/rng/rng.cpp @@ -12,14 +12,6 @@ namespace Botan { /************************************************* -* Default fast poll for EntropySources * -*************************************************/ -u32bit EntropySource::fast_poll(byte buf[], u32bit len) - { - return this->slow_poll(buf, len); - } - -/************************************************* * Get a single random byte * *************************************************/ byte RandomNumberGenerator::next_byte() diff --git a/src/rng/rng.h b/src/rng/rng.h index 20f2e47b1..fb92bb3c5 100644 --- a/src/rng/rng.h +++ b/src/rng/rng.h @@ -6,21 +6,12 @@ #ifndef BOTAN_RANDOM_NUMBER_GENERATOR_H__ #define BOTAN_RANDOM_NUMBER_GENERATOR_H__ +#include <botan/entropy_src.h> #include <botan/exceptn.h> +#include <string> namespace Botan { -/************************************************* -* Entropy Source * -*************************************************/ -class BOTAN_DLL EntropySource - { - public: - virtual u32bit slow_poll(byte[], u32bit) = 0; - virtual u32bit fast_poll(byte[], u32bit); - virtual ~EntropySource() {} - }; - /** * This class represents a random number (RNG) generator object. */ diff --git a/src/s2k/info.txt b/src/s2k/info.txt index 9c8bb0c45..44510bbd7 100644 --- a/src/s2k/info.txt +++ b/src/s2k/info.txt @@ -4,6 +4,7 @@ load_on auto <requires> utils +rng </requires> <add> diff --git a/src/utils/timer/timers.cpp b/src/utils/timer/timers.cpp index 4f482916f..b10b09038 100644 --- a/src/utils/timer/timers.cpp +++ b/src/utils/timer/timers.cpp @@ -29,7 +29,7 @@ u64bit Timer::clock() const /************************************************* * Read the clock and return the output * *************************************************/ -u32bit Timer::slow_poll(byte out[], u32bit length) +u32bit Timer::fast_poll(byte out[], u32bit length) { const u64bit clock_value = this->clock(); @@ -39,6 +39,11 @@ u32bit Timer::slow_poll(byte out[], u32bit length) return (length < 8) ? length : 8; } +u32bit Timer::slow_poll(byte out[], u32bit length) + { + return fast_poll(out, length); + } + /************************************************* * Combine a two time values into a single one * *************************************************/ diff --git a/src/utils/timer/timers.h b/src/utils/timer/timers.h index 253f71f6b..5ad2cfbea 100644 --- a/src/utils/timer/timers.h +++ b/src/utils/timer/timers.h @@ -18,6 +18,7 @@ class BOTAN_DLL Timer : public EntropySource public: virtual u64bit clock() const; u32bit slow_poll(byte[], u32bit); + u32bit fast_poll(byte[], u32bit); virtual ~Timer() {} protected: |