aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash
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/hash
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/hash')
-rw-r--r--src/lib/hash/comb4p/comb4p.cpp54
-rw-r--r--src/lib/hash/comb4p/comb4p.h15
2 files changed, 32 insertions, 37 deletions
diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp
index 7aec5972e..7abc3a3d2 100644
--- a/src/lib/hash/comb4p/comb4p.cpp
+++ b/src/lib/hash/comb4p/comb4p.cpp
@@ -16,42 +16,42 @@ namespace {
void comb4p_round(secure_vector<byte>& out,
const secure_vector<byte>& in,
byte round_no,
- HashFunction* h1,
- HashFunction* h2)
+ HashFunction& h1,
+ HashFunction& h2)
{
- h1->update(round_no);
- h2->update(round_no);
+ h1.update(round_no);
+ h2.update(round_no);
- h1->update(&in[0], in.size());
- h2->update(&in[0], in.size());
+ h1.update(&in[0], in.size());
+ h2.update(&in[0], in.size());
- secure_vector<byte> h_buf = h1->final();
+ secure_vector<byte> h_buf = h1.final();
xor_buf(&out[0], &h_buf[0], std::min(out.size(), h_buf.size()));
- h_buf = h2->final();
+ h_buf = h2.final();
xor_buf(&out[0], &h_buf[0], std::min(out.size(), h_buf.size()));
}
}
Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
- hash1(h1), hash2(h2)
+ m_hash1(h1), m_hash2(h2)
{
- if(hash1->name() == hash2->name())
+ if(m_hash1->name() == m_hash2->name())
throw std::invalid_argument("Comb4P: Must use two distinct hashes");
- if(hash1->output_length() != hash2->output_length())
+ if(m_hash1->output_length() != m_hash2->output_length())
throw std::invalid_argument("Comb4P: Incompatible hashes " +
- hash1->name() + " and " +
- hash2->name());
+ m_hash1->name() + " and " +
+ m_hash2->name());
clear();
}
size_t Comb4P::hash_block_size() const
{
- if(hash1->hash_block_size() == hash2->hash_block_size())
- return hash1->hash_block_size();
+ if(m_hash1->hash_block_size() == m_hash2->hash_block_size())
+ return m_hash1->hash_block_size();
/*
* Return LCM of the block sizes? This would probably be OK for
@@ -62,40 +62,40 @@ size_t Comb4P::hash_block_size() const
void Comb4P::clear()
{
- hash1->clear();
- hash2->clear();
+ m_hash1->clear();
+ m_hash2->clear();
// Prep for processing next message, if any
- hash1->update(0);
- hash2->update(0);
+ m_hash1->update(0);
+ m_hash2->update(0);
}
void Comb4P::add_data(const byte input[], size_t length)
{
- hash1->update(input, length);
- hash2->update(input, length);
+ m_hash1->update(input, length);
+ m_hash2->update(input, length);
}
void Comb4P::final_result(byte out[])
{
- secure_vector<byte> h1 = hash1->final();
- secure_vector<byte> h2 = hash2->final();
+ secure_vector<byte> h1 = m_hash1->final();
+ secure_vector<byte> h2 = m_hash2->final();
// First round
xor_buf(&h1[0], &h2[0], std::min(h1.size(), h2.size()));
// Second round
- comb4p_round(h2, h1, 1, hash1, hash2);
+ comb4p_round(h2, h1, 1, *m_hash1, *m_hash2);
// Third round
- comb4p_round(h1, h2, 2, hash1, hash2);
+ comb4p_round(h1, h2, 2, *m_hash1, *m_hash2);
copy_mem(out , &h1[0], h1.size());
copy_mem(out + h1.size(), &h2[0], h2.size());
// Prep for processing next message, if any
- hash1->update(0);
- hash2->update(0);
+ m_hash1->update(0);
+ m_hash2->update(0);
}
}
diff --git a/src/lib/hash/comb4p/comb4p.h b/src/lib/hash/comb4p/comb4p.h
index e0cffc22b..818990439 100644
--- a/src/lib/hash/comb4p/comb4p.h
+++ b/src/lib/hash/comb4p/comb4p.h
@@ -9,6 +9,7 @@
#define BOTAN_COMB4P_H__
#include <botan/hash.h>
+#include <memory>
namespace Botan {
@@ -25,26 +26,21 @@ class BOTAN_DLL Comb4P : public HashFunction
*/
Comb4P(HashFunction* h1, HashFunction* h2);
- Comb4P(const Comb4P&) = delete;
- Comb4P& operator=(const Comb4P&) = delete;
-
- ~Comb4P() { delete hash1; delete hash2; }
-
size_t hash_block_size() const;
size_t output_length() const
{
- return hash1->output_length() + hash2->output_length();
+ return m_hash1->output_length() + m_hash2->output_length();
}
HashFunction* clone() const
{
- return new Comb4P(hash1->clone(), hash2->clone());
+ return new Comb4P(m_hash1->clone(), m_hash2->clone());
}
std::string name() const
{
- return "Comb4P(" + hash1->name() + "," + hash2->name() + ")";
+ return "Comb4P(" + m_hash1->name() + "," + m_hash2->name() + ")";
}
void clear();
@@ -52,8 +48,7 @@ class BOTAN_DLL Comb4P : public HashFunction
void add_data(const byte input[], size_t length);
void final_result(byte out[]);
- HashFunction* hash1;
- HashFunction* hash2;
+ std::unique_ptr<HashFunction> m_hash1, m_hash2;
};
}