diff options
author | lloyd <[email protected]> | 2008-09-30 05:46:54 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-30 05:46:54 +0000 |
commit | c9749d5d4693b5d93171f6085b29fc72c1e12ba0 (patch) | |
tree | d4c8c958863dbcc18751abd5b084c89ce6a5296c /src | |
parent | 75ef07ee5378341adf054bd729232167c73e9e47 (diff) |
Remove lookup dependency on CMAC: takes a BlockCipher as constructor arg
Diffstat (limited to 'src')
-rw-r--r-- | src/core/libstate/def_alg.cpp | 9 | ||||
-rw-r--r-- | src/mac/cmac/cmac.cpp | 22 | ||||
-rw-r--r-- | src/mac/cmac/cmac.h | 2 |
3 files changed, 18 insertions, 15 deletions
diff --git a/src/core/libstate/def_alg.cpp b/src/core/libstate/def_alg.cpp index 6a12f79f2..ade7e8d08 100644 --- a/src/core/libstate/def_alg.cpp +++ b/src/core/libstate/def_alg.cpp @@ -542,9 +542,12 @@ Default_Engine::find_mac(const std::string& algo_spec) const HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC); #endif -#if defined(BOTAN_HAS_CMAC) - HANDLE_TYPE_ONE_STRING("CMAC", CMAC); -#endif + if(algo_name == "CMAC") + { + if(name.size() == 2) + return new CMAC(find_block_cipher(name[1])); + throw Invalid_Algorithm_Name(algo_spec); + } #if defined(BOTAN_HAS_HMAC) HANDLE_TYPE_ONE_STRING("HMAC", HMAC); diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp index 5a99f93b1..d3110f9f2 100644 --- a/src/mac/cmac/cmac.cpp +++ b/src/mac/cmac/cmac.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/cmac.h> -#include <botan/lookup.h> #include <botan/xor_buf.h> namespace Botan { @@ -123,22 +122,23 @@ std::string CMAC::name() const *************************************************/ MessageAuthenticationCode* CMAC::clone() const { - return new CMAC(e->name()); + return new CMAC(e->clone()); } /************************************************* * CMAC Constructor * *************************************************/ -CMAC::CMAC(const std::string& bc_name) : - MessageAuthenticationCode(block_size_of(bc_name), - min_keylength_of(bc_name), - max_keylength_of(bc_name), - keylength_multiple_of(bc_name)) +CMAC::CMAC(BlockCipher* e_in) : + MessageAuthenticationCode(e_in->BLOCK_SIZE, + e_in->MINIMUM_KEYLENGTH, + e_in->MAXIMUM_KEYLENGTH, + e_in->KEYLENGTH_MULTIPLE), + e(e_in) { - e = get_block_cipher(bc_name); - - if(e->BLOCK_SIZE == 16) polynomial = 0x87; - else if(e->BLOCK_SIZE == 8) polynomial = 0x1B; + if(e->BLOCK_SIZE == 16) + polynomial = 0x87; + else if(e->BLOCK_SIZE == 8) + polynomial = 0x1B; else throw Invalid_Argument("CMAC cannot use the cipher " + e->name()); diff --git a/src/mac/cmac/cmac.h b/src/mac/cmac/cmac.h index c7f107258..0fe5b75f8 100644 --- a/src/mac/cmac/cmac.h +++ b/src/mac/cmac/cmac.h @@ -23,7 +23,7 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode static SecureVector<byte> poly_double(const MemoryRegion<byte>& in, byte polynomial); - CMAC(const std::string&); + CMAC(BlockCipher* e); ~CMAC() { delete e; } private: void add_data(const byte[], u32bit); |