diff options
author | Jack Lloyd <[email protected]> | 2016-10-17 06:05:37 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-10-21 16:53:17 -0400 |
commit | df64fb318acbfee7911bee4fd021100f1d6532ed (patch) | |
tree | 20238e6f96c7d6e31539389c398255850177d970 /src/lib/pk_pad | |
parent | 558808900bffc3c48da5e6d79ba602e88e619154 (diff) |
Remove alias logic from SCAN_Name
This required taking a global lock and doing a map lookup each
time an algorithm was requested (and so many times during a TLS
handshake).
Diffstat (limited to 'src/lib/pk_pad')
-rw-r--r-- | src/lib/pk_pad/eme.cpp | 26 | ||||
-rw-r--r-- | src/lib/pk_pad/emsa.cpp | 52 |
2 files changed, 48 insertions, 30 deletions
diff --git a/src/lib/pk_pad/eme.cpp b/src/lib/pk_pad/eme.cpp index fa569d8e4..eab9862af 100644 --- a/src/lib/pk_pad/eme.cpp +++ b/src/lib/pk_pad/eme.cpp @@ -24,10 +24,22 @@ namespace Botan { EME* get_eme(const std::string& algo_spec) { - SCAN_Name req(algo_spec); +#if defined(BOTAN_HAS_EME_RAW) + if(algo_spec == "Raw") + return new EME_Raw; +#endif + +#if defined(BOTAN_HAS_EME_PKCS1v15) + if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5") + return new EME_PKCS1v15; +#endif #if defined(BOTAN_HAS_EME_OAEP) - if(req.algo_name() == "OAEP" && req.arg_count_between(1, 2)) + SCAN_Name req(algo_spec); + + if(req.algo_name() == "OAEP" || + req.algo_name() == "EME-OAEP" || + req.algo_name() == "EME1") { if(req.arg_count() == 1 || (req.arg_count() == 2 && req.arg(1) == "MGF1")) @@ -38,16 +50,6 @@ EME* get_eme(const std::string& algo_spec) } #endif -#if defined(BOTAN_HAS_EME_PKCS1v15) - if(req.algo_name() == "PKCS1v15" && req.arg_count() == 0) - return new EME_PKCS1v15; -#endif - -#if defined(BOTAN_HAS_EME_RAW) - if(req.algo_name() == "Raw" && req.arg_count() == 0) - return new EME_Raw; -#endif - throw Algorithm_Not_Found(algo_spec); } diff --git a/src/lib/pk_pad/emsa.cpp b/src/lib/pk_pad/emsa.cpp index c091319e2..719863557 100644 --- a/src/lib/pk_pad/emsa.cpp +++ b/src/lib/pk_pad/emsa.cpp @@ -44,42 +44,58 @@ EMSA* get_emsa(const std::string& algo_spec) #endif #if defined(BOTAN_HAS_EMSA_PKCS1) - if(req.algo_name() == "EMSA_PKCS1" && req.arg_count() == 1) + if(req.algo_name() == "EMSA_PKCS1" || + req.algo_name() == "EMSA-PKCS1-v1_5" || + req.algo_name() == "EMSA3") { - if(req.arg(0) == "Raw") + if(req.arg_count() == 1) { - return new EMSA_PKCS1v15_Raw; - } - else - { - if(auto hash = HashFunction::create(req.arg(0))) + if(req.arg(0) == "Raw") { - return new EMSA_PKCS1v15(hash.release()); + 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.algo_name() == "PSSR" || + req.algo_name() == "EMSA-PSS" || + req.algo_name() == "PSS-MGF1" || + req.algo_name() == "EMSA4") { - if(req.arg(1, "MGF1") != "MGF1") - return nullptr; // not supported - - if(auto h = HashFunction::create(req.arg(0))) + if(req.arg_count_between(2, 3)) { - const size_t salt_size = req.arg_as_integer(2, h->output_length()); - return new PSSR(h.release(), salt_size); + 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(req.algo_name() == "EMSA_X931" || + req.algo_name() == "EMSA2" || + req.algo_name() == "X9.31") { - if(auto hash = HashFunction::create(req.arg(0))) + if(req.arg_count() == 1) { - return new EMSA_X931(hash.release()); + if(auto hash = HashFunction::create(req.arg(0))) + { + return new EMSA_X931(hash.release()); + } } } #endif |