From ccdef57e8e3172805b33ebfa2f79654a407e97e3 Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Thu, 7 Aug 2025 07:49:53 +0900 Subject: [PATCH] add sha224 cryptcb --- wolfcrypt/src/cryptocb.c | 34 ++++++++++++++++++++++++++++++++++ wolfcrypt/src/sha256.c | 12 +++++++++++- wolfssl/wolfcrypt/cryptocb.h | 4 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/cryptocb.c b/wolfcrypt/src/cryptocb.c index 56d42b8be..b676c40de 100644 --- a/wolfcrypt/src/cryptocb.c +++ b/wolfcrypt/src/cryptocb.c @@ -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) diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 08434c90e..db7af7ae4 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -2133,7 +2133,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) diff --git a/wolfssl/wolfcrypt/cryptocb.h b/wolfssl/wolfcrypt/cryptocb.h index af5f912ff..e1cd2cb94 100644 --- a/wolfssl/wolfcrypt/cryptocb.h +++ b/wolfssl/wolfcrypt/cryptocb.h @@ -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);