check on hmac free and add else if case for check if key is 0's

This commit is contained in:
Jacob Barthelmeh
2021-05-28 16:27:54 +07:00
parent 252971aad7
commit ab07c55609

View File

@@ -5829,9 +5829,9 @@ static int _HMAC_K(byte* K, word32 KSz, byte* V, word32 VSz,
const byte* h1, word32 h1Sz, byte* x, word32 xSz, byte* oct, const byte* h1, word32 h1Sz, byte* x, word32 xSz, byte* oct,
byte* out, enum wc_HashType hashType, void* heap) { byte* out, enum wc_HashType hashType, void* heap) {
Hmac hmac; Hmac hmac;
int ret; int ret, init;
ret = wc_HmacInit(&hmac, heap, 0); ret = init = wc_HmacInit(&hmac, heap, 0);
if (ret == 0) if (ret == 0)
ret = wc_HmacSetKey(&hmac, hashType, K, KSz); ret = wc_HmacSetKey(&hmac, hashType, K, KSz);
@@ -5850,7 +5850,9 @@ static int _HMAC_K(byte* K, word32 KSz, byte* V, word32 VSz,
if (ret == 0) if (ret == 0)
ret = wc_HmacFinal(&hmac, out); ret = wc_HmacFinal(&hmac, out);
if (init == 0)
wc_HmacFree(&hmac); wc_HmacFree(&hmac);
return ret; return ret;
} }
@@ -6031,12 +6033,11 @@ int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
if (ret == 0) { if (ret == 0) {
if (mp_cmp(k, order) != MP_LT) { if (mp_cmp(k, order) != MP_LT) {
err = MP_VAL; err = MP_VAL;
} } else if (mp_iszero(k) == MP_YES) {
/* no 0 key's */ /* no 0 key's */
if (mp_iszero(k) == MP_YES)
err = MP_ZERO_E; err = MP_ZERO_E;
} }
}
/* 3.2 step h.3 if there was a problem with 'k' generated then try /* 3.2 step h.3 if there was a problem with 'k' generated then try
* again K = HMAC_K(V || 0x00) and V = HMAC_K(V) */ * again K = HMAC_K(V || 0x00) and V = HMAC_K(V) */