Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
FSChaCha20Poly1305 Class Reference

Forward-secure wrapper around AEADChaCha20Poly1305. More...

#include <chacha20poly1305.h>

Collaboration diagram for FSChaCha20Poly1305:
[legend]

Public Member Functions

 FSChaCha20Poly1305 (const FSChaCha20Poly1305 &)=delete
 FSChaCha20Poly1305 (FSChaCha20Poly1305 &&)=delete
FSChaCha20Poly1305operator= (const FSChaCha20Poly1305 &)=delete
FSChaCha20Poly1305operator= (FSChaCha20Poly1305 &&)=delete
 FSChaCha20Poly1305 (std::span< const std::byte > key, uint32_t rekey_interval) noexcept
 Construct an FSChaCha20Poly1305 cipher that rekeys every rekey_interval operations.
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.
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
 Encrypt a message (given split into plain1 + plain2) with a specified aad.
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.
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
 Decrypt a message with a specified aad and split the result.

Static Public Attributes

static constexpr auto KEYLEN = AEADChaCha20Poly1305::KEYLEN
 Length of keys expected by the constructor.
static constexpr auto EXPANSION = AEADChaCha20Poly1305::EXPANSION
 Expansion when encrypting.

Private Member Functions

void NextPacket () noexcept
 Update counters (and if necessary, key) to transition to the next message.

Private Attributes

AEADChaCha20Poly1305 m_aead
 Internal AEAD.
const uint32_t m_rekey_interval
 Every how many iterations this cipher rekeys.
uint32_t m_packet_counter {0}
 The number of encryptions/decryptions since the last rekey.
uint64_t m_rekey_counter {0}
 The number of rekeys performed so far.

Detailed Description

Forward-secure wrapper around AEADChaCha20Poly1305.

This implements an AEAD which automatically increments the nonce on every encryption or decryption, and cycles keys after a predetermined number of encryptions or decryptions.

See BIP324 for details.

Definition at line 82 of file chacha20poly1305.h.

Constructor & Destructor Documentation

◆ FSChaCha20Poly1305() [1/3]

FSChaCha20Poly1305::FSChaCha20Poly1305 ( const FSChaCha20Poly1305 & )
delete
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FSChaCha20Poly1305() [2/3]

FSChaCha20Poly1305::FSChaCha20Poly1305 ( FSChaCha20Poly1305 && )
delete
Here is the call graph for this function:

◆ FSChaCha20Poly1305() [3/3]

FSChaCha20Poly1305::FSChaCha20Poly1305 ( std::span< const std::byte > key,
uint32_t rekey_interval )
inlinenoexcept

Construct an FSChaCha20Poly1305 cipher that rekeys every rekey_interval operations.

Definition at line 114 of file chacha20poly1305.h.

Here is the call graph for this function:

Member Function Documentation

◆ Decrypt() [1/2]

bool FSChaCha20Poly1305::Decrypt ( std::span< const std::byte > cipher,
std::span< const std::byte > aad,
std::span< std::byte > plain )
inlinenoexcept

Decrypt a message with a specified aad.

Returns true if valid.

Requires cipher.size() = plain.size() + EXPANSION.

Definition at line 136 of file chacha20poly1305.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Decrypt() [2/2]

bool 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

Decrypt a message with a specified aad and split the result.

Returns true if valid.

Requires cipher.size() = plain1.size() + plain2.size() + EXPANSION.

Definition at line 130 of file chacha20poly1305.cpp.

Here is the call graph for this function:

◆ Encrypt() [1/2]

void FSChaCha20Poly1305::Encrypt ( std::span< const std::byte > plain,
std::span< const std::byte > aad,
std::span< std::byte > cipher )
inlinenoexcept

Encrypt a message with a specified aad.

Requires cipher.size() = plain.size() + EXPANSION.

Definition at line 121 of file chacha20poly1305.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Encrypt() [2/2]

void 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

Encrypt a message (given split into plain1 + plain2) with a specified aad.

Requires cipher.size() = plain.size() + EXPANSION.

Definition at line 124 of file chacha20poly1305.cpp.

Here is the call graph for this function:

◆ NextPacket()

void FSChaCha20Poly1305::NextPacket ( )
privatenoexcept

Update counters (and if necessary, key) to transition to the next message.

Definition at line 106 of file chacha20poly1305.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

FSChaCha20Poly1305 & FSChaCha20Poly1305::operator= ( const FSChaCha20Poly1305 & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

FSChaCha20Poly1305 & FSChaCha20Poly1305::operator= ( FSChaCha20Poly1305 && )
delete
Here is the call graph for this function:

Member Data Documentation

◆ EXPANSION

auto FSChaCha20Poly1305::EXPANSION = AEADChaCha20Poly1305::EXPANSION
staticconstexpr

Expansion when encrypting.

Definition at line 105 of file chacha20poly1305.h.

◆ KEYLEN

auto FSChaCha20Poly1305::KEYLEN = AEADChaCha20Poly1305::KEYLEN
staticconstexpr

Length of keys expected by the constructor.

Definition at line 102 of file chacha20poly1305.h.

◆ m_aead

AEADChaCha20Poly1305 FSChaCha20Poly1305::m_aead
private

Internal AEAD.

Definition at line 86 of file chacha20poly1305.h.

◆ m_packet_counter

uint32_t FSChaCha20Poly1305::m_packet_counter {0}
private

The number of encryptions/decryptions since the last rekey.

Definition at line 92 of file chacha20poly1305.h.

◆ m_rekey_counter

uint64_t FSChaCha20Poly1305::m_rekey_counter {0}
private

The number of rekeys performed so far.

Definition at line 95 of file chacha20poly1305.h.

◆ m_rekey_interval

const uint32_t FSChaCha20Poly1305::m_rekey_interval
private

Every how many iterations this cipher rekeys.

Definition at line 89 of file chacha20poly1305.h.


The documentation for this class was generated from the following files: