diff options
author | lloyd <[email protected]> | 2008-11-12 18:11:50 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-12 18:11:50 +0000 |
commit | ff1e835d888a2783e59efc30fa125bfaf7d150fe (patch) | |
tree | f69008ec6cfc733bd993a584e7298c1d48afc89d | |
parent | e99e232ac74cb2761468e2edad4881fc26033df3 (diff) |
Remove support for provider identifiers from SCAN_Name - it turns out this
was not the right place to keep track of this information. Also modify
all Algorithm_Factory constructor functions to take instead of a SCAN_Name
a pair of std::strings - the SCAN name and an optional provider name. If
a provider is specified, either that provider will be used or the request
will fail. Otherwise, the library will attempt best effort, based on
user-set algorithm implementation settings (combine with benchmark.h for
choosing the fastest implementation at runtime) or if not set, a static
ordering (preset in static_provider_weight in prov_weight.cpp, though it
would be nice to make this easier to toggle).
-rw-r--r-- | checks/check.cpp | 2 | ||||
-rwxr-xr-x | configure.pl | 2 | ||||
-rw-r--r-- | doc/log.txt | 3 | ||||
-rw-r--r-- | readme.txt | 2 | ||||
-rw-r--r-- | src/algo_factory/algo_cache.h | 91 | ||||
-rw-r--r-- | src/algo_factory/algo_factory.cpp | 219 | ||||
-rw-r--r-- | src/algo_factory/algo_factory.h | 83 | ||||
-rw-r--r-- | src/algo_factory/info.txt | 1 | ||||
-rw-r--r-- | src/benchmark/benchmark.cpp | 13 | ||||
-rw-r--r-- | src/engine/def_engine/lookup_mac.cpp | 2 | ||||
-rw-r--r-- | src/libstate/get_enc.cpp | 6 | ||||
-rw-r--r-- | src/pbe/get_pbe.cpp | 12 | ||||
-rw-r--r-- | src/pbe/pbes2/pbes2.cpp | 2 | ||||
-rw-r--r-- | src/selftest/selftest.cpp | 10 | ||||
-rw-r--r-- | src/utils/scan_name.cpp | 14 | ||||
-rw-r--r-- | src/utils/scan_name.h | 28 |
16 files changed, 277 insertions, 213 deletions
diff --git a/checks/check.cpp b/checks/check.cpp index 93d7e9b94..5cf5c1c31 100644 --- a/checks/check.cpp +++ b/checks/check.cpp @@ -102,6 +102,8 @@ int main(int argc, char* argv[]) Botan::LibraryInitializer init("thread_safe=no"); + //Botan::global_state().algorithm_factory().set_preferred_provider("SHA-160", "core"); + Botan::AutoSeeded_RNG rng; if(opts.is_set("help") || argc <= 1) diff --git a/configure.pl b/configure.pl index 8fa976fff..737800665 100755 --- a/configure.pl +++ b/configure.pl @@ -13,7 +13,7 @@ use Sys::Hostname; my $MAJOR_VERSION = 1; my $MINOR_VERSION = 7; -my $PATCH_VERSION = 21; +my $PATCH_VERSION = 22; my $VERSION_STRING = "$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION"; diff --git a/doc/log.txt b/doc/log.txt index 923279e34..02c5609f9 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -1,4 +1,7 @@ +* 1.7.22, ????-??-?? + - Add provider preferences to Algorithm_Factory + * 1.7.21, 2008-11-11 - Make algorithm lookup much more configuable - Add facilities for runtime performance testing of algorithms diff --git a/readme.txt b/readme.txt index 505f59a63..c11a1ea27 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -Botan 1.7.21 2008-11-11 +Botan 1.7.22 ????-??-?? http://botan.randombit.net/ Please note that this is an experimental / development version of diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 699078b03..17ea9964a 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -5,25 +5,46 @@ #ifndef BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ #define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ -#include <botan/scan_name.h> #include <botan/mutex.h> +#include <botan/stl_util.h> #include <string> +#include <vector> #include <map> namespace Botan { /** +* @param prov_name a provider name +* @return weight for this provider +*/ +u32bit static_provider_weight(const std::string& prov_name); + +/** * Algorithm_Cache (used by Algorithm_Factory) */ template<typename T> class Algorithm_Cache { public: - const T* get(const SCAN_Name& request); + const T* get(const std::string& algo_spec, + const std::string& pref_provider); + + /** + * Add a new algorithm implementation to the cache + */ void add(T* algo, const std::string& requested_name, - const std::string& provider); + const std::string& provider_name); + + /** + * Set the preferred provider + */ + void set_preferred_provider(const std::string& algo_spec, + const std::string& provider); + /** + * Return the list of providers of this algorithm + */ std::vector<std::string> providers_of(const std::string& algo_name); Algorithm_Cache(Mutex* m) : mutex(m) {} @@ -38,17 +59,18 @@ class Algorithm_Cache Mutex* mutex; std::map<std::string, std::string> aliases; + std::map<std::string, std::string> pref_providers; std::map<std::string, std::map<std::string, T*> > algorithms; }; /** * Look for an algorithm implementation in the cache, also checking aliases +* Assumes object lock is held */ template<typename T> typename Algorithm_Cache<T>::algorithms_iterator Algorithm_Cache<T>::find_algorithm(const std::string& algo_spec) { - // Assumes mutex is held algorithms_iterator algo = algorithms.find(algo_spec); // Not found? Check if a known alias @@ -65,40 +87,51 @@ Algorithm_Cache<T>::find_algorithm(const std::string& algo_spec) } /** -* Look for an algorithm implementation in the cache +* Look for an algorithm implementation by a particular provider */ template<typename T> -const T* Algorithm_Cache<T>::get(const SCAN_Name& request) +const T* Algorithm_Cache<T>::get(const std::string& algo_spec, + const std::string& requested_provider) { Mutex_Holder lock(mutex); - algorithms_iterator algo = find_algorithm(request.as_string()); - if(algo == algorithms.end()) // not found at all + algorithms_iterator algo = find_algorithm(algo_spec); + if(algo == algorithms.end()) // algo not found at all (no providers) return 0; - const std::string requested_provider = request.provider(); - + // If a provider is requested specifically, return it or fail entirely if(requested_provider != "") { - provider_iterator provider = algo->second.find(requested_provider); - - if(provider != algo->second.end()) - return provider->second; + provider_iterator prov = algo->second.find(requested_provider); + if(prov != algo->second.end()) + return prov->second; + return 0; } - else // no specific provider requested: pick one + + const T* prototype = 0; + std::string prototype_provider; + u32bit prototype_prov_weight = 0; + + const std::string pref_provider = search_map(pref_providers, algo_spec); + + for(provider_iterator i = algo->second.begin(); i != algo->second.end(); ++i) { - provider_iterator provider = algo->second.begin(); + const std::string prov_name = i->first; + const u32bit prov_weight = static_provider_weight(prov_name); - while(provider != algo->second.end()) - ++provider; + // preferred prov exists, return immediately + if(prov_name == pref_provider) + return i->second; - provider = algo->second.begin(); - // @fixme: Just picks the lexicographically first one - if(provider != algo->second.end()) - return provider->second; + if(prototype == 0 || prov_weight > prototype_prov_weight) + { + prototype = i->second; + prototype_provider = i->first; + prototype_prov_weight = prov_weight; + } } - return 0; // cache miss + return prototype; } /** @@ -151,6 +184,18 @@ Algorithm_Cache<T>::providers_of(const std::string& algo_name) } /** +* Set the preferred provider for an algorithm +*/ +template<typename T> +void Algorithm_Cache<T>::set_preferred_provider(const std::string& algo_spec, + const std::string& provider) + { + Mutex_Holder lock(mutex); + + pref_providers[algo_spec] = provider; + } + +/** * Algorithm_Cache<T> Destructor */ template<typename T> diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp index 0756d02d8..5b300b7c6 100644 --- a/src/algo_factory/algo_factory.cpp +++ b/src/algo_factory/algo_factory.cpp @@ -45,9 +45,25 @@ void Algorithm_Factory::add_engine(Engine* engine) engines.push_back(engine); } -/************************************************* -* Get an engine out of the list * -*************************************************/ +/** +* Set the preferred provider for an algorithm +*/ +void Algorithm_Factory::set_preferred_provider(const std::string& algo_spec, + const std::string& provider) + { + if(prototype_block_cipher(algo_spec)) + block_cipher_cache.set_preferred_provider(algo_spec, provider); + else if(prototype_stream_cipher(algo_spec)) + stream_cipher_cache.set_preferred_provider(algo_spec, provider); + else if(prototype_hash_function(algo_spec)) + hash_cache.set_preferred_provider(algo_spec, provider); + else if(prototype_mac(algo_spec)) + mac_cache.set_preferred_provider(algo_spec, provider); + } + +/** +* Get an engine out of the list +*/ Engine* Algorithm_Factory::get_engine_n(u32bit n) const { if(n >= engines.size()) @@ -57,180 +73,173 @@ Engine* Algorithm_Factory::get_engine_n(u32bit n) const /** * Return the possible providers of a request +* Note: assumes you don't have different types by the same name */ std::vector<std::string> -Algorithm_Factory::providers_of(const std::string& algo_name) +Algorithm_Factory::providers_of(const std::string& algo_spec) { - if(prototype_block_cipher(algo_name)) - return block_cipher_cache.providers_of(algo_name); - - if(prototype_stream_cipher(algo_name)) - return stream_cipher_cache.providers_of(algo_name); - - if(prototype_hash_function(algo_name)) - return hash_cache.providers_of(algo_name); - - if(prototype_mac(algo_name)) - return mac_cache.providers_of(algo_name); - - return std::vector<std::string>(); + if(prototype_block_cipher(algo_spec)) + return block_cipher_cache.providers_of(algo_spec); + else if(prototype_stream_cipher(algo_spec)) + return stream_cipher_cache.providers_of(algo_spec); + else if(prototype_hash_function(algo_spec)) + return hash_cache.providers_of(algo_spec); + else if(prototype_mac(algo_spec)) + return mac_cache.providers_of(algo_spec); + else + return std::vector<std::string>(); } /** * Return the prototypical block cipher cooresponding to this request */ const BlockCipher* -Algorithm_Factory::prototype_block_cipher(const SCAN_Name& request) +Algorithm_Factory::prototype_block_cipher(const std::string& algo_spec, + const std::string& provider) { - if(const BlockCipher* cache_hit = block_cipher_cache.get(request)) - return cache_hit; + if(const BlockCipher* hit = block_cipher_cache.get(algo_spec, provider)) + return hit; + SCAN_Name scan_name(algo_spec); for(u32bit i = 0; i != engines.size(); ++i) { - const std::string provider = engines[i]->provider_name(); - - SCAN_Name request_i(request.as_string(), provider); - - if(BlockCipher* impl = engines[i]->find_block_cipher(request_i, *this)) - block_cipher_cache.add(impl, request.as_string(), provider); + if(BlockCipher* impl = engines[i]->find_block_cipher(scan_name, *this)) + block_cipher_cache.add(impl, algo_spec, engines[i]->provider_name()); } - return block_cipher_cache.get(request); + return block_cipher_cache.get(algo_spec, provider); } /** -* Return a new block cipher cooresponding to this request +* Return the prototypical stream cipher cooresponding to this request */ -BlockCipher* Algorithm_Factory::make_block_cipher(const SCAN_Name& request) +const StreamCipher* +Algorithm_Factory::prototype_stream_cipher(const std::string& algo_spec, + const std::string& provider) { - if(const BlockCipher* prototype = prototype_block_cipher(request)) - return prototype->clone(); - throw Algorithm_Not_Found(request.as_string()); + if(const StreamCipher* hit = stream_cipher_cache.get(algo_spec, provider)) + return hit; + + SCAN_Name scan_name(algo_spec); + for(u32bit i = 0; i != engines.size(); ++i) + { + if(StreamCipher* impl = engines[i]->find_stream_cipher(scan_name, *this)) + stream_cipher_cache.add(impl, algo_spec, engines[i]->provider_name()); + } + + return stream_cipher_cache.get(algo_spec, provider); } /** -* Add a new block cipher +* Return the prototypical object cooresponding to this request (if found) */ -void Algorithm_Factory::add_block_cipher(BlockCipher* block_cipher, - const std::string& provider) +const HashFunction* +Algorithm_Factory::prototype_hash_function(const std::string& algo_spec, + const std::string& provider) { - block_cipher_cache.add(block_cipher, block_cipher->name(), provider); + if(const HashFunction* hit = hash_cache.get(algo_spec, provider)) + return hit; + + SCAN_Name scan_name(algo_spec); + for(u32bit i = 0; i != engines.size(); ++i) + { + if(HashFunction* impl = engines[i]->find_hash(scan_name, *this)) + hash_cache.add(impl, algo_spec, engines[i]->provider_name()); + } + + return hash_cache.get(algo_spec, provider); } /** -* Return the prototypical stream cipher cooresponding to this request +* Return the prototypical object cooresponding to this request */ -const StreamCipher* -Algorithm_Factory::prototype_stream_cipher(const SCAN_Name& request) +const MessageAuthenticationCode* +Algorithm_Factory::prototype_mac(const std::string& algo_spec, + const std::string& provider) { - if(const StreamCipher* cache_hit = stream_cipher_cache.get(request)) - return cache_hit; + if(const MessageAuthenticationCode* hit = mac_cache.get(algo_spec, provider)) + return hit; + SCAN_Name scan_name(algo_spec); for(u32bit i = 0; i != engines.size(); ++i) { - const std::string provider = engines[i]->provider_name(); - - SCAN_Name request_i(request.as_string(), provider); - - if(StreamCipher* impl = engines[i]->find_stream_cipher(request_i, *this)) - stream_cipher_cache.add(impl, request.as_string(), provider); + if(MessageAuthenticationCode* impl = engines[i]->find_mac(scan_name, *this)) + mac_cache.add(impl, algo_spec, engines[i]->provider_name()); } - return stream_cipher_cache.get(request); + return mac_cache.get(algo_spec, provider); } /** -* Return a new stream cipher cooresponding to this request +* Return a new block cipher cooresponding to this request */ -StreamCipher* Algorithm_Factory::make_stream_cipher(const SCAN_Name& request) +BlockCipher* Algorithm_Factory::make_block_cipher(const std::string& algo_spec, + const std::string& provider) { - if(const StreamCipher* prototype = prototype_stream_cipher(request)) - return prototype->clone(); - throw Algorithm_Not_Found(request.as_string()); + if(const BlockCipher* proto = prototype_block_cipher(algo_spec, provider)) + return proto->clone(); + throw Algorithm_Not_Found(algo_spec); } /** -* Add a new stream cipher +* Return a new stream cipher cooresponding to this request */ -void Algorithm_Factory::add_stream_cipher(StreamCipher* stream_cipher, - const std::string& provider) +StreamCipher* Algorithm_Factory::make_stream_cipher(const std::string& algo_spec, + const std::string& provider) { - stream_cipher_cache.add(stream_cipher, stream_cipher->name(), provider); + if(const StreamCipher* prototype = prototype_stream_cipher(algo_spec, provider)) + return prototype->clone(); + throw Algorithm_Not_Found(algo_spec); } /** -* Return the prototypical object cooresponding to this request (if found) +* Return a new object cooresponding to this request */ -const HashFunction* -Algorithm_Factory::prototype_hash_function(const SCAN_Name& request) +HashFunction* Algorithm_Factory::make_hash_function(const std::string& algo_spec, + const std::string& provider) { - if(const HashFunction* cache_hit = hash_cache.get(request)) - return cache_hit; - - for(u32bit i = 0; i != engines.size(); ++i) - { - const std::string provider = engines[i]->provider_name(); - - SCAN_Name request_i(request.as_string(), provider); - - if(HashFunction* impl = engines[i]->find_hash(request_i, *this)) - hash_cache.add(impl, request.as_string(), provider); - } - - return hash_cache.get(request); + if(const HashFunction* prototype = prototype_hash_function(algo_spec, provider)) + return prototype->clone(); + throw Algorithm_Not_Found(algo_spec); } /** * Return a new object cooresponding to this request */ -HashFunction* Algorithm_Factory::make_hash_function(const SCAN_Name& request) +MessageAuthenticationCode* +Algorithm_Factory::make_mac(const std::string& algo_spec, + const std::string& provider) { - if(const HashFunction* prototype = prototype_hash_function(request)) + if(const MessageAuthenticationCode* prototype = prototype_mac(algo_spec, provider)) return prototype->clone(); - throw Algorithm_Not_Found(request.as_string()); + throw Algorithm_Not_Found(algo_spec); } /** -* Add a new hash +* Add a new block cipher */ -void Algorithm_Factory::add_hash_function(HashFunction* hash, - const std::string& provider) +void Algorithm_Factory::add_block_cipher(BlockCipher* block_cipher, + const std::string& provider) { - hash_cache.add(hash, hash->name(), provider); + block_cipher_cache.add(block_cipher, block_cipher->name(), provider); } /** -* Return the prototypical object cooresponding to this request +* Add a new stream cipher */ -const MessageAuthenticationCode* -Algorithm_Factory::prototype_mac(const SCAN_Name& request) +void Algorithm_Factory::add_stream_cipher(StreamCipher* stream_cipher, + const std::string& provider) { - if(const MessageAuthenticationCode* cache_hit = mac_cache.get(request)) - return cache_hit; - - for(u32bit i = 0; i != engines.size(); ++i) - { - const std::string provider = engines[i]->provider_name(); - - SCAN_Name request_i(request.as_string(), provider); - - if(MessageAuthenticationCode* impl = - engines[i]->find_mac(request_i, *this)) - mac_cache.add(impl, request.as_string(), provider); - } - - return mac_cache.get(request); + stream_cipher_cache.add(stream_cipher, stream_cipher->name(), provider); } /** -* Return a new object cooresponding to this request +* Add a new hash */ -MessageAuthenticationCode* -Algorithm_Factory::make_mac(const SCAN_Name& request) +void Algorithm_Factory::add_hash_function(HashFunction* hash, + const std::string& provider) { - if(const MessageAuthenticationCode* prototype = prototype_mac(request)) - return prototype->clone(); - throw Algorithm_Not_Found(request.as_string()); + hash_cache.add(hash, hash->name(), provider); } /** diff --git a/src/algo_factory/algo_factory.h b/src/algo_factory/algo_factory.h index 07a8c93f1..fbaf26ebf 100644 --- a/src/algo_factory/algo_factory.h +++ b/src/algo_factory/algo_factory.h @@ -7,11 +7,9 @@ #define BOTAN_ALGORITHM_FACTORY_H__ #include <botan/algo_cache.h> -#include <botan/scan_name.h> #include <botan/mutex.h> #include <string> #include <vector> -#include <map> namespace Botan { @@ -29,11 +27,70 @@ class MessageAuthenticationCode; class BOTAN_DLL Algorithm_Factory { public: + /** + * Contructor + * @param mf a mutex factory + */ Algorithm_Factory(Mutex_Factory& mf); + + /** + * Destructor + */ ~Algorithm_Factory(); + /** + * Add an engine implementation to this factory (how steampunk) + */ void add_engine(class Engine*); + /* + * Provider management + */ + std::vector<std::string> providers_of(const std::string& algo_spec); + + void set_preferred_provider(const std::string& algo_spec, + const std::string& provider); + + /* + * Block cipher operations + */ + const BlockCipher* prototype_block_cipher(const std::string& algo_spec, + const std::string& provider = ""); + BlockCipher* make_block_cipher(const std::string& algo_spec, + const std::string& provider = ""); + void add_block_cipher(BlockCipher* hash, const std::string& provider); + + /* + * Stream cipher operations + */ + const StreamCipher* prototype_stream_cipher(const std::string& algo_spec, + const std::string& provider = ""); + StreamCipher* make_stream_cipher(const std::string& algo_spec, + const std::string& provider = ""); + void add_stream_cipher(StreamCipher* hash, const std::string& provider); + + /* + * Hash function operations + */ + const HashFunction* prototype_hash_function(const std::string& algo_spec, + const std::string& provider = ""); + HashFunction* make_hash_function(const std::string& algo_spec, + const std::string& provider = ""); + void add_hash_function(HashFunction* hash, const std::string& provider); + + /* + * MAC operations + */ + const MessageAuthenticationCode* prototype_mac(const std::string& algo_spec, + const std::string& provider = ""); + MessageAuthenticationCode* make_mac(const std::string& algo_spec, + const std::string& provider = ""); + void add_mac(MessageAuthenticationCode* mac, + const std::string& provider); + + /* + * Deprecated + */ class BOTAN_DLL Engine_Iterator { public: @@ -45,28 +102,6 @@ class BOTAN_DLL Algorithm_Factory }; friend class Engine_Iterator; - std::vector<std::string> providers_of(const std::string& algo_spec); - - // Block cipher operations - const BlockCipher* prototype_block_cipher(const SCAN_Name& request); - BlockCipher* make_block_cipher(const SCAN_Name& request); - void add_block_cipher(BlockCipher* hash, const std::string& provider); - - // Stream cipher operations - const StreamCipher* prototype_stream_cipher(const SCAN_Name& request); - StreamCipher* make_stream_cipher(const SCAN_Name& request); - void add_stream_cipher(StreamCipher* hash, const std::string& provider); - - // Hash function operations - const HashFunction* prototype_hash_function(const SCAN_Name& request); - HashFunction* make_hash_function(const SCAN_Name& request); - void add_hash_function(HashFunction* hash, const std::string& provider); - - // MAC operations - const MessageAuthenticationCode* prototype_mac(const SCAN_Name& request); - MessageAuthenticationCode* make_mac(const SCAN_Name& request); - void add_mac(MessageAuthenticationCode* mac, - const std::string& provider); private: class Engine* get_engine_n(u32bit) const; diff --git a/src/algo_factory/info.txt b/src/algo_factory/info.txt index 34f2a94cc..937b91353 100644 --- a/src/algo_factory/info.txt +++ b/src/algo_factory/info.txt @@ -12,4 +12,5 @@ utils algo_factory.cpp algo_factory.h algo_cache.h +prov_weight.cpp </add> diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 41e41bfcc..fe6cf0a41 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -137,32 +137,33 @@ algorithm_benchmark(const std::string& name, { const std::string provider = providers[i]; - SCAN_Name request(name, provider); - std::pair<u32bit, u64bit> results = std::make_pair(0, 0); - if(const BlockCipher* proto = af.prototype_block_cipher(request)) + if(const BlockCipher* proto = + af.prototype_block_cipher(name, provider)) { std::auto_ptr<BlockCipher> block_cipher(proto->clone()); results = bench_block_cipher(block_cipher.get(), timer, ns_per_provider, &buf[0], buf.size()); } - else if(const StreamCipher* proto = af.prototype_stream_cipher(request)) + else if(const StreamCipher* proto = + af.prototype_stream_cipher(name, provider)) { std::auto_ptr<StreamCipher> stream_cipher(proto->clone()); results = bench_stream_cipher(stream_cipher.get(), timer, ns_per_provider, &buf[0], buf.size()); } - else if(const HashFunction* proto = af.prototype_hash_function(request)) + else if(const HashFunction* proto = + af.prototype_hash_function(name, provider)) { std::auto_ptr<HashFunction> hash(proto->clone()); results = bench_hash(hash.get(), timer, ns_per_provider, &buf[0], buf.size()); } else if(const MessageAuthenticationCode* proto = - af.prototype_mac(request)) + af.prototype_mac(name, provider)) { std::auto_ptr<MessageAuthenticationCode> mac(proto->clone()); results = bench_mac(mac.get(), timer, ns_per_provider, diff --git a/src/engine/def_engine/lookup_mac.cpp b/src/engine/def_engine/lookup_mac.cpp index ae44bbe3d..35f17e134 100644 --- a/src/engine/def_engine/lookup_mac.cpp +++ b/src/engine/def_engine/lookup_mac.cpp @@ -59,7 +59,7 @@ Default_Engine::find_mac(const SCAN_Name& request, #if defined(BOTAN_HAS_ANSI_X919_MAC) if(request.algo_name() == "X9.19-MAC" && request.arg_count() == 0) - return new ANSI_X919_MAC(af.make_block_cipher(SCAN_Name("DES"))); + return new ANSI_X919_MAC(af.make_block_cipher("DES")); #endif return 0; diff --git a/src/libstate/get_enc.cpp b/src/libstate/get_enc.cpp index a5231db91..60a92d53e 100644 --- a/src/libstate/get_enc.cpp +++ b/src/libstate/get_enc.cpp @@ -146,7 +146,7 @@ EMSA* get_emsa(const std::string& algo_spec) if(request.arg_count() == 1) return new EMSA4(af.make_hash_function(request.arg(0))); - if(request.arg_count() == 2 && request.arg_as_string(1) != "MGF1") + if(request.arg_count() == 2 && request.arg(1) != "MGF1") return new EMSA4(af.make_hash_function(request.arg(0))); if(request.arg_count() == 3) @@ -179,7 +179,7 @@ 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_as_string(1) == "MGF1")) + (request.arg_count() == 2 && request.arg(1) == "MGF1")) { return new EME1(af.make_hash_function(request.arg(0))); } @@ -213,7 +213,7 @@ KDF* get_kdf(const std::string& algo_spec) #if defined(BOTAN_HAS_X942_PRF) if(request.algo_name() == "X9.42-PRF" && request.arg_count() == 1) - return new X942_PRF(request.arg_as_string(0)); // OID + return new X942_PRF(request.arg(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 985f61cf8..5fa0291c8 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(); - SCAN_Name digest_name = request.arg(0); - const std::string cipher = request.arg_as_string(1); + std::string digest_name = request.arg(0); + const std::string cipher = request.arg(1); std::vector<std::string> cipher_spec = split_on(cipher, '/'); if(cipher_spec.size() != 2) @@ -48,7 +48,7 @@ PBE* get_pbe(const std::string& algo_spec) const HashFunction* hash_function = af.make_hash_function(digest_name); if(!hash_function) - throw Algorithm_Not_Found(digest_name.as_string()); + throw Algorithm_Not_Found(digest_name); 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()); - SCAN_Name digest_name = request.arg(0); - const std::string cipher = request.arg_as_string(1); + std::string digest_name = request.arg(0); + const std::string cipher = request.arg(1); std::vector<std::string> cipher_spec = split_on(cipher, '/'); if(cipher_spec.size() != 2) @@ -105,7 +105,7 @@ PBE* get_pbe(const OID& pbe_oid, DataSource& params) const HashFunction* hash_function = af.make_hash_function(digest_name); if(!hash_function) - throw Algorithm_Not_Found(digest_name.as_string()); + throw Algorithm_Not_Found(digest_name); PBE* pbe = new PBE_PKCS5v15(block_cipher->clone(), hash_function->clone(), diff --git a/src/pbe/pbes2/pbes2.cpp b/src/pbe/pbes2/pbes2.cpp index 25be6f98a..3935bd702 100644 --- a/src/pbe/pbes2/pbes2.cpp +++ b/src/pbe/pbes2/pbes2.cpp @@ -176,7 +176,7 @@ void PBE_PKCS5v20::decode_params(DataSource& source) BER_Decoder(enc_algo.parameters).decode(iv, OCTET_STRING).verify_end(); block_cipher = af.make_block_cipher(cipher_spec[0]); - hash_function = af.make_hash_function(SCAN_Name("SHA-160")); + hash_function = af.make_hash_function("SHA-160"); if(key_length == 0) key_length = block_cipher->MAXIMUM_KEYLENGTH; diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp index f18ab5f7e..4222dc3c9 100644 --- a/src/selftest/selftest.cpp +++ b/src/selftest/selftest.cpp @@ -80,7 +80,7 @@ bool passes_self_tests(Algorithm_Factory& af) { try { - if(const BlockCipher* proto = af.prototype_block_cipher(SCAN_Name("DES"))) + if(const BlockCipher* proto = af.prototype_block_cipher("DES")) { cipher_kat(proto, "0123456789ABCDEF", "1234567890ABCDEF", @@ -92,7 +92,7 @@ bool passes_self_tests(Algorithm_Factory& af) "F3096249C7F46E51163A8CA0FFC94C27FA2F80F480B86F75"); } - if(const BlockCipher* proto = af.prototype_block_cipher(SCAN_Name("TripleDES"))) + if(const BlockCipher* proto = af.prototype_block_cipher("TripleDES")) { cipher_kat(proto, "385D7189A5C3D485E1370AA5D408082B5CCCCB5E19F2D90E", @@ -105,7 +105,7 @@ bool passes_self_tests(Algorithm_Factory& af) "E26BA806A59B03303C62C2EFF32D3ACDD5D5F35EBCC53371"); } - if(const BlockCipher* proto = af.prototype_block_cipher(SCAN_Name("AES"))) + if(const BlockCipher* proto = af.prototype_block_cipher("AES")) { cipher_kat(proto, "2B7E151628AED2A6ABF7158809CF4F3C", @@ -124,7 +124,7 @@ bool passes_self_tests(Algorithm_Factory& af) "010C041999E03F36448624483E582D0E"); } - if(const HashFunction* proto = af.prototype_hash_function(SCAN_Name("SHA-1"))) + if(const HashFunction* proto = af.prototype_hash_function("SHA-1")) { do_kat("", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", proto->name(), new Hash_Filter(proto->clone())); @@ -144,7 +144,7 @@ bool passes_self_tests(Algorithm_Factory& af) SymmetricKey("0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"))); } - if(const HashFunction* proto = af.prototype_hash_function(SCAN_Name("SHA-256"))) + if(const HashFunction* proto = af.prototype_hash_function("SHA-256")) { do_kat("", "E3B0C44298FC1C149AFBF4C8996FB924" diff --git a/src/utils/scan_name.cpp b/src/utils/scan_name.cpp index f5a1a9245..c0e931e14 100644 --- a/src/utils/scan_name.cpp +++ b/src/utils/scan_name.cpp @@ -40,11 +40,9 @@ parse_and_deref_aliases(const std::string& algo_spec) } -SCAN_Name::SCAN_Name(const std::string& algo_spec, - const std::string& provider) +SCAN_Name::SCAN_Name(const std::string& algo_spec) { orig_algo_spec = algo_spec; - m_provider = provider; name = parse_and_deref_aliases(algo_spec); @@ -52,15 +50,7 @@ SCAN_Name::SCAN_Name(const std::string& algo_spec, throw Decoding_Error("Bad SCAN name " + algo_spec); } -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], m_provider); - } - -std::string SCAN_Name::arg_as_string(u32bit i) const +std::string SCAN_Name::arg(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 b01411c94..4e391c37d 100644 --- a/src/utils/scan_name.h +++ b/src/utils/scan_name.h @@ -22,10 +22,8 @@ class SCAN_Name public: /** @param algo_spec A SCAN name - @param providers An optional provider name */ - SCAN_Name(const std::string& algo_spec, - const std::string& providers = ""); + SCAN_Name(const std::string& algo_spec); /** @return the original input string @@ -33,11 +31,6 @@ class SCAN_Name std::string as_string() const { return orig_algo_spec; } /** - @return the provider name (or empty) - */ - std::string provider() const { return m_provider; } - - /** @return the algorithm name */ std::string algo_name() const { return name[0]; } @@ -48,15 +41,6 @@ class SCAN_Name u32bit arg_count() const { return name.size() - 1; } /** - @param provider a provider name - @returns if this provider was allowed by the request - */ - bool provider_allowed(const std::string& provider) const - { - return (m_provider == "" || m_provider == provider); - } - - /** @return if the number of arguments is between lower and upper */ bool arg_count_between(u32bit lower, u32bit upper) const @@ -66,13 +50,7 @@ class SCAN_Name @param i which argument @return the ith argument */ - std::string arg_as_string(u32bit i) const; - - /** - @param i which argument - @return the ith argument - */ - SCAN_Name arg(u32bit i) const; + std::string arg(u32bit i) const; /** @param i which argument @@ -80,7 +58,7 @@ class SCAN_Name */ u32bit arg_as_u32bit(u32bit i, u32bit def_value) const; private: - std::string orig_algo_spec, m_provider; + std::string orig_algo_spec; std::vector<std::string> name; }; |