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/block/cascade | |
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/block/cascade')
-rw-r--r-- | src/lib/block/cascade/cascade.cpp | 42 | ||||
-rw-r--r-- | src/lib/block/cascade/cascade.h | 14 |
2 files changed, 24 insertions, 32 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; }; |