diff options
author | lloyd <[email protected]> | 2014-01-01 21:20:55 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-01 21:20:55 +0000 |
commit | 197dc467dec28a04c3b2f30da7cef122dfbb13e9 (patch) | |
tree | cdbd3ddaec051c72f0a757db461973d90c37b97a /src/entropy/dev_random | |
parent | 62faac373c07cfe10bc8c309e89ebdd30d8e5eaa (diff) |
Shuffle things around. Add NIST X.509 test to build.
Diffstat (limited to 'src/entropy/dev_random')
-rw-r--r-- | src/entropy/dev_random/dev_random.cpp | 97 | ||||
-rw-r--r-- | src/entropy/dev_random/dev_random.h | 37 | ||||
-rw-r--r-- | src/entropy/dev_random/info.txt | 27 |
3 files changed, 0 insertions, 161 deletions
diff --git a/src/entropy/dev_random/dev_random.cpp b/src/entropy/dev_random/dev_random.cpp deleted file mode 100644 index 3f8df8749..000000000 --- a/src/entropy/dev_random/dev_random.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -* Reader of /dev/random and company -* (C) 1999-2009,2013 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/internal/dev_random.h> -#include <botan/internal/rounding.h> - -#include <sys/types.h> -#include <sys/select.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> - -namespace Botan { - -/** -Device_EntropySource constructor -Open a file descriptor to each (available) device in fsnames -*/ -Device_EntropySource::Device_EntropySource(const std::vector<std::string>& fsnames) - { -#ifndef O_NONBLOCK - #define O_NONBLOCK 0 -#endif - -#ifndef O_NOCTTY - #define O_NOCTTY 0 -#endif - - const int flags = O_RDONLY | O_NONBLOCK | O_NOCTTY; - - for(auto fsname : fsnames) - { - fd_type fd = ::open(fsname.c_str(), flags); - - if(fd >= 0 && fd < FD_SETSIZE) - m_devices.push_back(fd); - else if(fd >= 0) - ::close(fd); - } - } - -/** -Device_EntropySource destructor: close all open devices -*/ -Device_EntropySource::~Device_EntropySource() - { - for(size_t i = 0; i != m_devices.size(); ++i) - ::close(m_devices[i]); - } - -/** -* Gather entropy from a RNG device -*/ -void Device_EntropySource::poll(Entropy_Accumulator& accum) - { - 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 = m_devices[0]; - fd_set read_set; - FD_ZERO(&read_set); - for(size_t i = 0; i != m_devices.size(); ++i) - { - FD_SET(m_devices[i], &read_set); - max_fd = std::max(m_devices[i], max_fd); - } - - struct ::timeval timeout; - - timeout.tv_sec = (MS_WAIT_TIME / 1000); - timeout.tv_usec = (MS_WAIT_TIME % 1000) * 1000; - - if(::select(max_fd + 1, &read_set, nullptr, nullptr, &timeout) < 0) - return; - - secure_vector<byte>& io_buffer = accum.get_io_buffer(READ_ATTEMPT); - - for(size_t i = 0; i != m_devices.size(); ++i) - { - if(FD_ISSET(m_devices[i], &read_set)) - { - 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 deleted file mode 100644 index d74412b27..000000000 --- a/src/entropy/dev_random/dev_random.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* /dev/random EntropySource -* (C) 1999-2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ENTROPY_SRC_DEVICE_H__ -#define BOTAN_ENTROPY_SRC_DEVICE_H__ - -#include <botan/entropy_src.h> -#include <vector> -#include <string> - -namespace Botan { - -/** -* Entropy source reading from kernel devices like /dev/random -*/ -class Device_EntropySource : public EntropySource - { - public: - std::string name() const { return "RNG Device Reader"; } - - void poll(Entropy_Accumulator& accum); - - Device_EntropySource(const std::vector<std::string>& fsnames); - ~Device_EntropySource(); - private: - typedef int fd_type; - - std::vector<fd_type> m_devices; - }; - -} - -#endif diff --git a/src/entropy/dev_random/info.txt b/src/entropy/dev_random/info.txt deleted file mode 100644 index 98a6a7e61..000000000 --- a/src/entropy/dev_random/info.txt +++ /dev/null @@ -1,27 +0,0 @@ -define ENTROPY_SRC_DEV_RANDOM 20131128 - -<source> -dev_random.cpp -</source> - -<header:internal> -dev_random.h -</header:internal> - -<os> -aix -cygwin -darwin -dragonfly -freebsd -haiku -hpux -hurd -irix -linux -netbsd -openbsd -qnx -solaris -tru64 -</os> |