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 /modules/mac/x919_mac/x919_mac.cpp | |
parent | b677f899b4175dfb1e8910e219ade760cd716d95 (diff) |
Modularize SSLv3 MAC and X9.19 MACs. Fix some feature macro inconsistencies.
Diffstat (limited to 'modules/mac/x919_mac/x919_mac.cpp')
-rw-r--r-- | modules/mac/x919_mac/x919_mac.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/modules/mac/x919_mac/x919_mac.cpp b/modules/mac/x919_mac/x919_mac.cpp new file mode 100644 index 000000000..92ec7b7b8 --- /dev/null +++ b/modules/mac/x919_mac/x919_mac.cpp @@ -0,0 +1,92 @@ +/************************************************* +* 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; + } + +} |