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

Unrestricted ChaCha20 cipher. More...

#include <chacha20.h>

Collaboration diagram for ChaCha20:
[legend]

Public Types

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

Public Member Functions

 ChaCha20 () noexcept=delete
 For safety, disallow initialization without key. More...
 
 ChaCha20 (Span< const std::byte > key) noexcept
 Initialize a cipher with specified 32-byte key. More...
 
 ~ChaCha20 ()
 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 Crypt (Span< const std::byte > in_bytes, Span< std::byte > out_bytes) noexcept
 en/deciphers the message <in_bytes> and write the result into <out_bytes> More...
 
void Keystream (Span< std::byte > out) noexcept
 outputs the keystream to out. More...
 

Static Public Attributes

static constexpr unsigned KEYLEN = ChaCha20Aligned::KEYLEN
 Expected key length in constructor and SetKey. More...
 

Private Attributes

ChaCha20Aligned m_aligned
 
std::array< std::byte, ChaCha20Aligned::BLOCKLENm_buffer
 
unsigned m_bufleft {0}
 

Detailed Description

Unrestricted ChaCha20 cipher.

Definition at line 77 of file chacha20.h.

Member Typedef Documentation

◆ Nonce96

96-bit nonce type.

Definition at line 101 of file chacha20.h.

Constructor & Destructor Documentation

◆ ChaCha20() [1/2]

ChaCha20::ChaCha20 ( )
deletenoexcept

For safety, disallow initialization without key.

◆ ChaCha20() [2/2]

ChaCha20::ChaCha20 ( Span< const std::byte >  key)
inlinenoexcept

Initialize a cipher with specified 32-byte key.

Definition at line 92 of file chacha20.h.

◆ ~ChaCha20()

ChaCha20::~ChaCha20 ( )

Destructor to clean up private memory.

Definition at line 332 of file chacha20.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Crypt()

void ChaCha20::Crypt ( Span< const std::byte >  in_bytes,
Span< std::byte >  out_bytes 
)
noexcept

en/deciphers the message <in_bytes> and write the result into <out_bytes>

The size of in_bytes and out_bytes must be equal.

Definition at line 303 of file chacha20.cpp.

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

◆ Keystream()

void ChaCha20::Keystream ( Span< std::byte >  out)
noexcept

outputs the keystream to out.

Definition at line 282 of file chacha20.cpp.

Here is the caller graph for this function:

◆ Seek()

void ChaCha20::Seek ( Nonce96  nonce,
uint32_t  block_counter 
)
inlinenoexcept

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

See ChaCha20Aligned::Seek.

Definition at line 104 of file chacha20.h.

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

◆ SetKey()

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

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

Definition at line 337 of file chacha20.cpp.

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

Member Data Documentation

◆ KEYLEN

constexpr unsigned ChaCha20::KEYLEN = ChaCha20Aligned::KEYLEN
staticconstexpr

Expected key length in constructor and SetKey.

Definition at line 86 of file chacha20.h.

◆ m_aligned

ChaCha20Aligned ChaCha20::m_aligned
private

Definition at line 80 of file chacha20.h.

◆ m_buffer

std::array<std::byte, ChaCha20Aligned::BLOCKLEN> ChaCha20::m_buffer
private

Definition at line 81 of file chacha20.h.

◆ m_bufleft

unsigned ChaCha20::m_bufleft {0}
private

Definition at line 82 of file chacha20.h.


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