diff options
Diffstat (limited to 'src/entropy/proc_walk')
-rw-r--r-- | src/entropy/proc_walk/es_ftw.cpp | 49 | ||||
-rw-r--r-- | src/entropy/proc_walk/es_ftw.h | 13 |
2 files changed, 27 insertions, 35 deletions
diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/es_ftw.cpp index f90d422a5..013bb922b 100644 --- a/src/entropy/proc_walk/es_ftw.cpp +++ b/src/entropy/proc_walk/es_ftw.cpp @@ -4,6 +4,7 @@ *************************************************/ #include <botan/es_ftw.h> +#include <botan/secmem.h> #include <botan/util.h> #include <cstring> #include <deque> @@ -109,34 +110,16 @@ FTW_EntropySource::~FTW_EntropySource() delete dir; } -/************************************************* -* FTW Fast Poll * -*************************************************/ -void FTW_EntropySource::do_fast_poll() - { - poll(32*1024); - } - -/************************************************* -* FTW Slow Poll * -*************************************************/ -void FTW_EntropySource::do_slow_poll() - { - poll(256*1024); - } - -/************************************************* -* FTW Poll * -*************************************************/ -void FTW_EntropySource::poll(u32bit max_read) +u32bit FTW_EntropySource::slow_poll(byte buf[], u32bit length) { if(!dir) dir = new Directory_Walker(path); - SecureVector<byte> read_buf(1024); + SecureVector<byte> read_buf(4096); - u32bit read_so_far = 0; - while(read_so_far < max_read) + u32bit bytes_read = 0; + + while(bytes_read < length * 32) { int fd = dir->next_fd(); @@ -146,20 +129,30 @@ void FTW_EntropySource::poll(u32bit max_read) dir = new Directory_Walker(path); fd = dir->next_fd(); - if(fd == -1) // still fails (directory not mounted, etc) -> exit - break; + if(fd == -1) // still fails (directory not mounted, etc) -> fail + return 0; } ssize_t got = ::read(fd, read_buf.begin(), read_buf.size()); - if(got > 0) + if(got > 0 && got <= read_buf.size()) { - add_bytes(read_buf, got); - read_so_far += got; + for(ssize_t i = 0; i != got; ++i) + buf[i % length] ^= read_buf[i]; + + // never count any one file for more than 128 bytes + bytes_read += std::min<u32bit>(got, 128); } ::close(fd); } + + return length; + } + +u32bit FTW_EntropySource::fast_poll(byte[], u32bit) + { + return 0; // no op } } diff --git a/src/entropy/proc_walk/es_ftw.h b/src/entropy/proc_walk/es_ftw.h index a0d480aae..5b127943f 100644 --- a/src/entropy/proc_walk/es_ftw.h +++ b/src/entropy/proc_walk/es_ftw.h @@ -6,18 +6,21 @@ #ifndef BOTAN_ENTROPY_SRC_FTW_H__ #define BOTAN_ENTROPY_SRC_FTW_H__ -#include <botan/buf_es.h> +#include <botan/entropy_src.h> namespace Botan { /************************************************* * File Tree Walking Entropy Source * *************************************************/ -class BOTAN_DLL FTW_EntropySource : public Buffered_EntropySource +class BOTAN_DLL FTW_EntropySource : public EntropySource { public: std::string name() const { return "Proc Walker"; } + u32bit slow_poll(byte buf[], u32bit len); + u32bit fast_poll(byte buf[], u32bit len); + FTW_EntropySource(const std::string& root_dir); ~FTW_EntropySource(); @@ -28,12 +31,8 @@ class BOTAN_DLL FTW_EntropySource : public Buffered_EntropySource virtual ~File_Descriptor_Source() {} }; private: - void do_fast_poll(); - void do_slow_poll(); - - void poll(u32bit max_read); - const std::string path; + std::string path; File_Descriptor_Source* dir; }; |