diff options
author | lloyd <[email protected]> | 2008-09-28 17:10:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 17:10:16 +0000 |
commit | 1680c75cd7f583f213493731c50eeb6dd6fea74a (patch) | |
tree | 3f7884ed4b4dedebd6113d53742844e72033c61f /src | |
parent | b677f899b4175dfb1e8910e219ade760cd716d95 (diff) |
Modularize SSLv3 MAC and X9.19 MACs. Fix some feature macro inconsistencies.
Diffstat (limited to 'src')
-rw-r--r-- | src/def_alg.cpp | 18 | ||||
-rw-r--r-- | src/ssl3_mac.cpp | 88 | ||||
-rw-r--r-- | src/x919_mac.cpp | 92 |
3 files changed, 15 insertions, 183 deletions
diff --git a/src/def_alg.cpp b/src/def_alg.cpp index 4cd48b1a3..64e27d480 100644 --- a/src/def_alg.cpp +++ b/src/def_alg.cpp @@ -40,7 +40,7 @@ #include <botan/lion.h> #endif -#ifdef BOTAN_HAS_LUBYRACK +#ifdef BOTAN_HAS_LUBY_RACKOFF #include <botan/lubyrack.h> #endif @@ -148,11 +148,11 @@ #include <botan/md5.h> #endif -#ifdef BOTAN_HAS_RIPEMD128 +#ifdef BOTAN_HAS_RIPEMD_128 #include <botan/rmd128.h> #endif -#ifdef BOTAN_HAS_RIPEMD160 +#ifdef BOTAN_HAS_RIPEMD_160 #include <botan/rmd160.h> #endif @@ -178,8 +178,14 @@ #include <botan/cbc_mac.h> #include <botan/cmac.h> #include <botan/hmac.h> + +#ifdef BOTAN_HAS_SSL3_MAC #include <botan/ssl3_mac.h> +#endif + +#ifdef BOTAN_HAS_ANSI_X919_MAC #include <botan/x919_mac.h> +#endif #include <botan/mode_pad.h> #include <botan/pgp_s2k.h> @@ -475,8 +481,14 @@ Default_Engine::find_mac(const std::string& algo_spec) const HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC); HANDLE_TYPE_ONE_STRING("CMAC", CMAC); HANDLE_TYPE_ONE_STRING("HMAC", HMAC); + +#ifdef BOTAN_HAS_SSL3_MAC HANDLE_TYPE_ONE_STRING("SSL3-MAC", SSL3_MAC); +#endif + +#ifdef BOTAN_HAS_ANSI_X919_MAC HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC); +#endif return 0; } diff --git a/src/ssl3_mac.cpp b/src/ssl3_mac.cpp deleted file mode 100644 index ceb04bf44..000000000 --- a/src/ssl3_mac.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************* -* SSL3-MAC Source File * -* (C) 1999-2004 Jack Lloyd * -*************************************************/ - -#include <botan/ssl3_mac.h> -#include <botan/lookup.h> - -namespace Botan { - -/************************************************* -* Update a SSL3-MAC Calculation * -*************************************************/ -void SSL3_MAC::add_data(const byte input[], u32bit length) - { - hash->update(input, length); - } - -/************************************************* -* Finalize a SSL3-MAC Calculation * -*************************************************/ -void SSL3_MAC::final_result(byte mac[]) - { - hash->final(mac); - hash->update(o_key); - hash->update(mac, OUTPUT_LENGTH); - hash->final(mac); - hash->update(i_key); - } - -/************************************************* -* SSL3-MAC Key Schedule * -*************************************************/ -void SSL3_MAC::key(const byte key[], u32bit length) - { - hash->clear(); - std::fill(i_key.begin(), i_key.end(), 0x36); - std::fill(o_key.begin(), o_key.end(), 0x5C); - - i_key.copy(key, length); - o_key.copy(key, length); - hash->update(i_key); - } - -/************************************************* -* Clear memory of sensitive data * -*************************************************/ -void SSL3_MAC::clear() throw() - { - hash->clear(); - i_key.clear(); - o_key.clear(); - } - -/************************************************* -* Return the name of this type * -*************************************************/ -std::string SSL3_MAC::name() const - { - return "SSL3-MAC(" + hash->name() + ")"; - } - -/************************************************* -* Return a clone of this object * -*************************************************/ -MessageAuthenticationCode* SSL3_MAC::clone() const - { - return new SSL3_MAC(hash->name()); - } - -/************************************************* -* SSL3-MAC Constructor * -*************************************************/ -SSL3_MAC::SSL3_MAC(const std::string& hash_name) : - MessageAuthenticationCode(output_length_of(hash_name), - output_length_of(hash_name)), - hash(get_hash(hash_name)) - { - if(hash->name() != "MD5" && hash->name() != "SHA-160") - throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name()); - - const u32bit INNER_HASH_LENGTH = (hash->name() == "MD5") ? 64 : 60; - - i_key.create(INNER_HASH_LENGTH); - o_key.create(INNER_HASH_LENGTH); - } - -} diff --git a/src/x919_mac.cpp b/src/x919_mac.cpp deleted file mode 100644 index 92ec7b7b8..000000000 --- a/src/x919_mac.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************* -* ANSI X9.19 MAC Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/x919_mac.h> -#include <botan/lookup.h> -#include <botan/xor_buf.h> -#include <algorithm> - -namespace Botan { - -/************************************************* -* Update an ANSI X9.19 MAC Calculation * -*************************************************/ -void ANSI_X919_MAC::add_data(const byte input[], u32bit length) - { - u32bit xored = std::min(8 - position, length); - xor_buf(state + position, input, xored); - position += xored; - - if(position < 8) return; - - e->encrypt(state); - input += xored; - length -= xored; - while(length >= 8) - { - xor_buf(state, input, 8); - e->encrypt(state); - input += 8; - length -= 8; - } - - xor_buf(state, input, length); - position = length; - } - -/************************************************* -* Finalize an ANSI X9.19 MAC Calculation * -*************************************************/ -void ANSI_X919_MAC::final_result(byte mac[]) - { - if(position) - e->encrypt(state); - d->decrypt(state, mac); - e->encrypt(mac); - state.clear(); - position = 0; - } - -/************************************************* -* ANSI X9.19 MAC Key Schedule * -*************************************************/ -void ANSI_X919_MAC::key(const byte key[], u32bit length) - { - e->set_key(key, 8); - if(length == 8) d->set_key(key, 8); - else d->set_key(key + 8, 8); - } - -/************************************************* -* Clear memory of sensitive data * -*************************************************/ -void ANSI_X919_MAC::clear() throw() - { - e->clear(); - d->clear(); - state.clear(); - position = 0; - } - -/************************************************* -* ANSI X9.19 MAC Constructor * -*************************************************/ -ANSI_X919_MAC::ANSI_X919_MAC() : MessageAuthenticationCode(8, 8, 16, 8) - { - e = get_block_cipher("DES"); - d = get_block_cipher("DES"); - position = 0; - } - -/************************************************* -* ANSI X9.19 MAC Destructor * -*************************************************/ -ANSI_X919_MAC::~ANSI_X919_MAC() - { - delete e; - delete d; - } - -} |