aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/libstate/modules.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-30 21:13:38 +0000
committerlloyd <[email protected]>2008-09-30 21:13:38 +0000
commit3f0d484096e1e782f72e3cdf43853c7d9f309ee9 (patch)
tree341f05d66128321304aafc72df28854650e13ef1 /src/core/libstate/modules.cpp
parentb8115f4123a55510ab4f4840efb623de662a248f (diff)
parenta2c9be1a6bf801aac4d6d32759d51608f536d14a (diff)
propagate from branch 'net.randombit.botan' (head 9524e848cdacd0b56ded9bd6b51fd34b6a7d3fc4)
to branch 'net.randombit.botan.ecdsa' (head 8231f4285dce2d5ec754f7afa72e0d34807de061)
Diffstat (limited to 'src/core/libstate/modules.cpp')
-rw-r--r--src/core/libstate/modules.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/core/libstate/modules.cpp b/src/core/libstate/modules.cpp
new file mode 100644
index 000000000..bdebc3460
--- /dev/null
+++ b/src/core/libstate/modules.cpp
@@ -0,0 +1,126 @@
+/*************************************************
+* Module Factory Source File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/modules.h>
+#include <botan/defalloc.h>
+#include <botan/eng_def.h>
+#include <botan/parsing.h>
+
+#if defined(BOTAN_HAS_MUTEX_PTHREAD)
+ #include <botan/mux_pthr.h>
+#elif defined(BOTAN_HAS_MUTEX_WIN32)
+ #include <botan/mux_win32.h>
+#elif defined(BOTAN_HAS_MUTEX_QT)
+ #include <botan/mux_qt.h>
+#endif
+
+#if defined(BOTAN_HAS_MUTEX_NOOP)
+ #include <botan/mux_noop.h>
+#endif
+
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ #include <botan/mmap_mem.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_GNU_MP)
+ #include <botan/eng_gmp.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_OPENSSL)
+ #include <botan/eng_ossl.h>
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Return a mutex factory, if available *
+*************************************************/
+Mutex_Factory* Builtin_Modules::mutex_factory(bool thread_safe) const
+ {
+ if(!thread_safe)
+ {
+#if defined(BOTAN_HAS_MUTEX_NOOP)
+ return new Noop_Mutex_Factory;
+#endif
+ }
+
+#if defined(BOTAN_HAS_MUTEX_PTHREAD)
+ return new Pthread_Mutex_Factory;
+#elif defined(BOTAN_HAS_MUTEX_WIN32)
+ return new Win32_Mutex_Factory;
+#elif defined(BOTAN_HAS_MUTEX_QT)
+ return new Qt_Mutex_Factory;
+#else
+ return 0;
+#endif
+ }
+
+/*************************************************
+* Find any usable allocators *
+*************************************************/
+std::vector<Allocator*> Builtin_Modules::allocators(Mutex_Factory* mf) const
+ {
+ std::vector<Allocator*> allocators;
+
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ allocators.push_back(new MemoryMapping_Allocator(mf->make()));
+#endif
+
+ allocators.push_back(new Locking_Allocator(mf->make()));
+ allocators.push_back(new Malloc_Allocator);
+
+ return allocators;
+ }
+
+/*************************************************
+* Return the default allocator *
+*************************************************/
+std::string Builtin_Modules::default_allocator() const
+ {
+ if(should_lock)
+ {
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ return "mmap";
+#else
+ return "locking";
+#endif
+ }
+ else
+ return "malloc";
+ }
+
+/*************************************************
+* Find any usable engines *
+*************************************************/
+std::vector<Engine*> Builtin_Modules::engines() const
+ {
+ std::vector<Engine*> engines;
+
+ if(use_engines)
+ {
+#if defined(BOTAN_HAS_ENGINE_GNU_MP)
+ engines.push_back(new GMP_Engine);
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_OPENSSL)
+ engines.push_back(new OpenSSL_Engine);
+#endif
+ }
+
+ engines.push_back(new Default_Engine);
+
+ return engines;
+ }
+
+/*************************************************
+* Builtin_Modules Constructor *
+*************************************************/
+Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
+ should_lock(args.secure_memory()),
+ use_engines(args.use_engines())
+ {
+ }
+
+}