diff options
author | Pieter Wuille <pieter@wuille.net> | 2023-08-17 15:37:41 -0400 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2023-08-17 15:37:41 -0400 |
commit | 57cc136282c38825e97bbf85728df4bdf1ccc648 (patch) | |
tree | 6d45fc64b0fae213556b10cacf5797c8d9708edf /src/crypto | |
parent | da0ec62e34cc56bf8990e28c6ec12683d4752305 (diff) |
crypto: make ChaCha20::SetKey wipe buffer
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/chacha20.cpp | 7 | ||||
-rw-r--r-- | src/crypto/chacha20.h | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/crypto/chacha20.cpp b/src/crypto/chacha20.cpp index 143179f905..a3cc87e81b 100644 --- a/src/crypto/chacha20.cpp +++ b/src/crypto/chacha20.cpp @@ -335,6 +335,13 @@ ChaCha20::~ChaCha20() memory_cleanse(m_buffer.data(), m_buffer.size()); } +void ChaCha20::SetKey(Span<const std::byte> key) noexcept +{ + m_aligned.SetKey(key); + m_bufleft = 0; + memory_cleanse(m_buffer.data(), m_buffer.size()); +} + FSChaCha20::FSChaCha20(Span<const std::byte> key, uint32_t rekey_interval) noexcept : m_chacha20(key), m_rekey_interval(rekey_interval) { diff --git a/src/crypto/chacha20.h b/src/crypto/chacha20.h index 4d16961609..5f0f1ff64b 100644 --- a/src/crypto/chacha20.h +++ b/src/crypto/chacha20.h @@ -95,11 +95,7 @@ public: ~ChaCha20(); /** Set 32-byte key, and seek to nonce 0 and block position 0. */ - void SetKey(Span<const std::byte> key) noexcept - { - m_aligned.SetKey(key); - m_bufleft = 0; - } + void SetKey(Span<const std::byte> key) noexcept; /** 96-bit nonce type. */ using Nonce96 = ChaCha20Aligned::Nonce96; |