ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
aes_block.h File Reference

Compact table-free software AES key schedule + single-block encrypt (FIPS 197) - one source of truth. More...

#include "crypto/cipher/aes_sbox.h"
#include <stdint.h>
#include <string.h>

Go to the source code of this file.

Functions

uint8_t pc_aes_xtime (uint8_t a)
 GF(2^8) multiply-by-2 (xtime) for the AES MixColumns step.
 
uint32_t pc_aes_sub_word (uint32_t w)
 AES SubWord (FIPS 197 sec 5.2): apply the S-box to each of the four bytes of a 32-bit word.
 
uint32_t pc_aes_rot_word (uint32_t w)
 AES RotWord (FIPS 197 sec 5.2): cyclically rotate a 32-bit word one byte left.
 
void pc_aes_key_expand (const uint8_t *key, int nk, uint32_t *rk)
 AES key expansion (FIPS 197 sec 5.2). nk key words (4=AES-128, 8=AES-256); rk receives 4*(nk + 7) round-key words (44 for AES-128, 60 for AES-256).
 
void pc_aes_encrypt_block (const uint32_t *rk, int nr, const uint8_t in[16], uint8_t out[16])
 AES single-block encrypt (FIPS 197 sec 5.1), nr rounds (10=AES-128, 14=AES-256). State is column-major: s[col*4 + row]. rk is the schedule from pc_aes_key_expand.
 

Detailed Description

Compact table-free software AES key schedule + single-block encrypt (FIPS 197) - one source of truth.

The SSH AES-256-GCM, SSH AES-256-CTR, and QUIC/TLS AES-128 modules each carried a byte-for-byte copy of the same software AES (key expansion + the SubBytes/ShiftRows/MixColumns/AddRoundKey block cipher). They differ ONLY in the key size: parameterize on nk (key words: 4 for AES-128, 8 for AES-256) and nr (rounds: 10 or 14) and one implementation serves all three.

Only the S-box (PC_AES_SBOX from aes_sbox.h) and the GF(2^8) xtime are used - no large T-tables - so this is the same "constant-time by structure" shape the copies had (a table-indexed S-box; no secret- dependent branching introduced here). Header-only and pure (S-box + <string.h>), so it is compiled into only the NATIVE software path of each module; the #ifdef ARDUINO mbedTLS/HW branches are untouched.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file aes_block.h.

Function Documentation

◆ pc_aes_xtime()

uint8_t pc_aes_xtime ( uint8_t  a)
inline

GF(2^8) multiply-by-2 (xtime) for the AES MixColumns step.

Definition at line 30 of file aes_block.h.

Referenced by pc_aes_encrypt_block().

◆ pc_aes_sub_word()

uint32_t pc_aes_sub_word ( uint32_t  w)
inline

AES SubWord (FIPS 197 sec 5.2): apply the S-box to each of the four bytes of a 32-bit word.

Definition at line 36 of file aes_block.h.

Referenced by pc_aes_key_expand().

◆ pc_aes_rot_word()

uint32_t pc_aes_rot_word ( uint32_t  w)
inline

AES RotWord (FIPS 197 sec 5.2): cyclically rotate a 32-bit word one byte left.

Definition at line 43 of file aes_block.h.

Referenced by pc_aes_key_expand().

◆ pc_aes_key_expand()

void pc_aes_key_expand ( const uint8_t *  key,
int  nk,
uint32_t *  rk 
)
inline

AES key expansion (FIPS 197 sec 5.2). nk key words (4=AES-128, 8=AES-256); rk receives 4*(nk + 7) round-key words (44 for AES-128, 60 for AES-256).

Definition at line 52 of file aes_block.h.

References pc_aes_rot_word(), and pc_aes_sub_word().

Referenced by pc_aes256ctr_get_length().

◆ pc_aes_encrypt_block()

void pc_aes_encrypt_block ( const uint32_t *  rk,
int  nr,
const uint8_t  in[16],
uint8_t  out[16] 
)
inline

AES single-block encrypt (FIPS 197 sec 5.1), nr rounds (10=AES-128, 14=AES-256). State is column-major: s[col*4 + row]. rk is the schedule from pc_aes_key_expand.

Definition at line 82 of file aes_block.h.

References pc_aes_xtime().

Referenced by pc_aes256ctr_get_length().