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/tls | |
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/tls')
-rw-r--r-- | src/lib/tls/tls_ciphersuite.cpp | 10 | ||||
-rw-r--r-- | src/lib/tls/tls_handshake_hash.cpp | 18 | ||||
-rw-r--r-- | src/lib/tls/tls_record.cpp | 4 |
3 files changed, 14 insertions, 18 deletions
diff --git a/src/lib/tls/tls_ciphersuite.cpp b/src/lib/tls/tls_ciphersuite.cpp index 31c688c51..c0f9dbf76 100644 --- a/src/lib/tls/tls_ciphersuite.cpp +++ b/src/lib/tls/tls_ciphersuite.cpp @@ -7,7 +7,7 @@ #include <botan/tls_ciphersuite.h> #include <botan/parsing.h> -#include <botan/internal/algo_registry.h> +#include <botan/lookup.h> #include <botan/block_cipher.h> #include <botan/stream_cipher.h> #include <botan/hash.h> @@ -104,16 +104,14 @@ namespace { bool have_hash(const std::string& prf) { - if(Algo_Registry<HashFunction>::global_registry().providers_of(prf).size() > 0) - return true; - return false; + return (!get_hash_function_providers(prf).empty()); } bool have_cipher(const std::string& cipher) { - if(Algo_Registry<BlockCipher>::global_registry().providers_of(cipher).size() > 0) + if(!get_block_cipher_providers(cipher).empty()) return true; - if(Algo_Registry<StreamCipher>::global_registry().providers_of(cipher).size() > 0) + if(!get_stream_cipher_providers(cipher).empty()) return true; return false; } diff --git a/src/lib/tls/tls_handshake_hash.cpp b/src/lib/tls/tls_handshake_hash.cpp index 76766c5fc..94c2774c5 100644 --- a/src/lib/tls/tls_handshake_hash.cpp +++ b/src/lib/tls/tls_handshake_hash.cpp @@ -7,7 +7,7 @@ #include <botan/internal/tls_handshake_hash.h> #include <botan/tls_exceptn.h> -#include <botan/internal/algo_registry.h> +#include <botan/lookup.h> #include <botan/hash.h> namespace Botan { @@ -20,18 +20,16 @@ namespace TLS { secure_vector<byte> Handshake_Hash::final(Protocol_Version version, const std::string& mac_algo) const { - std::unique_ptr<HashFunction> hash; + auto choose_hash = [=]() { + if(!version.supports_ciphersuite_specific_prf()) + return "Parallel(MD5,SHA-160)";; - if(version.supports_ciphersuite_specific_prf()) - { if(mac_algo == "MD5" || mac_algo == "SHA-1") - hash.reset(make_a<HashFunction>("SHA-256")); - else - hash.reset(make_a<HashFunction>(mac_algo)); - } - else - hash.reset(make_a<HashFunction>("Parallel(MD5,SHA-160)")); + return "SHA-256"; + return mac_algo.c_str(); + }; + std::unique_ptr<HashFunction> hash(make_hash_function(choose_hash())); hash->update(data); return hash->final(); } diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp index 521e7e4c1..6ccb31165 100644 --- a/src/lib/tls/tls_record.cpp +++ b/src/lib/tls/tls_record.cpp @@ -65,7 +65,7 @@ Connection_Cipher_State::Connection_Cipher_State(Protocol_Version version, if(BlockCipher* bc = get_block_cipher(cipher_algo)) { - m_block_cipher.reset(bc->clone()); + m_block_cipher.reset(bc); m_block_cipher->set_key(cipher_key); m_block_cipher_cbc_state = iv.bits_of(); m_block_size = bc->block_size(); @@ -75,7 +75,7 @@ Connection_Cipher_State::Connection_Cipher_State(Protocol_Version version, } else if(StreamCipher* sc = get_stream_cipher(cipher_algo)) { - m_stream_cipher.reset(sc->clone()); + m_stream_cipher.reset(sc); m_stream_cipher->set_key(cipher_key); } else |