early-access version 1503

This commit is contained in:
pineappleEA
2021-03-06 01:41:47 +01:00
parent a37fdd48d5
commit 3fd627d0ba
558 changed files with 55823 additions and 15727 deletions

View File

@@ -9,33 +9,23 @@
*/
/* BEGIN_CASE */
void test_hkdf( int md_alg, char *hex_ikm_string, char *hex_salt_string,
char *hex_info_string, char *hex_okm_string )
void test_hkdf( int md_alg, data_t *ikm, data_t *salt, data_t *info,
data_t *expected_okm )
{
int ret;
size_t ikm_len, salt_len, info_len, okm_len;
unsigned char ikm[1024] = { '\0' };
unsigned char salt[1024] = { '\0' };
unsigned char info[1024] = { '\0' };
unsigned char expected_okm[1024] = { '\0' };
unsigned char okm[1024] = { '\0' };
unsigned char okm_string[1000] = { '\0' };
unsigned char okm[128] = { '\0' };
const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
TEST_ASSERT( md != NULL );
ikm_len = unhexify( ikm, hex_ikm_string );
salt_len = unhexify( salt, hex_salt_string );
info_len = unhexify( info, hex_info_string );
okm_len = unhexify( expected_okm, hex_okm_string );
TEST_ASSERT( expected_okm->len <= sizeof( okm ) );
ret = mbedtls_hkdf( md, salt, salt_len, ikm, ikm_len, info, info_len, okm,
okm_len);
ret = mbedtls_hkdf( md, salt->x, salt->len, ikm->x, ikm->len,
info->x, info->len, okm, expected_okm->len );
TEST_ASSERT( ret == 0 );
// Run hexify on it so that it looks nicer if the assertion fails
hexify( okm_string, okm, okm_len );
TEST_ASSERT( !strcmp( (char *)okm_string, hex_okm_string ) );
ASSERT_COMPARE( okm , expected_okm->len,
expected_okm->x, expected_okm->len );
}
/* END_CASE */
@@ -59,12 +49,11 @@ void test_hkdf_extract( int md_alg, char *hex_ikm_string,
ikm = unhexify_alloc( hex_ikm_string, &ikm_len );
salt = unhexify_alloc( hex_salt_string, &salt_len );
prk = unhexify_alloc( hex_prk_string, &prk_len );
TEST_ASSERT( prk_len == output_prk_len );
ret = mbedtls_hkdf_extract( md, salt, salt_len, ikm, ikm_len, output_prk );
TEST_ASSERT( ret == 0 );
TEST_ASSERT( !memcmp( output_prk, prk, prk_len ) );
ASSERT_COMPARE( output_prk, output_prk_len, prk, prk_len );
exit:
mbedtls_free(ikm);
@@ -100,7 +89,7 @@ void test_hkdf_expand( int md_alg, char *hex_info_string,
ret = mbedtls_hkdf_expand( md, prk, prk_len, info, info_len,
output_okm, OKM_LEN );
TEST_ASSERT( ret == 0 );
TEST_ASSERT( !memcmp( output_okm, okm, okm_len ) );
ASSERT_COMPARE( output_okm, okm_len, okm, okm_len );
exit:
mbedtls_free(info);