5#ifndef BITCOIN_CRYPTO_CHACHA20POLY1305_H
6#define BITCOIN_CRYPTO_CHACHA20POLY1305_H
23 static constexpr unsigned KEYLEN = 32;
123 Encrypt(plain, {}, aad, cipher);
138 return Decrypt(cipher, aad, plain, {});
The AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC8439 section 2....
AEADChaCha20Poly1305(Span< const std::byte > key) noexcept
Initialize an AEAD instance with a specified 32-byte key.
ChaCha20::Nonce96 Nonce96
96-bit nonce type.
void Encrypt(Span< const std::byte > plain, Span< const std::byte > aad, Nonce96 nonce, Span< std::byte > cipher) noexcept
Encrypt a message with a specified 96-bit nonce and aad.
static constexpr unsigned EXPANSION
Expansion when encrypting.
void SetKey(Span< const std::byte > key) noexcept
Switch to another 32-byte key.
static constexpr unsigned KEYLEN
Expected size of key argument in constructor.
bool Decrypt(Span< const std::byte > cipher, Span< const std::byte > aad, Nonce96 nonce, Span< std::byte > plain) noexcept
Decrypt a message with a specified 96-bit nonce and aad.
void Keystream(Nonce96 nonce, Span< std::byte > keystream) noexcept
Get a number of keystream bytes from the underlying stream cipher.
ChaCha20 m_chacha20
Internal stream cipher.
Unrestricted ChaCha20 cipher.
ChaCha20Aligned::Nonce96 Nonce96
96-bit nonce type.
Forward-secure wrapper around AEADChaCha20Poly1305.
void NextPacket() noexcept
Update counters (and if necessary, key) to transition to the next message.
const uint32_t m_rekey_interval
Every how many iterations this cipher rekeys.
bool Decrypt(Span< const std::byte > cipher, Span< const std::byte > aad, Span< std::byte > plain) noexcept
Decrypt a message with a specified aad.
uint32_t m_packet_counter
The number of encryptions/decryptions since the last rekey.
AEADChaCha20Poly1305 m_aead
Internal AEAD.
static constexpr auto KEYLEN
Length of keys expected by the constructor.
uint64_t m_rekey_counter
The number of rekeys performed so far.
static constexpr auto EXPANSION
Expansion when encrypting.
void Encrypt(Span< const std::byte > plain, Span< const std::byte > aad, Span< std::byte > cipher) noexcept
Encrypt a message with a specified aad.
static constexpr unsigned TAGLEN
Length of the output produced by Finalize().