diff options
author | lloyd <[email protected]> | 2008-11-11 03:49:23 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-11 03:49:23 +0000 |
commit | 54f82a91844808eb1612080427fb64d44c486aad (patch) | |
tree | 82de46d4ae586f389120a5257576e8354b1e2d3a | |
parent | 6d2db29350761e5573c6f7fafefb2b937993fb80 (diff) |
Make SCAN_Name::arg return a new SCAN_Name that has the same providers list,
this allows provider preferences to be passed down to sub-algorithms.
-rw-r--r-- | src/libstate/engine/def_engine/lookup_hash.cpp | 5 | ||||
-rw-r--r-- | src/libstate/get_enc.cpp | 40 | ||||
-rw-r--r-- | src/pbe/get_pbe.cpp | 16 | ||||
-rw-r--r-- | src/utils/scan_name.cpp | 10 | ||||
-rw-r--r-- | src/utils/scan_name.h | 8 |
5 files changed, 49 insertions, 30 deletions
diff --git a/src/libstate/engine/def_engine/lookup_hash.cpp b/src/libstate/engine/def_engine/lookup_hash.cpp index da782fc0a..48ed8bc04 100644 --- a/src/libstate/engine/def_engine/lookup_hash.cpp +++ b/src/libstate/engine/def_engine/lookup_hash.cpp @@ -166,10 +166,7 @@ Default_Engine::find_hash(const SCAN_Name& request, */ for(size_t i = 0; i != request.arg_count(); ++i) { - SCAN_Name hash_request(request.arg(i), - request.providers_string()); - - const HashFunction* hash = af.prototype_hash_function(hash_request); + const HashFunction* hash = af.prototype_hash_function(request.arg(i)); if(!hash) return 0; diff --git a/src/libstate/get_enc.cpp b/src/libstate/get_enc.cpp index 143cec21c..a5231db91 100644 --- a/src/libstate/get_enc.cpp +++ b/src/libstate/get_enc.cpp @@ -85,19 +85,21 @@ S2K* get_s2k(const std::string& algo_spec) { SCAN_Name request(algo_spec); + Algorithm_Factory& af = global_state().algorithm_factory(); + #if defined(BOTAN_HAS_PBKDF1) if(request.algo_name() == "PBKDF1" && request.arg_count() == 1) - return new PKCS5_PBKDF1(get_hash(request.arg(0))); + return new PKCS5_PBKDF1(af.make_hash_function(request.arg(0))); #endif #if defined(BOTAN_HAS_PBKDF2) if(request.algo_name() == "PBKDF2" && request.arg_count() == 1) - return new PKCS5_PBKDF2(new HMAC(get_hash(request.arg(0)))); + return new PKCS5_PBKDF2(new HMAC(af.make_hash_function(request.arg(0)))); #endif #if defined(BOTAN_HAS_PGPS2K) if(request.algo_name() == "OpenPGP-S2K" && request.arg_count() == 1) - return new OpenPGP_S2K(get_hash(request.arg(0))); + return new OpenPGP_S2K(af.make_hash_function(request.arg(0))); #endif throw Algorithm_Not_Found(algo_spec); @@ -110,6 +112,8 @@ EMSA* get_emsa(const std::string& algo_spec) { SCAN_Name request(algo_spec); + Algorithm_Factory& af = global_state().algorithm_factory(); + #if defined(BOTAN_HAS_EMSA_RAW) if(request.algo_name() == "Raw" && request.arg_count() == 0) return new EMSA_Raw; @@ -117,22 +121,22 @@ EMSA* get_emsa(const std::string& algo_spec) #if defined(BOTAN_HAS_EMSA1) if(request.algo_name() == "EMSA1" && request.arg_count() == 1) - return new EMSA1(get_hash(request.arg(0))); + return new EMSA1(af.make_hash_function(request.arg(0))); #endif #if defined(BOTAN_HAS_EMSA1_BSI) if(request.algo_name() == "EMSA1_BSI" && request.arg_count() == 1) - return new EMSA1_BSI(get_hash(request.arg(0))); + return new EMSA1_BSI(af.make_hash_function(request.arg(0))); #endif #if defined(BOTAN_HAS_EMSA2) if(request.algo_name() == "EMSA2" && request.arg_count() == 1) - return new EMSA2(get_hash(request.arg(0))); + return new EMSA2(af.make_hash_function(request.arg(0))); #endif #if defined(BOTAN_HAS_EMSA3) if(request.algo_name() == "EMSA3" && request.arg_count() == 1) - return new EMSA3(get_hash(request.arg(0))); + return new EMSA3(af.make_hash_function(request.arg(0))); #endif #if defined(BOTAN_HAS_EMSA4) @@ -140,13 +144,13 @@ EMSA* get_emsa(const std::string& algo_spec) { // 3 args: Hash, MGF, salt size (MGF is hardcoded MGF1 in Botan) if(request.arg_count() == 1) - return new EMSA4(get_hash(request.arg(0))); + return new EMSA4(af.make_hash_function(request.arg(0))); - if(request.arg_count() == 2 && request.arg(1) != "MGF1") - return new EMSA4(get_hash(request.arg(0))); + if(request.arg_count() == 2 && request.arg_as_string(1) != "MGF1") + return new EMSA4(af.make_hash_function(request.arg(0))); if(request.arg_count() == 3) - return new EMSA4(get_hash(request.arg(0)), + return new EMSA4(af.make_hash_function(request.arg(0)), request.arg_as_u32bit(2, 0)); } #endif @@ -161,6 +165,8 @@ EME* get_eme(const std::string& algo_spec) { SCAN_Name request(algo_spec); + Algorithm_Factory& af = global_state().algorithm_factory(); + if(request.algo_name() == "Raw") return 0; // No padding @@ -173,9 +179,9 @@ EME* get_eme(const std::string& algo_spec) if(request.algo_name() == "EME1" && request.arg_count_between(1, 2)) { if(request.arg_count() == 1 || - (request.arg_count() == 2 && request.arg(1) == "MGF1")) + (request.arg_count() == 2 && request.arg_as_string(1) == "MGF1")) { - return new EME1(get_hash(request.arg(0))); + return new EME1(af.make_hash_function(request.arg(0))); } } #endif @@ -190,22 +196,24 @@ 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 0; // No KDF #if defined(BOTAN_HAS_KDF1) if(request.algo_name() == "KDF1" && request.arg_count() == 1) - return new KDF1(get_hash(request.arg(0))); + 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(get_hash(request.arg(0))); + 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)); + return new X942_PRF(request.arg_as_string(0)); // OID #endif #if defined(BOTAN_HAS_TLS_V10_PRF) diff --git a/src/pbe/get_pbe.cpp b/src/pbe/get_pbe.cpp index 7e76b7943..985f61cf8 100644 --- a/src/pbe/get_pbe.cpp +++ b/src/pbe/get_pbe.cpp @@ -27,8 +27,8 @@ PBE* get_pbe(const std::string& algo_spec) SCAN_Name request(algo_spec); const std::string pbe = request.algo_name(); - const std::string digest = request.arg(0); - const std::string cipher = request.arg(1); + SCAN_Name digest_name = request.arg(0); + const std::string cipher = request.arg_as_string(1); std::vector<std::string> cipher_spec = split_on(cipher, '/'); if(cipher_spec.size() != 2) @@ -46,9 +46,9 @@ PBE* get_pbe(const std::string& algo_spec) if(!block_cipher) throw Algorithm_Not_Found(cipher_algo); - const HashFunction* hash_function = af.make_hash_function(digest); + const HashFunction* hash_function = af.make_hash_function(digest_name); if(!hash_function) - throw Algorithm_Not_Found(digest); + throw Algorithm_Not_Found(digest_name.as_string()); if(request.arg_count() != 2) throw Invalid_Algorithm_Name(algo_spec); @@ -84,8 +84,8 @@ PBE* get_pbe(const OID& pbe_oid, DataSource& params) if(request.arg_count() != 2) throw Invalid_Algorithm_Name(request.as_string()); - const std::string digest = request.arg(0); - const std::string cipher = request.arg(1); + SCAN_Name digest_name = request.arg(0); + const std::string cipher = request.arg_as_string(1); std::vector<std::string> cipher_spec = split_on(cipher, '/'); if(cipher_spec.size() != 2) @@ -103,9 +103,9 @@ PBE* get_pbe(const OID& pbe_oid, DataSource& params) if(!block_cipher) throw Algorithm_Not_Found(cipher_algo); - const HashFunction* hash_function = af.make_hash_function(digest); + const HashFunction* hash_function = af.make_hash_function(digest_name); if(!hash_function) - throw Algorithm_Not_Found(digest); + throw Algorithm_Not_Found(digest_name.as_string()); PBE* pbe = new PBE_PKCS5v15(block_cipher->clone(), hash_function->clone(), diff --git a/src/utils/scan_name.cpp b/src/utils/scan_name.cpp index 7855f3ec3..b90211dea 100644 --- a/src/utils/scan_name.cpp +++ b/src/utils/scan_name.cpp @@ -71,7 +71,15 @@ bool SCAN_Name::provider_allowed(const std::string& provider) const return (providers.find(provider) != providers.end()); } -std::string SCAN_Name::arg(u32bit i) const +SCAN_Name SCAN_Name::arg(u32bit i) const + { + if(i > arg_count()) + throw std::range_error("SCAN_Name::argument"); + + return SCAN_Name(name[i+1], orig_providers); + } + +std::string SCAN_Name::arg_as_string(u32bit i) const { if(i > arg_count()) throw std::range_error("SCAN_Name::argument"); diff --git a/src/utils/scan_name.h b/src/utils/scan_name.h index 15fa09f48..22b7aa528 100644 --- a/src/utils/scan_name.h +++ b/src/utils/scan_name.h @@ -53,7 +53,13 @@ class SCAN_Name @param i which argument @return the ith argument */ - std::string arg(u32bit i) const; + std::string arg_as_string(u32bit i) const; + + /** + @param i which argument + @return the ith argument + */ + SCAN_Name arg(u32bit i) const; /** @param i which argument |