aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/engine/dyn_engine
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-10 03:41:59 +0000
committerlloyd <[email protected]>2014-01-10 03:41:59 +0000
commit6894dca64c04936d07048c0e8cbf7e25858548c3 (patch)
tree5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/engine/dyn_engine
parent9efa3be92442afb3d0b69890a36c7f122df18eda (diff)
Move lib into src
Diffstat (limited to 'src/lib/engine/dyn_engine')
-rw-r--r--src/lib/engine/dyn_engine/dyn_engine.cpp63
-rw-r--r--src/lib/engine/dyn_engine/dyn_engine.h115
-rw-r--r--src/lib/engine/dyn_engine/info.txt14
3 files changed, 192 insertions, 0 deletions
diff --git a/src/lib/engine/dyn_engine/dyn_engine.cpp b/src/lib/engine/dyn_engine/dyn_engine.cpp
new file mode 100644
index 000000000..078ec4b83
--- /dev/null
+++ b/src/lib/engine/dyn_engine/dyn_engine.cpp
@@ -0,0 +1,63 @@
+/**
+* Dynamically Loaded Engine
+* (C) 2010 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/dyn_engine.h>
+#include <botan/internal/dyn_load.h>
+
+namespace Botan {
+
+namespace {
+
+extern "C" {
+ typedef Engine* (*creator_func)(void);
+ typedef u32bit (*module_version_func)(void);
+}
+
+}
+
+Dynamically_Loaded_Engine::Dynamically_Loaded_Engine(
+ const std::string& library_path) :
+ engine(nullptr)
+ {
+ lib = new Dynamically_Loaded_Library(library_path);
+
+ try
+ {
+ module_version_func get_version =
+ lib->resolve<module_version_func>("module_version");
+
+ const u32bit mod_version = get_version();
+
+ if(mod_version != 20101003)
+ throw std::runtime_error("Incompatible version in " +
+ library_path + " of " +
+ std::to_string(mod_version));
+
+ creator_func creator =
+ lib->resolve<creator_func>("create_engine");
+
+ engine = creator();
+
+ if(!engine)
+ throw std::runtime_error("Creator function in " +
+ library_path + " failed");
+ }
+ catch(...)
+ {
+ delete lib;
+ lib = nullptr;
+ throw;
+ }
+ }
+
+Dynamically_Loaded_Engine::~Dynamically_Loaded_Engine()
+ {
+ delete engine;
+ delete lib;
+ }
+
+}
diff --git a/src/lib/engine/dyn_engine/dyn_engine.h b/src/lib/engine/dyn_engine/dyn_engine.h
new file mode 100644
index 000000000..39e13ab36
--- /dev/null
+++ b/src/lib/engine/dyn_engine/dyn_engine.h
@@ -0,0 +1,115 @@
+/**
+* Dynamically Loaded Engine
+* (C) 2010 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_DYN_LOADED_ENGINE_H__
+#define BOTAN_DYN_LOADED_ENGINE_H__
+
+#include <botan/engine.h>
+
+namespace Botan {
+
+/**
+* Dynamically_Loaded_Engine just proxies the requests to the underlying
+* Engine object, and handles load/unload details
+*/
+class BOTAN_DLL Dynamically_Loaded_Engine : public Engine
+ {
+ public:
+ /**
+ * @param lib_path full pathname to DLL to load
+ */
+ Dynamically_Loaded_Engine(const std::string& lib_path);
+
+ Dynamically_Loaded_Engine(const Dynamically_Loaded_Engine&) = delete;
+
+ Dynamically_Loaded_Engine& operator=(const Dynamically_Loaded_Engine&) = delete;
+
+ ~Dynamically_Loaded_Engine();
+
+ std::string provider_name() const override { return engine->provider_name(); }
+
+ BlockCipher* find_block_cipher(const SCAN_Name& algo_spec,
+ Algorithm_Factory& af) const override
+ {
+ return engine->find_block_cipher(algo_spec, af);
+ }
+
+ StreamCipher* find_stream_cipher(const SCAN_Name& algo_spec,
+ Algorithm_Factory& af) const override
+ {
+ return engine->find_stream_cipher(algo_spec, af);
+ }
+
+ HashFunction* find_hash(const SCAN_Name& algo_spec,
+ Algorithm_Factory& af) const override
+ {
+ return engine->find_hash(algo_spec, af);
+ }
+
+ MessageAuthenticationCode* find_mac(const SCAN_Name& algo_spec,
+ Algorithm_Factory& af) const override
+ {
+ return engine->find_mac(algo_spec, af);
+ }
+
+ PBKDF* find_pbkdf(const SCAN_Name& algo_spec,
+ Algorithm_Factory& af) const override
+ {
+ return engine->find_pbkdf(algo_spec, af);
+ }
+
+ Modular_Exponentiator* mod_exp(const BigInt& n,
+ Power_Mod::Usage_Hints hints) const override
+ {
+ return engine->mod_exp(n, hints);
+ }
+
+ Keyed_Filter* get_cipher(const std::string& algo_spec,
+ Cipher_Dir dir,
+ Algorithm_Factory& af)
+ {
+ return engine->get_cipher(algo_spec, dir, af);
+ }
+
+ PK_Ops::Key_Agreement*
+ get_key_agreement_op(const Private_Key& key, RandomNumberGenerator& rng) const override
+ {
+ return engine->get_key_agreement_op(key, rng);
+ }
+
+ PK_Ops::Signature*
+ get_signature_op(const Private_Key& key, RandomNumberGenerator& rng) const override
+ {
+ return engine->get_signature_op(key, rng);
+ }
+
+ PK_Ops::Verification*
+ get_verify_op(const Public_Key& key, RandomNumberGenerator& rng) const override
+ {
+ return engine->get_verify_op(key, rng);
+ }
+
+ PK_Ops::Encryption*
+ get_encryption_op(const Public_Key& key, RandomNumberGenerator& rng) const override
+ {
+ return engine->get_encryption_op(key, rng);
+ }
+
+ PK_Ops::Decryption*
+ get_decryption_op(const Private_Key& key, RandomNumberGenerator& rng) const override
+ {
+ return engine->get_decryption_op(key, rng);
+ }
+
+ private:
+ class Dynamically_Loaded_Library* lib;
+ Engine* engine;
+ };
+
+}
+
+#endif
diff --git a/src/lib/engine/dyn_engine/info.txt b/src/lib/engine/dyn_engine/info.txt
new file mode 100644
index 000000000..54379f501
--- /dev/null
+++ b/src/lib/engine/dyn_engine/info.txt
@@ -0,0 +1,14 @@
+define DYNAMICALLY_LOADED_ENGINE 20131128
+
+<header:public>
+dyn_engine.h
+</header:public>
+
+<source>
+dyn_engine.cpp
+</source>
+
+<requires>
+engine
+dyn_load
+</requires>