Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The policy changes are internally consistent and comprehensively covered by targeted configuration tests.
0 open findings
What changed in this PR
Strengthens wolfPSA’s constant-time AES policy to reject unsafe GHASH and assembly configurations.
Changes:
- Adds GHASH, assembly-backend, RISC-V, and FIPS policy checks.
- Documents the expanded
WOLFPSA_AES_FASTwaiver. - Adds policy tests and CI coverage across supported wolfSSL versions.
| File | Description |
|---|---|
src/psa_config.h |
Enforces constant-time AES and GHASH configurations. |
build-test/psa-config-policy.sh |
Tests accepted, rejected, and waived configurations. |
.github/workflows/build-config-matrix.yml |
Runs policy tests and adds a table-GHASH waiver build. |
zephyr/Kconfig |
Updates waiver guidance for GHASH and Arm assembly. |
zephyr/README.md |
Documents the expanded policy and trade-offs. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@wolfSSL-Fenrir-bot review balanced |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #34
No scan targets match the changed files in this PR. Review skipped.
0050877 to
5ea804e
Compare
| @@ -82,7 +82,21 @@ config, wolfPSA's Kconfig turns both on; a settings file must set them itself: | |||
| `WOLFPSA_AES_FAST` to waive it and take wolfCrypt's faster T-table core | |||
| instead. `zephyr/user_settings_example.h` selects `WOLFSSL_AES_TOUCH_LINES`: | |||
There was a problem hiding this comment.
AI says the Zephyr build fails with wolfssl 5.9.4 and no settings file (CI only builds Zephyr with CONFIG_WOLFSSL_SETTINGS_FILE set). Can you check? Maybe we should add this to CI
There was a problem hiding this comment.
Confirmed: wolfSSL 5.9.4's module hard-codes GCM_SMALL, so the GHASH check fires without a settings file. The README now says so, and CI builds psa_consumer on the module config, with WOLFPSA_AES_FAST on 5.9.4.
| /* FIPS v2 and v5 have no RISC-V AES, and the older port in v6 runs a branching | ||
| * GHASH unless its carry-less multiply macros are also set. */ | ||
| #undef WOLFPSA_RISCV_CRYPTO_CT | ||
| #if defined(WOLFSSL_RISCV_ASM) && \ |
There was a problem hiding this comment.
I'm a bit concerned that we are inferring wolfSSL implementation in wolfPSA, and even duplicating some logic. Feels a bit fragile. Not a blocker for this PR, but I suggest this logic should live in wolfSSL, and it could provide flags indicating which algs are implemented as CT.
There was a problem hiding this comment.
Agreed. I'll propose a flag in wolfSSL's aes.h saying whether the AES core and GHASH are constant time, on top of wolfSSL/wolfssl#12089, and have psa_config.h prefer it, keeping this logic as the fallback.
psa_config.h only looked at the AES block cipher core, so two non-constant-time configurations passed its check. GHASH. Only the 64-bit GHASH wolfCrypt builds with no GCM method set is masked. GCM_SMALL and GCM_WORD32 branch on the hash subkey, and GCM_TABLE and GCM_TABLE_4BIT index tables with secret data, as does anything built with AES_GCM_GMULT_NCT. Without WORD64_AVAILABLE (NO_64BIT, a 16-bit CPU) aes.c falls back to the branching word32 multiply even with no method set. The check now rejects all of these when HAVE_AESGCM is set, whatever the AES backend: a hardware AES core does not imply a hardware GHASH (settings.h itself selects GCM_TABLE for an LTC part without the GCM engine). psa_config.h includes types.h for WORD64_AVAILABLE. Assembly. WOLFSSL_ARMASM was counted as a hardware AES backend. Every Arm port picks its AES path at run time from cpuid and falls back to T-table assembly, the Thumb2 and WOLFSSL_ARMASM_NO_HW_CRYPTO builds always use it, and WOLFSSL_AES_TOUCH_LINES has no effect on any of them. That is the reason WOLFSSL_AESNI is already left out, so WOLFSSL_ARMASM leaves the list and gets its own error. The PowerPC assembly (WOLFSSL_PPC64_ASM, WOLFSSL_PPC32_ASM) is refused the same way: it too selects vector AES at run time and falls back to a T-table core (L_AES_PPC32_te). WOLFSSL_RISCV_ASM stays on the list only with the scalar or vector crypto extension: the base RISC-V assembly uses a T-table AES (L_AES_base_te) and a GHASH that branches on each bit, while the extensions use the AES instructions and clmul or vghsh, and run all of GCM in assembly, so the C GHASH check is skipped for them. FIPS. The aes.c in FIPS v2 (WCv4-stable) and v5 (WCv5.0-RC12) has neither WC_AES_BITSLICED nor WOLFSSL_AES_TOUCH_LINES, so before v6 those macros no longer satisfy the check. FIPS v5 masks GHASH only under AES_GCM_GMULT_CT, and v2 never does. WOLFPSA_AES_FAST waives all of it, as it already did for the AES core. It stays a single waiver, so a build refused only for its GHASH gives up the constant-time AES core with it; the Zephyr README says so. On Zephyr, the wolfSSL module's default GHASH is already the masked one, so only a build that selects a GHASH table or CONFIG_WOLFCRYPT_ASM now needs CONFIG_WOLFPSA_AES_FAST. build-test/psa-config-policy.sh preprocesses psa_config.h against the sibling wolfSSL and checks which configurations it accepts and which wolfPSA error each refused one stops on, with WOLFPSA_AES_FAST as the control for every refusal. It uses build-test/user_settings.h, so it can take the bitsliced core away and reach the generic AES refusal, and it covers the FIPS cases through an empty wolfcrypt/fips.h stub, since a plain wolfSSL tree has none. The build matrix runs it against both wolfSSL refs, and a new aes-fast-gcm-table lane builds the waiver with a GHASH table.
WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP compiles the base T-table assembly, including its te/td tables, out of armv8-aes-asm.S. On AArch64 with NEON every AES path in aes.c then runs on the AES instructions or the NEON core, which keeps its S-box in registers. GHASH there goes through GCM_gmult_len_NEON (polynomial multiplies and XORs only) or PMULL for the default 4-bit table that aes.h selects under WOLFSSL_ARMASM and for GCM_TABLE, so these builds skip the C GHASH check, the same as the RISC-V crypto extensions. GCM_SMALL is the exception: its GHASH(), used for nonces other than 12 bytes and by streaming GCM without PMULL, keeps the branching C GMULT, so it is still refused. The macro does nothing on 32-bit Arm, which has no NEON AES, and nothing is left to call with WOLFSSL_ARMASM_NO_NEON. It first appeared in wolfSSL 5.9.0, and compiled for AArch64 the aes.c of 5.9.0, 5.9.2, 5.9.4 and master references none of the base assembly, so the exemption needs 5.9.0 or later. FIPS builds are excluded: no FIPS aes.c up to v6 has the macro. wolfSSL after 5.9.4 routes 32-bit Arm AES through the C touch-lines core when WOLFSSL_AES_TOUCH_LINES is set on a Thumb-2 or WOLFSSL_ARMASM_NO_HW_CRYPTO build (e60a34d18b). Compiled for Cortex-M4 Thumb-2 and for armv7-a ARM mode, aes.c then references none of the T-table assembly in ECB, CBC, CTR, XTS, CFB, OFB, CCM, key wrap or CMAC. Its GHASH stays on the table assembly, so the exemption needs AES-GCM off. 5.9.4 still runs the T-table assembly, and the development tree reports the same version, so the check also keys on WOLFSSL_AES_TABLE_SECTION, which settings.h defines from that commit on. The hardware backend list now counts a backend under FIPS only when that module's aes.c has it. FIPS v2 lacks SiLabs, AF_ALG, devcrypto and SCE, and no FIPS module up to v6 has PSoC6 or WOLF_CRYPTO_CB_ONLY_AES, which wolfSSL added in April 2026; those FIPS builds compiled the T-table core while passing the check. The RISC-V crypto exemption excludes FIPS for the same reason: v2 and v5 have no RISC-V AES, and the older port in v6 runs a branching GHASH unless its carry-less multiply macros are set. The RISC-V refusal now tests that marker, not the combined hardware list, so an unrelated hardware AES macro no longer silences it. Each error message now says what is not constant time and why, and the cost of each fix: a larger Aes for WC_AES_BITSLICED, slower code for WOLFSSL_AES_TOUCH_LINES, the timing leak for WOLFPSA_AES_FAST. The "without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED" tail is dropped since the conflict check already reports that combination. The Zephyr README says both Arm exemptions need a custom settings file, since the wolfSSL module's own settings define WOLFSSL_ARMASM_NO_NEON and HAVE_AESGCM, and lists every GHASH setting the check refuses. The Kconfig help says the same of the waiver. The policy script puts its fips.h stub ahead of the wolfSSL tree, so a fips.h already in that tree no longer shadows it. New cases cover NEON with the GCM tables and GCM_SMALL, Thumb-2 and NO_HW_CRYPTO with and without GCM, touch-lines, AArch64 and FIPS, RISC-V under FIPS and with an unrelated hardware macro, one backend from each FIPS tier, and externally defined markers. The 32-bit pass cases expect a refusal against a tree whose aes.c has no WC_AES_TOUCH_LINES_C_CORE, so the header's probe is checked against the real feature, and the RISC-V pass cases run without the bitsliced core so the marker itself is what satisfies the AES check.
Every Zephyr app sets CONFIG_WOLFSSL_SETTINGS_FILE, so CI never built wolfPSA on the module's default config. On wolfSSL 5.9.4 that config hard-codes GCM_SMALL and the GHASH check refuses it; the GHASH choice arrived after 5.9.4. psa_consumer_mod reruns the consumer test with the settings file cleared, and the 5.9.4 rows add CONFIG_WOLFPSA_AES_FAST=y, the waiver the README now names for that release.
5ea804e to
1ecd54e
Compare
src/psa_config.honly checked the AES core, so a table-based or branching GHASH and the T-table Arm, PowerPC and RISC-V assembly passed as constant time. This is the wolfPSA side of wolfSSL/wolfssl#11691.Changes
GCM_SMALL,GCM_WORD32,GCM_TABLE,GCM_TABLE_4BIT,AES_GCM_GMULT_NCTand builds withoutWORD64_AVAILABLEunderHAVE_AESGCM.WOLFSSL_ARMASMand the PowerPC assembly from the hardware list: both fall back to T-tables.WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUPoutside FIPS on wolfSSL 5.9.0+;GCM_SMALLstays refused there.WOLFSSL_ARMASM_NO_HW_CRYPTOwithWOLFSSL_AES_TOUCH_LINESand no AES-GCM on wolfSSL after 5.9.4, which runs that AES on the C core.aes.chas it; FIPS before v6 has no constant-time software AES, and FIPS v5 GHASH needsAES_GCM_GMULT_CT.WOLFPSA_AES_FASTstays the only waiver.Behaviour change
These now stop with a
wolfPSA:error unlessWOLFPSA_AES_FASTis defined:GCM_SMALL, including autoconf's default 4-bit table.The Zephyr module's default build is unaffected.
Testing
build-test/psa-config-policy.shhas 63 cases: each refusal hits its own error and passes underWOLFPSA_AES_FAST.build-config-matrix.ymlruns it against wolfSSL master andv5.9.4-stable, and adds anaes-fast-gcm-tablelane.