aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/dlies/dlies.cpp12
-rw-r--r--src/lib/pubkey/dlies/dlies.h13
-rw-r--r--src/lib/stream/ctr/ctr.cpp90
-rw-r--r--src/lib/stream/ctr/ctr.h18
-rw-r--r--src/lib/stream/ofb/ofb.cpp72
-rw-r--r--src/lib/stream/ofb/ofb.h14
-rw-r--r--src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.cpp1
-rw-r--r--src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.h3
8 files changed, 74 insertions, 149 deletions
diff --git a/src/lib/pubkey/dlies/dlies.cpp b/src/lib/pubkey/dlies/dlies.cpp
index 715b55a36..a969eaec7 100644
--- a/src/lib/pubkey/dlies/dlies.cpp
+++ b/src/lib/pubkey/dlies/dlies.cpp
@@ -25,12 +25,6 @@ DLIES_Encryptor::DLIES_Encryptor(const PK_Key_Agreement_Key& key,
my_key = key.public_value();
}
-DLIES_Encryptor::~DLIES_Encryptor()
- {
- delete kdf;
- delete mac;
- }
-
/*
* DLIES Encryption
*/
@@ -99,12 +93,6 @@ DLIES_Decryptor::DLIES_Decryptor(const PK_Key_Agreement_Key& key,
my_key = key.public_value();
}
-DLIES_Decryptor::~DLIES_Decryptor()
- {
- delete kdf;
- delete mac;
- }
-
/*
* DLIES Decryption
*/
diff --git a/src/lib/pubkey/dlies/dlies.h b/src/lib/pubkey/dlies/dlies.h
index 9739afeb2..643ef95c5 100644
--- a/src/lib/pubkey/dlies/dlies.h
+++ b/src/lib/pubkey/dlies/dlies.h
@@ -11,6 +11,7 @@
#include <botan/pubkey.h>
#include <botan/mac.h>
#include <botan/kdf.h>
+#include <memory>
namespace Botan {
@@ -25,8 +26,6 @@ class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor
MessageAuthenticationCode* mac,
size_t mac_key_len = 20);
- ~DLIES_Encryptor();
-
void set_other_key(const std::vector<byte>&);
private:
std::vector<byte> enc(const byte[], size_t,
@@ -37,8 +36,8 @@ class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor
std::vector<byte> other_key, my_key;
PK_Key_Agreement ka;
- KDF* kdf;
- MessageAuthenticationCode* mac;
+ std::unique_ptr<KDF> kdf;
+ std::unique_ptr<MessageAuthenticationCode> mac;
size_t mac_keylen;
};
@@ -53,16 +52,14 @@ class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor
MessageAuthenticationCode* mac,
size_t mac_key_len = 20);
- ~DLIES_Decryptor();
-
private:
secure_vector<byte> dec(const byte[], size_t) const;
std::vector<byte> my_key;
PK_Key_Agreement ka;
- KDF* kdf;
- MessageAuthenticationCode* mac;
+ std::unique_ptr<KDF> kdf;
+ std::unique_ptr<MessageAuthenticationCode> mac;
size_t mac_keylen;
};
diff --git a/src/lib/stream/ctr/ctr.cpp b/src/lib/stream/ctr/ctr.cpp
index 87ec86c65..ad0fd363a 100644
--- a/src/lib/stream/ctr/ctr.cpp
+++ b/src/lib/stream/ctr/ctr.cpp
@@ -1,6 +1,6 @@
/*
* Counter mode
-* (C) 1999-2011 Jack Lloyd
+* (C) 1999-2011,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -10,101 +10,72 @@
namespace Botan {
-/*
-* CTR-BE Constructor
-*/
-
CTR_BE::CTR_BE(BlockCipher* ciph) :
- permutation(ciph),
- counter(256 * permutation->block_size()),
- buffer(counter.size()),
- position(0)
+ m_cipher(ciph),
+ m_counter(256 * m_cipher->block_size()),
+ m_pad(m_counter.size()),
+ m_pad_pos(0)
{
}
-/*
-* CTR_BE Destructor
-*/
-CTR_BE::~CTR_BE()
- {
- delete permutation;
- }
-
-/*
-* Zeroize
-*/
void CTR_BE::clear()
{
- permutation->clear();
- zeroise(buffer);
- zeroise(counter);
- position = 0;
+ m_cipher->clear();
+ zeroise(m_pad);
+ zeroise(m_counter);
+ m_pad_pos = 0;
}
-/*
-* Set the key
-*/
void CTR_BE::key_schedule(const byte key[], size_t key_len)
{
- permutation->set_key(key, key_len);
+ m_cipher->set_key(key, key_len);
// Set a default all-zeros IV
set_iv(nullptr, 0);
}
-/*
-* Return the name of this type
-*/
std::string CTR_BE::name() const
{
- return ("CTR-BE(" + permutation->name() + ")");
+ return ("CTR-BE(" + m_cipher->name() + ")");
}
-/*
-* CTR-BE Encryption/Decryption
-*/
void CTR_BE::cipher(const byte in[], byte out[], size_t length)
{
- while(length >= buffer.size() - position)
+ while(length >= m_pad.size() - m_pad_pos)
{
- xor_buf(out, in, &buffer[position], buffer.size() - position);
- length -= (buffer.size() - position);
- in += (buffer.size() - position);
- out += (buffer.size() - position);
+ xor_buf(out, in, &m_pad[m_pad_pos], m_pad.size() - m_pad_pos);
+ length -= (m_pad.size() - m_pad_pos);
+ in += (m_pad.size() - m_pad_pos);
+ out += (m_pad.size() - m_pad_pos);
increment_counter();
}
- xor_buf(out, in, &buffer[position], length);
- position += length;
+ xor_buf(out, in, &m_pad[m_pad_pos], length);
+ m_pad_pos += length;
}
-/*
-* Set CTR-BE IV
-*/
void CTR_BE::set_iv(const byte iv[], size_t iv_len)
{
if(!valid_iv_length(iv_len))
throw Invalid_IV_Length(name(), iv_len);
- const size_t bs = permutation->block_size();
+ const size_t bs = m_cipher->block_size();
- zeroise(counter);
+ zeroise(m_counter);
- buffer_insert(counter, 0, iv, iv_len);
+ buffer_insert(m_counter, 0, iv, iv_len);
- /*
- * Set counter blocks to IV, IV + 1, ... IV + 255
- */
+ // Set m_counter blocks to IV, IV + 1, ... IV + 255
for(size_t i = 1; i != 256; ++i)
{
- buffer_insert(counter, i*bs, &counter[(i-1)*bs], bs);
+ buffer_insert(m_counter, i*bs, &m_counter[(i-1)*bs], bs);
for(size_t j = 0; j != bs; ++j)
- if(++counter[i*bs + (bs - 1 - j)])
+ if(++m_counter[i*bs + (bs - 1 - j)])
break;
}
- permutation->encrypt_n(&counter[0], &buffer[0], 256);
- position = 0;
+ m_cipher->encrypt_n(&m_counter[0], &m_pad[0], 256);
+ m_pad_pos = 0;
}
/*
@@ -112,7 +83,7 @@ void CTR_BE::set_iv(const byte iv[], size_t iv_len)
*/
void CTR_BE::increment_counter()
{
- const size_t bs = permutation->block_size();
+ const size_t bs = m_cipher->block_size();
/*
* Each counter value always needs to be incremented by 256,
@@ -122,13 +93,12 @@ void CTR_BE::increment_counter()
for(size_t i = 0; i != 256; ++i)
{
for(size_t j = 1; j != bs; ++j)
- if(++counter[i*bs + (bs - 1 - j)])
+ if(++m_counter[i*bs + (bs - 1 - j)])
break;
}
- permutation->encrypt_n(&counter[0], &buffer[0], 256);
-
- position = 0;
+ m_cipher->encrypt_n(&m_counter[0], &m_pad[0], 256);
+ m_pad_pos = 0;
}
}
diff --git a/src/lib/stream/ctr/ctr.h b/src/lib/stream/ctr/ctr.h
index 84cf9ed5d..c262f4ad9 100644
--- a/src/lib/stream/ctr/ctr.h
+++ b/src/lib/stream/ctr/ctr.h
@@ -10,6 +10,7 @@
#include <botan/block_cipher.h>
#include <botan/stream_cipher.h>
+#include <memory>
namespace Botan {
@@ -24,17 +25,17 @@ class BOTAN_DLL CTR_BE : public StreamCipher
void set_iv(const byte iv[], size_t iv_len);
bool valid_iv_length(size_t iv_len) const
- { return (iv_len <= permutation->block_size()); }
+ { return (iv_len <= m_cipher->block_size()); }
Key_Length_Specification key_spec() const
{
- return permutation->key_spec();
+ return m_cipher->key_spec();
}
std::string name() const;
CTR_BE* clone() const
- { return new CTR_BE(permutation->clone()); }
+ { return new CTR_BE(m_cipher->clone()); }
void clear();
@@ -42,18 +43,13 @@ class BOTAN_DLL CTR_BE : public StreamCipher
* @param cipher the underlying block cipher to use
*/
CTR_BE(BlockCipher* cipher);
-
- CTR_BE(const CTR_BE&) = delete;
- CTR_BE& operator=(const CTR_BE&) = delete;
-
- ~CTR_BE();
private:
void key_schedule(const byte key[], size_t key_len);
void increment_counter();
- BlockCipher* permutation;
- secure_vector<byte> counter, buffer;
- size_t position;
+ std::unique_ptr<BlockCipher> m_cipher;
+ secure_vector<byte> m_counter, m_pad;
+ size_t m_pad_pos;
};
}
diff --git a/src/lib/stream/ofb/ofb.cpp b/src/lib/stream/ofb/ofb.cpp
index 1137a58af..9d01c7712 100644
--- a/src/lib/stream/ofb/ofb.cpp
+++ b/src/lib/stream/ofb/ofb.cpp
@@ -1,93 +1,67 @@
/*
* OFB Mode
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/ofb.h>
#include <botan/internal/xor_buf.h>
-#include <algorithm>
namespace Botan {
-/*
-* OFB Constructor
-*/
-OFB::OFB(BlockCipher* ciph) : permutation(ciph)
+OFB::OFB(BlockCipher* cipher) :
+ m_cipher(cipher),
+ m_buffer(m_cipher->block_size()),
+ m_buf_pos(0)
{
- position = 0;
- buffer.resize(permutation->block_size());
}
-/*
-* OFB Destructor
-*/
-OFB::~OFB()
- {
- delete permutation;
- }
-
-/*
-* Zeroize
-*/
void OFB::clear()
{
- permutation->clear();
- zeroise(buffer);
- position = 0;
+ m_cipher->clear();
+ zeroise(m_buffer);
+ m_buf_pos = 0;
}
-/*
-* Set the key
-*/
void OFB::key_schedule(const byte key[], size_t key_len)
{
- permutation->set_key(key, key_len);
+ m_cipher->set_key(key, key_len);
// Set a default all-zeros IV
set_iv(nullptr, 0);
}
-/*
-* Return the name of this type
-*/
std::string OFB::name() const
{
- return ("OFB(" + permutation->name() + ")");
+ return "OFB(" + m_cipher->name() + ")";
}
-/*
-* CTR-BE Encryption/Decryption
-*/
void OFB::cipher(const byte in[], byte out[], size_t length)
{
- while(length >= buffer.size() - position)
+ while(length >= m_buffer.size() - m_buf_pos)
{
- xor_buf(out, in, &buffer[position], buffer.size() - position);
- length -= (buffer.size() - position);
- in += (buffer.size() - position);
- out += (buffer.size() - position);
- permutation->encrypt(buffer);
- position = 0;
+ xor_buf(out, in, &m_buffer[m_buf_pos], m_buffer.size() - m_buf_pos);
+ length -= (m_buffer.size() - m_buf_pos);
+ in += (m_buffer.size() - m_buf_pos);
+ out += (m_buffer.size() - m_buf_pos);
+ m_cipher->encrypt(m_buffer);
+ m_buf_pos = 0;
}
- xor_buf(out, in, &buffer[position], length);
- position += length;
+ xor_buf(out, in, &m_buffer[m_buf_pos], length);
+ m_buf_pos += length;
}
-/*
-* Set CTR-BE IV
-*/
void OFB::set_iv(const byte iv[], size_t iv_len)
{
if(!valid_iv_length(iv_len))
throw Invalid_IV_Length(name(), iv_len);
- zeroise(buffer);
- buffer_insert(buffer, 0, iv, iv_len);
+ zeroise(m_buffer);
+ buffer_insert(m_buffer, 0, iv, iv_len);
- permutation->encrypt(buffer);
- position = 0;
+ m_cipher->encrypt(m_buffer);
+ m_buf_pos = 0;
}
}
diff --git a/src/lib/stream/ofb/ofb.h b/src/lib/stream/ofb/ofb.h
index 9d4fd882f..0d08dac0a 100644
--- a/src/lib/stream/ofb/ofb.h
+++ b/src/lib/stream/ofb/ofb.h
@@ -10,6 +10,7 @@
#include <botan/stream_cipher.h>
#include <botan/block_cipher.h>
+#include <memory>
namespace Botan {
@@ -24,17 +25,17 @@ class BOTAN_DLL OFB : public StreamCipher
void set_iv(const byte iv[], size_t iv_len);
bool valid_iv_length(size_t iv_len) const
- { return (iv_len <= permutation->block_size()); }
+ { return (iv_len <= m_cipher->block_size()); }
Key_Length_Specification key_spec() const
{
- return permutation->key_spec();
+ return m_cipher->key_spec();
}
std::string name() const;
OFB* clone() const
- { return new OFB(permutation->clone()); }
+ { return new OFB(m_cipher->clone()); }
void clear();
@@ -42,13 +43,12 @@ class BOTAN_DLL OFB : public StreamCipher
* @param cipher the underlying block cipher to use
*/
OFB(BlockCipher* cipher);
- ~OFB();
private:
void key_schedule(const byte key[], size_t key_len);
- BlockCipher* permutation;
- secure_vector<byte> buffer;
- size_t position;
+ std::unique_ptr<BlockCipher> m_cipher;
+ secure_vector<byte> m_buffer;
+ size_t m_buf_pos;
};
}
diff --git a/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.cpp b/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.cpp
index d4f286a8d..bddb7822c 100644
--- a/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.cpp
+++ b/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.cpp
@@ -119,7 +119,6 @@ Session_Manager_SQLite::Session_Manager_SQLite(const std::string& passphrase,
Session_Manager_SQLite::~Session_Manager_SQLite()
{
- delete m_db;
}
bool Session_Manager_SQLite::load_from_session_id(const std::vector<byte>& session_id,
diff --git a/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.h b/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.h
index 7892ccd6a..04e8135a8 100644
--- a/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.h
+++ b/src/lib/tls/sessions_sqlite/tls_session_manager_sqlite.h
@@ -10,6 +10,7 @@
#include <botan/tls_session_manager.h>
#include <botan/rng.h>
+#include <memory>
namespace Botan {
@@ -70,7 +71,7 @@ class BOTAN_DLL Session_Manager_SQLite : public Session_Manager
RandomNumberGenerator& m_rng;
size_t m_max_sessions;
std::chrono::seconds m_session_lifetime;
- sqlite3_database* m_db;
+ std::unique_ptr<sqlite3_database> m_db;
};
}