Skip to content

stm32h5, stm32u5: verify images with the PKA and HASH peripherals - #1024

Draft
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:stm32_pka_hash
Draft

dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:stm32_pka_hash

Conversation

@dgarske

@dgarske dgarske commented Dec 3, 2026

Copy link
Copy Markdown
Member

Adds PKA=1 (ECDSA signature verification on the PKA) and STM32_HASH=1 (SHA-256 image digest on the HASH engine) for TARGET=stm32h5 and TARGET=stm32u5, using wolfCrypt's register-level STM32 port (WOLFSSL_STM32_BARE). Only the CMSIS device headers of an STM32Cube package are needed, not the ST HAL drivers.

Depends on #1022 (this branch is stacked on it) and on a wolfSSL change that keeps the CMSIS device header out of assembler sources (wolfSSL/wolfssl#12371), followed by a lib/wolfssl bump.

What it adds

  • options.mk:
    • Builds port/st/stm32.c with the family and device macros and the CMSIS include paths; STM32CUBE_H5/STM32CUBE_U5 default to the newest tree under ~/STM32Cube/Repository.
    • PKA=1 leaves the public wolfCrypt types unchanged, so its flags go to the wolfCrypt objects only. STM32_HASH=1 changes the hash context layout, so it applies to every object, defaults to 4 KB hash blocks, and is refused with WOLFTPM, SPI/QSPI/OCTOSPI flash, PSA, wolfHSM and fwTPM.
    • Applies to wolfBoot only, not the test-app.
  • hal/stm32_hwcrypto.h: force-included into the HAL objects with STM32_HASH=1 to hide the port, whose CMSIS header clashes with the HAL register macros.
  • hal/stm32h5.c, hal/stm32u5.c:
    • start HSI48 with PKA=1, because PKA initialization needs the RNG kernel clock;
    • add a DWT-based hal_get_timer_us(), so BOOT_BENCHMARK=1 now builds on both targets.
  • CI build jobs: stm32h5-dk and stm32u5 with both options and BOOT_BENCHMARK=1, and stm32h5-tz with PKA=1 alone. docs/Targets.md gets a section with the measured boot times.

Default builds without the options are byte-identical for every stm32h5, stm32u5 and stm32wb example config checked.

Hardware / test status

Validated on the STM32H573I-DK (TZEN=0), NUCLEO-H563ZI (TZEN=1, PKCS11 test app) and B-U585I-IOT02A (TZEN=0), ST-LINK, 115200 8N1:

  • Boot with each option set.
  • Update with confirm and rollback, on the DK and H563.
  • A flipped payload byte is rejected by the HASH path and a flipped signature byte by the PKA.
  • On the H563, the secure PKCS11 provider and the wolfCrypt test pass after a hardware-crypto boot.
  • All stm32h5/stm32u5 example configs build with PKA=1.

Scope

Not run on hardware: the U5 TrustZone configs and the NUCLEO-U5A5. CMake builds do not offer PKA for any target and are unchanged. The STM32_HASH=1 limits above are follow-on work.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 03:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The configuration rewrite omits four STM32 overrides from persistence, so running make config can cause missing CMSIS headers or incorrect device selection in subsequent builds.

1 open issue
What changed in this PR

Adds optional PKA signature verification and HASH image hashing for STM32H5/U5 through wolfCrypt’s register-level port, alongside the STM32H573I-DK support stacked from #1022.

Changes:

  • Adds hardware-crypto build options and CMSIS header selection.
  • Initializes the required clock and adds boot benchmark timers.
  • Adds board configurations, CI coverage, and documentation.
File Description
tools/​config.mk Persists board and HASH selections.
test-app/​startup_arm.c Routes DK USART1 interrupts.
test-app/​Makefile Selects the non-secure UART object.
test-app/​app_stm32h5.c Adds DK LEDs and corrects console timing.
options.mk Configures hardware crypto and compatibility guards.
hal/​uart/​uart_drv_stm32h5.c Adds DK UART support and fixes baud calculation.
hal/​stm32u5.c Starts HSI48 and adds benchmark timing.
hal/​stm32h5.h Adds board definitions and corrects UART registers.
hal/​stm32h5.c Adds DK setup, crypto clock initialization, and timing.
hal/​stm32_hwcrypto.h Prevents CMSIS conflicts in HAL objects.
docs/​Targets.md Documents board setup, crypto options, and measurements.
config/​examples/​stm32h5-dk.config Adds the non-TrustZone DK configuration.
config/​examples/​stm32h5-dk-tz.config Adds the TrustZone DK configuration.
CMakeLists.txt Supports DK board selection.
arch.mk Sets the DK board macro.
.github/​workflows/​test-configs.yml Adds board and hardware-crypto build jobs.

Review effort: Balanced

Comment thread tools/config.mk
DISABLE_BACKUP WOLFBOOT_VERSION V NO_MPU ENCRYPT FLAGS_HOME FLAGS_INVERT NO_SWAP_EXT \
SPMATH SPMATHALL RAM_CODE DUALBANK_SWAP IMAGE_HEADER_SIZE PKA TZEN PSOC6_CRYPTO PSOC6_BOARD PSOC6_CM4_APP \
SPMATH SPMATHALL RAM_CODE DUALBANK_SWAP IMAGE_HEADER_SIZE PKA TZEN PSOC6_CRYPTO PSOC6_BOARD PSOC6_CM4_APP STM32H5_BOARD \
STM32_HASH \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants