Skip to content

Commit d6a45dd

Browse files
committed
Make SHA3_SMALL a Zephyr Kconfig option, off by default
The module's user_settings.h defined WOLFSSL_SHA3_SMALL for every build with ML-KEM, ML-DSA, XMSS or Falcon enabled, FIPS v6 builds included. The small Keccak permutation runs about 1.5x slower: on STM32H743 (Cortex-M7) and RW612 (Cortex-M33) with the C permutation at -O2, it made BlockSha3 45-50% slower, ML-KEM-768 25-35% slower and ML-DSA-65 key generation and verification 36-43% slower. It saves about 3 KB of flash (2.8 KB at -Os) and 170 bytes of stack. Add CONFIG_WOLFSSL_SHA3_SMALL, default n, so PQC builds get the fast permutation and size-constrained targets can still opt in. The option is only offered where the C permutation is built: the Arm assembly BlockSha3 ignores WOLFSSL_SHA3_SMALL, FIPS v7 and FIPS Ready take their SHA-3 settings from user_settings-fips-v7.h, and FIPS v2 and v5 never defined it. Builds that supply their own settings file are unaffected. PQC builds without the Arm assembly grow by about 3 KB of flash and 170 bytes of stack unless they enable the option. Under FIPS v6 the compiled sha3.c changes, so the module has to be rehashed as after any other configuration change.
1 parent 8ae4ab5 commit d6a45dd

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎zephyr/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ config WOLFSSL_FALCON
323323
Enable PQC Falcon (FN-DSA) signatures. Needs SHAKE, which the FIPS v2
324324
and v5 boundaries do not build.
325325

326+
config WOLFSSL_SHA3_SMALL
327+
bool "Smaller, slower SHA-3/SHAKE"
328+
depends on !WOLFSSL_HAS_SETTINGS_FILE
329+
depends on !WOLFCRYPT_ARM_SYMMETRIC_ASM
330+
depends on !WOLFCRYPT_FIPS_V2 && !WOLFCRYPT_FIPS_V5
331+
depends on !WOLFCRYPT_FIPS_V7 && !WOLFCRYPT_FIPS_READY
332+
help
333+
Define WOLFSSL_SHA3_SMALL, a smaller and about 1.5x slower C Keccak
334+
permutation.
335+
326336
config WOLFSSL_RSA
327337
bool "wolfCrypt RSA support"
328338
depends on !WOLFSSL_HAS_SETTINGS_FILE

‎zephyr/user_settings.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,15 +646,17 @@ extern "C" {
646646
#define WOLFSSL_FALCON_SIGN_SMALL_MEM
647647
#endif
648648

649+
#if defined(CONFIG_WOLFSSL_SHA3_SMALL)
650+
#define WOLFSSL_SHA3_SMALL
651+
#endif
649652
/* SHA-3 / SHAKE are required by ML-KEM, ML-DSA, and Falcon, and XMSS derives
650653
* its SHAKE parameter sets from WOLFSSL_SHAKE128/256 (see wc_xmss.h); enable
651-
* them (small variant) when any is on, and explicitly disable SHAKE otherwise
654+
* them when any is on, and explicitly disable SHAKE otherwise
652655
* to keep a non-PQC build lean. LMS is deliberately absent: its SHAKE-256
653656
* support is opt-in via WOLFSSL_LMS_SHAKE256 and is never derived from
654657
* WOLFSSL_SHAKE256. */
655658
#if defined(CONFIG_WOLFSSL_MLKEM) || defined(CONFIG_WOLFSSL_MLDSA) || \
656659
defined(CONFIG_WOLFSSL_XMSS) || defined(CONFIG_WOLFSSL_FALCON)
657-
#define WOLFSSL_SHA3_SMALL
658660
#define WOLFSSL_SHAKE128
659661
#define WOLFSSL_SHAKE256
660662
#elif defined(CONFIG_WOLFSSL_ED448)

0 commit comments

Comments
 (0)