diff options
author | lloyd <[email protected]> | 2010-10-28 21:15:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-28 21:15:21 +0000 |
commit | 22f02b418f7f53431da168abe9fb74f15bf3cb0e (patch) | |
tree | cdc81938c979403d20a438d134bbd6d64479f17d /src/mac | |
parent | a7a047e6823dcbf23e172dd5c0f9a7b4fd748f10 (diff) |
Eliminate the constant size_t values in SymmetricAlgorithm that give
the parameters of the key length. Instead define a new function which
returns a simple object which contains this information.
This definitely breaks backwards compatability, though only with code
that directly manipulates low level objects like BlockCipher*s
directly, which is probably relatively rare.
Also remove some deprecated accessor functions from lookup.h. It turns
out block_size_of and output_size_of are being used in the TLS code; I
need to remove them from there before I can delete these entirely.
Really that didn't make much sense, because they assumed all
implementations of a particular algorithm will have the same
specifications, which is definitely not necessarily true, especially
WRT key length. It is much safer (and probably simpler) to first
retrieve an instance of the actual object you are going to use and
then ask it directly.
Diffstat (limited to 'src/mac')
-rw-r--r-- | src/mac/cbc_mac/cbc_mac.cpp | 5 | ||||
-rw-r--r-- | src/mac/cbc_mac/cbc_mac.h | 5 | ||||
-rw-r--r-- | src/mac/cmac/cmac.cpp | 5 | ||||
-rw-r--r-- | src/mac/cmac/cmac.h | 5 | ||||
-rw-r--r-- | src/mac/hmac/hmac.cpp | 3 | ||||
-rw-r--r-- | src/mac/hmac/hmac.h | 5 | ||||
-rw-r--r-- | src/mac/mac.h | 15 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.cpp | 6 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.h | 5 | ||||
-rw-r--r-- | src/mac/x919_mac/x919_mac.cpp | 5 | ||||
-rw-r--r-- | src/mac/x919_mac/x919_mac.h | 5 |
11 files changed, 34 insertions, 30 deletions
diff --git a/src/mac/cbc_mac/cbc_mac.cpp b/src/mac/cbc_mac/cbc_mac.cpp index 48cc8ab3e..a3899c87e 100644 --- a/src/mac/cbc_mac/cbc_mac.cpp +++ b/src/mac/cbc_mac/cbc_mac.cpp @@ -89,10 +89,7 @@ MessageAuthenticationCode* CBC_MAC::clone() const * CBC-MAC Constructor */ CBC_MAC::CBC_MAC(BlockCipher* e_in) : - MessageAuthenticationCode(e_in->block_size(), - e_in->MINIMUM_KEYLENGTH, - e_in->MAXIMUM_KEYLENGTH, - e_in->KEYLENGTH_MULTIPLE), + MessageAuthenticationCode(e_in->block_size()), e(e_in), state(e->block_size()) { position = 0; diff --git a/src/mac/cbc_mac/cbc_mac.h b/src/mac/cbc_mac/cbc_mac.h index 6b30ef764..ff2a8f3fa 100644 --- a/src/mac/cbc_mac/cbc_mac.h +++ b/src/mac/cbc_mac/cbc_mac.h @@ -23,6 +23,11 @@ class BOTAN_DLL CBC_MAC : public MessageAuthenticationCode std::string name() const; MessageAuthenticationCode* clone() const; + Key_Length_Specification key_spec() const + { + return e->key_spec(); + } + /** * @param cipher the underlying block cipher to use */ diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp index 2147f9a45..37f83ffe4 100644 --- a/src/mac/cmac/cmac.cpp +++ b/src/mac/cmac/cmac.cpp @@ -131,10 +131,7 @@ MessageAuthenticationCode* CMAC::clone() const * CMAC Constructor */ CMAC::CMAC(BlockCipher* e_in) : - MessageAuthenticationCode(e_in->block_size(), - e_in->MINIMUM_KEYLENGTH, - e_in->MAXIMUM_KEYLENGTH, - e_in->KEYLENGTH_MULTIPLE), + MessageAuthenticationCode(e_in->block_size()), e(e_in) { if(e->block_size() == 16) diff --git a/src/mac/cmac/cmac.h b/src/mac/cmac/cmac.h index ac929eaf3..aa9bfb38e 100644 --- a/src/mac/cmac/cmac.h +++ b/src/mac/cmac/cmac.h @@ -23,6 +23,11 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode std::string name() const; MessageAuthenticationCode* clone() const; + Key_Length_Specification key_spec() const + { + return e->key_spec(); + } + /** * CMAC's polynomial doubling operation * @param in the input diff --git a/src/mac/hmac/hmac.cpp b/src/mac/hmac/hmac.cpp index 06923138a..284bc87ec 100644 --- a/src/mac/hmac/hmac.cpp +++ b/src/mac/hmac/hmac.cpp @@ -85,8 +85,7 @@ MessageAuthenticationCode* HMAC::clone() const * HMAC Constructor */ HMAC::HMAC(HashFunction* hash_in) : - MessageAuthenticationCode(hash_in->output_length(), - 0, 2*hash_in->hash_block_size()), + MessageAuthenticationCode(hash_in->output_length()), hash(hash_in) { if(hash->hash_block_size() == 0) diff --git a/src/mac/hmac/hmac.h b/src/mac/hmac/hmac.h index 33af62f6a..505d0dd6b 100644 --- a/src/mac/hmac/hmac.h +++ b/src/mac/hmac/hmac.h @@ -23,6 +23,11 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode std::string name() const; MessageAuthenticationCode* clone() const; + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(0, 2*hash->hash_block_size()); + } + /** * @param hash the hash to use for HMACing */ diff --git a/src/mac/mac.h b/src/mac/mac.h index b788e06c8..1cb87d21e 100644 --- a/src/mac/mac.h +++ b/src/mac/mac.h @@ -41,24 +41,13 @@ class BOTAN_DLL MessageAuthenticationCode : public BufferedComputation, virtual std::string name() const = 0; /** - * Reset the internal state of this object. - */ - virtual void clear() = 0; - - /** * @param mac_len the output length of this MAC * @param key_min the minimum key size * @param key_max the maximum key size * @param key_mod the modulo restriction on the key size */ - MessageAuthenticationCode(size_t mac_len, - size_t key_min, - size_t key_max = 0, - size_t key_mod = 1) : - BufferedComputation(mac_len), - SymmetricAlgorithm(key_min, key_max, key_mod) {} - - virtual ~MessageAuthenticationCode() {} + MessageAuthenticationCode(size_t mac_len) : + BufferedComputation(mac_len) {} }; } diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp index fcbccc06e..daaca1b57 100644 --- a/src/mac/ssl3mac/ssl3_mac.cpp +++ b/src/mac/ssl3mac/ssl3_mac.cpp @@ -73,14 +73,14 @@ MessageAuthenticationCode* SSL3_MAC::clone() const * SSL3-MAC Constructor */ SSL3_MAC::SSL3_MAC(HashFunction* hash_in) : - MessageAuthenticationCode(hash_in->output_length(), - hash_in->output_length()), + MessageAuthenticationCode(hash_in->output_length()), hash(hash_in) { if(hash->hash_block_size() == 0) throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name()); - size_t INNER_HASH_LENGTH = + // Quirk to deal with specification bug + const size_t INNER_HASH_LENGTH = (hash->name() == "SHA-160") ? 60 : hash->hash_block_size(); i_key.resize(INNER_HASH_LENGTH); diff --git a/src/mac/ssl3mac/ssl3_mac.h b/src/mac/ssl3mac/ssl3_mac.h index 50042f3d0..455cfa266 100644 --- a/src/mac/ssl3mac/ssl3_mac.h +++ b/src/mac/ssl3mac/ssl3_mac.h @@ -23,6 +23,11 @@ class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode std::string name() const; MessageAuthenticationCode* clone() const; + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(hash->output_length()); + } + /** * @param hash the underlying hash to use */ diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp index c46ab82cb..bd53a6c7d 100644 --- a/src/mac/x919_mac/x919_mac.cpp +++ b/src/mac/x919_mac/x919_mac.cpp @@ -85,10 +85,7 @@ MessageAuthenticationCode* ANSI_X919_MAC::clone() const * ANSI X9.19 MAC Constructor */ ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) : - MessageAuthenticationCode(e_in->block_size(), - e_in->MINIMUM_KEYLENGTH, - 2*e_in->MAXIMUM_KEYLENGTH, - 2*e_in->KEYLENGTH_MULTIPLE), + MessageAuthenticationCode(e_in->block_size()), e(e_in), d(e->clone()), state(e->block_size()), position(0) { if(e->name() != "DES") diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h index e9fe56c8d..600955919 100644 --- a/src/mac/x919_mac/x919_mac.h +++ b/src/mac/x919_mac/x919_mac.h @@ -23,6 +23,11 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode std::string name() const; MessageAuthenticationCode* clone() const; + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(8, 16, 8); + } + /** * @param cipher the underlying block cipher to use */ |