diff options
author | lloyd <[email protected]> | 2013-11-09 15:56:50 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-11-09 15:56:50 +0000 |
commit | b5d287a9cfa9416aba675dd1778838e67efceefc (patch) | |
tree | b0011b9e821c4cc406b1ce191a3042610f2aa122 | |
parent | 99eb63b2340e77d14555491c065b55135c78c18e (diff) |
Fix EGD settings. Some cleanup and renaming.
-rw-r--r-- | src/entropy/dev_random/dev_random.cpp | 22 | ||||
-rw-r--r-- | src/entropy/dev_random/dev_random.h | 2 | ||||
-rw-r--r-- | src/entropy/proc_walk/info.txt | 6 | ||||
-rw-r--r-- | src/entropy/proc_walk/proc_walk.cpp (renamed from src/entropy/proc_walk/es_ftw.cpp) | 32 | ||||
-rw-r--r-- | src/entropy/proc_walk/proc_walk.h (renamed from src/entropy/proc_walk/es_ftw.h) | 16 | ||||
-rw-r--r-- | src/libstate/global_rng.cpp | 17 |
6 files changed, 46 insertions, 49 deletions
diff --git a/src/entropy/dev_random/dev_random.cpp b/src/entropy/dev_random/dev_random.cpp index 6feefb6fc..fedba6810 100644 --- a/src/entropy/dev_random/dev_random.cpp +++ b/src/entropy/dev_random/dev_random.cpp @@ -38,7 +38,7 @@ Device_EntropySource::Device_EntropySource(const std::vector<std::string>& fsnam fd_type fd = ::open(fsname.c_str(), flags); if(fd >= 0 && fd < FD_SETSIZE) - devices.push_back(fd); + m_devices.push_back(fd); else if(fd >= 0) ::close(fd); } @@ -49,8 +49,8 @@ Device_EntropySource destructor: close all open devices */ Device_EntropySource::~Device_EntropySource() { - for(size_t i = 0; i != devices.size(); ++i) - ::close(devices[i]); + for(size_t i = 0; i != m_devices.size(); ++i) + ::close(m_devices[i]); } /** @@ -58,20 +58,20 @@ Device_EntropySource::~Device_EntropySource() */ void Device_EntropySource::poll(Entropy_Accumulator& accum) { - if(devices.empty()) + if(m_devices.empty()) return; const size_t ENTROPY_BITS_PER_BYTE = 8; const size_t MS_WAIT_TIME = 32; const size_t READ_ATTEMPT = std::max<size_t>(accum.desired_remaining_bits() / 8, 16); - int max_fd = devices[0]; + int max_fd = m_devices[0]; fd_set read_set; FD_ZERO(&read_set); - for(size_t i = 0; i != devices.size(); ++i) + for(size_t i = 0; i != m_devices.size(); ++i) { - FD_SET(devices[i], &read_set); - max_fd = std::max(devices[i], max_fd); + FD_SET(m_devices[i], &read_set); + max_fd = std::max(m_devices[i], max_fd); } struct ::timeval timeout; @@ -84,11 +84,11 @@ void Device_EntropySource::poll(Entropy_Accumulator& accum) secure_vector<byte>& io_buffer = accum.get_io_buffer(READ_ATTEMPT); - for(size_t i = 0; i != devices.size(); ++i) + for(size_t i = 0; i != m_devices.size(); ++i) { - if(FD_ISSET(devices[i], &read_set)) + if(FD_ISSET(m_devices[i], &read_set)) { - const ssize_t got = ::read(devices[i], &io_buffer[0], io_buffer.size()); + const ssize_t got = ::read(m_devices[i], &io_buffer[0], io_buffer.size()); accum.add(&io_buffer[0], got, ENTROPY_BITS_PER_BYTE); } } diff --git a/src/entropy/dev_random/dev_random.h b/src/entropy/dev_random/dev_random.h index 4386db7fe..d74412b27 100644 --- a/src/entropy/dev_random/dev_random.h +++ b/src/entropy/dev_random/dev_random.h @@ -29,7 +29,7 @@ class Device_EntropySource : public EntropySource private: typedef int fd_type; - std::vector<fd_type> devices; + std::vector<fd_type> m_devices; }; } diff --git a/src/entropy/proc_walk/info.txt b/src/entropy/proc_walk/info.txt index 9039f0ad9..d8c60a2a7 100644 --- a/src/entropy/proc_walk/info.txt +++ b/src/entropy/proc_walk/info.txt @@ -1,11 +1,11 @@ -define ENTROPY_SRC_FTW +define ENTROPY_SRC_PROC_WALKER <source> -es_ftw.cpp +proc_walk.cpp </source> <header:internal> -es_ftw.h +proc_walk.h </header:internal> <os> diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/proc_walk.cpp index 7d72e7752..050d9dcf7 100644 --- a/src/entropy/proc_walk/es_ftw.cpp +++ b/src/entropy/proc_walk/proc_walk.cpp @@ -1,11 +1,13 @@ /* -* FTW EntropySource +* Entropy source based on reading files in /proc on the assumption +* that a remote attacker will have difficulty guessing some of them. +* * (C) 1999-2008,2012 Jack Lloyd * * Distributed under the terms of the Botan license */ -#include <botan/internal/es_ftw.h> +#include <botan/internal/proc_walk.h> #include <botan/secmem.h> #include <cstring> #include <deque> @@ -129,39 +131,31 @@ int Directory_Walker::next_fd() } /** -* FTW_EntropySource Constructor -*/ -FTW_EntropySource::FTW_EntropySource(const std::string& p) : path(p), dir(nullptr) - { - } - -/** -* FTW_EntropySource Destructor +* ProcWalking_EntropySource Destructor */ -FTW_EntropySource::~FTW_EntropySource() +ProcWalking_EntropySource::~ProcWalking_EntropySource() { - delete dir; - dir = nullptr; + // for ~unique_ptr } -void FTW_EntropySource::poll(Entropy_Accumulator& accum) +void ProcWalking_EntropySource::poll(Entropy_Accumulator& accum) { const size_t MAX_FILES_READ_PER_POLL = 2048; - if(!dir) - dir = new Directory_Walker(path); + if(!m_dir) + m_dir = new Directory_Walker(m_path); secure_vector<byte>& io_buffer = accum.get_io_buffer(4096); for(size_t i = 0; i != MAX_FILES_READ_PER_POLL; ++i) { - int fd = dir->next_fd(); + int fd = m_dir->next_fd(); // If we've exhaused this walk of the directory, halt the poll if(fd == -1) { - delete dir; - dir = nullptr; + delete m_dir; + m_dir = nullptr; break; } diff --git a/src/entropy/proc_walk/es_ftw.h b/src/entropy/proc_walk/proc_walk.h index 3ba222d46..e493c7ed2 100644 --- a/src/entropy/proc_walk/es_ftw.h +++ b/src/entropy/proc_walk/proc_walk.h @@ -5,28 +5,30 @@ * Distributed under the terms of the Botan license */ -#ifndef BOTAN_ENTROPY_SRC_FTW_H__ -#define BOTAN_ENTROPY_SRC_FTW_H__ +#ifndef BOTAN_ENTROPY_SRC_PROC_WALK_H__ +#define BOTAN_ENTROPY_SRC_PROC_WALK_H__ #include <botan/entropy_src.h> +#include <memory> namespace Botan { /** * File Tree Walking Entropy Source */ -class FTW_EntropySource : public EntropySource +class ProcWalking_EntropySource : public EntropySource { public: std::string name() const { return "Proc Walker"; } void poll(Entropy_Accumulator& accum); - FTW_EntropySource(const std::string& root_dir); - ~FTW_EntropySource(); + ProcWalking_EntropySource(const std::string& root_dir) : m_path(root_dir) {} + + ~ProcWalking_EntropySource(); private: - std::string path; - class File_Descriptor_Source* dir; + const std::string m_path; + class File_Descriptor_Source* m_dir; }; } diff --git a/src/libstate/global_rng.cpp b/src/libstate/global_rng.cpp index 38b8ec559..631d81bce 100644 --- a/src/libstate/global_rng.cpp +++ b/src/libstate/global_rng.cpp @@ -23,8 +23,8 @@ #include <botan/internal/es_egd.h> #endif -#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX) - #include <botan/internal/es_unix.h> +#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) + #include <botan/internal/unix_procs.h> #endif #if defined(BOTAN_HAS_ENTROPY_SRC_BEOS) @@ -39,8 +39,8 @@ #include <botan/internal/es_win32.h> #endif -#if defined(BOTAN_HAS_ENTROPY_SRC_FTW) - #include <botan/internal/es_ftw.h> +#if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER) + #include <botan/internal/proc_walk.h> #endif namespace Botan { @@ -67,8 +67,9 @@ std::vector<std::unique_ptr<EntropySource>> Library_State::entropy_sources() sources.push_back(std::unique_ptr<EntropySource>(new Win32_CAPI_EntropySource)); #endif -#if defined(BOTAN_HAS_ENTROPY_SRC_FTW) - sources.push_back(std::unique_ptr<EntropySource>(new FTW_EntropySource("/proc"))); +#if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER) + sources.push_back(std::unique_ptr<EntropySource>( + new ProcWalking_EntropySource("/proc"))); #endif #if defined(BOTAN_HAS_ENTROPY_SRC_WIN32) @@ -79,7 +80,7 @@ std::vector<std::unique_ptr<EntropySource>> Library_State::entropy_sources() sources.push_back(std::unique_ptr<EntropySource>(new BeOS_EntropySource)); #endif -#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX) +#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) sources.push_back(std::unique_ptr<EntropySource>( new Unix_EntropySource( { "/bin", "/sbin", "/usr/bin", "/usr/sbin" } @@ -88,7 +89,7 @@ std::vector<std::unique_ptr<EntropySource>> Library_State::entropy_sources() #if defined(BOTAN_HAS_ENTROPY_SRC_EGD) sources.push_back(std::unique_ptr<EntropySource>( - new EGD_EntropySource({ "/var/run/egd-pool" "/dev/egd-pool" }) + new EGD_EntropySource({ "/var/run/egd-pool", "/dev/egd-pool" }) )); #endif |