@@ -60,10 +60,6 @@ on the specific device platform.
6060
6161#if !defined(NO_SHA256 ) && !defined(WOLFSSL_RISCV_ASM )
6262
63- #if defined(WOLF_CRYPTO_CB_ONLY_SHA256 ) && defined(WOLFSSL_SHA224 )
64- #error "WOLF_CRYPTO_CB_ONLY_SHA256 is incompatible with WOLFSSL_SHA224"
65- #endif
66-
6763#if defined(HAVE_FIPS ) && defined(HAVE_FIPS_VERSION ) && (HAVE_FIPS_VERSION >= 2 )
6864 /* set NO_WRAPPERS before headers, use direct internal f()s not wrappers */
6965 #define FIPS_NO_WRAPPERS
@@ -101,6 +97,42 @@ on the specific device platform.
10197 #undef WOLFSSL_USE_ESP32_CRYPT_HASH_HW
10298#endif
10399
100+ /* WOLF_CRYPTO_CB_ONLY_SHA256 strips the software SHA-256 implementation and
101+ * routes every operation through the crypto callback. It is mutually exclusive
102+ * with any in-tree SHA-256 hardware/asm backend below: keep this list in sync
103+ * with the #elif chain at the start of the "Hardware Acceleration" section. */
104+ #if defined(WOLF_CRYPTO_CB_ONLY_SHA256 ) && ( \
105+ defined(WOLFSSL_TI_HASH ) || \
106+ defined(WOLFSSL_CRYPTOCELL ) || \
107+ defined(MAX3266X_SHA ) || \
108+ defined(FREESCALE_LTC_SHA ) || \
109+ defined(FREESCALE_MMCAU_SHA ) || \
110+ defined(WOLFSSL_PIC32MZ_HASH ) || \
111+ defined(STM32_HASH_SHA2 ) || \
112+ (defined(WOLFSSL_IMX6_CAAM ) && !defined(NO_IMX6_CAAM_HASH )) || \
113+ (defined(WOLFSSL_SE050 ) && defined(WOLFSSL_SE050_HASH )) || \
114+ defined(WOLFSSL_AFALG_HASH ) || \
115+ defined(WOLFSSL_DEVCRYPTO_HASH ) || \
116+ (defined(WOLFSSL_SCE ) && !defined(WOLFSSL_SCE_NO_HASH )) || \
117+ defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW ) || \
118+ defined(WOLFSSL_RENESAS_TSIP_TLS ) || \
119+ defined(WOLFSSL_RENESAS_SCEPROTECT ) || \
120+ defined(WOLFSSL_RENESAS_RSIP ) || \
121+ defined(PSOC6_HASH_SHA2 ) || \
122+ defined(WOLFSSL_IMXRT_DCP ) || \
123+ defined(WOLFSSL_NXP_HASHCRYPT_SHA ) || \
124+ defined(WOLFSSL_SILABS_SE_ACCEL ) || \
125+ defined(WOLFSSL_KCAPI_HASH ) || \
126+ (defined(WOLFSSL_HAVE_PSA ) && !defined(WOLFSSL_PSA_NO_HASH )) || \
127+ defined(WOLFSSL_RENESAS_RX64_HASH ) || \
128+ defined(WOLFSSL_PPC32_ASM ) || \
129+ defined(WOLFSSL_ARMASM ) || \
130+ (defined(WOLFSSL_X86_64_BUILD ) && defined(USE_INTEL_SPEEDUP ) && \
131+ (defined(HAVE_INTEL_AVX1 ) || defined(HAVE_INTEL_AVX2 ))))
132+ #error "WOLF_CRYPTO_CB_ONLY_SHA256 is incompatible with SHA-256 hardware" \
133+ " acceleration backends"
134+ #endif
135+
104136#ifdef WOLFSSL_ESPIDF
105137 /* Define the ESP_LOGx(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE value for output messages here.
106138 **
@@ -2148,6 +2180,35 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
21482180#elif defined(PSOC6_HASH_SHA2 )
21492181 /* Implemented in wolfcrypt/src/port/cypress/psoc6_crypto.c */
21502182
2183+ #elif defined(WOLF_CRYPTO_CB_ONLY_SHA256 )
2184+ int wc_InitSha224_ex (wc_Sha224 * sha224 , void * heap , int devId )
2185+ {
2186+ int ret ;
2187+ if (sha224 == NULL )
2188+ return BAD_FUNC_ARG ;
2189+ ret = InitSha256 ((wc_Sha256 * )sha224 );
2190+ if (ret != 0 )
2191+ return ret ;
2192+ sha224 -> digest [0 ] = 0xc1059ed8 ;
2193+ sha224 -> digest [1 ] = 0x367cd507 ;
2194+ sha224 -> digest [2 ] = 0x3070dd17 ;
2195+ sha224 -> digest [3 ] = 0xf70e5939 ;
2196+ sha224 -> digest [4 ] = 0xffc00b31 ;
2197+ sha224 -> digest [5 ] = 0x68581511 ;
2198+ sha224 -> digest [6 ] = 0x64f98fa7 ;
2199+ sha224 -> digest [7 ] = 0xbefa4fa4 ;
2200+ sha224 -> heap = heap ;
2201+ sha224 -> devId = devId ;
2202+ sha224 -> devCtx = NULL ;
2203+ #ifdef WOLFSSL_SMALL_STACK_CACHE
2204+ sha224 -> W = NULL ;
2205+ #endif
2206+ #ifdef WOLFSSL_ASYNC_CRYPT
2207+ XMEMSET (& sha224 -> asyncDev , 0 , sizeof (sha224 -> asyncDev ));
2208+ #endif
2209+ return ret ;
2210+ }
2211+
21512212#else
21522213
21532214 #define NEED_SOFT_SHA224
@@ -2369,6 +2430,50 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
23692430 }
23702431#endif /* end of SHA224 software implementation */
23712432
2433+ #ifdef WOLF_CRYPTO_CB_ONLY_SHA256
2434+
2435+ int wc_Sha224Update (wc_Sha224 * sha224 , const byte * data , word32 len )
2436+ {
2437+ if (sha224 == NULL )
2438+ return BAD_FUNC_ARG ;
2439+ if (data == NULL && len == 0 )
2440+ return 0 ;
2441+ if (data == NULL )
2442+ return BAD_FUNC_ARG ;
2443+
2444+ #ifndef WOLF_CRYPTO_CB_FIND
2445+ if (sha224 -> devId != INVALID_DEVID )
2446+ #endif
2447+ {
2448+ int ret = wc_CryptoCb_Sha224Hash (sha224 , data , len , NULL );
2449+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
2450+ return ret ;
2451+ }
2452+
2453+ return NO_VALID_DEVID ;
2454+ }
2455+
2456+ int wc_Sha224Final (wc_Sha224 * sha224 , byte * hash )
2457+ {
2458+ int ret ;
2459+
2460+ if (sha224 == NULL || hash == NULL )
2461+ return BAD_FUNC_ARG ;
2462+
2463+ #ifndef WOLF_CRYPTO_CB_FIND
2464+ if (sha224 -> devId != INVALID_DEVID )
2465+ #endif
2466+ {
2467+ ret = wc_CryptoCb_Sha224Hash (sha224 , NULL , 0 , hash );
2468+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
2469+ return ret ;
2470+ }
2471+
2472+ return NO_VALID_DEVID ;
2473+ }
2474+
2475+ #endif /* WOLF_CRYPTO_CB_ONLY_SHA256 */
2476+
23722477 int wc_InitSha224 (wc_Sha224 * sha224 )
23732478 {
23742479 int devId = INVALID_DEVID ;
0 commit comments