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

ChaCha20 cipher that only operates on multiples of 64 bytes. More...

#include <chacha20.h>

Public Types

using Nonce96 = std::pair< uint32_t, uint64_t >
 Type for 96-bit nonces used by the Set function below. More...
 

Public Member Functions

 ChaCha20Aligned () noexcept=delete
 For safety, disallow initialization without key. More...
 
 ChaCha20Aligned (Span< const std::byte > key) noexcept
 Initialize a cipher with specified 32-byte key. More...
 
 ~ChaCha20Aligned ()
 Destructor to clean up private memory. More...
 
void SetKey (Span< const std::byte > key) noexcept
 Set 32-byte key, and seek to nonce 0 and block position 0. More...
 
void Seek (Nonce96 nonce, uint32_t block_counter) noexcept
 Set the 96-bit nonce and 32-bit block counter. More...
 
void Keystream (Span< std::byte > out) noexcept
 outputs the keystream into out, whose length must be a multiple of BLOCKLEN. More...
 
void Crypt (Span< const std::byte > input, Span< std::byte > output) noexcept
 en/deciphers the message <input> and write the result into <output> More...
 

Static Public Attributes

static constexpr unsigned KEYLEN {32}
 Expected key length in constructor and SetKey. More...
 
static constexpr unsigned BLOCKLEN {64}
 Block size (inputs/outputs to Keystream / Crypt should be multiples of this). More...
 

Private Attributes

uint32_t input [12]
 

Detailed Description

ChaCha20 cipher that only operates on multiples of 64 bytes.

Definition at line 25 of file chacha20.h.

Member Typedef Documentation

◆ Nonce96

using ChaCha20Aligned::Nonce96 = std::pair<uint32_t, uint64_t>

Type for 96-bit nonces used by the Set function below.

The first field corresponds to the LE32-encoded first 4 bytes of the nonce, also referred to as the '32-bit fixed-common part' in Example 2.8.2 of RFC8439.

The second field corresponds to the LE64-encoded last 8 bytes of the nonce.

Definition at line 57 of file chacha20.h.

Constructor & Destructor Documentation

◆ ChaCha20Aligned() [1/2]

ChaCha20Aligned::ChaCha20Aligned ( )
deletenoexcept

For safety, disallow initialization without key.

◆ ChaCha20Aligned() [2/2]

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

Initialize a cipher with specified 32-byte key.

Definition at line 47 of file chacha20.cpp.

◆ ~ChaCha20Aligned()

ChaCha20Aligned::~ChaCha20Aligned ( )

Destructor to clean up private memory.

Definition at line 42 of file chacha20.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Crypt()

void ChaCha20Aligned::Crypt ( Span< const std::byte >  input,
Span< std::byte >  output 
)
inlinenoexcept

en/deciphers the message <input> and write the result into <output>

The size of input and output must be equal, and be a multiple of BLOCKLEN.

Definition at line 161 of file chacha20.cpp.

Here is the call graph for this function:

◆ Keystream()

void ChaCha20Aligned::Keystream ( Span< std::byte >  out)
inlinenoexcept

outputs the keystream into out, whose length must be a multiple of BLOCKLEN.

Definition at line 60 of file chacha20.cpp.

Here is the call graph for this function:

◆ Seek()

void ChaCha20Aligned::Seek ( Nonce96  nonce,
uint32_t  block_counter 
)
noexcept

Set the 96-bit nonce and 32-bit block counter.

Block_counter selects a position to seek to (to byte BLOCKLEN*block_counter). After 256 GiB, the block counter overflows, and nonce.first is incremented.

Definition at line 52 of file chacha20.cpp.

Here is the caller graph for this function:

◆ SetKey()

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

Set 32-byte key, and seek to nonce 0 and block position 0.

Definition at line 25 of file chacha20.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ BLOCKLEN

constexpr unsigned ChaCha20Aligned::BLOCKLEN {64}
staticconstexpr

Block size (inputs/outputs to Keystream / Crypt should be multiples of this).

Definition at line 35 of file chacha20.h.

◆ input

uint32_t ChaCha20Aligned::input[12]
private

Definition at line 28 of file chacha20.h.

◆ KEYLEN

constexpr unsigned ChaCha20Aligned::KEYLEN {32}
staticconstexpr

Expected key length in constructor and SetKey.

Definition at line 32 of file chacha20.h.


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