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/modes/aead/chacha20poly1305/chacha20poly1305.cpp | |
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/modes/aead/chacha20poly1305/chacha20poly1305.cpp')
-rw-r--r-- | src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp index 15fd8f959..37e0ef96b 100644 --- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp +++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp @@ -13,6 +13,11 @@ namespace Botan { BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Encryption); BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Decryption); +ChaCha20Poly1305_Mode::ChaCha20Poly1305_Mode() : + m_chacha(make_stream_cipher("ChaCha")), + m_poly1305(make_message_auth("Poly1305")) + {} + bool ChaCha20Poly1305_Mode::valid_nonce_length(size_t n) const { return (n == 8 || n == 12); @@ -20,16 +25,14 @@ bool ChaCha20Poly1305_Mode::valid_nonce_length(size_t n) const void ChaCha20Poly1305_Mode::clear() { - m_chacha.reset(); - m_poly1305.reset(); + m_chacha->clear(); + m_poly1305->clear(); m_ad.clear(); m_ctext_len = 0; } void ChaCha20Poly1305_Mode::key_schedule(const byte key[], size_t length) { - if(!m_chacha.get()) - m_chacha.reset(make_a<StreamCipher>("ChaCha")); m_chacha->set_key(key, length); } @@ -60,8 +63,6 @@ secure_vector<byte> ChaCha20Poly1305_Mode::start_raw(const byte nonce[], size_t secure_vector<byte> zeros(64); m_chacha->encrypt(zeros); - if(!m_poly1305.get()) - m_poly1305.reset(make_a<MessageAuthenticationCode>("Poly1305")); m_poly1305->set_key(&zeros[0], 32); // Remainder of output is discard |