From 46e8fd8263a0806028f8cac919cb030c9d8d3a2b Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Wed, 14 Dec 2022 10:58:02 +0100 Subject: [PATCH] test: sha: test SHA224 and SHA256 separately This is meant to adapt to the new library design in which SHA224 and SHA256 can be built independently from each other. Signed-off-by: Valerio Setti --- programs/test/selftest.c | 3 +++ tests/suites/test_suite_shax.data | 4 ++++ tests/suites/test_suite_shax.function | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/programs/test/selftest.c b/programs/test/selftest.c index 163fda924..de1ee0fdb 100644 --- a/programs/test/selftest.c +++ b/programs/test/selftest.c @@ -243,6 +243,9 @@ const selftest_t selftests[] = #if defined(MBEDTLS_SHA1_C) {"sha1", mbedtls_sha1_self_test}, #endif +#if defined(MBEDTLS_SHA224_C) + {"sha256", mbedtls_sha224_self_test}, +#endif #if defined(MBEDTLS_SHA256_C) {"sha256", mbedtls_sha256_self_test}, #endif diff --git a/tests/suites/test_suite_shax.data b/tests/suites/test_suite_shax.data index dce9b7dc1..2af85c3cd 100644 --- a/tests/suites/test_suite_shax.data +++ b/tests/suites/test_suite_shax.data @@ -169,6 +169,10 @@ SHA-1 Selftest depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA1_C sha1_selftest: +SHA-224 Selftest +depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA224_C +sha224_selftest: + SHA-256 Selftest depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA256_C sha256_selftest: diff --git a/tests/suites/test_suite_shax.function b/tests/suites/test_suite_shax.function index c3c1708c9..79afe015d 100644 --- a/tests/suites/test_suite_shax.function +++ b/tests/suites/test_suite_shax.function @@ -46,9 +46,9 @@ void sha224( data_t * src_str, data_t * hash ) memset(output, 0x00, 57); - TEST_ASSERT( mbedtls_sha256( src_str->x, src_str->len, output, 1 ) == 0 ); + TEST_EQUAL( mbedtls_sha256( src_str->x, src_str->len, output, 1 ), 0 ); - TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ) == 0 ); + TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ), 0 ); } /* END_CASE */ @@ -60,9 +60,9 @@ void mbedtls_sha256( data_t * src_str, data_t * hash ) memset(output, 0x00, 65); - TEST_ASSERT( mbedtls_sha256( src_str->x, src_str->len, output, 0 ) == 0 ); + TEST_EQUAL( mbedtls_sha256( src_str->x, src_str->len, output, 0 ), 0 ); - TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ) == 0 ); + TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ), 0 ); } /* END_CASE */ @@ -121,10 +121,17 @@ void sha1_selftest( ) } /* END_CASE */ +/* BEGIN_CASE depends_on:MBEDTLS_SHA224_C:MBEDTLS_SELF_TEST */ +void sha224_selftest( ) +{ + TEST_EQUAL( mbedtls_sha224_self_test( 1 ), 0 ); +} +/* END_CASE */ + /* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */ void sha256_selftest( ) { - TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 ); + TEST_EQUAL( mbedtls_sha256_self_test( 1 ), 0 ); } /* END_CASE */