diff options
Diffstat (limited to 'src/libstate')
-rw-r--r-- | src/libstate/def_mode.cpp | 177 | ||||
-rw-r--r-- | src/libstate/def_powm.cpp | 22 | ||||
-rw-r--r-- | src/libstate/eng_base.cpp | 252 | ||||
-rw-r--r-- | src/libstate/eng_def.h | 72 | ||||
-rw-r--r-- | src/libstate/engine.cpp | 431 | ||||
-rw-r--r-- | src/libstate/engine.h | 212 | ||||
-rw-r--r-- | src/libstate/info.txt | 10 | ||||
-rw-r--r-- | src/libstate/lookup_cipher.cpp | 351 | ||||
-rw-r--r-- | src/libstate/lookup_hash.cpp | 211 | ||||
-rw-r--r-- | src/libstate/lookup_mac.cpp | 92 | ||||
-rw-r--r-- | src/libstate/lookup_s2k.cpp | 66 |
11 files changed, 0 insertions, 1896 deletions
diff --git a/src/libstate/def_mode.cpp b/src/libstate/def_mode.cpp deleted file mode 100644 index b062cc34b..000000000 --- a/src/libstate/def_mode.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/************************************************* -* Default Engine Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/eng_def.h> -#include <botan/parsing.h> -#include <botan/filters.h> -#include <botan/lookup.h> - -#if defined(BOTAN_HAS_ECB) - #include <botan/ecb.h> -#endif - -#if defined(BOTAN_HAS_CBC) - #include <botan/cbc.h> -#endif - -#if defined(BOTAN_HAS_CTS) - #include <botan/cts.h> -#endif - -#if defined(BOTAN_HAS_CFB) - #include <botan/cfb.h> -#endif - -#if defined(BOTAN_HAS_OFB) - #include <botan/ofb.h> -#endif - -#if defined(BOTAN_HAS_CTR) - #include <botan/ctr.h> -#endif - -#if defined(BOTAN_HAS_EAX) - #include <botan/eax.h> -#endif - -namespace Botan { - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, - Cipher_Dir direction) - { - std::vector<std::string> algo_parts = split_on(algo_spec, '/'); - if(algo_parts.empty()) - throw Invalid_Algorithm_Name(algo_spec); - - const std::string cipher = algo_parts[0]; - - if(have_stream_cipher(cipher)) - { - if(algo_parts.size() == 1) - return new StreamCipher_Filter(cipher); - return 0; - } - else if(have_block_cipher(cipher)) - { - if(algo_parts.size() != 2 && algo_parts.size() != 3) - return 0; - - std::string mode = algo_parts[1]; - u32bit bits = 0; - - if(mode.find("CFB") != std::string::npos || - mode.find("EAX") != std::string::npos) - { - std::vector<std::string> algo_info = parse_algorithm_name(mode); - mode = algo_info[0]; - if(algo_info.size() == 1) - bits = 8*block_size_of(cipher); - else if(algo_info.size() == 2) - bits = to_u32bit(algo_info[1]); - else - throw Invalid_Algorithm_Name(algo_spec); - } - - std::string padding; - if(algo_parts.size() == 3) - padding = algo_parts[2]; - else - padding = (mode == "CBC") ? "PKCS7" : "NoPadding"; - - if(mode == "ECB" && padding == "CTS") - return 0; - else if((mode != "CBC" && mode != "ECB") && padding != "NoPadding") - throw Invalid_Algorithm_Name(algo_spec); - - if(mode == "OFB") - { -#if defined(BOTAN_HAS_OFB) - return new OFB(cipher); -#else - return 0; -#endif - } - else if(mode == "CTR-BE") - { -#if defined(BOTAN_HAS_CTR) - return new CTR_BE(cipher); -#else - return 0; -#endif - } - else if(mode == "ECB" || mode == "CBC" || mode == "CTS" || - mode == "CFB" || mode == "EAX") - { - if(mode == "ECB") - { -#if defined(BOTAN_HAS_ECB) - if(direction == ENCRYPTION) - return new ECB_Encryption(cipher, padding); - else - return new ECB_Decryption(cipher, padding); -#else - return 0; -#endif - } - else if(mode == "CFB") - { -#if defined(BOTAN_HAS_CFB) - if(direction == ENCRYPTION) - return new CFB_Encryption(cipher, bits); - else - return new CFB_Decryption(cipher, bits); -#else - return 0; -#endif - } - else if(mode == "CBC") - { - if(padding == "CTS") - { -#if defined(BOTAN_HAS_CTS) - if(direction == ENCRYPTION) - return new CTS_Encryption(cipher); - else - return new CTS_Decryption(cipher); -#else - return 0; -#endif - } - -#if defined(BOTAN_HAS_CBC) - if(direction == ENCRYPTION) - return new CBC_Encryption(cipher, padding); - else - return new CBC_Decryption(cipher, padding); -#else - return 0; -#endif - } - else if(mode == "EAX") - { -#if defined(BOTAN_HAS_EAX) - if(direction == ENCRYPTION) - return new EAX_Encryption(cipher, bits); - else - return new EAX_Decryption(cipher, bits); -#else - return 0; -#endif - } - else - throw Internal_Error("get_mode: " + cipher + "/" - + mode + "/" + padding); - } - else - return 0; - } - - return 0; - } - -} diff --git a/src/libstate/def_powm.cpp b/src/libstate/def_powm.cpp deleted file mode 100644 index a28438f5b..000000000 --- a/src/libstate/def_powm.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/************************************************* -* Modular Exponentiation Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/eng_def.h> -#include <botan/def_powm.h> - -namespace Botan { - -/************************************************* -* Choose a modular exponentation algorithm * -*************************************************/ -Modular_Exponentiator* -Default_Engine::mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) const - { - if(n.is_odd()) - return new Montgomery_Exponentiator(n, hints); - return new Fixed_Window_Exponentiator(n, hints); - } - -} diff --git a/src/libstate/eng_base.cpp b/src/libstate/eng_base.cpp deleted file mode 100644 index aaaf46723..000000000 --- a/src/libstate/eng_base.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/************************************************* -* Basic No-Op Engine Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/engine.h> -#include <botan/libstate.h> -#include <botan/stl_util.h> -#include <botan/lookup.h> - -namespace Botan { - -namespace { - -/************************************************* -* Algorithm Cache * -*************************************************/ -template<typename T> -class Algorithm_Cache_Impl : public Engine::Algorithm_Cache<T> - { - public: - T* get(const std::string& name) const - { - Mutex_Holder lock(mutex); - return search_map(mappings, name); - } - - void add(T* algo, const std::string& index_name = "") const - { - if(!algo) - return; - - Mutex_Holder lock(mutex); - - const std::string name = - (index_name != "" ? index_name : algo->name()); - - if(mappings.find(name) != mappings.end()) - delete mappings[name]; - mappings[name] = algo; - } - - Algorithm_Cache_Impl() - { - mutex = global_state().get_mutex(); - } - - ~Algorithm_Cache_Impl() - { - typename std::map<std::string, T*>::iterator i = mappings.begin(); - - while(i != mappings.end()) - { - delete i->second; - ++i; - } - delete mutex; - } - private: - Mutex* mutex; - mutable std::map<std::string, T*> mappings; - }; - -} - -/************************************************* -* Acquire a BlockCipher * -*************************************************/ -const BlockCipher* Engine::block_cipher(const std::string& name) const - { - return lookup_algo(cache_of_bc, global_state().deref_alias(name), - this, &Engine::find_block_cipher); - } - -/************************************************* -* Acquire a StreamCipher * -*************************************************/ -const StreamCipher* Engine::stream_cipher(const std::string& name) const - { - return lookup_algo(cache_of_sc, global_state().deref_alias(name), - this, &Engine::find_stream_cipher); - } - -/************************************************* -* Acquire a HashFunction * -*************************************************/ -const HashFunction* Engine::hash(const std::string& name) const - { - return lookup_algo(cache_of_hf, global_state().deref_alias(name), - this, &Engine::find_hash); - } - -/************************************************* -* Acquire a MessageAuthenticationCode * -*************************************************/ -const MessageAuthenticationCode* Engine::mac(const std::string& name) const - { - return lookup_algo(cache_of_mac, global_state().deref_alias(name), - this, &Engine::find_mac); - } - -/************************************************* -* Acquire a S2K object * -*************************************************/ -const S2K* Engine::s2k(const std::string& name) const - { - return lookup_algo(cache_of_s2k, global_state().deref_alias(name), - this, &Engine::find_s2k); - } - -/************************************************* -* Acquire a cipher padding object * -*************************************************/ -const BlockCipherModePaddingMethod* -Engine::bc_pad(const std::string& name) const - { - return lookup_algo(cache_of_bc_pad, global_state().deref_alias(name), - this, &Engine::find_bc_pad); - } - -/************************************************* -* Add a block cipher to the lookup table * -*************************************************/ -void Engine::add_algorithm(BlockCipher* algo) const - { - cache_of_bc->add(algo); - } - -/************************************************* -* Add a stream cipher to the lookup table * -*************************************************/ -void Engine::add_algorithm(StreamCipher* algo) const - { - cache_of_sc->add(algo); - } - -/************************************************* -* Add a hash function to the lookup table * -*************************************************/ -void Engine::add_algorithm(HashFunction* algo) const - { - cache_of_hf->add(algo); - } - -/************************************************* -* Add a MAC to the lookup table * -*************************************************/ -void Engine::add_algorithm(MessageAuthenticationCode* algo) const - { - cache_of_mac->add(algo); - } - -/************************************************* -* Add a S2K to the lookup table * -*************************************************/ -void Engine::add_algorithm(S2K* algo) const - { - cache_of_s2k->add(algo); - } - -/************************************************* -* Add a cipher pad method to the lookup table * -*************************************************/ -void Engine::add_algorithm(BlockCipherModePaddingMethod* algo) const - { - cache_of_bc_pad->add(algo); - } - -/************************************************* -* Create an Engine * -*************************************************/ -Engine::Engine() - { - cache_of_bc = new Algorithm_Cache_Impl<BlockCipher>(); - cache_of_sc = new Algorithm_Cache_Impl<StreamCipher>(); - cache_of_hf = new Algorithm_Cache_Impl<HashFunction>(); - cache_of_mac = new Algorithm_Cache_Impl<MessageAuthenticationCode>(); - cache_of_s2k = new Algorithm_Cache_Impl<S2K>(); - cache_of_bc_pad = - new Algorithm_Cache_Impl<BlockCipherModePaddingMethod>(); - } - -/************************************************* -* Destroy an Engine * -*************************************************/ -Engine::~Engine() - { - delete cache_of_bc; - delete cache_of_sc; - delete cache_of_hf; - delete cache_of_mac; - delete cache_of_s2k; - delete cache_of_bc_pad; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -BlockCipher* Engine::find_block_cipher(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -StreamCipher* Engine::find_stream_cipher(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -HashFunction* Engine::find_hash(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -MessageAuthenticationCode* Engine::find_mac(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -S2K* Engine::find_s2k(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -BlockCipherModePaddingMethod* Engine::find_bc_pad(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -Keyed_Filter* Engine::get_cipher(const std::string&, Cipher_Dir) - { - return 0; - } - -} diff --git a/src/libstate/eng_def.h b/src/libstate/eng_def.h deleted file mode 100644 index 36ef14a69..000000000 --- a/src/libstate/eng_def.h +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************* -* Default Engine Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_DEFAULT_ENGINE_H__ -#define BOTAN_DEFAULT_ENGINE_H__ - -#include <botan/engine.h> - -namespace Botan { - -/************************************************* -* Default Engine * -*************************************************/ -class BOTAN_DLL Default_Engine : public Engine - { - public: -#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) - IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&) const; -#endif - -#if defined(BOTAN_HAS_DSA) - DSA_Operation* dsa_op(const DL_Group&, const BigInt&, - const BigInt&) const; -#endif - -#if defined(BOTAN_HAS_NYBERG_RUEPPEL) - NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const; -#endif - -#if defined(BOTAN_HAS_ELGAMAL) - ELG_Operation* elg_op(const DL_Group&, const BigInt&, - const BigInt&) const; -#endif - -#if defined(BOTAN_HAS_DIFFIE_HELLMAN) - DH_Operation* dh_op(const DL_Group&, const BigInt&) const; -#endif - -#if defined(BOTAN_HAS_ECDSA) - virtual ECDSA_Operation* ecdsa_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const; -#endif - -#if defined(BOTAN_HAS_ECKAEG) - virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const; -#endif - - Modular_Exponentiator* mod_exp(const BigInt&, - Power_Mod::Usage_Hints) const; - - Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); - private: - BlockCipher* find_block_cipher(const std::string&) const; - StreamCipher* find_stream_cipher(const std::string&) const; - HashFunction* find_hash(const std::string&) const; - MessageAuthenticationCode* find_mac(const std::string&) const; - - class S2K* find_s2k(const std::string&) const; - class BlockCipherModePaddingMethod* - find_bc_pad(const std::string&) const; - }; - -} - -#endif diff --git a/src/libstate/engine.cpp b/src/libstate/engine.cpp deleted file mode 100644 index ce32fa3b4..000000000 --- a/src/libstate/engine.cpp +++ /dev/null @@ -1,431 +0,0 @@ -/************************************************* -* Engine Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/engine.h> -#include <botan/libstate.h> -#include <botan/lookup.h> -#include <botan/look_add.h> -#include <botan/eng_def.h> - -namespace Botan { - -namespace Engine_Core { - -#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) -/************************************************* -* Acquire an IF op * -*************************************************/ -IF_Operation* if_op(const BigInt& e, const BigInt& n, const BigInt& d, - const BigInt& p, const BigInt& q, const BigInt& d1, - const BigInt& d2, const BigInt& c) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - IF_Operation* op = engine->if_op(e, n, d, p, q, d1, d2, c); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::if_op: Unable to find a working engine"); - } -#endif - -#if defined(BOTAN_HAS_DSA) -/************************************************* -* Acquire a DSA op * -*************************************************/ -DSA_Operation* dsa_op(const DL_Group& group, const BigInt& y, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - DSA_Operation* op = engine->dsa_op(group, y, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::dsa_op: Unable to find a working engine"); - } -#endif - -#if defined(BOTAN_HAS_NYBERG_RUEPPEL) -/************************************************* -* Acquire a NR op * -*************************************************/ -NR_Operation* nr_op(const DL_Group& group, const BigInt& y, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - NR_Operation* op = engine->nr_op(group, y, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::nr_op: Unable to find a working engine"); - } -#endif - -#if defined(BOTAN_HAS_ELGAMAL) -/************************************************* -* Acquire an ElGamal op * -*************************************************/ -ELG_Operation* elg_op(const DL_Group& group, const BigInt& y, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - ELG_Operation* op = engine->elg_op(group, y, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::elg_op: Unable to find a working engine"); - } -#endif - -#if defined(BOTAN_HAS_DIFFIE_HELLMAN) -/************************************************* -* Acquire a DH op * -*************************************************/ -DH_Operation* dh_op(const DL_Group& group, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - DH_Operation* op = engine->dh_op(group, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::dh_op: Unable to find a working engine"); - } -#endif - -#if defined(BOTAN_HAS_ECDSA) -/************************************************* -* Acquire an ECDSA op * -*************************************************/ -ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - ECDSA_Operation* op = engine->ecdsa_op(dom_pars, priv_key, pub_key); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::ecdsa_op: Unable to find a working engine"); - } -#endif - -#if defined(BOTAN_HAS_ECKAEG) -/************************************************* -* Acquire a ECKAEG op * -*************************************************/ -ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - ECKAEG_Operation* op = engine->eckaeg_op(dom_pars, priv_key, pub_key); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::eckaeg_op: Unable to find a working engine"); - } -#endif - -/************************************************* -* Acquire a modular exponentiator * -*************************************************/ -Modular_Exponentiator* mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - Modular_Exponentiator* op = engine->mod_exp(n, hints); - - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::mod_exp: Unable to find a working engine"); - } - -} - -/************************************************* -* Acquire a block cipher * -*************************************************/ -const BlockCipher* retrieve_block_cipher(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const BlockCipher* algo = engine->block_cipher(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire a stream cipher * -*************************************************/ -const StreamCipher* retrieve_stream_cipher(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const StreamCipher* algo = engine->stream_cipher(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire a hash function * -*************************************************/ -const HashFunction* retrieve_hash(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const HashFunction* algo = engine->hash(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire an authentication code * -*************************************************/ -const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const MessageAuthenticationCode* algo = engine->mac(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire a string-to-key algorithm * -*************************************************/ -const S2K* retrieve_s2k(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const S2K* algo = engine->s2k(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Retrieve a block cipher padding method * -*************************************************/ -const BlockCipherModePaddingMethod* retrieve_bc_pad(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const BlockCipherModePaddingMethod* algo = engine->bc_pad(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Add a new block cipher * -*************************************************/ -void add_algorithm(Library_State& libstate, BlockCipher* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast<Default_Engine*>(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a new stream cipher * -*************************************************/ -void add_algorithm(Library_State& libstate, StreamCipher* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast<Default_Engine*>(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a new hash function * -*************************************************/ -void add_algorithm(Library_State& libstate, HashFunction* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast<Default_Engine*>(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a new authentication code * -*************************************************/ -void add_algorithm(Library_State& libstate, - MessageAuthenticationCode* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast<Default_Engine*>(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a padding method to the lookup table * -*************************************************/ -void add_algorithm(Library_State& libstate, - BlockCipherModePaddingMethod* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast<Default_Engine*>(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir direction) - { - Library_State::Engine_Iterator i(global_state()); - - while(Engine* engine = i.next()) - { - Keyed_Filter* algo = engine->get_cipher(algo_spec, direction); - if(algo) - return algo; - } - - throw Algorithm_Not_Found(algo_spec); - } - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - const InitializationVector& iv, - Cipher_Dir direction) - { - Keyed_Filter* cipher = get_cipher(algo_spec, direction); - cipher->set_key(key); - - if(iv.length()) - cipher->set_iv(iv); - - return cipher; - } - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - Cipher_Dir direction) - { - return get_cipher(algo_spec, - key, InitializationVector(), direction); - } - -} diff --git a/src/libstate/engine.h b/src/libstate/engine.h deleted file mode 100644 index d7fae2348..000000000 --- a/src/libstate/engine.h +++ /dev/null @@ -1,212 +0,0 @@ -/************************************************* -* Engine Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_ENGINE_H__ -#define BOTAN_ENGINE_H__ - -#include <botan/block_cipher.h> -#include <botan/stream_cipher.h> -#include <botan/hash.h> -#include <botan/mac.h> - -#include <botan/mutex.h> -#include <botan/pow_mod.h> -#include <botan/basefilt.h> -#include <utility> -#include <map> - -#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) - #include <botan/if_op.h> -#endif - -#if defined(BOTAN_HAS_DSA) - #include <botan/dsa_op.h> -#endif - -#if defined(BOTAN_HAS_DIFFIE_HELLMAN) - #include <botan/dh_op.h> -#endif - -#if defined(BOTAN_HAS_NYBERG_RUEPPEL) - #include <botan/nr_op.h> -#endif - -#if defined(BOTAN_HAS_ELGAMAL) - #include <botan/elg_op.h> -#endif - -#if defined(BOTAN_HAS_ECDSA) - #include <botan/ecdsa_op.h> - #include <botan/ec_dompar.h> -#endif - -#if defined(BOTAN_HAS_ECKAEG) - #include <botan/eckaeg_op.h> - #include <botan/ec_dompar.h> -#endif - -namespace Botan { - -/************************************************* -* Engine Base Class * -*************************************************/ -class BOTAN_DLL Engine - { - public: - template<typename T> - class BOTAN_DLL Algorithm_Cache - { - public: - virtual T* get(const std::string&) const = 0; - virtual void add(T* algo, const std::string& = "") const = 0; - virtual ~Algorithm_Cache() {} - }; - -#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) - virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&) const - { return 0; } -#endif - -#if defined(BOTAN_HAS_DSA) - virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, - const BigInt&) const - { return 0; } -#endif - -#if defined(BOTAN_HAS_NYBERG_RUEPPEL) - virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, - const BigInt&) const - { return 0; } -#endif - -#if defined(BOTAN_HAS_ELGAMAL) - virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, - const BigInt&) const - { return 0; } -#endif - -#if defined(BOTAN_HAS_DIFFIE_HELLMAN) - virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const - { return 0; } -#endif - -#if defined(BOTAN_HAS_ECDSA) - virtual ECDSA_Operation* ecdsa_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const - { return 0; } -#endif - -#if defined(BOTAN_HAS_ECKAEG) - virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const - { return 0; } -#endif - - virtual Modular_Exponentiator* mod_exp(const BigInt&, - Power_Mod::Usage_Hints) const - { return 0; } - - virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); - - const BlockCipher* block_cipher(const std::string&) const; - const StreamCipher* stream_cipher(const std::string&) const; - const HashFunction* hash(const std::string&) const; - const MessageAuthenticationCode* mac(const std::string&) const; - const class S2K* s2k(const std::string&) const; - const class BlockCipherModePaddingMethod* - bc_pad(const std::string&) const; - - void add_algorithm(BlockCipher*) const; - void add_algorithm(StreamCipher*) const; - void add_algorithm(HashFunction*) const; - void add_algorithm(MessageAuthenticationCode*) const; - void add_algorithm(class S2K*) const; - void add_algorithm(class BlockCipherModePaddingMethod*) const; - - Engine(); - virtual ~Engine(); - private: - virtual BlockCipher* find_block_cipher(const std::string&) const; - virtual StreamCipher* find_stream_cipher(const std::string&) const; - virtual HashFunction* find_hash(const std::string&) const; - virtual MessageAuthenticationCode* find_mac(const std::string&) const; - virtual class S2K* find_s2k(const std::string&) const; - virtual class BlockCipherModePaddingMethod* - find_bc_pad(const std::string&) const; - - template<typename T> - const T* lookup_algo(const Algorithm_Cache<T>* cache, - const std::string& name, - const Engine* engine, - T* (Engine::*find)(const std::string&) const) const - { - T* algo = cache->get(name); - if(!algo) - { - algo = (engine->*find)(name); - if(algo) - cache->add(algo, name); - } - return algo; - } - - Algorithm_Cache<BlockCipher>* cache_of_bc; - Algorithm_Cache<StreamCipher>* cache_of_sc; - Algorithm_Cache<HashFunction>* cache_of_hf; - Algorithm_Cache<MessageAuthenticationCode>* cache_of_mac; - Algorithm_Cache<BlockCipherModePaddingMethod>* cache_of_bc_pad; - Algorithm_Cache<S2K>* cache_of_s2k; - }; - -namespace Engine_Core { - -/************************************************* -* Get an operation from an Engine * -*************************************************/ -Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); - -#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) -IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&); -#endif - -#if defined(BOTAN_HAS_DSA) -DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&); -#endif - -#if defined(BOTAN_HAS_NYBERG_RUEPPEL) -NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); -#endif - -#if defined(BOTAN_HAS_ELGAMAL) -ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); -#endif - -#if defined(BOTAN_HAS_DIFFIE_HELLMAN) -DH_Operation* dh_op(const DL_Group&, const BigInt&); -#endif - -#if defined(BOTAN_HAS_ECDSA) -ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key); -#endif - -#if defined(BOTAN_HAS_ECKAEG) -ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key); -#endif - -} - -} - -#endif diff --git a/src/libstate/info.txt b/src/libstate/info.txt index c1a0b8667..d625dcae8 100644 --- a/src/libstate/info.txt +++ b/src/libstate/info.txt @@ -12,12 +12,6 @@ s2k <add> botan.h -def_mode.cpp -def_powm.cpp -eng_base.cpp -eng_def.h -engine.cpp -engine.h get_enc.cpp init.h init_def.cpp @@ -27,10 +21,6 @@ libstate.h look_add.h lookup.cpp lookup.h -lookup_cipher.cpp -lookup_hash.cpp -lookup_mac.cpp -lookup_s2k.cpp modules.cpp modules.h policy.cpp diff --git a/src/libstate/lookup_cipher.cpp b/src/libstate/lookup_cipher.cpp deleted file mode 100644 index ac66c1c40..000000000 --- a/src/libstate/lookup_cipher.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/************************************************* -* Cipher Lookup * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/eng_def.h> -#include <botan/lookup.h> -#include <botan/libstate.h> -#include <botan/parsing.h> -#include <memory> - -#if defined(BOTAN_HAS_AES) - #include <botan/aes.h> -#endif - -#if defined(BOTAN_HAS_BLOWFISH) - #include <botan/blowfish.h> -#endif - -#if defined(BOTAN_HAS_CAST) - #include <botan/cast128.h> - #include <botan/cast256.h> -#endif - -#if defined(BOTAN_HAS_DES) - #include <botan/des.h> - #include <botan/desx.h> -#endif - -#if defined(BOTAN_HAS_GOST) - #include <botan/gost.h> -#endif - -#if defined(BOTAN_HAS_IDEA) - #include <botan/idea.h> -#endif - -#if defined(BOTAN_HAS_KASUMI) - #include <botan/kasumi.h> -#endif - -#if defined(BOTAN_HAS_LION) - #include <botan/lion.h> -#endif - -#if defined(BOTAN_HAS_LUBY_RACKOFF) - #include <botan/lubyrack.h> -#endif - -#if defined(BOTAN_HAS_MARS) - #include <botan/mars.h> -#endif - -#if defined(BOTAN_HAS_MISTY1) - #include <botan/misty1.h> -#endif - -#if defined(BOTAN_HAS_NOEKEON) - #include <botan/noekeon.h> -#endif - -#if defined(BOTAN_HAS_RC2) - #include <botan/rc2.h> -#endif - -#if defined(BOTAN_HAS_RC5) - #include <botan/rc5.h> -#endif - -#if defined(BOTAN_HAS_RC6) - #include <botan/rc6.h> -#endif - -#if defined(BOTAN_HAS_SAFER) - #include <botan/safer_sk.h> -#endif - -#if defined(BOTAN_HAS_SEED) - #include <botan/seed.h> -#endif - -#if defined(BOTAN_HAS_SERPENT) - #include <botan/serpent.h> -#endif - -#if defined(BOTAN_HAS_SERPENT_IA32) - #include <botan/serp_ia32.h> -#endif - -#if defined(BOTAN_HAS_SKIPJACK) - #include <botan/skipjack.h> -#endif - -#if defined(BOTAN_HAS_SQUARE) - #include <botan/square.h> -#endif - -#if defined(BOTAN_HAS_TEA) - #include <botan/tea.h> -#endif - -#if defined(BOTAN_HAS_TWOFISH) - #include <botan/twofish.h> -#endif - -#if defined(BOTAN_HAS_XTEA) - #include <botan/xtea.h> -#endif - -#if defined(BOTAN_HAS_ARC4) - #include <botan/arc4.h> -#endif - -#if defined(BOTAN_HAS_SALSA20) - #include <botan/salsa20.h> -#endif - -#if defined(BOTAN_HAS_TURING) - #include <botan/turing.h> -#endif - -#if defined(BOTAN_HAS_WID_WAKE) - #include <botan/wid_wake.h> -#endif - -#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) - #include <botan/mode_pad.h> -#endif - -namespace Botan { - -/************************************************* -* Some macros to simplify control flow * -*************************************************/ -#define HANDLE_TYPE_NO_ARGS(NAME, TYPE) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE; \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -#define HANDLE_TYPE_ONE_U32BIT(NAME, TYPE, DEFAULT) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE(DEFAULT); \ - if(name.size() == 2) \ - return new TYPE(to_u32bit(name[1])); \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -#define HANDLE_TYPE_TWO_U32BIT(NAME, TYPE, DEFAULT) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE(DEFAULT); \ - if(name.size() == 2) \ - return new TYPE(to_u32bit(name[1])); \ - if(name.size() == 3) \ - return new TYPE(to_u32bit(name[1]), to_u32bit(name[2])); \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -BlockCipher* -Default_Engine::find_block_cipher(const std::string& algo_spec) const - { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_AES) - HANDLE_TYPE_NO_ARGS("AES", AES); - HANDLE_TYPE_NO_ARGS("AES-128", AES_128); - HANDLE_TYPE_NO_ARGS("AES-192", AES_192); - HANDLE_TYPE_NO_ARGS("AES-256", AES_256); -#endif - -#if defined(BOTAN_HAS_BLOWFISH) - HANDLE_TYPE_NO_ARGS("Blowfish", Blowfish); -#endif - -#if defined(BOTAN_HAS_CAST) - HANDLE_TYPE_NO_ARGS("CAST-128", CAST_128); - HANDLE_TYPE_NO_ARGS("CAST-256", CAST_256); -#endif - -#if defined(BOTAN_HAS_DES) - HANDLE_TYPE_NO_ARGS("DES", DES); - HANDLE_TYPE_NO_ARGS("DESX", DESX); - HANDLE_TYPE_NO_ARGS("TripleDES", TripleDES); -#endif - -#if defined(BOTAN_HAS_GOST) - HANDLE_TYPE_NO_ARGS("GOST", GOST); -#endif - -#if defined(BOTAN_HAS_IDEA) - HANDLE_TYPE_NO_ARGS("IDEA", IDEA); -#endif - -#if defined(BOTAN_HAS_KASUMI) - HANDLE_TYPE_NO_ARGS("KASUMI", KASUMI); -#endif - -#if defined(BOTAN_HAS_MARS) - HANDLE_TYPE_NO_ARGS("MARS", MARS); -#endif - -#if defined(BOTAN_HAS_MISTY1) - HANDLE_TYPE_ONE_U32BIT("MISTY1", MISTY1, 8); -#endif - -#if defined(BOTAN_HAS_NOEKEON) - HANDLE_TYPE_NO_ARGS("Noekeon", Noekeon); -#endif - -#if defined(BOTAN_HAS_RC2) - HANDLE_TYPE_NO_ARGS("RC2", RC2); -#endif - -#if defined(BOTAN_HAS_RC5) - HANDLE_TYPE_ONE_U32BIT("RC5", RC5, 12); -#endif - -#if defined(BOTAN_HAS_RC6) - HANDLE_TYPE_NO_ARGS("RC6", RC6); -#endif - -#if defined(BOTAN_HAS_SAFER) - HANDLE_TYPE_ONE_U32BIT("SAFER-SK", SAFER_SK, 10); -#endif - -#if defined(BOTAN_HAS_SEED) - HANDLE_TYPE_NO_ARGS("SEED", SEED); -#endif - -#if defined(BOTAN_HAS_SERPENT_IA32) - HANDLE_TYPE_NO_ARGS("Serpent", Serpent_IA32); -#elif defined(BOTAN_HAS_SERPENT) - HANDLE_TYPE_NO_ARGS("Serpent", Serpent); -#endif - -#if defined(BOTAN_HAS_SKIPJACK) - HANDLE_TYPE_NO_ARGS("Skipjack", Skipjack); -#endif - -#if defined(BOTAN_HAS_SQUARE) - HANDLE_TYPE_NO_ARGS("Square", Square); -#endif - -#if defined(BOTAN_HAS_TEA) - HANDLE_TYPE_NO_ARGS("TEA", TEA); -#endif - -#if defined(BOTAN_HAS_TWOFISH) - HANDLE_TYPE_NO_ARGS("Twofish", Twofish); -#endif - -#if defined(BOTAN_HAS_XTEA) - HANDLE_TYPE_NO_ARGS("XTEA", XTEA); -#endif - -#if defined(BOTAN_HAS_LUBY_RACKOFF) - if(algo_name == "Luby-Rackoff" && name.size() >= 2) - { - HashFunction* hash = get_hash(name[1]); - if(hash) - return new LubyRackoff(hash); - } -#endif - -#if defined(BOTAN_HAS_LION) - if(algo_name == "Lion") - { - if(name.size() != 4) - throw Invalid_Algorithm_Name(algo_spec); - - std::auto_ptr<HashFunction> hash(get_hash(name[1])); - if(!hash.get()) - throw Algorithm_Not_Found(name[1]); - - std::auto_ptr<StreamCipher> sc(get_stream_cipher(name[2])); - if(!sc.get()) - throw Algorithm_Not_Found(name[2]); - - return new Lion(hash.release(), sc.release(), to_u32bit(name[3])); - } -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -StreamCipher* -Default_Engine::find_stream_cipher(const std::string& algo_spec) const - { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_ARC4) - HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0); - HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768); -#endif - -#if defined(BOTAN_HAS_SALSA20) - HANDLE_TYPE_NO_ARGS("Salsa20", Salsa20); -#endif - -#if defined(BOTAN_HAS_TURING) - HANDLE_TYPE_NO_ARGS("Turing", Turing); -#endif - -#if defined(BOTAN_HAS_WID_WAKE) - HANDLE_TYPE_NO_ARGS("WiderWake4+1-BE", WiderWake_41_BE); -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -BlockCipherModePaddingMethod* -Default_Engine::find_bc_pad(const std::string& algo_spec) const - { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) - HANDLE_TYPE_NO_ARGS("PKCS7", PKCS7_Padding); - HANDLE_TYPE_NO_ARGS("OneAndZeros", OneAndZeros_Padding); - HANDLE_TYPE_NO_ARGS("X9.23", ANSI_X923_Padding); - HANDLE_TYPE_NO_ARGS("NoPadding", Null_Padding); -#endif - - return 0; - } - -} diff --git a/src/libstate/lookup_hash.cpp b/src/libstate/lookup_hash.cpp deleted file mode 100644 index 14ca5a859..000000000 --- a/src/libstate/lookup_hash.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/************************************************* -* Hash Algorithms Lookup * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/eng_def.h> -#include <botan/lookup.h> -#include <botan/libstate.h> -#include <botan/parsing.h> -#include <memory> - -#if defined(BOTAN_HAS_ADLER32) - #include <botan/adler32.h> -#endif - -#if defined(BOTAN_HAS_CRC24) - #include <botan/crc24.h> -#endif - -#if defined(BOTAN_HAS_CRC32) - #include <botan/crc32.h> -#endif - -#if defined(BOTAN_HAS_FORK_256) - #include <botan/fork256.h> -#endif - -#if defined(BOTAN_HAS_HAS_160) - #include <botan/has160.h> -#endif - -#if defined(BOTAN_HAS_MD2) - #include <botan/md2.h> -#endif - -#if defined(BOTAN_HAS_MD4) - #include <botan/md4.h> -#endif - -#if defined(BOTAN_HAS_MD4_IA32) - #include <botan/md4_ia32.h> -#endif - -#if defined(BOTAN_HAS_MD5) - #include <botan/md5.h> -#endif - -#if defined(BOTAN_HAS_MD5_IA32) - #include <botan/md5_ia32.h> -#endif - -#if defined(BOTAN_HAS_RIPEMD_128) - #include <botan/rmd128.h> -#endif - -#if defined(BOTAN_HAS_RIPEMD_160) - #include <botan/rmd160.h> -#endif - -#if defined(BOTAN_HAS_SHA1) - #include <botan/sha160.h> -#endif - -#if defined(BOTAN_HAS_SHA1_IA32) - #include <botan/sha1_ia32.h> -#endif - -#if defined(BOTAN_HAS_SHA1_SSE2) - #include <botan/sha1_sse2.h> -#endif - -#if defined(BOTAN_HAS_SHA1_AMD64) - #include <botan/sha1_amd64.h> -#endif - -#if defined(BOTAN_HAS_SHA2) - #include <botan/sha2_32.h> - #include <botan/sha2_64.h> -#endif - -#if defined(BOTAN_HAS_TIGER) - #include <botan/tiger.h> -#endif - -#if defined(BOTAN_HAS_WHIRLPOOL) - #include <botan/whrlpool.h> -#endif - -#if defined(BOTAN_HAS_PARALLEL_HASH) - #include <botan/par_hash.h> -#endif - -namespace Botan { - -/************************************************* -* Some macros to simplify control flow * -*************************************************/ -#define HANDLE_TYPE_NO_ARGS(NAME, TYPE) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE; \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -#define HANDLE_TYPE_TWO_U32BIT(NAME, TYPE, DEFAULT) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE(DEFAULT); \ - if(name.size() == 2) \ - return new TYPE(to_u32bit(name[1])); \ - if(name.size() == 3) \ - return new TYPE(to_u32bit(name[1]), to_u32bit(name[2])); \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -HashFunction* -Default_Engine::find_hash(const std::string& algo_spec) const - { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_ADLER32) - HANDLE_TYPE_NO_ARGS("Adler32", Adler32); -#endif - -#if defined(BOTAN_HAS_CRC24) - HANDLE_TYPE_NO_ARGS("CRC24", CRC24); -#endif - -#if defined(BOTAN_HAS_CRC32) - HANDLE_TYPE_NO_ARGS("CRC32", CRC32); -#endif - -#if defined(BOTAN_HAS_FORK_256) - HANDLE_TYPE_NO_ARGS("FORK-256", FORK_256); -#endif - -#if defined(BOTAN_HAS_HAS_160) - HANDLE_TYPE_NO_ARGS("HAS-160", HAS_160); -#endif - -#if defined(BOTAN_HAS_MD2) - HANDLE_TYPE_NO_ARGS("MD2", MD2); -#endif - -#if defined(BOTAN_HAS_MD4_IA32) - HANDLE_TYPE_NO_ARGS("MD4", MD4_IA32); -#elif defined(BOTAN_HAS_MD4) - HANDLE_TYPE_NO_ARGS("MD4", MD4); -#endif - -#if defined(BOTAN_HAS_MD5_IA32) - HANDLE_TYPE_NO_ARGS("MD5", MD5_IA32); -#elif defined(BOTAN_HAS_MD5) - HANDLE_TYPE_NO_ARGS("MD5", MD5); -#endif - -#if defined(BOTAN_HAS_RIPEMD_128) - HANDLE_TYPE_NO_ARGS("RIPEMD-128", RIPEMD_128); -#endif - -#if defined(BOTAN_HAS_RIPEMD_160) - HANDLE_TYPE_NO_ARGS("RIPEMD-160", RIPEMD_160); -#endif - -#if defined(BOTAN_HAS_SHA1_SSE2) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_SSE2); -#elif defined(BOTAN_HAS_SHA1_AMD64) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_AMD64); -#elif defined(BOTAN_HAS_SHA1_IA32) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_IA32); -#elif defined(BOTAN_HAS_SHA1) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160); -#endif - -#if defined(BOTAN_HAS_SHA2) - HANDLE_TYPE_NO_ARGS("SHA-224", SHA_224); - HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256); - HANDLE_TYPE_NO_ARGS("SHA-384", SHA_384); - HANDLE_TYPE_NO_ARGS("SHA-512", SHA_512); -#endif - -#if defined(BOTAN_HAS_TIGER) - HANDLE_TYPE_TWO_U32BIT("Tiger", Tiger, 24); -#endif - -#if defined(BOTAN_HAS_WHIRLPOOL) - HANDLE_TYPE_NO_ARGS("Whirlpool", Whirlpool); -#endif - -#if defined(BOTAN_HAS_PARALLEL_HASH) - if(algo_name == "Parallel") - { - if(name.size() < 2) - throw Invalid_Algorithm_Name(algo_spec); - name.erase(name.begin()); - return new Parallel(name); - } -#endif - - return 0; - } - -} diff --git a/src/libstate/lookup_mac.cpp b/src/libstate/lookup_mac.cpp deleted file mode 100644 index baaea15dd..000000000 --- a/src/libstate/lookup_mac.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************* -* MAC Lookup * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/eng_def.h> -#include <botan/lookup.h> -#include <botan/libstate.h> -#include <botan/parsing.h> - -#if defined(BOTAN_HAS_CBC_MAC) - #include <botan/cbc_mac.h> -#endif - -#if defined(BOTAN_HAS_CMAC) - #include <botan/cmac.h> -#endif - -#if defined(BOTAN_HAS_HMAC) - #include <botan/hmac.h> -#endif - -#if defined(BOTAN_HAS_SSL3_MAC) - #include <botan/ssl3_mac.h> -#endif - -#if defined(BOTAN_HAS_ANSI_X919_MAC) - #include <botan/x919_mac.h> -#endif - -namespace Botan { - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -MessageAuthenticationCode* -Default_Engine::find_mac(const std::string& algo_spec) const - { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_CBC_MAC) - if(algo_name == "CBC-MAC") - { - if(name.size() == 2) - return new CBC_MAC(get_block_cipher(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - -#if defined(BOTAN_HAS_CMAC) - if(algo_name == "CMAC") - { - if(name.size() == 2) - return new CMAC(get_block_cipher(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - -#if defined(BOTAN_HAS_HMAC) - if(algo_name == "HMAC") - { - if(name.size() == 2) - return new HMAC(get_hash(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - -#if defined(BOTAN_HAS_SSL3_MAC) - if(algo_name == "SSL3-MAC") - { - if(name.size() == 2) - return new SSL3_MAC(get_hash(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - -#if defined(BOTAN_HAS_ANSI_X919_MAC) - if(algo_name == "X9.19-MAC") - { - if(name.size() == 1) - return new ANSI_X919_MAC(get_block_cipher("DES")); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - - return 0; - } - -} diff --git a/src/libstate/lookup_s2k.cpp b/src/libstate/lookup_s2k.cpp deleted file mode 100644 index 91e986abc..000000000 --- a/src/libstate/lookup_s2k.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/************************************************* -* S2K Lookup * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/eng_def.h> -#include <botan/lookup.h> -#include <botan/libstate.h> -#include <botan/parsing.h> - -#if defined(BOTAN_HAS_PBKDF1) - #include <botan/pbkdf1.h> -#endif - -#if defined(BOTAN_HAS_PBKDF2) - #include <botan/pbkdf2.h> -#endif - -#if defined(BOTAN_HAS_PGPS2K) - #include <botan/pgp_s2k.h> -#endif - -namespace Botan { - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -S2K* Default_Engine::find_s2k(const std::string& algo_spec) const - { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_PBKDF1) - if(algo_name == "PBKDF1") - { - if(name.size() == 2) - return new PKCS5_PBKDF1(get_hash(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - -#if defined(BOTAN_HAS_PBKDF2) - if(algo_name == "PBKDF2") - { - if(name.size() == 2) - return new PKCS5_PBKDF2(get_mac("HMAC(" + name[1] + ")")); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - -#if defined(BOTAN_HAS_PGPS2K) - if(algo_name == "OpenPGP-S2K") - { - if(name.size() == 2) - return new OpenPGP_S2K(get_hash(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - - return 0; - } - -} |