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,8 +820,12 @@ 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 );
823+ #elif defined(WOLF_CRYPTO_CB )
824+ sha3 -> devId = devId ;
825+ sha3 -> type = type ;
820826#else
821827 (void )devId ;
828+ (void )type ;
822829#endif /* WOLFSSL_ASYNC_CRYPT */
823830
824831 return ret ;
@@ -845,6 +852,17 @@ static int wc_Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, byte p)
845852 return 0 ;
846853 }
847854
855+ #ifdef WOLF_CRYPTO_CB
856+ #ifndef WOLF_CRYPTO_CB_FIND
857+ if (sha3 -> devId != INVALID_DEVID )
858+ #endif
859+ {
860+ ret = wc_CryptoCb_Sha3Hash (sha3 , sha3 -> type , data , len , NULL );
861+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
862+ return ret ;
863+ /* fall-through when unavailable */
864+ }
865+ #endif
848866#if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_SHA3 )
849867 if (sha3 -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_SHA3 ) {
850868 #if defined(HAVE_INTEL_QA ) && defined(QAT_V2 )
@@ -880,6 +898,17 @@ static int wc_Sha3Final(wc_Sha3* sha3, byte* hash, byte p, byte len)
880898 return BAD_FUNC_ARG ;
881899 }
882900
901+ #ifdef WOLF_CRYPTO_CB
902+ #ifndef WOLF_CRYPTO_CB_FIND
903+ if (sha3 -> devId != INVALID_DEVID )
904+ #endif
905+ {
906+ ret = wc_CryptoCb_Sha3Hash (sha3 , sha3 -> type , NULL , 0 , hash );
907+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
908+ return ret ;
909+ /* fall-through when unavailable */
910+ }
911+ #endif
883912#if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_SHA3 )
884913 if (sha3 -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_SHA3 ) {
885914 #if defined(HAVE_INTEL_QA ) && defined(QAT_V2 )
@@ -981,7 +1010,7 @@ static int wc_Sha3GetHash(wc_Sha3* sha3, byte* hash, byte p, byte len)
9811010 */
9821011int wc_InitSha3_224 (wc_Sha3 * sha3 , void * heap , int devId )
9831012{
984- return wc_InitSha3 (sha3 , heap , devId );
1013+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_224 , heap , devId );
9851014}
9861015
9871016/* Update the SHA3-224 hash state with message data.
@@ -1053,7 +1082,7 @@ int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
10531082 */
10541083int wc_InitSha3_256 (wc_Sha3 * sha3 , void * heap , int devId )
10551084{
1056- return wc_InitSha3 (sha3 , heap , devId );
1085+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_256 , heap , devId );
10571086}
10581087
10591088/* Update the SHA3-256 hash state with message data.
@@ -1125,7 +1154,7 @@ int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
11251154 */
11261155int wc_InitSha3_384 (wc_Sha3 * sha3 , void * heap , int devId )
11271156{
1128- return wc_InitSha3 (sha3 , heap , devId );
1157+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_384 , heap , devId );
11291158}
11301159
11311160/* Update the SHA3-384 hash state with message data.
@@ -1197,7 +1226,7 @@ int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
11971226 */
11981227int wc_InitSha3_512 (wc_Sha3 * sha3 , void * heap , int devId )
11991228{
1200- return wc_InitSha3 (sha3 , heap , devId );
1229+ return wc_InitSha3 (sha3 , WC_HASH_TYPE_SHA3_512 , heap , devId );
12011230}
12021231
12031232/* Update the SHA3-512 hash state with message data.
@@ -1286,7 +1315,7 @@ int wc_Sha3_GetFlags(wc_Sha3* sha3, word32* flags)
12861315 */
12871316int wc_InitShake128 (wc_Shake * shake , void * heap , int devId )
12881317{
1289- return wc_InitSha3 (shake , heap , devId );
1318+ return wc_InitSha3 (shake , WC_HASH_TYPE_SHAKE128 , heap , devId );
12901319}
12911320
12921321/* Update the SHAKE128 hash state with message data.
@@ -1430,7 +1459,7 @@ int wc_Shake128_Copy(wc_Shake* src, wc_Shake* dst)
14301459 */
14311460int wc_InitShake256 (wc_Shake * shake , void * heap , int devId )
14321461{
1433- return wc_InitSha3 (shake , heap , devId );
1462+ return wc_InitSha3 (shake , WC_HASH_TYPE_SHAKE256 , heap , devId );
14341463}
14351464
14361465/* Update the SHAKE256 hash state with message data.
0 commit comments