diff options
author | lloyd <[email protected]> | 2008-06-27 17:09:48 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-06-27 17:09:48 +0000 |
commit | e6a5313d766829e2f5f17763d148a26d1a358c05 (patch) | |
tree | 9f426437a3996a5a96d9cdb71897a69dfb5ad2ae | |
parent | 7861a5a673ab8176d8d89e3f69a4c5a0cd649485 (diff) |
Remove the global PRNG object as well as the global list of entropy sources.
-rw-r--r-- | include/init.h | 1 | ||||
-rw-r--r-- | include/libstate.h | 16 | ||||
-rw-r--r-- | src/init_opt.cpp | 8 | ||||
-rw-r--r-- | src/libstate.cpp | 110 |
4 files changed, 1 insertions, 134 deletions
diff --git a/include/init.h b/include/init.h index 85f47545f..f4296a868 100644 --- a/include/init.h +++ b/include/init.h @@ -20,7 +20,6 @@ class BOTAN_DLL InitializerOptions public: bool thread_safe() const; bool use_engines() const; - bool seed_rng() const; bool secure_memory() const; bool fips_mode() const; bool self_test() const; diff --git a/include/libstate.h b/include/libstate.h index 69f30a886..51be2431e 100644 --- a/include/libstate.h +++ b/include/libstate.h @@ -45,18 +45,6 @@ class BOTAN_DLL Library_State void add_allocator(Allocator*); void set_default_allocator(const std::string&) const; - bool rng_is_seeded() const { return rng->is_seeded(); } - void randomize(byte[], u32bit); - byte random(); - - void set_prng(RandomNumberGenerator*); - void add_entropy_source(EntropySource*, bool = true); - void add_entropy(const byte[], u32bit); - void add_entropy(EntropySource&, bool); - u32bit seed_prng(bool, u32bit); - - RandomNumberGenerator& prng_reference() { return (*rng); } - class Config& config() const; class Mutex* get_mutex() const; @@ -73,11 +61,7 @@ class BOTAN_DLL Library_State class Mutex* allocator_lock; std::map<std::string, Allocator*> alloc_factory; mutable Allocator* cached_default_allocator; - - class Mutex* rng_lock; - RandomNumberGenerator* rng; std::vector<Allocator*> allocators; - std::vector<EntropySource*> entropy_sources; class Mutex* engine_lock; std::vector<class Engine*> engines; diff --git a/src/init_opt.cpp b/src/init_opt.cpp index f84ac83c2..5c4fbee65 100644 --- a/src/init_opt.cpp +++ b/src/init_opt.cpp @@ -62,14 +62,6 @@ bool InitializerOptions::use_engines() const } /************************************************* -* Check if RNG seeding should be enabled * -*************************************************/ -bool InitializerOptions::seed_rng() const - { - return boolean_arg(args, "seed_rng", true); - } - -/************************************************* * Check if FIPS mode was requested * *************************************************/ bool InitializerOptions::fips_mode() const diff --git a/src/libstate.cpp b/src/libstate.cpp index 7751216cb..22156af79 100644 --- a/src/libstate.cpp +++ b/src/libstate.cpp @@ -122,89 +122,6 @@ void Library_State::set_default_allocator(const std::string& type) const } /************************************************* -* Set the global PRNG * -*************************************************/ -void Library_State::set_prng(RandomNumberGenerator* new_rng) - { - Mutex_Holder lock(rng_lock); - - delete rng; - rng = new_rng; - } - -/************************************************* -* Get bytes from the global PRNG * -*************************************************/ -void Library_State::randomize(byte out[], u32bit length) - { - Mutex_Holder lock(rng_lock); - - rng->randomize(out, length); - } - -/************************************************* -* Get a byte from the global PRNG * -*************************************************/ -byte Library_State::random() - { - byte out; - rng->randomize(&out, 1); - return out; - } - -/************************************************* -* Add a new entropy source to use * -*************************************************/ -void Library_State::add_entropy_source(EntropySource* src, bool last_in_list) - { - Mutex_Holder lock(rng_lock); - - if(last_in_list) - entropy_sources.push_back(src); - else - entropy_sources.insert(entropy_sources.begin(), src); - } - -/************************************************* -* Add some bytes of entropy to the global PRNG * -*************************************************/ -void Library_State::add_entropy(const byte in[], u32bit length) - { - Mutex_Holder lock(rng_lock); - - rng->add_entropy(in, length); - } - -/************************************************* -* Add some bytes of entropy to the global PRNG * -*************************************************/ -void Library_State::add_entropy(EntropySource& source, bool slow_poll) - { - Mutex_Holder lock(rng_lock); - - rng->add_entropy(source, slow_poll); - } - -/************************************************* -* Gather entropy for our PRNG object * -*************************************************/ -u32bit Library_State::seed_prng(bool slow_poll, u32bit bits_to_get) - { - Mutex_Holder lock(rng_lock); - - u32bit bits = 0; - for(u32bit j = 0; j != entropy_sources.size(); ++j) - { - bits += rng->add_entropy(*(entropy_sources[j]), slow_poll); - - if(bits_to_get && bits >= bits_to_get) - return bits; - } - - return bits; - } - -/************************************************* * Get an engine out of the list * *************************************************/ Engine* Library_State::get_engine_n(u32bit n) const @@ -255,7 +172,6 @@ void Library_State::initialize(const InitializerOptions& args, allocator_lock = get_mutex(); engine_lock = get_mutex(); - rng_lock = get_mutex(); cached_default_allocator = 0; @@ -269,26 +185,6 @@ void Library_State::initialize(const InitializerOptions& args, for(u32bit j = 0; j != mod_engines.size(); ++j) engines.push_back(mod_engines[j]); - std::vector<EntropySource*> sources = modules.entropy_sources(); - for(u32bit j = 0; j != sources.size(); ++j) - add_entropy_source(sources[j]); - - set_prng(new ANSI_X931_RNG("AES-256", - new Randpool("AES-256", "HMAC(SHA-256)"))); - - if(args.seed_rng()) - { - for(u32bit j = 0; j != 4; ++j) - { - seed_prng(true, 384); - if(rng_is_seeded()) - break; - } - - if(!rng_is_seeded()) - throw PRNG_Unseeded("Unable to collect sufficient entropy"); - } - if(args.fips_mode() || args.self_test()) { if(!passes_self_tests()) @@ -303,11 +199,10 @@ Library_State::Library_State() { mutex_factory = 0; - allocator_lock = engine_lock = rng_lock = 0; + allocator_lock = engine_lock = 0; config_obj = 0; - rng = 0; cached_default_allocator = 0; } @@ -316,11 +211,8 @@ Library_State::Library_State() *************************************************/ Library_State::~Library_State() { - delete rng; delete config_obj; - std::for_each(entropy_sources.begin(), entropy_sources.end(), - del_fun<EntropySource>()); std::for_each(engines.begin(), engines.end(), del_fun<Engine>()); cached_default_allocator = 0; |