diff options
author | lloyd <[email protected]> | 2014-01-18 21:26:38 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-18 21:26:38 +0000 |
commit | b3bffeff3553f4b609afe634c8c8b56ca0a2384c (patch) | |
tree | e81f39a9f86fcefffdf9e7704dd0b7a7c337edb7 /src/lib/kdf/prf_tls | |
parent | ef465af87d61c0cfbba17b86a3e1cc48b90ab391 (diff) |
More unique_ptr, also cleanup MGF1 usage
Diffstat (limited to 'src/lib/kdf/prf_tls')
-rw-r--r-- | src/lib/kdf/prf_tls/prf_tls.cpp | 35 | ||||
-rw-r--r-- | src/lib/kdf/prf_tls/prf_tls.h | 10 |
2 files changed, 16 insertions, 29 deletions
diff --git a/src/lib/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp index 006b418c9..6437932a8 100644 --- a/src/lib/kdf/prf_tls/prf_tls.cpp +++ b/src/lib/kdf/prf_tls/prf_tls.cpp @@ -19,13 +19,13 @@ namespace { * TLS PRF P_hash function */ void P_hash(secure_vector<byte>& output, - MessageAuthenticationCode* mac, + MessageAuthenticationCode& mac, const byte secret[], size_t secret_len, const byte seed[], size_t seed_len) { try { - mac->set_key(secret, secret_len); + mac.set_key(secret, secret_len); } catch(Invalid_Key_Length) { @@ -41,13 +41,13 @@ void P_hash(secure_vector<byte>& output, while(offset != output.size()) { const size_t this_block_len = - std::min<size_t>(mac->output_length(), output.size() - offset); + std::min<size_t>(mac.output_length(), output.size() - offset); - A = mac->process(A); + A = mac.process(A); - mac->update(A); - mac->update(seed, seed_len); - secure_vector<byte> block = mac->final(); + mac.update(A); + mac.update(seed, seed_len); + secure_vector<byte> block = mac.final(); xor_buf(&output[offset], &block[0], this_block_len); offset += this_block_len; @@ -61,14 +61,8 @@ void P_hash(secure_vector<byte>& output, */ TLS_PRF::TLS_PRF() { - hmac_md5 = new HMAC(new MD5); - hmac_sha1 = new HMAC(new SHA_160); - } - -TLS_PRF::~TLS_PRF() - { - delete hmac_md5; - delete hmac_sha1; + hmac_md5.reset(new HMAC(new MD5)); + hmac_sha1.reset(new HMAC(new SHA_160)); } /* @@ -85,8 +79,8 @@ secure_vector<byte> TLS_PRF::derive(size_t key_len, const byte* S1 = secret; const byte* S2 = secret + (secret_len - S2_len); - P_hash(output, hmac_md5, S1, S1_len, seed, seed_len); - P_hash(output, hmac_sha1, S2, S2_len, seed, seed_len); + P_hash(output, *hmac_md5, S1, S1_len, seed, seed_len); + P_hash(output, *hmac_sha1, S2, S2_len, seed, seed_len); return output; } @@ -98,18 +92,13 @@ TLS_12_PRF::TLS_12_PRF(MessageAuthenticationCode* mac) : hmac(mac) { } -TLS_12_PRF::~TLS_12_PRF() - { - delete hmac; - } - secure_vector<byte> TLS_12_PRF::derive(size_t key_len, const byte secret[], size_t secret_len, const byte seed[], size_t seed_len) const { secure_vector<byte> output(key_len); - P_hash(output, hmac, secret, secret_len, seed, seed_len); + P_hash(output, *hmac, secret, secret_len, seed, seed_len); return output; } diff --git a/src/lib/kdf/prf_tls/prf_tls.h b/src/lib/kdf/prf_tls/prf_tls.h index fce11eae0..654b7abdb 100644 --- a/src/lib/kdf/prf_tls/prf_tls.h +++ b/src/lib/kdf/prf_tls/prf_tls.h @@ -10,7 +10,7 @@ #include <botan/kdf.h> #include <botan/mac.h> -#include <botan/hash.h> +#include <memory> namespace Botan { @@ -28,10 +28,9 @@ class BOTAN_DLL TLS_PRF : public KDF KDF* clone() const { return new TLS_PRF; } TLS_PRF(); - ~TLS_PRF(); private: - MessageAuthenticationCode* hmac_md5; - MessageAuthenticationCode* hmac_sha1; + std::unique_ptr<MessageAuthenticationCode> hmac_md5; + std::unique_ptr<MessageAuthenticationCode> hmac_sha1; }; /** @@ -48,9 +47,8 @@ class BOTAN_DLL TLS_12_PRF : public KDF KDF* clone() const { return new TLS_12_PRF(hmac->clone()); } TLS_12_PRF(MessageAuthenticationCode* hmac); - ~TLS_12_PRF(); private: - MessageAuthenticationCode* hmac; + std::unique_ptr<MessageAuthenticationCode> hmac; }; } |