aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/block/cascade/cascade.cpp42
-rw-r--r--src/lib/block/cascade/cascade.h14
-rw-r--r--src/lib/block/lion/lion.cpp86
-rw-r--r--src/lib/block/lion/lion.h34
-rw-r--r--src/lib/block/lubyrack/lubyrack.cpp75
-rw-r--r--src/lib/block/lubyrack/lubyrack.h27
-rw-r--r--src/lib/hash/comb4p/comb4p.cpp54
-rw-r--r--src/lib/hash/comb4p/comb4p.h15
-rw-r--r--src/lib/mac/cbc_mac/cbc_mac.cpp53
-rw-r--r--src/lib/mac/cbc_mac/cbc_mac.h13
-rw-r--r--src/lib/mac/cmac/cmac.cpp104
-rw-r--r--src/lib/mac/cmac/cmac.h19
-rw-r--r--src/lib/mac/hmac/hmac.cpp54
-rw-r--r--src/lib/mac/hmac/hmac.h12
-rw-r--r--src/lib/mac/ssl3mac/ssl3_mac.cpp46
-rw-r--r--src/lib/mac/ssl3mac/ssl3_mac.h5
-rw-r--r--src/lib/mac/x919_mac/info.txt2
-rw-r--r--src/lib/mac/x919_mac/x919_mac.cpp64
-rw-r--r--src/lib/mac/x919_mac/x919_mac.h13
-rw-r--r--src/lib/modes/aead/ocb/ocb.cpp2
-rw-r--r--src/lib/modes/aead/siv/siv.cpp6
21 files changed, 347 insertions, 393 deletions
diff --git a/src/lib/block/cascade/cascade.cpp b/src/lib/block/cascade/cascade.cpp
index f1b1a8f2c..67846204d 100644
--- a/src/lib/block/cascade/cascade.cpp
+++ b/src/lib/block/cascade/cascade.cpp
@@ -12,46 +12,46 @@ namespace Botan {
void Cascade_Cipher::encrypt_n(const byte in[], byte out[],
size_t blocks) const
{
- size_t c1_blocks = blocks * (block_size() / cipher1->block_size());
- size_t c2_blocks = blocks * (block_size() / cipher2->block_size());
+ size_t c1_blocks = blocks * (block_size() / m_cipher1->block_size());
+ size_t c2_blocks = blocks * (block_size() / m_cipher2->block_size());
- cipher1->encrypt_n(in, out, c1_blocks);
- cipher2->encrypt_n(out, out, c2_blocks);
+ m_cipher1->encrypt_n(in, out, c1_blocks);
+ m_cipher2->encrypt_n(out, out, c2_blocks);
}
void Cascade_Cipher::decrypt_n(const byte in[], byte out[],
size_t blocks) const
{
- size_t c1_blocks = blocks * (block_size() / cipher1->block_size());
- size_t c2_blocks = blocks * (block_size() / cipher2->block_size());
+ size_t c1_blocks = blocks * (block_size() / m_cipher1->block_size());
+ size_t c2_blocks = blocks * (block_size() / m_cipher2->block_size());
- cipher2->decrypt_n(in, out, c2_blocks);
- cipher1->decrypt_n(out, out, c1_blocks);
+ m_cipher2->decrypt_n(in, out, c2_blocks);
+ m_cipher1->decrypt_n(out, out, c1_blocks);
}
void Cascade_Cipher::key_schedule(const byte key[], size_t)
{
- const byte* key2 = key + cipher1->maximum_keylength();
+ const byte* key2 = key + m_cipher1->maximum_keylength();
- cipher1->set_key(key , cipher1->maximum_keylength());
- cipher2->set_key(key2, cipher2->maximum_keylength());
+ m_cipher1->set_key(key , m_cipher1->maximum_keylength());
+ m_cipher2->set_key(key2, m_cipher2->maximum_keylength());
}
void Cascade_Cipher::clear()
{
- cipher1->clear();
- cipher2->clear();
+ m_cipher1->clear();
+ m_cipher2->clear();
}
std::string Cascade_Cipher::name() const
{
- return "Cascade(" + cipher1->name() + "," + cipher2->name() + ")";
+ return "Cascade(" + m_cipher1->name() + "," + m_cipher2->name() + ")";
}
BlockCipher* Cascade_Cipher::clone() const
{
- return new Cascade_Cipher(cipher1->clone(),
- cipher2->clone());
+ return new Cascade_Cipher(m_cipher1->clone(),
+ m_cipher2->clone());
}
namespace {
@@ -81,18 +81,12 @@ size_t block_size_for_cascade(size_t bs, size_t bs2)
}
Cascade_Cipher::Cascade_Cipher(BlockCipher* c1, BlockCipher* c2) :
- cipher1(c1), cipher2(c2)
+ m_cipher1(c1), m_cipher2(c2)
{
- block = block_size_for_cascade(c1->block_size(), c2->block_size());
+ m_block = block_size_for_cascade(c1->block_size(), c2->block_size());
if(block_size() % c1->block_size() || block_size() % c2->block_size())
throw Internal_Error("Failure in " + name() + " constructor");
}
-Cascade_Cipher::~Cascade_Cipher()
- {
- delete cipher1;
- delete cipher2;
- }
-
}
diff --git a/src/lib/block/cascade/cascade.h b/src/lib/block/cascade/cascade.h
index 9b7d44fdf..3634b2f5b 100644
--- a/src/lib/block/cascade/cascade.h
+++ b/src/lib/block/cascade/cascade.h
@@ -9,6 +9,7 @@
#define BOTAN_CASCADE_H__
#include <botan/block_cipher.h>
+#include <memory>
namespace Botan {
@@ -21,12 +22,12 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
void decrypt_n(const byte in[], byte out[], size_t blocks) const;
- size_t block_size() const { return block; }
+ size_t block_size() const { return m_block; }
Key_Length_Specification key_spec() const
{
- return Key_Length_Specification(cipher1->maximum_keylength() +
- cipher2->maximum_keylength());
+ return Key_Length_Specification(m_cipher1->maximum_keylength() +
+ m_cipher2->maximum_keylength());
}
void clear();
@@ -42,14 +43,11 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher
Cascade_Cipher(const Cascade_Cipher&) = delete;
Cascade_Cipher& operator=(const Cascade_Cipher&) = delete;
-
- ~Cascade_Cipher();
private:
void key_schedule(const byte[], size_t);
- size_t block;
- BlockCipher* cipher1;
- BlockCipher* cipher2;
+ size_t m_block;
+ std::unique_ptr<BlockCipher> m_cipher1, m_cipher2;
};
diff --git a/src/lib/block/lion/lion.cpp b/src/lib/block/lion/lion.cpp
index e1e0b56c6..95f703f8b 100644
--- a/src/lib/block/lion/lion.cpp
+++ b/src/lib/block/lion/lion.cpp
@@ -1,6 +1,6 @@
/*
* Lion
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -16,25 +16,28 @@ namespace Botan {
*/
void Lion::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
+ const size_t LEFT_SIZE = left_size();
+ const size_t RIGHT_SIZE = right_size();
+
secure_vector<byte> buffer_vec(LEFT_SIZE);
byte* buffer = &buffer_vec[0];
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(buffer, in, &key1[0], LEFT_SIZE);
- cipher->set_key(buffer, LEFT_SIZE);
- cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
+ xor_buf(buffer, in, &m_key1[0], LEFT_SIZE);
+ m_cipher->set_key(buffer, LEFT_SIZE);
+ m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
- hash->update(out + LEFT_SIZE, RIGHT_SIZE);
- hash->final(buffer);
+ m_hash->update(out + LEFT_SIZE, RIGHT_SIZE);
+ m_hash->final(buffer);
xor_buf(out, in, buffer, LEFT_SIZE);
- xor_buf(buffer, out, &key2[0], LEFT_SIZE);
- cipher->set_key(buffer, LEFT_SIZE);
- cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
+ xor_buf(buffer, out, &m_key2[0], LEFT_SIZE);
+ m_cipher->set_key(buffer, LEFT_SIZE);
+ m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += m_block_size;
+ out += m_block_size;
}
}
@@ -43,25 +46,28 @@ void Lion::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void Lion::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
+ const size_t LEFT_SIZE = left_size();
+ const size_t RIGHT_SIZE = right_size();
+
secure_vector<byte> buffer_vec(LEFT_SIZE);
byte* buffer = &buffer_vec[0];
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(buffer, in, &key2[0], LEFT_SIZE);
- cipher->set_key(buffer, LEFT_SIZE);
- cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
+ xor_buf(buffer, in, &m_key2[0], LEFT_SIZE);
+ m_cipher->set_key(buffer, LEFT_SIZE);
+ m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
- hash->update(out + LEFT_SIZE, RIGHT_SIZE);
- hash->final(buffer);
+ m_hash->update(out + LEFT_SIZE, RIGHT_SIZE);
+ m_hash->final(buffer);
xor_buf(out, in, buffer, LEFT_SIZE);
- xor_buf(buffer, out, &key1[0], LEFT_SIZE);
- cipher->set_key(buffer, LEFT_SIZE);
- cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
+ xor_buf(buffer, out, &m_key1[0], LEFT_SIZE);
+ m_cipher->set_key(buffer, LEFT_SIZE);
+ m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += m_block_size;
+ out += m_block_size;
}
}
@@ -73,8 +79,8 @@ void Lion::key_schedule(const byte key[], size_t length)
clear();
const size_t half = length / 2;
- copy_mem(&key1[0], key, half);
- copy_mem(&key2[0], key + half, half);
+ copy_mem(&m_key1[0], key, half);
+ copy_mem(&m_key2[0], key + half, half);
}
/*
@@ -82,9 +88,9 @@ void Lion::key_schedule(const byte key[], size_t length)
*/
std::string Lion::name() const
{
- return "Lion(" + hash->name() + "," +
- cipher->name() + "," +
- std::to_string(BLOCK_SIZE) + ")";
+ return "Lion(" + m_hash->name() + "," +
+ m_cipher->name() + "," +
+ std::to_string(block_size()) + ")";
}
/*
@@ -92,7 +98,7 @@ std::string Lion::name() const
*/
BlockCipher* Lion::clone() const
{
- return new Lion(hash->clone(), cipher->clone(), BLOCK_SIZE);
+ return new Lion(m_hash->clone(), m_cipher->clone(), block_size());
}
/*
@@ -100,30 +106,28 @@ BlockCipher* Lion::clone() const
*/
void Lion::clear()
{
- zeroise(key1);
- zeroise(key2);
- hash->clear();
- cipher->clear();
+ zeroise(m_key1);
+ zeroise(m_key2);
+ m_hash->clear();
+ m_cipher->clear();
}
/*
* Lion Constructor
*/
-Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, size_t block_len) :
- BLOCK_SIZE(std::max<size_t>(2*hash_in->output_length() + 1, block_len)),
- LEFT_SIZE(hash_in->output_length()),
- RIGHT_SIZE(BLOCK_SIZE - LEFT_SIZE),
- hash(hash_in),
- cipher(sc_in)
+Lion::Lion(HashFunction* hash, StreamCipher* cipher, size_t block_size) :
+ m_block_size(std::max<size_t>(2*hash->output_length() + 1, block_size)),
+ m_hash(hash),
+ m_cipher(cipher)
{
- if(2*LEFT_SIZE + 1 > BLOCK_SIZE)
+ if(2*left_size() + 1 > m_block_size)
throw Invalid_Argument(name() + ": Chosen block size is too small");
- if(!cipher->valid_keylength(LEFT_SIZE))
+ if(!m_cipher->valid_keylength(left_size()))
throw Invalid_Argument(name() + ": This stream/hash combo is invalid");
- key1.resize(LEFT_SIZE);
- key2.resize(LEFT_SIZE);
+ m_key1.resize(left_size());
+ m_key2.resize(left_size());
}
}
diff --git a/src/lib/block/lion/lion.h b/src/lib/block/lion/lion.h
index 37aad19f2..afee95b4e 100644
--- a/src/lib/block/lion/lion.h
+++ b/src/lib/block/lion/lion.h
@@ -1,6 +1,6 @@
/*
* Lion
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -11,6 +11,7 @@
#include <botan/block_cipher.h>
#include <botan/stream_cipher.h>
#include <botan/hash.h>
+#include <memory>
namespace Botan {
@@ -25,19 +26,19 @@ namespace Botan {
class BOTAN_DLL Lion : public BlockCipher
{
public:
- void encrypt_n(const byte in[], byte out[], size_t blocks) const;
- void decrypt_n(const byte in[], byte out[], size_t blocks) const;
+ void encrypt_n(const byte in[], byte out[], size_t blocks) const override;
+ void decrypt_n(const byte in[], byte out[], size_t blocks) const override;
- size_t block_size() const { return BLOCK_SIZE; }
+ size_t block_size() const override { return m_block_size; }
- Key_Length_Specification key_spec() const
+ Key_Length_Specification key_spec() const override
{
- return Key_Length_Specification(2, 2*hash->output_length(), 2);
+ return Key_Length_Specification(2, 2*m_hash->output_length(), 2);
}
- void clear();
- std::string name() const;
- BlockCipher* clone() const;
+ void clear() override;
+ std::string name() const override;
+ BlockCipher* clone() const override;
/**
* @param hash the hash to use internally
@@ -47,19 +48,16 @@ class BOTAN_DLL Lion : public BlockCipher
Lion(HashFunction* hash,
StreamCipher* cipher,
size_t block_size);
-
- Lion(const Lion&) = delete;
- Lion& operator=(const Lion&) = delete;
-
- ~Lion() { delete hash; delete cipher; }
private:
void key_schedule(const byte[], size_t);
- const size_t BLOCK_SIZE, LEFT_SIZE, RIGHT_SIZE;
+ size_t left_size() const { return m_hash->output_length(); }
+ size_t right_size() const { return m_block_size - left_size(); }
- HashFunction* hash;
- StreamCipher* cipher;
- secure_vector<byte> key1, key2;
+ const size_t m_block_size;
+ std::unique_ptr<HashFunction> m_hash;
+ std::unique_ptr<StreamCipher> m_cipher;
+ secure_vector<byte> m_key1, m_key2;
};
}
diff --git a/src/lib/block/lubyrack/lubyrack.cpp b/src/lib/block/lubyrack/lubyrack.cpp
index 9be079003..92974b761 100644
--- a/src/lib/block/lubyrack/lubyrack.cpp
+++ b/src/lib/block/lubyrack/lubyrack.cpp
@@ -1,6 +1,6 @@
/*
* Luby-Rackoff
-* (C) 1999-2008 Jack Lloyd
+* (C) 1999-2008,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -15,31 +15,31 @@ namespace Botan {
*/
void LubyRackoff::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const size_t len = hash->output_length();
+ const size_t len = m_hash->output_length();
secure_vector<byte> buffer_vec(len);
byte* buffer = &buffer_vec[0];
for(size_t i = 0; i != blocks; ++i)
{
- hash->update(K1);
- hash->update(in, len);
- hash->final(buffer);
+ m_hash->update(m_K1);
+ m_hash->update(in, len);
+ m_hash->final(buffer);
xor_buf(out + len, in + len, buffer, len);
- hash->update(K2);
- hash->update(out + len, len);
- hash->final(buffer);
+ m_hash->update(m_K2);
+ m_hash->update(out + len, len);
+ m_hash->final(buffer);
xor_buf(out, in, buffer, len);
- hash->update(K1);
- hash->update(out, len);
- hash->final(buffer);
+ m_hash->update(m_K1);
+ m_hash->update(out, len);
+ m_hash->final(buffer);
xor_buf(out + len, buffer, len);
- hash->update(K2);
- hash->update(out + len, len);
- hash->final(buffer);
+ m_hash->update(m_K2);
+ m_hash->update(out + len, len);
+ m_hash->final(buffer);
xor_buf(out, buffer, len);
in += 2 * len;
@@ -52,31 +52,31 @@ void LubyRackoff::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void LubyRackoff::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const size_t len = hash->output_length();
+ const size_t len = m_hash->output_length();
secure_vector<byte> buffer_vec(len);
byte* buffer = &buffer_vec[0];
for(size_t i = 0; i != blocks; ++i)
{
- hash->update(K2);
- hash->update(in + len, len);
- hash->final(buffer);
+ m_hash->update(m_K2);
+ m_hash->update(in + len, len);
+ m_hash->final(buffer);
xor_buf(out, in, buffer, len);
- hash->update(K1);
- hash->update(out, len);
- hash->final(buffer);
+ m_hash->update(m_K1);
+ m_hash->update(out, len);
+ m_hash->final(buffer);
xor_buf(out + len, in + len, buffer, len);
- hash->update(K2);
- hash->update(out + len, len);
- hash->final(buffer);
+ m_hash->update(m_K2);
+ m_hash->update(out + len, len);
+ m_hash->final(buffer);
xor_buf(out, buffer, len);
- hash->update(K1);
- hash->update(out, len);
- hash->final(buffer);
+ m_hash->update(m_K1);
+ m_hash->update(out, len);
+ m_hash->final(buffer);
xor_buf(out + len, buffer, len);
in += 2 * len;
@@ -89,8 +89,8 @@ void LubyRackoff::decrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void LubyRackoff::key_schedule(const byte key[], size_t length)
{
- K1.assign(key, key + (length / 2));
- K2.assign(key + (length / 2), key + length);
+ m_K1.assign(key, key + (length / 2));
+ m_K2.assign(key + (length / 2), key + length);
}
/*
@@ -98,9 +98,9 @@ void LubyRackoff::key_schedule(const byte key[], size_t length)
*/
void LubyRackoff::clear()
{
- zap(K1);
- zap(K2);
- hash->clear();
+ zap(m_K1);
+ zap(m_K2);
+ m_hash->clear();
}
/*
@@ -108,7 +108,7 @@ void LubyRackoff::clear()
*/
BlockCipher* LubyRackoff::clone() const
{
- return new LubyRackoff(hash->clone());
+ return new LubyRackoff(m_hash->clone());
}
/*
@@ -116,14 +116,7 @@ BlockCipher* LubyRackoff::clone() const
*/
std::string LubyRackoff::name() const
{
- return "Luby-Rackoff(" + hash->name() + ")";
- }
-
-/*
-* Luby-Rackoff Constructor
-*/
-LubyRackoff::LubyRackoff(HashFunction* h) : hash(h)
- {
+ return "Luby-Rackoff(" + m_hash->name() + ")";
}
}
diff --git a/src/lib/block/lubyrack/lubyrack.h b/src/lib/block/lubyrack/lubyrack.h
index e28c60be7..236be53d6 100644
--- a/src/lib/block/lubyrack/lubyrack.h
+++ b/src/lib/block/lubyrack/lubyrack.h
@@ -1,6 +1,6 @@
/*
* Luby-Rackoff
-* (C) 1999-2008 Jack Lloyd
+* (C) 1999-2008,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -10,6 +10,7 @@
#include <botan/block_cipher.h>
#include <botan/hash.h>
+#include <memory>
namespace Botan {
@@ -19,30 +20,30 @@ namespace Botan {
class BOTAN_DLL LubyRackoff : public BlockCipher
{
public:
- void encrypt_n(const byte in[], byte out[], size_t blocks) const;
- void decrypt_n(const byte in[], byte out[], size_t blocks) const;
+ void encrypt_n(const byte in[], byte out[], size_t blocks) const override;
+ void decrypt_n(const byte in[], byte out[], size_t blocks) const override;
- size_t block_size() const { return 2 * hash->output_length(); }
+ size_t block_size() const override { return 2 * m_hash->output_length(); }
- Key_Length_Specification key_spec() const
+ Key_Length_Specification key_spec() const override
{
return Key_Length_Specification(2, 32, 2);
}
- void clear();
- std::string name() const;
- BlockCipher* clone() const;
+ void clear() override;
+ std::string name() const override;
+ BlockCipher* clone() const override;
/**
* @param hash function to use to form the block cipher
*/
- LubyRackoff(HashFunction* hash);
- ~LubyRackoff() { delete hash; }
+ LubyRackoff(HashFunction* hash) : m_hash(hash) {}
+
private:
- void key_schedule(const byte[], size_t);
+ void key_schedule(const byte[], size_t) override;
- HashFunction* hash;
- secure_vector<byte> K1, K2;
+ std::unique_ptr<HashFunction> m_hash;
+ secure_vector<byte> m_K1, m_K2;
};
}
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;
};
}
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;
};
}
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp
index 00120cf14..16524faec 100644
--- a/src/lib/mac/cmac/cmac.cpp
+++ b/src/lib/mac/cmac/cmac.cpp
@@ -1,11 +1,12 @@
/*
* CMAC
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/cmac.h>
+#include <botan/loadstor.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
@@ -13,9 +14,10 @@ namespace Botan {
/*
* Perform CMAC's multiplication in GF(2^n)
*/
-secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in,
- byte polynomial)
+secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in)
{
+ const byte polynomial = (in.size() == 16) ? 0x87 : 0x1B;
+
const byte poly_xor = (in[0] & 0x80) ? polynomial : 0;
secure_vector<byte> out = in;
@@ -38,24 +40,24 @@ secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in,
*/
void CMAC::add_data(const byte input[], size_t length)
{
- buffer_insert(buffer, position, input, length);
- if(position + length > output_length())
+ buffer_insert(m_buffer, m_position, input, length);
+ if(m_position + length > output_length())
{
- xor_buf(state, buffer, output_length());
- e->encrypt(state);
- input += (output_length() - position);
- length -= (output_length() - position);
+ xor_buf(m_state, m_buffer, output_length());
+ m_cipher->encrypt(m_state);
+ input += (output_length() - m_position);
+ length -= (output_length() - m_position);
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();
}
- copy_mem(&buffer[0], input, length);
- position = 0;
+ copy_mem(&m_buffer[0], input, length);
+ m_position = 0;
}
- position += length;
+ m_position += length;
}
/*
@@ -63,26 +65,26 @@ void CMAC::add_data(const byte input[], size_t length)
*/
void CMAC::final_result(byte mac[])
{
- xor_buf(state, buffer, position);
+ xor_buf(m_state, m_buffer, m_position);
- if(position == output_length())
+ if(m_position == output_length())
{
- xor_buf(state, B, output_length());
+ xor_buf(m_state, m_B, output_length());
}
else
{
- state[position] ^= 0x80;
- xor_buf(state, P, output_length());
+ m_state[m_position] ^= 0x80;
+ xor_buf(m_state, m_P, output_length());
}
- e->encrypt(state);
+ m_cipher->encrypt(m_state);
for(size_t i = 0; i != output_length(); ++i)
- mac[i] = state[i];
+ mac[i] = m_state[i];
- zeroise(state);
- zeroise(buffer);
- position = 0;
+ zeroise(m_state);
+ zeroise(m_buffer);
+ m_position = 0;
}
/*
@@ -91,10 +93,10 @@ void CMAC::final_result(byte mac[])
void CMAC::key_schedule(const byte key[], size_t length)
{
clear();
- e->set_key(key, length);
- e->encrypt(B);
- B = poly_double(B, polynomial);
- P = poly_double(B, polynomial);
+ m_cipher->set_key(key, length);
+ m_cipher->encrypt(m_B);
+ m_B = poly_double(m_B);
+ m_P = poly_double(m_B);
}
/*
@@ -102,12 +104,12 @@ void CMAC::key_schedule(const byte key[], size_t length)
*/
void CMAC::clear()
{
- e->clear();
- zeroise(state);
- zeroise(buffer);
- zeroise(B);
- zeroise(P);
- position = 0;
+ m_cipher->clear();
+ zeroise(m_state);
+ zeroise(m_buffer);
+ zeroise(m_B);
+ zeroise(m_P);
+ m_position = 0;
}
/*
@@ -115,7 +117,7 @@ void CMAC::clear()
*/
std::string CMAC::name() const
{
- return "CMAC(" + e->name() + ")";
+ return "CMAC(" + m_cipher->name() + ")";
}
/*
@@ -123,34 +125,22 @@ std::string CMAC::name() const
*/
MessageAuthenticationCode* CMAC::clone() const
{
- return new CMAC(e->clone());
+ return new CMAC(m_cipher->clone());
}
/*
* CMAC Constructor
*/
-CMAC::CMAC(BlockCipher* e_in) : e(e_in)
- {
- if(e->block_size() == 16)
- polynomial = 0x87;
- else if(e->block_size() == 8)
- polynomial = 0x1B;
- else
- throw Invalid_Argument("CMAC cannot use the cipher " + e->name());
-
- state.resize(output_length());
- buffer.resize(output_length());
- B.resize(output_length());
- P.resize(output_length());
- position = 0;
- }
-
-/*
-* CMAC Destructor
-*/
-CMAC::~CMAC()
+CMAC::CMAC(BlockCipher* cipher) : m_cipher(cipher)
{
- delete e;
+ if(m_cipher->block_size() != 8 && m_cipher->block_size() != 16)
+ throw Invalid_Argument("CMAC cannot use the cipher " + m_cipher->name());
+
+ m_state.resize(output_length());
+ m_buffer.resize(output_length());
+ m_B.resize(output_length());
+ m_P.resize(output_length());
+ m_position = 0;
}
}
diff --git a/src/lib/mac/cmac/cmac.h b/src/lib/mac/cmac/cmac.h
index c1b75cfa5..f363eade5 100644
--- a/src/lib/mac/cmac/cmac.h
+++ b/src/lib/mac/cmac/cmac.h
@@ -1,6 +1,6 @@
/*
* CMAC
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -10,6 +10,7 @@
#include <botan/mac.h>
#include <botan/block_cipher.h>
+#include <memory>
namespace Botan {
@@ -20,14 +21,14 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode
{
public:
std::string name() const;
- size_t output_length() const { return e->block_size(); }
+ size_t output_length() const { return m_cipher->block_size(); }
MessageAuthenticationCode* clone() const;
void clear();
Key_Length_Specification key_spec() const
{
- return e->key_spec();
+ return m_cipher->key_spec();
}
/**
@@ -35,8 +36,7 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode
* @param in the input
* @param polynomial the byte value of the polynomial
*/
- static secure_vector<byte> poly_double(const secure_vector<byte>& in,
- byte polynomial);
+ static secure_vector<byte> poly_double(const secure_vector<byte>& in);
/**
* @param cipher the underlying block cipher to use
@@ -45,17 +45,14 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode
CMAC(const CMAC&) = delete;
CMAC& operator=(const CMAC&) = delete;
-
- ~CMAC();
private:
void add_data(const byte[], size_t);
void final_result(byte[]);
void key_schedule(const byte[], size_t);
- BlockCipher* e;
- secure_vector<byte> buffer, state, B, P;
- size_t position;
- byte polynomial;
+ std::unique_ptr<BlockCipher> m_cipher;
+ secure_vector<byte> m_buffer, m_state, m_B, m_P;
+ size_t m_position;
};
}
diff --git a/src/lib/mac/hmac/hmac.cpp b/src/lib/mac/hmac/hmac.cpp
index 9e9a643db..6d8e393ae 100644
--- a/src/lib/mac/hmac/hmac.cpp
+++ b/src/lib/mac/hmac/hmac.cpp
@@ -1,6 +1,6 @@
/*
* HMAC
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
* 2007 Yves Jerschow
*
* Distributed under the terms of the Botan license
@@ -16,7 +16,7 @@ namespace Botan {
*/
void HMAC::add_data(const byte input[], size_t length)
{
- hash->update(input, length);
+ m_hash->update(input, length);
}
/*
@@ -24,11 +24,11 @@ void HMAC::add_data(const byte input[], size_t length)
*/
void HMAC::final_result(byte mac[])
{
- hash->final(mac);
- hash->update(o_key);
- hash->update(mac, output_length());
- hash->final(mac);
- hash->update(i_key);
+ m_hash->final(mac);
+ m_hash->update(m_okey);
+ m_hash->update(mac, output_length());
+ m_hash->final(mac);
+ m_hash->update(m_ikey);
}
/*
@@ -36,27 +36,27 @@ void HMAC::final_result(byte mac[])
*/
void HMAC::key_schedule(const byte key[], size_t length)
{
- hash->clear();
+ m_hash->clear();
- i_key.resize(hash->hash_block_size());
- o_key.resize(hash->hash_block_size());
+ m_ikey.resize(m_hash->hash_block_size());
+ m_okey.resize(m_hash->hash_block_size());
- std::fill(i_key.begin(), i_key.end(), 0x36);
- std::fill(o_key.begin(), o_key.end(), 0x5C);
+ std::fill(m_ikey.begin(), m_ikey.end(), 0x36);
+ std::fill(m_okey.begin(), m_okey.end(), 0x5C);
- if(length > hash->hash_block_size())
+ if(length > m_hash->hash_block_size())
{
- secure_vector<byte> hmac_key = hash->process(key, length);
- xor_buf(i_key, hmac_key, hmac_key.size());
- xor_buf(o_key, hmac_key, hmac_key.size());
+ secure_vector<byte> hmac_key = m_hash->process(key, length);
+ xor_buf(m_ikey, hmac_key, hmac_key.size());
+ xor_buf(m_okey, hmac_key, hmac_key.size());
}
else
{
- xor_buf(i_key, key, length);
- xor_buf(o_key, key, length);
+ xor_buf(m_ikey, key, length);
+ xor_buf(m_okey, key, length);
}
- hash->update(i_key);
+ m_hash->update(m_ikey);
}
/*
@@ -64,9 +64,9 @@ void HMAC::key_schedule(const byte key[], size_t length)
*/
void HMAC::clear()
{
- hash->clear();
- zap(i_key);
- zap(o_key);
+ m_hash->clear();
+ zap(m_ikey);
+ zap(m_okey);
}
/*
@@ -74,7 +74,7 @@ void HMAC::clear()
*/
std::string HMAC::name() const
{
- return "HMAC(" + hash->name() + ")";
+ return "HMAC(" + m_hash->name() + ")";
}
/*
@@ -82,16 +82,16 @@ std::string HMAC::name() const
*/
MessageAuthenticationCode* HMAC::clone() const
{
- return new HMAC(hash->clone());
+ return new HMAC(m_hash->clone());
}
/*
* HMAC Constructor
*/
-HMAC::HMAC(HashFunction* hash_in) : hash(hash_in)
+HMAC::HMAC(HashFunction* hash) : m_hash(hash)
{
- if(hash->hash_block_size() == 0)
- throw Invalid_Argument("HMAC cannot be used with " + hash->name());
+ if(m_hash->hash_block_size() == 0)
+ throw Invalid_Argument("HMAC cannot be used with " + m_hash->name());
}
}
diff --git a/src/lib/mac/hmac/hmac.h b/src/lib/mac/hmac/hmac.h
index 39a084874..359d4e6f3 100644
--- a/src/lib/mac/hmac/hmac.h
+++ b/src/lib/mac/hmac/hmac.h
@@ -1,6 +1,6 @@
/*
* HMAC
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -10,6 +10,7 @@
#include <botan/mac.h>
#include <botan/hash.h>
+#include <memory>
namespace Botan {
@@ -23,10 +24,11 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode
std::string name() const;
MessageAuthenticationCode* clone() const;
- size_t output_length() const { return hash->output_length(); }
+ size_t output_length() const { return m_hash->output_length(); }
Key_Length_Specification key_spec() const
{
+ // Absurd max length here is to support PBKDF2
return Key_Length_Specification(0, 512);
}
@@ -37,15 +39,13 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode
HMAC(const HMAC&) = delete;
HMAC& operator=(const HMAC&) = delete;
-
- ~HMAC() { delete hash; }
private:
void add_data(const byte[], size_t);
void final_result(byte[]);
void key_schedule(const byte[], size_t);
- HashFunction* hash;
- secure_vector<byte> i_key, o_key;
+ std::unique_ptr<HashFunction> m_hash;
+ secure_vector<byte> m_ikey, m_okey;
};
}
diff --git a/src/lib/mac/ssl3mac/ssl3_mac.cpp b/src/lib/mac/ssl3mac/ssl3_mac.cpp
index 64f3103ef..82a26cfaf 100644
--- a/src/lib/mac/ssl3mac/ssl3_mac.cpp
+++ b/src/lib/mac/ssl3mac/ssl3_mac.cpp
@@ -14,7 +14,7 @@ namespace Botan {
*/
void SSL3_MAC::add_data(const byte input[], size_t length)
{
- hash->update(input, length);
+ m_hash->update(input, length);
}
/*
@@ -22,11 +22,11 @@ void SSL3_MAC::add_data(const byte input[], size_t length)
*/
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);
+ m_hash->final(mac);
+ m_hash->update(m_okey);
+ m_hash->update(mac, output_length());
+ m_hash->final(mac);
+ m_hash->update(m_ikey);
}
/*
@@ -34,22 +34,22 @@ void SSL3_MAC::final_result(byte mac[])
*/
void SSL3_MAC::key_schedule(const byte key[], size_t length)
{
- hash->clear();
+ m_hash->clear();
// Quirk to deal with specification bug
const size_t inner_hash_length =
- (hash->name() == "SHA-160") ? 60 : hash->hash_block_size();
+ (m_hash->name() == "SHA-160") ? 60 : m_hash->hash_block_size();
- i_key.resize(inner_hash_length);
- o_key.resize(inner_hash_length);
+ m_ikey.resize(inner_hash_length);
+ m_okey.resize(inner_hash_length);
- std::fill(i_key.begin(), i_key.end(), 0x36);
- std::fill(o_key.begin(), o_key.end(), 0x5C);
+ std::fill(m_ikey.begin(), m_ikey.end(), 0x36);
+ std::fill(m_okey.begin(), m_okey.end(), 0x5C);
- copy_mem(&i_key[0], key, length);
- copy_mem(&o_key[0], key, length);
+ copy_mem(&m_ikey[0], key, length);
+ copy_mem(&m_okey[0], key, length);
- hash->update(i_key);
+ m_hash->update(m_ikey);
}
/*
@@ -57,9 +57,9 @@ void SSL3_MAC::key_schedule(const byte key[], size_t length)
*/
void SSL3_MAC::clear()
{
- hash->clear();
- zap(i_key);
- zap(o_key);
+ m_hash->clear();
+ zap(m_ikey);
+ zap(m_okey);
}
/*
@@ -67,7 +67,7 @@ void SSL3_MAC::clear()
*/
std::string SSL3_MAC::name() const
{
- return "SSL3-MAC(" + hash->name() + ")";
+ return "SSL3-MAC(" + m_hash->name() + ")";
}
/*
@@ -75,16 +75,16 @@ std::string SSL3_MAC::name() const
*/
MessageAuthenticationCode* SSL3_MAC::clone() const
{
- return new SSL3_MAC(hash->clone());
+ return new SSL3_MAC(m_hash->clone());
}
/*
* SSL3-MAC Constructor
*/
-SSL3_MAC::SSL3_MAC(HashFunction* hash_in) : hash(hash_in)
+SSL3_MAC::SSL3_MAC(HashFunction* hash) : m_hash(hash)
{
- if(hash->hash_block_size() == 0)
- throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name());
+ if(m_hash->hash_block_size() == 0)
+ throw Invalid_Argument("SSL3-MAC cannot be used with " + m_hash->name());
}
}
diff --git a/src/lib/mac/ssl3mac/ssl3_mac.h b/src/lib/mac/ssl3mac/ssl3_mac.h
index d23ac023c..8ddb13ce8 100644
--- a/src/lib/mac/ssl3mac/ssl3_mac.h
+++ b/src/lib/mac/ssl3mac/ssl3_mac.h
@@ -34,14 +34,13 @@ class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode
* @param hash the underlying hash to use
*/
SSL3_MAC(HashFunction* hash);
- ~SSL3_MAC() { delete hash; }
private:
void add_data(const byte[], size_t);
void final_result(byte[]);
void key_schedule(const byte[], size_t);
- HashFunction* hash;
- secure_vector<byte> i_key, o_key;
+ std::unique_ptr<HashFunction> m_hash;
+ secure_vector<byte> m_ikey, m_okey;
};
}
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;
};
}
diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp
index fd66bb2e9..2e337ba66 100644
--- a/src/lib/modes/aead/ocb/ocb.cpp
+++ b/src/lib/modes/aead/ocb/ocb.cpp
@@ -63,7 +63,7 @@ class L_computer
secure_vector<byte> poly_double(const secure_vector<byte>& in) const
{
- return CMAC::poly_double(in, 0x87);
+ return CMAC::poly_double(in);
}
secure_vector<byte> m_L_dollar, m_L_star;
diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp
index a89c3dd08..be998cdb0 100644
--- a/src/lib/modes/aead/siv/siv.cpp
+++ b/src/lib/modes/aead/siv/siv.cpp
@@ -104,19 +104,19 @@ secure_vector<byte> SIV_Mode::S2V(const byte* text, size_t text_len)
for(size_t i = 0; i != m_ad_macs.size(); ++i)
{
- V = CMAC::poly_double(V, 0x87);
+ V = CMAC::poly_double(V);
V ^= m_ad_macs[i];
}
if(m_nonce.size())
{
- V = CMAC::poly_double(V, 0x87);
+ V = CMAC::poly_double(V);
V ^= m_nonce;
}
if(text_len < 16)
{
- V = CMAC::poly_double(V, 0x87);
+ V = CMAC::poly_double(V);
xor_buf(&V[0], text, text_len);
V[text_len] ^= 0x80;
return cmac().process(V);