diff options
author | Jack Lloyd <[email protected]> | 2016-10-11 13:00:57 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-10-21 16:53:16 -0400 |
commit | 558808900bffc3c48da5e6d79ba602e88e619154 (patch) | |
tree | fd76ee2d009c2b707d888683cbd767351c4ff6b3 /src/lib/pk_pad | |
parent | 6aa855bba613c7b6fedfbe71d15930964acb1633 (diff) |
Remove Algo_Registry
I repent my use of global constructors.
I repent my use of global locks.
Hopefully I will never touch this code again.
:)
Diffstat (limited to 'src/lib/pk_pad')
-rw-r--r-- | src/lib/pk_pad/eme.cpp | 36 | ||||
-rw-r--r-- | src/lib/pk_pad/eme.h | 3 | ||||
-rw-r--r-- | src/lib/pk_pad/eme_oaep/oaep.cpp | 15 | ||||
-rw-r--r-- | src/lib/pk_pad/eme_oaep/oaep.h | 2 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa.cpp | 90 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa.h | 3 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp | 12 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h | 2 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa_pssr/pssr.cpp | 14 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa_pssr/pssr.h | 2 |
10 files changed, 74 insertions, 105 deletions
diff --git a/src/lib/pk_pad/eme.cpp b/src/lib/pk_pad/eme.cpp index b36ed6e67..fa569d8e4 100644 --- a/src/lib/pk_pad/eme.cpp +++ b/src/lib/pk_pad/eme.cpp @@ -6,7 +6,7 @@ */ #include <botan/eme.h> -#include <botan/internal/algo_registry.h> +#include <botan/scan_name.h> #if defined(BOTAN_HAS_EME_OAEP) #include <botan/oaep.h> @@ -22,34 +22,32 @@ 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>) +EME* get_eme(const std::string& algo_spec) + { + SCAN_Name req(algo_spec); #if defined(BOTAN_HAS_EME_OAEP) -BOTAN_REGISTER_NAMED_T(EME, "OAEP", OAEP, OAEP::make); + if(req.algo_name() == "OAEP" && req.arg_count_between(1, 2)) + { + if(req.arg_count() == 1 || + (req.arg_count() == 2 && req.arg(1) == "MGF1")) + { + if(auto hash = HashFunction::create(req.arg(0))) + return new OAEP(hash.release()); + } + } #endif #if defined(BOTAN_HAS_EME_PKCS1v15) -BOTAN_REGISTER_EME_NAMED_NOARGS(EME_PKCS1v15, "PKCS1v15"); + if(req.algo_name() == "PKCS1v15" && req.arg_count() == 0) + return new EME_PKCS1v15; #endif #if defined(BOTAN_HAS_EME_RAW) -BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw"); + if(req.algo_name() == "Raw" && req.arg_count() == 0) + return new EME_Raw; #endif -EME* get_eme(const std::string& algo_spec) - { - SCAN_Name request(algo_spec); - - if(EME* eme = make_a<EME>(Botan::EME::Spec(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/eme.h b/src/lib/pk_pad/eme.h index 9c72cb023..a5ad27b4e 100644 --- a/src/lib/pk_pad/eme.h +++ b/src/lib/pk_pad/eme.h @@ -8,7 +8,6 @@ #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> @@ -20,8 +19,6 @@ namespace Botan { class BOTAN_DLL EME { public: - typedef SCAN_Name Spec; - virtual ~EME() = default; /** diff --git a/src/lib/pk_pad/eme_oaep/oaep.cpp b/src/lib/pk_pad/eme_oaep/oaep.cpp index 1ae1068a7..81d41afea 100644 --- a/src/lib/pk_pad/eme_oaep/oaep.cpp +++ b/src/lib/pk_pad/eme_oaep/oaep.cpp @@ -11,21 +11,6 @@ namespace Botan { -OAEP* OAEP::make(const Spec& request) - { - if(request.algo_name() == "OAEP" && request.arg_count_between(1, 2)) - { - if(request.arg_count() == 1 || - (request.arg_count() == 2 && request.arg(1) == "MGF1")) - { - if(auto hash = HashFunction::create(request.arg(0))) - return new OAEP(hash.release()); - } - } - - return nullptr; - } - /* * OAEP Pad Operation */ diff --git a/src/lib/pk_pad/eme_oaep/oaep.h b/src/lib/pk_pad/eme_oaep/oaep.h index 2a0f0f28c..3e476f6a3 100644 --- a/src/lib/pk_pad/eme_oaep/oaep.h +++ b/src/lib/pk_pad/eme_oaep/oaep.h @@ -21,8 +21,6 @@ class BOTAN_DLL OAEP final : public EME public: size_t maximum_input_size(size_t) const override; - static OAEP* make(const Spec& spec); - /** * @param hash function to use for hashing (takes ownership) * @param P an optional label. Normally empty. diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp index 4d4b96ad1..c091319e2 100644 --- a/src/lib/pk_pad/emsa.cpp +++ b/src/lib/pk_pad/emsa.cpp @@ -5,7 +5,7 @@ */ #include <botan/emsa.h> -#include <botan/internal/algo_registry.h> +#include <botan/scan_name.h> #if defined(BOTAN_HAS_EMSA1) #include <botan/emsa1.h> @@ -33,10 +33,63 @@ EMSA::~EMSA() {} EMSA* get_emsa(const std::string& algo_spec) { - SCAN_Name request(algo_spec); + SCAN_Name req(algo_spec); - if(EMSA* emsa = make_a<EMSA>(Botan::EMSA::Spec(algo_spec))) - return emsa; +#if defined(BOTAN_HAS_EMSA1) + if(req.algo_name() == "EMSA1" && req.arg_count() == 1) + { + if(auto hash = HashFunction::create(req.arg(0))) + return new EMSA1(hash.release()); + } +#endif + +#if defined(BOTAN_HAS_EMSA_PKCS1) + if(req.algo_name() == "EMSA_PKCS1" && req.arg_count() == 1) + { + if(req.arg(0) == "Raw") + { + return new EMSA_PKCS1v15_Raw; + } + else + { + if(auto hash = HashFunction::create(req.arg(0))) + { + return new EMSA_PKCS1v15(hash.release()); + } + } + } +#endif + +#if defined(BOTAN_HAS_EMSA_PSSR) + if(req.algo_name() == "PSSR") + { + if(req.arg(1, "MGF1") != "MGF1") + return nullptr; // not supported + + if(auto h = HashFunction::create(req.arg(0))) + { + const size_t salt_size = req.arg_as_integer(2, h->output_length()); + return new PSSR(h.release(), salt_size); + } + } +#endif + +#if defined(BOTAN_HAS_EMSA_X931) + if(req.algo_name() == "EMSA_X931" && req.arg_count() == 1) + { + if(auto hash = HashFunction::create(req.arg(0))) + { + return new EMSA_X931(hash.release()); + } + } +#endif + +#if defined(BOTAN_HAS_EMSA_RAW) + if(req.algo_name() == "Raw" && req.arg_count() == 0) + { + return new EMSA_Raw; + } +#endif throw Algorithm_Not_Found(algo_spec); } @@ -54,35 +107,6 @@ std::string hash_for_emsa(const std::string& algo_spec) return "SHA-512"; // safe default if nothing we understand } -#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_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 8e8720a66..bc930ae22 100644 --- a/src/lib/pk_pad/emsa.h +++ b/src/lib/pk_pad/emsa.h @@ -8,7 +8,6 @@ #ifndef BOTAN_PUBKEY_EMSA_H__ #define BOTAN_PUBKEY_EMSA_H__ -#include <botan/scan_name.h> #include <botan/secmem.h> #include <botan/rng.h> @@ -22,8 +21,6 @@ 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/emsa_pkcs1/emsa_pkcs1.cpp b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp index e990ef8af..b3f74930b 100644 --- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp +++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp @@ -10,18 +10,6 @@ namespace Botan { -EMSA* EMSA_PKCS1v15::make(const EMSA::Spec& spec) - { - if(spec.arg(0) == "Raw") - return new EMSA_PKCS1v15_Raw; - else - { - if(auto h = HashFunction::create(spec.arg(0))) - return new EMSA_PKCS1v15(h.release()); - } - return nullptr; - } - 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 917f03ac8..65daaf7ce 100644 --- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h +++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h @@ -21,8 +21,6 @@ namespace Botan { class BOTAN_DLL EMSA_PKCS1v15 final : public EMSA { public: - static EMSA* make(const EMSA::Spec& spec); - /** * @param hash the hash function to use */ diff --git a/src/lib/pk_pad/emsa_pssr/pssr.cpp b/src/lib/pk_pad/emsa_pssr/pssr.cpp index ddd8c5f0b..a41e79e78 100644 --- a/src/lib/pk_pad/emsa_pssr/pssr.cpp +++ b/src/lib/pk_pad/emsa_pssr/pssr.cpp @@ -11,20 +11,6 @@ namespace Botan { -PSSR* PSSR::make(const Spec& request) - { - if(request.arg(1, "MGF1") != "MGF1") - return nullptr; - - if(auto h = HashFunction::create(request.arg(0))) - { - const size_t salt_size = request.arg_as_integer(2, h->output_length()); - return new PSSR(h.release(), salt_size); - } - - return nullptr; - } - /* * PSSR Update Operation */ diff --git a/src/lib/pk_pad/emsa_pssr/pssr.h b/src/lib/pk_pad/emsa_pssr/pssr.h index fa8687fee..bf465eadf 100644 --- a/src/lib/pk_pad/emsa_pssr/pssr.h +++ b/src/lib/pk_pad/emsa_pssr/pssr.h @@ -32,8 +32,6 @@ class BOTAN_DLL PSSR final : public EMSA PSSR(HashFunction* hash, size_t salt_size); EMSA* clone() override { return new PSSR(m_hash->clone(), m_SALT_SIZE); } - - static PSSR* make(const Spec& spec); private: void update(const byte input[], size_t length) override; |