embassy-stm32

Crates

git

Versions

stm32n655b0

Flavors

Module saes

Module saes 

Source
Expand description

Secure Advanced Encryption Standard (SAES) hardware accelerator

SAES provides the same cipher modes as AES but with enhanced security features for key management and protection. It’s particularly useful in secure boot scenarios and applications requiring hardware root of trust.

§Key Differences from AES

FeatureAESSAES
Key SourcesSoftware onlySoftware + Hardware (DHUK, BHK)
Key ProtectionBasicKEYPROT + isolation
Key SharingNoYes (with AES, other peripherals)
Key WrappingNoYes (wrapped/encrypted keys)
Security ContextStandardEnhanced/Secure

§Hardware Key Sources

  • DHUK (Derived Hardware Unique Key): Device-unique key derived from UID
  • BHK (Boot Hardware Key): Key loaded during secure boot
  • XOR: XOR combination of DHUK and BHK

These keys are never exposed to software and remain in secure hardware.

§Examples

§Using Software Keys (Same as AES)

use embassy_stm32::saes::{Saes, AesGcm, Direction};

let key = [0u8; 16];
let iv = [0u8; 12];
let cipher = AesGcm::new(&key, &iv);

let mut saes = Saes::new_blocking(p.SAES, Irqs);
let mut ctx = saes.start(&cipher, Direction::Encrypt);
// ... same as AES

§Using Hardware-Derived Keys

use embassy_stm32::saes::{Saes, AesGcm, Direction, HardwareKeySource};

let iv = [0u8; 12];
let cipher = AesGcm::new(&[], &iv); // No software key needed

let mut saes = Saes::new_blocking(p.SAES, Irqs);

// Use device-unique hardware key
let mut ctx = saes.start_with_hw_key(
    HardwareKeySource::DHUK,
    &cipher,
    Direction::Encrypt
);

// Hardware key is used automatically - never exposed to software
saes.payload_blocking(&mut ctx, &plaintext, &mut ciphertext, true);
saes.finish_blocking(ctx);

§Key Sharing Between Peripherals

use embassy_stm32::saes::{Saes, KeyShareTarget};

// After unwrapping a key with SAES, share it with AES peripheral
saes.share_key_with(KeyShareTarget::AES);
// Now AES peripheral can use the unwrapped key

§Security Features

  • Key Protection: KEYPROT flag prevents key readback
  • Hardware Keys: Never exposed to software, immune to memory dumps
  • Key Wrapping: Import encrypted keys securely
  • Peripheral Isolation: Keys can be shared without software access

§Availability

Important: SAES is only available on:

  • STM32WBA52 and higher
  • STM32WBA55
  • STM32WBA6x
  • NOT available on STM32WBA50

§Use Cases

  • Secure boot key management
  • Device-unique encryption (uses DHUK based on chip UID)
  • Key provisioning and wrapping
  • Multi-peripheral cryptographic workflows
  • High-security applications requiring hardware root of trust

§See Also

  • aes - Standard AES implementation (all WBA chips)
  • pka - Public Key Accelerator

Structs§

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 suspending/resuming operations.
InterruptHandler
SAES interrupt handler.
Saes
SAES driver.

Enums§

Direction
AES cipher direction
Error
AES error
HardwareKeySource
Hardware key source for SAES
KeyMode
Key mode for SAES
KeyShareTarget
Peripheral to share key with
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
SAES instance trait.