From 8820c122b9cd665621729abfcf8c6751762535df Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 28 Sep 2008 23:04:35 +0000 Subject: Move buf_es into module, add deps where needed --- src/buf_es.cpp | 89 ------------------------------------- src/entropy/beos_stats/modinfo.txt | 4 ++ src/entropy/buf_es/buf_es.cpp | 89 +++++++++++++++++++++++++++++++++++++ src/entropy/buf_es/buf_es.h | 39 ++++++++++++++++ src/entropy/proc_walk/modinfo.txt | 4 ++ src/entropy/unix_procs/modinfo.txt | 4 ++ src/entropy/win32_stats/modinfo.txt | 4 ++ 7 files changed, 144 insertions(+), 89 deletions(-) delete mode 100644 src/buf_es.cpp create mode 100644 src/entropy/buf_es/buf_es.cpp create mode 100644 src/entropy/buf_es/buf_es.h (limited to 'src') diff --git a/src/buf_es.cpp b/src/buf_es.cpp deleted file mode 100644 index 19f30e22c..000000000 --- a/src/buf_es.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/************************************************* -* Buffered EntropySource Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* Buffered_EntropySource Constructor * -*************************************************/ -Buffered_EntropySource::Buffered_EntropySource() : buffer(256) - { - read_pos = write_pos = 0; - done_slow_poll = false; - } - -/************************************************* -* Fast Poll * -*************************************************/ -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); - } - -/************************************************* -* Slow Poll * -*************************************************/ -u32bit Buffered_EntropySource::slow_poll(byte out[], u32bit length) - { - do_slow_poll(); - done_slow_poll = true; - return copy_out(out, length, buffer.size()); - } - -/************************************************* -* Default fast poll operation * -*************************************************/ -void Buffered_EntropySource::do_fast_poll() - { - return do_slow_poll(); - } - -/************************************************* -* Add entropy to the internal buffer * -*************************************************/ -void Buffered_EntropySource::add_bytes(const void* entropy_ptr, u32bit length) - { - const byte* bytes = static_cast(entropy_ptr); - - while(length) - { - u32bit copied = std::min(length, buffer.size() - write_pos); - xor_buf(buffer + write_pos, bytes, copied); - bytes += copied; - length -= copied; - write_pos = (write_pos + copied) % buffer.size(); - } - } - -/************************************************* -* Add entropy to the internal buffer * -*************************************************/ -void Buffered_EntropySource::add_bytes(u64bit entropy) - { - add_bytes(&entropy, 8); - } - -/************************************************* -* Take entropy from the internal buffer * -*************************************************/ -u32bit Buffered_EntropySource::copy_out(byte out[], u32bit length, - u32bit max_read) - { - length = std::min(length, max_read); - u32bit copied = std::min(length, buffer.size() - read_pos); - xor_buf(out, buffer + read_pos, copied); - read_pos = (read_pos + copied) % buffer.size(); - return copied; - } - -} diff --git a/src/entropy/beos_stats/modinfo.txt b/src/entropy/beos_stats/modinfo.txt index a7e62cfb3..33badd5c3 100644 --- a/src/entropy/beos_stats/modinfo.txt +++ b/src/entropy/beos_stats/modinfo.txt @@ -17,3 +17,7 @@ beos beos -> root,be + + +buf_es + diff --git a/src/entropy/buf_es/buf_es.cpp b/src/entropy/buf_es/buf_es.cpp new file mode 100644 index 000000000..19f30e22c --- /dev/null +++ b/src/entropy/buf_es/buf_es.cpp @@ -0,0 +1,89 @@ +/************************************************* +* Buffered EntropySource Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Buffered_EntropySource Constructor * +*************************************************/ +Buffered_EntropySource::Buffered_EntropySource() : buffer(256) + { + read_pos = write_pos = 0; + done_slow_poll = false; + } + +/************************************************* +* Fast Poll * +*************************************************/ +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); + } + +/************************************************* +* Slow Poll * +*************************************************/ +u32bit Buffered_EntropySource::slow_poll(byte out[], u32bit length) + { + do_slow_poll(); + done_slow_poll = true; + return copy_out(out, length, buffer.size()); + } + +/************************************************* +* Default fast poll operation * +*************************************************/ +void Buffered_EntropySource::do_fast_poll() + { + return do_slow_poll(); + } + +/************************************************* +* Add entropy to the internal buffer * +*************************************************/ +void Buffered_EntropySource::add_bytes(const void* entropy_ptr, u32bit length) + { + const byte* bytes = static_cast(entropy_ptr); + + while(length) + { + u32bit copied = std::min(length, buffer.size() - write_pos); + xor_buf(buffer + write_pos, bytes, copied); + bytes += copied; + length -= copied; + write_pos = (write_pos + copied) % buffer.size(); + } + } + +/************************************************* +* Add entropy to the internal buffer * +*************************************************/ +void Buffered_EntropySource::add_bytes(u64bit entropy) + { + add_bytes(&entropy, 8); + } + +/************************************************* +* Take entropy from the internal buffer * +*************************************************/ +u32bit Buffered_EntropySource::copy_out(byte out[], u32bit length, + u32bit max_read) + { + length = std::min(length, max_read); + u32bit copied = std::min(length, buffer.size() - read_pos); + xor_buf(out, buffer + read_pos, copied); + read_pos = (read_pos + copied) % buffer.size(); + return copied; + } + +} diff --git a/src/entropy/buf_es/buf_es.h b/src/entropy/buf_es/buf_es.h new file mode 100644 index 000000000..5748613da --- /dev/null +++ b/src/entropy/buf_es/buf_es.h @@ -0,0 +1,39 @@ +/************************************************* +* Buffered EntropySource Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_BUFFERED_ES_H__ +#define BOTAN_BUFFERED_ES_H__ + +#include +#include + +namespace Botan { + +/************************************************* +* Buffered EntropySource * +*************************************************/ +class BOTAN_DLL Buffered_EntropySource : public EntropySource + { + public: + u32bit slow_poll(byte[], u32bit); + u32bit fast_poll(byte[], u32bit); + protected: + Buffered_EntropySource(); + u32bit copy_out(byte[], u32bit, u32bit); + + void add_bytes(const void*, u32bit); + void add_bytes(u64bit); + + virtual void do_slow_poll() = 0; + virtual void do_fast_poll(); + private: + SecureVector buffer; + u32bit write_pos, read_pos; + bool done_slow_poll; + }; + +} + +#endif diff --git a/src/entropy/proc_walk/modinfo.txt b/src/entropy/proc_walk/modinfo.txt index d932523fd..ad945ee46 100644 --- a/src/entropy/proc_walk/modinfo.txt +++ b/src/entropy/proc_walk/modinfo.txt @@ -10,6 +10,10 @@ es_ftw.h es_ftw.cpp + +buf_es + + aix cygwin diff --git a/src/entropy/unix_procs/modinfo.txt b/src/entropy/unix_procs/modinfo.txt index f16e21289..981399dbb 100644 --- a/src/entropy/unix_procs/modinfo.txt +++ b/src/entropy/unix_procs/modinfo.txt @@ -13,6 +13,10 @@ es_unix.h unix_cmd.h + +buf_es + + aix beos diff --git a/src/entropy/win32_stats/modinfo.txt b/src/entropy/win32_stats/modinfo.txt index 931760979..6be850561 100644 --- a/src/entropy/win32_stats/modinfo.txt +++ b/src/entropy/win32_stats/modinfo.txt @@ -13,6 +13,10 @@ es_win32.h es_win32.cpp + +buf_es + + windows cygwin -- cgit v1.2.3