diff options
author | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
commit | 0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch) | |
tree | ed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/engine | |
parent | f9a7c85b74be0f4a7273e8e0591703af83036e81 (diff) |
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry
The shared pool of entropy sources remains but is moved to EntropySource.
With that and few remaining initializations (default OIDs and aliases)
moved elsewhere, the global state is empty and init and shutdown are no-ops.
Remove almost all of the headers and code for handling the global
state, except LibraryInitializer which remains as a compatability stub.
Update seeding for blinding so only one hacky almost-global RNG
instance needs to be setup instead of across all pubkey uses (it uses
either the system RNG or an AutoSeeded_RNG if the system RNG is not
available).
Diffstat (limited to 'src/lib/engine')
27 files changed, 0 insertions, 1292 deletions
diff --git a/src/lib/engine/aes_isa_eng/aes_isa_engine.cpp b/src/lib/engine/aes_isa_eng/aes_isa_engine.cpp deleted file mode 100644 index d581b65ad..000000000 --- a/src/lib/engine/aes_isa_eng/aes_isa_engine.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -* Engine for AES instructions -* (C) 2009 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/aes_isa_engine.h> -#include <botan/algo_registry.h> - -namespace Botan { - -BlockCipher* -AES_ISA_Engine::find_block_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(BlockCipher* c = Algo_Registry<BlockCipher>::global_registry().make(request, "aes_ni")) - return c; - - return nullptr; - } - -} diff --git a/src/lib/engine/aes_isa_eng/aes_isa_engine.h b/src/lib/engine/aes_isa_eng/aes_isa_engine.h deleted file mode 100644 index 298574543..000000000 --- a/src/lib/engine/aes_isa_eng/aes_isa_engine.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Engine for AES instructions -* (C) 2009 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_AES_ISA_ENGINE_H__ -#define BOTAN_AES_ISA_ENGINE_H__ - -#include <botan/engine.h> - -namespace Botan { - -/** -* Engine for implementations that hook into CPU-specific -* AES implementations (eg AES-NI, VIA C7, or AMD Geode) -*/ -class AES_ISA_Engine : public Engine - { - public: - std::string provider_name() const { return "aes_isa"; } - - BlockCipher* find_block_cipher(const SCAN_Name&, - Algorithm_Factory&) const; - }; - -} - -#endif diff --git a/src/lib/engine/aes_isa_eng/info.txt b/src/lib/engine/aes_isa_eng/info.txt deleted file mode 100644 index 4284e75bd..000000000 --- a/src/lib/engine/aes_isa_eng/info.txt +++ /dev/null @@ -1,11 +0,0 @@ -define ENGINE_AES_ISA 20131128 - -load_on dep - -<source> -aes_isa_engine.cpp -</source> - -<header:internal> -aes_isa_engine.h -</header:internal> diff --git a/src/lib/engine/asm_engine/asm_engine.cpp b/src/lib/engine/asm_engine/asm_engine.cpp deleted file mode 100644 index d30bae035..000000000 --- a/src/lib/engine/asm_engine/asm_engine.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Assembly Implementation Engine -* (C) 1999-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/asm_engine.h> -#include <botan/algo_registry.h> - -namespace Botan { - -BlockCipher* -Assembler_Engine::find_block_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { - auto& block_cipher = Algo_Registry<BlockCipher>::global_registry(); - - if(BlockCipher* c = block_cipher.make(request, "x86-32")) - return c; - - return nullptr; - } - -HashFunction* -Assembler_Engine::find_hash(const SCAN_Name& request, - Algorithm_Factory&) const - { - auto& hash_fns = Algo_Registry<HashFunction>::global_registry(); - if(HashFunction* c = hash_fns.make(request, "x86-64")) - return c; - - if(HashFunction* c = hash_fns.make(request, "x86-32")) - return c; - - return nullptr; - } - -} diff --git a/src/lib/engine/asm_engine/asm_engine.h b/src/lib/engine/asm_engine/asm_engine.h deleted file mode 100644 index 02e629e98..000000000 --- a/src/lib/engine/asm_engine/asm_engine.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Assembly Implementation Engine -* (C) 1999-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_X86_32_ASM_ENGINE_H__ -#define BOTAN_X86_32_ASM_ENGINE_H__ - -#include <botan/engine.h> - -namespace Botan { - -/** -* Engine for x86-32 specific implementations -*/ -class Assembler_Engine : public Engine - { - public: - std::string provider_name() const { return "asm"; } - - BlockCipher* find_block_cipher(const SCAN_Name&, - Algorithm_Factory&) const; - - HashFunction* find_hash(const SCAN_Name& request, - Algorithm_Factory&) const; - }; - -} - -#endif diff --git a/src/lib/engine/asm_engine/info.txt b/src/lib/engine/asm_engine/info.txt deleted file mode 100644 index 185656e3d..000000000 --- a/src/lib/engine/asm_engine/info.txt +++ /dev/null @@ -1,11 +0,0 @@ -define ENGINE_ASSEMBLER 20131128 - -load_on dep - -<source> -asm_engine.cpp -</source> - -<header:internal> -asm_engine.h -</header:internal> diff --git a/src/lib/engine/core_engine/core_engine.h b/src/lib/engine/core_engine/core_engine.h deleted file mode 100644 index c98ee031b..000000000 --- a/src/lib/engine/core_engine/core_engine.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Core Engine -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_CORE_ENGINE_H__ -#define BOTAN_CORE_ENGINE_H__ - -#include <botan/engine.h> - -namespace Botan { - -/** -* Core Engine -*/ -class Core_Engine : public Engine - { - public: - std::string provider_name() const override { return "core"; } - - BlockCipher* find_block_cipher(const SCAN_Name&, - Algorithm_Factory&) const override; - - StreamCipher* find_stream_cipher(const SCAN_Name&, - Algorithm_Factory&) const override; - - HashFunction* find_hash(const SCAN_Name& request, - Algorithm_Factory&) const override; - - MessageAuthenticationCode* find_mac(const SCAN_Name& request, - Algorithm_Factory&) const override; - - PBKDF* find_pbkdf(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const override; - }; - -} - -#endif diff --git a/src/lib/engine/core_engine/info.txt b/src/lib/engine/core_engine/info.txt deleted file mode 100644 index c726464f4..000000000 --- a/src/lib/engine/core_engine/info.txt +++ /dev/null @@ -1,18 +0,0 @@ -define CORE_ENGINE 20131128 - -<header:internal> -core_engine.h -</header:internal> - -<source> -lookup_block.cpp -lookup_hash.cpp -lookup_mac.cpp -lookup_stream.cpp -lookup_pbkdf.cpp -</source> - -<requires> -algo_factory -libstate -</requires> diff --git a/src/lib/engine/core_engine/lookup_block.cpp b/src/lib/engine/core_engine/lookup_block.cpp deleted file mode 100644 index 98186403e..000000000 --- a/src/lib/engine/core_engine/lookup_block.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* -* Block Cipher Lookup -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/core_engine.h> -#include <botan/scan_name.h> -#include <botan/algo_registry.h> - -namespace Botan { - -/* -* Look for an algorithm with this name -*/ -BlockCipher* Core_Engine::find_block_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(BlockCipher* c = Algo_Registry<BlockCipher>::global_registry().make(request, "builtin")) - return c; - - return nullptr; - } - -} diff --git a/src/lib/engine/core_engine/lookup_hash.cpp b/src/lib/engine/core_engine/lookup_hash.cpp deleted file mode 100644 index ed48c3549..000000000 --- a/src/lib/engine/core_engine/lookup_hash.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* -* Hash Algorithms Lookup -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/core_engine.h> -#include <botan/scan_name.h> -#include <botan/algo_registry.h> - -namespace Botan { - -/* -* Look for an algorithm with this name -*/ -HashFunction* Core_Engine::find_hash(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(HashFunction* c = Algo_Registry<HashFunction>::global_registry().make(request, "builtin")) - return c; - - return nullptr; - } - -} diff --git a/src/lib/engine/core_engine/lookup_mac.cpp b/src/lib/engine/core_engine/lookup_mac.cpp deleted file mode 100644 index 1336cee5f..000000000 --- a/src/lib/engine/core_engine/lookup_mac.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* -* MAC Lookup -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/core_engine.h> -#include <botan/scan_name.h> -#include <botan/algo_registry.h> - -namespace Botan { - -/* -* Look for an algorithm with this name -*/ -MessageAuthenticationCode* -Core_Engine::find_mac(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(MessageAuthenticationCode* m = Algo_Registry<MessageAuthenticationCode>::global_registry().make(request, "builtin")) - return m; - - return nullptr; - } - -} diff --git a/src/lib/engine/core_engine/lookup_pbkdf.cpp b/src/lib/engine/core_engine/lookup_pbkdf.cpp deleted file mode 100644 index 1dc40322c..000000000 --- a/src/lib/engine/core_engine/lookup_pbkdf.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -* PBKDF Lookup -* (C) 2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/core_engine.h> -#include <botan/scan_name.h> -#include <botan/algo_factory.h> - -#if defined(BOTAN_HAS_PBKDF1) - #include <botan/pbkdf1.h> -#endif - -#if defined(BOTAN_HAS_PBKDF2) - #include <botan/pbkdf2.h> -#endif - -namespace Botan { - -PBKDF* Core_Engine::find_pbkdf(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const - { -#if defined(BOTAN_HAS_PBKDF1) - if(algo_spec.algo_name() == "PBKDF1" && algo_spec.arg_count() == 1) - return new PKCS5_PBKDF1(af.make_hash_function(algo_spec.arg(0))); -#endif - -#if defined(BOTAN_HAS_PBKDF2) - if(algo_spec.algo_name() == "PBKDF2" && algo_spec.arg_count() == 1) - { - if(const MessageAuthenticationCode* mac_proto = af.prototype_mac(algo_spec.arg(0))) - return new PKCS5_PBKDF2(mac_proto->clone()); - - return new PKCS5_PBKDF2(af.make_mac("HMAC(" + algo_spec.arg(0) + ")")); - } -#endif - - return nullptr; - } - -} diff --git a/src/lib/engine/core_engine/lookup_stream.cpp b/src/lib/engine/core_engine/lookup_stream.cpp deleted file mode 100644 index 068db7def..000000000 --- a/src/lib/engine/core_engine/lookup_stream.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Stream Cipher Lookup -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/core_engine.h> -#include <botan/scan_name.h> -#include <botan/algo_registry.h> - -namespace Botan { - -/* -* Look for an algorithm with this name -*/ -StreamCipher* -Core_Engine::find_stream_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(StreamCipher* c = Algo_Registry<StreamCipher>::global_registry().make(request, "builtin")) - return c; - - return nullptr; - } - -} diff --git a/src/lib/engine/dyn_engine/dyn_engine.cpp b/src/lib/engine/dyn_engine/dyn_engine.cpp deleted file mode 100644 index ad74370a2..000000000 --- a/src/lib/engine/dyn_engine/dyn_engine.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/** -* Dynamically Loaded Engine -* (C) 2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#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 deleted file mode 100644 index d40df5663..000000000 --- a/src/lib/engine/dyn_engine/dyn_engine.h +++ /dev/null @@ -1,72 +0,0 @@ -/** -* Dynamically Loaded Engine -* (C) 2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#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); - } - - 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 deleted file mode 100644 index 54379f501..000000000 --- a/src/lib/engine/dyn_engine/info.txt +++ /dev/null @@ -1,14 +0,0 @@ -define DYNAMICALLY_LOADED_ENGINE 20131128 - -<header:public> -dyn_engine.h -</header:public> - -<source> -dyn_engine.cpp -</source> - -<requires> -engine -dyn_load -</requires> diff --git a/src/lib/engine/engine.cpp b/src/lib/engine/engine.cpp deleted file mode 100644 index 7aab64cad..000000000 --- a/src/lib/engine/engine.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Engine -* (C) 2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/engine.h> - -namespace Botan { - -BlockCipher* -Engine::find_block_cipher(const SCAN_Name&, - Algorithm_Factory&) const - { - return nullptr; - } - -StreamCipher* -Engine::find_stream_cipher(const SCAN_Name&, - Algorithm_Factory&) const - { - return nullptr; - } - -HashFunction* -Engine::find_hash(const SCAN_Name&, - Algorithm_Factory&) const - { - return nullptr; - } - -MessageAuthenticationCode* -Engine::find_mac(const SCAN_Name&, - Algorithm_Factory&) const - { - return nullptr; - } - -PBKDF* -Engine::find_pbkdf(const SCAN_Name&, - Algorithm_Factory&) const - { - return nullptr; - } - -} diff --git a/src/lib/engine/engine.h b/src/lib/engine/engine.h deleted file mode 100644 index 7fe11c12e..000000000 --- a/src/lib/engine/engine.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -* Engine -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_ENGINE_H__ -#define BOTAN_ENGINE_H__ - -#include <botan/scan_name.h> -#include <botan/block_cipher.h> -#include <botan/stream_cipher.h> -#include <botan/hash.h> -#include <botan/mac.h> -#include <botan/pbkdf.h> -#include <botan/pow_mod.h> -#include <botan/pk_keys.h> - -namespace Botan { - -class Algorithm_Factory; -class RandomNumberGenerator; - -/** -* Base class for all engines. All non-pure virtual functions simply -* return NULL, indicating the algorithm in question is not -* supported. Subclasses can reimplement whichever function(s) -* they want to hook in a particular type. -*/ -class BOTAN_DLL Engine - { - public: - virtual ~Engine() {} - - /** - * @return name of this engine - */ - virtual std::string provider_name() const = 0; - - /** - * @param algo_spec the algorithm name/specification - * @param af an algorithm factory object - * @return newly allocated object, or NULL - */ - virtual BlockCipher* - find_block_cipher(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const; - - /** - * @param algo_spec the algorithm name/specification - * @param af an algorithm factory object - * @return newly allocated object, or NULL - */ - virtual StreamCipher* - find_stream_cipher(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const; - - /** - * @param algo_spec the algorithm name/specification - * @param af an algorithm factory object - * @return newly allocated object, or NULL - */ - virtual HashFunction* - find_hash(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const; - - /** - * @param algo_spec the algorithm name/specification - * @param af an algorithm factory object - * @return newly allocated object, or NULL - */ - virtual MessageAuthenticationCode* - find_mac(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const; - - /** - * @param algo_spec the algorithm name/specification - * @param af an algorithm factory object - * @return newly allocated object, or NULL - */ - virtual PBKDF* find_pbkdf(const SCAN_Name& algo_spec, - Algorithm_Factory& af) const; - }; - -} - -#endif diff --git a/src/lib/engine/info.txt b/src/lib/engine/info.txt deleted file mode 100644 index 800a007a1..000000000 --- a/src/lib/engine/info.txt +++ /dev/null @@ -1,20 +0,0 @@ -define ENGINES 20131128 - -<header:public> -engine.h -</header:public> - -<source> -engine.cpp -</source> - -<requires> -block -hash -libstate -mac -numbertheory -pbkdf -pubkey -stream -</requires> diff --git a/src/lib/engine/openssl/info.txt b/src/lib/engine/openssl/info.txt deleted file mode 100644 index c1be7bf9b..000000000 --- a/src/lib/engine/openssl/info.txt +++ /dev/null @@ -1,21 +0,0 @@ -define ENGINE_OPENSSL 20131128 - -load_on request - -<libs> -all -> crypto -</libs> - -<header:internal> -openssl_engine.h -</header:internal> - -<source> -ossl_arc4.cpp -ossl_bc.cpp -ossl_md.cpp -</source> - -<requires> -bigint -</requires> diff --git a/src/lib/engine/openssl/openssl_engine.h b/src/lib/engine/openssl/openssl_engine.h deleted file mode 100644 index 3e3940499..000000000 --- a/src/lib/engine/openssl/openssl_engine.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* OpenSSL Engine -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_ENGINE_OPENSSL_H__ -#define BOTAN_ENGINE_OPENSSL_H__ - -#include <botan/engine.h> - -namespace Botan { - -/** -* OpenSSL Engine -*/ -class OpenSSL_Engine : public Engine - { - public: - std::string provider_name() const override { return "openssl"; } - - BlockCipher* find_block_cipher(const SCAN_Name&, - Algorithm_Factory&) const override; - - StreamCipher* find_stream_cipher(const SCAN_Name&, - Algorithm_Factory&) const override; - - HashFunction* find_hash(const SCAN_Name&, Algorithm_Factory&) const override; - }; - -} - -#endif diff --git a/src/lib/engine/openssl/ossl_arc4.cpp b/src/lib/engine/openssl/ossl_arc4.cpp deleted file mode 100644 index 4533c2688..000000000 --- a/src/lib/engine/openssl/ossl_arc4.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* -* OpenSSL RC4 -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/openssl_engine.h> -#include <botan/parsing.h> -#include <openssl/rc4.h> - -namespace Botan { - -namespace { - -/** -* RC4 as implemented by OpenSSL -*/ -class RC4_OpenSSL : public StreamCipher - { - public: - void clear() { clear_mem(&state, 1); } - - std::string name() const; - StreamCipher* clone() const { return new RC4_OpenSSL(SKIP); } - - Key_Length_Specification key_spec() const - { - return Key_Length_Specification(1, 32); - } - - - RC4_OpenSSL(size_t s = 0) : SKIP(s) { clear(); } - ~RC4_OpenSSL() { clear(); } - private: - void cipher(const byte[], byte[], size_t); - void key_schedule(const byte[], size_t); - - const size_t SKIP; - RC4_KEY state; - }; - -/* -* Return the name of this type -*/ -std::string RC4_OpenSSL::name() const - { - if(SKIP == 0) return "RC4"; - if(SKIP == 256) return "MARK-4"; - else return "RC4_skip(" + std::to_string(SKIP) + ")"; - } - -/* -* RC4 Key Schedule -*/ -void RC4_OpenSSL::key_schedule(const byte key[], size_t length) - { - RC4_set_key(&state, length, key); - byte dummy = 0; - for(size_t i = 0; i != SKIP; ++i) - RC4(&state, 1, &dummy, &dummy); - } - -/* -* RC4 Encryption -*/ -void RC4_OpenSSL::cipher(const byte in[], byte out[], size_t length) - { - RC4(&state, length, in, out); - } - -} - -/** -* Look for an OpenSSL-supported stream cipher (RC4) -*/ -StreamCipher* -OpenSSL_Engine::find_stream_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(request.algo_name() == "RC4") - return new RC4_OpenSSL(request.arg_as_integer(0, 0)); - if(request.algo_name() == "RC4_drop") - return new RC4_OpenSSL(768); - - return 0; - } - -} diff --git a/src/lib/engine/openssl/ossl_bc.cpp b/src/lib/engine/openssl/ossl_bc.cpp deleted file mode 100644 index 8e8c6e5a8..000000000 --- a/src/lib/engine/openssl/ossl_bc.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* -* OpenSSL Block Cipher -* (C) 1999-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/openssl_engine.h> -#include <openssl/evp.h> - -namespace Botan { - -namespace { - -/* -* EVP Block Cipher -*/ -class EVP_BlockCipher : public BlockCipher - { - public: - void clear(); - std::string name() const { return cipher_name; } - BlockCipher* clone() const; - - size_t block_size() const { return block_sz; } - - EVP_BlockCipher(const EVP_CIPHER*, const std::string&); - - EVP_BlockCipher(const EVP_CIPHER*, const std::string&, - size_t, size_t, size_t); - - Key_Length_Specification key_spec() const { return cipher_key_spec; } - - ~EVP_BlockCipher(); - private: - void encrypt_n(const byte in[], byte out[], size_t blocks) const; - void decrypt_n(const byte in[], byte out[], size_t blocks) const; - void key_schedule(const byte[], size_t); - - size_t block_sz; - Key_Length_Specification cipher_key_spec; - std::string cipher_name; - mutable EVP_CIPHER_CTX encrypt, decrypt; - }; - -/* -* EVP Block Cipher Constructor -*/ -EVP_BlockCipher::EVP_BlockCipher(const EVP_CIPHER* algo, - const std::string& algo_name) : - block_sz(EVP_CIPHER_block_size(algo)), - cipher_key_spec(EVP_CIPHER_key_length(algo)), - cipher_name(algo_name) - { - if(EVP_CIPHER_mode(algo) != EVP_CIPH_ECB_MODE) - throw Invalid_Argument("EVP_BlockCipher: Non-ECB EVP was passed in"); - - EVP_CIPHER_CTX_init(&encrypt); - EVP_CIPHER_CTX_init(&decrypt); - - EVP_EncryptInit_ex(&encrypt, algo, 0, 0, 0); - EVP_DecryptInit_ex(&decrypt, algo, 0, 0, 0); - - EVP_CIPHER_CTX_set_padding(&encrypt, 0); - EVP_CIPHER_CTX_set_padding(&decrypt, 0); - } - -/* -* EVP Block Cipher Constructor -*/ -EVP_BlockCipher::EVP_BlockCipher(const EVP_CIPHER* algo, - const std::string& algo_name, - size_t key_min, size_t key_max, - size_t key_mod) : - block_sz(EVP_CIPHER_block_size(algo)), - cipher_key_spec(key_min, key_max, key_mod), - cipher_name(algo_name) - { - if(EVP_CIPHER_mode(algo) != EVP_CIPH_ECB_MODE) - throw Invalid_Argument("EVP_BlockCipher: Non-ECB EVP was passed in"); - - EVP_CIPHER_CTX_init(&encrypt); - EVP_CIPHER_CTX_init(&decrypt); - - EVP_EncryptInit_ex(&encrypt, algo, 0, 0, 0); - EVP_DecryptInit_ex(&decrypt, algo, 0, 0, 0); - - EVP_CIPHER_CTX_set_padding(&encrypt, 0); - EVP_CIPHER_CTX_set_padding(&decrypt, 0); - } - -/* -* EVP Block Cipher Destructor -*/ -EVP_BlockCipher::~EVP_BlockCipher() - { - EVP_CIPHER_CTX_cleanup(&encrypt); - EVP_CIPHER_CTX_cleanup(&decrypt); - } - -/* -* Encrypt a block -*/ -void EVP_BlockCipher::encrypt_n(const byte in[], byte out[], - size_t blocks) const - { - int out_len = 0; - EVP_EncryptUpdate(&encrypt, out, &out_len, in, blocks * block_sz); - } - -/* -* Decrypt a block -*/ -void EVP_BlockCipher::decrypt_n(const byte in[], byte out[], - size_t blocks) const - { - int out_len = 0; - EVP_DecryptUpdate(&decrypt, out, &out_len, in, blocks * block_sz); - } - -/* -* Set the key -*/ -void EVP_BlockCipher::key_schedule(const byte key[], size_t length) - { - secure_vector<byte> full_key(key, key + length); - - if(cipher_name == "TripleDES" && length == 16) - { - full_key += std::make_pair(key, 8); - } - else - if(EVP_CIPHER_CTX_set_key_length(&encrypt, length) == 0 || - EVP_CIPHER_CTX_set_key_length(&decrypt, length) == 0) - throw Invalid_Argument("EVP_BlockCipher: Bad key length for " + - cipher_name); - - if(cipher_name == "RC2") - { - EVP_CIPHER_CTX_ctrl(&encrypt, EVP_CTRL_SET_RC2_KEY_BITS, length*8, 0); - EVP_CIPHER_CTX_ctrl(&decrypt, EVP_CTRL_SET_RC2_KEY_BITS, length*8, 0); - } - - EVP_EncryptInit_ex(&encrypt, 0, 0, &full_key[0], 0); - EVP_DecryptInit_ex(&decrypt, 0, 0, &full_key[0], 0); - } - -/* -* Return a clone of this object -*/ -BlockCipher* EVP_BlockCipher::clone() const - { - return new EVP_BlockCipher(EVP_CIPHER_CTX_cipher(&encrypt), - cipher_name, - cipher_key_spec.minimum_keylength(), - cipher_key_spec.maximum_keylength(), - cipher_key_spec.keylength_multiple()); - } - -/* -* Clear memory of sensitive data -*/ -void EVP_BlockCipher::clear() - { - const EVP_CIPHER* algo = EVP_CIPHER_CTX_cipher(&encrypt); - - EVP_CIPHER_CTX_cleanup(&encrypt); - EVP_CIPHER_CTX_cleanup(&decrypt); - EVP_CIPHER_CTX_init(&encrypt); - EVP_CIPHER_CTX_init(&decrypt); - EVP_EncryptInit_ex(&encrypt, algo, 0, 0, 0); - EVP_DecryptInit_ex(&decrypt, algo, 0, 0, 0); - EVP_CIPHER_CTX_set_padding(&encrypt, 0); - EVP_CIPHER_CTX_set_padding(&decrypt, 0); - } - -} - -/* -* Look for an algorithm with this name -*/ -BlockCipher* -OpenSSL_Engine::find_block_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { -#define HANDLE_EVP_CIPHER(NAME, EVP) \ - if(request.algo_name() == NAME && request.arg_count() == 0) \ - return new EVP_BlockCipher(EVP, NAME); - -#define HANDLE_EVP_CIPHER_KEYLEN(NAME, EVP, MIN, MAX, MOD) \ - if(request.algo_name() == NAME && request.arg_count() == 0) \ - return new EVP_BlockCipher(EVP, NAME, MIN, MAX, MOD); - -#if !defined(OPENSSL_NO_AES) - /* - Using OpenSSL's AES causes crashes inside EVP on x86-64 with OpenSSL 0.9.8g - cause is unknown - */ - HANDLE_EVP_CIPHER("AES-128", EVP_aes_128_ecb()); - HANDLE_EVP_CIPHER("AES-192", EVP_aes_192_ecb()); - HANDLE_EVP_CIPHER("AES-256", EVP_aes_256_ecb()); -#endif - -#if !defined(OPENSSL_NO_DES) - HANDLE_EVP_CIPHER("DES", EVP_des_ecb()); - HANDLE_EVP_CIPHER_KEYLEN("TripleDES", EVP_des_ede3_ecb(), 16, 24, 8); -#endif - -#if !defined(OPENSSL_NO_BF) - HANDLE_EVP_CIPHER_KEYLEN("Blowfish", EVP_bf_ecb(), 1, 56, 1); -#endif - -#if !defined(OPENSSL_NO_CAST) - HANDLE_EVP_CIPHER_KEYLEN("CAST-128", EVP_cast5_ecb(), 1, 16, 1); -#endif - -#if !defined(OPENSSL_NO_CAMELLIA) - HANDLE_EVP_CIPHER("Camellia-128", EVP_camellia_128_ecb()); - HANDLE_EVP_CIPHER("Camellia-192", EVP_camellia_192_ecb()); - HANDLE_EVP_CIPHER("Camellia-256", EVP_camellia_256_ecb()); -#endif - -#if !defined(OPENSSL_NO_RC2) - HANDLE_EVP_CIPHER_KEYLEN("RC2", EVP_rc2_ecb(), 1, 32, 1); -#endif - -#if !defined(OPENSSL_NO_RC5) && 0 - if(request.algo_name() == "RC5") - if(request.arg_as_integer(0, 12) == 12) - return new EVP_BlockCipher(EVP_rc5_32_12_16_ecb(), - "RC5(12)", 1, 32, 1); -#endif - -#if !defined(OPENSSL_NO_IDEA) && 0 - HANDLE_EVP_CIPHER("IDEA", EVP_idea_ecb()); -#endif - -#if !defined(OPENSSL_NO_SEED) - HANDLE_EVP_CIPHER("SEED", EVP_seed_ecb()); -#endif - -#undef HANDLE_EVP_CIPHER -#undef HANDLE_EVP_CIPHER_KEYLEN - - return 0; - } - -} diff --git a/src/lib/engine/openssl/ossl_md.cpp b/src/lib/engine/openssl/ossl_md.cpp deleted file mode 100644 index 063271151..000000000 --- a/src/lib/engine/openssl/ossl_md.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* -* OpenSSL Hash Functions -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/openssl_engine.h> -#include <openssl/evp.h> - -namespace Botan { - -namespace { - -/* -* EVP Hash Function -*/ -class EVP_HashFunction : public HashFunction - { - public: - void clear(); - std::string name() const { return algo_name; } - HashFunction* clone() const; - - size_t output_length() const - { - return EVP_MD_size(EVP_MD_CTX_md(&md)); - } - - size_t hash_block_size() const - { - return EVP_MD_block_size(EVP_MD_CTX_md(&md)); - } - - EVP_HashFunction(const EVP_MD*, const std::string&); - ~EVP_HashFunction(); - private: - void add_data(const byte[], size_t); - void final_result(byte[]); - - std::string algo_name; - EVP_MD_CTX md; - }; - -/* -* Update an EVP Hash Calculation -*/ -void EVP_HashFunction::add_data(const byte input[], size_t length) - { - EVP_DigestUpdate(&md, input, length); - } - -/* -* Finalize an EVP Hash Calculation -*/ -void EVP_HashFunction::final_result(byte output[]) - { - EVP_DigestFinal_ex(&md, output, 0); - const EVP_MD* algo = EVP_MD_CTX_md(&md); - EVP_DigestInit_ex(&md, algo, 0); - } - -/* -* Clear memory of sensitive data -*/ -void EVP_HashFunction::clear() - { - const EVP_MD* algo = EVP_MD_CTX_md(&md); - EVP_DigestInit_ex(&md, algo, 0); - } - -/* -* Return a clone of this object -*/ -HashFunction* EVP_HashFunction::clone() const - { - const EVP_MD* algo = EVP_MD_CTX_md(&md); - return new EVP_HashFunction(algo, name()); - } - -/* -* Create an EVP hash function -*/ -EVP_HashFunction::EVP_HashFunction(const EVP_MD* algo, - const std::string& name) : - algo_name(name) - { - EVP_MD_CTX_init(&md); - EVP_DigestInit_ex(&md, algo, 0); - } - -/* -* Destroy an EVP hash function -*/ -EVP_HashFunction::~EVP_HashFunction() - { - EVP_MD_CTX_cleanup(&md); - } - -} - -/* -* Look for an algorithm with this name -*/ -HashFunction* OpenSSL_Engine::find_hash(const SCAN_Name& request, - Algorithm_Factory&) const - { -#if !defined(OPENSSL_NO_SHA) - if(request.algo_name() == "SHA-160") - return new EVP_HashFunction(EVP_sha1(), "SHA-160"); -#endif - -#if !defined(OPENSSL_NO_SHA256) - if(request.algo_name() == "SHA-224") - return new EVP_HashFunction(EVP_sha224(), "SHA-224"); - if(request.algo_name() == "SHA-256") - return new EVP_HashFunction(EVP_sha256(), "SHA-256"); -#endif - -#if !defined(OPENSSL_NO_SHA512) - if(request.algo_name() == "SHA-384") - return new EVP_HashFunction(EVP_sha384(), "SHA-384"); - if(request.algo_name() == "SHA-512") - return new EVP_HashFunction(EVP_sha512(), "SHA-512"); -#endif - -#if !defined(OPENSSL_NO_MD2) - if(request.algo_name() == "MD2") - return new EVP_HashFunction(EVP_md2(), "MD2"); -#endif - -#if !defined(OPENSSL_NO_MD4) - if(request.algo_name() == "MD4") - return new EVP_HashFunction(EVP_md4(), "MD4"); -#endif - -#if !defined(OPENSSL_NO_MD5) - if(request.algo_name() == "MD5") - return new EVP_HashFunction(EVP_md5(), "MD5"); -#endif - -#if !defined(OPENSSL_NO_RIPEMD) - if(request.algo_name() == "RIPEMD-160") - return new EVP_HashFunction(EVP_ripemd160(), "RIPEMD-160"); -#endif - - return 0; - } - -} diff --git a/src/lib/engine/simd_engine/info.txt b/src/lib/engine/simd_engine/info.txt deleted file mode 100644 index 2063c9dfe..000000000 --- a/src/lib/engine/simd_engine/info.txt +++ /dev/null @@ -1,15 +0,0 @@ -define ENGINE_SIMD 20131128 - -load_on dep - -<source> -simd_engine.cpp -</source> - -<header:internal> -simd_engine.h -</header:internal> - -<requires> -simd -</requires> diff --git a/src/lib/engine/simd_engine/simd_engine.cpp b/src/lib/engine/simd_engine/simd_engine.cpp deleted file mode 100644 index f60c5beb2..000000000 --- a/src/lib/engine/simd_engine/simd_engine.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -* SIMD Engine -* (C) 1999-2009 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/internal/simd_engine.h> -#include <botan/algo_registry.h> -#include <botan/cpuid.h> - -namespace Botan { - -BlockCipher* -SIMD_Engine::find_block_cipher(const SCAN_Name& request, - Algorithm_Factory&) const - { - auto& block_cipher = Algo_Registry<BlockCipher>::global_registry(); - - if(BlockCipher* c = block_cipher.make(request, "avx2")) - return c; - - if(BlockCipher* c = block_cipher.make(request, "ssse3")) - return c; - - if(BlockCipher* c = block_cipher.make(request, "sse2")) - return c; - - if(BlockCipher* c = block_cipher.make(request, "simd32")) - return c; - - return nullptr; - } - -HashFunction* -SIMD_Engine::find_hash(const SCAN_Name& request, - Algorithm_Factory&) const - { - if(HashFunction* c = Algo_Registry<HashFunction>::global_registry().make(request, "sse2")) - return c; - - return nullptr; - } - -} diff --git a/src/lib/engine/simd_engine/simd_engine.h b/src/lib/engine/simd_engine/simd_engine.h deleted file mode 100644 index 3429e0fbd..000000000 --- a/src/lib/engine/simd_engine/simd_engine.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* SIMD Assembly Engine -* (C) 1999-2009 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_SIMD_ENGINE_H__ -#define BOTAN_SIMD_ENGINE_H__ - -#include <botan/engine.h> - -namespace Botan { - -/** -* Engine for implementations that use some kind of SIMD -*/ -class SIMD_Engine : public Engine - { - public: - std::string provider_name() const { return "simd"; } - - BlockCipher* find_block_cipher(const SCAN_Name&, - Algorithm_Factory&) const; - - HashFunction* find_hash(const SCAN_Name& request, - Algorithm_Factory&) const; - }; - -} - -#endif |