Skip to content

Reject a non-constant-time GHASH and the table-based AES assembly - #34

Open
Frauschi wants to merge 3 commits into
wolfSSL:masterfrom
Frauschi:ghash-ct-check
Open

Frauschi wants to merge 3 commits into
wolfSSL:masterfrom
Frauschi:ghash-ct-check

Conversation

@Frauschi

@Frauschi Frauschi commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

src/psa_config.h only 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

  • Refuse GCM_SMALL, GCM_WORD32, GCM_TABLE, GCM_TABLE_4BIT, AES_GCM_GMULT_NCT and builds without WORD64_AVAILABLE under HAVE_AESGCM.
  • Drop WOLFSSL_ARMASM and the PowerPC assembly from the hardware list: both fall back to T-tables.
  • Accept AArch64 with NEON and WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP outside FIPS on wolfSSL 5.9.0+; GCM_SMALL stays refused there.
  • Accept 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, which runs that AES on the C core.
  • Accept RISC-V assembly only with a crypto extension, outside FIPS.
  • Count a hardware AES backend only for the FIPS versions whose aes.c has it; FIPS before v6 has no constant-time software AES, and FIPS v5 GHASH needs AES_GCM_GMULT_CT.
  • Errors name what is not constant time and each fix's cost; WOLFPSA_AES_FAST stays the only waiver.

Behaviour change

These now stop with a wolfPSA: error unless WOLFPSA_AES_FAST is defined:

  • AES-GCM with a GCM table or GCM_SMALL, including autoconf's default 4-bit table.
  • Arm assembly outside the two exemptions, PowerPC assembly, and RISC-V assembly without a crypto extension.
  • FIPS v2 and v5 without a hardware AES backend.

The Zephyr module's default build is unaffected.

Testing

  • New build-test/psa-config-policy.sh has 63 cases: each refusal hits its own error and passes under WOLFPSA_AES_FAST.
  • build-config-matrix.yml runs it against wolfSSL master and v5.9.4-stable, and adds an aes-fast-gcm-table lane.

@Frauschi Frauschi self-assigned this Oct 9, 2026
Copilot AI balanced review requested due to automatic review settings October 9, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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_FAST waiver.
  • 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.

@Frauschi

Frauschi commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

@wolfSSL-Fenrir-bot review balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #34

No scan targets match the changed files in this PR. Review skipped.

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Oct 9, 2026
@Frauschi
Frauschi requested a review from danielinux October 9, 2026 15:03
@Frauschi
Frauschi requested a review from padelsbach November 5, 2026 14:51
Comment thread src/psa_config.h Resolved
Comment thread src/psa_config.h Resolved
Comment thread zephyr/README.md
@@ -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`:

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.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread src/psa_config.h
/* 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) && \

@padelsbach padelsbach Nov 11, 2026 •

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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

5 participants