Skip to content

Commit 2ba2e38

Browse files
committed
address copilot comments
1 parent 4114712 commit 2ba2e38

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

doc/dox_comments/header_files/hmac.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ int wc_HKDF_Extract(
254254
\param saltSz length of the salt. Use 0 if not using a salt
255255
\param inKey pointer to the buffer containing the key to use for KDF
256256
\param inKeySz length of the input key
257-
\param out pointer to the buffer in which to store the derived key
257+
\param out pointer to the buffer in which to store the derived key. Must be
258+
digest length per hash 'type'. See wc_HmacSizeByType()
258259
\param heap heap hint to use for memory. Can be NULL
259260
\param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
260261
@@ -275,6 +276,7 @@ int wc_HKDF_Extract(
275276
\sa wc_HKDF_Extract
276277
\sa wc_HKDF_Expand
277278
\sa wc_HKDF_Expand_ex
279+
\sa wc_HmacSizeByType
278280
*/
279281
int wc_HKDF_Extract_ex(
280282
int type,

wolfcrypt/src/cryptocb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,7 @@ int wc_CryptoCb_Hkdf(int hashType, const byte* inKey, word32 inKeySz,
25322532
return wc_CryptoCb_TranslateErrorCode(ret);
25332533
}
25342534

2535+
/* NOTE: size of 'out' must be the digest size per hashType */
25352536
int wc_CryptoCb_Hkdf_Extract(int hashType, const byte* salt, word32 saltSz,
25362537
const byte* inKey, word32 inKeySz, byte* out, int devId)
25372538
{

wolfcrypt/src/hmac.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,8 +1754,9 @@ int wolfSSL_GetHmacMaxSize(void)
17541754
const byte* localSalt; /* either points to user input or tmp */
17551755
word32 hashSz;
17561756

1757-
if (out == NULL || (inKey == NULL && inKeySz > 0))
1757+
if (out == NULL || (inKey == NULL && inKeySz > 0)) {
17581758
return BAD_FUNC_ARG;
1759+
}
17591760

17601761
#ifdef WOLF_CRYPTO_CB
17611762
/* Try crypto callback first */
@@ -1768,8 +1769,9 @@ int wolfSSL_GetHmacMaxSize(void)
17681769
#endif
17691770

17701771
ret = wc_HmacSizeByType(type);
1771-
if (ret < 0)
1772+
if (ret < 0) {
17721773
return ret;
1774+
}
17731775
hashSz = (word32)ret;
17741776

17751777
WC_ALLOC_VAR_EX(myHmac, Hmac, 1, NULL, DYNAMIC_TYPE_HMAC,
@@ -1830,12 +1832,14 @@ int wolfSSL_GetHmacMaxSize(void)
18301832
word32 hashSz;
18311833
byte n = 0x1;
18321834

1833-
if (out == NULL || (inKey == NULL && inKeySz > 0))
1835+
if (out == NULL || (inKey == NULL && inKeySz > 0)) {
18341836
return BAD_FUNC_ARG;
1837+
}
18351838

18361839
ret = wc_HmacSizeByType(type);
1837-
if (ret < 0)
1840+
if (ret < 0) {
18381841
return ret;
1842+
}
18391843
hashSz = (word32)ret;
18401844

18411845
/* RFC 5869 states that the length of output keying material in

wolfssl/wolfcrypt/cryptocb.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -638,20 +638,20 @@ typedef struct wc_CryptoInfo {
638638
int hashType; /* WC_SHA256, etc. */
639639
const byte* inKey; /* Input keying material */
640640
word32 inKeySz;
641-
const byte* salt; /* Optional salt */
641+
const byte* salt; /* Optional salt */
642642
word32 saltSz;
643-
const byte* info; /* Optional info */
643+
const byte* info; /* Optional info */
644644
word32 infoSz;
645-
byte* out; /* Output key material */
645+
byte* out; /* Output key material */
646646
word32 outSz;
647647
} hkdf;
648648
struct { /* HKDF extract */
649649
int hashType; /* WC_SHA256, etc. */
650-
const byte* salt; /* Optional salt */
651-
word32 saltSz;
650+
const byte* salt; /* Optional salt */
651+
word32 saltSz; /* must be 0 if salt==NULL */
652652
const byte* inKey; /* Input keying material */
653653
word32 inKeySz;
654-
byte* out; /* Output key material */
654+
byte* out; /* out must be size of the hashType digest */
655655
} hkdf_extract;
656656
struct { /* HKDF expand */
657657
int hashType; /* WC_SHA256, etc. */
@@ -905,7 +905,7 @@ WOLFSSL_LOCAL int wc_CryptoCb_Hmac(Hmac* hmac, int macType, const byte* in,
905905
word32 inSz, byte* digest);
906906
#endif /* !NO_HMAC */
907907

908-
#ifdef HAVE_HKDF
908+
#if defined(HAVE_HKDF) && !defined(NO_HMAC)
909909
WOLFSSL_LOCAL int wc_CryptoCb_Hkdf(int hashType, const byte* inKey,
910910
word32 inKeySz, const byte* salt,
911911
word32 saltSz, const byte* info,
@@ -916,7 +916,7 @@ WOLFSSL_LOCAL int wc_CryptoCb_Hkdf_Extract(int hashType, const byte* salt,
916916
WOLFSSL_LOCAL int wc_CryptoCb_Hkdf_Expand(int hashType, const byte* inKey,
917917
word32 inKeySz, const byte* info, word32 infoSz,
918918
byte* out, word32 outSz, int devId);
919-
#endif
919+
#endif /* HAVE_HKDF && !NO_HMAC */
920920

921921
#if defined(HAVE_CMAC_KDF)
922922
WOLFSSL_LOCAL int wc_CryptoCb_Kdf_TwostepCmac(const byte * salt, word32 saltSz,

0 commit comments

Comments
 (0)