Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 2.16: Reduce Stack usage of hkdf test function #2364

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Bugfix
replacements of standard calloc/free functions through the macros
MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_FREE_MACRO.
Reported by ole-de and ddhome2006. Fixes #882, #1642 and #1706.
* Reduce stack usage of hkdf tests. Fixes #2195.

Changes
* Removed support for Yotta as a build tool.
Expand Down
20 changes: 12 additions & 8 deletions tests/suites/test_suite_hkdf.function
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ void test_hkdf( int md_alg, char *hex_ikm_string, char *hex_salt_string,
{
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 ikm[128] = { '\0' };
unsigned char salt[128] = { '\0' };
unsigned char info[128] = { '\0' };
unsigned char expected_okm[128] = { '\0' };
unsigned char okm[128] = { '\0' };
/*
* okm_hex is the string representation of okm,
* so its size is twice the size of okm, and an extra null-termination.
*/
unsigned char okm_hex[257] = { '\0' };

const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
TEST_ASSERT( md != NULL );
Expand All @@ -34,8 +38,8 @@ void test_hkdf( int md_alg, char *hex_ikm_string, char *hex_salt_string,
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 ) );
hexify( okm_hex, okm, okm_len );
TEST_ASSERT( !strcmp( (char *)okm_hex, hex_okm_string ) );
}
/* END_CASE */

Expand Down