46e8fd8263
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 <vsetti@baylibre.com>
150 lines
3.6 KiB
C
150 lines
3.6 KiB
C
/* BEGIN_HEADER */
|
|
#include "mbedtls/sha1.h"
|
|
#include "mbedtls/sha256.h"
|
|
#include "mbedtls/sha512.h"
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
|
void mbedtls_sha1( data_t * src_str, data_t * hash )
|
|
{
|
|
unsigned char output[41];
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
|
TEST_ASSERT( mbedtls_sha1( src_str->x, src_str->len, output ) == 0 );
|
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 20, hash->len ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
|
void sha256_invalid_param( )
|
|
{
|
|
mbedtls_sha256_context ctx;
|
|
unsigned char buf[64] = { 0 };
|
|
size_t const buflen = sizeof( buf );
|
|
int invalid_type = 42;
|
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
mbedtls_sha256_starts( &ctx, invalid_type ) );
|
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
mbedtls_sha256( buf, buflen,
|
|
buf, invalid_type ) );
|
|
|
|
exit:
|
|
return;
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA224_C */
|
|
void sha224( data_t * src_str, data_t * hash )
|
|
{
|
|
unsigned char output[57];
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
|
TEST_EQUAL( mbedtls_sha256( src_str->x, src_str->len, output, 1 ), 0 );
|
|
|
|
TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ), 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
|
void mbedtls_sha256( data_t * src_str, data_t * hash )
|
|
{
|
|
unsigned char output[65];
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
|
TEST_EQUAL( mbedtls_sha256( src_str->x, src_str->len, output, 0 ), 0 );
|
|
|
|
TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ), 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
|
void sha512_invalid_param( )
|
|
{
|
|
mbedtls_sha512_context ctx;
|
|
unsigned char buf[64] = { 0 };
|
|
size_t const buflen = sizeof( buf );
|
|
int invalid_type = 42;
|
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
mbedtls_sha512_starts( &ctx, invalid_type ) );
|
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
mbedtls_sha512( buf, buflen,
|
|
buf, invalid_type ) );
|
|
|
|
exit:
|
|
return;
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA384_C */
|
|
void sha384( data_t * src_str, data_t * hash )
|
|
{
|
|
unsigned char output[97];
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
|
TEST_EQUAL( mbedtls_sha512( src_str->x, src_str->len, output, 1 ), 0 );
|
|
|
|
TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ), 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
|
void mbedtls_sha512( data_t * src_str, data_t * hash )
|
|
{
|
|
unsigned char output[129];
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
|
TEST_EQUAL( mbedtls_sha512( src_str->x, src_str->len, output, 0 ), 0 );
|
|
|
|
TEST_EQUAL( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ), 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
|
|
void sha1_selftest( )
|
|
{
|
|
TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
|
|
}
|
|
/* 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_EQUAL( mbedtls_sha256_self_test( 1 ), 0 );
|
|
}
|
|
/* 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_EQUAL( mbedtls_sha512_self_test( 1 ), 0 );
|
|
}
|
|
/* END_CASE */
|