diff options
author | lloyd <[email protected]> | 2015-01-31 16:18:09 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-31 16:18:09 +0000 |
commit | fd3016d10124d2b7ccd7bc885235f2e407d73800 (patch) | |
tree | e237b54c3a8d465c893a012157d9d52014eaccc9 /src/lib | |
parent | 00c9b3f4834603946065c15b9b2e9fa5e973b979 (diff) |
Use registry also for KDF, EMSA, and EME
Diffstat (limited to 'src/lib')
26 files changed, 173 insertions, 174 deletions
diff --git a/src/lib/algo_base/algo_registry.h b/src/lib/algo_base/algo_registry.h index 80eff47be..77ed3591f 100644 --- a/src/lib/algo_base/algo_registry.h +++ b/src/lib/algo_base/algo_registry.h @@ -38,6 +38,12 @@ class Algo_Registry m_maker_fns[name][provider] = fn; } + T* make(const std::string& spec_str) + { + const Spec spec(spec_str); + return make(spec_str, ""); + } + T* make(const Spec& spec, const std::string& provider = "") { maker_fn maker = find_maker(spec, provider); @@ -48,6 +54,7 @@ class Algo_Registry } catch(std::exception& e) { + //return nullptr; // ?? throw std::runtime_error("Creating '" + spec.as_string() + "' failed: " + e.what()); } } @@ -111,6 +118,19 @@ class Algo_Registry }; template<typename T> T* +make_a(const typename T::Spec& spec, const std::string provider = "") + { + return Algo_Registry<T>::global_registry().make(spec, provider); + } + +template<typename T> T* +make_a(const std::string& spec_str, const std::string provider = "") + { + typename T::Spec spec(spec_str); + return make_a<T>(spec, provider); + } + +template<typename T> T* make_new_T(const typename Algo_Registry<T>::Spec&) { return new T; } template<typename T, size_t DEF_VAL> T* @@ -131,7 +151,22 @@ make_new_T_1str(const typename Algo_Registry<T>::Spec& spec, const std::string& return new T(spec.arg(0, def)); } -#define BOTAN_REGISTER_NAMED_T(T, namestr, type, maker) \ +template<typename T> T* +make_new_T_1str_req(const typename Algo_Registry<T>::Spec& spec) + { + return new T(spec.arg(0)); + } + +template<typename T, typename X> T* +make_new_T_1X(const typename Algo_Registry<T>::Spec& spec) + { + std::unique_ptr<X> x(Algo_Registry<X>::global_registry().make(spec.arg(0))); + if(!x) + throw std::runtime_error(spec.arg(0)); + return new T(x.release()); + } + +#define BOTAN_REGISTER_NAMED_T(T, namestr, type, maker) \ namespace { Algo_Registry<T>::Add g_ ## type ## _reg(namestr, maker); } #define BOTAN_REGISTER_T(T, name, maker) \ namespace { Algo_Registry<T>::Add g_ ## name ## _reg(#name, maker); } diff --git a/src/lib/algo_base/scan_name.cpp b/src/lib/algo_base/scan_name.cpp index ad34e05c1..6206ab60a 100644 --- a/src/lib/algo_base/scan_name.cpp +++ b/src/lib/algo_base/scan_name.cpp @@ -155,7 +155,8 @@ std::string SCAN_Name::all_arguments() const std::string SCAN_Name::arg(size_t i) const { if(i >= arg_count()) - throw std::range_error("SCAN_Name::arg - i out of range"); + throw std::range_error("SCAN_Name::arg " + std::to_string(i) + + " out of range for '" + as_string() + "'"); return args[i]; } diff --git a/src/lib/filters/algo_filt.cpp b/src/lib/filters/algo_filt.cpp index 2cbb3acff..828f15155 100644 --- a/src/lib/filters/algo_filt.cpp +++ b/src/lib/filters/algo_filt.cpp @@ -80,7 +80,7 @@ Hash_Filter::Hash_Filter(const std::string& algo_spec, size_t len) : OUTPUT_LENGTH(len) { - m_hash.reset(Algo_Registry<HashFunction>::global_registry().make(sc_name)); + m_hash.reset(Algo_Registry<HashFunction>::global_registry().make(algo_spec)); } /* diff --git a/src/lib/kdf/info.txt b/src/lib/kdf/info.txt index f33a4bc8d..91489ca24 100644 --- a/src/lib/kdf/info.txt +++ b/src/lib/kdf/info.txt @@ -4,3 +4,11 @@ define KDF_BASE 20131128 alloc libstate </requires> + +<header:public> +kdf.h +</header:public> + +<header:internal> +kdf_utils.h +</header:internal> diff --git a/src/lib/kdf/kdf.cpp b/src/lib/kdf/kdf.cpp index a0ee580ab..e18d9ce75 100644 --- a/src/lib/kdf/kdf.cpp +++ b/src/lib/kdf/kdf.cpp @@ -6,24 +6,8 @@ */ #include <botan/kdf.h> -#include <botan/libstate.h> -#include <botan/scan_name.h> - -#if defined(BOTAN_HAS_KDF1) - #include <botan/kdf1.h> -#endif - -#if defined(BOTAN_HAS_KDF2) - #include <botan/kdf2.h> -#endif - -#if defined(BOTAN_HAS_X942_PRF) - #include <botan/prf_x942.h> -#endif - -#if defined(BOTAN_HAS_TLS_V10_PRF) - #include <botan/prf_tls.h> -#endif +#include <botan/algo_registry.h> +#include <botan/exceptn.h> namespace Botan { @@ -31,36 +15,11 @@ KDF* get_kdf(const std::string& algo_spec) { SCAN_Name request(algo_spec); - Algorithm_Factory& af = global_state().algorithm_factory(); - if(request.algo_name() == "Raw") return nullptr; // No KDF -#if defined(BOTAN_HAS_KDF1) - if(request.algo_name() == "KDF1" && request.arg_count() == 1) - return new KDF1(af.make_hash_function(request.arg(0))); -#endif - -#if defined(BOTAN_HAS_KDF2) - if(request.algo_name() == "KDF2" && request.arg_count() == 1) - return new KDF2(af.make_hash_function(request.arg(0))); -#endif - -#if defined(BOTAN_HAS_X942_PRF) - if(request.algo_name() == "X9.42-PRF" && request.arg_count() == 1) - return new X942_PRF(request.arg(0)); // OID -#endif - -#if defined(BOTAN_HAS_TLS_V10_PRF) - if(request.algo_name() == "TLS-PRF" && request.arg_count() == 0) - return new TLS_PRF; -#endif - -#if defined(BOTAN_HAS_TLS_V12_PRF) - if(request.algo_name() == "TLS-12-PRF" && request.arg_count() == 1) - return new TLS_12_PRF(af.make_mac("HMAC(" + request.arg(0) + ")")); -#endif - + if(KDF* kdf = make_a<KDF>(algo_spec)) + return kdf; throw Algorithm_Not_Found(algo_spec); } diff --git a/src/lib/kdf/kdf.h b/src/lib/kdf/kdf.h index 7b417fcd9..9d8ca57fc 100644 --- a/src/lib/kdf/kdf.h +++ b/src/lib/kdf/kdf.h @@ -8,6 +8,7 @@ #ifndef BOTAN_KDF_BASE_H__ #define BOTAN_KDF_BASE_H__ +#include <botan/scan_name.h> #include <botan/secmem.h> #include <botan/types.h> #include <string> @@ -107,6 +108,8 @@ class BOTAN_DLL KDF } virtual KDF* clone() const = 0; + + typedef SCAN_Name Spec; private: virtual secure_vector<byte> derive(size_t key_len, diff --git a/src/lib/kdf/kdf1/kdf1.cpp b/src/lib/kdf/kdf1/kdf1.cpp index b0fa97443..df84a1a00 100644 --- a/src/lib/kdf/kdf1/kdf1.cpp +++ b/src/lib/kdf/kdf1/kdf1.cpp @@ -5,10 +5,13 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/kdf_utils.h> #include <botan/kdf1.h> namespace Botan { +BOTAN_REGISTER_KDF_1HASH(KDF1, "KDF1"); + /* * KDF1 Key Derivation Mechanism */ diff --git a/src/lib/kdf/kdf2/kdf2.cpp b/src/lib/kdf/kdf2/kdf2.cpp index 052df0b6a..c7b355580 100644 --- a/src/lib/kdf/kdf2/kdf2.cpp +++ b/src/lib/kdf/kdf2/kdf2.cpp @@ -5,10 +5,13 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/kdf_utils.h> #include <botan/kdf2.h> namespace Botan { +BOTAN_REGISTER_KDF_1HASH(KDF2, "KDF2"); + /* * KDF2 Key Derivation Mechanism */ diff --git a/src/lib/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp index 79292922c..f1061fd10 100644 --- a/src/lib/kdf/prf_tls/prf_tls.cpp +++ b/src/lib/kdf/prf_tls/prf_tls.cpp @@ -5,14 +5,24 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/kdf_utils.h> #include <botan/prf_tls.h> -#include <botan/internal/xor_buf.h> #include <botan/hmac.h> -#include <botan/md5.h> -#include <botan/sha160.h> namespace Botan { +TLS_12_PRF* TLS_12_PRF::make(const Spec& spec) + { + if(auto mac = make_a<MessageAuthenticationCode>(spec.arg(0))) + return new TLS_12_PRF(mac); + if(auto hash = make_a<HashFunction>(spec.arg(0))) + return new TLS_12_PRF(new HMAC(hash)); + return nullptr; + } + +BOTAN_REGISTER_NAMED_T(KDF, "TLS-12-PRF", TLS_12_PRF, TLS_12_PRF::make); +BOTAN_REGISTER_KDF_NOARGS(TLS_PRF, "TLS-PRF"); + namespace { /* @@ -61,8 +71,8 @@ void P_hash(secure_vector<byte>& output, */ TLS_PRF::TLS_PRF() { - hmac_md5.reset(new HMAC(new MD5)); - hmac_sha1.reset(new HMAC(new SHA_160)); + hmac_md5.reset(make_a<MessageAuthenticationCode>("HMAC(MD5)")); + hmac_sha1.reset(make_a<MessageAuthenticationCode>("HMAC(SHA-1)")); } /* @@ -88,7 +98,7 @@ secure_vector<byte> TLS_PRF::derive(size_t key_len, /* * TLS v1.2 PRF Constructor and Destructor */ -TLS_12_PRF::TLS_12_PRF(MessageAuthenticationCode* mac) : hmac(mac) +TLS_12_PRF::TLS_12_PRF(MessageAuthenticationCode* mac) : m_mac(mac) { } @@ -98,7 +108,7 @@ secure_vector<byte> TLS_12_PRF::derive(size_t key_len, { secure_vector<byte> output(key_len); - P_hash(output, *hmac, secret, secret_len, seed, seed_len); + P_hash(output, *m_mac, secret, secret_len, seed, seed_len); return output; } diff --git a/src/lib/kdf/prf_tls/prf_tls.h b/src/lib/kdf/prf_tls/prf_tls.h index 71b4d55e9..c3adc6caf 100644 --- a/src/lib/kdf/prf_tls/prf_tls.h +++ b/src/lib/kdf/prf_tls/prf_tls.h @@ -42,12 +42,14 @@ class BOTAN_DLL TLS_12_PRF : public KDF const byte secret[], size_t secret_len, const byte seed[], size_t seed_len) const; - std::string name() const { return "TLSv12-PRF(" + hmac->name() + ")"; } - KDF* clone() const { return new TLS_12_PRF(hmac->clone()); } + std::string name() const { return "TLS-12-PRF(" + m_mac->name() + ")"; } + KDF* clone() const { return new TLS_12_PRF(m_mac->clone()); } - TLS_12_PRF(MessageAuthenticationCode* hmac); + TLS_12_PRF(MessageAuthenticationCode* mac); + + static TLS_12_PRF* make(const Spec& spec); private: - std::unique_ptr<MessageAuthenticationCode> hmac; + std::unique_ptr<MessageAuthenticationCode> m_mac; }; } diff --git a/src/lib/kdf/prf_x942/prf_x942.cpp b/src/lib/kdf/prf_x942/prf_x942.cpp index a5ee1f3e4..30bf737a9 100644 --- a/src/lib/kdf/prf_x942/prf_x942.cpp +++ b/src/lib/kdf/prf_x942/prf_x942.cpp @@ -5,6 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/kdf_utils.h> #include <botan/prf_x942.h> #include <botan/der_enc.h> #include <botan/oids.h> @@ -14,6 +15,8 @@ namespace Botan { +BOTAN_REGISTER_KDF_NAMED_1STR(X942_PRF, "X9.42-PRF"); + namespace { /* 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> diff --git a/src/lib/pubkey/rfc6979/rfc6979.cpp b/src/lib/pubkey/rfc6979/rfc6979.cpp index 1b22fae54..5ba2f844a 100644 --- a/src/lib/pubkey/rfc6979/rfc6979.cpp +++ b/src/lib/pubkey/rfc6979/rfc6979.cpp @@ -8,6 +8,7 @@ #include <botan/rfc6979.h> #include <botan/hmac_drbg.h> #include <botan/scan_name.h> +#include <botan/algo_registry.h> namespace Botan { @@ -29,9 +30,8 @@ BigInt generate_rfc6979_nonce(const BigInt& x, const BigInt& h, const std::string& hash) { - Algorithm_Factory& af = global_state().algorithm_factory(); - - HMAC_DRBG rng(af.make_mac("HMAC(" + hash + ")"), nullptr); + auto& macs = Algo_Registry<MessageAuthenticationCode>::global_registry(); + HMAC_DRBG rng(macs.make("HMAC(" + hash + ")"), nullptr); const size_t qlen = q.bits(); const size_t rlen = qlen / 8 + (qlen % 8 ? 1 : 0); |