aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/ecies
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-07-17 11:07:23 -0400
committerJack Lloyd <[email protected]>2016-07-17 11:07:23 -0400
commit6b642492f956aa05232701f9506d09ebc887e256 (patch)
treec7017f637d98f19bdbabe39d35355200ac6c116e /src/lib/pubkey/ecies
parent471d883cb8d2c52e969bc13b9ec76759da1cccdc (diff)
parent2c5aa12e843db35365e77d8db750658b76bb894d (diff)
Merge GH #535 Use Cipher_Mode instead of Pipe in ECIES
Diffstat (limited to 'src/lib/pubkey/ecies')
-rw-r--r--src/lib/pubkey/ecies/ecies.cpp37
-rw-r--r--src/lib/pubkey/ecies/ecies.h4
-rw-r--r--src/lib/pubkey/ecies/info.txt1
3 files changed, 20 insertions, 22 deletions
diff --git a/src/lib/pubkey/ecies/ecies.cpp b/src/lib/pubkey/ecies/ecies.cpp
index 0efdc64e1..59f7c9eca 100644
--- a/src/lib/pubkey/ecies/ecies.cpp
+++ b/src/lib/pubkey/ecies/ecies.cpp
@@ -1,13 +1,13 @@
/*
* ECIES
* (C) 2016 Philipp Weber
+* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/ecies.h>
#include <botan/cipher_mode.h>
-#include <botan/pipe.h>
#include <botan/internal/ct_utils.h>
#include <botan/internal/pk_utils.h>
@@ -217,14 +217,14 @@ std::unique_ptr<MessageAuthenticationCode> ECIES_System_Params::create_mac() con
return mac;
}
-std::unique_ptr<Keyed_Filter> ECIES_System_Params::create_cipher(Botan::Cipher_Dir direction) const
+std::unique_ptr<Cipher_Mode> ECIES_System_Params::create_cipher(Botan::Cipher_Dir direction) const
{
- Keyed_Filter* cipher = get_cipher(m_dem_spec, direction);
+ Cipher_Mode* cipher = get_cipher_mode(m_dem_spec, direction);
if(cipher == nullptr)
{
throw Algorithm_Not_Found(m_dem_spec);
}
- return std::unique_ptr<Keyed_Filter>(cipher);
+ return std::unique_ptr<Cipher_Mode>(cipher);
}
@@ -270,17 +270,16 @@ std::vector<byte> ECIES_Encryptor::enc(const byte data[], size_t length, RandomN
const SymmetricKey secret_key = m_ka.derive_secret(m_eph_public_key_bin, m_other_point);
// encryption
- std::unique_ptr<Keyed_Filter> cipher = m_params.create_cipher(ENCRYPTION);
+ std::unique_ptr<Cipher_Mode> cipher = m_params.create_cipher(ENCRYPTION);
BOTAN_ASSERT(cipher != nullptr, "Cipher is found");
cipher->set_key(SymmetricKey(secret_key.begin(), m_params.dem_keylen()));
if(m_iv.size() != 0)
{
- cipher->set_iv(m_iv);
+ cipher->start(m_iv.bits_of());
}
- Pipe pipe(cipher.release());
- pipe.process_msg(data, length);
- const secure_vector<byte> encrypted_data = pipe.read_all(0);
+ secure_vector<byte> encrypted_data(data, data + length);
+ cipher->finish(encrypted_data);
// concat elements
std::unique_ptr<MessageAuthenticationCode> mac = m_params.create_mac();
@@ -371,28 +370,28 @@ secure_vector<byte> ECIES_Decryptor::do_decrypt(byte& valid_mask, const byte in[
if(valid_mask)
{
// decrypt data
- std::unique_ptr<Keyed_Filter> cipher = m_params.create_cipher(DECRYPTION);
+ std::unique_ptr<Cipher_Mode> cipher = m_params.create_cipher(DECRYPTION);
BOTAN_ASSERT(cipher != nullptr, "Cipher is found");
cipher->set_key(SymmetricKey(secret_key.begin(), m_params.dem_keylen()));
if(m_iv.size() != 0)
{
- cipher->set_iv(m_iv);
+ cipher->start(m_iv.bits_of());
}
-
+
try
{
- // the decryption can fail:
- // e.g. Integrity_Failure is thrown if GCM is used and the message does not have a valid tag
- Pipe pipe(cipher.release());
- pipe.process_msg(encrypted_data);
- return pipe.read_all(0);
+ // the decryption can fail:
+ // e.g. Integrity_Failure is thrown if GCM is used and the message does not have a valid tag
+ secure_vector<byte> decrypted_data(encrypted_data.begin(), encrypted_data.end());
+ cipher->finish(decrypted_data);
+ return decrypted_data;
}
catch(...)
{
- valid_mask = 0;
+ valid_mask = 0;
}
- }
+ }
return secure_vector<byte>();
}
diff --git a/src/lib/pubkey/ecies/ecies.h b/src/lib/pubkey/ecies/ecies.h
index 34c2850aa..1008473c9 100644
--- a/src/lib/pubkey/ecies/ecies.h
+++ b/src/lib/pubkey/ecies/ecies.h
@@ -11,7 +11,7 @@
#include <botan/ecdh.h>
#include <botan/ec_group.h>
#include <botan/kdf.h>
-#include <botan/key_filt.h>
+#include <botan/cipher_mode.h>
#include <botan/mac.h>
#include <botan/point_gfp.h>
#include <botan/pubkey.h>
@@ -150,7 +150,7 @@ class BOTAN_DLL ECIES_System_Params : public ECIES_KA_Params
std::unique_ptr<MessageAuthenticationCode> create_mac() const;
/// creates an instance of the data encryption method
- std::unique_ptr<Keyed_Filter> create_cipher(Botan::Cipher_Dir direction) const;
+ std::unique_ptr<Cipher_Mode> create_cipher(Botan::Cipher_Dir direction) const;
/// returns the length of the key used by the data encryption method
inline size_t dem_keylen() const
diff --git a/src/lib/pubkey/ecies/info.txt b/src/lib/pubkey/ecies/info.txt
index dacefc88a..12776f8c2 100644
--- a/src/lib/pubkey/ecies/info.txt
+++ b/src/lib/pubkey/ecies/info.txt
@@ -5,5 +5,4 @@ kdf
mac
ecdh
modes
-filters
</requires> \ No newline at end of file