diff options
author | lloyd <[email protected]> | 2008-11-10 21:40:08 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-10 21:40:08 +0000 |
commit | a886514a112f32351025454ff2c316ebd17684e2 (patch) | |
tree | 1ecdc630266894f2593a72c0073e9c040d2c458f /src/libstate | |
parent | 78c642d4ed03aca15ae211595f796296ea5e86bd (diff) |
Move block and stream ciphers also into Algorithm_Factory
Diffstat (limited to 'src/libstate')
-rw-r--r-- | src/libstate/algo_factory.cpp | 106 | ||||
-rw-r--r-- | src/libstate/algo_factory.h | 12 | ||||
-rw-r--r-- | src/libstate/engine/def_engine/def_eng.h | 7 | ||||
-rw-r--r-- | src/libstate/engine/def_engine/lookup_block.cpp | 17 | ||||
-rw-r--r-- | src/libstate/engine/def_engine/lookup_stream.cpp | 5 | ||||
-rw-r--r-- | src/libstate/engine/engine.cpp | 34 | ||||
-rw-r--r-- | src/libstate/engine/engine.h | 31 | ||||
-rw-r--r-- | src/libstate/engine/openssl/eng_ossl.cpp | 6 | ||||
-rw-r--r-- | src/libstate/engine/openssl/eng_ossl.h | 8 | ||||
-rw-r--r-- | src/libstate/engine/openssl/ossl_bc.cpp | 6 | ||||
-rw-r--r-- | src/libstate/engine/openssl/ossl_md.cpp | 1 | ||||
-rw-r--r-- | src/libstate/lookup.cpp | 270 |
12 files changed, 293 insertions, 210 deletions
diff --git a/src/libstate/algo_factory.cpp b/src/libstate/algo_factory.cpp index 4ae3a251a..e4ddc473e 100644 --- a/src/libstate/algo_factory.cpp +++ b/src/libstate/algo_factory.cpp @@ -7,6 +7,9 @@ Algorithm Factory #include <botan/stl_util.h> #include <botan/engine.h> #include <botan/exceptn.h> + +#include <botan/block_cipher.h> +#include <botan/stream_cipher.h> #include <botan/hash.h> #include <botan/mac.h> @@ -44,6 +47,106 @@ Engine* Algorithm_Factory::get_engine_n(u32bit n) const /** * Return the prototypical object cooresponding to this request */ +const BlockCipher* +Algorithm_Factory::prototype_block_cipher(const SCAN_Name& request) + { + for(u32bit i = 0; i != engines.size(); ++i) + { + if(request.provider_allowed(engines[i]->provider_name())) + { + const BlockCipher* algo = + engines[i]->prototype_block_cipher(request, *this); + + if(algo) + return algo; + } + } + + return 0; + } + +/** +* Return a new object cooresponding to this request +*/ +BlockCipher* Algorithm_Factory::make_block_cipher(const SCAN_Name& request) + { + const BlockCipher* prototype = prototype_block_cipher(request); + if(prototype) + return prototype->clone(); + + throw Algorithm_Not_Found(request.as_string()); + } + +/** +* Add a new object +*/ +void Algorithm_Factory::add_block_cipher(BlockCipher* hash) + { + for(u32bit i = 0; i != engines.size(); ++i) + { + if(engines[i]->can_add_algorithms()) + { + engines[i]->add_algorithm(hash); + return; + } + } + + throw Exception("Algorithm_Factory::add_block_cipher: No engine found"); + } + +/** +* Return the prototypical object cooresponding to this request +*/ +const StreamCipher* +Algorithm_Factory::prototype_stream_cipher(const SCAN_Name& request) + { + for(u32bit i = 0; i != engines.size(); ++i) + { + if(request.provider_allowed(engines[i]->provider_name())) + { + const StreamCipher* algo = + engines[i]->prototype_stream_cipher(request, *this); + + if(algo) + return algo; + } + } + + return 0; + } + +/** +* Return a new object cooresponding to this request +*/ +StreamCipher* Algorithm_Factory::make_stream_cipher(const SCAN_Name& request) + { + const StreamCipher* prototype = prototype_stream_cipher(request); + if(prototype) + return prototype->clone(); + + throw Algorithm_Not_Found(request.as_string()); + } + +/** +* Add a new object +*/ +void Algorithm_Factory::add_stream_cipher(StreamCipher* hash) + { + for(u32bit i = 0; i != engines.size(); ++i) + { + if(engines[i]->can_add_algorithms()) + { + engines[i]->add_algorithm(hash); + return; + } + } + + throw Exception("Algorithm_Factory::add_stream_cipher: No engine found"); + } + +/** +* Return the prototypical object cooresponding to this request +*/ const HashFunction* Algorithm_Factory::prototype_hash_function(const SCAN_Name& request) { @@ -91,8 +194,6 @@ void Algorithm_Factory::add_hash_function(HashFunction* hash) throw Exception("Algorithm_Factory::add_hash_function: No engine found"); } - - /** * Return the prototypical object cooresponding to this request */ @@ -144,5 +245,4 @@ void Algorithm_Factory::add_mac(MessageAuthenticationCode* hash) throw Exception("Algorithm_Factory::add_mac: No engine found"); } - } diff --git a/src/libstate/algo_factory.h b/src/libstate/algo_factory.h index 098c7836b..2513c42c9 100644 --- a/src/libstate/algo_factory.h +++ b/src/libstate/algo_factory.h @@ -13,6 +13,8 @@ namespace Botan { +class BlockCipher; +class StreamCipher; class HashFunction; class MessageAuthenticationCode; @@ -37,6 +39,16 @@ class BOTAN_DLL Algorithm_Factory }; friend class Engine_Iterator; + // Block cipher operations + const BlockCipher* prototype_block_cipher(const SCAN_Name& request); + BlockCipher* make_block_cipher(const SCAN_Name& request); + void add_block_cipher(BlockCipher* hash); + + // Stream cipher operations + const StreamCipher* prototype_stream_cipher(const SCAN_Name& request); + StreamCipher* make_stream_cipher(const SCAN_Name& request); + void add_stream_cipher(StreamCipher* hash); + // Hash function operations const HashFunction* prototype_hash_function(const SCAN_Name& request); HashFunction* make_hash_function(const SCAN_Name& request); diff --git a/src/libstate/engine/def_engine/def_eng.h b/src/libstate/engine/def_engine/def_eng.h index fe05e9fce..0c95c08c5 100644 --- a/src/libstate/engine/def_engine/def_eng.h +++ b/src/libstate/engine/def_engine/def_eng.h @@ -61,8 +61,11 @@ class BOTAN_DLL Default_Engine : public Engine 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; + BlockCipher* find_block_cipher(const SCAN_Name&, + Algorithm_Factory&) const; + + StreamCipher* find_stream_cipher(const SCAN_Name&, + Algorithm_Factory&) const; HashFunction* find_hash(const SCAN_Name& reqeust, Algorithm_Factory&) const; diff --git a/src/libstate/engine/def_engine/lookup_block.cpp b/src/libstate/engine/def_engine/lookup_block.cpp index 00d9ad03c..d9da83afd 100644 --- a/src/libstate/engine/def_engine/lookup_block.cpp +++ b/src/libstate/engine/def_engine/lookup_block.cpp @@ -6,6 +6,7 @@ #include <botan/def_eng.h> #include <botan/lookup.h> #include <botan/scan_name.h> +#include <botan/algo_factory.h> #include <memory> #if defined(BOTAN_HAS_AES) @@ -112,9 +113,9 @@ namespace Botan { * Look for an algorithm with this name * *************************************************/ BlockCipher* -Default_Engine::find_block_cipher(const std::string& algo_spec) const +Default_Engine::find_block_cipher(const SCAN_Name& request, + Algorithm_Factory& af) const { - SCAN_Name request(algo_spec); #if defined(BOTAN_HAS_AES) if(request.algo_name() == "AES") @@ -239,9 +240,11 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const #if defined(BOTAN_HAS_LUBY_RACKOFF) if(request.algo_name() == "Luby-Rackoff" && request.arg_count() == 1) { - HashFunction* hash = get_hash(request.argument(0)); + const HashFunction* hash = + af.make_hash_function(request.argument(0)); + if(hash) - return new LubyRackoff(hash); + return new LubyRackoff(hash->clone()); } #endif @@ -250,15 +253,15 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const { const u32bit block_size = request.argument_as_u32bit(2, 1024); - std::auto_ptr<HashFunction> hash(get_hash(request.argument(0))); - if(!hash.get()) + const HashFunction* hash = af.make_hash_function(request.argument(0)); + if(!hash) return 0; std::auto_ptr<StreamCipher> sc(get_stream_cipher(request.argument(1))); if(!sc.get()) return 0; - return new Lion(hash.release(), sc.release(), block_size); + return new Lion(hash->clone(), sc.release(), block_size); } #endif diff --git a/src/libstate/engine/def_engine/lookup_stream.cpp b/src/libstate/engine/def_engine/lookup_stream.cpp index 252fb545a..87ae6c62a 100644 --- a/src/libstate/engine/def_engine/lookup_stream.cpp +++ b/src/libstate/engine/def_engine/lookup_stream.cpp @@ -28,10 +28,9 @@ namespace Botan { * Look for an algorithm with this name * *************************************************/ StreamCipher* -Default_Engine::find_stream_cipher(const std::string& algo_spec) const +Default_Engine::find_stream_cipher(const SCAN_Name& request, + Algorithm_Factory&) const { - SCAN_Name request(algo_spec); - #if defined(BOTAN_HAS_ARC4) if(request.algo_name() == "ARC4") return new ARC4(request.argument_as_u32bit(0, 0)); diff --git a/src/libstate/engine/engine.cpp b/src/libstate/engine/engine.cpp index f973c0939..cd9db5141 100644 --- a/src/libstate/engine/engine.cpp +++ b/src/libstate/engine/engine.cpp @@ -63,19 +63,41 @@ class Algorithm_Cache_Impl : public Engine::Algorithm_Cache<T> /************************************************* * Acquire a BlockCipher * *************************************************/ -const BlockCipher* Engine::block_cipher(const std::string& name) const +const BlockCipher* +Engine::prototype_block_cipher(const SCAN_Name& request, + Algorithm_Factory& af) const { - return lookup_algo(cache_of_bc, global_state().deref_alias(name), - this, &Engine::find_block_cipher); + // This needs to respect provider settings + BlockCipher* algo = cache_of_bc->get(request.as_string()); + if(algo) + return algo; + + // cache miss: do full search + algo = find_block_cipher(request, af); + if(algo) + cache_of_bc->add(algo, request.as_string()); + + return algo; } /************************************************* * Acquire a StreamCipher * *************************************************/ -const StreamCipher* Engine::stream_cipher(const std::string& name) const +const StreamCipher* +Engine::prototype_stream_cipher(const SCAN_Name& request, + Algorithm_Factory& af) const { - return lookup_algo(cache_of_sc, global_state().deref_alias(name), - this, &Engine::find_stream_cipher); + // This needs to respect provider settings + StreamCipher* algo = cache_of_sc->get(request.as_string()); + if(algo) + return algo; + + // cache miss: do full search + algo = find_stream_cipher(request, af); + if(algo) + cache_of_sc->add(algo, request.as_string()); + + return algo; } /************************************************* diff --git a/src/libstate/engine/engine.h b/src/libstate/engine/engine.h index 74b40e637..42fc1e0d7 100644 --- a/src/libstate/engine/engine.h +++ b/src/libstate/engine/engine.h @@ -120,8 +120,13 @@ class BOTAN_DLL Engine { return 0; } // Prototype object accessors - const BlockCipher* block_cipher(const std::string&) const; - const StreamCipher* stream_cipher(const std::string&) const; + const BlockCipher* + prototype_block_cipher(const SCAN_Name& request, + Algorithm_Factory& af) const; + + const StreamCipher* + prototype_stream_cipher(const SCAN_Name& request, + Algorithm_Factory& af) const; const HashFunction* prototype_hash_function(const SCAN_Name& request, @@ -144,10 +149,12 @@ class BOTAN_DLL Engine Engine(); virtual ~Engine(); private: - virtual BlockCipher* find_block_cipher(const std::string&) const + virtual BlockCipher* find_block_cipher(const SCAN_Name&, + Algorithm_Factory&) const { return 0; } - virtual StreamCipher* find_stream_cipher(const std::string&) const + virtual StreamCipher* find_stream_cipher(const SCAN_Name&, + Algorithm_Factory&) const { return 0; } virtual HashFunction* find_hash(const SCAN_Name&, @@ -158,22 +165,6 @@ class BOTAN_DLL Engine Algorithm_Factory&) const { return 0; } - 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; diff --git a/src/libstate/engine/openssl/eng_ossl.cpp b/src/libstate/engine/openssl/eng_ossl.cpp index 6aaabcbfc..26e041293 100644 --- a/src/libstate/engine/openssl/eng_ossl.cpp +++ b/src/libstate/engine/openssl/eng_ossl.cpp @@ -5,7 +5,6 @@ OpenSSL Engine #include <botan/eng_ossl.h> #include <botan/arc4_openssl.h> -#include <botan/scan_name.h> namespace Botan { @@ -13,10 +12,9 @@ namespace Botan { * Look for an OpenSSL-suported stream cipher (ARC4) */ StreamCipher* -OpenSSL_Engine::find_stream_cipher(const std::string& algo_spec) const +OpenSSL_Engine::find_stream_cipher(const SCAN_Name& request, + Algorithm_Factory&) { - SCAN_Name request(algo_spec); - if(request.algo_name() == "ARC4") return new ARC4_OpenSSL(request.argument_as_u32bit(0, 0)); if(request.algo_name() == "RC4_drop") diff --git a/src/libstate/engine/openssl/eng_ossl.h b/src/libstate/engine/openssl/eng_ossl.h index 6eb5700d6..7f345f0ff 100644 --- a/src/libstate/engine/openssl/eng_ossl.h +++ b/src/libstate/engine/openssl/eng_ossl.h @@ -48,8 +48,12 @@ class BOTAN_DLL OpenSSL_Engine : public Engine Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints) const; private: - BlockCipher* find_block_cipher(const std::string&) const; - StreamCipher* find_stream_cipher(const std::string&) const; + BlockCipher* find_block_cipher(const SCAN_Name&, + Algorithm_Factory&) const; + + StreamCipher* find_stream_cipher(const SCAN_Name&, + Algorithm_Factory&) const; + HashFunction* find_hash(const SCAN_Name&, Algorithm_Factory&) const; }; diff --git a/src/libstate/engine/openssl/ossl_bc.cpp b/src/libstate/engine/openssl/ossl_bc.cpp index 3427fce59..c6ec0da4e 100644 --- a/src/libstate/engine/openssl/ossl_bc.cpp +++ b/src/libstate/engine/openssl/ossl_bc.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/eng_ossl.h> -#include <botan/scan_name.h> #include <openssl/evp.h> namespace Botan { @@ -162,10 +161,9 @@ void EVP_BlockCipher::clear() throw() * Look for an algorithm with this name * *************************************************/ BlockCipher* -OpenSSL_Engine::find_block_cipher(const std::string& algo_spec) const +OpenSSL_Engine::find_block_cipher(const SCAN_Name& request, + Algorithm_Factory&) { - SCAN_Name request(algo_spec); - #define HANDLE_EVP_CIPHER(NAME, EVP) \ if(request.algo_name() == NAME && request.arg_count() == 0) \ return new EVP_BlockCipher(EVP, NAME); diff --git a/src/libstate/engine/openssl/ossl_md.cpp b/src/libstate/engine/openssl/ossl_md.cpp index 04ef59f99..4e28c515e 100644 --- a/src/libstate/engine/openssl/ossl_md.cpp +++ b/src/libstate/engine/openssl/ossl_md.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/eng_ossl.h> -#include <botan/scan_name.h> #include <openssl/evp.h> namespace Botan { diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp index 501f973b0..cbd2ff616 100644 --- a/src/libstate/lookup.cpp +++ b/src/libstate/lookup.cpp @@ -9,98 +9,126 @@ namespace Botan { -/************************************************* -* Acquire a hash function * -*************************************************/ +/** +* Acquire a block cipher +*/ +const BlockCipher* retrieve_block_cipher(Library_State& libstate, + const std::string& algo_spec) + { + return libstate.algo_factory().prototype_block_cipher(algo_spec); + } + +/** +* Get a block cipher by name +*/ +BlockCipher* get_block_cipher(const std::string& algo_spec) + { + return global_state().algo_factory().make_block_cipher(algo_spec); + } + +/** +* Add a new block cipher +*/ +void add_algorithm(Library_State& libstate, BlockCipher* algo) + { + libstate.algo_factory().add_block_cipher(algo); + } + +/** +* Acquire a stream cipher +*/ +const StreamCipher* retrieve_stream_cipher(Library_State& libstate, + const std::string& algo_spec) + { + return libstate.algo_factory().prototype_stream_cipher(algo_spec); + } + +/** +* Get a stream cipher by name +*/ +StreamCipher* get_stream_cipher(const std::string& algo_spec) + { + return global_state().algo_factory().make_stream_cipher(algo_spec); + } + +/** +* Add a new stream cipher +*/ +void add_algorithm(Library_State& libstate, StreamCipher* algo) + { + libstate.algo_factory().add_stream_cipher(algo); + } + +/** +* Acquire a hash function +*/ const HashFunction* retrieve_hash(Library_State& libstate, - const std::string& name) + const std::string& algo_spec) { - return libstate.algo_factory().prototype_hash_function(name); + return libstate.algo_factory().prototype_hash_function(algo_spec); } -/************************************************* -* Get a hash function by name * -*************************************************/ +/** +* Get a hash function by name +*/ HashFunction* get_hash(const std::string& algo_spec) { return global_state().algo_factory().make_hash_function(algo_spec); } -/************************************************* -* Add a new hash function * -*************************************************/ +/** +* Add a new hash function +*/ void add_algorithm(Library_State& libstate, HashFunction* algo) { libstate.algo_factory().add_hash_function(algo); } -/************************************************* -* Query if Botan has the named hash function * -*************************************************/ +/** +* Query if Botan has the named hash function +*/ bool have_hash(const std::string& algo_spec) { return global_state().algo_factory().prototype_hash_function(algo_spec); } -/************************************************* -* Acquire an authentication code * -*************************************************/ +/** +* Acquire an authentication code +*/ const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, const std::string& algo_spec) { return libstate.algo_factory().prototype_mac(algo_spec); } -/************************************************* -* Get a MAC by name * -*************************************************/ +/** +* Get a MAC by name +*/ MessageAuthenticationCode* get_mac(const std::string& algo_spec) { return global_state().algo_factory().make_mac(algo_spec); } -/************************************************* -* Query if Botan has the named MAC * -*************************************************/ +/** +* Query if Botan has the named MAC +*/ bool have_mac(const std::string& algo_spec) { return global_state().algo_factory().prototype_mac(algo_spec); } -/************************************************* -* Add a new authentication code * -*************************************************/ +/** +* Add a new authentication code +*/ void add_algorithm(Library_State& libstate, MessageAuthenticationCode* algo) { libstate.algo_factory().add_mac(algo); } -/************************************************* -* Get a block cipher by name * -*************************************************/ -BlockCipher* get_block_cipher(const std::string& name) - { - const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); - if(cipher) - return cipher->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Get a stream cipher by name * -*************************************************/ -StreamCipher* get_stream_cipher(const std::string& name) - { - const StreamCipher* cipher = retrieve_stream_cipher(global_state(), name); - if(cipher) - return cipher->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Query if an algorithm exists * -*************************************************/ +/** +* Query if an algorithm exists +*/ bool have_algorithm(const std::string& name) { if(retrieve_block_cipher(global_state(), name)) @@ -114,25 +142,25 @@ bool have_algorithm(const std::string& name) return false; } -/************************************************* -* Query if Botan has the named block cipher * -*************************************************/ +/** +* Query if Botan has the named block cipher +*/ bool have_block_cipher(const std::string& name) { return (retrieve_block_cipher(global_state(), name) != 0); } -/************************************************* -* Query if Botan has the named stream cipher * -*************************************************/ +/** +* Query if Botan has the named stream cipher +*/ bool have_stream_cipher(const std::string& name) { return (retrieve_stream_cipher(global_state(), name) != 0); } -/************************************************* -* Query the block size of a cipher or hash * -*************************************************/ +/** +* Query the block size of a cipher or hash +*/ u32bit block_size_of(const std::string& name) { const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); @@ -146,9 +174,9 @@ u32bit block_size_of(const std::string& name) throw Algorithm_Not_Found(name); } -/************************************************* -* Query the OUTPUT_LENGTH of a hash or MAC * -*************************************************/ +/** +* Query the OUTPUT_LENGTH of a hash or MAC +*/ u32bit output_length_of(const std::string& name) { const HashFunction* hash = retrieve_hash(global_state(), name); @@ -162,9 +190,9 @@ u32bit output_length_of(const std::string& name) throw Algorithm_Not_Found(name); } -/************************************************* -* Check if a keylength is valid for this algo * -*************************************************/ +/** +* Check if a keylength is valid for this algo +*/ bool valid_keylength_for(u32bit key_len, const std::string& name) { const BlockCipher* bc = retrieve_block_cipher(global_state(), name); @@ -182,9 +210,9 @@ bool valid_keylength_for(u32bit key_len, const std::string& name) throw Algorithm_Not_Found(name); } -/************************************************* -* Query the MINIMUM_KEYLENGTH of an algorithm * -*************************************************/ +/** +* Query the MINIMUM_KEYLENGTH of an algorithm +*/ u32bit min_keylength_of(const std::string& name) { const BlockCipher* bc = retrieve_block_cipher(global_state(), name); @@ -202,9 +230,9 @@ u32bit min_keylength_of(const std::string& name) throw Algorithm_Not_Found(name); } -/************************************************* -* Query the MAXIMUM_KEYLENGTH of an algorithm * -*************************************************/ +/** +* Query the MAXIMUM_KEYLENGTH of an algorithm +*/ u32bit max_keylength_of(const std::string& name) { const BlockCipher* bc = retrieve_block_cipher(global_state(), name); @@ -222,9 +250,9 @@ u32bit max_keylength_of(const std::string& name) throw Algorithm_Not_Found(name); } -/************************************************* -* Query the KEYLENGTH_MULTIPLE of an algorithm * -*************************************************/ +/** +* Query the KEYLENGTH_MULTIPLE of an algorithm +*/ u32bit keylength_multiple_of(const std::string& name) { const BlockCipher* bc = retrieve_block_cipher(global_state(), name); @@ -242,83 +270,9 @@ u32bit keylength_multiple_of(const std::string& name) throw Algorithm_Not_Found(name); } -/************************************************* -* Acquire a block cipher * -*************************************************/ -const BlockCipher* retrieve_block_cipher(Library_State& libstate, - const std::string& name) - { - Algorithm_Factory::Engine_Iterator i(libstate.algo_factory()); - - 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) - { - Algorithm_Factory::Engine_Iterator i(libstate.algo_factory()); - - while(const Engine* engine = i.next()) - { - const StreamCipher* algo = engine->stream_cipher(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Add a new block cipher * -*************************************************/ -void add_algorithm(Library_State& libstate, BlockCipher* algo) - { - Algorithm_Factory::Engine_Iterator i(libstate.algo_factory()); - - while(Engine* engine = i.next()) - { - if(engine->can_add_algorithms()) - { - 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) - { - Algorithm_Factory::Engine_Iterator i(libstate.algo_factory()); - - while(Engine* engine = i.next()) - { - if(engine->can_add_algorithms()) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Get a cipher object * -*************************************************/ +/** +* Get a cipher object +*/ Keyed_Filter* get_cipher(const std::string& algo_spec, Cipher_Dir direction) { @@ -334,9 +288,9 @@ Keyed_Filter* get_cipher(const std::string& algo_spec, throw Algorithm_Not_Found(algo_spec); } -/************************************************* -* Get a cipher object * -*************************************************/ +/** +* Get a cipher object +*/ Keyed_Filter* get_cipher(const std::string& algo_spec, const SymmetricKey& key, const InitializationVector& iv, @@ -351,9 +305,9 @@ Keyed_Filter* get_cipher(const std::string& algo_spec, return cipher; } -/************************************************* -* Get a cipher object * -*************************************************/ +/** +* Get a cipher object +*/ Keyed_Filter* get_cipher(const std::string& algo_spec, const SymmetricKey& key, Cipher_Dir direction) |