From 50b51adc938348841dcf386c90aec09432869c1b Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 16 Dec 2025 16:59:11 -0600 Subject: [PATCH] wolfcrypt/src/hmac.c and wolfssl/wolfcrypt/hmac.h: implement WOLFSSL_API wc_HmacCopy(), and remove the WOLFSSL_HMAC_COPY_HASH gate on HmacKeyCopyHash(). --- wolfcrypt/src/hmac.c | 17 +++++++++++++++-- wolfssl/wolfcrypt/hmac.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/hmac.c b/wolfcrypt/src/hmac.c index e7e23387f..f50c235e1 100644 --- a/wolfcrypt/src/hmac.c +++ b/wolfcrypt/src/hmac.c @@ -248,7 +248,6 @@ int _InitHmac(Hmac* hmac, int type, void* heap) return ret; } -#ifdef WOLFSSL_HMAC_COPY_HASH static int HmacKeyCopyHash(byte macType, wc_HmacHash* src, wc_HmacHash* dst) { int ret = 0; @@ -323,7 +322,21 @@ static int HmacKeyCopyHash(byte macType, wc_HmacHash* src, wc_HmacHash* dst) return ret; } -#endif + +int wc_HmacCopy(Hmac* src, Hmac* dst) { + int ret; + + if ((src == NULL) || (dst == NULL)) + return BAD_FUNC_ARG; + + XMEMCPY(dst, src, sizeof(*dst)); + + ret = HmacKeyCopyHash(src->macType, &src->hash, &dst->hash); + + if (ret != 0) + XMEMSET(dst, 0, sizeof(*dst)); + return ret; +} static int HmacKeyHashUpdate(byte macType, wc_HmacHash* hash, byte* pad) { diff --git a/wolfssl/wolfcrypt/hmac.h b/wolfssl/wolfcrypt/hmac.h index 326ed4a52..92392dc41 100644 --- a/wolfssl/wolfcrypt/hmac.h +++ b/wolfssl/wolfcrypt/hmac.h @@ -190,6 +190,7 @@ WOLFSSL_API int wc_HmacInit_Id(Hmac* hmac, byte* id, int len, void* heap, WOLFSSL_API int wc_HmacInit_Label(Hmac* hmac, const char* label, void* heap, int devId); #endif +WOLFSSL_API int wc_HmacCopy(Hmac* src, Hmac* dst); WOLFSSL_API void wc_HmacFree(Hmac* hmac); WOLFSSL_API int wolfSSL_GetHmacMaxSize(void);