@@ -60,6 +60,10 @@ 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+
6367#if defined(HAVE_FIPS ) && defined(HAVE_FIPS_VERSION ) && (HAVE_FIPS_VERSION >= 2 )
6468 /* set NO_WRAPPERS before headers, use direct internal f()s not wrappers */
6569 #define FIPS_NO_WRAPPERS
@@ -290,7 +294,8 @@ static int InitSha256(wc_Sha256* sha256)
290294
291295/* Hardware Acceleration */
292296#if defined(WOLFSSL_X86_64_BUILD ) && defined(USE_INTEL_SPEEDUP ) && \
293- (defined(HAVE_INTEL_AVX1 ) || defined(HAVE_INTEL_AVX2 ))
297+ (defined(HAVE_INTEL_AVX1 ) || defined(HAVE_INTEL_AVX2 )) && \
298+ !defined(WOLF_CRYPTO_CB_ONLY_SHA256 )
294299
295300 /* in case intel instructions aren't available, plus we need the K[] global */
296301 #define NEED_SOFT_SHA256
@@ -1080,7 +1085,7 @@ static int InitSha256(wc_Sha256* sha256)
10801085#elif defined(WOLFSSL_RENESAS_RX64_HASH)
10811086
10821087 /* implemented in wolfcrypt/src/port/Renesas/renesas_rx64_hw_sha.c */
1083- #elif defined(WOLFSSL_PPC32_ASM)
1088+ #elif defined(WOLFSSL_PPC32_ASM) && !defined(WOLF_CRYPTO_CB_ONLY_SHA256)
10841089
10851090extern void Transform_Sha256_Len (wc_Sha256 * sha256 , const byte * data ,
10861091 word32 len );
@@ -1110,7 +1115,7 @@ static int Transform_Sha256(wc_Sha256* sha256, const byte* data)
11101115#define XTRANSFORM Transform_Sha256
11111116#define XTRANSFORM_LEN Transform_Sha256_Len
11121117
1113- #elif defined(WOLFSSL_ARMASM)
1118+ #elif defined(WOLFSSL_ARMASM) && !defined(WOLF_CRYPTO_CB_ONLY_SHA256)
11141119
11151120int wc_InitSha256_ex (wc_Sha256 * sha256 , void * heap , int devId )
11161121{
@@ -1165,6 +1170,21 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
11651170#define XTRANSFORM Transform_Sha256
11661171#define XTRANSFORM_LEN Transform_Sha256_Len
11671172
1173+ #elif defined(WOLF_CRYPTO_CB_ONLY_SHA256)
1174+ /* Software SHA-256 stripped; every op dispatches via cryptocb. */
1175+ int wc_InitSha256_ex (wc_Sha256 * sha256 , void * heap , int devId )
1176+ {
1177+ int ret ;
1178+ if (sha256 == NULL )
1179+ return BAD_FUNC_ARG ;
1180+ ret = InitSha256 (sha256 );
1181+ if (ret != 0 )
1182+ return ret ;
1183+ sha256 -> heap = heap ;
1184+ sha256 -> devId = devId ;
1185+ sha256 -> devCtx = NULL ;
1186+ return ret ;
1187+ }
11681188#else
11691189 #define NEED_SOFT_SHA256
11701190
@@ -1397,7 +1417,6 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
13971417#endif
13981418/* End wc_ software implementation */
13991419
1400-
14011420#ifdef XTRANSFORM
14021421
14031422 static WC_INLINE void AddLength (wc_Sha256 * sha256 , word32 len )
@@ -1774,6 +1793,7 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
17741793
17751794#if !defined(WOLFSSL_KCAPI_HASH )
17761795
1796+ #ifndef WOLFSSL_NO_HASH_RAW
17771797 int wc_Sha256FinalRaw (wc_Sha256 * sha256 , byte * hash )
17781798 {
17791799 #ifdef LITTLE_ENDIAN_ORDER
@@ -1797,6 +1817,7 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
17971817
17981818 return 0 ;
17991819 }
1820+ #endif /* !WOLFSSL_NO_HASH_RAW */
18001821
18011822 int wc_Sha256Final (wc_Sha256 * sha256 , byte * hash )
18021823 {
@@ -1960,6 +1981,55 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
19601981
19611982#endif /* XTRANSFORM */
19621983
1984+ #ifdef WOLF_CRYPTO_CB_ONLY_SHA256
1985+
1986+ int wc_Sha256Update (wc_Sha256 * sha256 , const byte * data , word32 len )
1987+ {
1988+ if (sha256 == NULL ) {
1989+ return BAD_FUNC_ARG ;
1990+ }
1991+ if (data == NULL && len == 0 ) {
1992+ /* valid, but do nothing */
1993+ return 0 ;
1994+ }
1995+ if (data == NULL ) {
1996+ return BAD_FUNC_ARG ;
1997+ }
1998+
1999+ #ifndef WOLF_CRYPTO_CB_FIND
2000+ if (sha256 -> devId != INVALID_DEVID )
2001+ #endif
2002+ {
2003+ int ret = wc_CryptoCb_Sha256Hash (sha256 , data , len , NULL );
2004+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
2005+ return ret ;
2006+ }
2007+
2008+ return NO_VALID_DEVID ;
2009+ }
2010+
2011+ int wc_Sha256Final (wc_Sha256 * sha256 , byte * hash )
2012+ {
2013+ int ret ;
2014+
2015+ if (sha256 == NULL || hash == NULL ) {
2016+ return BAD_FUNC_ARG ;
2017+ }
2018+
2019+ #ifndef WOLF_CRYPTO_CB_FIND
2020+ if (sha256 -> devId != INVALID_DEVID )
2021+ #endif
2022+ {
2023+ ret = wc_CryptoCb_Sha256Hash (sha256 , NULL , 0 , hash );
2024+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
2025+ return ret ;
2026+ }
2027+
2028+ return NO_VALID_DEVID ;
2029+ }
2030+
2031+ #endif /* WOLF_CRYPTO_CB_ONLY_SHA256 */
2032+
19632033
19642034#ifdef WOLFSSL_SHA224
19652035
0 commit comments