5#ifndef BITCOIN_CRYPTO_CHACHA20_H
6#define BITCOIN_CRYPTO_CHACHA20_H
32 static constexpr unsigned KEYLEN{32};
81 std::array<std::byte, ChaCha20Aligned::BLOCKLEN>
m_buffer;
82 unsigned m_bufleft{0};
137 uint32_t m_chunk_counter{0};
140 uint64_t m_rekey_counter{0};
ChaCha20 cipher that only operates on multiples of 64 bytes.
void Keystream(Span< std::byte > out) noexcept
outputs the keystream into out, whose length must be a multiple of BLOCKLEN.
void Crypt(Span< const std::byte > input, Span< std::byte > output) noexcept
en/deciphers the message <input> and write the result into <output>
ChaCha20Aligned() noexcept=delete
For safety, disallow initialization without key.
std::pair< uint32_t, uint64_t > Nonce96
Type for 96-bit nonces used by the Set function below.
void SetKey(Span< const std::byte > key) noexcept
Set 32-byte key, and seek to nonce 0 and block position 0.
void Seek(Nonce96 nonce, uint32_t block_counter) noexcept
Set the 96-bit nonce and 32-bit block counter.
static constexpr unsigned BLOCKLEN
Block size (inputs/outputs to Keystream / Crypt should be multiples of this).
static constexpr unsigned KEYLEN
Expected key length in constructor and SetKey.
Unrestricted ChaCha20 cipher.
ChaCha20() noexcept=delete
For safety, disallow initialization without key.
std::array< std::byte, ChaCha20Aligned::BLOCKLEN > m_buffer
void Seek(Nonce96 nonce, uint32_t block_counter) noexcept
Set the 96-bit nonce and 32-bit block counter.
ChaCha20Aligned m_aligned
ChaCha20Aligned::Nonce96 Nonce96
96-bit nonce type.
ChaCha20 m_chacha20
Internal stream cipher.
FSChaCha20 & operator=(const FSChaCha20 &)=delete
FSChaCha20(FSChaCha20 &&)=delete
const uint32_t m_rekey_interval
The number of encryptions/decryptions before a rekey happens.
FSChaCha20 & operator=(FSChaCha20 &&)=delete
FSChaCha20(const FSChaCha20 &)=delete
A Span is an object that can refer to a contiguous sequence of objects.