/************************************************* * Load modules * *************************************************/ void Library_State::load(Modules& modules) { #ifndef BOTAN_TOOLS_ONLY set_timer(modules.timer()); set_transcoder(modules.transcoder()); #endif std::vector<Allocator*> mod_allocs = modules.allocators(); for(u32bit j = 0; j != mod_allocs.size(); j++) add_allocator(mod_allocs[j]); set_default_allocator(modules.default_allocator()); #ifndef BOTAN_TOOLS_ONLY std::vector<Engine*> mod_engines = modules.engines(); for(u32bit j = 0; j != mod_engines.size(); ++j) { Named_Mutex_Holder lock("engine"); 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]); #endif }
/* * Load a set of modules */ void Library_State::initialize(bool thread_safe) { CPUID::initialize(); if(mutex_factory) throw Invalid_State("Library_State has already been initialized"); if(!thread_safe) { mutex_factory = new Noop_Mutex_Factory; } else { #if defined(BOTAN_HAS_MUTEX_PTHREAD) mutex_factory = new Pthread_Mutex_Factory; #elif defined(BOTAN_HAS_MUTEX_WIN32) mutex_factory = new Win32_Mutex_Factory; #else throw Invalid_State("Could not find a thread-safe mutex object to use"); #endif } allocator_lock = get_mutex(); config_lock = get_mutex(); global_rng_lock = get_mutex(); default_allocator_name = has_mlock() ? "locking" : "malloc"; add_allocator(new Malloc_Allocator); add_allocator(new Locking_Allocator(get_mutex())); #if defined(BOTAN_HAS_ALLOC_MMAP) add_allocator(new MemoryMapping_Allocator(get_mutex())); #endif load_default_config(); m_algorithm_factory = new Algorithm_Factory(*mutex_factory); #if defined(BOTAN_HAS_ENGINE_GNU_MP) algorithm_factory().add_engine(new GMP_Engine); #endif #if defined(BOTAN_HAS_ENGINE_OPENSSL) algorithm_factory().add_engine(new OpenSSL_Engine); #endif #if defined(BOTAN_HAS_ENGINE_AES_ISA) algorithm_factory().add_engine(new AES_ISA_Engine); #endif #if defined(BOTAN_HAS_ENGINE_SIMD) algorithm_factory().add_engine(new SIMD_Engine); #endif #if defined(BOTAN_HAS_ENGINE_ASSEMBLER) algorithm_factory().add_engine(new Assembler_Engine); #endif algorithm_factory().add_engine(new Core_Engine); #if defined(BOTAN_HAS_SELFTESTS) confirm_startup_self_tests(algorithm_factory()); #endif }