diff options
author | lloyd <[email protected]> | 2014-01-18 19:45:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-18 19:45:16 +0000 |
commit | ef465af87d61c0cfbba17b86a3e1cc48b90ab391 (patch) | |
tree | 151aafc54f2a57c1ca037653b647398616221060 /src/lib/mac/x919_mac | |
parent | 1822ba0d828d2c7bec51313597a9a64a54ccc559 (diff) |
Use unique_ptr instead of bare pointers and explicit delete in block, mac, hash.
m_ namespaced everything while I'm in there. Changed CMAC poly_double signature.
Diffstat (limited to 'src/lib/mac/x919_mac')
-rw-r--r-- | src/lib/mac/x919_mac/info.txt | 2 | ||||
-rw-r--r-- | src/lib/mac/x919_mac/x919_mac.cpp | 64 | ||||
-rw-r--r-- | src/lib/mac/x919_mac/x919_mac.h | 13 |
3 files changed, 36 insertions, 43 deletions
diff --git a/src/lib/mac/x919_mac/info.txt b/src/lib/mac/x919_mac/info.txt index 63bf40790..90d849803 100644 --- a/src/lib/mac/x919_mac/info.txt +++ b/src/lib/mac/x919_mac/info.txt @@ -1,5 +1,5 @@ define ANSI_X919_MAC 20131128 <requires> -block +des </requires> diff --git a/src/lib/mac/x919_mac/x919_mac.cpp b/src/lib/mac/x919_mac/x919_mac.cpp index faf6138ef..1a6d03761 100644 --- a/src/lib/mac/x919_mac/x919_mac.cpp +++ b/src/lib/mac/x919_mac/x919_mac.cpp @@ -16,25 +16,25 @@ namespace Botan { */ void ANSI_X919_MAC::add_data(const byte input[], size_t length) { - size_t xored = std::min(8 - position, length); - xor_buf(&state[position], input, xored); - position += xored; + size_t xored = std::min(8 - m_position, length); + xor_buf(&m_state[m_position], input, xored); + m_position += xored; - if(position < 8) return; + if(m_position < 8) return; - e->encrypt(state); + m_des1->encrypt(m_state); input += xored; length -= xored; while(length >= 8) { - xor_buf(state, input, 8); - e->encrypt(state); + xor_buf(m_state, input, 8); + m_des1->encrypt(m_state); input += 8; length -= 8; } - xor_buf(state, input, length); - position = length; + xor_buf(m_state, input, length); + m_position = length; } /* @@ -42,12 +42,12 @@ void ANSI_X919_MAC::add_data(const byte input[], size_t length) */ void ANSI_X919_MAC::final_result(byte mac[]) { - if(position) - e->encrypt(state); - d->decrypt(&state[0], mac); - e->encrypt(mac); - zeroise(state); - position = 0; + if(m_position) + m_des1->encrypt(m_state); + m_des2->decrypt(&m_state[0], mac); + m_des1->encrypt(mac); + zeroise(m_state); + m_position = 0; } /* @@ -55,9 +55,12 @@ void ANSI_X919_MAC::final_result(byte mac[]) */ void ANSI_X919_MAC::key_schedule(const byte key[], size_t length) { - e->set_key(key, 8); - if(length == 8) d->set_key(key, 8); - else d->set_key(key + 8, 8); + m_des1->set_key(key, 8); + + if(length == 16) + key += 8; + + m_des2->set_key(key, 8); } /* @@ -65,10 +68,10 @@ void ANSI_X919_MAC::key_schedule(const byte key[], size_t length) */ void ANSI_X919_MAC::clear() { - e->clear(); - d->clear(); - zeroise(state); - position = 0; + m_des1->clear(); + m_des2->clear(); + zeroise(m_state); + m_position = 0; } std::string ANSI_X919_MAC::name() const @@ -78,26 +81,17 @@ std::string ANSI_X919_MAC::name() const MessageAuthenticationCode* ANSI_X919_MAC::clone() const { - return new ANSI_X919_MAC(e->clone()); + return new ANSI_X919_MAC(m_des1->clone()); } /* * ANSI X9.19 MAC Constructor */ -ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) : - e(e_in), d(e->clone()), state(e->block_size()), position(0) +ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* cipher) : + m_des1(cipher), m_des2(m_des1->clone()), m_state(8), m_position(0) { - if(e->name() != "DES") + if(cipher->name() != "DES") throw Invalid_Argument("ANSI X9.19 MAC only supports DES"); } -/* -* ANSI X9.19 MAC Destructor -le*/ -ANSI_X919_MAC::~ANSI_X919_MAC() - { - delete e; - delete d; - } - } diff --git a/src/lib/mac/x919_mac/x919_mac.h b/src/lib/mac/x919_mac/x919_mac.h index b7b7d685e..38993af62 100644 --- a/src/lib/mac/x919_mac/x919_mac.h +++ b/src/lib/mac/x919_mac/x919_mac.h @@ -10,6 +10,7 @@ #include <botan/mac.h> #include <botan/block_cipher.h> +#include <memory> namespace Botan { @@ -21,7 +22,8 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode public: void clear(); std::string name() const; - size_t output_length() const { return e->block_size(); } + size_t output_length() const { return 8; } + MessageAuthenticationCode* clone() const; Key_Length_Specification key_spec() const @@ -36,17 +38,14 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode ANSI_X919_MAC(const ANSI_X919_MAC&) = delete; ANSI_X919_MAC& operator=(const ANSI_X919_MAC&) = delete; - - ~ANSI_X919_MAC(); private: void add_data(const byte[], size_t); void final_result(byte[]); void key_schedule(const byte[], size_t); - BlockCipher* e; - BlockCipher* d; - secure_vector<byte> state; - size_t position; + std::unique_ptr<BlockCipher> m_des1, m_des2; + secure_vector<byte> m_state; + size_t m_position; }; } |