diff options
Diffstat (limited to 'src/lib/base')
-rw-r--r-- | src/lib/base/algo_registry.h | 10 | ||||
-rw-r--r-- | src/lib/base/buf_comp.h | 2 | ||||
-rw-r--r-- | src/lib/base/info.txt | 1 | ||||
-rw-r--r-- | src/lib/base/lookup.cpp | 109 | ||||
-rw-r--r-- | src/lib/base/lookup.h | 108 | ||||
-rw-r--r-- | src/lib/base/symkey.cpp | 1 | ||||
-rw-r--r-- | src/lib/base/transform.cpp | 20 |
7 files changed, 100 insertions, 151 deletions
diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h index 498021194..e16522d94 100644 --- a/src/lib/base/algo_registry.h +++ b/src/lib/base/algo_registry.h @@ -7,7 +7,7 @@ #ifndef BOTAN_ALGO_REGISTRY_H__ #define BOTAN_ALGO_REGISTRY_H__ -#include <botan/lookup.h> +#include <botan/types.h> #include <functional> #include <stdexcept> #include <mutex> @@ -35,7 +35,8 @@ class Algo_Registry void add(const std::string& name, const std::string& provider, maker_fn fn, byte pref) { std::unique_lock<std::mutex> lock(m_mutex); - m_algo_info[name].add_provider(provider, fn, pref); + if(!m_algo_info[name].add_provider(provider, fn, pref)) + throw std::runtime_error("Duplicated registration of " + name + "/" + provider); } std::vector<std::string> providers_of(const Spec& spec) @@ -102,13 +103,14 @@ class Algo_Registry struct Algo_Info { public: - void add_provider(const std::string& provider, maker_fn fn, byte pref) + bool add_provider(const std::string& provider, maker_fn fn, byte pref) { if(m_maker_fns.count(provider) > 0) - throw std::runtime_error("Duplicated registration of '" + provider + "'"); + return false; m_maker_fns[provider] = fn; m_prefs.insert(std::make_pair(pref, provider)); + return true; } std::vector<std::string> providers() const diff --git a/src/lib/base/buf_comp.h b/src/lib/base/buf_comp.h index 30e30c71c..d0793b84b 100644 --- a/src/lib/base/buf_comp.h +++ b/src/lib/base/buf_comp.h @@ -9,7 +9,7 @@ #define BOTAN_BUFFERED_COMPUTATION_H__ #include <botan/secmem.h> -#include <botan/get_byte.h> +#include <botan/loadstor.h> #include <string> namespace Botan { diff --git a/src/lib/base/info.txt b/src/lib/base/info.txt index 19eee6608..33d22a279 100644 --- a/src/lib/base/info.txt +++ b/src/lib/base/info.txt @@ -23,7 +23,6 @@ hash hex mac modes -pbkdf rng stream utils diff --git a/src/lib/base/lookup.cpp b/src/lib/base/lookup.cpp deleted file mode 100644 index 6655a4fb4..000000000 --- a/src/lib/base/lookup.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Algorithm Retrieval -* (C) 1999-2007,2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/lookup.h> -#include <botan/internal/algo_registry.h> -#include <botan/cipher_mode.h> -#include <botan/block_cipher.h> -#include <botan/stream_cipher.h> -#include <botan/hash.h> -#include <botan/mac.h> -#include <botan/pbkdf.h> - -namespace Botan { - -Transform* get_transform(const std::string& specstr, - const std::string& provider, - const std::string& dirstr) - { - Algo_Registry<Transform>::Spec spec(specstr, dirstr); - return Algo_Registry<Transform>::global_registry().make(spec, provider); - } - -BlockCipher* get_block_cipher(const std::string& algo_spec, const std::string& provider) - { - return make_a<BlockCipher>(algo_spec, provider); - } - -StreamCipher* get_stream_cipher(const std::string& algo_spec, const std::string& provider) - { - return make_a<StreamCipher>(algo_spec, provider); - } - -HashFunction* get_hash_function(const std::string& algo_spec, const std::string& provider) - { - return make_a<HashFunction>(algo_spec, provider); - } - -MessageAuthenticationCode* get_mac(const std::string& algo_spec, const std::string& provider) - { - return make_a<MessageAuthenticationCode>(algo_spec, provider); - } - -std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec, - const std::string& provider) - { - if(auto x = get_block_cipher(algo_spec, provider)) - return std::unique_ptr<BlockCipher>(x); - throw Algorithm_Not_Found(algo_spec); - } - -std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec, - const std::string& provider) - { - if(auto x = get_stream_cipher(algo_spec, provider)) - return std::unique_ptr<StreamCipher>(x); - throw Algorithm_Not_Found(algo_spec); - } - -std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec, - const std::string& provider) - { - if(auto x = get_hash_function(algo_spec, provider)) - return std::unique_ptr<HashFunction>(x); - throw Algorithm_Not_Found(algo_spec); - } - -std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec, - const std::string& provider) - { - if(auto x = get_mac(algo_spec, provider)) - return std::unique_ptr<MessageAuthenticationCode>(x); - throw Algorithm_Not_Found(algo_spec); - } - -std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec) - { - return providers_of<BlockCipher>(BlockCipher::Spec(algo_spec)); - } - -std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec) - { - return providers_of<StreamCipher>(StreamCipher::Spec(algo_spec)); - } - -std::vector<std::string> get_hash_function_providers(const std::string& algo_spec) - { - return providers_of<HashFunction>(HashFunction::Spec(algo_spec)); - } - -std::vector<std::string> get_mac_providers(const std::string& algo_spec) - { - return providers_of<MessageAuthenticationCode>(MessageAuthenticationCode::Spec(algo_spec)); - } - -/* -* Get a PBKDF algorithm by name -*/ -PBKDF* get_pbkdf(const std::string& algo_spec, const std::string& provider) - { - if(PBKDF* pbkdf = make_a<PBKDF>(algo_spec, provider)) - return pbkdf; - throw Algorithm_Not_Found(algo_spec); - } - -} diff --git a/src/lib/base/lookup.h b/src/lib/base/lookup.h index d5b17237e..9595d1f06 100644 --- a/src/lib/base/lookup.h +++ b/src/lib/base/lookup.h @@ -8,19 +8,17 @@ #ifndef BOTAN_LOOKUP_H__ #define BOTAN_LOOKUP_H__ -#include <botan/types.h> +#include <botan/block_cipher.h> +#include <botan/stream_cipher.h> +#include <botan/hash.h> +#include <botan/mac.h> +#include <botan/exceptn.h> #include <string> #include <vector> #include <memory> namespace Botan { -class BlockCipher; -class StreamCipher; -class HashFunction; -class MessageAuthenticationCode; -class PBKDF; - /* * Get an algorithm object * NOTE: these functions create and return new objects, letting the @@ -33,13 +31,25 @@ class PBKDF; * @param algo_spec the name of the desired block cipher * @return pointer to the block cipher object */ -BOTAN_DLL BlockCipher* get_block_cipher(const std::string& algo_spec, - const std::string& provider = ""); +inline BlockCipher* get_block_cipher(const std::string& algo_spec, + const std::string& provider = "") + { + return BlockCipher::create(algo_spec, provider).release(); + } -BOTAN_DLL std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec, - const std::string& provider = ""); +inline std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec, + const std::string& provider = "") + { + std::unique_ptr<BlockCipher> p(BlockCipher::create(algo_spec, provider)); + if(p) + return p; + throw Algorithm_Not_Found(algo_spec); + } -BOTAN_DLL std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec); +inline std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec) + { + return BlockCipher::providers(algo_spec); + } /** * Stream cipher factory method. @@ -47,13 +57,25 @@ BOTAN_DLL std::vector<std::string> get_block_cipher_providers(const std::string& * @param algo_spec the name of the desired stream cipher * @return pointer to the stream cipher object */ -BOTAN_DLL StreamCipher* get_stream_cipher(const std::string& algo_spec, - const std::string& provider = ""); +inline StreamCipher* get_stream_cipher(const std::string& algo_spec, + const std::string& provider = "") + { + return StreamCipher::create(algo_spec, provider).release(); + } -BOTAN_DLL std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec, - const std::string& provider = ""); +inline std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec, + const std::string& provider = "") + { + std::unique_ptr<StreamCipher> p(StreamCipher::create(algo_spec, provider)); + if(p) + return p; + throw Algorithm_Not_Found(algo_spec); + } -BOTAN_DLL std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec); +inline std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec) + { + return StreamCipher::providers(algo_spec); + } /** * Hash function factory method. @@ -61,11 +83,20 @@ BOTAN_DLL std::vector<std::string> get_stream_cipher_providers(const std::string * @param algo_spec the name of the desired hash function * @return pointer to the hash function object */ -BOTAN_DLL HashFunction* get_hash_function(const std::string& algo_spec, - const std::string& provider = ""); +inline HashFunction* get_hash_function(const std::string& algo_spec, + const std::string& provider = "") + { + return HashFunction::create(algo_spec, provider).release(); + } -BOTAN_DLL std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec, - const std::string& provider = ""); +inline std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec, + const std::string& provider = "") + { + std::unique_ptr<HashFunction> p(HashFunction::create(algo_spec, provider)); + if(p) + return p; + throw Algorithm_Not_Found(algo_spec); + } inline HashFunction* get_hash(const std::string& algo_spec, const std::string& provider = "") @@ -73,7 +104,10 @@ inline HashFunction* get_hash(const std::string& algo_spec, return get_hash_function(algo_spec, provider); } -BOTAN_DLL std::vector<std::string> get_hash_function_providers(const std::string& algo_spec); +inline std::vector<std::string> get_hash_function_providers(const std::string& algo_spec) + { + return HashFunction::providers(algo_spec); + } /** * MAC factory method. @@ -81,21 +115,25 @@ BOTAN_DLL std::vector<std::string> get_hash_function_providers(const std::string * @param algo_spec the name of the desired MAC * @return pointer to the MAC object */ -BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string& algo_spec, - const std::string& provider = ""); - -BOTAN_DLL std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec, - const std::string& provider = ""); +inline MessageAuthenticationCode* get_mac(const std::string& algo_spec, + const std::string& provider = "") + { + return MessageAuthenticationCode::create(algo_spec, provider).release(); + } -BOTAN_DLL std::vector<std::string> get_mac_providers(const std::string& algo_spec); +inline std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec, + const std::string& provider = "") + { + std::unique_ptr<MessageAuthenticationCode> p(MessageAuthenticationCode::create(algo_spec, provider)); + if(p) + return p; + throw Algorithm_Not_Found(algo_spec); + } -/** -* Password based key derivation function factory method -* @param algo_spec the name of the desired PBKDF algorithm -* @return pointer to newly allocated object of that type -*/ -BOTAN_DLL PBKDF* get_pbkdf(const std::string& algo_spec, - const std::string& provider = ""); +inline std::vector<std::string> get_mac_providers(const std::string& algo_spec) + { + return MessageAuthenticationCode::providers(algo_spec); + } } diff --git a/src/lib/base/symkey.cpp b/src/lib/base/symkey.cpp index 88642747b..2c98da051 100644 --- a/src/lib/base/symkey.cpp +++ b/src/lib/base/symkey.cpp @@ -6,7 +6,6 @@ */ #include <botan/symkey.h> -#include <botan/internal/xor_buf.h> #include <botan/rng.h> #include <botan/hex.h> #include <algorithm> diff --git a/src/lib/base/transform.cpp b/src/lib/base/transform.cpp new file mode 100644 index 000000000..8f05a33ad --- /dev/null +++ b/src/lib/base/transform.cpp @@ -0,0 +1,20 @@ +/* +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include <botan/internal/algo_registry.h> +#include <botan/transform.h> + +namespace Botan { + +Transform* get_transform(const std::string& specstr, + const std::string& provider, + const std::string& dirstr) + { + Algo_Registry<Transform>::Spec spec(specstr, dirstr); + return Algo_Registry<Transform>::global_registry().make(spec, provider); + } + +} |