diff options
author | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
commit | 0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch) | |
tree | ed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/libstate | |
parent | f9a7c85b74be0f4a7273e8e0591703af83036e81 (diff) |
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry
The shared pool of entropy sources remains but is moved to EntropySource.
With that and few remaining initializations (default OIDs and aliases)
moved elsewhere, the global state is empty and init and shutdown are no-ops.
Remove almost all of the headers and code for handling the global
state, except LibraryInitializer which remains as a compatability stub.
Update seeding for blinding so only one hacky almost-global RNG
instance needs to be setup instead of across all pubkey uses (it uses
either the system RNG or an AutoSeeded_RNG if the system RNG is not
available).
Diffstat (limited to 'src/lib/libstate')
-rw-r--r-- | src/lib/libstate/botan.h | 23 | ||||
-rw-r--r-- | src/lib/libstate/entropy_srcs.cpp | 121 | ||||
-rw-r--r-- | src/lib/libstate/global_state.cpp | 88 | ||||
-rw-r--r-- | src/lib/libstate/global_state.h | 69 | ||||
-rw-r--r-- | src/lib/libstate/info.txt | 21 | ||||
-rw-r--r-- | src/lib/libstate/init.cpp | 44 | ||||
-rw-r--r-- | src/lib/libstate/init.h | 31 | ||||
-rw-r--r-- | src/lib/libstate/libstate.cpp | 87 | ||||
-rw-r--r-- | src/lib/libstate/libstate.h | 54 | ||||
-rw-r--r-- | src/lib/libstate/lookup.cpp | 166 | ||||
-rw-r--r-- | src/lib/libstate/lookup.h | 275 |
11 files changed, 0 insertions, 979 deletions
diff --git a/src/lib/libstate/botan.h b/src/lib/libstate/botan.h deleted file mode 100644 index d586f5a21..000000000 --- a/src/lib/libstate/botan.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -* A vague catch all include file for Botan -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_BOTAN_H__ -#define BOTAN_BOTAN_H__ - -#include <botan/init.h> -#include <botan/lookup.h> -#include <botan/libstate.h> -#include <botan/version.h> -#include <botan/parsing.h> - -#include <botan/rng.h> - -#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) - #include <botan/auto_rng.h> -#endif - -#endif diff --git a/src/lib/libstate/entropy_srcs.cpp b/src/lib/libstate/entropy_srcs.cpp deleted file mode 100644 index de146d0ba..000000000 --- a/src/lib/libstate/entropy_srcs.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* -* Global PRNG -* (C) 2008-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/libstate.h> - -#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER) - #include <botan/internal/hres_timer.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND) - #include <botan/internal/rdrand.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM) - #include <botan/internal/dev_random.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_EGD) - #include <botan/internal/es_egd.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) - #include <botan/internal/unix_procs.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_BEOS) - #include <botan/internal/es_beos.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_CAPI) - #include <botan/internal/es_capi.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32) - #include <botan/internal/es_win32.h> -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER) - #include <botan/internal/proc_walk.h> -#endif - -namespace Botan { - -std::vector<std::unique_ptr<EntropySource>> Library_State::entropy_sources() - { - std::vector<std::unique_ptr<EntropySource>> sources; - -#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER) - sources.push_back(std::unique_ptr<EntropySource>(new High_Resolution_Timestamp)); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND) - sources.push_back(std::unique_ptr<EntropySource>(new Intel_Rdrand)); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) - sources.push_back(std::unique_ptr<EntropySource>(new UnixProcessInfo_EntropySource)); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM) - sources.push_back(std::unique_ptr<EntropySource>(new Device_EntropySource( - { "/dev/random", "/dev/srandom", "/dev/urandom" } - ))); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_CAPI) - sources.push_back(std::unique_ptr<EntropySource>(new Win32_CAPI_EntropySource)); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER) - sources.push_back(std::unique_ptr<EntropySource>( - new ProcWalking_EntropySource("/proc"))); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32) - sources.push_back(std::unique_ptr<EntropySource>(new Win32_EntropySource)); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_BEOS) - sources.push_back(std::unique_ptr<EntropySource>(new BeOS_EntropySource)); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER) - sources.push_back(std::unique_ptr<EntropySource>( - new Unix_EntropySource( - { "/bin", "/sbin", "/usr/bin", "/usr/sbin" } - ))); -#endif - -#if defined(BOTAN_HAS_ENTROPY_SRC_EGD) - sources.push_back(std::unique_ptr<EntropySource>( - new EGD_EntropySource({ "/var/run/egd-pool", "/dev/egd-pool" }) - )); -#endif - - return sources; - } - -void Library_State::poll_available_sources(class Entropy_Accumulator& accum) - { - std::lock_guard<std::mutex> lock(m_entropy_src_mutex); - - if(m_sources.empty()) - throw std::runtime_error("No entropy sources enabled at build time, poll failed"); - - size_t poll_attempt = 0; - - while(!accum.polling_goal_achieved() && poll_attempt < 16) - { - const size_t src_idx = poll_attempt % m_sources.size(); - m_sources[src_idx]->poll(accum); - ++poll_attempt; - } - } - -} - diff --git a/src/lib/libstate/global_state.cpp b/src/lib/libstate/global_state.cpp deleted file mode 100644 index b9b755d87..000000000 --- a/src/lib/libstate/global_state.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* -* Global State Management -* (C) 2010,2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/global_state.h> -#include <botan/libstate.h> -#include <memory> -#include <mutex> - -namespace Botan { - -namespace Global_State_Management { - -namespace { - -std::mutex g_lib_state_mutex; -std::unique_ptr<Library_State> g_lib_state; - -} - -/* -* Access the global state object -*/ -Library_State& global_state() - { - // @todo use double checked locking? (Is this safe in C++11 mm?) - std::lock_guard<std::mutex> lock(g_lib_state_mutex); - - /* Lazy initialization. Botan still needs to be deinitialized later - on or memory might leak. - */ - if(!g_lib_state) - { - g_lib_state.reset(new Library_State); - g_lib_state->initialize(); - } - - return (*g_lib_state); - } - -/* -* Set a new global state object -*/ -void set_global_state(Library_State* state) - { - std::lock_guard<std::mutex> lock(g_lib_state_mutex); - g_lib_state.reset(state); - } - -/* -* Set a new global state object unless one already existed -*/ -bool set_global_state_unless_set(Library_State* state) - { - std::lock_guard<std::mutex> lock(g_lib_state_mutex); - - if(g_lib_state) - return false; - - g_lib_state.reset(state); - return true; - } - -/* -* Swap two global state objects -*/ -Library_State* swap_global_state(Library_State* new_state) - { - std::lock_guard<std::mutex> lock(g_lib_state_mutex); - Library_State* old_state = g_lib_state.release(); - g_lib_state.reset(new_state); - return old_state; - } - -/* -* Query if library is initialized -*/ -bool global_state_exists() - { - return (g_lib_state != nullptr); - } - -} - -} diff --git a/src/lib/libstate/global_state.h b/src/lib/libstate/global_state.h deleted file mode 100644 index 6597b6606..000000000 --- a/src/lib/libstate/global_state.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* Global State Management -* (C) 2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_GLOBAL_STATE_H__ -#define BOTAN_GLOBAL_STATE_H__ - -#include <botan/build.h> - -namespace Botan { - -/* -* Forward declare to avoid recursive dependency between this header -* and libstate.h -*/ -class Library_State; - -/** -* Namespace for management of the global state -*/ -namespace Global_State_Management { - -/** -* Access the global library state -* @return reference to the global library state -*/ -BOTAN_DLL Library_State& global_state(); - -/** -* Set the global state object -* @param state the new global state to use -*/ -BOTAN_DLL void set_global_state(Library_State* state); - -/** -* Set the global state object unless it is already set -* @param state the new global state to use -* @return true if the state parameter is now being used as the global -* state, or false if one was already set, in which case the -* parameter was deleted immediately -*/ -BOTAN_DLL bool set_global_state_unless_set(Library_State* state); - -/** -* Swap the current state for another -* @param new_state the new state object to use -* @return previous state (or NULL if none) -*/ -BOTAN_DLL Library_State* swap_global_state(Library_State* new_state); - -/** -* Query if the library is currently initialized -* @return true iff the library is initialized -*/ -BOTAN_DLL bool global_state_exists(); - -} - -/* -* Insert into Botan ns for convenience/backwards compatability -*/ -using Global_State_Management::global_state; - -} - -#endif diff --git a/src/lib/libstate/info.txt b/src/lib/libstate/info.txt deleted file mode 100644 index 49a6d38ee..000000000 --- a/src/lib/libstate/info.txt +++ /dev/null @@ -1,21 +0,0 @@ -load_on always - -<requires> -algo_factory -alloc -bigint -block -core_engine -engine -filters -hash -hmac -kdf -mac -mode_pad -pbkdf -pk_pad -pubkey -rng -stream -</requires> diff --git a/src/lib/libstate/init.cpp b/src/lib/libstate/init.cpp deleted file mode 100644 index 6155b3bd2..000000000 --- a/src/lib/libstate/init.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Library initialization -* (C) 1999-2009.2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/init.h> -#include <botan/libstate.h> -#include <botan/global_state.h> - -namespace Botan { - -LibraryInitializer::LibraryInitializer() - { - /* - This two stage initialization process is because Library_State's - constructor will implicitly refer to global state through the - allocators and so forth, so global_state() has to be a valid - reference before initialize() can be called. Yeah, gross. - */ - m_owned = Global_State_Management::set_global_state_unless_set(new Library_State); - - if(m_owned) - { - try - { - global_state().initialize(); - } - catch(...) - { - Global_State_Management::set_global_state(nullptr); - throw; - } - } - } - -LibraryInitializer::~LibraryInitializer() - { - if(m_owned) - Global_State_Management::set_global_state(nullptr); - } - -} diff --git a/src/lib/libstate/init.h b/src/lib/libstate/init.h deleted file mode 100644 index 46bcc66fa..000000000 --- a/src/lib/libstate/init.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -* Library Initialization -* (C) 1999-2008 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_LIBRARY_INITIALIZER_H__ -#define BOTAN_LIBRARY_INITIALIZER_H__ - -#include <botan/build.h> -#include <string> - -namespace Botan { - -/** -* This class represents the Library Initialization/Shutdown Object. It -* has to exceed the lifetime of any Botan object used in an application. -*/ -class BOTAN_DLL LibraryInitializer - { - public: - LibraryInitializer(); - ~LibraryInitializer(); - private: - bool m_owned; - }; - -} - -#endif diff --git a/src/lib/libstate/libstate.cpp b/src/lib/libstate/libstate.cpp deleted file mode 100644 index a5010fc1a..000000000 --- a/src/lib/libstate/libstate.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -* Library Internal/Global State -* (C) 1999-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/libstate.h> -#include <botan/charset.h> -#include <botan/engine.h> -#include <botan/oids.h> -#include <botan/internal/core_engine.h> -#include <botan/internal/stl_util.h> -#include <algorithm> - -#if defined(BOTAN_HAS_ENGINE_ASSEMBLER) - #include <botan/internal/asm_engine.h> -#endif - -#if defined(BOTAN_HAS_ENGINE_AES_ISA) - #include <botan/internal/aes_isa_engine.h> -#endif - -#if defined(BOTAN_HAS_ENGINE_SIMD) - #include <botan/internal/simd_engine.h> -#endif - -#if defined(BOTAN_HAS_ENGINE_GNU_MP) - #include <botan/internal/gnump_engine.h> -#endif - -#if defined(BOTAN_HAS_ENGINE_OPENSSL) - #include <botan/internal/openssl_engine.h> -#endif - -namespace Botan { - -/* -* Return a reference to the Algorithm_Factory -*/ -Algorithm_Factory& Library_State::algorithm_factory() const - { - if(!m_algorithm_factory) - throw Invalid_State("Uninitialized in Library_State::algorithm_factory"); - return *m_algorithm_factory; - } - -Library_State::~Library_State() - { - } - -void Library_State::initialize() - { - SCAN_Name::set_default_aliases(); - OIDS::set_defaults(); - - if(m_algorithm_factory.get()) - throw Invalid_State("Library_State has already been initialized"); - - m_algorithm_factory.reset(new Algorithm_Factory()); - -#if defined(BOTAN_HAS_ENGINE_GNU_MP) - algorithm_factory().add_engine(new GMP_Engine); -#endif - -#if defined(BOTAN_HAS_ENGINE_OPENSSL) - algorithm_factory().add_engine(new OpenSSL_Engine); -#endif - -#if defined(BOTAN_HAS_ENGINE_AES_ISA) - algorithm_factory().add_engine(new AES_ISA_Engine); -#endif - -#if defined(BOTAN_HAS_ENGINE_SIMD) - algorithm_factory().add_engine(new SIMD_Engine); -#endif - -#if defined(BOTAN_HAS_ENGINE_ASSEMBLER) - algorithm_factory().add_engine(new Assembler_Engine); -#endif - - algorithm_factory().add_engine(new Core_Engine); - - m_sources = entropy_sources(); - } - -} diff --git a/src/lib/libstate/libstate.h b/src/lib/libstate/libstate.h deleted file mode 100644 index 908f92f4d..000000000 --- a/src/lib/libstate/libstate.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Library Internal/Global State -* (C) 1999-2008 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_LIB_STATE_H__ -#define BOTAN_LIB_STATE_H__ - -#include <botan/global_state.h> -#include <botan/algo_factory.h> -#include <botan/rng.h> -#include <mutex> -#include <string> -#include <vector> -#include <map> - -namespace Botan { - -/** -* Global Library State -*/ -class BOTAN_DLL Library_State - { - public: - Library_State() {} - - ~Library_State(); - - Library_State(const Library_State&) = delete; - Library_State& operator=(const Library_State&) = delete; - - void initialize(); - - /** - * @return global Algorithm_Factory - */ - Algorithm_Factory& algorithm_factory() const; - - void poll_available_sources(class Entropy_Accumulator& accum); - - private: - static std::vector<std::unique_ptr<EntropySource>> entropy_sources(); - - std::mutex m_entropy_src_mutex; - std::vector<std::unique_ptr<EntropySource>> m_sources; - - std::unique_ptr<Algorithm_Factory> m_algorithm_factory; - }; - -} - -#endif diff --git a/src/lib/libstate/lookup.cpp b/src/lib/libstate/lookup.cpp deleted file mode 100644 index 08f0ac866..000000000 --- a/src/lib/libstate/lookup.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* -* Algorithm Retrieval -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/lookup.h> -#include <botan/cipher_mode.h> -#include <botan/filters.h> -#include <botan/libstate.h> -#include <botan/parsing.h> -#include <botan/transform_filter.h> - -#if defined(BOTAN_HAS_OFB) - #include <botan/ofb.h> -#endif - -#if defined(BOTAN_HAS_CTR_BE) - #include <botan/ctr.h> -#endif - -namespace Botan { - -/* -* Get a PBKDF algorithm by name -*/ -PBKDF* get_pbkdf(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(PBKDF* pbkdf = af.make_pbkdf(algo_spec)) - return pbkdf; - - throw Algorithm_Not_Found(algo_spec); - } - -/* -* Query if an algorithm exists -*/ -bool have_algorithm(const std::string& name) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(af.prototype_block_cipher(name)) - return true; - if(af.prototype_stream_cipher(name)) - return true; - if(af.prototype_hash_function(name)) - return true; - if(af.prototype_mac(name)) - return true; - return false; - } - -/* -* Query the block size of a cipher or hash -*/ -size_t block_size_of(const std::string& name) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(const BlockCipher* cipher = af.prototype_block_cipher(name)) - return cipher->block_size(); - - if(const HashFunction* hash = af.prototype_hash_function(name)) - return hash->hash_block_size(); - - throw Algorithm_Not_Found(name); - } - -/* -* Query the output_length() of a hash or MAC -*/ -size_t output_length_of(const std::string& name) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(const HashFunction* hash = af.prototype_hash_function(name)) - return hash->output_length(); - - if(const MessageAuthenticationCode* mac = af.prototype_mac(name)) - return mac->output_length(); - - throw Algorithm_Not_Found(name); - } - -/* -* Get a cipher object -*/ -Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir direction) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - - std::unique_ptr<Cipher_Mode> c(get_cipher_mode(algo_spec, direction)); - if(c) - return new Transform_Filter(c.release()); - - std::vector<std::string> algo_parts = split_on(algo_spec, '/'); - if(algo_parts.empty()) - throw Invalid_Algorithm_Name(algo_spec); - - const std::string cipher_name = algo_parts[0]; - - // check if it is a stream cipher first (easy case) - const StreamCipher* stream_cipher = af.prototype_stream_cipher(cipher_name); - if(stream_cipher) - return new StreamCipher_Filter(stream_cipher->clone()); - - const BlockCipher* block_cipher = af.prototype_block_cipher(cipher_name); - if(!block_cipher) - return nullptr; - - if(algo_parts.size() >= 4) - return nullptr; // 4 part mode, not something we know about - - if(algo_parts.size() < 2) - throw Lookup_Error("Cipher specification '" + algo_spec + - "' is missing mode identifier"); - - const std::string mode = algo_parts[1]; - - -#if defined(BOTAN_HAS_OFB) - if(mode == "OFB") - return new StreamCipher_Filter(new OFB(block_cipher->clone())); -#endif - -#if defined(BOTAN_HAS_CTR_BE) - if(mode == "CTR-BE") - return new StreamCipher_Filter(new CTR_BE(block_cipher->clone())); -#endif - - throw Algorithm_Not_Found(algo_spec); - } - -/* -* Get a cipher object -*/ -Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - const InitializationVector& iv, - Cipher_Dir direction) - { - Keyed_Filter* cipher = get_cipher(algo_spec, direction); - cipher->set_key(key); - - if(iv.length()) - cipher->set_iv(iv); - - return cipher; - } - -/* -* Get a cipher object -*/ -Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - Cipher_Dir direction) - { - return get_cipher(algo_spec, - key, InitializationVector(), direction); - } - -} diff --git a/src/lib/libstate/lookup.h b/src/lib/libstate/lookup.h deleted file mode 100644 index 4350fbbd5..000000000 --- a/src/lib/libstate/lookup.h +++ /dev/null @@ -1,275 +0,0 @@ -/* -* Algorithm Lookup -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_LOOKUP_H__ -#define BOTAN_LOOKUP_H__ - -#include <botan/libstate.h> -#include <botan/filters.h> -#include <botan/mode_pad.h> -#include <botan/kdf.h> -#include <botan/eme.h> -#include <botan/emsa.h> -#include <botan/pbkdf.h> - -namespace Botan { - -/** -* Retrieve an object prototype from the global factory -* @param algo_spec an algorithm name -* @return constant prototype object (use clone to create usable object), - library retains ownership -*/ -inline const BlockCipher* -retrieve_block_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_block_cipher(algo_spec); - } - -/** -* Retrieve an object prototype from the global factory -* @param algo_spec an algorithm name -* @return constant prototype object (use clone to create usable object), - library retains ownership -*/ -inline const StreamCipher* -retrieve_stream_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_stream_cipher(algo_spec); - } - -/** -* Retrieve an object prototype from the global factory -* @param algo_spec an algorithm name -* @return constant prototype object (use clone to create usable object), - library retains ownership -*/ -inline const HashFunction* -retrieve_hash(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_hash_function(algo_spec); - } - -/** -* Retrieve an object prototype from the global factory -* @param algo_spec an algorithm name -* @return constant prototype object (use clone to create usable object), - library retains ownership -*/ -inline const MessageAuthenticationCode* -retrieve_mac(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_mac(algo_spec); - } - -/* -* Get an algorithm object -* NOTE: these functions create and return new objects, letting the -* caller assume ownership of them -*/ - -/** -* Block cipher factory method. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the desired block cipher -* @return pointer to the block cipher object -*/ -inline BlockCipher* get_block_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_block_cipher(algo_spec); - } - -/** -* Stream cipher factory method. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the desired stream cipher -* @return pointer to the stream cipher object -*/ -inline StreamCipher* get_stream_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_stream_cipher(algo_spec); - } - -/** -* Hash function factory method. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the desired hash function -* @return pointer to the hash function object -*/ -inline HashFunction* get_hash(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_hash_function(algo_spec); - } - -/** -* MAC factory method. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the desired MAC -* @return pointer to the MAC object -*/ -inline MessageAuthenticationCode* get_mac(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_mac(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); - -/** -* @deprecated Use get_pbkdf -* @param algo_spec the name of the desired algorithm -* @return pointer to newly allocated object of that type -*/ -inline PBKDF* get_s2k(const std::string& algo_spec) - { - return get_pbkdf(algo_spec); - } - -/* -* Get a cipher object -*/ - -/** -* Factory method for general symmetric cipher filters. -* @param algo_spec the name of the desired cipher -* @param key the key to be used for encryption/decryption performed by -* the filter -* @param iv the initialization vector to be used -* @param direction determines whether the filter will be an encrypting -* or decrypting filter -* @return pointer to newly allocated encryption or decryption filter -*/ -BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - const InitializationVector& iv, - Cipher_Dir direction); - -/** -* Factory method for general symmetric cipher filters. -* @param algo_spec the name of the desired cipher -* @param key the key to be used for encryption/decryption performed by -* the filter -* @param direction determines whether the filter will be an encrypting -* or decrypting filter -* @return pointer to the encryption or decryption filter -*/ -BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - Cipher_Dir direction); - -/** -* Factory method for general symmetric cipher filters. No key will be -* set in the filter. -* -* @param algo_spec the name of the desired cipher -* @param direction determines whether the filter will be an encrypting or -* decrypting filter -* @return pointer to the encryption or decryption filter -*/ -BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir direction); - -/** -* Check if an algorithm exists. -* @param algo_spec the name of the algorithm to check for -* @return true if the algorithm exists, false otherwise -*/ -BOTAN_DLL bool have_algorithm(const std::string& algo_spec); - -/** -* Check if a block cipher algorithm exists. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the algorithm to check for -* @return true if the algorithm exists, false otherwise -*/ -inline bool have_block_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return (af.prototype_block_cipher(algo_spec) != nullptr); - } - -/** -* Check if a stream cipher algorithm exists. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the algorithm to check for -* @return true if the algorithm exists, false otherwise -*/ -inline bool have_stream_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return (af.prototype_stream_cipher(algo_spec) != nullptr); - } - -/** -* Check if a hash algorithm exists. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the algorithm to check for -* @return true if the algorithm exists, false otherwise -*/ -inline bool have_hash(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return (af.prototype_hash_function(algo_spec) != nullptr); - } - -/** -* Check if a MAC algorithm exists. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the algorithm to check for -* @return true if the algorithm exists, false otherwise -*/ -inline bool have_mac(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return (af.prototype_mac(algo_spec) != nullptr); - } - -/* -* Query information about an algorithm -*/ - -/** -* Find out the block size of a certain symmetric algorithm. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the algorithm -* @return block size of the specified algorithm -*/ -BOTAN_DLL size_t block_size_of(const std::string& algo_spec); - -/** -* Find out the output length of a certain symmetric algorithm. -* @deprecated Call algorithm_factory() directly -* -* @param algo_spec the name of the algorithm -* @return output length of the specified algorithm -*/ -BOTAN_DLL size_t output_length_of(const std::string& algo_spec); - -} - -#endif |