8 #include <botan/libstate.h>
9 #include <botan/charset.h>
10 #include <botan/engine.h>
11 #include <botan/cpuid.h>
12 #include <botan/internal/defalloc.h>
13 #include <botan/internal/core_engine.h>
14 #include <botan/internal/mutex.h>
15 #include <botan/internal/mux_noop.h>
16 #include <botan/internal/stl_util.h>
17 #include <botan/internal/mlock.h>
20 #if defined(BOTAN_HAS_SELFTESTS)
21 #include <botan/selftest.h>
24 #if defined(BOTAN_HAS_MUTEX_PTHREAD)
25 #include <botan/internal/mux_pthr.h>
26 #elif defined(BOTAN_HAS_MUTEX_WIN32)
27 #include <botan/internal/mux_win32.h>
30 #if defined(BOTAN_HAS_ALLOC_MMAP)
31 #include <botan/internal/mmap_mem.h>
34 #if defined(BOTAN_HAS_ENGINE_ASSEMBLER)
35 #include <botan/internal/asm_engine.h>
38 #if defined(BOTAN_HAS_ENGINE_AES_ISA)
39 #include <botan/internal/aes_isa_engine.h>
42 #if defined(BOTAN_HAS_ENGINE_SIMD)
43 #include <botan/internal/simd_engine.h>
46 #if defined(BOTAN_HAS_ENGINE_GNU_MP)
47 #include <botan/internal/gnump_engine.h>
50 #if defined(BOTAN_HAS_ENGINE_OPENSSL)
51 #include <botan/internal/openssl_engine.h>
61 return mutex_factory->
make();
72 return search_map<std::string, Allocator*>(alloc_factory, type, 0);
74 if(!cached_default_allocator)
76 cached_default_allocator =
77 search_map<std::string, Allocator*>(alloc_factory,
78 default_allocator_name, 0);
81 return cached_default_allocator;
93 allocators.push_back(allocator);
94 alloc_factory[allocator->
type()] = allocator;
107 default_allocator_name = type;
108 cached_default_allocator = 0;
115 const std::string& key)
const
119 return search_map<std::string, std::string>(config,
120 section +
"/" + key,
"");
127 const std::string& key)
const
131 return config.count(section +
"/" + key) != 0;
138 const std::string& value,
bool overwrite)
142 std::string full_key = section +
"/" + key;
144 std::map<std::string, std::string>::const_iterator i =
145 config.find(full_key);
147 if(overwrite || i == config.end() || i->second ==
"")
148 config[full_key] = value;
156 set(
"alias", key, value);
164 std::string result = key;
165 while(
is_set(
"alias", result))
166 result =
get(
"alias", result);
175 if(!m_algorithm_factory)
176 throw Invalid_State(
"Uninitialized in Library_State::algorithm_factory");
177 return *m_algorithm_factory;
191 return *global_rng_ptr;
202 throw Invalid_State(
"Library_State has already been initialized");
210 #if defined(BOTAN_HAS_MUTEX_PTHREAD)
212 #elif defined(BOTAN_HAS_MUTEX_WIN32)
215 throw Invalid_State(
"Could not find a thread-safe mutex object to use");
223 default_allocator_name =
has_mlock() ?
"locking" :
"malloc";
228 #if defined(BOTAN_HAS_ALLOC_MMAP)
232 load_default_config();
236 #if defined(BOTAN_HAS_ENGINE_GNU_MP)
240 #if defined(BOTAN_HAS_ENGINE_OPENSSL)
244 #if defined(BOTAN_HAS_ENGINE_AES_ISA)
248 #if defined(BOTAN_HAS_ENGINE_SIMD)
252 #if defined(BOTAN_HAS_ENGINE_ASSEMBLER)
258 #if defined(BOTAN_HAS_SELFTESTS)
269 allocator_lock = config_lock = 0;
270 cached_default_allocator = 0;
271 m_algorithm_factory = 0;
282 delete m_algorithm_factory;
283 delete global_rng_ptr;
285 cached_default_allocator = 0;
287 for(
size_t i = 0; i != allocators.size(); ++i)
289 allocators[i]->destroy();
290 delete allocators[i];
293 delete global_rng_lock;
294 delete allocator_lock;
295 delete mutex_factory;
RandomNumberGenerator & global_rng()
void confirm_startup_self_tests(Algorithm_Factory &af)
void set_default_allocator(const std::string &name)
Mutex * get_mutex() const
Algorithm_Factory & algorithm_factory() const
Allocator * get_allocator(const std::string &name="") const
void initialize(bool thread_safe)
bool is_set(const std::string §ion, const std::string &key) const
std::string deref_alias(const std::string &alias) const
virtual std::string type() const =0
void add_allocator(Allocator *alloc)
void add_engine(Engine *engine)
void set(const std::string §ion, const std::string &key, const std::string &value, bool overwrite=true)
void add_alias(const std::string &key, const std::string &value)
std::string get(const std::string §ion, const std::string &key) const