diff options
author | lloyd <[email protected]> | 2015-03-04 04:30:20 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-03-04 04:30:20 +0000 |
commit | 2591a2cd863696b91128ff4a8461bb96d497e7b4 (patch) | |
tree | acb7a179a0790ec63c0c21ecb2ea9d7939e05248 /src/lib/base | |
parent | c794f78bd9b7eebc58c39fd00de90b26fb4cfb67 (diff) |
Hide Algorithm_Factory and use the functions in lookup.h internally.
Fix two memory leaks (in TLS and modes) caused by calling get_foo and
then cloning the result before saving it (leaking the original object),
a holdover from the conversion between construction techniques in 1.11.14
Diffstat (limited to 'src/lib/base')
-rw-r--r-- | src/lib/base/algo_registry.h | 2 | ||||
-rw-r--r-- | src/lib/base/lookup.cpp | 32 | ||||
-rw-r--r-- | src/lib/base/lookup.h | 34 | ||||
-rw-r--r-- | src/lib/base/symkey.h | 1 |
4 files changed, 61 insertions, 8 deletions
diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h index e94c45541..63f376cc9 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/types.h> +#include <botan/lookup.h> #include <functional> #include <stdexcept> #include <mutex> diff --git a/src/lib/base/lookup.cpp b/src/lib/base/lookup.cpp index b6a49ec6b..6655a4fb4 100644 --- a/src/lib/base/lookup.cpp +++ b/src/lib/base/lookup.cpp @@ -44,6 +44,38 @@ MessageAuthenticationCode* get_mac(const std::string& algo_spec, const std::stri 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)); diff --git a/src/lib/base/lookup.h b/src/lib/base/lookup.h index c50186e35..d5b17237e 100644 --- a/src/lib/base/lookup.h +++ b/src/lib/base/lookup.h @@ -8,8 +8,10 @@ #ifndef BOTAN_LOOKUP_H__ #define BOTAN_LOOKUP_H__ -#include <botan/symkey.h> +#include <botan/types.h> #include <string> +#include <vector> +#include <memory> namespace Botan { @@ -31,7 +33,11 @@ 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 = ""); +BOTAN_DLL BlockCipher* get_block_cipher(const std::string& algo_spec, + const std::string& provider = ""); + +BOTAN_DLL std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec, + const std::string& provider = ""); BOTAN_DLL std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec); @@ -41,7 +47,11 @@ 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 = ""); +BOTAN_DLL StreamCipher* get_stream_cipher(const std::string& algo_spec, + const std::string& provider = ""); + +BOTAN_DLL std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec, + const std::string& provider = ""); BOTAN_DLL std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec); @@ -51,9 +61,14 @@ 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 = ""); +BOTAN_DLL HashFunction* get_hash_function(const std::string& algo_spec, + const std::string& provider = ""); -inline HashFunction* get_hash(const std::string& algo_spec, const std::string& provider = "") +BOTAN_DLL std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec, + const std::string& provider = ""); + +inline HashFunction* get_hash(const std::string& algo_spec, + const std::string& provider = "") { return get_hash_function(algo_spec, provider); } @@ -66,7 +81,11 @@ 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 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 = ""); BOTAN_DLL std::vector<std::string> get_mac_providers(const std::string& algo_spec); @@ -75,7 +94,8 @@ BOTAN_DLL std::vector<std::string> get_mac_providers(const std::string& algo_spe * @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 = ""); +BOTAN_DLL PBKDF* get_pbkdf(const std::string& algo_spec, + const std::string& provider = ""); } diff --git a/src/lib/base/symkey.h b/src/lib/base/symkey.h index f49bf226f..c837e8ca5 100644 --- a/src/lib/base/symkey.h +++ b/src/lib/base/symkey.h @@ -23,6 +23,7 @@ class BOTAN_DLL OctetString * @return size of this octet string in bytes */ size_t length() const { return bits.size(); } + size_t size() const { return bits.size(); } /** * @return this object as a secure_vector<byte> |