From e35afa28f7ede1083453ef707daac3ccbcb6bfd6 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Wed, 13 Jul 2016 17:09:14 +0100 Subject: [PATCH] Update *_multi tests in test_suite_md to do more than 1 step --- tests/suites/test_suite_md.function | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function index 0fcaa388f..e8fec2826 100644 --- a/tests/suites/test_suite_md.function +++ b/tests/suites/test_suite_md.function @@ -187,6 +187,7 @@ void md_text_multi( char *text_md_name, char *text_src_string, unsigned char src_str[1000]; unsigned char hash_str[1000]; unsigned char output[100]; + int halfway, len; const mbedtls_md_info_t *md_info = NULL; mbedtls_md_context_t ctx; @@ -200,13 +201,17 @@ void md_text_multi( char *text_md_name, char *text_src_string, strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 ); strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 ); + len = strlen( (char *) src_str ); + halfway = len / 2; + md_info = mbedtls_md_info_from_string(md_name); TEST_ASSERT( md_info != NULL ); TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) ); TEST_ASSERT ( 0 == mbedtls_md_starts( &ctx ) ); TEST_ASSERT ( ctx.md_ctx != NULL ); - TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str, strlen( (char *) src_str ) ) ); + TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str, halfway ) ); + TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, len - halfway ) ); TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) ); hexify( hash_str, output, mbedtls_md_get_size(md_info) ); @@ -226,7 +231,7 @@ void md_hex_multi( char *text_md_name, char *hex_src_string, unsigned char src_str[10000]; unsigned char hash_str[10000]; unsigned char output[100]; - int src_len; + int src_len, halfway; const mbedtls_md_info_t *md_info = NULL; mbedtls_md_context_t ctx; @@ -243,10 +248,12 @@ void md_hex_multi( char *text_md_name, char *hex_src_string, TEST_ASSERT ( 0 == mbedtls_md_setup( &ctx, md_info, 0 ) ); src_len = unhexify( src_str, hex_src_string ); + halfway = src_len / 2; TEST_ASSERT ( 0 == mbedtls_md_starts( &ctx ) ); TEST_ASSERT ( ctx.md_ctx != NULL ); - TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str, src_len ) ); + TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str, halfway ) ); + TEST_ASSERT ( 0 == mbedtls_md_update( &ctx, src_str + halfway, src_len - halfway) ); TEST_ASSERT ( 0 == mbedtls_md_finish( &ctx, output ) ); hexify( hash_str, output, mbedtls_md_get_size(md_info) ); @@ -299,7 +306,7 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string, unsigned char key_str[10000]; unsigned char hash_str[10000]; unsigned char output[100]; - int key_len, src_len; + int key_len, src_len, halfway; const mbedtls_md_info_t *md_info = NULL; mbedtls_md_context_t ctx; @@ -318,10 +325,12 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string, key_len = unhexify( key_str, hex_key_string ); src_len = unhexify( src_str, hex_src_string ); + halfway = src_len / 2; TEST_ASSERT ( 0 == mbedtls_md_hmac_starts( &ctx, key_str, key_len ) ); TEST_ASSERT ( ctx.md_ctx != NULL ); - TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str, src_len ) ); + TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str, halfway ) ); + TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str + halfway, src_len - halfway ) ); TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) ); hexify( hash_str, output, mbedtls_md_get_size(md_info) ); @@ -332,7 +341,8 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string, memset(output, 0x00, 100); TEST_ASSERT ( 0 == mbedtls_md_hmac_reset( &ctx ) ); - TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str, src_len ) ); + TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str, halfway ) ); + TEST_ASSERT ( 0 == mbedtls_md_hmac_update( &ctx, src_str + halfway, src_len - halfway ) ); TEST_ASSERT ( 0 == mbedtls_md_hmac_finish( &ctx, output ) ); hexify( hash_str, output, mbedtls_md_get_size(md_info) );