Skip to content

Commit 03eaddf

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 3fd873c commit 03eaddf

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎.wolfssl_known_macro_extras‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ CONFIG_WOLFSSL_SESSION_CACHE
266266
CONFIG_WOLFSSL_SESSION_EXPORT
267267
CONFIG_WOLFSSL_SESSION_TICKET
268268
CONFIG_WOLFSSL_SETTINGS_FILE
269+
CONFIG_WOLFSSL_SHA3_SMALL
269270
CONFIG_WOLFSSL_SINGLE_THREADED
270271
CONFIG_WOLFSSL_SMALL_STACK
271272
CONFIG_WOLFSSL_SNI

‎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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,12 @@ extern "C" {
648648

649649
/* SHA-3 / SHAKE are required by ML-KEM, ML-DSA, and Falcon, and XMSS derives
650650
* 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
652-
* to keep a non-PQC build lean. LMS is deliberately absent: its SHAKE-256
653-
* support is opt-in via WOLFSSL_LMS_SHAKE256 and is never derived from
651+
* them when any is on, and explicitly disable SHAKE otherwise to keep a
652+
* non-PQC build lean. LMS is deliberately absent: its SHAKE-256 support is
653+
* opt-in via WOLFSSL_LMS_SHAKE256 and is never derived from
654654
* WOLFSSL_SHAKE256. */
655655
#if defined(CONFIG_WOLFSSL_MLKEM) || defined(CONFIG_WOLFSSL_MLDSA) || \
656656
defined(CONFIG_WOLFSSL_XMSS) || defined(CONFIG_WOLFSSL_FALCON)
657-
#define WOLFSSL_SHA3_SMALL
658657
#define WOLFSSL_SHAKE128
659658
#define WOLFSSL_SHAKE256
660659
#elif defined(CONFIG_WOLFSSL_ED448)
@@ -664,6 +663,10 @@ extern "C" {
664663
#define WOLFSSL_NO_SHAKE128
665664
#define WOLFSSL_NO_SHAKE256
666665
#endif
666+
667+
#if defined(CONFIG_WOLFSSL_SHA3_SMALL)
668+
#define WOLFSSL_SHA3_SMALL
669+
#endif
667670
#endif /* !WOLFSSL_ZEPHYR_FIPS_V7_H */
668671

669672

0 commit comments

Comments
 (0)