4343#include <wolfssl/wolfcrypt/error-crypt.h>
4444#include <wolfssl/wolfcrypt/hash.h>
4545
46+ #ifdef WOLF_CRYPTO_CB
47+ #include <wolfssl/wolfcrypt/cryptocb.h>
48+ #endif
4649#ifdef NO_INLINE
4750 #include <wolfssl/wolfcrypt/misc.h>
4851#else
@@ -802,7 +805,7 @@ static int Sha3Final(wc_Sha3* sha3, byte padChar, byte* hash, byte p, word32 l)
802805 * devId Device identifier for asynchronous operation.
803806 * returns 0 on success.
804807 */
805- static int wc_InitSha3 (wc_Sha3 * sha3 , void * heap , int devId )
808+ static int wc_InitSha3 (wc_Sha3 * sha3 , int type , void * heap , int devId )
806809{
807810 int ret = 0 ;
808811
@@ -817,10 +820,15 @@ static int wc_InitSha3(wc_Sha3* sha3, void* heap, int devId)
817820#if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_SHA3 )
818821 ret = wolfAsync_DevCtxInit (& sha3 -> asyncDev ,
819822 WOLFSSL_ASYNC_MARKER_SHA3 , sha3 -> heap , devId );
820- #else
821- (void )devId ;
823+ #elif defined(WOLF_CRYPTO_CB )
824+ sha3 -> devId = devId ;
825+ sha3 -> type = type ;
826+
822827#endif /* WOLFSSL_ASYNC_CRYPT */
823828
829+ (void )devId ;
830+ (void )type ;
831+
824832 return ret ;
825833}
826834
@@ -845,6 +853,17 @@ static int wc_Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, byte p)
845853 return 0 ;
846854 }
847855
856+ #ifdef WOLF_CRYPTO_CB
857+ #ifndef WOLF_CRYPTO_CB_FIND
858+ if (sha3 -> devId != INVALID_DEVID )
859+ #endif
860+ {
861+ ret = wc_CryptoCb_Sha3Hash (sha3 , sha3 -> type , data , len , NULL );
862+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
863+ return ret ;
864+ /* fall-through when unavailable */
865+ }
866+ #endif
848867#if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_SHA3 )
849868 if (sha3 -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_SHA3 ) {
850869 #if defined(HAVE_INTEL_QA ) && defined(QAT_V2 )
@@ -880,6 +899,17 @@ static int wc_Sha3Final(wc_Sha3* sha3, byte* hash, byte p, byte len)
880899 return BAD_FUNC_ARG ;
881900 }
882901
902+ #ifdef WOLF_CRYPTO_CB
903+ #ifndef WOLF_CRYPTO_CB_FIND
904+ if (sha3 -> devId != INVALID_DEVID )
905+ #endif
906+ {
907+ ret = wc_CryptoCb_Sha3Hash (sha3 , sha3 -> type , NULL , 0 , hash );
908+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
909+ return ret ;
910+ /* fall-through when unavailable */
911+ }
912+ #endif
883913#if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_SHA3 )
884914 if (sha3 -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_SHA3 ) {
885915 #if defined(HAVE_INTEL_QA ) && defined(QAT_V2 )
@@ -981,7 +1011,7 @@ static int wc_Sha3GetHash(wc_Sha3* sha3, byte* hash, byte p, byte len)
9811011 */
9821012int wc_InitSha3_224 (wc_Sha3 * sha3 , void * heap , int devId )
9831013{
984- return wc_InitSha3 (sha3 , heap , devId );
1014+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_224 , heap , devId );
9851015}
9861016
9871017/* Update the SHA3-224 hash state with message data.
@@ -1053,7 +1083,7 @@ int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
10531083 */
10541084int wc_InitSha3_256 (wc_Sha3 * sha3 , void * heap , int devId )
10551085{
1056- return wc_InitSha3 (sha3 , heap , devId );
1086+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_256 , heap , devId );
10571087}
10581088
10591089/* Update the SHA3-256 hash state with message data.
@@ -1125,7 +1155,7 @@ int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
11251155 */
11261156int wc_InitSha3_384 (wc_Sha3 * sha3 , void * heap , int devId )
11271157{
1128- return wc_InitSha3 (sha3 , heap , devId );
1158+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_384 , heap , devId );
11291159}
11301160
11311161/* Update the SHA3-384 hash state with message data.
@@ -1197,7 +1227,7 @@ int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
11971227 */
11981228int wc_InitSha3_512 (wc_Sha3 * sha3 , void * heap , int devId )
11991229{
1200- return wc_InitSha3 (sha3 , heap , devId );
1230+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_512 , heap , devId );
12011231}
12021232
12031233/* Update the SHA3-512 hash state with message data.
@@ -1286,7 +1316,7 @@ int wc_Sha3_GetFlags(wc_Sha3* sha3, word32* flags)
12861316 */
12871317int wc_InitShake128 (wc_Shake * shake , void * heap , int devId )
12881318{
1289- return wc_InitSha3 (shake , heap , devId );
1319+ return wc_InitSha3 (shake , WC_HASH_TYPE_SHAKE128 , heap , devId );
12901320}
12911321
12921322/* Update the SHAKE128 hash state with message data.
@@ -1430,7 +1460,7 @@ int wc_Shake128_Copy(wc_Shake* src, wc_Shake* dst)
14301460 */
14311461int wc_InitShake256 (wc_Shake * shake , void * heap , int devId )
14321462{
1433- return wc_InitSha3 (shake , heap , devId );
1463+ return wc_InitSha3 (shake , WC_HASH_TYPE_SHAKE256 , heap , devId );
14341464}
14351465
14361466/* Update the SHAKE256 hash state with message data.
0 commit comments