aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pk_pad
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pk_pad')
-rw-r--r--src/lib/pk_pad/eme.cpp44
-rw-r--r--src/lib/pk_pad/eme_oaep/oaep.cpp9
-rw-r--r--src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp3
-rw-r--r--src/lib/pk_pad/eme_raw/eme_raw.cpp3
-rw-r--r--src/lib/pk_pad/emsa.cpp83
-rw-r--r--src/lib/pk_pad/emsa.h7
-rw-r--r--src/lib/pk_pad/emsa1/emsa1.cpp3
-rw-r--r--src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp3
-rw-r--r--src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp13
-rw-r--r--src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h2
-rw-r--r--src/lib/pk_pad/emsa_pssr/pssr.cpp9
-rw-r--r--src/lib/pk_pad/emsa_raw/emsa_raw.cpp3
-rw-r--r--src/lib/pk_pad/emsa_x931/emsa_x931.cpp3
-rw-r--r--src/lib/pk_pad/get_pk_pad.cpp38
-rw-r--r--src/lib/pk_pad/info.txt4
-rw-r--r--src/lib/pk_pad/mgf1/mgf1.cpp1
-rw-r--r--src/lib/pk_pad/pad_utils.h44
17 files changed, 142 insertions, 130 deletions
diff --git a/src/lib/pk_pad/eme.cpp b/src/lib/pk_pad/eme.cpp
index 9398b4c83..4804a8a81 100644
--- a/src/lib/pk_pad/eme.cpp
+++ b/src/lib/pk_pad/eme.cpp
@@ -6,9 +6,53 @@
*/
#include <botan/eme.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_EME_OAEP)
+#include <botan/oaep.h>
+#endif
+
+#if defined(BOTAN_HAS_EME_PKCS1v15)
+#include <botan/eme_pkcs.h>
+#endif
+
+#if defined(BOTAN_HAS_EME_RAW)
+#include <botan/eme_raw.h>
+#endif
namespace Botan {
+#define BOTAN_REGISTER_EME(name, maker) BOTAN_REGISTER_T(EME, name, maker)
+#define BOTAN_REGISTER_EME_NOARGS(name) BOTAN_REGISTER_T_NOARGS(EME, name)
+
+#define BOTAN_REGISTER_EME_NAMED_NOARGS(type, name) \
+ BOTAN_REGISTER_NAMED_T(EME, name, type, make_new_T<type>)
+
+#if defined(BOTAN_HAS_EME_OAEP)
+BOTAN_REGISTER_NAMED_T(EME, "OAEP", OAEP, OAEP::make);
+#endif
+
+#if defined(BOTAN_HAS_EME_PKCS1v15)
+BOTAN_REGISTER_EME_NAMED_NOARGS(EME_PKCS1v15, "PKCS1v15");
+#endif
+
+#if defined(BOTAN_HAS_EME_RAW)
+BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw");
+#endif
+
+EME* get_eme(const std::string& algo_spec)
+ {
+ SCAN_Name request(algo_spec);
+
+ if(EME* eme = make_a<EME>(algo_spec))
+ return eme;
+
+ if(request.algo_name() == "Raw")
+ return nullptr; // No padding
+
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
/*
* Encode a message
*/
diff --git a/src/lib/pk_pad/eme_oaep/oaep.cpp b/src/lib/pk_pad/eme_oaep/oaep.cpp
index 871f40142..f214c25d2 100644
--- a/src/lib/pk_pad/eme_oaep/oaep.cpp
+++ b/src/lib/pk_pad/eme_oaep/oaep.cpp
@@ -5,12 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/oaep.h>
#include <botan/mgf1.h>
#include <botan/mem_ops.h>
-
namespace Botan {
OAEP* OAEP::make(const Spec& request)
@@ -20,17 +18,14 @@ OAEP* OAEP::make(const Spec& request)
if(request.arg_count() == 1 ||
(request.arg_count() == 2 && request.arg(1) == "MGF1"))
{
- if(HashFunction* hash = get_hash_function(request.arg(0)))
- return new OAEP(hash);
+ if(auto hash = HashFunction::create(request.arg(0)))
+ return new OAEP(hash.release());
}
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(EME, "OAEP", OAEP, OAEP::make);
-
-
/*
* OAEP Pad Operation
*/
diff --git a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
index 90af17565..65d29cd59 100644
--- a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
+++ b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/eme_pkcs.h>
namespace Botan {
-BOTAN_REGISTER_EME_NAMED_NOARGS(EME_PKCS1v15, "PKCS1v15");
-
/*
* PKCS1 Pad Operation
*/
diff --git a/src/lib/pk_pad/eme_raw/eme_raw.cpp b/src/lib/pk_pad/eme_raw/eme_raw.cpp
index 9ae894c70..78b670b65 100644
--- a/src/lib/pk_pad/eme_raw/eme_raw.cpp
+++ b/src/lib/pk_pad/eme_raw/eme_raw.cpp
@@ -4,14 +4,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/internal/bit_ops.h>
#include <botan/eme_raw.h>
namespace Botan {
-BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw");
-
secure_vector<byte> EME_Raw::pad(const byte in[], size_t in_length,
size_t key_bits,
RandomNumberGenerator&) const
diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp
new file mode 100644
index 000000000..e20286a7d
--- /dev/null
+++ b/src/lib/pk_pad/emsa.cpp
@@ -0,0 +1,83 @@
+/*
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/emsa.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_EMSA1)
+ #include <botan/emsa1.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA1_BSI)
+ #include <botan/emsa1_bsi.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_X931)
+ #include <botan/emsa_x931.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PKCS1)
+ #include <botan/emsa_pkcs1.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PSSR)
+ #include <botan/pssr.h>
+#endif
+
+#if defined(BOTAN_HAS_EMSA_RAW)
+ #include <botan/emsa_raw.h>
+#endif
+
+namespace Botan {
+
+EMSA::~EMSA() {}
+
+EMSA* get_emsa(const std::string& algo_spec)
+ {
+ SCAN_Name request(algo_spec);
+
+ if(EMSA* emsa = make_a<EMSA>(algo_spec))
+ return emsa;
+
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
+#define BOTAN_REGISTER_EMSA_NAMED_NOARGS(type, name) \
+ BOTAN_REGISTER_NAMED_T(EMSA, name, type, make_new_T<type>)
+
+#define BOTAN_REGISTER_EMSA(name, maker) BOTAN_REGISTER_T(EMSA, name, maker)
+#define BOTAN_REGISTER_EMSA_NOARGS(name) BOTAN_REGISTER_T_NOARGS(EMSA, name)
+
+#define BOTAN_REGISTER_EMSA_1HASH(type, name) \
+ BOTAN_REGISTER_NAMED_T(EMSA, name, type, (make_new_T_1X<type, HashFunction>))
+
+#if defined(BOTAN_HAS_EMSA1)
+BOTAN_REGISTER_EMSA_1HASH(EMSA1, "EMSA1");
+#endif
+
+#if defined(BOTAN_HAS_EMSA1_BSI)
+BOTAN_REGISTER_EMSA_1HASH(EMSA1_BSI, "EMSA1_BSI");
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PKCS1)
+BOTAN_REGISTER_NAMED_T(EMSA, "EMSA_PKCS1", EMSA_PCS1v15, EMSA_PKCS1v15::make);
+#endif
+
+#if defined(BOTAN_HAS_EMSA_PSSR)
+BOTAN_REGISTER_NAMED_T(EMSA, "PSSR", PSSR, PSSR::make);
+#endif
+
+#if defined(BOTAN_HAS_EMSA_X931)
+BOTAN_REGISTER_EMSA_1HASH(EMSA_X931, "EMSA_X931");
+#endif
+
+#if defined(BOTAN_HAS_EMSA_RAW)
+BOTAN_REGISTER_EMSA_NAMED_NOARGS(EMSA_Raw, "Raw");
+#endif
+
+}
+
+
diff --git a/src/lib/pk_pad/emsa.h b/src/lib/pk_pad/emsa.h
index b0295636c..d4fd146da 100644
--- a/src/lib/pk_pad/emsa.h
+++ b/src/lib/pk_pad/emsa.h
@@ -15,7 +15,9 @@
namespace Botan {
/**
-* Encoding Method for Signatures, Appendix
+* EMSA, from IEEE 1363s Encoding Method for Signatures, Appendix
+*
+* Any way of encoding/padding signatures
*/
class BOTAN_DLL EMSA
{
@@ -55,7 +57,8 @@ class BOTAN_DLL EMSA
virtual bool verify(const secure_vector<byte>& coded,
const secure_vector<byte>& raw,
size_t key_bits) = 0;
- virtual ~EMSA() {}
+
+ virtual ~EMSA();
};
/**
diff --git a/src/lib/pk_pad/emsa1/emsa1.cpp b/src/lib/pk_pad/emsa1/emsa1.cpp
index 89f0d244a..0031bf263 100644
--- a/src/lib/pk_pad/emsa1/emsa1.cpp
+++ b/src/lib/pk_pad/emsa1/emsa1.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa1.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_1HASH(EMSA1, "EMSA1");
-
namespace {
secure_vector<byte> emsa1_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp b/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
index 81a168b7d..5fc96da8d 100644
--- a/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
+++ b/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
@@ -6,13 +6,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa1_bsi.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_1HASH(EMSA1_BSI, "EMSA1_BSI");
-
/*
* EMSA1 BSI Encode Operation
*/
diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
index e6ce5ec2f..940f91c9a 100644
--- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
+++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
@@ -5,30 +5,23 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa_pkcs1.h>
#include <botan/hash_id.h>
namespace Botan {
-namespace {
-
-EMSA* make_pkcs1v15(const EMSA::Spec& spec)
+EMSA* EMSA_PKCS1v15::make(const EMSA::Spec& spec)
{
if(spec.arg(0) == "Raw")
return new EMSA_PKCS1v15_Raw;
else
{
- if(HashFunction* h = get_hash_function(spec.arg(0)))
- return new EMSA_PKCS1v15(h);
+ if(auto h = HashFunction::create(spec.arg(0)))
+ return new EMSA_PKCS1v15(h.release());
}
return nullptr;
}
-}
-
-BOTAN_REGISTER_NAMED_T(EMSA, "EMSA_PKCS1", EMSA_PCS1v15, make_pkcs1v15);
-
namespace {
secure_vector<byte> emsa3_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
index 7bcae3bd1..19886f80c 100644
--- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
+++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
@@ -21,6 +21,8 @@ namespace Botan {
class BOTAN_DLL EMSA_PKCS1v15 : public EMSA
{
public:
+ static EMSA* make(const EMSA::Spec& spec);
+
/**
* @param hash the hash object to use
*/
diff --git a/src/lib/pk_pad/emsa_pssr/pssr.cpp b/src/lib/pk_pad/emsa_pssr/pssr.cpp
index a4744f8f4..36b0ab64c 100644
--- a/src/lib/pk_pad/emsa_pssr/pssr.cpp
+++ b/src/lib/pk_pad/emsa_pssr/pssr.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/pssr.h>
#include <botan/mgf1.h>
#include <botan/internal/bit_ops.h>
@@ -17,17 +16,15 @@ PSSR* PSSR::make(const Spec& request)
if(request.arg(1, "MGF1") != "MGF1")
return nullptr;
- if(HashFunction* hash = get_hash_function(request.arg(0)))
+ if(auto h = HashFunction::create(request.arg(0)))
{
- const size_t salt_size = request.arg_as_integer(2, hash->output_length());
- return new PSSR(hash, salt_size);
+ const size_t salt_size = request.arg_as_integer(2, h->output_length());
+ return new PSSR(h.release(), salt_size);
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(EMSA, "PSSR", PSSR, PSSR::make);
-
/*
* PSSR Update Operation
*/
diff --git a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
index dcce888f2..4560bd3c3 100644
--- a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
+++ b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa_raw.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_NAMED_NOARGS(EMSA_Raw, "Raw");
-
/*
* EMSA-Raw Encode Operation
*/
diff --git a/src/lib/pk_pad/emsa_x931/emsa_x931.cpp b/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
index fb1e4343a..2feedee1c 100644
--- a/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
+++ b/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
@@ -5,14 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/pad_utils.h>
#include <botan/emsa_x931.h>
#include <botan/hash_id.h>
namespace Botan {
-BOTAN_REGISTER_EMSA_1HASH(EMSA_X931, "EMSA_X931");
-
namespace {
secure_vector<byte> emsa2_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/get_pk_pad.cpp b/src/lib/pk_pad/get_pk_pad.cpp
deleted file mode 100644
index 691de23e2..000000000
--- a/src/lib/pk_pad/get_pk_pad.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-* EMSA/EME Retrieval
-* (C) 1999-2007 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#include <botan/emsa.h>
-#include <botan/eme.h>
-#include <botan/scan_name.h>
-#include <botan/internal/algo_registry.h>
-
-namespace Botan {
-
-EMSA* get_emsa(const std::string& algo_spec)
- {
- SCAN_Name request(algo_spec);
-
- if(EMSA* emsa = make_a<EMSA>(algo_spec))
- return emsa;
-
- throw Algorithm_Not_Found(algo_spec);
- }
-
-EME* get_eme(const std::string& algo_spec)
- {
- SCAN_Name request(algo_spec);
-
- if(EME* eme = make_a<EME>(algo_spec))
- return eme;
-
- if(request.algo_name() == "Raw")
- return nullptr; // No padding
-
- throw Algorithm_Not_Found(algo_spec);
- }
-
-}
diff --git a/src/lib/pk_pad/info.txt b/src/lib/pk_pad/info.txt
index cc3a3fb3b..8cb935faa 100644
--- a/src/lib/pk_pad/info.txt
+++ b/src/lib/pk_pad/info.txt
@@ -10,7 +10,3 @@ rng
eme.h
emsa.h
</header:public>
-
-<header:internal>
-pad_utils.h
-</header:internal>
diff --git a/src/lib/pk_pad/mgf1/mgf1.cpp b/src/lib/pk_pad/mgf1/mgf1.cpp
index 950961f89..34bc4a9a9 100644
--- a/src/lib/pk_pad/mgf1/mgf1.cpp
+++ b/src/lib/pk_pad/mgf1/mgf1.cpp
@@ -7,7 +7,6 @@
#include <botan/mgf1.h>
#include <botan/exceptn.h>
-#include <botan/internal/xor_buf.h>
#include <algorithm>
namespace Botan {
diff --git a/src/lib/pk_pad/pad_utils.h b/src/lib/pk_pad/pad_utils.h
deleted file mode 100644
index 3918e133a..000000000
--- a/src/lib/pk_pad/pad_utils.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-* Public Key Padding Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_PK_PAD_UTILS_H__
-#define BOTAN_PK_PAD_UTILS_H__
-
-#include <botan/internal/algo_registry.h>
-#include <botan/internal/xor_buf.h>
-#include <botan/loadstor.h>
-#include <algorithm>
-
-namespace Botan {
-
-#define BOTAN_REGISTER_EME(name, maker) BOTAN_REGISTER_T(EME, name, maker)
-#define BOTAN_REGISTER_EME_NOARGS(name) BOTAN_REGISTER_T_NOARGS(EME, name)
-
-#define BOTAN_REGISTER_EME_NAMED_NOARGS(type, name) \
- BOTAN_REGISTER_NAMED_T(EME, name, type, make_new_T<type>)
-
-#define BOTAN_REGISTER_EMSA_1HASH_1LEN(type, name) \
- BOTAN_REGISTER_NAMED_T(EMSA, name, type, (make_new_T_1X_1len<type, HashFunction>))
-
-#define BOTAN_REGISTER_EME_NAMED_1LEN(type, name, def) \
- BOTAN_REGISTER_NAMED_T(EME, name, type, (make_new_T_1len<type,def>))
-#define BOTAN_REGISTER_EME_NAMED_1STR(type, name, def) \
- BOTAN_REGISTER_NAMED_T(EME, name, type, \
- std::bind(make_new_T_1str<type>, std::placeholders::_1, def));
-
-#define BOTAN_REGISTER_EMSA_NAMED_NOARGS(type, name) \
- BOTAN_REGISTER_NAMED_T(EMSA, name, type, make_new_T<type>)
-
-#define BOTAN_REGISTER_EMSA(name, maker) BOTAN_REGISTER_T(EMSA, name, maker)
-#define BOTAN_REGISTER_EMSA_NOARGS(name) BOTAN_REGISTER_T_NOARGS(EMSA, name)
-
-#define BOTAN_REGISTER_EMSA_1HASH(type, name) \
- BOTAN_REGISTER_NAMED_T(EMSA, name, type, (make_new_T_1X<type, HashFunction>))
-
-}
-
-#endif