C/C++ API Reference
Loading...
Searching...
No Matches
pw::crypto::chacha20 Namespace Reference

Overview

ChaCha20 stream cipher.

This module provides a backend-agnostic API for the ChaCha20 stream cipher as defined in RFC 8439.

Functions

Status Crypt (span< const std::byte > key, span< const std::byte > nonce, span< const std::byte > input, span< std::byte > output)
 

Variables

constexpr size_t kKeySizeBytes = 32
 
constexpr size_t kNonceSizeBytes = 12
 

Function Documentation

◆ Crypt()

Status pw::crypto::chacha20::Crypt ( span< const std::byte >  key,
span< const std::byte >  nonce,
span< const std::byte >  input,
span< std::byte >  output 
)
inline

Performs ChaCha20 encryption or decryption. Since ChaCha20 is a stream cipher, encryption and decryption are the same operation. InitialCounter had been removed from the cacnonical API and is hardcoded to 0 for simplicity of a one-shot only implementation.

Parameters
[in]keyThe 256-bit secret key.
[in]nonceThe 96-bit nonce. MUST be unique for each encryption with the same key.
[in]inputThe data to encrypt or decrypt.
[out]outputThe buffer to store the result. Must be at least as large as input. In-place operation is allowed (input == output).
Returns
OkStatus() on success. or Status::InvalidArgument() if key, nonce, or buffer sizes are incorrect. Status::Internal() for any other backend-related errors.