test: sha: test SHA384 and SHA512 separately

This is meant to adapt to the new library design in which
SHA384 and SHA512 can be built independently from each other.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This commit is contained in:
Valerio Setti 2022-12-14 08:55:53 +01:00
parent 43363f5962
commit 898e7a3afe
4 changed files with 23 additions and 5 deletions

View File

@ -1031,15 +1031,19 @@ exit:
return( ret );
}
#if defined(MBEDTLS_SHA512_C)
int mbedtls_sha512_self_test( int verbose )
{
return mbedtls_sha512_common_self_test( verbose, 0 );
}
#endif /* MBEDTLS_SHA512_C */
#if defined(MBEDTLS_SHA384_C)
int mbedtls_sha384_self_test( int verbose )
{
return mbedtls_sha512_common_self_test( verbose, 1 );
}
#endif /* MBEDTLS_SHA384_C */
#undef ARRAY_LENGTH

View File

@ -246,6 +246,9 @@ const selftest_t selftests[] =
#if defined(MBEDTLS_SHA256_C)
{"sha256", mbedtls_sha256_self_test},
#endif
#if defined(MBEDTLS_SHA384_C)
{"sha512", mbedtls_sha384_self_test},
#endif
#if defined(MBEDTLS_SHA512_C)
{"sha512", mbedtls_sha512_self_test},
#endif

View File

@ -173,6 +173,10 @@ SHA-256 Selftest
depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA256_C
sha256_selftest:
SHA-384 Selftest
depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA384_C
sha384_selftest:
SHA-512 Selftest
depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA512_C
sha512_selftest:

View File

@ -94,9 +94,9 @@ void sha384( data_t * src_str, data_t * hash )
memset(output, 0x00, 97);
TEST_ASSERT( mbedtls_sha512( src_str->x, src_str->len, output, 1 ) == 0 );
TEST_EQUAL( mbedtls_sha512( src_str->x, src_str->len, output, 1 ), 0 );
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ) == 0 );
TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ), 0 );
}
/* END_CASE */
@ -108,9 +108,9 @@ void mbedtls_sha512( data_t * src_str, data_t * hash )
memset(output, 0x00, 129);
TEST_ASSERT( mbedtls_sha512( src_str->x, src_str->len, output, 0 ) == 0 );
TEST_EQUAL( mbedtls_sha512( src_str->x, src_str->len, output, 0 ), 0 );
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ) == 0 );
TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ), 0 );
}
/* END_CASE */
@ -128,9 +128,16 @@ void sha256_selftest( )
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA384_C:MBEDTLS_SELF_TEST */
void sha384_selftest( )
{
TEST_EQUAL( mbedtls_sha384_self_test( 1 ), 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
void sha512_selftest( )
{
TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
TEST_EQUAL( mbedtls_sha512_self_test( 1 ), 0 );
}
/* END_CASE */