@@ -1720,7 +1720,7 @@ int wc_CryptoCb_Sha384Hash(wc_Sha384* sha384, const byte* in,
17201720
17211721#ifdef WOLFSSL_SHA512
17221722int wc_CryptoCb_Sha512Hash (wc_Sha512 * sha512 , const byte * in ,
1723- word32 inSz , byte * digest )
1723+ word32 inSz , byte * digest , size_t digestSz )
17241724{
17251725 int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
17261726 CryptoCb * dev ;
@@ -1738,16 +1738,43 @@ int wc_CryptoCb_Sha512Hash(wc_Sha512* sha512, const byte* in,
17381738 }
17391739
17401740 if (dev && dev -> cb ) {
1741+ byte localHash [WC_SHA512_DIGEST_SIZE ];
17411742 wc_CryptoInfo cryptoInfo ;
17421743 XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
17431744 cryptoInfo .algo_type = WC_ALGO_TYPE_HASH ;
1744- cryptoInfo .hash .type = WC_HASH_TYPE_SHA512 ;
17451745 cryptoInfo .hash .sha512 = sha512 ;
17461746 cryptoInfo .hash .in = in ;
17471747 cryptoInfo .hash .inSz = inSz ;
17481748 cryptoInfo .hash .digest = digest ;
17491749
1750+ /* try the specific family callbacks first */
1751+ #if !defined(WOLFSSL_NOSHA512_224 )
1752+ if (digest != NULL && digestSz == WC_SHA512_224_DIGEST_SIZE ) {
1753+ cryptoInfo .hash .type = WC_HASH_TYPE_SHA512_224 ;
1754+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1755+ ret = wc_CryptoCb_TranslateErrorCode (ret );
1756+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
1757+ return ret ;
1758+ }
1759+ #endif
1760+ #if !defined(WOLFSSL_NOSHA512_256 )
1761+ if (digest != NULL && digestSz == WC_SHA512_256_DIGEST_SIZE ) {
1762+ cryptoInfo .hash .type = WC_HASH_TYPE_SHA512_256 ;
1763+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1764+ ret = wc_CryptoCb_TranslateErrorCode (ret );
1765+ if (ret != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
1766+ return ret ;
1767+ }
1768+ #endif
1769+ cryptoInfo .hash .type = WC_HASH_TYPE_SHA512 ;
1770+ /* use local buffer if not full size */
1771+ if (digest != NULL && digestSz != WC_SHA512_DIGEST_SIZE )
1772+ cryptoInfo .hash .digest = localHash ;
17501773 ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1774+ ret = wc_CryptoCb_TranslateErrorCode (ret );
1775+ if (ret == 0 && digest != NULL && digestSz != WC_SHA512_DIGEST_SIZE )
1776+ XMEMCPY (digest , localHash , digestSz );
1777+ return ret ;
17511778 }
17521779
17531780 return wc_CryptoCb_TranslateErrorCode (ret );
0 commit comments