From 6894dca64c04936d07048c0e8cbf7e25858548c3 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 10 Jan 2014 03:41:59 +0000 Subject: Move lib into src --- src/lib/engine/dyn_engine/dyn_engine.cpp | 63 +++++++++++++++++ src/lib/engine/dyn_engine/dyn_engine.h | 115 +++++++++++++++++++++++++++++++ src/lib/engine/dyn_engine/info.txt | 14 ++++ 3 files changed, 192 insertions(+) create mode 100644 src/lib/engine/dyn_engine/dyn_engine.cpp create mode 100644 src/lib/engine/dyn_engine/dyn_engine.h create mode 100644 src/lib/engine/dyn_engine/info.txt (limited to 'src/lib/engine/dyn_engine') 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 +#include + +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"); + + 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("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 + +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 + + +dyn_engine.h + + + +dyn_engine.cpp + + + +engine +dyn_load + -- cgit v1.2.3