aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/dlies
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-18 20:32:36 +0000
committerlloyd <[email protected]>2012-05-18 20:32:36 +0000
commitc691561f3198f481c13457433efbccc1c9fcd898 (patch)
treea45ea2c5a30e0cb009fbcb68a61ef39332ff790c /src/pubkey/dlies
parentd76700f01c7ecac5633edf75f8d7408b46c5dbac (diff)
Fairly huge update that replaces the old secmem types with std::vector
using a custom allocator. Currently our allocator just does new/delete with a memset before deletion, and the mmap and mlock allocators have been removed.
Diffstat (limited to 'src/pubkey/dlies')
-rw-r--r--src/pubkey/dlies/dlies.cpp27
-rw-r--r--src/pubkey/dlies/dlies.h13
2 files changed, 22 insertions, 18 deletions
diff --git a/src/pubkey/dlies/dlies.cpp b/src/pubkey/dlies/dlies.cpp
index 80dde048b..715b55a36 100644
--- a/src/pubkey/dlies/dlies.cpp
+++ b/src/pubkey/dlies/dlies.cpp
@@ -34,19 +34,19 @@ DLIES_Encryptor::~DLIES_Encryptor()
/*
* DLIES Encryption
*/
-SecureVector<byte> DLIES_Encryptor::enc(const byte in[], size_t length,
- RandomNumberGenerator&) const
+std::vector<byte> DLIES_Encryptor::enc(const byte in[], size_t length,
+ RandomNumberGenerator&) const
{
if(length > maximum_input_size())
throw Invalid_Argument("DLIES: Plaintext too large");
if(other_key.empty())
throw Invalid_State("DLIES: The other key was never set");
- SecureVector<byte> out(my_key.size() + length + mac->output_length());
+ secure_vector<byte> out(my_key.size() + length + mac->output_length());
buffer_insert(out, 0, my_key);
buffer_insert(out, my_key.size(), in, length);
- SecureVector<byte> vz = my_key;
+ secure_vector<byte> vz(my_key.begin(), my_key.end());
vz += ka.derive_key(0, other_key).bits_of();
const size_t K_LENGTH = length + mac_keylen;
@@ -65,13 +65,13 @@ SecureVector<byte> DLIES_Encryptor::enc(const byte in[], size_t length,
mac->final(C + length);
- return out;
+ return unlock(out);
}
/*
* Set the other parties public key
*/
-void DLIES_Encryptor::set_other_key(const MemoryRegion<byte>& ok)
+void DLIES_Encryptor::set_other_key(const std::vector<byte>& ok)
{
other_key = ok;
}
@@ -108,18 +108,21 @@ DLIES_Decryptor::~DLIES_Decryptor()
/*
* DLIES Decryption
*/
-SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], size_t length) const
+secure_vector<byte> DLIES_Decryptor::dec(const byte msg[], size_t length) const
{
if(length < my_key.size() + mac->output_length())
throw Decoding_Error("DLIES decryption: ciphertext is too short");
const size_t CIPHER_LEN = length - my_key.size() - mac->output_length();
- SecureVector<byte> v(msg, my_key.size());
- SecureVector<byte> C(msg + my_key.size(), CIPHER_LEN);
- SecureVector<byte> T(msg + my_key.size() + CIPHER_LEN, mac->output_length());
+ std::vector<byte> v(msg, msg + my_key.size());
- SecureVector<byte> vz(msg, my_key.size());
+ secure_vector<byte> C(msg + my_key.size(), msg + my_key.size() + CIPHER_LEN);
+
+ secure_vector<byte> T(msg + my_key.size() + CIPHER_LEN,
+ msg + my_key.size() + CIPHER_LEN + mac->output_length());
+
+ secure_vector<byte> vz(msg, msg + my_key.size());
vz += ka.derive_key(0, v).bits_of();
const size_t K_LENGTH = C.size() + mac_keylen;
@@ -131,7 +134,7 @@ SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], size_t length) const
mac->update(C);
for(size_t j = 0; j != 8; ++j)
mac->update(0);
- SecureVector<byte> T2 = mac->final();
+ secure_vector<byte> T2 = mac->final();
if(T != T2)
throw Decoding_Error("DLIES: message authentication failed");
diff --git a/src/pubkey/dlies/dlies.h b/src/pubkey/dlies/dlies.h
index 8e5c05852..9739afeb2 100644
--- a/src/pubkey/dlies/dlies.h
+++ b/src/pubkey/dlies/dlies.h
@@ -27,13 +27,14 @@ class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor
~DLIES_Encryptor();
- void set_other_key(const MemoryRegion<byte>&);
+ void set_other_key(const std::vector<byte>&);
private:
- SecureVector<byte> enc(const byte[], size_t,
- RandomNumberGenerator&) const;
+ std::vector<byte> enc(const byte[], size_t,
+ RandomNumberGenerator&) const;
+
size_t maximum_input_size() const;
- SecureVector<byte> other_key, my_key;
+ std::vector<byte> other_key, my_key;
PK_Key_Agreement ka;
KDF* kdf;
@@ -55,9 +56,9 @@ class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor
~DLIES_Decryptor();
private:
- SecureVector<byte> dec(const byte[], size_t) const;
+ secure_vector<byte> dec(const byte[], size_t) const;
- SecureVector<byte> my_key;
+ std::vector<byte> my_key;
PK_Key_Agreement ka;
KDF* kdf;