18 assert(key.size() == KEYLEN);
23 assert(key.size() == KEYLEN);
24 m_chacha20.SetKey(key);
31 const unsigned char *
p1 =
b1, *
p2 =
b2;
41 static const std::byte
PADDING[16] = {{}};
74 m_chacha20.Seek(
nonce, 1);
79 m_chacha20.Seek(
nonce, 0);
80 ComputeTag(m_chacha20,
aad, cipher.first(cipher.size() - EXPANSION), cipher.last(EXPANSION));
88 m_chacha20.Seek(
nonce, 0);
102 m_chacha20.Seek(
nonce, 1);
126 m_aead.Encrypt(
plain1,
plain2,
aad, {m_packet_counter, m_rekey_counter}, cipher);
132 bool ret = m_aead.Decrypt(cipher,
aad, {m_packet_counter, m_rekey_counter},
plain1,
plain2);
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.
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.
static constexpr unsigned BLOCKLEN
Block size (inputs/outputs to Keystream / Crypt should be multiples of this).
Unrestricted ChaCha20 cipher.
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.
C++ wrapper with std::byte span interface around poly1305_donna code.
Poly1305 & Update(std::span< const std::byte > msg) noexcept
Process message bytes.
static constexpr unsigned KEYLEN
Length of the keys expected by the constructor.
static constexpr unsigned TAGLEN
Length of the output produced by Finalize().
void memory_cleanse(void *ptr, size_t len)
Secure overwrite a buffer (possibly containing secret data) with zero-bytes.
void WriteLE64(B *ptr, uint64_t x)
unsigned char * UCharCast(char *c)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.