DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ssh_aes256ctr.cpp File Reference

AES-256-CTR implementation. More...

Go to the source code of this file.

Functions

void ssh_aes256ctr_init (SshAesCtrCtx *ctx, const uint8_t key[32], const uint8_t iv[16])
 Initialize an AES-256-CTR context.
 
void ssh_aes256ctr_crypt (SshAesCtrCtx *ctx, const uint8_t *in, uint8_t *out, size_t len)
 Encrypt or decrypt len bytes in-place (or src→dst).
 
void ssh_aes256ctr_wipe (SshAesCtrCtx *ctx)
 Zero the key schedule and all context fields.
 

Detailed Description

AES-256-CTR implementation.

Arduino path: delegates block encryption to mbedtls_aes_crypt_ecb(), which the ESP32 mbedtls port routes to the hardware AES accelerator.

Native path: compact software AES-256 using only the 256-byte forward S-box and GF(2^8) multiply-by-2/3 for MixColumns. No large lookup tables.

Definition in file ssh_aes256ctr.cpp.

Function Documentation

◆ ssh_aes256ctr_init()

void ssh_aes256ctr_init ( SshAesCtrCtx ctx,
const uint8_t  key[32],
const uint8_t  iv[16] 
)

Initialize an AES-256-CTR context.

Expands the key schedule (hardware on Arduino, software on native) and stores the initial counter/IV.

Parameters
ctxUninitialized context.
key32-byte AES-256 key (derived from KEX via RFC 4253 §7.2).
iv16-byte initial counter block (derived from KEX).

Definition at line 24 of file ssh_aes256ctr.cpp.

References SshAesCtrCtx::_mbed, SshAesCtrCtx::counter, SshAesCtrCtx::keystream, and SshAesCtrCtx::pos.

Referenced by ssh_dh_derive_keys_sid().

◆ ssh_aes256ctr_crypt()

void ssh_aes256ctr_crypt ( SshAesCtrCtx ctx,
const uint8_t *  in,
uint8_t *  out,
size_t  len 
)

Encrypt or decrypt len bytes in-place (or src→dst).

AES-CTR is symmetric: XOR with keystream is its own inverse. Calling this function for encryption and decryption is identical.

The counter advances by ceil(len/16) blocks. If in == out the operation is in-place (the only mode used by ssh_packet.cpp).

Parameters
ctxInitialized AES-256-CTR context.
inInput bytes.
outOutput bytes (may equal in for in-place).
lenNumber of bytes to process.

Definition at line 33 of file ssh_aes256ctr.cpp.

References SshAesCtrCtx::_mbed, SshAesCtrCtx::counter, SshAesCtrCtx::keystream, and SshAesCtrCtx::pos.

Referenced by ssh_pkt_recv(), and ssh_pkt_send().

◆ ssh_aes256ctr_wipe()

void ssh_aes256ctr_wipe ( SshAesCtrCtx ctx)

Zero the key schedule and all context fields.

Call on disconnect. Uses a volatile wipe so the compiler cannot elide it. On Arduino also calls mbedtls_aes_free() to release any internal resources.

Parameters
ctxContext to wipe.

Definition at line 46 of file ssh_aes256ctr.cpp.

References SshAesCtrCtx::_mbed.