aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2023-07-18 13:52:52 -0400
committerPieter Wuille <pieter@wuille.net>2023-08-17 15:31:27 -0400
commit7d1cd932342e74421ae927800eeada14f504b944 (patch)
tree5dda099aae936cf061c04bfa20731fd2e5ea4d90 /src/crypto
parent44c11769a83b90ca6b8af086d6fa69ff7ac1c3ae (diff)
crypto: require key on ChaCha20 initialization
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/chacha20.cpp5
-rw-r--r--src/crypto/chacha20.h6
2 files changed, 4 insertions, 7 deletions
diff --git a/src/crypto/chacha20.cpp b/src/crypto/chacha20.cpp
index 438e451c9a..143179f905 100644
--- a/src/crypto/chacha20.cpp
+++ b/src/crypto/chacha20.cpp
@@ -40,11 +40,6 @@ void ChaCha20Aligned::SetKey(Span<const std::byte> key) noexcept
input[11] = 0;
}
-ChaCha20Aligned::ChaCha20Aligned() noexcept
-{
- memset(input, 0, sizeof(input));
-}
-
ChaCha20Aligned::~ChaCha20Aligned()
{
memory_cleanse(input, sizeof(input));
diff --git a/src/crypto/chacha20.h b/src/crypto/chacha20.h
index a766f7d13c..4d16961609 100644
--- a/src/crypto/chacha20.h
+++ b/src/crypto/chacha20.h
@@ -34,7 +34,8 @@ public:
/** Block size (inputs/outputs to Keystream / Crypt should be multiples of this). */
static constexpr unsigned BLOCKLEN{64};
- ChaCha20Aligned() noexcept;
+ /** For safety, disallow initialization without key. */
+ ChaCha20Aligned() noexcept = delete;
/** Initialize a cipher with specified 32-byte key. */
ChaCha20Aligned(Span<const std::byte> key) noexcept;
@@ -84,7 +85,8 @@ public:
/** Expected key length in constructor and SetKey. */
static constexpr unsigned KEYLEN = ChaCha20Aligned::KEYLEN;
- ChaCha20() noexcept = default;
+ /** For safety, disallow initialization without key. */
+ ChaCha20() noexcept = delete;
/** Initialize a cipher with specified 32-byte key. */
ChaCha20(Span<const std::byte> key) noexcept : m_aligned(key) {}