/* * Library Internal/Global State * (C) 1999-2010 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include #include #include #include #include #include #include #include #if defined(BOTAN_HAS_SELFTESTS) #include #endif #if defined(BOTAN_HAS_ENGINE_ASSEMBLER) #include #endif #if defined(BOTAN_HAS_ENGINE_AES_ISA) #include #endif #if defined(BOTAN_HAS_ENGINE_SIMD) #include #endif #if defined(BOTAN_HAS_ENGINE_GNU_MP) #include #endif #if defined(BOTAN_HAS_ENGINE_OPENSSL) #include #endif namespace Botan { /* * Return a reference to the Algorithm_Factory */ Algorithm_Factory& Library_State::algorithm_factory() const { if(!m_algorithm_factory) throw Invalid_State("Uninitialized in Library_State::algorithm_factory"); return *m_algorithm_factory; } /* * Return a reference to the global PRNG */ RandomNumberGenerator& Library_State::global_rng() { return *m_global_prng; } void Library_State::initialize() { if(m_algorithm_factory.get()) throw Invalid_State("Library_State has already been initialized"); CPUID::initialize(); SCAN_Name::set_default_aliases(); OIDS::set_defaults(); m_algorithm_factory.reset(new Algorithm_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); m_sources = entropy_sources(); m_global_prng.reset(new Serialized_RNG()); #if defined(BOTAN_HAS_SELFTESTS) confirm_startup_self_tests(algorithm_factory()); #endif } }