diff options
author | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
commit | 0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch) | |
tree | ed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/entropy/entropy_srcs.cpp | |
parent | f9a7c85b74be0f4a7273e8e0591703af83036e81 (diff) |
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry
The shared pool of entropy sources remains but is moved to EntropySource.
With that and few remaining initializations (default OIDs and aliases)
moved elsewhere, the global state is empty and init and shutdown are no-ops.
Remove almost all of the headers and code for handling the global
state, except LibraryInitializer which remains as a compatability stub.
Update seeding for blinding so only one hacky almost-global RNG
instance needs to be setup instead of across all pubkey uses (it uses
either the system RNG or an AutoSeeded_RNG if the system RNG is not
available).
Diffstat (limited to 'src/lib/entropy/entropy_srcs.cpp')
-rw-r--r-- | src/lib/entropy/entropy_srcs.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/lib/entropy/entropy_srcs.cpp b/src/lib/entropy/entropy_srcs.cpp new file mode 100644 index 000000000..67bced409 --- /dev/null +++ b/src/lib/entropy/entropy_srcs.cpp @@ -0,0 +1,126 @@ +/* +* Entropy Source Polling +* (C) 2008-2010,2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include <botan/entropy_src.h> + +#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER) + #include <botan/internal/hres_timer.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND) + #include <botan/internal/rdrand.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM) + #include <botan/internal/dev_random.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_EGD) + #include <botan/internal/es_egd.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) + #include <botan/internal/unix_procs.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_BEOS) + #include <botan/internal/es_beos.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_CAPI) + #include <botan/internal/es_capi.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32) + #include <botan/internal/es_win32.h> +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER) + #include <botan/internal/proc_walk.h> +#endif + +namespace Botan { + +namespace { + +std::vector<std::unique_ptr<EntropySource>> get_default_entropy_sources() + { + std::vector<std::unique_ptr<EntropySource>> sources; + +#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER) + sources.push_back(std::unique_ptr<EntropySource>(new High_Resolution_Timestamp)); +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND) + sources.push_back(std::unique_ptr<EntropySource>(new Intel_Rdrand)); +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) + sources.push_back(std::unique_ptr<EntropySource>(new UnixProcessInfo_EntropySource)); +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM) + sources.push_back(std::unique_ptr<EntropySource>(new Device_EntropySource( + { "/dev/random", "/dev/srandom", "/dev/urandom" } + ))); +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_CAPI) + sources.push_back(std::unique_ptr<EntropySource>(new Win32_CAPI_EntropySource)); +#endif + +#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) + sources.push_back(std::unique_ptr<EntropySource>(new Win32_EntropySource)); +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_BEOS) + sources.push_back(std::unique_ptr<EntropySource>(new BeOS_EntropySource)); +#endif + +#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" } + ))); +#endif + +#if defined(BOTAN_HAS_ENTROPY_SRC_EGD) + sources.push_back(std::unique_ptr<EntropySource>( + new EGD_EntropySource({ "/var/run/egd-pool", "/dev/egd-pool" }) + )); +#endif + + return sources; + } + +} + +//static +void EntropySource::poll_available_sources(class Entropy_Accumulator& accum) + { + static std::vector<std::unique_ptr<EntropySource>> g_sources(get_default_entropy_sources()); + + if(g_sources.empty()) + throw std::runtime_error("No entropy sources enabled at build time, poll failed"); + + size_t poll_attempt = 0; + + while(!accum.polling_goal_achieved() && poll_attempt < 16) + { + const size_t src_idx = poll_attempt % g_sources.size(); + g_sources[src_idx]->poll(accum); + ++poll_attempt; + } + } + +} + |