29int timingsafe_bcmp_internal(
const unsigned char* b1,
const unsigned char* b2,
size_t n)
noexcept
31 const unsigned char *p1 = b1, *p2 = b2;
39void ComputeTag(
ChaCha20& chacha20, std::span<const std::byte> aad, std::span<const std::byte> cipher, std::span<std::byte> tag)
noexcept
41 static const std::byte PADDING[16] = {{}};
45 chacha20.Keystream(first_block);
52 const unsigned aad_padding_length = (16 - (aad.size() % 16)) % 16;
53 poly1305.
Update(aad).
Update(std::span{PADDING}.first(aad_padding_length));
55 const unsigned cipher_padding_length = (16 - (cipher.size() % 16)) % 16;
56 poly1305.
Update(cipher).
Update(std::span{PADDING}.first(cipher_padding_length));
60 WriteLE64(length_desc + 8, cipher.size());
61 poly1305.
Update(length_desc);
75 m_chacha20.Crypt(plain1, cipher.first(plain1.size()));
76 m_chacha20.Crypt(plain2, cipher.subspan(plain1.size()).first(plain2.size()));
94 m_chacha20.Crypt(cipher.first(plain1.size()), plain1);
95 m_chacha20.Crypt(cipher.subspan(plain1.size()).first(plain2.size()), plain2);
124void FSChaCha20Poly1305::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
130bool FSChaCha20Poly1305::Decrypt(std::span<const std::byte> cipher, std::span<const std::byte> aad, std::span<std::byte> plain1, std::span<std::byte> plain2)
noexcept
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.
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.
void Finalize(std::span< std::byte > out) noexcept
Write authentication tag to 16-byte out.
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)