Bitcoin Core  26.99.0
P2P Digital Currency
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
AEADChaCha20Poly1305 Class Reference

The AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC8439 section 2.8. More...

#include <chacha20poly1305.h>

Collaboration diagram for AEADChaCha20Poly1305:
[legend]

Public Types

using Nonce96 = ChaCha20::Nonce96
 96-bit nonce type. More...
 

Public Member Functions

 AEADChaCha20Poly1305 (Span< const std::byte > key) noexcept
 Initialize an AEAD instance with a specified 32-byte key. More...
 
void SetKey (Span< const std::byte > key) noexcept
 Switch to another 32-byte key. More...
 
void Encrypt (Span< const std::byte > plain, Span< const std::byte > aad, Nonce96 nonce, Span< std::byte > cipher) noexcept
 Encrypt a message with a specified 96-bit nonce and aad. More...
 
void Encrypt (Span< const std::byte > plain1, Span< const std::byte > plain2, Span< const std::byte > aad, Nonce96 nonce, Span< std::byte > cipher) noexcept
 Encrypt a message (given split into plain1 + plain2) with a specified 96-bit nonce and aad. More...
 
bool Decrypt (Span< const std::byte > cipher, Span< const std::byte > aad, Nonce96 nonce, Span< std::byte > plain) noexcept
 Decrypt a message with a specified 96-bit nonce and aad. More...
 
bool Decrypt (Span< const std::byte > cipher, Span< const std::byte > aad, Nonce96 nonce, Span< std::byte > plain1, Span< std::byte > plain2) noexcept
 Decrypt a message with a specified 96-bit nonce and aad and split the result. More...
 
void Keystream (Nonce96 nonce, Span< std::byte > keystream) noexcept
 Get a number of keystream bytes from the underlying stream cipher. More...
 

Static Public Attributes

static constexpr unsigned KEYLEN = 32
 Expected size of key argument in constructor. More...
 
static constexpr unsigned EXPANSION = Poly1305::TAGLEN
 Expansion when encrypting. More...
 

Private Attributes

ChaCha20 m_chacha20
 Internal stream cipher. More...
 

Detailed Description

The AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC8439 section 2.8.

Definition at line 16 of file chacha20poly1305.h.

Member Typedef Documentation

◆ Nonce96

96-bit nonce type.

Definition at line 35 of file chacha20poly1305.h.

Constructor & Destructor Documentation

◆ AEADChaCha20Poly1305()

AEADChaCha20Poly1305::AEADChaCha20Poly1305 ( Span< const std::byte >  key)
noexcept

Initialize an AEAD instance with a specified 32-byte key.

Definition at line 20 of file chacha20poly1305.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Decrypt() [1/2]

bool AEADChaCha20Poly1305::Decrypt ( Span< const std::byte >  cipher,
Span< const std::byte >  aad,
Nonce96  nonce,
Span< std::byte >  plain 
)
inlinenoexcept

Decrypt a message with a specified 96-bit nonce and aad.

Returns true if valid.

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

Definition at line 56 of file chacha20poly1305.h.

◆ Decrypt() [2/2]

bool AEADChaCha20Poly1305::Decrypt ( Span< const std::byte >  cipher,
Span< const std::byte >  aad,
Nonce96  nonce,
Span< std::byte >  plain1,
Span< std::byte >  plain2 
)
noexcept

Decrypt a message with a specified 96-bit nonce and aad and split the result.

Returns true if valid.

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

Definition at line 92 of file chacha20poly1305.cpp.

Here is the call graph for this function:

◆ Encrypt() [1/2]

void AEADChaCha20Poly1305::Encrypt ( Span< const std::byte >  plain,
Span< const std::byte >  aad,
Nonce96  nonce,
Span< std::byte >  cipher 
)
inlinenoexcept

Encrypt a message with a specified 96-bit nonce and aad.

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

Definition at line 41 of file chacha20poly1305.h.

Here is the caller graph for this function:

◆ Encrypt() [2/2]

void AEADChaCha20Poly1305::Encrypt ( Span< const std::byte >  plain1,
Span< const std::byte >  plain2,
Span< const std::byte >  aad,
Nonce96  nonce,
Span< std::byte >  cipher 
)
noexcept

Encrypt a message (given split into plain1 + plain2) with a specified 96-bit nonce and aad.

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

Definition at line 78 of file chacha20poly1305.cpp.

Here is the call graph for this function:

◆ Keystream()

void AEADChaCha20Poly1305::Keystream ( Nonce96  nonce,
Span< std::byte >  keystream 
)
noexcept

Get a number of keystream bytes from the underlying stream cipher.

This is equivalent to Encrypt() with plain set to that many zero bytes, and dropping the last EXPANSION bytes off the result.

Definition at line 108 of file chacha20poly1305.cpp.

Here is the caller graph for this function:

◆ SetKey()

void AEADChaCha20Poly1305::SetKey ( Span< const std::byte >  key)
noexcept

Switch to another 32-byte key.

Definition at line 25 of file chacha20poly1305.cpp.

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

Member Data Documentation

◆ EXPANSION

constexpr unsigned AEADChaCha20Poly1305::EXPANSION = Poly1305::TAGLEN
staticconstexpr

Expansion when encrypting.

Definition at line 26 of file chacha20poly1305.h.

◆ KEYLEN

constexpr unsigned AEADChaCha20Poly1305::KEYLEN = 32
staticconstexpr

Expected size of key argument in constructor.

Definition at line 23 of file chacha20poly1305.h.

◆ m_chacha20

ChaCha20 AEADChaCha20Poly1305::m_chacha20
private

Internal stream cipher.

Definition at line 19 of file chacha20poly1305.h.


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