5#ifndef BITCOIN_CRYPTO_CHACHA20POLY1305_H
6#define BITCOIN_CRYPTO_CHACHA20POLY1305_H
23 static constexpr unsigned KEYLEN = 32;
32 void SetKey(std::span<const std::byte> key)
noexcept;
41 void Encrypt(std::span<const std::byte> plain, std::span<const std::byte> aad,
Nonce96 nonce, std::span<std::byte> cipher)
noexcept
50 void Encrypt(std::span<const std::byte> plain1, std::span<const std::byte> plain2, std::span<const std::byte> aad,
Nonce96 nonce, std::span<std::byte> cipher)
noexcept;
56 bool Decrypt(std::span<const std::byte> cipher, std::span<const std::byte> aad,
Nonce96 nonce, std::span<std::byte> plain)
noexcept
65 bool Decrypt(std::span<const std::byte> cipher, std::span<const std::byte> aad,
Nonce96 nonce, std::span<std::byte> plain1, std::span<std::byte> plain2)
noexcept;
121 void Encrypt(std::span<const std::byte> plain, std::span<const std::byte> aad, std::span<std::byte> cipher)
noexcept
123 Encrypt(plain, {}, aad, cipher);
130 void Encrypt(std::span<const std::byte> plain1, std::span<const std::byte> plain2, std::span<const std::byte> aad, std::span<std::byte> cipher)
noexcept;
136 bool Decrypt(std::span<const std::byte> cipher, std::span<const std::byte> aad, std::span<std::byte> plain)
noexcept
138 return Decrypt(cipher, aad, plain, {});
145 bool Decrypt(std::span<const std::byte> cipher, std::span<const std::byte> aad, std::span<std::byte> plain1, std::span<std::byte> plain2)
noexcept;
The AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC8439 section 2....
ChaCha20::Nonce96 Nonce96
96-bit nonce type.
void Encrypt(std::span< const std::byte > plain, std::span< const std::byte > aad, Nonce96 nonce, std::span< std::byte > cipher) noexcept
Encrypt a message with a specified 96-bit nonce and aad.
bool Decrypt(std::span< const std::byte > cipher, std::span< const std::byte > aad, Nonce96 nonce, std::span< std::byte > plain) noexcept
Decrypt a message with a specified 96-bit nonce and aad.
static constexpr unsigned EXPANSION
Expansion when encrypting.
static constexpr unsigned KEYLEN
Expected size of key argument in constructor.
AEADChaCha20Poly1305(std::span< const std::byte > key) noexcept
Initialize an AEAD instance with a specified 32-byte key.
void SetKey(std::span< const std::byte > key) noexcept
Switch to another 32-byte key.
void Keystream(Nonce96 nonce, std::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.
uint32_t m_packet_counter
The number of encryptions/decryptions since the last rekey.
bool Decrypt(std::span< const std::byte > cipher, std::span< const std::byte > aad, std::span< std::byte > plain) noexcept
Decrypt a message with a specified aad.
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.
void Encrypt(std::span< const std::byte > plain, std::span< const std::byte > aad, std::span< std::byte > cipher) noexcept
Encrypt a message with a specified aad.
static constexpr auto EXPANSION
Expansion when encrypting.
static constexpr unsigned TAGLEN
Length of the output produced by Finalize().