aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 23:04:35 +0000
committerlloyd <[email protected]>2008-09-28 23:04:35 +0000
commit8820c122b9cd665621729abfcf8c6751762535df (patch)
tree26f775d42720c60adf13127da17d715d51187765 /src/entropy
parent7b04ba8df59963f9907bcd5fd6eb3dcfc81513cf (diff)
Move buf_es into module, add deps where needed
Diffstat (limited to 'src/entropy')
-rw-r--r--src/entropy/beos_stats/modinfo.txt4
-rw-r--r--src/entropy/buf_es/buf_es.cpp89
-rw-r--r--src/entropy/buf_es/buf_es.h39
-rw-r--r--src/entropy/proc_walk/modinfo.txt4
-rw-r--r--src/entropy/unix_procs/modinfo.txt4
-rw-r--r--src/entropy/win32_stats/modinfo.txt4
6 files changed, 144 insertions, 0 deletions
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
<libs>
beos -> root,be
</libs>
+
+<requires>
+buf_es
+</requires>
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 <botan/buf_es.h>
+#include <botan/xor_buf.h>
+#include <botan/util.h>
+#include <algorithm>
+
+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<const byte*>(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 <botan/rng.h>
+#include <botan/secmem.h>
+
+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<byte> 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
</add>
+<requires>
+buf_es
+</requires>
+
<os>
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
</add>
+<requires>
+buf_es
+</requires>
+
<os>
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
</add>
+<requires>
+buf_es
+</requires>
+
<os>
windows
cygwin