From 67565d0f22d3d8e4412ab81ad2209e9e2916bac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 3 Feb 2023 12:51:03 +0100 Subject: [PATCH] Use TEST_EQUAL when applicable in test_suite_md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backporting note: contextual differences because we don't have info_from_ctx in 2.28. Signed-off-by: Manuel Pégourié-Gonnard --- tests/suites/test_suite_md.function | 134 ++++++++++++++-------------- 1 file changed, 66 insertions(+), 68 deletions(-) diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function index a499ca064..c91aba36d 100644 --- a/tests/suites/test_suite_md.function +++ b/tests/suites/test_suite_md.function @@ -29,9 +29,9 @@ void mbedtls_md_process() for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++) { info = mbedtls_md_info_from_type(*md_type_ptr); TEST_ASSERT(info != NULL); - TEST_ASSERT(mbedtls_md_setup(&ctx, info, 0) == 0); - TEST_ASSERT(mbedtls_md_starts(&ctx) == 0); - TEST_ASSERT(mbedtls_md_process(&ctx, buf) == 0); + TEST_EQUAL(0, mbedtls_md_setup(&ctx, info, 0)); + TEST_EQUAL(0, mbedtls_md_starts(&ctx)); + TEST_EQUAL(0, mbedtls_md_process(&ctx, buf)); mbedtls_md_free(&ctx); } @@ -49,53 +49,51 @@ void md_null_args() mbedtls_md_init(&ctx); - TEST_ASSERT(mbedtls_md_get_size(NULL) == 0); + TEST_EQUAL(0, mbedtls_md_get_size(NULL)); TEST_ASSERT(mbedtls_md_get_type(NULL) == MBEDTLS_MD_NONE); TEST_ASSERT(mbedtls_md_get_name(NULL) == NULL); TEST_ASSERT(mbedtls_md_info_from_string(NULL) == NULL); - TEST_ASSERT(mbedtls_md_setup(&ctx, NULL, 0) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_setup(NULL, info, 0) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_setup(&ctx, NULL, 0), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_setup(NULL, info, 0), MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_starts(NULL) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_starts(&ctx) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_starts(NULL), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_starts(&ctx), MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_update(NULL, buf, 1) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_update(&ctx, buf, 1) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_update(NULL, buf, 1), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_update(&ctx, buf, 1), MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_finish(NULL, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_finish(&ctx, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_finish(NULL, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_finish(&ctx, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md(NULL, buf, 1, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md(NULL, buf, 1, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); #if defined(MBEDTLS_FS_IO) - TEST_ASSERT(mbedtls_md_file(NULL, "", buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_file(NULL, "", buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); #endif - TEST_ASSERT(mbedtls_md_hmac_starts(NULL, buf, 1) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_starts(&ctx, buf, 1) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_starts(NULL, buf, 1), + MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_starts(&ctx, buf, 1), + MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_update(NULL, buf, 1) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_update(&ctx, buf, 1) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_update(NULL, buf, 1), + MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_update(&ctx, buf, 1), + MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_finish(NULL, buf) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_finish(&ctx, buf) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_finish(NULL, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_finish(&ctx, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_reset(NULL) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac_reset(&ctx) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_reset(NULL), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac_reset(&ctx), MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_hmac(NULL, buf, 1, buf, 1, buf) - == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_hmac(NULL, buf, 1, buf, 1, buf), + MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_process(NULL, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); - TEST_ASSERT(mbedtls_md_process(&ctx, buf) == MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_process(NULL, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); + TEST_EQUAL(mbedtls_md_process(&ctx, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA); /* Ok, this is not NULL arg but NULL return... */ TEST_ASSERT(mbedtls_md_info_from_type(MBEDTLS_MD_NONE) == NULL); @@ -114,9 +112,9 @@ void md_info(int md_type, char *md_name, int md_size) TEST_ASSERT(md_info != NULL); TEST_ASSERT(md_info == mbedtls_md_info_from_string(md_name)); - TEST_ASSERT(mbedtls_md_get_type(md_info) == (mbedtls_md_type_t) md_type); - TEST_ASSERT(mbedtls_md_get_size(md_info) == (unsigned char) md_size); - TEST_ASSERT(strcmp(mbedtls_md_get_name(md_info), md_name) == 0); + TEST_EQUAL(mbedtls_md_get_type(md_info), (mbedtls_md_type_t) md_type); + TEST_EQUAL(mbedtls_md_get_size(md_info), (unsigned char) md_size); + TEST_EQUAL(0, strcmp(mbedtls_md_get_name(md_info), md_name)); found = 0; for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++) { @@ -124,7 +122,7 @@ void md_info(int md_type, char *md_name, int md_size) found = 1; } } - TEST_ASSERT(found == 1); + TEST_EQUAL(found, 1); } /* END_CASE */ @@ -139,7 +137,7 @@ void md_text(int md_type, char *text_src_string, data_t *hash) md_info = mbedtls_md_info_from_type(md_type); TEST_ASSERT(md_info != NULL); - TEST_ASSERT(0 == mbedtls_md(md_info, src, src_len, output)); + TEST_EQUAL(0, mbedtls_md(md_info, src, src_len, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, mbedtls_md_get_size(md_info), @@ -156,7 +154,7 @@ void md_hex(int md_type, data_t *src_str, data_t *hash) md_info = mbedtls_md_info_from_type(md_type); TEST_ASSERT(md_info != NULL); - TEST_ASSERT(0 == mbedtls_md(md_info, src_str->x, src_str->len, output)); + TEST_EQUAL(0, mbedtls_md(md_info, src_str->x, src_str->len, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, @@ -184,16 +182,16 @@ void md_text_multi(int md_type, char *text_src_string, md_info = mbedtls_md_info_from_type(md_type); TEST_ASSERT(md_info != NULL); - TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 0)); - TEST_ASSERT(0 == mbedtls_md_setup(&ctx_copy, md_info, 0)); + TEST_EQUAL(0, mbedtls_md_setup(&ctx, md_info, 0)); + TEST_EQUAL(0, mbedtls_md_setup(&ctx_copy, md_info, 0)); - TEST_ASSERT(0 == mbedtls_md_starts(&ctx)); + TEST_EQUAL(0, mbedtls_md_starts(&ctx)); TEST_ASSERT(ctx.md_ctx != NULL); - TEST_ASSERT(0 == mbedtls_md_update(&ctx, src, halfway)); - TEST_ASSERT(0 == mbedtls_md_clone(&ctx_copy, &ctx)); + TEST_EQUAL(0, mbedtls_md_update(&ctx, src, halfway)); + TEST_EQUAL(0, mbedtls_md_clone(&ctx_copy, &ctx)); - TEST_ASSERT(0 == mbedtls_md_update(&ctx, src + halfway, src_len - halfway)); - TEST_ASSERT(0 == mbedtls_md_finish(&ctx, output)); + TEST_EQUAL(0, mbedtls_md_update(&ctx, src + halfway, src_len - halfway)); + TEST_EQUAL(0, mbedtls_md_finish(&ctx, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, mbedtls_md_get_size(md_info), hash->len) == 0); @@ -201,8 +199,8 @@ void md_text_multi(int md_type, char *text_src_string, /* Test clone */ memset(output, 0x00, sizeof(output)); - TEST_ASSERT(0 == mbedtls_md_update(&ctx_copy, src + halfway, src_len - halfway)); - TEST_ASSERT(0 == mbedtls_md_finish(&ctx_copy, output)); + TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src + halfway, src_len - halfway)); + TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, mbedtls_md_get_size(md_info), hash->len) == 0); @@ -226,18 +224,18 @@ void md_hex_multi(int md_type, data_t *src_str, data_t *hash) md_info = mbedtls_md_info_from_type(md_type); TEST_ASSERT(md_info != NULL); - TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 0)); - TEST_ASSERT(0 == mbedtls_md_setup(&ctx_copy, md_info, 0)); + TEST_EQUAL(0, mbedtls_md_setup(&ctx, md_info, 0)); + TEST_EQUAL(0, mbedtls_md_setup(&ctx_copy, md_info, 0)); halfway = src_str->len / 2; - TEST_ASSERT(0 == mbedtls_md_starts(&ctx)); + TEST_EQUAL(0, mbedtls_md_starts(&ctx)); TEST_ASSERT(ctx.md_ctx != NULL); - TEST_ASSERT(0 == mbedtls_md_update(&ctx, src_str->x, halfway)); - TEST_ASSERT(0 == mbedtls_md_clone(&ctx_copy, &ctx)); + TEST_EQUAL(0, mbedtls_md_update(&ctx, src_str->x, halfway)); + TEST_EQUAL(0, mbedtls_md_clone(&ctx_copy, &ctx)); - TEST_ASSERT(0 == mbedtls_md_update(&ctx, src_str->x + halfway, src_str->len - halfway)); - TEST_ASSERT(0 == mbedtls_md_finish(&ctx, output)); + TEST_EQUAL(0, mbedtls_md_update(&ctx, src_str->x + halfway, src_str->len - halfway)); + TEST_EQUAL(0, mbedtls_md_finish(&ctx, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, mbedtls_md_get_size(md_info), hash->len) == 0); @@ -245,8 +243,8 @@ void md_hex_multi(int md_type, data_t *src_str, data_t *hash) /* Test clone */ memset(output, 0x00, sizeof(output)); - TEST_ASSERT(0 == mbedtls_md_update(&ctx_copy, src_str->x + halfway, src_str->len - halfway)); - TEST_ASSERT(0 == mbedtls_md_finish(&ctx_copy, output)); + TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src_str->x + halfway, src_str->len - halfway)); + TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, mbedtls_md_get_size(md_info), hash->len) == 0); @@ -269,8 +267,8 @@ void mbedtls_md_hmac(int md_type, int trunc_size, TEST_ASSERT(md_info != NULL); - TEST_ASSERT(mbedtls_md_hmac(md_info, key_str->x, key_str->len, src_str->x, src_str->len, - output) == 0); + TEST_EQUAL(0, mbedtls_md_hmac(md_info, key_str->x, key_str->len, + src_str->x, src_str->len, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, trunc_size, hash->len) == 0); @@ -290,15 +288,15 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str, md_info = mbedtls_md_info_from_type(md_type); TEST_ASSERT(md_info != NULL); - TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 1)); + TEST_EQUAL(0, mbedtls_md_setup(&ctx, md_info, 1)); halfway = src_str->len / 2; - TEST_ASSERT(0 == mbedtls_md_hmac_starts(&ctx, key_str->x, key_str->len)); + TEST_EQUAL(0, mbedtls_md_hmac_starts(&ctx, key_str->x, key_str->len)); TEST_ASSERT(ctx.md_ctx != NULL); - TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x, halfway)); - TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway)); - TEST_ASSERT(0 == mbedtls_md_hmac_finish(&ctx, output)); + TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x, halfway)); + TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway)); + TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, trunc_size, hash->len) == 0); @@ -306,10 +304,10 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str, /* Test again, for reset() */ memset(output, 0x00, sizeof(output)); - TEST_ASSERT(0 == mbedtls_md_hmac_reset(&ctx)); - TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x, halfway)); - TEST_ASSERT(0 == mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway)); - TEST_ASSERT(0 == mbedtls_md_hmac_finish(&ctx, output)); + TEST_EQUAL(0, mbedtls_md_hmac_reset(&ctx)); + TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x, halfway)); + TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway)); + TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, trunc_size, hash->len) == 0); @@ -329,7 +327,7 @@ void mbedtls_md_file(int md_type, char *filename, md_info = mbedtls_md_info_from_type(md_type); TEST_ASSERT(md_info != NULL); - TEST_ASSERT(mbedtls_md_file(md_info, filename, output) == 0); + TEST_EQUAL(0, mbedtls_md_file(md_info, filename, output)); TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, mbedtls_md_get_size(md_info),