Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
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.

Public Member Functions

 ChaCha20 () noexcept=delete
 For safety, disallow initialization without key.
 ChaCha20 (std::span< const std::byte > key) noexcept
 Initialize a cipher with specified 32-byte key.
 ~ChaCha20 ()
 Destructor to clean up private memory.
void SetKey (std::span< const std::byte > key) noexcept
 Set 32-byte key, and seek to nonce 0 and block position 0.
void Seek (Nonce96 nonce, uint32_t block_counter) noexcept
 Set the 96-bit nonce and 32-bit block counter.
void Crypt (std::span< const std::byte > in_bytes, std::span< std::byte > out_bytes) noexcept
 en/deciphers the message <in_bytes> and write the result into <out_bytes>
void Keystream (std::span< std::byte > out) noexcept
 outputs the keystream to out.

Static Public Attributes

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

Private Attributes

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

Detailed Description

Unrestricted ChaCha20 cipher.

Definition at line 75 of file chacha20.h.

Member Typedef Documentation

◆ Nonce96

96-bit nonce type.

Definition at line 99 of file chacha20.h.

Constructor & Destructor Documentation

◆ ChaCha20() [1/2]

ChaCha20::ChaCha20 ( )
deletenoexcept

For safety, disallow initialization without key.

Here is the caller graph for this function:

◆ ChaCha20() [2/2]

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

Initialize a cipher with specified 32-byte key.

Definition at line 90 of file chacha20.h.

Here is the call graph for this function:

◆ ~ChaCha20()

ChaCha20::~ChaCha20 ( )

Destructor to clean up private memory.

Definition at line 331 of file chacha20.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Crypt()

void ChaCha20::Crypt ( std::span< const std::byte > in_bytes,
std::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 302 of file chacha20.cpp.

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

◆ Keystream()

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

outputs the keystream to out.

Definition at line 281 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 102 of file chacha20.h.

Here is the caller graph for this function:

◆ SetKey()

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

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

Definition at line 336 of file chacha20.cpp.

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

Member Data Documentation

◆ KEYLEN

unsigned ChaCha20::KEYLEN = ChaCha20Aligned::KEYLEN
staticconstexpr

Expected key length in constructor and SetKey.

Definition at line 84 of file chacha20.h.

◆ m_aligned

ChaCha20Aligned ChaCha20::m_aligned
private

Definition at line 78 of file chacha20.h.

◆ m_buffer

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

Definition at line 79 of file chacha20.h.

◆ m_bufleft

unsigned ChaCha20::m_bufleft {0}
private

Definition at line 80 of file chacha20.h.


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