embassy-stm32

Crates

git

Versions

stm32u5a9bj

Flavors

Skip to main content

Module aes

Module aes 

Source
Expand description

Advanced Encryption Standard (AES) hardware accelerator.

This module drives the on-chip AES block. The hardware revisions below are supported, selected automatically from the target chip:

  • aes_v1 (STM32L0, L1, L4, F423) — blocking driver, plus an interrupt-driven async API where the engine has its own interrupt (L4). This revision only does ECB, CBC and CTR with 128-bit keys.
  • aes_v2 (STM32G0, G4, L5, U0, WL) — blocking driver, plus an interrupt-driven async API where the engine has its own interrupt (L5, WL). Elsewhere the engine shares its interrupt line with another peripheral (e.g. RNG) or has no dedicated line at all, so only the blocking API is offered.
  • aes_f7 (STM32F72x, F73x) — same register map as aes_v2 minus the NPBLB field, so a final partial payload block cannot be masked out of the authentication: GCM (both directions) and CCM decryption return Error::ConfigError when the payload is not a multiple of 16 bytes.
  • aes_v3a (STM32U5) and aes_v3b (STM32H5, WBA) — blocking driver plus an interrupt/DMA-backed async API. The two revisions have the same register map.

All revisions expose the same cipher types and the same start / aad_blocking / payload_blocking / finish_blocking blocking flow, so blocking code is portable across them.

§Supported cipher modes

ModePaddingAuthUse case
ECBRequiredNoKeys only (not recommended for data)
CBCRequiredNoFile/disk encryption
CTRNoNoStreaming data, random access
GCMNoYesRecommended — modern applications
GMACNoYesAuthentication without encryption
CCMNoYesResource‑constrained devices

GCM, GMAC and CCM are not available on aes_v1.

§Key sizes

  • 128-bit (16 bytes) and 256-bit (32 bytes); only 128-bit on aes_v1.
  • 192-bit keys are not supported by this hardware.

§IV / nonce requirements

  • CBC: random, unique per message.
  • CTR: must never repeat with the same key.
  • GCM/GMAC: 96-bit (12 bytes), unique per message. IV reuse is catastrophic.

Structs§

Aes
AES driver.
AesCbc
AES-CBC Cipher Mode
AesCcm
AES-CCM Cipher Mode (Counter with CBC-MAC)
AesCtr
AES-CTR Cipher Mode
AesEcb
AES-ECB Cipher Mode
AesGcm
AES-GCM Cipher Mode
AesGmac
AES-GMAC Cipher Mode (Galois Message Authentication Code)
Context
Stores the state of the AES peripheral for a cipher operation.
InterruptHandler
AES interrupt handler.

Enums§

Direction
AES cipher direction
Error
AES error
KeySize
AES key size

Traits§

Cipher
This trait encapsulates all cipher-specific behavior.
CipherAuthenticated
This trait enables restriction of a header phase to authenticated ciphers only.
CipherSized
This trait enables restriction of ciphers to specific key sizes.
DmaIn
DmaIn DMA request trait
DmaOut
DmaOut DMA request trait
IVSized
This trait enables restriction of initialization vectors to sizes compatible with a cipher mode.
Instance
AES instance trait.