aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/pubkey/mce/mce_kem.cpp74
-rw-r--r--src/lib/pubkey/mce/mceliece_key.cpp65
2 files changed, 65 insertions, 74 deletions
diff --git a/src/lib/pubkey/mce/mce_kem.cpp b/src/lib/pubkey/mce/mce_kem.cpp
deleted file mode 100644
index b2cefaab2..000000000
--- a/src/lib/pubkey/mce/mce_kem.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
-* (C) 2014 cryptosource GmbH
-* (C) 2014 Falko Strenzke [email protected]
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*
-*/
-
-#include <botan/internal/mce_internal.h>
-#include <botan/internal/pk_ops_impl.h>
-#include <botan/internal/pk_utils.h>
-
-namespace Botan {
-
-class MCE_KEM_Encryptor : public PK_Ops::KEM_Encryption_with_KDF
- {
- public:
- typedef McEliece_PublicKey Key_Type;
-
- MCE_KEM_Encryptor(const McEliece_PublicKey& key,
- const std::string& kdf) :
- KEM_Encryption_with_KDF(kdf), m_key(key) {}
-
- private:
- void raw_kem_encrypt(secure_vector<byte>& out_encapsulated_key,
- secure_vector<byte>& raw_shared_key,
- Botan::RandomNumberGenerator& rng) override
- {
- secure_vector<byte> plaintext = m_key.random_plaintext_element(rng);
-
- secure_vector<byte> ciphertext, error_mask;
- mceliece_encrypt(ciphertext, error_mask, plaintext, m_key, rng);
-
- raw_shared_key.clear();
- raw_shared_key += plaintext;
- raw_shared_key += error_mask;
-
- out_encapsulated_key.swap(ciphertext);
- }
-
- const McEliece_PublicKey& m_key;
- };
-
-class MCE_KEM_Decryptor : public PK_Ops::KEM_Decryption_with_KDF
- {
- public:
- typedef McEliece_PrivateKey Key_Type;
-
- MCE_KEM_Decryptor(const McEliece_PrivateKey& key,
- const std::string& kdf) :
- KEM_Decryption_with_KDF(kdf), m_key(key) {}
-
- private:
- secure_vector<byte>
- raw_kem_decrypt(const byte encap_key[], size_t len) override
- {
- secure_vector<byte> plaintext, error_mask;
- mceliece_decrypt(plaintext, error_mask, encap_key, len, m_key);
-
- secure_vector<byte> output;
- output.reserve(plaintext.size() + error_mask.size());
- output.insert(output.end(), plaintext.begin(), plaintext.end());
- output.insert(output.end(), error_mask.begin(), error_mask.end());
- return output;
- }
-
- const McEliece_PrivateKey& m_key;
- };
-
-BOTAN_REGISTER_PK_KEM_ENCRYPTION_OP("McEliece", MCE_KEM_Encryptor);
-BOTAN_REGISTER_PK_KEM_DECRYPTION_OP("McEliece", MCE_KEM_Decryptor);
-
-}
diff --git a/src/lib/pubkey/mce/mceliece_key.cpp b/src/lib/pubkey/mce/mceliece_key.cpp
index 8edbbf88a..455d1f381 100644
--- a/src/lib/pubkey/mce/mceliece_key.cpp
+++ b/src/lib/pubkey/mce/mceliece_key.cpp
@@ -4,6 +4,7 @@
*
* (C) 2014 cryptosource GmbH
* (C) 2014 Falko Strenzke [email protected]
+ * (C) 2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*
@@ -13,6 +14,8 @@
#include <botan/internal/mce_internal.h>
#include <botan/internal/bit_ops.h>
#include <botan/internal/code_based_util.h>
+#include <botan/internal/pk_ops_impl.h>
+#include <botan/internal/pk_utils.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
@@ -292,6 +295,68 @@ bool McEliece_PublicKey::operator==(const McEliece_PublicKey& other) const
return true;
}
+namespace {
+
+class MCE_KEM_Encryptor : public PK_Ops::KEM_Encryption_with_KDF
+ {
+ public:
+ typedef McEliece_PublicKey Key_Type;
+
+ MCE_KEM_Encryptor(const McEliece_PublicKey& key,
+ const std::string& kdf) :
+ KEM_Encryption_with_KDF(kdf), m_key(key) {}
+
+ private:
+ void raw_kem_encrypt(secure_vector<byte>& out_encapsulated_key,
+ secure_vector<byte>& raw_shared_key,
+ Botan::RandomNumberGenerator& rng) override
+ {
+ secure_vector<byte> plaintext = m_key.random_plaintext_element(rng);
+
+ secure_vector<byte> ciphertext, error_mask;
+ mceliece_encrypt(ciphertext, error_mask, plaintext, m_key, rng);
+
+ raw_shared_key.clear();
+ raw_shared_key += plaintext;
+ raw_shared_key += error_mask;
+
+ out_encapsulated_key.swap(ciphertext);
+ }
+
+ const McEliece_PublicKey& m_key;
+ };
+
+class MCE_KEM_Decryptor : public PK_Ops::KEM_Decryption_with_KDF
+ {
+ public:
+ typedef McEliece_PrivateKey Key_Type;
+
+ MCE_KEM_Decryptor(const McEliece_PrivateKey& key,
+ const std::string& kdf) :
+ KEM_Decryption_with_KDF(kdf), m_key(key) {}
+
+ private:
+ secure_vector<byte>
+ raw_kem_decrypt(const byte encap_key[], size_t len) override
+ {
+ secure_vector<byte> plaintext, error_mask;
+ mceliece_decrypt(plaintext, error_mask, encap_key, len, m_key);
+
+ secure_vector<byte> output;
+ output.reserve(plaintext.size() + error_mask.size());
+ output.insert(output.end(), plaintext.begin(), plaintext.end());
+ output.insert(output.end(), error_mask.begin(), error_mask.end());
+ return output;
+ }
+
+ const McEliece_PrivateKey& m_key;
+ };
+
+BOTAN_REGISTER_PK_KEM_ENCRYPTION_OP("McEliece", MCE_KEM_Encryptor);
+BOTAN_REGISTER_PK_KEM_DECRYPTION_OP("McEliece", MCE_KEM_Decryptor);
+
+}
+
}