From b512b4b04331c8a52bd3b9024e558ba29ebd8950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Fri, 9 Oct 2026 10:03:51 +0200 Subject: [PATCH 1/3] Reject a non-constant-time GHASH and the table-based AES assembly 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. --- .github/workflows/build-config-matrix.yml | 19 +++++ build-test/psa-config-policy.sh | 95 +++++++++++++++++++++++ src/psa_config.h | 44 ++++++++++- zephyr/Kconfig | 5 +- zephyr/README.md | 10 ++- 5 files changed, 167 insertions(+), 6 deletions(-) create mode 100755 build-test/psa-config-policy.sh diff --git a/.github/workflows/build-config-matrix.yml b/.github/workflows/build-config-matrix.yml index 90747ae4..fc21924a 100644 --- a/.github/workflows/build-config-matrix.yml +++ b/.github/workflows/build-config-matrix.yml @@ -41,6 +41,8 @@ jobs: modifiers: "-HAVE_AES_ECB +WOLFPSA_NO_AES_BITSLICED +WOLFSSL_AES_TOUCH_LINES" - name: aes-fast modifiers: "+WOLFPSA_NO_AES_BITSLICED +WOLFPSA_AES_FAST" + - name: aes-fast-gcm-table + modifiers: "+WOLFPSA_NO_AES_BITSLICED +WOLFPSA_AES_FAST +GCM_TABLE_4BIT" - name: aes-ctr modifiers: "-WOLFSSL_AES_COUNTER" - name: aes-cfb @@ -116,3 +118,20 @@ jobs: # Fail on undefined symbols LDFLAGS: -Wl,-z,defs run: ./build-test/build-variant.sh "${{ matrix.config.name }}" ${{ matrix.config.modifiers }} + + psa-config-policy: + name: psa_config.h policy / wolfSSL ${{ matrix.wolfssl-ref }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + wolfssl-ref: [ master, v5.9.4-stable ] + steps: + - name: Check out wolfPSA + uses: actions/checkout@v4 + + - name: Clone sibling wolfSSL + run: git clone --depth 1 --branch ${{ matrix.wolfssl-ref }} https://github.com/wolfSSL/wolfssl ../wolfssl + + - name: Check accepted and refused configurations + run: ./build-test/psa-config-policy.sh ../wolfssl diff --git a/build-test/psa-config-policy.sh b/build-test/psa-config-policy.sh new file mode 100755 index 00000000..f0716419 --- /dev/null +++ b/build-test/psa-config-policy.sh @@ -0,0 +1,95 @@ +#!/bin/sh +# +# Check that src/psa_config.h accepts and refuses the AES and GHASH +# configurations it should, by preprocessing it against the sibling wolfSSL. +# build-test/user_settings.h is the config, so WOLFPSA_NO_AES_BITSLICED can +# take the constant-time AES core away. +# +# Usage: build-test/psa-config-policy.sh [WOLFSSL_PATH] + +set -u + +repo_root="$(cd "$(dirname "$0")/.." && pwd)" +wolfssl="${1:-${repo_root}/../wolfssl}" +cc="${CC:-cc}" +fails=0 + +# wolfcrypt/fips.h ships only with a FIPS bundle; an empty one lets the +# HAVE_FIPS cases preprocess against a plain wolfSSL tree. +stub="$(mktemp -d)" +trap 'rm -rf "${stub}"' EXIT +mkdir -p "${stub}/wolfssl/wolfcrypt" +: > "${stub}/wolfssl/wolfcrypt/fips.h" + +# check [-DFLAG ...] +# The outcome is "pass", or a fragment of the wolfPSA #error the build must +# stop on, so a failure for any other reason does not count. +check() { + want="$1" + shift + out="$(echo '#include "psa_config.h"' | "${cc}" -x c -fsyntax-only \ + -I"${repo_root}/build-test" -I"${repo_root}/src" -I"${wolfssl}" \ + -I"${stub}" \ + -DWOLFSSL_USER_SETTINGS -DHAVE_AESGCM -DHAVE_AES_ECB "$@" - 2>&1)" + rc=$? + if [ "${want}" = "pass" ]; then + [ "${rc}" -eq 0 ] && ok=1 || ok=0 + else + case "${out}" in + *"wolfPSA: ${want}"*) ok=1 ;; + *) ok=0 ;; + esac + fi + if [ "${ok}" -eq 1 ]; then + echo "ok $*" + else + echo "FAIL expected '${want}': $*" + echo "${out}" | grep -m3 "error" + fails=$((fails + 1)) + fi +} + +ghash="GHASH is not constant time" +nobs="-DWOLFPSA_NO_AES_BITSLICED" +hwaes="-DWOLF_CRYPTO_CB -DWOLF_CRYPTO_CB_ONLY_AES" +fips2="-DHAVE_FIPS -DHAVE_FIPS_VERSION=2 -DHAVE_FIPS_VERSION_MAJOR=2" +fips5="-DHAVE_FIPS -DHAVE_FIPS_VERSION=5 -DHAVE_FIPS_VERSION_MAJOR=5" +fips6="-DHAVE_FIPS -DHAVE_FIPS_VERSION=6 -DHAVE_FIPS_VERSION_MAJOR=6" + +check pass +check pass ${nobs} -DWOLFSSL_AES_TOUCH_LINES +check pass ${nobs} ${hwaes} +check "AES backend is not constant time" ${nobs} +check "AES backend is not constant time" ${nobs} -DWOLFPSA_AES_HW_BACKEND +check "${ghash}" ${nobs} ${hwaes} -DGCM_TABLE +check "${ghash}" -DGCM_SMALL +check "${ghash}" -DGCM_WORD32 +check "${ghash}" -DGCM_TABLE +check "${ghash}" -DGCM_TABLE -DWOLFPSA_GHASH_HW_BACKEND +check "${ghash}" -DGCM_TABLE_4BIT +check "${ghash}" -DAES_GCM_GMULT_NCT +check "the masked GHASH needs a 64-bit type" -DNO_64BIT +check "the Arm AES assembly" -DWOLFSSL_ARMASM +check "the PowerPC AES assembly" -DWOLFSSL_PPC64_ASM +check "the PowerPC AES assembly" -DWOLFSSL_PPC32_ASM +check "the RISC-V assembly" -DWOLFSSL_RISCV_ASM +check pass -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM +check pass -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_VECTOR_CRYPTO_ASM +check pass -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM -DGCM_TABLE_4BIT + +check "FIPS modules before v6" ${fips5} +check "FIPS v2 has no constant-time GHASH" ${fips2} ${nobs} ${hwaes} +check "FIPS v5 masks GHASH only under" ${fips5} ${nobs} ${hwaes} +check pass ${fips5} ${nobs} ${hwaes} -DAES_GCM_GMULT_CT +check pass ${fips6} +check pass -DWOLFPSA_AES_FAST ${fips2} +check pass -DWOLFPSA_AES_FAST ${fips5} + +# WOLFPSA_AES_FAST waives each of the refusals above. +for flag in GCM_SMALL GCM_WORD32 GCM_TABLE GCM_TABLE_4BIT AES_GCM_GMULT_NCT \ + NO_64BIT WOLFSSL_ARMASM WOLFSSL_PPC64_ASM WOLFSSL_PPC32_ASM \ + WOLFSSL_RISCV_ASM; do + check pass -DWOLFPSA_AES_FAST "-D${flag}" +done + +[ "${fails}" -eq 0 ] diff --git a/src/psa_config.h b/src/psa_config.h index 947506c8..18449ecb 100644 --- a/src/psa_config.h +++ b/src/psa_config.h @@ -28,6 +28,7 @@ #define WOLFPSA_CONFIG_H #include +#include #if defined(WOLFSSL_PSA_ENGINE) && !defined(NO_AES) @@ -50,7 +51,9 @@ * outside would otherwise satisfy the policy check below on any build. */ #undef WOLFPSA_AES_HW_BACKEND -#if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM) || \ +#if (defined(WOLFSSL_RISCV_ASM) && \ + (defined(WOLFSSL_RISCV_SCALAR_CRYPTO_ASM) || \ + defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM))) || \ defined(FREESCALE_LTC) || defined(FREESCALE_MMCAU) || \ defined(WOLFSSL_SILABS_SE_ACCEL) || defined(WOLFSSL_PSOC6_CRYPTO) || \ defined(WOLFSSL_AFALG) || defined(WOLFSSL_DEVCRYPTO_AES) || \ @@ -60,11 +63,46 @@ #define WOLFPSA_AES_HW_BACKEND #endif -#if !defined(WOLFPSA_AES_FAST) && !defined(WC_AES_BITSLICED) && \ - !defined(WOLFSSL_AES_TOUCH_LINES) && !defined(WOLFPSA_AES_HW_BACKEND) +/* The RISC-V crypto extensions run all of GCM in assembly, never the C GHASH. */ +#undef WOLFPSA_GHASH_HW_BACKEND +#if defined(WOLFSSL_RISCV_ASM) && \ + (defined(WOLFSSL_RISCV_SCALAR_CRYPTO_ASM) || \ + defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM)) + #define WOLFPSA_GHASH_HW_BACKEND +#endif + +#ifndef WOLFPSA_AES_FAST +#if defined(WOLFSSL_ARMASM) +#error "wolfPSA: the Arm AES assembly falls back to a T-table core and ignores WOLFSSL_AES_TOUCH_LINES. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#elif defined(WOLFSSL_PPC64_ASM) || defined(WOLFSSL_PPC32_ASM) +#error "wolfPSA: the PowerPC AES assembly falls back to a T-table core and ignores WOLFSSL_AES_TOUCH_LINES. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#elif defined(WOLFSSL_RISCV_ASM) && !defined(WOLFPSA_AES_HW_BACKEND) +#error "wolfPSA: the RISC-V assembly without the scalar or vector crypto extension uses a T-table AES and a branching GHASH. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && \ + !defined(WOLFPSA_AES_HW_BACKEND) +#error "wolfPSA: FIPS modules before v6 have neither WC_AES_BITSLICED nor WOLFSSL_AES_TOUCH_LINES. Define WOLFPSA_AES_FAST, without either of them, to accept the T-table core." +#elif !defined(WC_AES_BITSLICED) && !defined(WOLFSSL_AES_TOUCH_LINES) && \ + !defined(WOLFPSA_AES_HW_BACKEND) #error "wolfPSA: AES backend is not constant time. Select WC_AES_BITSLICED or WOLFSSL_AES_TOUCH_LINES, or define WOLFPSA_AES_FAST to accept the T-table core." #endif +/* Only the 64-bit GHASH built with no GCM method set is masked; FIPS v5 masks + * it only under AES_GCM_GMULT_CT, and FIPS v2 never does. */ +#if defined(HAVE_AESGCM) && !defined(WOLFPSA_GHASH_HW_BACKEND) +#if defined(GCM_SMALL) || defined(GCM_WORD32) || defined(GCM_TABLE) || \ + defined(GCM_TABLE_4BIT) || defined(AES_GCM_GMULT_NCT) +#error "wolfPSA: GHASH is not constant time. Leave the GCM method unset and AES_GCM_GMULT_NCT undefined for the masked multiply (an LTC part without its GCM engine sets GCM_TABLE itself), or define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED." +#elif !defined(WORD64_AVAILABLE) +#error "wolfPSA: the masked GHASH needs a 64-bit type, and WORD64_AVAILABLE is off (NO_64BIT, or a 16-bit CPU). Remove NO_64BIT, or define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept the branching one." +#elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(5,0,0) +#error "wolfPSA: FIPS v2 has no constant-time GHASH. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && \ + !defined(AES_GCM_GMULT_CT) +#error "wolfPSA: FIPS v5 masks GHASH only under AES_GCM_GMULT_CT. Define it, or define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED." +#endif +#endif /* HAVE_AESGCM && !WOLFPSA_GHASH_HW_BACKEND */ +#endif /* !WOLFPSA_AES_FAST */ + #if defined(WOLFPSA_AES_FAST) && \ (defined(WC_AES_BITSLICED) || defined(WOLFSSL_AES_TOUCH_LINES)) #error "wolfPSA: WOLFPSA_AES_FAST conflicts with WC_AES_BITSLICED/WOLFSSL_AES_TOUCH_LINES" diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 3448e895..42728e55 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -59,8 +59,9 @@ config WOLFPSA_AES_FAST bool "Accept wolfCrypt's T-table AES core (not constant time)" help Define WOLFPSA_AES_FAST, which waives src/psa_config.h's requirement for - an AES backend with no secret-indexed table load, and leaves - WOLFSSL_AES_CONSTANT_TIME off by default. + an AES backend and a GHASH with no secret-indexed table load, and leaves + WOLFSSL_AES_CONSTANT_TIME off by default. Builds with the Arm assembly + need it, since that assembly falls back to a T-table core. The T-table core is wolfCrypt's fastest software AES, and its access pattern is key- and state-dependent. Enable this only where that timing diff --git a/zephyr/README.md b/zephyr/README.md index 2b76fa11..0a0ed68f 100644 --- a/zephyr/README.md +++ b/zephyr/README.md @@ -84,7 +84,15 @@ 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`: it leaves `sizeof(Aes)` at 416 bytes, where `WC_AES_BITSLICED` would grow it - to 123,296 at the default `WC_AES_BS_WORD_SIZE` of 64. + to 123,296 at the default `WC_AES_BS_WORD_SIZE` of 64. AES-GCM also needs + the masked GHASH, which the wolfSSL module builds by default; a GCM table or + `GCM_SMALL` fails the check unless `WOLFPSA_AES_FAST` is set. The Arm + symmetric assembly (`CONFIG_WOLFCRYPT_ARM_SYMMETRIC_ASM`, which + `CONFIG_WOLFCRYPT_ASM` turns on for AArch64, ARMv7-M, ARMv8-M mainline and + 32-bit Cortex-A/R) is not constant time either and needs `WOLFPSA_AES_FAST`. + That one option waives both checks and cannot be combined with + `WOLFSSL_AES_TOUCH_LINES` or `WC_AES_BITSLICED`, so a build refused only for + its GHASH gives up the constant-time AES core as well. - `WC_ALLOW_ECC_ZERO_HASH` when `HAVE_ECC` is on, because `psa_sign_hash()`/`psa_verify_hash()` must accept an all-zero digest. From 7a9bb3d37aabaf1b3b7783c5e5630d09afffea4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Fri, 6 Nov 2026 08:44:07 +0100 Subject: [PATCH 2/3] Accept AArch64 NEON and 32-bit Arm touch-lines AES, say "constant time" 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. --- build-test/psa-config-policy.sh | 81 ++++++++++++++++++++++-------- src/psa_config.h | 89 +++++++++++++++++++++++---------- zephyr/Kconfig | 5 +- zephyr/README.md | 14 ++++-- 4 files changed, 136 insertions(+), 53 deletions(-) diff --git a/build-test/psa-config-policy.sh b/build-test/psa-config-policy.sh index f0716419..db7968fe 100755 --- a/build-test/psa-config-policy.sh +++ b/build-test/psa-config-policy.sh @@ -1,9 +1,7 @@ #!/bin/sh # -# Check that src/psa_config.h accepts and refuses the AES and GHASH -# configurations it should, by preprocessing it against the sibling wolfSSL. -# build-test/user_settings.h is the config, so WOLFPSA_NO_AES_BITSLICED can -# take the constant-time AES core away. +# Preprocess src/psa_config.h against a wolfSSL tree and check which AES and +# GHASH configurations it accepts and refuses. # # Usage: build-test/psa-config-policy.sh [WOLFSSL_PATH] @@ -21,15 +19,13 @@ trap 'rm -rf "${stub}"' EXIT mkdir -p "${stub}/wolfssl/wolfcrypt" : > "${stub}/wolfssl/wolfcrypt/fips.h" -# check [-DFLAG ...] -# The outcome is "pass", or a fragment of the wolfPSA #error the build must -# stop on, so a failure for any other reason does not count. +# check <"pass" | fragment of the expected wolfPSA #error> [-DFLAG ...] check() { want="$1" shift out="$(echo '#include "psa_config.h"' | "${cc}" -x c -fsyntax-only \ - -I"${repo_root}/build-test" -I"${repo_root}/src" -I"${wolfssl}" \ - -I"${stub}" \ + -I"${repo_root}/build-test" -I"${repo_root}/src" -I"${stub}" \ + -I"${wolfssl}" \ -DWOLFSSL_USER_SETTINGS -DHAVE_AESGCM -DHAVE_AES_ECB "$@" - 2>&1)" rc=$? if [ "${want}" = "pass" ]; then @@ -49,18 +45,32 @@ check() { fi } -ghash="GHASH is not constant time" +ghash="GHASH is not constant time:" nobs="-DWOLFPSA_NO_AES_BITSLICED" hwaes="-DWOLF_CRYPTO_CB -DWOLF_CRYPTO_CB_ONLY_AES" +# Backends that every FIPS aes.c, FIPS v5 on, and none of them carry. +hwall="-DWOLFSSL_PIC32MZ_CRYPT" +hwv5="-DWOLFSSL_DEVCRYPTO_AES" +hwnofips="-DWOLFSSL_PSOC6_CRYPTO" fips2="-DHAVE_FIPS -DHAVE_FIPS_VERSION=2 -DHAVE_FIPS_VERSION_MAJOR=2" fips5="-DHAVE_FIPS -DHAVE_FIPS_VERSION=5 -DHAVE_FIPS_VERSION_MAJOR=5" fips6="-DHAVE_FIPS -DHAVE_FIPS_VERSION=6 -DHAVE_FIPS_VERSION_MAJOR=6" +neon="-DWOLFSSL_ARMASM -D__aarch64__ -DWOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP" +a32="-DWOLFSSL_ARMASM -U__aarch64__ -DWOLFSSL_AES_TOUCH_LINES" +t2="${a32} -DWOLFSSL_ARMASM_THUMB2" +nohw="${a32} -DWOLFSSL_ARMASM_NO_HW_CRYPTO" +nogcm="-UHAVE_AESGCM" +if grep -q WC_AES_TOUCH_LINES_C_CORE "${wolfssl}/wolfcrypt/src/aes.c"; then + a32_nogcm="pass" +else + a32_nogcm="the Arm AES assembly" +fi check pass check pass ${nobs} -DWOLFSSL_AES_TOUCH_LINES check pass ${nobs} ${hwaes} -check "AES backend is not constant time" ${nobs} -check "AES backend is not constant time" ${nobs} -DWOLFPSA_AES_HW_BACKEND +check "the AES backend is not constant time" ${nobs} +check "the AES backend is not constant time" ${nobs} -DWOLFPSA_AES_HW_BACKEND check "${ghash}" ${nobs} ${hwaes} -DGCM_TABLE check "${ghash}" -DGCM_SMALL check "${ghash}" -DGCM_WORD32 @@ -68,20 +78,51 @@ check "${ghash}" -DGCM_TABLE check "${ghash}" -DGCM_TABLE -DWOLFPSA_GHASH_HW_BACKEND check "${ghash}" -DGCM_TABLE_4BIT check "${ghash}" -DAES_GCM_GMULT_NCT -check "the masked GHASH needs a 64-bit type" -DNO_64BIT +check "GHASH is not constant time without a 64-bit type" -DNO_64BIT check "the Arm AES assembly" -DWOLFSSL_ARMASM +check pass ${nobs} ${neon} +check pass ${nobs} ${neon} -DGCM_TABLE_4BIT +check pass ${nobs} ${neon} -DGCM_TABLE +check "the Arm AES assembly" ${nobs} ${neon} -U__aarch64__ +check "the Arm AES assembly" ${nobs} ${neon} -DWOLFSSL_ARMASM_NO_NEON +check "the Arm AES assembly" ${nobs} ${neon} ${fips6} +check "the Arm AES assembly" ${nobs} -DWOLFSSL_ARMASM -DWOLFPSA_ARM64_NEON_CT +check "${ghash}" ${nobs} ${neon} -DGCM_SMALL +check "${a32_nogcm}" ${nobs} ${t2} ${nogcm} +check "${a32_nogcm}" ${nobs} ${nohw} ${nogcm} +check "the Arm AES assembly" ${nobs} ${t2} +check "the Arm AES assembly" ${nobs} ${nohw} +check "the Arm AES assembly" ${nobs} ${t2} ${nogcm} ${fips6} +check "the Arm AES assembly" ${nobs} ${t2} ${nogcm} -UWOLFSSL_AES_TOUCH_LINES +check "the Arm AES assembly" ${nobs} ${a32} ${nogcm} +check "the Arm AES assembly" ${nobs} ${t2} ${nogcm} -D__aarch64__ +check "the Arm AES assembly" ${nobs} -DWOLFSSL_ARMASM -U__aarch64__ \ + -DWOLFPSA_ARM32_TOUCH_LINES_CT ${nogcm} check "the PowerPC AES assembly" -DWOLFSSL_PPC64_ASM check "the PowerPC AES assembly" -DWOLFSSL_PPC32_ASM check "the RISC-V assembly" -DWOLFSSL_RISCV_ASM -check pass -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM -check pass -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_VECTOR_CRYPTO_ASM -check pass -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM -DGCM_TABLE_4BIT +check "the RISC-V assembly" ${nobs} ${hwaes} -DWOLFSSL_RISCV_ASM +check "the RISC-V assembly" -DWOLFSSL_RISCV_ASM -DWOLFPSA_RISCV_CRYPTO_CT +check pass ${nobs} -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM +check pass ${nobs} -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_VECTOR_CRYPTO_ASM +check pass ${nobs} -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM \ + -DGCM_TABLE_4BIT +check pass ${nobs} ${hwnofips} -check "FIPS modules before v6" ${fips5} -check "FIPS v2 has no constant-time GHASH" ${fips2} ${nobs} ${hwaes} -check "FIPS v5 masks GHASH only under" ${fips5} ${nobs} ${hwaes} -check pass ${fips5} ${nobs} ${hwaes} -DAES_GCM_GMULT_CT +check "AES in FIPS modules before v6" ${fips5} +check "GHASH in FIPS v2 is not constant time" ${fips2} ${nobs} ${hwall} +check "AES in FIPS modules before v6" ${fips2} ${nobs} ${hwv5} +check "GHASH in FIPS v5 is constant time only under" ${fips5} ${nobs} ${hwv5} +check pass ${fips5} ${nobs} ${hwv5} -DAES_GCM_GMULT_CT +check "AES in FIPS modules before v6" ${fips5} ${nobs} ${hwaes} \ + -DAES_GCM_GMULT_CT check pass ${fips6} +check pass ${fips6} ${nobs} ${hwv5} +check "the AES backend is not constant time" ${fips6} ${nobs} ${hwaes} +check "the RISC-V assembly" ${fips5} ${nobs} -DWOLFSSL_RISCV_ASM \ + -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM -DAES_GCM_GMULT_CT +check "the RISC-V assembly" ${fips6} -DWOLFSSL_RISCV_ASM \ + -DWOLFSSL_RISCV_VECTOR_CRYPTO_ASM check pass -DWOLFPSA_AES_FAST ${fips2} check pass -DWOLFPSA_AES_FAST ${fips5} diff --git a/src/psa_config.h b/src/psa_config.h index 18449ecb..28a17e3c 100644 --- a/src/psa_config.h +++ b/src/psa_config.h @@ -29,6 +29,7 @@ #include #include +#include #if defined(WOLFSSL_PSA_ENGINE) && !defined(NO_AES) @@ -39,10 +40,11 @@ * at W = 64 down to 1,920 at W = 8 * WOLFSSL_AES_TOUCH_LINES every lookup touches each cache line of the * table; sizeof(Aes) is unchanged - * a hardware AES core the list below, which compiles no software - * tables. WOLFSSL_AESNI and WOLFSSL_ESP32_CRYPT - * are absent: both keep the T-table core as a - * runtime fallback + * a listed backend the list below: hardware AES cores, the RISC-V + * AES instructions and the AArch64 NEON core, none + * with a table in memory. WOLFSSL_AESNI and + * WOLFSSL_ESP32_CRYPT are absent: both keep the + * T-table core as a runtime fallback * WOLFPSA_AES_FAST waives the check and accepts the T-table core: * faster, not constant time, not PSA compliant */ @@ -51,39 +53,72 @@ * outside would otherwise satisfy the policy check below on any build. */ #undef WOLFPSA_AES_HW_BACKEND -#if (defined(WOLFSSL_RISCV_ASM) && \ - (defined(WOLFSSL_RISCV_SCALAR_CRYPTO_ASM) || \ - defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM))) || \ - defined(FREESCALE_LTC) || defined(FREESCALE_MMCAU) || \ - defined(WOLFSSL_SILABS_SE_ACCEL) || defined(WOLFSSL_PSOC6_CRYPTO) || \ - defined(WOLFSSL_AFALG) || defined(WOLFSSL_DEVCRYPTO_AES) || \ +/* 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) && \ + (defined(WOLFSSL_RISCV_SCALAR_CRYPTO_ASM) || \ + defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM)) && !defined(HAVE_FIPS) + #define WOLFPSA_RISCV_CRYPTO_CT +#endif + +/* The AArch64 NEON AES and GHASH keep their tables in registers. wolfSSL 5.9.0 + * added WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP; no FIPS aes.c up to v6 has it. */ +#undef WOLFPSA_ARM64_NEON_CT +#if defined(WOLFSSL_ARMASM) && defined(__aarch64__) && \ + !defined(WOLFSSL_ARMASM_NO_NEON) && \ + defined(WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP) && !defined(HAVE_FIPS) && \ + LIBWOLFSSL_VERSION_HEX >= 0x05009000 + #define WOLFPSA_ARM64_NEON_CT +#endif + +/* wolfSSL after 5.9.4 (first to define WOLFSSL_AES_TABLE_SECTION) runs this + * AES on the C touch-lines core; its GHASH stays on the table assembly. */ +#undef WOLFPSA_ARM32_TOUCH_LINES_CT +#if defined(WOLFSSL_ARMASM) && !defined(__aarch64__) && \ + (defined(WOLFSSL_ARMASM_THUMB2) || \ + defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) && \ + defined(WOLFSSL_AES_TOUCH_LINES) && !defined(HAVE_AESGCM) && \ + !defined(HAVE_FIPS) && (defined(WOLFSSL_AES_TABLE_SECTION) || \ + LIBWOLFSSL_VERSION_HEX > 0x05009004) + #define WOLFPSA_ARM32_TOUCH_LINES_CT +#endif + +/* Grouped by the FIPS aes.c that has them: every version, v5 on, none. */ +#if defined(FREESCALE_LTC) || defined(FREESCALE_MMCAU) || \ defined(WOLFSSL_PIC32MZ_CRYPT) || defined(WOLFSSL_NRF51_AES) || \ - defined(WOLFSSL_SCE) || defined(HAVE_COLDFIRE_SEC) || \ - defined(WOLF_CRYPTO_CB_ONLY_AES) + defined(HAVE_COLDFIRE_SEC) || \ + ((!defined(HAVE_FIPS) || FIPS_VERSION3_GE(5,0,0)) && \ + (defined(WOLFSSL_SILABS_SE_ACCEL) || defined(WOLFSSL_AFALG) || \ + defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_SCE))) || \ + (!defined(HAVE_FIPS) && \ + (defined(WOLFSSL_PSOC6_CRYPTO) || defined(WOLF_CRYPTO_CB_ONLY_AES))) || \ + defined(WOLFPSA_RISCV_CRYPTO_CT) || defined(WOLFPSA_ARM64_NEON_CT) #define WOLFPSA_AES_HW_BACKEND #endif -/* The RISC-V crypto extensions run all of GCM in assembly, never the C GHASH. */ +/* These run GHASH in assembly, except GHASH() under GCM_SMALL on AArch64, + * which keeps the branching C GMULT. */ #undef WOLFPSA_GHASH_HW_BACKEND -#if defined(WOLFSSL_RISCV_ASM) && \ - (defined(WOLFSSL_RISCV_SCALAR_CRYPTO_ASM) || \ - defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM)) +#if defined(WOLFPSA_RISCV_CRYPTO_CT) || \ + (defined(WOLFPSA_ARM64_NEON_CT) && !defined(GCM_SMALL)) #define WOLFPSA_GHASH_HW_BACKEND #endif #ifndef WOLFPSA_AES_FAST -#if defined(WOLFSSL_ARMASM) -#error "wolfPSA: the Arm AES assembly falls back to a T-table core and ignores WOLFSSL_AES_TOUCH_LINES. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#if defined(WOLFSSL_ARMASM) && !defined(WOLFPSA_ARM64_NEON_CT) && \ + !defined(WOLFPSA_ARM32_TOUCH_LINES_CT) +#error "wolfPSA: the Arm AES assembly is not constant time: it falls back to T-table lookups, whose timing depends on the key and data. Outside FIPS, define WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP on AArch64 with NEON on (wolfSSL 5.9.0 or later), or WOLFSSL_AES_TOUCH_LINES on 32-bit Thumb-2 or WOLFSSL_ARMASM_NO_HW_CRYPTO without AES-GCM (wolfSSL after 5.9.4); or define WOLFPSA_AES_FAST to trade the timing leak for speed." #elif defined(WOLFSSL_PPC64_ASM) || defined(WOLFSSL_PPC32_ASM) -#error "wolfPSA: the PowerPC AES assembly falls back to a T-table core and ignores WOLFSSL_AES_TOUCH_LINES. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." -#elif defined(WOLFSSL_RISCV_ASM) && !defined(WOLFPSA_AES_HW_BACKEND) -#error "wolfPSA: the RISC-V assembly without the scalar or vector crypto extension uses a T-table AES and a branching GHASH. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#error "wolfPSA: the PowerPC AES assembly is not constant time: it falls back to T-table lookups, whose timing depends on the key and data. Define WOLFPSA_AES_FAST to trade the timing leak for speed." +#elif defined(WOLFSSL_RISCV_ASM) && !defined(WOLFPSA_RISCV_CRYPTO_CT) +#error "wolfPSA: the RISC-V assembly is not constant time without the scalar or vector crypto extension, or in a FIPS module: it uses a T-table AES or a GHASH that branches on the key. Outside FIPS, define WOLFSSL_RISCV_SCALAR_CRYPTO_ASM or WOLFSSL_RISCV_VECTOR_CRYPTO_ASM if the CPU has one; or define WOLFPSA_AES_FAST to trade the timing leak for speed." #elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && \ !defined(WOLFPSA_AES_HW_BACKEND) -#error "wolfPSA: FIPS modules before v6 have neither WC_AES_BITSLICED nor WOLFSSL_AES_TOUCH_LINES. Define WOLFPSA_AES_FAST, without either of them, to accept the T-table core." +#error "wolfPSA: AES in FIPS modules before v6 is not constant time: they have neither WC_AES_BITSLICED nor WOLFSSL_AES_TOUCH_LINES. Use a hardware AES backend, or define WOLFPSA_AES_FAST to trade the timing leak for speed." #elif !defined(WC_AES_BITSLICED) && !defined(WOLFSSL_AES_TOUCH_LINES) && \ !defined(WOLFPSA_AES_HW_BACKEND) -#error "wolfPSA: AES backend is not constant time. Select WC_AES_BITSLICED or WOLFSSL_AES_TOUCH_LINES, or define WOLFPSA_AES_FAST to accept the T-table core." +#error "wolfPSA: the AES backend is not constant time: the T-table core's timing depends on the key and data. Select WC_AES_BITSLICED (constant time, larger Aes) or WOLFSSL_AES_TOUCH_LINES (constant time, slower), or define WOLFPSA_AES_FAST to trade the timing leak for speed." #endif /* Only the 64-bit GHASH built with no GCM method set is masked; FIPS v5 masks @@ -91,14 +126,14 @@ #if defined(HAVE_AESGCM) && !defined(WOLFPSA_GHASH_HW_BACKEND) #if defined(GCM_SMALL) || defined(GCM_WORD32) || defined(GCM_TABLE) || \ defined(GCM_TABLE_4BIT) || defined(AES_GCM_GMULT_NCT) -#error "wolfPSA: GHASH is not constant time. Leave the GCM method unset and AES_GCM_GMULT_NCT undefined for the masked multiply (an LTC part without its GCM engine sets GCM_TABLE itself), or define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED." +#error "wolfPSA: GHASH is not constant time: GCM_SMALL and GCM_WORD32 branch on the hash key, and the GCM tables and AES_GCM_GMULT_NCT load from secret-indexed memory. Leave the GCM method unset and AES_GCM_GMULT_NCT undefined for the masked multiply (an LTC part without its GCM engine sets GCM_TABLE itself), or define WOLFPSA_AES_FAST to trade the timing leak for speed." #elif !defined(WORD64_AVAILABLE) -#error "wolfPSA: the masked GHASH needs a 64-bit type, and WORD64_AVAILABLE is off (NO_64BIT, or a 16-bit CPU). Remove NO_64BIT, or define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept the branching one." +#error "wolfPSA: GHASH is not constant time without a 64-bit type: WORD64_AVAILABLE is off (NO_64BIT, or a 16-bit CPU), so wolfCrypt uses a multiply that branches on the hash key. Remove NO_64BIT, or define WOLFPSA_AES_FAST to trade the timing leak for speed." #elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(5,0,0) -#error "wolfPSA: FIPS v2 has no constant-time GHASH. Define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED, to accept it." +#error "wolfPSA: GHASH in FIPS v2 is not constant time. Define WOLFPSA_AES_FAST to trade the timing leak for speed." #elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && \ !defined(AES_GCM_GMULT_CT) -#error "wolfPSA: FIPS v5 masks GHASH only under AES_GCM_GMULT_CT. Define it, or define WOLFPSA_AES_FAST, without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED." +#error "wolfPSA: GHASH in FIPS v5 is constant time only under AES_GCM_GMULT_CT. Define it, or define WOLFPSA_AES_FAST to trade the timing leak for speed." #endif #endif /* HAVE_AESGCM && !WOLFPSA_GHASH_HW_BACKEND */ #endif /* !WOLFPSA_AES_FAST */ diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 42728e55..3a262611 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -59,9 +59,10 @@ config WOLFPSA_AES_FAST bool "Accept wolfCrypt's T-table AES core (not constant time)" help Define WOLFPSA_AES_FAST, which waives src/psa_config.h's requirement for - an AES backend and a GHASH with no secret-indexed table load, and leaves + a constant-time AES backend and GHASH, and leaves WOLFSSL_AES_CONSTANT_TIME off by default. Builds with the Arm assembly - need it, since that assembly falls back to a T-table core. + from the wolfSSL module's settings need it, since that assembly falls + back to a T-table core. The T-table core is wolfCrypt's fastest software AES, and its access pattern is key- and state-dependent. Enable this only where that timing diff --git a/zephyr/README.md b/zephyr/README.md index 0a0ed68f..f1989aad 100644 --- a/zephyr/README.md +++ b/zephyr/README.md @@ -85,14 +85,20 @@ config, wolfPSA's Kconfig turns both on; a settings file must set them itself: instead. `zephyr/user_settings_example.h` selects `WOLFSSL_AES_TOUCH_LINES`: it leaves `sizeof(Aes)` at 416 bytes, where `WC_AES_BITSLICED` would grow it to 123,296 at the default `WC_AES_BS_WORD_SIZE` of 64. AES-GCM also needs - the masked GHASH, which the wolfSSL module builds by default; a GCM table or - `GCM_SMALL` fails the check unless `WOLFPSA_AES_FAST` is set. The Arm - symmetric assembly (`CONFIG_WOLFCRYPT_ARM_SYMMETRIC_ASM`, which + the masked GHASH, which the wolfSSL module builds by default outside FIPS v2; + a GCM table, `GCM_SMALL`, `GCM_WORD32`, `AES_GCM_GMULT_NCT` or a build + without a 64-bit type fails the check unless `WOLFPSA_AES_FAST` is set. The + Arm symmetric assembly (`CONFIG_WOLFCRYPT_ARM_SYMMETRIC_ASM`, which `CONFIG_WOLFCRYPT_ASM` turns on for AArch64, ARMv7-M, ARMv8-M mainline and 32-bit Cortex-A/R) is not constant time either and needs `WOLFPSA_AES_FAST`. That one option waives both checks and cannot be combined with `WOLFSSL_AES_TOUCH_LINES` or `WC_AES_BITSLICED`, so a build refused only for - its GHASH gives up the constant-time AES core as well. + its GHASH gives up the constant-time AES core as well. A custom settings file + can avoid the waiver for the Arm assembly on AArch64 with NEON and + `WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP`, or on 32-bit Thumb-2 or + `WOLFSSL_ARMASM_NO_HW_CRYPTO` with `WOLFSSL_AES_TOUCH_LINES` and no AES-GCM on + wolfSSL after 5.9.4. The wolfSSL module's own settings allow neither, since + they define `WOLFSSL_ARMASM_NO_NEON` and `HAVE_AESGCM`. - `WC_ALLOW_ECC_ZERO_HASH` when `HAVE_ECC` is on, because `psa_sign_hash()`/`psa_verify_hash()` must accept an all-zero digest. From 1ecd54e7c6526df974a2a1342cb6a830ce0793bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Mon, 16 Nov 2026 13:49:48 +0100 Subject: [PATCH 3/3] Build the Zephyr consumer test on the wolfSSL module's own config 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. --- .github/scripts/run-tests.sh | 4 ++++ .github/scripts/zephyr-4.x/zephyr-test.sh | 7 ++++++- .github/workflows/zephyr-4.x.yml | 8 +++++++- zephyr/README.md | 8 +++++--- zephyr/tests/psa_consumer/module_config.conf | 5 +++++ 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 zephyr/tests/psa_consumer/module_config.conf diff --git a/.github/scripts/run-tests.sh b/.github/scripts/run-tests.sh index f83761b6..d87c9bd4 100755 --- a/.github/scripts/run-tests.sh +++ b/.github/scripts/run-tests.sh @@ -22,6 +22,7 @@ # wolfPSA is already a manifest module (e.g. CI, where # zephyr-test.sh injects it into the manifest), to avoid # registering it twice. +# MODULE_CONFIG_ARGS extra west-build args for psa_consumer_mod set -u @@ -37,10 +38,13 @@ EXTRA_MODULE_ARG="${EXTRA_MODULE_ARG--DEXTRA_ZEPHYR_MODULES=${WOLFPSA_ROOT}}" # psa_consumer_st reruns the consumer with CONFIG_WOLFPSA_THREAD_SAFE=n so the # single-threaded baseline path (SINGLE_THREADED, no-op lock macros) is built # and run in CI, not just the default thread-safe (=y) path. +# psa_consumer_mod reruns it on the wolfSSL module's own config, plus +# MODULE_CONFIG_ARGS (CI sets CONFIG_WOLFPSA_AES_FAST=y for wolfSSL 5.9.4). TARGETS=" psa_smoke|${WOLFPSA_ROOT}/zephyr/samples/psa_smoke|sample psa_consumer|${WOLFPSA_ROOT}/zephyr/tests/psa_consumer|ztest psa_consumer_st|${WOLFPSA_ROOT}/zephyr/tests/psa_consumer|ztest|-DCONFIG_WOLFPSA_THREAD_SAFE=n +psa_consumer_mod|${WOLFPSA_ROOT}/zephyr/tests/psa_consumer|ztest|-DEXTRA_CONF_FILE=module_config.conf ${MODULE_CONFIG_ARGS:-} psa_concurrency|${WOLFPSA_ROOT}/zephyr/tests/psa_concurrency|ztest psa_entropy|${WOLFPSA_ROOT}/zephyr/tests/psa_entropy|ztest psa_transform|${WOLFPSA_ROOT}/zephyr/tests/psa_transform|ztest diff --git a/.github/scripts/zephyr-4.x/zephyr-test.sh b/.github/scripts/zephyr-4.x/zephyr-test.sh index 79705d96..deb93f6d 100644 --- a/.github/scripts/zephyr-4.x/zephyr-test.sh +++ b/.github/scripts/zephyr-4.x/zephyr-test.sh @@ -17,6 +17,7 @@ # -z, --zephyr Zephyr version tag (>= v4.3.0) # --wolfssl-repo wolfSSL repo URL (default: wolfSSL/wolfssl) # --wolfssl-ref wolfSSL revision (default: master) +# --module-config-args extra west-build args for psa_consumer_mod # -h, --help Show this help # # Examples: @@ -35,6 +36,7 @@ WOLFPSA_BRANCH="master" ZEPHYR_VERSION="v4.4.0" WOLFSSL_REPO="https://github.com/wolfSSL/wolfssl" WOLFSSL_REF="master" +MODULE_CONFIG_ARGS="" GHCR="ghcr.io/zephyrproject-rtos/zephyr-build" @@ -64,6 +66,7 @@ while [[ $# -gt 0 ]]; do -z|--zephyr) ZEPHYR_VERSION="$2"; shift 2 ;; --wolfssl-repo) WOLFSSL_REPO="$2"; shift 2 ;; --wolfssl-ref) WOLFSSL_REF="$2"; shift 2 ;; + --module-config-args) MODULE_CONFIG_ARGS="$2"; shift 2 ;; -h|--help) usage ;; *) echo "Unknown option: $1"; usage ;; esac @@ -89,6 +92,7 @@ WOLFPSA_REPO="__WOLFPSA_REPO__" WOLFPSA_BRANCH="__WOLFPSA_BRANCH__" WOLFSSL_REPO="__WOLFSSL_REPO__" WOLFSSL_REF="__WOLFSSL_REF__" +MODULE_CONFIG_ARGS="__MODULE_CONFIG_ARGS__" cd /workdir @@ -128,7 +132,7 @@ fi # Both modules are in the manifest now, so the runner must NOT also add wolfPSA # via EXTRA_ZEPHYR_MODULES. echo "==> [container] Running the wolfPSA test suite..." -EXTRA_MODULE_ARG="" \ +EXTRA_MODULE_ARG="" MODULE_CONFIG_ARGS="${MODULE_CONFIG_ARGS}" \ bash modules/crypto/wolfPSA/.github/scripts/run-tests.sh INNER_SCRIPT ) @@ -138,6 +142,7 @@ BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFPSA_REPO__/$WOLFPSA_REPO}" BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFPSA_BRANCH__/$WOLFPSA_BRANCH}" BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_REPO__/$WOLFSSL_REPO}" BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_REF__/$WOLFSSL_REF}" +BUILD_SCRIPT="${BUILD_SCRIPT//__MODULE_CONFIG_ARGS__/$MODULE_CONFIG_ARGS}" cleanup() { docker rm -f "${CONTAINER_NAME}" 2>/dev/null || true; } trap cleanup EXIT diff --git a/.github/workflows/zephyr-4.x.yml b/.github/workflows/zephyr-4.x.yml index 7988e41d..056a65ac 100644 --- a/.github/workflows/zephyr-4.x.yml +++ b/.github/workflows/zephyr-4.x.yml @@ -35,6 +35,11 @@ jobs: exclude: - zephyr-ref: v4.5.0 wolfssl-ref: v5.9.4-stable + # wolfSSL 5.9.4's module config hard-codes GCM_SMALL, which wolfPSA + # accepts only with its waiver. + include: + - wolfssl-ref: v5.9.4-stable + module-config-args: -DCONFIG_WOLFPSA_AES_FAST=y steps: - name: Checkout wolfPSA CI driver uses: actions/checkout@v5 @@ -62,4 +67,5 @@ jobs: -r "${{ steps.src.outputs.repo }}" \ -b "${{ steps.src.outputs.ref }}" \ -z "${{ matrix.zephyr-ref }}" \ - --wolfssl-ref "${{ matrix.wolfssl-ref }}" + --wolfssl-ref "${{ matrix.wolfssl-ref }}" \ + --module-config-args "${{ matrix.module-config-args }}" diff --git a/zephyr/README.md b/zephyr/README.md index f1989aad..71c0a0a8 100644 --- a/zephyr/README.md +++ b/zephyr/README.md @@ -85,9 +85,11 @@ config, wolfPSA's Kconfig turns both on; a settings file must set them itself: instead. `zephyr/user_settings_example.h` selects `WOLFSSL_AES_TOUCH_LINES`: it leaves `sizeof(Aes)` at 416 bytes, where `WC_AES_BITSLICED` would grow it to 123,296 at the default `WC_AES_BS_WORD_SIZE` of 64. AES-GCM also needs - the masked GHASH, which the wolfSSL module builds by default outside FIPS v2; - a GCM table, `GCM_SMALL`, `GCM_WORD32`, `AES_GCM_GMULT_NCT` or a build - without a 64-bit type fails the check unless `WOLFPSA_AES_FAST` is set. The + the masked GHASH, which the wolfSSL module builds by default outside FIPS v2 + from the release after 5.9.4 on; a GCM table, `GCM_SMALL`, `GCM_WORD32`, + `AES_GCM_GMULT_NCT` or a build without a 64-bit type fails the check unless + `WOLFPSA_AES_FAST` is set. The wolfSSL 5.9.4 module always sets `GCM_SMALL`, + so there a build needs a settings file or `WOLFPSA_AES_FAST`. The Arm symmetric assembly (`CONFIG_WOLFCRYPT_ARM_SYMMETRIC_ASM`, which `CONFIG_WOLFCRYPT_ASM` turns on for AArch64, ARMv7-M, ARMv8-M mainline and 32-bit Cortex-A/R) is not constant time either and needs `WOLFPSA_AES_FAST`. diff --git a/zephyr/tests/psa_consumer/module_config.conf b/zephyr/tests/psa_consumer/module_config.conf new file mode 100644 index 00000000..e5eb6d99 --- /dev/null +++ b/zephyr/tests/psa_consumer/module_config.conf @@ -0,0 +1,5 @@ +# Copyright (C) 2026 wolfSSL Inc. +# SPDX-License-Identifier: GPL-3.0-or-later + +# Build on the wolfSSL module's Kconfig defaults instead of a settings file. +CONFIG_WOLFSSL_SETTINGS_FILE=""