Sunshine master
Self-hosted game stream host for Moonlight.
crypto::cipher::cbc_t Class Reference

AES-CBC cipher helper used for block-mode encryption and decryption. More...

#include <src/crypto.h>

Inheritance diagram for crypto::cipher::cbc_t:
[legend]
Collaboration diagram for crypto::cipher::cbc_t:
[legend]

Public Member Functions

 cbc_t (cbc_t &&) noexcept=default
 Construct an AES-CBC cipher helper with key material and IV state.
 
 cbc_t (const crypto::aes_t &key, bool padding=true)
 Construct an AES-CBC cipher helper with key material and IV state.
 
int encrypt (const std::string_view &plaintext, std::uint8_t *cipher, aes_t *iv)
 Encrypts the plaintext using AES CBC mode. length of cipher must be at least: round_to_pkcs7_padded(plaintext.size())
 
cbc_toperator= (cbc_t &&) noexcept=default
 Assign state from another instance while preserving ownership semantics.
 

Additional Inherited Members

- Public Attributes inherited from crypto::cipher::cipher_t
cipher_ctx_t decrypt_ctx
 Decrypt ctx.
 
cipher_ctx_t encrypt_ctx
 Encrypt ctx.
 
aes_t key
 AES key used by the cipher context.
 
bool padding
 Enables block padding for the cipher.
 

Detailed Description

AES-CBC cipher helper used for block-mode encryption and decryption.

Constructor & Destructor Documentation

◆ cbc_t()

crypto::cipher::cbc_t::cbc_t ( const crypto::aes_t & key,
bool padding = true )

Construct an AES-CBC cipher helper with key material and IV state.

Parameters
keyAES key material used to initialize the cipher.
paddingWhether the cipher should use block padding.

Member Function Documentation

◆ encrypt()

int crypto::cipher::cbc_t::encrypt ( const std::string_view & plaintext,
std::uint8_t * cipher,
aes_t * iv )

Encrypts the plaintext using AES CBC mode. length of cipher must be at least: round_to_pkcs7_padded(plaintext.size())

Parameters
plaintextThe plaintext data to be encrypted.
cipherThe buffer where the resulting ciphertext will be written.
ivThe initialization vector to be used for the encryption.
Returns
The total length of the ciphertext written into cipher. Returns -1 in case of an error.

This function encrypts the given plaintext using the AES key in CBC mode. The initialization vector (IV) is also provided. The function handles the creation and initialization of the encryption context, and manages the encryption process. The resulting ciphertext is written into the cipher buffer.

◆ operator=()

cbc_t & crypto::cipher::cbc_t::operator= ( cbc_t && )
defaultnoexcept

Assign state from another instance while preserving ownership semantics.

Returns
Reference or value produced by the operator.

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