diff options
Diffstat (limited to 'src/libstate/libstate.cpp')
-rw-r--r-- | src/libstate/libstate.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 7706cef28..c62bd08db 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -214,8 +214,8 @@ std::string Library_State::deref_alias(const std::string& key) const return result; } -/** -Return a reference to the Algorithm_Factory +/* +* Return a reference to the Algorithm_Factory */ Algorithm_Factory& Library_State::algorithm_factory() const { @@ -225,6 +225,20 @@ Algorithm_Factory& Library_State::algorithm_factory() const } /* +* Return a reference to the global PRNG +*/ +RandomNumberGenerator& Library_State::global_rng() + { + Mutex_Holder lock(global_rng_lock); + + if(!global_rng_ptr) + global_rng_ptr = make_global_rng(algorithm_factory(), + global_rng_lock); + + return *global_rng_ptr; + } + +/* * Load a set of modules */ void Library_State::initialize(bool thread_safe) @@ -249,17 +263,20 @@ void Library_State::initialize(bool thread_safe) #endif } - allocator_lock = mutex_factory->make(); - config_lock = mutex_factory->make(); + allocator_lock = get_mutex(); + config_lock = get_mutex(); + global_rng_lock = get_mutex(); + + global_rng_ptr = 0; cached_default_allocator = 0; default_allocator_name = has_mlock() ? "locking" : "malloc"; add_allocator(new Malloc_Allocator); - add_allocator(new Locking_Allocator(mutex_factory->make())); + add_allocator(new Locking_Allocator(get_mutex())); #if defined(BOTAN_HAS_ALLOC_MMAP) - add_allocator(new MemoryMapping_Allocator(mutex_factory->make())); + add_allocator(new MemoryMapping_Allocator(get_mutex())); #endif load_default_config(); |