Skip to content

Commit 57cc136

Browse files
committed
crypto: make ChaCha20::SetKey wipe buffer
1 parent da0ec62 commit 57cc136

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/crypto/chacha20.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ ChaCha20::~ChaCha20()
335335
memory_cleanse(m_buffer.data(), m_buffer.size());
336336
}
337337

338+
void ChaCha20::SetKey(Span<const std::byte> key) noexcept
339+
{
340+
m_aligned.SetKey(key);
341+
m_bufleft = 0;
342+
memory_cleanse(m_buffer.data(), m_buffer.size());
343+
}
344+
338345
FSChaCha20::FSChaCha20(Span<const std::byte> key, uint32_t rekey_interval) noexcept :
339346
m_chacha20(key), m_rekey_interval(rekey_interval)
340347
{

src/crypto/chacha20.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ class ChaCha20
9595
~ChaCha20();
9696

9797
/** Set 32-byte key, and seek to nonce 0 and block position 0. */
98-
void SetKey(Span<const std::byte> key) noexcept
99-
{
100-
m_aligned.SetKey(key);
101-
m_bufleft = 0;
102-
}
98+
void SetKey(Span<const std::byte> key) noexcept;
10399

104100
/** 96-bit nonce type. */
105101
using Nonce96 = ChaCha20Aligned::Nonce96;

0 commit comments

Comments
 (0)