diff options
author | lloyd <[email protected]> | 2008-09-29 03:34:12 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-29 03:34:12 +0000 |
commit | 7553b5f1461d58eae49e81c2e9bacdf0ea7d4cab (patch) | |
tree | 695c966ed348afd43a8d48979f02205cc6ad5f77 /src/core | |
parent | ce7ef966e3a52731ad9d12a539d8db7fabe9f793 (diff) |
Expose use of global state in some of the lookup functions, including
get_cipher
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/engine.cpp | 68 | ||||
-rw-r--r-- | src/core/look_add.h | 13 | ||||
-rw-r--r-- | src/core/lookup.cpp | 63 | ||||
-rw-r--r-- | src/core/lookup.h | 30 |
4 files changed, 101 insertions, 73 deletions
diff --git a/src/core/engine.cpp b/src/core/engine.cpp index 8511c07c2..804ab3580 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -123,9 +123,10 @@ Modular_Exponentiator* mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) /************************************************* * Acquire a block cipher * *************************************************/ -const BlockCipher* retrieve_block_cipher(const std::string& name) +const BlockCipher* retrieve_block_cipher(Library_State& libstate, + const std::string& name) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(const Engine* engine = i.next()) { @@ -140,9 +141,10 @@ const BlockCipher* retrieve_block_cipher(const std::string& name) /************************************************* * Acquire a stream cipher * *************************************************/ -const StreamCipher* retrieve_stream_cipher(const std::string& name) +const StreamCipher* retrieve_stream_cipher(Library_State& libstate, + const std::string& name) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(const Engine* engine = i.next()) { @@ -157,9 +159,10 @@ const StreamCipher* retrieve_stream_cipher(const std::string& name) /************************************************* * Acquire a hash function * *************************************************/ -const HashFunction* retrieve_hash(const std::string& name) +const HashFunction* retrieve_hash(Library_State& libstate, + const std::string& name) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(const Engine* engine = i.next()) { @@ -174,9 +177,10 @@ const HashFunction* retrieve_hash(const std::string& name) /************************************************* * Acquire an authentication code * *************************************************/ -const MessageAuthenticationCode* retrieve_mac(const std::string& name) +const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, + const std::string& name) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(const Engine* engine = i.next()) { @@ -191,9 +195,10 @@ const MessageAuthenticationCode* retrieve_mac(const std::string& name) /************************************************* * Acquire a string-to-key algorithm * *************************************************/ -const S2K* retrieve_s2k(const std::string& name) +const S2K* retrieve_s2k(Library_State& libstate, + const std::string& name) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(const Engine* engine = i.next()) { @@ -208,9 +213,10 @@ const S2K* retrieve_s2k(const std::string& name) /************************************************* * Retrieve a block cipher padding method * *************************************************/ -const BlockCipherModePaddingMethod* retrieve_bc_pad(const std::string& name) +const BlockCipherModePaddingMethod* retrieve_bc_pad(Library_State& libstate, + const std::string& name) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(const Engine* engine = i.next()) { @@ -225,9 +231,9 @@ const BlockCipherModePaddingMethod* retrieve_bc_pad(const std::string& name) /************************************************* * Add a new block cipher * *************************************************/ -void add_algorithm(BlockCipher* algo) +void add_algorithm(Library_State& libstate, BlockCipher* algo) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(Engine* engine_base = i.next()) { @@ -245,9 +251,9 @@ void add_algorithm(BlockCipher* algo) /************************************************* * Add a new stream cipher * *************************************************/ -void add_algorithm(StreamCipher* algo) +void add_algorithm(Library_State& libstate, StreamCipher* algo) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(Engine* engine_base = i.next()) { @@ -265,9 +271,9 @@ void add_algorithm(StreamCipher* algo) /************************************************* * Add a new hash function * *************************************************/ -void add_algorithm(HashFunction* algo) +void add_algorithm(Library_State& libstate, HashFunction* algo) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(Engine* engine_base = i.next()) { @@ -285,9 +291,10 @@ void add_algorithm(HashFunction* algo) /************************************************* * Add a new authentication code * *************************************************/ -void add_algorithm(MessageAuthenticationCode* algo) +void add_algorithm(Library_State& libstate, + MessageAuthenticationCode* algo) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(Engine* engine_base = i.next()) { @@ -305,9 +312,10 @@ void add_algorithm(MessageAuthenticationCode* algo) /************************************************* * Add a padding method to the lookup table * *************************************************/ -void add_algorithm(BlockCipherModePaddingMethod* algo) +void add_algorithm(Library_State& libstate, + BlockCipherModePaddingMethod* algo) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(Engine* engine_base = i.next()) { @@ -325,10 +333,11 @@ void add_algorithm(BlockCipherModePaddingMethod* algo) /************************************************* * Get a cipher object * *************************************************/ -Keyed_Filter* get_cipher(const std::string& algo_spec, +Keyed_Filter* get_cipher(Library_State& libstate, + const std::string& algo_spec, Cipher_Dir direction) { - Library_State::Engine_Iterator i(global_state()); + Library_State::Engine_Iterator i(libstate); while(Engine* engine = i.next()) { @@ -343,12 +352,13 @@ Keyed_Filter* get_cipher(const std::string& algo_spec, /************************************************* * Get a cipher object * *************************************************/ -Keyed_Filter* get_cipher(const std::string& algo_spec, +Keyed_Filter* get_cipher(Library_State& libstate, + const std::string& algo_spec, const SymmetricKey& key, const InitializationVector& iv, Cipher_Dir direction) { - Keyed_Filter* cipher = get_cipher(algo_spec, direction); + Keyed_Filter* cipher = get_cipher(libstate, algo_spec, direction); cipher->set_key(key); if(iv.length()) @@ -360,11 +370,13 @@ Keyed_Filter* get_cipher(const std::string& algo_spec, /************************************************* * Get a cipher object * *************************************************/ -Keyed_Filter* get_cipher(const std::string& algo_spec, +Keyed_Filter* get_cipher(Library_State& libstate, + const std::string& algo_spec, const SymmetricKey& key, Cipher_Dir direction) { - return get_cipher(algo_spec, key, InitializationVector(), direction); + return get_cipher(libstate, algo_spec, + key, InitializationVector(), direction); } } diff --git a/src/core/look_add.h b/src/core/look_add.h index 4185cbc0a..8c170049d 100644 --- a/src/core/look_add.h +++ b/src/core/look_add.h @@ -7,6 +7,7 @@ #define BOTAN_LOOKUP_MANGEMENT_H__ #include <botan/base.h> +#include <botan/libstate.h> #include <botan/mode_pad.h> #include <botan/s2k.h> @@ -15,12 +16,12 @@ namespace Botan { /************************************************* * Add an algorithm to the lookup table * *************************************************/ -BOTAN_DLL void add_algorithm(BlockCipher*); -BOTAN_DLL void add_algorithm(StreamCipher*); -BOTAN_DLL void add_algorithm(HashFunction*); -BOTAN_DLL void add_algorithm(MessageAuthenticationCode*); -BOTAN_DLL void add_algorithm(S2K*); -BOTAN_DLL void add_algorithm(BlockCipherModePaddingMethod*); +BOTAN_DLL void add_algorithm(Library_State&, BlockCipher*); +BOTAN_DLL void add_algorithm(Library_State&, StreamCipher*); +BOTAN_DLL void add_algorithm(Library_State&, HashFunction*); +BOTAN_DLL void add_algorithm(Library_State&, MessageAuthenticationCode*); +BOTAN_DLL void add_algorithm(Library_State&, S2K*); +BOTAN_DLL void add_algorithm(Library_State&, BlockCipherModePaddingMethod*); } diff --git a/src/core/lookup.cpp b/src/core/lookup.cpp index 2325c144d..8e65afb93 100644 --- a/src/core/lookup.cpp +++ b/src/core/lookup.cpp @@ -4,6 +4,7 @@ *************************************************/ #include <botan/lookup.h> +#include <botan/libstate.h> namespace Botan { @@ -12,7 +13,7 @@ namespace Botan { *************************************************/ BlockCipher* get_block_cipher(const std::string& name) { - const BlockCipher* cipher = retrieve_block_cipher(name); + const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); if(cipher) return cipher->clone(); throw Algorithm_Not_Found(name); @@ -23,7 +24,7 @@ BlockCipher* get_block_cipher(const std::string& name) *************************************************/ StreamCipher* get_stream_cipher(const std::string& name) { - const StreamCipher* cipher = retrieve_stream_cipher(name); + const StreamCipher* cipher = retrieve_stream_cipher(global_state(), name); if(cipher) return cipher->clone(); throw Algorithm_Not_Found(name); @@ -34,7 +35,7 @@ StreamCipher* get_stream_cipher(const std::string& name) *************************************************/ HashFunction* get_hash(const std::string& name) { - const HashFunction* hash = retrieve_hash(name); + const HashFunction* hash = retrieve_hash(global_state(), name); if(hash) return hash->clone(); throw Algorithm_Not_Found(name); @@ -45,7 +46,7 @@ HashFunction* get_hash(const std::string& name) *************************************************/ MessageAuthenticationCode* get_mac(const std::string& name) { - const MessageAuthenticationCode* mac = retrieve_mac(name); + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); if(mac) return mac->clone(); throw Algorithm_Not_Found(name); @@ -56,7 +57,7 @@ MessageAuthenticationCode* get_mac(const std::string& name) *************************************************/ S2K* get_s2k(const std::string& name) { - const S2K* s2k = retrieve_s2k(name); + const S2K* s2k = retrieve_s2k(global_state(), name); if(s2k) return s2k->clone(); throw Algorithm_Not_Found(name); @@ -67,7 +68,9 @@ S2K* get_s2k(const std::string& name) *************************************************/ const BlockCipherModePaddingMethod* get_bc_pad(const std::string& name) { - const BlockCipherModePaddingMethod* pad = retrieve_bc_pad(name); + const BlockCipherModePaddingMethod* pad = + retrieve_bc_pad(global_state(), name); + if(pad) return pad; throw Algorithm_Not_Found(name); @@ -78,13 +81,13 @@ const BlockCipherModePaddingMethod* get_bc_pad(const std::string& name) *************************************************/ bool have_algorithm(const std::string& name) { - if(retrieve_block_cipher(name)) + if(retrieve_block_cipher(global_state(), name)) return true; - if(retrieve_stream_cipher(name)) + if(retrieve_stream_cipher(global_state(), name)) return true; - if(retrieve_hash(name)) + if(retrieve_hash(global_state(), name)) return true; - if(retrieve_mac(name)) + if(retrieve_mac(global_state(), name)) return true; return false; } @@ -94,7 +97,7 @@ bool have_algorithm(const std::string& name) *************************************************/ bool have_block_cipher(const std::string& name) { - return (retrieve_block_cipher(name) != 0); + return (retrieve_block_cipher(global_state(), name) != 0); } /************************************************* @@ -102,7 +105,7 @@ bool have_block_cipher(const std::string& name) *************************************************/ bool have_stream_cipher(const std::string& name) { - return (retrieve_stream_cipher(name) != 0); + return (retrieve_stream_cipher(global_state(), name) != 0); } /************************************************* @@ -110,7 +113,7 @@ bool have_stream_cipher(const std::string& name) *************************************************/ bool have_hash(const std::string& name) { - return (retrieve_hash(name) != 0); + return (retrieve_hash(global_state(), name) != 0); } /************************************************* @@ -118,7 +121,7 @@ bool have_hash(const std::string& name) *************************************************/ bool have_mac(const std::string& name) { - return (retrieve_mac(name) != 0); + return (retrieve_mac(global_state(), name) != 0); } /************************************************* @@ -126,11 +129,11 @@ bool have_mac(const std::string& name) *************************************************/ u32bit block_size_of(const std::string& name) { - const BlockCipher* cipher = retrieve_block_cipher(name); + const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); if(cipher) return cipher->BLOCK_SIZE; - const HashFunction* hash = retrieve_hash(name); + const HashFunction* hash = retrieve_hash(global_state(), name); if(hash) return hash->HASH_BLOCK_SIZE; @@ -142,11 +145,11 @@ u32bit block_size_of(const std::string& name) *************************************************/ u32bit output_length_of(const std::string& name) { - const HashFunction* hash = retrieve_hash(name); + const HashFunction* hash = retrieve_hash(global_state(), name); if(hash) return hash->OUTPUT_LENGTH; - const MessageAuthenticationCode* mac = retrieve_mac(name); + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); if(mac) return mac->OUTPUT_LENGTH; @@ -158,15 +161,15 @@ u32bit output_length_of(const std::string& name) *************************************************/ bool valid_keylength_for(u32bit key_len, const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); if(bc) return bc->valid_keylength(key_len); - const StreamCipher* sc = retrieve_stream_cipher(name); + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); if(sc) return sc->valid_keylength(key_len); - const MessageAuthenticationCode* mac = retrieve_mac(name); + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); if(mac) return mac->valid_keylength(key_len); @@ -178,15 +181,15 @@ bool valid_keylength_for(u32bit key_len, const std::string& name) *************************************************/ u32bit min_keylength_of(const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); if(bc) return bc->MINIMUM_KEYLENGTH; - const StreamCipher* sc = retrieve_stream_cipher(name); + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); if(sc) return sc->MINIMUM_KEYLENGTH; - const MessageAuthenticationCode* mac = retrieve_mac(name); + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); if(mac) return mac->MINIMUM_KEYLENGTH; @@ -198,15 +201,15 @@ u32bit min_keylength_of(const std::string& name) *************************************************/ u32bit max_keylength_of(const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); if(bc) return bc->MAXIMUM_KEYLENGTH; - const StreamCipher* sc = retrieve_stream_cipher(name); + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); if(sc) return sc->MAXIMUM_KEYLENGTH; - const MessageAuthenticationCode* mac = retrieve_mac(name); + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); if(mac) return mac->MAXIMUM_KEYLENGTH; @@ -218,15 +221,15 @@ u32bit max_keylength_of(const std::string& name) *************************************************/ u32bit keylength_multiple_of(const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); if(bc) return bc->KEYLENGTH_MULTIPLE; - const StreamCipher* sc = retrieve_stream_cipher(name); + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); if(sc) return sc->KEYLENGTH_MULTIPLE; - const MessageAuthenticationCode* mac = retrieve_mac(name); + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); if(mac) return mac->KEYLENGTH_MULTIPLE; diff --git a/src/core/lookup.h b/src/core/lookup.h index 97c2eff50..fb163342a 100644 --- a/src/core/lookup.h +++ b/src/core/lookup.h @@ -11,6 +11,7 @@ #include <botan/filters.h> #include <botan/mode_pad.h> #include <botan/pk_util.h> +#include <botan/libstate.h> #include <botan/s2k.h> #include <botan/pbe.h> @@ -19,14 +20,22 @@ namespace Botan { /************************************************* * Retrieve an object from the lookup table * *************************************************/ -BOTAN_DLL const BlockCipher* retrieve_block_cipher(const std::string&); -BOTAN_DLL const StreamCipher* retrieve_stream_cipher(const std::string&); -BOTAN_DLL const HashFunction* retrieve_hash(const std::string&); -BOTAN_DLL const MessageAuthenticationCode* retrieve_mac(const std::string&); -BOTAN_DLL const S2K* retrieve_s2k(const std::string&); +BOTAN_DLL const BlockCipher* +retrieve_block_cipher(Library_State&, const std::string&); + +BOTAN_DLL const StreamCipher* +retrieve_stream_cipher(Library_State&, const std::string&); + +BOTAN_DLL const HashFunction* +retrieve_hash(Library_State&, const std::string&); + +BOTAN_DLL const MessageAuthenticationCode* +retrieve_mac(Library_State&, const std::string&); + +BOTAN_DLL const S2K* retrieve_s2k(Library_State&, const std::string&); BOTAN_DLL const BlockCipherModePaddingMethod* -retrieve_bc_pad(const std::string&); +retrieve_bc_pad(Library_State&, const std::string&); /************************************************* * Get an algorithm object * @@ -55,16 +64,19 @@ BOTAN_DLL KDF* get_kdf(const std::string&); /************************************************* * Get a cipher object * *************************************************/ -BOTAN_DLL Keyed_Filter* get_cipher(const std::string&, +BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, + const std::string&, const SymmetricKey&, const InitializationVector&, Cipher_Dir); -BOTAN_DLL Keyed_Filter* get_cipher(const std::string&, +BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, + const std::string&, const SymmetricKey&, Cipher_Dir); -BOTAN_DLL Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); +BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, + const std::string&, Cipher_Dir); /************************************************* * Check to see if an algorithm exists * |