Skip to content

Commit 50b51ad

Browse files
committed
wolfcrypt/src/hmac.c and wolfssl/wolfcrypt/hmac.h: implement WOLFSSL_API wc_HmacCopy(), and remove the WOLFSSL_HMAC_COPY_HASH gate on HmacKeyCopyHash().
1 parent 8090817 commit 50b51ad

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

wolfcrypt/src/hmac.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ int _InitHmac(Hmac* hmac, int type, void* heap)
248248
return ret;
249249
}
250250

251-
#ifdef WOLFSSL_HMAC_COPY_HASH
252251
static int HmacKeyCopyHash(byte macType, wc_HmacHash* src, wc_HmacHash* dst)
253252
{
254253
int ret = 0;
@@ -323,7 +322,21 @@ static int HmacKeyCopyHash(byte macType, wc_HmacHash* src, wc_HmacHash* dst)
323322

324323
return ret;
325324
}
326-
#endif
325+
326+
int wc_HmacCopy(Hmac* src, Hmac* dst) {
327+
int ret;
328+
329+
if ((src == NULL) || (dst == NULL))
330+
return BAD_FUNC_ARG;
331+
332+
XMEMCPY(dst, src, sizeof(*dst));
333+
334+
ret = HmacKeyCopyHash(src->macType, &src->hash, &dst->hash);
335+
336+
if (ret != 0)
337+
XMEMSET(dst, 0, sizeof(*dst));
338+
return ret;
339+
}
327340

328341
static int HmacKeyHashUpdate(byte macType, wc_HmacHash* hash, byte* pad)
329342
{

wolfssl/wolfcrypt/hmac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ WOLFSSL_API int wc_HmacInit_Id(Hmac* hmac, byte* id, int len, void* heap,
190190
WOLFSSL_API int wc_HmacInit_Label(Hmac* hmac, const char* label, void* heap,
191191
int devId);
192192
#endif
193+
WOLFSSL_API int wc_HmacCopy(Hmac* src, Hmac* dst);
193194
WOLFSSL_API void wc_HmacFree(Hmac* hmac);
194195

195196
WOLFSSL_API int wolfSSL_GetHmacMaxSize(void);

0 commit comments

Comments
 (0)