Skip to content

Add WOLFCRYPT_TZ_WOLFHSM TrustZone engine for STM32H5#769

Open
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:h5-wolfhsm-port
Open

Add WOLFCRYPT_TZ_WOLFHSM TrustZone engine for STM32H5#769
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:h5-wolfhsm-port

Conversation

@aidangarske

@aidangarske aidangarske commented May 1, 2026

Copy link
Copy Markdown
Member

Description

  • Adds WOLFCRYPT_TZ_WOLFHSM=1 a fourth TrustZone engine for STM32H5
    alongside PKCS11, PSA, and fwTPM. New config:
    config/examples/stm32h5-tz-wolfhsm.config.
  • Hosts a wolfHSM server in the secure boot image and exposes it to
    the non-secure application through a single NSC veneer
    (wcs_wolfhsm_transmit). The non-secure app uses the standard
    wolfCrypt API; operations through WH_DEV_ID route to the secure
    side. Keys never leave the secure world.
  • Persistent flash-backed keystore via a new whFlashCb adapter
    (src/wolfhsm_flash_hal.c) over hal_flash_*, mirroring
    psa_store.c's sector-cached read-modify-erase-write pattern.
    Two-partition journaling in the existing keyvault region.
  • Mutually exclusive with PKCS11/PSA/fwTPM. Shared
    WOLFHSM_SERVER_OBJS / WOLFHSM_CLIENT_OBJS variables avoid
    object-list duplication with the existing AURIX/sim wolfHSM lanes.
  • New CI lane in .github/workflows/trustzone-emulator-tests.yml:
    m33mu first-boot/second-boot persistence test asserting CommInit,
    RNG, SHA256, AES, and keystore restore across reset.
  • New host unit test tools/unit-tests/unit-wolfhsm_flash_hal.c
    covers bounds, alignment, multi-sector, and write-failure paths.
  • Docs: new docs/wolfHSM.md + wolfHSM section in docs/STM32-TZ.md.

Notes

  • lib/wolfHSM submodule pin is not bumped in this PR. The wolfHSM
    PR (port/stmicro/stm32-tz NSC bridge transport) lands first; the
    pin bump will follow in a small standalone PR.
  • Update sub module pin to 384 wolfHSM PR

Test plan

  • m33mu first/second boot persistence (CI)
  • Host unit test for flash adapter (CI)
  • On-board STM32H5 NUCLEO-H563ZI: WOLFHSM_TZ_TEST_PASS over UART
  • On-board first/second boot persistence worked
  • PKCS11/PSA/fwTPM configs still build and pass m33mu
  • Skoll review passes

@aidangarske aidangarske self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 23:26
@aidangarske aidangarske changed the title H5 wolfhsm port Add WOLFCRYPT_TZ_WOLFHSM TrustZone engine for STM32H5 May 1, 2026

This comment was marked as resolved.

wolfSSL-Fenrir-bot

This comment was marked as resolved.

@aidangarske aidangarske marked this pull request as ready for review May 12, 2026 01:42
@aidangarske aidangarske requested review from danielinux and removed request for wolfSSL-Fenrir-bot May 12, 2026 01:43
@aidangarske aidangarske marked this pull request as draft May 13, 2026 16:06
@aidangarske aidangarske force-pushed the h5-wolfhsm-port branch 8 times, most recently from 24de72f to 1f1a3ac Compare May 26, 2026 16:48
@aidangarske aidangarske marked this pull request as ready for review May 26, 2026 17:24
@aidangarske aidangarske requested a review from bigbrett June 1, 2026 21:30
Comment thread src/wolfhsm_callable.c Outdated
Comment thread src/wolfhsm_callable.c
Comment thread options.mk
Comment thread .github/workflows/trustzone-emulator-tests.yml
Comment thread src/wolfhsm_callable.c Outdated
Comment thread port/stmicro/stm32h5-tz-wolfhsm/out/manifest.env Outdated
Comment thread config/examples/stm32h5-tz-wolfhsm.config
danielinux
danielinux previously approved these changes Jun 15, 2026

@bigbrett bigbrett 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.

@aidangarske a few questions

Comment thread docs/wolfHSM.md Outdated
Comment thread options.mk Outdated
bigbrett
bigbrett previously approved these changes Jun 17, 2026
danielinux
danielinux previously approved these changes Jun 23, 2026

@danielinux danielinux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking issue:
The three cmse_check_address_range() calls use CMSE_AU_NONSECURE, whereas the sibling veneers fwtpm_callable.c and pkcs11_callable.c use CMSE_NONSECURE (= CMSE_AU_NONSECURE | CMSE_MPU_NONSECURE).

All three correctly reject secure-world pointers, so this isn't a bug, also because NO_MPU=1 . But once an NS MPU is ever configured, this veneer alone won't enforce NS-MPU permissions on the buffer.

Note for later: consider aligning the flag across the three TZ veneers and add a one-line note on the chosen semantics so it's a deliberate decision rather than an accidental divergence.

Merging as is for now.

@danielinux

Copy link
Copy Markdown
Member

@aidangarske This has conflicts with master branch now: please rebase. Also perhaps consider fixing the CMSE_AU_NONSECURE / CMSE_NONSECURE minor remark above

danielinux
danielinux previously approved these changes Jun 24, 2026
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.

6 participants