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