aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pk_pad
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-31 16:18:09 +0000
committerlloyd <[email protected]>2015-01-31 16:18:09 +0000
commitfd3016d10124d2b7ccd7bc885235f2e407d73800 (patch)
treee237b54c3a8d465c893a012157d9d52014eaccc9 /src/lib/pk_pad
parent00c9b3f4834603946065c15b9b2e9fa5e973b979 (diff)
Use registry also for KDF, EMSA, and EME
Diffstat (limited to 'src/lib/pk_pad')
-rw-r--r--src/lib/pk_pad/eme.h3
-rw-r--r--src/lib/pk_pad/eme_oaep/oaep.cpp22
-rw-r--r--src/lib/pk_pad/eme_oaep/oaep.h2
-rw-r--r--src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp3
-rw-r--r--src/lib/pk_pad/emsa.h3
-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.cpp4
-rw-r--r--src/lib/pk_pad/emsa_pssr/pssr.cpp19
-rw-r--r--src/lib/pk_pad/emsa_pssr/pssr.h2
-rw-r--r--src/lib/pk_pad/emsa_raw/emsa_raw.cpp3
-rw-r--r--src/lib/pk_pad/emsa_x931/emsa_x931.cpp4
-rw-r--r--src/lib/pk_pad/get_pk_pad.cpp116
-rw-r--r--src/lib/pk_pad/info.txt9
14 files changed, 84 insertions, 112 deletions
diff --git a/src/lib/pk_pad/eme.h b/src/lib/pk_pad/eme.h
index 3c82a8b69..7318ec480 100644
--- a/src/lib/pk_pad/eme.h
+++ b/src/lib/pk_pad/eme.h
@@ -8,6 +8,7 @@
#ifndef BOTAN_PUBKEY_EME_ENCRYPTION_PAD_H__
#define BOTAN_PUBKEY_EME_ENCRYPTION_PAD_H__
+#include <botan/scan_name.h>
#include <botan/secmem.h>
#include <botan/rng.h>
@@ -19,6 +20,8 @@ namespace Botan {
class BOTAN_DLL EME
{
public:
+ typedef SCAN_Name Spec;
+
/**
* Return the maximum input size in bytes we can support
* @param keybits the size of the key in bits
diff --git a/src/lib/pk_pad/eme_oaep/oaep.cpp b/src/lib/pk_pad/eme_oaep/oaep.cpp
index 0922b8d5a..dc9266ee7 100644
--- a/src/lib/pk_pad/eme_oaep/oaep.cpp
+++ b/src/lib/pk_pad/eme_oaep/oaep.cpp
@@ -5,12 +5,34 @@
* 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)
+ {
+ if(request.algo_name() == "OAEP" && request.arg_count_between(1, 2))
+ {
+ auto& hashes = Algo_Registry<HashFunction>::global_registry();
+
+ if(request.arg_count() == 1 ||
+ (request.arg_count() == 2 && request.arg(1) == "MGF1"))
+ {
+ if(HashFunction* hash = hashes.make(request.arg(0)))
+ return new OAEP(hash);
+ }
+ }
+
+ return nullptr;
+ }
+
+BOTAN_REGISTER_NAMED_T(EME, "OAEP", OAEP, OAEP::make);
+
+
/*
* OAEP Pad Operation
*/
diff --git a/src/lib/pk_pad/eme_oaep/oaep.h b/src/lib/pk_pad/eme_oaep/oaep.h
index 293b4a45d..6765a67e2 100644
--- a/src/lib/pk_pad/eme_oaep/oaep.h
+++ b/src/lib/pk_pad/eme_oaep/oaep.h
@@ -22,6 +22,8 @@ class BOTAN_DLL OAEP : public EME
public:
size_t maximum_input_size(size_t) const;
+ static OAEP* make(const Spec& spec);
+
/**
* @param hash object to use for hashing (takes ownership)
* @param P an optional label. Normally empty.
diff --git a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
index beec40532..d279b8843 100644
--- a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
+++ b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
@@ -5,10 +5,13 @@
* 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/emsa.h b/src/lib/pk_pad/emsa.h
index 8d09e2c89..b0295636c 100644
--- a/src/lib/pk_pad/emsa.h
+++ b/src/lib/pk_pad/emsa.h
@@ -8,6 +8,7 @@
#ifndef BOTAN_PUBKEY_EMSA_H__
#define BOTAN_PUBKEY_EMSA_H__
+#include <botan/scan_name.h>
#include <botan/secmem.h>
#include <botan/rng.h>
@@ -19,6 +20,8 @@ namespace Botan {
class BOTAN_DLL EMSA
{
public:
+ typedef SCAN_Name Spec;
+
/**
* Add more data to the signature computation
* @param input some data
diff --git a/src/lib/pk_pad/emsa1/emsa1.cpp b/src/lib/pk_pad/emsa1/emsa1.cpp
index 0031bf263..89f0d244a 100644
--- a/src/lib/pk_pad/emsa1/emsa1.cpp
+++ b/src/lib/pk_pad/emsa1/emsa1.cpp
@@ -5,10 +5,13 @@
* 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 5fc96da8d..81a168b7d 100644
--- a/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
+++ b/src/lib/pk_pad/emsa1_bsi/emsa1_bsi.cpp
@@ -6,10 +6,13 @@
* 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 6ce3d4e73..6f6cf22b8 100644
--- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
+++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp
@@ -5,11 +5,13 @@
* 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 {
+BOTAN_REGISTER_EMSA_1HASH(EMSA_PKCS1v15, "PKCS1v15");
+
namespace {
secure_vector<byte> emsa3_encoding(const secure_vector<byte>& msg,
diff --git a/src/lib/pk_pad/emsa_pssr/pssr.cpp b/src/lib/pk_pad/emsa_pssr/pssr.cpp
index a7e5de6f1..3f93ca79d 100644
--- a/src/lib/pk_pad/emsa_pssr/pssr.cpp
+++ b/src/lib/pk_pad/emsa_pssr/pssr.cpp
@@ -5,13 +5,30 @@
* 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>
-#include <botan/internal/xor_buf.h>
namespace Botan {
+PSSR* PSSR::make(const Spec& request)
+ {
+ if(request.arg(1, "MGF1") != "MGF1")
+ return nullptr;
+
+ auto hash = make_a<HashFunction>(request.arg(0));
+
+ if(!hash)
+ return nullptr;
+
+ const size_t salt_size = request.arg_as_integer(2, hash->output_length());
+
+ return new PSSR(hash, salt_size);
+ }
+
+BOTAN_REGISTER_NAMED_T(EMSA, "PSSR", PSSR, PSSR::make);
+
/*
* PSSR Update Operation
*/
diff --git a/src/lib/pk_pad/emsa_pssr/pssr.h b/src/lib/pk_pad/emsa_pssr/pssr.h
index b5a4e393f..e51ade494 100644
--- a/src/lib/pk_pad/emsa_pssr/pssr.h
+++ b/src/lib/pk_pad/emsa_pssr/pssr.h
@@ -30,6 +30,8 @@ class BOTAN_DLL PSSR : public EMSA
* @param salt_size the size of the salt to use in bytes
*/
PSSR(HashFunction* hash, size_t salt_size);
+
+ static PSSR* make(const Spec& spec);
private:
void update(const byte input[], size_t length);
diff --git a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
index 66a5a55d5..8b5fd71fa 100644
--- a/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
+++ b/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
@@ -5,10 +5,13 @@
* 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 f78bcd430..cda3b22dd 100644
--- a/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
+++ b/src/lib/pk_pad/emsa_x931/emsa_x931.cpp
@@ -5,11 +5,13 @@
* 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
index b7df17158..e64c4e9d8 100644
--- a/src/lib/pk_pad/get_pk_pad.cpp
+++ b/src/lib/pk_pad/get_pk_pad.cpp
@@ -8,133 +8,31 @@
#include <botan/emsa.h>
#include <botan/eme.h>
#include <botan/scan_name.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
-
-#if defined(BOTAN_HAS_EME_OAEP)
- #include <botan/oaep.h>
-#endif
-
-#if defined(BOTAN_HAS_EME_PKCS1v15)
- #include <botan/eme_pkcs.h>
-#endif
+#include <botan/algo_registry.h>
namespace Botan {
-/*
-* Get an EMSA by name
-*/
EMSA* get_emsa(const std::string& algo_spec)
{
SCAN_Name request(algo_spec);
- auto& hashes = Algo_Registry<HashFunction>::global_registry();
-
-#if defined(BOTAN_HAS_EMSA_RAW)
- if(request.algo_name() == "Raw" && request.arg_count() == 0)
- return new EMSA_Raw;
-#endif
-
- if(request.algo_name() == "EMSA1" && request.arg_count() == 1)
- {
-#if defined(BOTAN_HAS_EMSA_RAW)
- if(request.arg(0) == "Raw")
- return new EMSA_Raw;
-#endif
-
-#if defined(BOTAN_HAS_EMSA1)
- return new EMSA1(hashes.make(request.arg(0)));
-#endif
- }
-
-#if defined(BOTAN_HAS_EMSA1_BSI)
- if(request.algo_name() == "EMSA1_BSI" && request.arg_count() == 1)
- return new EMSA1_BSI(hashes.make(request.arg(0)));
-#endif
-
-#if defined(BOTAN_HAS_EMSA_X931)
- if(request.algo_name() == "EMSA_X931" && request.arg_count() == 1)
- return new EMSA_X931(hashes.make(request.arg(0)));
-#endif
-
-#if defined(BOTAN_HAS_EMSA_PKCS1)
- if(request.algo_name() == "EMSA_PKCS1" && request.arg_count() == 1)
- {
- if(request.arg(0) == "Raw")
- return new EMSA_PKCS1v15_Raw;
- return new EMSA_PKCS1v15(hashes.make(request.arg(0)));
- }
-#endif
-
-#if defined(BOTAN_HAS_EMSA_PSSR)
- if(request.algo_name() == "PSSR" && request.arg_count_between(1, 3))
- {
- // 3 args: Hash, MGF, salt size (MGF is hardcoded MGF1 in Botan)
- if(request.arg_count() == 1)
- return new PSSR(hashes.make(request.arg(0)));
-
- if(request.arg_count() == 2 && request.arg(1) != "MGF1")
- return new PSSR(hashes.make(request.arg(0)));
-
- if(request.arg_count() == 3)
- return new PSSR(hashes.make(request.arg(0)),
- request.arg_as_integer(2, 0));
- }
-#endif
+ if(EMSA* emsa = make_a<EMSA>(algo_spec))
+ return emsa;
+ printf("EMSA missing? %s\n", algo_spec.c_str());
throw Algorithm_Not_Found(algo_spec);
}
-/*
-* Get an EME by name
-*/
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
-#if defined(BOTAN_HAS_EME_PKCS1v15)
- if(request.algo_name() == "PKCS1v15" && request.arg_count() == 0)
- return new EME_PKCS1v15;
-#endif
-
-#if defined(BOTAN_HAS_EME_OAEP)
- if(request.algo_name() == "OAEP" && request.arg_count_between(1, 2))
- {
- auto& hashes = Algo_Registry<HashFunction>::global_registry();
-
- if(request.arg_count() == 1 ||
- (request.arg_count() == 2 && request.arg(1) == "MGF1"))
- {
- return new OAEP(hashes.make(request.arg(0)));
- }
- }
-#endif
-
throw Algorithm_Not_Found(algo_spec);
}
diff --git a/src/lib/pk_pad/info.txt b/src/lib/pk_pad/info.txt
index 5c6a9e4a7..d77e1defd 100644
--- a/src/lib/pk_pad/info.txt
+++ b/src/lib/pk_pad/info.txt
@@ -6,3 +6,12 @@ load_on auto
alloc
rng
</requires>
+
+<header:public>
+eme.h
+emsa.h
+</header:public>
+
+<header:internal>
+pad_utils.h
+</header:internal>