From cd33413a55aad3cf7ed68427dfa98cf25beaf35b Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 30 May 2023 16:41:55 +0100 Subject: [PATCH 1/3] Modify tests to suit new behaviour Prevent the null argument test from running when only MBEDTLS_MD_LIGHT is enabled. Signed-off-by: Thomas Daubney --- tests/suites/test_suite_md.data | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/suites/test_suite_md.data b/tests/suites/test_suite_md.data index ccc7b10ae4..15e3b99d56 100644 --- a/tests/suites/test_suite_md.data +++ b/tests/suites/test_suite_md.data @@ -3,6 +3,7 @@ MD list mbedtls_md_list: MD NULL/uninitialised arguments +depends_on:MBEDTLS_MD_C md_null_args: Information on MD5 From 73cfde8f85e10f4face574ee783904b33e6d0c62 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 30 May 2023 15:34:28 +0100 Subject: [PATCH 2/3] Remove certain null pointer checks when only MD_LIGHT enabled When MD_LIGHT is enabled but MD_C is not then certain null pointer checks can be removed on functions that take an mbedtls_md_context_t * as a parameter, since MD_LIGHT does not support these null pointers. Signed-off-by: Thomas Daubney --- library/md.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/library/md.c b/library/md.c index bebe3580bd..306af72b32 100644 --- a/library/md.c +++ b/library/md.c @@ -376,7 +376,12 @@ int mbedtls_md_clone(mbedtls_md_context_t *dst, int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac) { - if (md_info == NULL || ctx == NULL) { +#if defined(MBEDTLS_MD_C) + if (ctx == NULL) { + return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + } +#endif + if (md_info == NULL) { return MBEDTLS_ERR_MD_BAD_INPUT_DATA; } @@ -455,9 +460,11 @@ int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info int mbedtls_md_starts(mbedtls_md_context_t *ctx) { +#if defined(MBEDTLS_MD_C) if (ctx == NULL || ctx->md_info == NULL) { return MBEDTLS_ERR_MD_BAD_INPUT_DATA; } +#endif #if defined(MBEDTLS_MD_SOME_PSA) if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { @@ -504,9 +511,11 @@ int mbedtls_md_starts(mbedtls_md_context_t *ctx) int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen) { +#if defined(MBEDTLS_MD_C) if (ctx == NULL || ctx->md_info == NULL) { return MBEDTLS_ERR_MD_BAD_INPUT_DATA; } +#endif #if defined(MBEDTLS_MD_SOME_PSA) if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { @@ -551,9 +560,11 @@ int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, siz int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output) { +#if defined(MBEDTLS_MD_C) if (ctx == NULL || ctx->md_info == NULL) { return MBEDTLS_ERR_MD_BAD_INPUT_DATA; } +#endif #if defined(MBEDTLS_MD_SOME_PSA) if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { From 5903e9c428ce0800fc3bb447cb038b96cd4fb597 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 2 Jun 2023 10:43:08 +0100 Subject: [PATCH 3/3] Modify tests in response to review comments. Address the way the tests have been modified in response to review comments. Signed-off-by: Thomas Daubney --- tests/suites/test_suite_md.data | 1 - tests/suites/test_suite_md.function | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/suites/test_suite_md.data b/tests/suites/test_suite_md.data index 15e3b99d56..ccc7b10ae4 100644 --- a/tests/suites/test_suite_md.data +++ b/tests/suites/test_suite_md.data @@ -3,7 +3,6 @@ MD list mbedtls_md_list: MD NULL/uninitialised arguments -depends_on:MBEDTLS_MD_C md_null_args: Information on MD5 diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function index 4438fa1509..ac9516ab8d 100644 --- a/tests/suites/test_suite_md.function +++ b/tests/suites/test_suite_md.function @@ -61,7 +61,6 @@ void md_null_args() TEST_EQUAL(mbedtls_md_setup(&ctx, NULL, 0), MBEDTLS_ERR_MD_BAD_INPUT_DATA); #if defined(MBEDTLS_MD_C) TEST_EQUAL(mbedtls_md_setup(NULL, info, 0), MBEDTLS_ERR_MD_BAD_INPUT_DATA); -#endif TEST_EQUAL(mbedtls_md_starts(NULL), MBEDTLS_ERR_MD_BAD_INPUT_DATA); TEST_EQUAL(mbedtls_md_starts(&ctx), MBEDTLS_ERR_MD_BAD_INPUT_DATA); @@ -71,6 +70,7 @@ void md_null_args() 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); +#endif TEST_EQUAL(mbedtls_md(NULL, buf, 1, buf), MBEDTLS_ERR_MD_BAD_INPUT_DATA);