Bitcoin Core  26.99.0
P2P Digital Currency
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
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 (Span< const std::byte > key, uint32_t rekey_interval) noexcept
 Construct an FSChaCha20Poly1305 cipher that rekeys every rekey_interval operations. More...
 
void Encrypt (Span< const std::byte > plain, Span< const std::byte > aad, Span< std::byte > cipher) noexcept
 Encrypt a message with a specified aad. More...
 
void Encrypt (Span< const std::byte > plain1, Span< const std::byte > plain2, Span< const std::byte > aad, Span< std::byte > cipher) noexcept
 Encrypt a message (given split into plain1 + plain2) with a specified aad. More...
 
bool Decrypt (Span< const std::byte > cipher, Span< const std::byte > aad, Span< std::byte > plain) noexcept
 Decrypt a message with a specified aad. More...
 
bool Decrypt (Span< const std::byte > cipher, Span< const std::byte > aad, Span< std::byte > plain1, Span< std::byte > plain2) noexcept
 Decrypt a message with a specified aad and split the result. More...
 

Static Public Attributes

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

Private Member Functions

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

Private Attributes

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

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

◆ FSChaCha20Poly1305() [2/3]

FSChaCha20Poly1305::FSChaCha20Poly1305 ( FSChaCha20Poly1305 &&  )
delete

◆ FSChaCha20Poly1305() [3/3]

FSChaCha20Poly1305::FSChaCha20Poly1305 ( 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.

Member Function Documentation

◆ Decrypt() [1/2]

bool FSChaCha20Poly1305::Decrypt ( Span< const std::byte >  cipher,
Span< const std::byte >  aad,
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 caller graph for this function:

◆ Decrypt() [2/2]

bool FSChaCha20Poly1305::Decrypt ( Span< const std::byte >  cipher,
Span< const std::byte >  aad,
Span< std::byte >  plain1,
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 139 of file chacha20poly1305.cpp.

◆ Encrypt() [1/2]

void FSChaCha20Poly1305::Encrypt ( Span< const std::byte >  plain,
Span< const std::byte >  aad,
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 caller graph for this function:

◆ Encrypt() [2/2]

void FSChaCha20Poly1305::Encrypt ( Span< const std::byte >  plain1,
Span< const std::byte >  plain2,
Span< const std::byte >  aad,
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 133 of file chacha20poly1305.cpp.

◆ NextPacket()

void FSChaCha20Poly1305::NextPacket ( )
privatenoexcept

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

Definition at line 115 of file chacha20poly1305.cpp.

Here is the call graph for this function:

◆ operator=() [1/2]

FSChaCha20Poly1305& FSChaCha20Poly1305::operator= ( const FSChaCha20Poly1305 )
delete

◆ operator=() [2/2]

FSChaCha20Poly1305& FSChaCha20Poly1305::operator= ( FSChaCha20Poly1305 &&  )
delete

Member Data Documentation

◆ EXPANSION

constexpr auto FSChaCha20Poly1305::EXPANSION = AEADChaCha20Poly1305::EXPANSION
staticconstexpr

Expansion when encrypting.

Definition at line 105 of file chacha20poly1305.h.

◆ KEYLEN

constexpr 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: