[IoT-Safe] Add support sha384 + sha512

This commit is contained in:
Daniele Lacamera
2024-01-26 10:20:03 +01:00
parent 578735e06c
commit 6dab75368d

View File

@@ -749,43 +749,37 @@ static int iotsafe_hkdf_extract(byte* prk, const byte* salt, word32 saltLen,
int ret; int ret;
char *resp; char *resp;
uint16_t hash_algo = 0; uint16_t hash_algo = 0;
int len; int hash_len;
uint16_t hash_algo_be = 0; uint16_t hash_algo_be = 0;
WOLFSSL_MSG("Enter iotsafe_hkdf_extract"); WOLFSSL_MSG("Enter iotsafe_hkdf_extract");
switch (digest) { switch (digest) {
#ifndef NO_SHA256 #ifndef NO_SHA256
case WC_SHA256: case WC_SHA256:
hash_algo = (uint16_t)1; hash_algo = (uint16_t)1;
if (ikmLen == 0) { hash_len = WC_SHA256_DIGEST_SIZE;
len = WC_SHA256_DIGEST_SIZE;
}
break; break;
#endif #endif
#ifdef WOLFSSL_SHA384 #ifdef WOLFSSL_SHA384
case WC_SHA384: case WC_SHA384:
hash_algo = (uint16_t)2; hash_algo = (uint16_t)2;
if (ikmLen == 0) { hash_len = WC_SHA384_DIGEST_SIZE;
len = WC_SHA384_DIGEST_SIZE;
}
break; break;
#endif #endif
#ifdef WOLFSSL_TLS13_SHA512 #ifdef WOLFSSL_TLS13_SHA512
case WC_SHA512: case WC_SHA512:
hash_algo = (uint16_t)4; hash_algo = (uint16_t)4;
if (ikmLen == 0) { hash_len = WC_SHA512_DIGEST_SIZE;
len = WC_SHA512_DIGEST_SIZE;
}
break; break;
#endif #endif
default: default:
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
break; break;
} }
if (ikmLen == 0) { if (ikmLen == 0) {
ikmLen = len; ikmLen = hash_len;
XMEMSET(ikm, 0, len); XMEMSET(ikm, 0, hash_len);
} }
#ifdef DEBUG_IOTSAFE #ifdef DEBUG_IOTSAFE
@@ -812,14 +806,12 @@ static int iotsafe_hkdf_extract(byte* prk, const byte* salt, word32 saltLen,
WOLFSSL_MSG("Unexpected reply from HKDF extract"); WOLFSSL_MSG("Unexpected reply from HKDF extract");
ret = WC_HW_E; ret = WC_HW_E;
} else { } else {
ret = hexbuffer_conv(resp, prk, hash_len);
ret = hexbuffer_conv(resp, prk, 32);
if (ret < 0) if (ret < 0)
ret = WC_HW_E; ret = WC_HW_E;
else else
ret = 0; ret = 0;
} }
return ret; return ret;
} }
#endif #endif