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/lookup.cpp | |
parent | 78c642d4ed03aca15ae211595f796296ea5e86bd (diff) |
Move block and stream ciphers also into Algorithm_Factory
Diffstat (limited to 'src/libstate/lookup.cpp')
-rw-r--r-- | src/libstate/lookup.cpp | 270 |
1 files changed, 112 insertions, 158 deletions
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) |