7676 #include <wolfcrypt/src/misc.c>
7777#endif
7878
79+ /* Gates the non-WOLFSSL_SHA3_SMALL software Keccak primitives
80+ * (hash_keccak_r, BlockSha3, InitSha3, Sha3Update, Sha3Final and the
81+ * Load64* helpers). Compiled when:
82+ * - No HW SHA-3 backend is selected (the original baseline), OR
83+ * - STM32 HW SHA-3 is selected and SHAKE is enabled - SHAKE on STM32MP13
84+ * runs in software because the HASH peripheral's SHAKE support is
85+ * fixed-length and does not match wolfSSL's variable-length / iterative
86+ * SqueezeBlocks API. SHA-3 still uses the HASH peripheral.
87+ *
88+ * Note: the WOLFSSL_SHA3_SMALL branch earlier in this file defines its
89+ * own hash_keccak_r and BlockSha3 unconditionally inside its #ifdef
90+ * block, so this macro only controls the non-SMALL implementation. */
91+ #if (!defined(STM32_HASH_SHA3 ) && !defined(PSOC6_HASH_SHA3 )) || \
92+ (defined(STM32_HASH_SHA3 ) && \
93+ (defined(WOLFSSL_SHAKE128 ) || defined(WOLFSSL_SHAKE256 )))
94+ #define WC_SHA3_SW_KECCAK
95+ #endif
96+
7997#if FIPS_VERSION3_GE (6 ,0 ,0 )
8098 const unsigned int wolfCrypt_FIPS_sha3_ro_sanity [2 ] =
8199 { 0x1a2b3c4d , 0x00000016 };
@@ -320,7 +338,7 @@ void BlockSha3(word64* s)
320338 */
321339#define ROTL64 (a , n ) (((a)<<(n))|((a)>>(64-(n))))
322340
323- #if !defined( STM32_HASH_SHA3 ) && !defined( PSOC6_HASH_SHA3 )
341+ #ifdef WC_SHA3_SW_KECCAK
324342/* An array of values to XOR for block operation. */
325343static const word64 hash_keccak_r [24 ] =
326344{
@@ -555,7 +573,7 @@ do { \
555573while (0)
556574#endif /* SHA3_BY_SPEC */
557575
558- #if !defined( STM32_HASH_SHA3 ) && !defined( PSOC6_HASH_SHA3 )
576+ #ifdef WC_SHA3_SW_KECCAK
559577/* The block operation performed on the state.
560578 *
561579 * s The state.
@@ -581,11 +599,11 @@ void BlockSha3(word64* s)
581599 s [0 ] ^= hash_keccak_r [i + 1 ];
582600 }
583601}
584- #endif /* WOLFSSL_SHA3_SMALL */
585- #endif /* STM32_HASH_SHA3 */
602+ #endif /* WC_SHA3_SW_KECCAK */
603+ #endif /* !WOLFSSL_SHA3_SMALL */
586604#endif /* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */
587605
588- #if !defined( STM32_HASH_SHA3 ) && !defined( PSOC6_HASH_SHA3 )
606+ #ifdef WC_SHA3_SW_KECCAK
589607#if defined(BIG_ENDIAN_ORDER )
590608static WC_INLINE word64 Load64Unaligned (const unsigned char * a )
591609{
@@ -929,7 +947,7 @@ static int Sha3Final(wc_Sha3* sha3, byte padChar, byte* hash, byte p, word32 l)
929947
930948 return 0 ;
931949}
932- #endif
950+ #endif /* WC_SHA3_SW_KECCAK */
933951#if defined(STM32_HASH_SHA3 )
934952
935953/* Supports CubeMX HAL or Standard Peripheral Library */
0 commit comments