Repository navigation
Conversation
Adds the F4 crypto block to STM32Sim so wolfSSL's F4 hardware crypto and STM32 RNG seed code can be tested in CI, prompted by a wolfSSL wc_GenerateSeed() that hung forever when the F4 RNG raised an error mid-request (reproduced on an STM32F4DISCOVERY first). Simulator: - stm32f417 chip (CRYP, HASH, RNG, USART1/2/3, RCC) and stm32f407 (no CRYP/HASH), with the RM0090 memory map. - CRYP v1: DES/TDES ECB/CBC; an F4 variant that drops the GCM/CCM mode bits as F405/F415/F417 silicon does; the IV registers track the chaining value, as wolfSSL's HAL_V2 DES path reads them back. - HASH v1: an F4 layout with SHA-1/MD5 only (ALGO bit 18 reserved, no extended HR window). - USART: the F1/F2/F4 register layout. RCC: F4 ready bits. - RNG: --rng-fault seed|clock:<reads>[:sticky] injects a seed or clock error after a number of RNG_DR reads, with the RM0090 recovery rules (seed error clears on SEIS clear + RNGEN cycle; clock error clears after a short glitch; sticky never clears). Works on every chip. - A run that hits --timeout logs the PC it stopped at. Firmware and CI: - firmware/rng-fault-f4: wc_GenerateSeed() fault test for the StdPeriph and WOLFSSL_STM32_RNG_NOLIB arms. Builds for stm32-sim or for a real STM32F4DISCOVERY, where it stops the RNG kernel clock from SysTick (board-run.sh flashes and reads it back over OpenOCD). ST's StdPeriph library is not vendored; a small shim stands in. - firmware/wolfcrypt-test-f417: the wolfCrypt test through the STM32CubeF4 HAL (CRYP for DES/TDES and AES ECB/CBC/CTR, HASH for SHA-1/MD5, RNG), including the software GCM fallback and DES ECB. - scripts/run-wolfcrypt-f417.sh, scripts/run-rng-fault-f417.sh, the Docker image gains cmsis-device-f4 and stm32f4xx-hal-driver, and a new stm32-wolfcrypt-test-f417 workflow runs both. The workflow tests wolfSSL master, so it needs the wolfSSL fixes for the StdPeriph RNG hang, the NOLIB clock-error handling and the STM32 DES ECB build merged first.
There was a problem hiding this comment.
🟡 Changes recommended
Zero-read RNG faults are not latched before the first data read, and both CI scripts can report success despite simulator failure after expected output appears.
3 open issues
What changed in this PR
Adds STM32F417 and STM32F407 support to STM32Sim so CI can exercise wolfSSL’s F4 hardware crypto and reproduce RNG error-handling hangs observed on hardware.
Changes:
- Adds F4 chip configurations, legacy USART support, and F4-specific CRYP/HASH behavior, including DES/TDES.
- Adds configurable RNG fault injection and program-counter reporting on timeout.
- Adds wolfCrypt and RNG regression firmware, run scripts, Docker support, and an F417 CI workflow.
| File | Description |
|---|---|
| STM32Sim/stm32-sim/runner-bin/src/main.rs | Exposes RNG fault injection and timeout diagnostics. |
| STM32Sim/stm32-sim/peripherals/src/usart.rs | Adds the legacy F4 USART layout and tests. |
| STM32Sim/stm32-sim/peripherals/src/rng.rs | Models seed and clock faults with recovery rules. |
| STM32Sim/stm32-sim/peripherals/src/rcc.rs | Adds F4 clock-ready bits. |
| STM32Sim/stm32-sim/peripherals/src/lib.rs | Exports fault and USART layout types. |
| STM32Sim/stm32-sim/peripherals/src/hash/v1.rs | Adds F4 SHA-1/MD5-only behavior. |
| STM32Sim/stm32-sim/peripherals/src/cryp/v1.rs | Adds F4 modes, DES/TDES wiring, and IV readback. |
| STM32Sim/stm32-sim/peripherals/src/cryp/mod.rs | Implements shared DES/TDES block processing. |
| STM32Sim/stm32-sim/peripherals/Cargo.toml | Enables the DES dependency. |
| STM32Sim/stm32-sim/core/src/runner.rs | Records the program counter on timeout. |
| STM32Sim/stm32-sim/chips/src/stm32u575.rs | Passes RNG fault options to U5 targets. |
| STM32Sim/stm32-sim/chips/src/stm32mp135.rs | Passes RNG fault options to MP135. |
| STM32Sim/stm32-sim/chips/src/stm32h753.rs | Passes RNG fault options to H753. |
| STM32Sim/stm32-sim/chips/src/stm32f417.rs | Defines F417/F407 memory and peripheral maps. |
| STM32Sim/stm32-sim/chips/src/lib.rs | Registers F4 targets and shared chip options. |
| STM32Sim/stm32-sim/Cargo.toml | Declares the workspace DES dependency. |
| STM32Sim/scripts/run-wolfcrypt-f417.sh | Builds and runs F417 wolfCrypt firmware. |
| STM32Sim/scripts/run-rng-fault-f417.sh | Runs ten RNG fault regression scenarios. |
| STM32Sim/README.md | Documents F4 support and fault injection. |
| STM32Sim/firmware/wolfcrypt-test-f417/user_settings.h | Configures wolfSSL’s F4 crypto paths. |
| STM32Sim/firmware/wolfcrypt-test-f417/toolchain-arm-none-eabi.cmake | Configures Cortex-M4 compilation and vendor headers. |
| STM32Sim/firmware/wolfcrypt-test-f417/stm32f4xx_hal_conf.h | Enables required F4 HAL modules. |
| STM32Sim/firmware/wolfcrypt-test-f417/stm32f417.ld | Maps firmware, heap, and CCM stack. |
| STM32Sim/firmware/wolfcrypt-test-f417/startup_stm32f417.c | Provides startup and exception vectors. |
| STM32Sim/firmware/wolfcrypt-test-f417/main.c | Runs wolfCrypt and reports completion. |
| STM32Sim/firmware/wolfcrypt-test-f417/CMakeLists.txt | Links wolfSSL, HAL, and test firmware. |
| STM32Sim/firmware/rng-fault-f4/user_settings.h | Selects the two RNG implementation paths. |
| STM32Sim/firmware/rng-fault-f4/stm32f4.ld | Defines the RNG firmware memory layout. |
| STM32Sim/firmware/rng-fault-f4/stdperiph/stm32f4xx.h | Wraps CMSIS with StdPeriph declarations. |
| STM32Sim/firmware/rng-fault-f4/stdperiph/stdperiph_shim.h | Declares the RNG/RCC compatibility interface. |
| STM32Sim/firmware/rng-fault-f4/stdperiph_shim.c | Implements register-level StdPeriph calls. |
| STM32Sim/firmware/rng-fault-f4/startup_stm32f4.c | Provides minimal RNG firmware startup. |
| STM32Sim/firmware/rng-fault-f4/README.md | Documents simulator and board fault tests. |
| STM32Sim/firmware/rng-fault-f4/Makefile | Builds simulator and board variants. |
| STM32Sim/firmware/rng-fault-f4/main.c | Exercises seed requests and board clock faults. |
| STM32Sim/firmware/rng-fault-f4/board-run.sh | Flashes hardware and reads diagnostics. |
| STM32Sim/Dockerfile.wolfcrypt | Packages F4 dependencies, firmware, and scripts. |
| README.md | Lists F417/F407 support. |
| .github/workflows/stm32-wolfcrypt-test-f417.yml | Runs F417 crypto and RNG tests against wolfSSL master. |
Review effort: Balanced
wc_GenerateSeed() must release the crypto hardware mutex on every return path, including when it gives up with RNG_FAILURE_E. In a SINGLE_THREADED build the mutex itself is a no-op, so a leak would go unnoticed. The rng-fault-f4 firmware now links with ld --wrap for wolfSSL_CryptHwMutexLock/UnLock, tracks the lock depth, and reports "mutex=ok" or "mutex=bad" after each call (also g_hw_mutex_errors for board runs). run-rng-fault-f417.sh fails a scenario whose mutex is not released. With a wolfSSL copy whose StdPeriph retry-exhaustion path skips the unlock, the seed:200:sticky and clock:200:sticky scenarios now fail with "mutex='bad'"; the fixed tree passes all ten. The runner also cleans the copied firmware directory before building, so build output left in a local checkout can't stand in for a fresh build against WOLFSSL_ROOT.
- run-wolfcrypt-f417.sh: the firmware prints its pass line before it sets test_complete, so a simulator timeout or fault after that line still exited 0. Pass now needs the marker and a zero simulator exit status, and a run with neither exits non-zero. - run-rng-fault-f417.sh: likewise, a scenario whose RNG_FAULT line matches now also needs the simulator to exit cleanly. - rng: a fault armed with zero reads latched only after the first RNG_DR read had returned fresh data, so seed:0 behaved like seed:1 and the firmware's first status check saw a healthy RNG. It now latches when armed, so the error is there from the start.
…ropy wolfSSL master (76aed2f9d4, "Use available entropy sources in embedded configurations") turned weak PIC32 seed sources into #errors, which broke three of the four PIC32MZ wolfCrypt tiers: - EC direct: the EC has no TRNG, so wolfSSL seeds the PIC32MZ RNG block from the core timer and now requires WOLFSSL_ACCEPT_WEAK_ENTROPY. - EC and EF Harmony: the Harmony build never defined WOLFSSL_PIC32MZ_RNG (the direct port gets it with WOLFSSL_MICROCHIP_PIC32MZ), so wolfSSL fell back to rand() seeded from the core timer, which is now an #error too, even on the EF with its TRNG. Define WOLFSSL_PIC32MZ_RNG for the Harmony tier, so it seeds from the RNG block like the direct port (the EF from its TRNG), and define WOLFSSL_ACCEPT_WEAK_ENTROPY on EC parts only, keyed on __PIC32_FEATURE_SET1 as wolfSSL's own check is. All four tiers pass against wolfSSL master.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds an STM32F417 (and F407) target to STM32Sim, so wolfSSL's F4 hardware crypto and its STM32 RNG seed code can be tested in CI. It started from a wolfSSL
wc_GenerateSeed()that hung forever when the F4 RNG raised an error mid-request. That was reproduced on an STM32F4DISCOVERY first, and the same firmware now runs here.Also fixes the PIC32MZ CI (last commit), which wolfSSL master broke for every simulators PR; see the PIC32MZSim section below.
Merge order: the new workflow tests wolfSSL master and needs these merged first:
WOLFSSL_DES_ECB, fails to linkHow it was validated
firmware/rng-fault-f4was run on an STM32F4DISCOVERY (STM32F407), where it stops the RNG kernel clock from SysTick part way through a seed request. RNG_SR reads0x22(CECS | CEIS). The unfixed StdPeriph arm hangs, and the fixed one returns. The simulator's fault model follows what the chip did: DRDY stays low during the error, CECS clears when the clock returns, and CEIS stays latched until cleared.scripts/run-rng-fault-f417.shpasses all 10 scenarios against wolfssl#12265. Against master it fails, reporting the PC the StdPeriph arm hung at (RNG_GetFlagStatus).scripts/run-wolfcrypt-f417.shpasses the full wolfCrypt test on--chip stm32f417: DES/3DES (CBC and ECB) and AES ECB/CBC/CTR on the CRYP, MD5/SHA-1 on the HASH, the HAL RNG, AES-GCM through wolfSSL's software GHASH fallback, RSA and ECC. Tracing MMIO confirms the CRYP and HASH are heavily used.Dockerfile.wolfcryptimage. The existing H7, U5 and MP135 wolfCrypt runs still pass in that image, since the RNG and CRYP v1 models are shared.cargo testpasses, including the smoke firmware.Changes
chips/src/stm32f417.rs):stm32f417(CRYP, HASH, RNG, USART1/2/3, RCC, flash interface) andstm32f407(no CRYP/HASH), with the RM0090 memory map.ChipOptionscarries run-time knobs to every chip.descrate).CrypV1::new_f4()drops the GCM/CCM mode bits, as F405/F415/F417 silicon does, so firmware that tries GCM gets wrong output instead of a model that silently works.STM32_HAL_V2DES path reads them back, which RM0090's context-swap procedure supports.HashV1::new_f4(), SHA-1/MD5 only. ALGO bit 18 is reserved, and the extended HR window is absent.Usart::new_legacy). RCC: F4 ready bits.--rng-fault seed|clock:<reads>[:sticky].:stickynever clears.--timeoutlogs the PC it stopped at.rng-fault-f4: the StdPeriph and NOLIB arms, for the sim or the Discovery board (board-run.shflashes it and reads the result back with OpenOCD). ST's StdPeriph library isn't vendored; a small shim implements the calls the seed code makes.wolfcrypt-test-f417: the STM32CubeF4 HAL (stm32f4xx-hal-driver,STM32_HAL_V2).Dockerfile.wolfcryptaddscmsis-device-f4andstm32f4xx-hal-driver; there is a newstm32-wolfcrypt-test-f417workflow; READMEs are updated.Found along the way
PIC32MZSim CI fix
wolfSSL master
76aed2f9d4("Use available entropy sources in embedded configurations") turned weak PIC32 seed sources into#errors. That broke three of the four PIC32MZ wolfCrypt jobs on every PR:WOLFSSL_ACCEPT_WEAK_ENTROPY.WOLFSSL_PIC32MZ_RNG(the direct port gets it withWOLFSSL_MICROCHIP_PIC32MZ), so wolfSSL fell back torand()seeded from the core timer. That is now an#errortoo, even on the EF, which has a TRNG.PIC32MZSim/firmware/common/user_settings.hnow definesWOLFSSL_PIC32MZ_RNGfor the Harmony tier, so it seeds from the RNG block like the direct port and the EF uses its TRNG. It also definesWOLFSSL_ACCEPT_WEAK_ENTROPYon EC parts only, keyed on__PIC32_FEATURE_SET1the same way wolfSSL's own check is. All four tiers (EC/EF, direct/Harmony) pass against wolfSSL master in the CI images.