Repository navigation
Conversation
53ba1fc to
5a7a1ce
Compare
|
There was a problem hiding this comment.
🟡 Changes recommended
Critical GHASH defects produce incorrect authentication tags on supported 16-bit-byte targets, while the missing generated-header selector can create incompatible library and application layouts.
3 open issues
What changed in this PR
Adds a table-free integer-multiply GHASH implementation to wolfCrypt and makes it the default for cache-resistant software AES-GCM configurations.
Changes:
- Implements
GCM_INT_MULfor GHASH and reuses it for AES-GCM-SIV POLYVAL. - Replaces secret-dependent branches with masks in cache-resistant
GCM_SMALLandGCM_WORD32multiplication. - Adds build-system selection and benchmark labeling for intmul, while preserving assembly and FIPS defaults.
| File | Description |
|---|---|
wolfssl/wolfcrypt/aes.h |
Selects the default GHASH implementation and defines cache-resistance controls. |
wolfcrypt/src/aes.c |
Implements integer-multiply GHASH, POLYVAL reuse, and branch-free masking. |
wolfcrypt/benchmark/benchmark.c |
Labels intmul GMAC benchmark results. |
configure.ac |
Adds intmul selection and delegates non-FIPS defaults to aes.h. |
CMakeLists.txt |
Adds intmul selection and preserves explicit GHASH choices. |
Review effort: Balanced
bf1ac32 to
81203b1
Compare
|
@claude review |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved defects can produce incorrect GCM/GMAC tags, retain secret-dependent GHASH branches, and break PPC intmul builds.
5 open issues
Add intmul GHASH support for PPC one-shot callers · New Harden PPC and Arm bulk GHASH against secret-dependent branches · New Avoid stale AAD length when calculating consecutive GMAC tags · New Reset cached AAD length when starting a new stream · New Wipe GHASH subkey copies from stack temporaries · New
3 resolved since last review
Review effort: Balanced
81203b1 to
cd9ee4e
Compare
|
Jenkins: retest this please |
3066b57 to
5f09d71
Compare
|
GCM_INT_MUL is now the default on cores whose multiply can be variable time: MIPS32 4K/M4K, PowerPC 750/7400 (mullw early-out) and Cortex-M3 under armcc (which defines __TARGET_ARCH_7_M, not ARM_ARCH_7M); the masked GCM_SMALL may be the safer default there. |
|
The default GHASH now depends on |
5f09d71 to
429640f
Compare
|
Fixed the MIPS, PowerPC, Cortex-M3 to use small table by default. configure and CMake now both record the GHASH choice in options.h |
Frauschi
left a comment
There was a problem hiding this comment.
The new GHASH passes the GCM/GMAC/SIV KATs on 32/64-bit LE and BE targets under qemu; the asm default split in user_settings builds needs fixing before merge.
Table-free GHASH multiply using integer multiplies on operands masked to every fourth bit. Variants (GCM_IM_64, GCM_IM_32W, GCM_IM_32): 64x64 multiplies on 64-bit CPUs, 32x32->64 on 32-bit CPUs, and 32x32->32 only (GCM_INT_MUL_32_ONLY, default on M-profile Arm without DSP, e.g. Cortex-M0/M3). The key prepared from H is stored in Gcm.M0, sized for the variant. settings.h now picks the GHASH implementation when none is chosen, so the PPC, RISC-V and Arm assembly, which include only settings.h, agree with the C code: - GCM_TABLE_4BIT when cache resistance is off (WC_NO_CACHE_RESISTANT, e.g. --disable-harden, or the new AES_GCM_GMULT_NO_CACHE_RESIST) and for Arm/PPC/RISC-V asm builds. - GCM_SMALL where the CPU multiply may take data-dependent time (WC_GCM_MUL_VAR_TIME): Armv4/Armv5, MIPS, 32-bit PowerPC, RISC-V without Zkt, and 16-bit or multiplier-less CPUs (AVR, MSP430). - GCM_INT_MUL otherwise. Choosing it explicitly asserts the CPU multiply is constant time. configure and CMake compile settings.h and aes.h to get the GHASH and the GCM_INT_MUL variant and record both in options.h, also for an explicit GCM_INT_MUL, as the Gcm layout depends on them and the CPU macros depend on flags like -march. aes.h uses a recorded variant as is. Arm/PPC asm GCM_SMALL bulk GHASH helpers no longer branch on H. AES-GCM-SIV POLYVAL uses the GCM_INT_MUL multiply when it is compiled. configure/CMake: add --enable-aesgcm=intmul, rejected with armasm. --enable-aesgcm=word now selects the word64 GHASH (new GCM_WORD64); CMake gains "word" too. FIPS before v7 keeps GCM_TABLE_4BIT. CMake no longer forces 4bit over an explicit choice on little-endian, and WOLFSSL_HARDEN=no defines WC_NO_CACHE_RESISTANT, recorded in options.h, as configure does. CI: multi-arch armhf leg for GCM_INT_MUL with 32x32->32 multiplies. mcapi: CRYPT_AES_CTX grows to fit the larger Aes.
429640f to
0d6ae4a
Compare
| #error "GCM_IM_64 and GCM_IM_32W need a 64-bit type (WORD64_AVAILABLE)" | ||
| #endif | ||
| #if defined(GCM_INT_MUL_32_ONLY) && !defined(GCM_IM_32) | ||
| #error "GCM_INT_MUL_32_ONLY needs GCM_IM_32" |
There was a problem hiding this comment.
With -DGCM_INT_MUL_32_ONLY on a 64-bit build (configure or CMake), the probe records GCM_IM_64 because the WC_64BIT_CPU branch is tested first, so the build now stops at this #error; the previous head built. Check GCM_INT_MUL_32_ONLY before WC_64BIT_CPU in the default chain.


Description
Table-free GHASH multiply using integer multiplies on operands masked to
every fourth bit. Variants: 64x64 multiplies on 64-bit CPUs, 32x32->64
on 32-bit CPUs, and 32x32->32 only (GCM_INT_MUL_32_ONLY, default on
M-profile Arm without DSP, e.g. Cortex-M0/M3). The key prepared from H
is stored in Gcm.M0, sized for the variant.
aes.h now picks the GHASH implementation when none is chosen:
e.g. --disable-harden, or the new AES_GCM_GMULT_NO_CACHE_RESIST) and
for Arm/PPC/RISC-V asm builds.
(WC_GCM_MUL_VAR_TIME): Armv4/Armv5, MIPS, 32-bit PowerPC and RISC-V
without Zkt.
multiply is constant time.
configure and CMake compile aes.h to get its choice and record it in
options.h, as the Gcm layout depends on it and the CPU macros depend on
flags like -march.
Arm/PPC asm GCM_SMALL bulk GHASH helpers no longer branch on H.
AES-GCM-SIV POLYVAL uses the GCM_INT_MUL multiply when it is compiled.
configure/CMake: add --enable-aesgcm=intmul. FIPS before v7 keeps
GCM_TABLE_4BIT. CMake no longer forces 4bit over an explicit choice on
little-endian, and WOLFSSL_HARDEN=no defines WC_NO_CACHE_RESISTANT as
configure does.
mcapi: CRYPT_AES_CTX grows to fit the larger Aes.
Fixes zd#22771
Testing
./configure --enable-aes-gcm=4bit
./configure --enable-aes-gcm=word32
./configure --enable-aes-gcm=small
./configure --enable-aes-gcm=intmul