diff options
author | lloyd <[email protected]> | 2008-11-08 20:58:33 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-08 20:58:33 +0000 |
commit | bee2ca1cd5c59318d95d9363d82632aee253b913 (patch) | |
tree | 125a31fdccf62cf6a0fef72509384f4223f35374 /src/engine/def_engine/lookup_mac.cpp | |
parent | de0e6d06a2efa362f9803be6ca5a3535c043ebc8 (diff) |
Move most of the Default_Engine code into engine/def_engine, and the
engine base classes into src/engine
Diffstat (limited to 'src/engine/def_engine/lookup_mac.cpp')
-rw-r--r-- | src/engine/def_engine/lookup_mac.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/engine/def_engine/lookup_mac.cpp b/src/engine/def_engine/lookup_mac.cpp new file mode 100644 index 000000000..baaea15dd --- /dev/null +++ b/src/engine/def_engine/lookup_mac.cpp @@ -0,0 +1,92 @@ +/************************************************* +* 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; + } + +} |