Merge pull request #9070 from miyazakh/cb_sha224

Support sha224 cryptocb
This commit is contained in:
David Garske
2025-08-07 07:07:05 -07:00
committed by GitHub
4 changed files with 68 additions and 3 deletions

View File

@@ -1596,6 +1596,40 @@ int wc_CryptoCb_ShaHash(wc_Sha* sha, const byte* in,
}
#endif /* !NO_SHA */
#ifdef WOLFSSL_SHA224
int wc_CryptoCb_Sha224Hash(wc_Sha224* sha224, const byte* in,
word32 inSz, byte* digest)
{
int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
CryptoCb* dev;
/* locate registered callback */
if (sha224) {
dev = wc_CryptoCb_FindDevice(sha224->devId, WC_ALGO_TYPE_HASH);
}
else {
/* locate first callback and try using it */
dev = wc_CryptoCb_FindDeviceByIndex(0);
}
if (dev && dev->cb) {
wc_CryptoInfo cryptoInfo;
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
cryptoInfo.algo_type = WC_ALGO_TYPE_HASH;
cryptoInfo.hash.type = WC_HASH_TYPE_SHA224;
cryptoInfo.hash.sha224 = sha224;
cryptoInfo.hash.in = in;
cryptoInfo.hash.inSz = inSz;
cryptoInfo.hash.digest = digest;
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
}
return wc_CryptoCb_TranslateErrorCode(ret);
}
#endif /* WOLFSSL_SHA224 */
#ifndef NO_SHA256
int wc_CryptoCb_Sha256Hash(wc_Sha256* sha256, const byte* in,
word32 inSz, byte* digest)

View File

@@ -2074,7 +2074,10 @@ static int Transform_Sha256(wc_Sha256* sha256, const byte* data)
#ifdef WOLFSSL_SMALL_STACK_CACHE
sha224->W = NULL;
#endif
#ifdef WOLF_CRYPTO_CB
sha224->devId = devId;
sha224->devCtx = NULL;
#endif
#if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW)
#if defined(NO_WOLFSSL_ESP32_CRYPT_HASH_SHA224)
/* We know this is a fresh, uninitialized item, so set to INIT */
@@ -2133,7 +2136,17 @@ static int Transform_Sha256(wc_Sha256* sha256, const byte* data)
if (data == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLF_CRYPTO_CB
#ifndef WOLF_CRYPTO_CB_FIND
if (sha224->devId != INVALID_DEVID)
#endif
{
ret = wc_CryptoCb_Sha224Hash(sha224, data, len, NULL);
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
return ret;
/* fall-through when unavailable */
}
#endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
if (sha224->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA224) {
#if defined(HAVE_INTEL_QA)
@@ -2160,7 +2173,17 @@ static int Transform_Sha256(wc_Sha256* sha256, const byte* data)
if (sha224 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLF_CRYPTO_CB
#ifndef WOLF_CRYPTO_CB_FIND
if (sha224->devId != INVALID_DEVID)
#endif
{
ret = wc_CryptoCb_Sha224Hash(sha224, NULL, 0, hash);
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
return ret;
/* fall-through when unavailable */
}
#endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
if (sha224->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA224) {
#if defined(HAVE_INTEL_QA)

View File

@@ -60741,6 +60741,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
if (ret == 0)
ret = sha_test();
#endif
#ifdef WOLFSSL_SHA224
if (ret == 0)
ret = sha224_test();
#endif
#ifndef NO_SHA256
if (ret == 0)
ret = sha256_test();

View File

@@ -639,6 +639,10 @@ WOLFSSL_LOCAL int wc_CryptoCb_ShaHash(wc_Sha* sha, const byte* in,
word32 inSz, byte* digest);
#endif /* !NO_SHA */
#ifdef WOLFSSL_SHA224
WOLFSSL_LOCAL int wc_CryptoCb_Sha224Hash(wc_Sha224* sha224, const byte* in,
word32 inSz, byte* digest);
#endif /* WOLFSSL_SHA224 */
#ifndef NO_SHA256
WOLFSSL_LOCAL int wc_CryptoCb_Sha256Hash(wc_Sha256* sha256, const byte* in,
word32 inSz, byte* digest);