aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/mac/cbc_mac
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-18 19:45:16 +0000
committerlloyd <[email protected]>2014-01-18 19:45:16 +0000
commitef465af87d61c0cfbba17b86a3e1cc48b90ab391 (patch)
tree151aafc54f2a57c1ca037653b647398616221060 /src/lib/mac/cbc_mac
parent1822ba0d828d2c7bec51313597a9a64a54ccc559 (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/cbc_mac')
-rw-r--r--src/lib/mac/cbc_mac/cbc_mac.cpp53
-rw-r--r--src/lib/mac/cbc_mac/cbc_mac.h13
2 files changed, 29 insertions, 37 deletions
diff --git a/src/lib/mac/cbc_mac/cbc_mac.cpp b/src/lib/mac/cbc_mac/cbc_mac.cpp
index 118570e72..7d9a55e28 100644
--- a/src/lib/mac/cbc_mac/cbc_mac.cpp
+++ b/src/lib/mac/cbc_mac/cbc_mac.cpp
@@ -16,26 +16,26 @@ namespace Botan {
*/
void CBC_MAC::add_data(const byte input[], size_t length)
{
- size_t xored = std::min(output_length() - position, length);
- xor_buf(&state[position], input, xored);
- position += xored;
+ size_t xored = std::min(output_length() - m_position, length);
+ xor_buf(&m_state[m_position], input, xored);
+ m_position += xored;
- if(position < output_length())
+ if(m_position < output_length())
return;
- e->encrypt(state);
+ m_cipher->encrypt(m_state);
input += xored;
length -= xored;
while(length >= output_length())
{
- xor_buf(state, input, output_length());
- e->encrypt(state);
+ xor_buf(m_state, input, output_length());
+ m_cipher->encrypt(m_state);
input += output_length();
length -= output_length();
}
- xor_buf(state, input, length);
- position = length;
+ xor_buf(m_state, input, length);
+ m_position = length;
}
/*
@@ -43,12 +43,12 @@ void CBC_MAC::add_data(const byte input[], size_t length)
*/
void CBC_MAC::final_result(byte mac[])
{
- if(position)
- e->encrypt(state);
+ if(m_position)
+ m_cipher->encrypt(m_state);
- copy_mem(mac, &state[0], state.size());
- zeroise(state);
- position = 0;
+ copy_mem(mac, &m_state[0], m_state.size());
+ zeroise(m_state);
+ m_position = 0;
}
/*
@@ -56,7 +56,7 @@ void CBC_MAC::final_result(byte mac[])
*/
void CBC_MAC::key_schedule(const byte key[], size_t length)
{
- e->set_key(key, length);
+ m_cipher->set_key(key, length);
}
/*
@@ -64,9 +64,9 @@ void CBC_MAC::key_schedule(const byte key[], size_t length)
*/
void CBC_MAC::clear()
{
- e->clear();
- zeroise(state);
- position = 0;
+ m_cipher->clear();
+ zeroise(m_state);
+ m_position = 0;
}
/*
@@ -74,7 +74,7 @@ void CBC_MAC::clear()
*/
std::string CBC_MAC::name() const
{
- return "CBC-MAC(" + e->name() + ")";
+ return "CBC-MAC(" + m_cipher->name() + ")";
}
/*
@@ -82,24 +82,15 @@ std::string CBC_MAC::name() const
*/
MessageAuthenticationCode* CBC_MAC::clone() const
{
- return new CBC_MAC(e->clone());
+ return new CBC_MAC(m_cipher->clone());
}
/*
* CBC-MAC Constructor
*/
-CBC_MAC::CBC_MAC(BlockCipher* e_in) :
- e(e_in), state(e->block_size())
+CBC_MAC::CBC_MAC(BlockCipher* cipher) :
+ m_cipher(cipher), m_state(cipher->block_size())
{
- position = 0;
- }
-
-/*
-* CBC-MAC Destructor
-*/
-CBC_MAC::~CBC_MAC()
- {
- delete e;
}
}
diff --git a/src/lib/mac/cbc_mac/cbc_mac.h b/src/lib/mac/cbc_mac/cbc_mac.h
index be25718d9..e7285d0cb 100644
--- a/src/lib/mac/cbc_mac/cbc_mac.h
+++ b/src/lib/mac/cbc_mac/cbc_mac.h
@@ -10,6 +10,7 @@
#include <botan/mac.h>
#include <botan/block_cipher.h>
+#include <memory>
namespace Botan {
@@ -21,27 +22,27 @@ class BOTAN_DLL CBC_MAC : public MessageAuthenticationCode
public:
std::string name() const;
MessageAuthenticationCode* clone() const;
- size_t output_length() const { return e->block_size(); }
+ size_t output_length() const { return m_cipher->block_size(); }
void clear();
Key_Length_Specification key_spec() const
{
- return e->key_spec();
+ return m_cipher->key_spec();
}
/**
* @param cipher the underlying block cipher to use
*/
CBC_MAC(BlockCipher* cipher);
- ~CBC_MAC();
+
private:
void add_data(const byte[], size_t);
void final_result(byte[]);
void key_schedule(const byte[], size_t);
- BlockCipher* e;
- secure_vector<byte> state;
- size_t position;
+ std::unique_ptr<BlockCipher> m_cipher;
+ secure_vector<byte> m_state;
+ size_t m_position = 0;
};
}