2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/sha1.h"
|
|
|
|
#include "mbedtls/sha256.h"
|
|
|
|
#include "mbedtls/sha512.h"
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_HEADER */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2019-01-31 14:20:20 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
|
|
|
void sha1_valid_param( )
|
|
|
|
{
|
|
|
|
TEST_VALID_PARAM( mbedtls_sha1_free( NULL ) );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
|
|
|
|
void sha1_invalid_param( )
|
|
|
|
{
|
|
|
|
mbedtls_sha1_context ctx;
|
|
|
|
unsigned char buf[64] = { 0 };
|
|
|
|
size_t const buflen = sizeof( buf );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha1_init( NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha1_clone( NULL, &ctx ) );
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha1_clone( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_starts_ret( NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_update_ret( NULL, buf, buflen ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_update_ret( &ctx, NULL, buflen ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_finish_ret( NULL, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_finish_ret( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_internal_sha1_process( NULL, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_internal_sha1_process( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_ret( NULL, buflen, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha1_ret( buf, buflen, NULL ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
2018-06-29 12:05:32 +02:00
|
|
|
void mbedtls_sha1( data_t * src_str, data_t * hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[41];
|
|
|
|
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
|
|
|
|
2017-06-09 05:32:58 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha1_ret( src_str->x, src_str->len, output ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2020-06-10 11:03:08 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, 20, hex_hash_string->len ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2019-01-31 14:20:20 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
|
|
|
void sha256_valid_param( )
|
|
|
|
{
|
|
|
|
TEST_VALID_PARAM( mbedtls_sha256_free( NULL ) );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
|
|
|
|
void sha256_invalid_param( )
|
|
|
|
{
|
|
|
|
mbedtls_sha256_context ctx;
|
|
|
|
unsigned char buf[64] = { 0 };
|
|
|
|
size_t const buflen = sizeof( buf );
|
|
|
|
int valid_type = 0;
|
|
|
|
int invalid_type = 42;
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha256_init( NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha256_clone( NULL, &ctx ) );
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha256_clone( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_starts_ret( NULL, valid_type ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_starts_ret( &ctx, invalid_type ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_update_ret( NULL, buf, buflen ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_update_ret( &ctx, NULL, buflen ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_finish_ret( NULL, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_finish_ret( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_internal_sha256_process( NULL, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_internal_sha256_process( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_ret( NULL, buflen,
|
|
|
|
buf, valid_type ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_ret( buf, buflen,
|
|
|
|
NULL, valid_type ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha256_ret( buf, buflen,
|
|
|
|
buf, invalid_type ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
2018-06-29 12:05:32 +02:00
|
|
|
void sha224( data_t * src_str, data_t * hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[57];
|
|
|
|
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
|
|
|
|
2017-06-09 05:32:58 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha256_ret( src_str->x, src_str->len, output, 1 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2020-06-10 11:03:08 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, 28, hex_hash_string->len ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
2018-06-29 12:05:32 +02:00
|
|
|
void mbedtls_sha256( data_t * src_str, data_t * hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[65];
|
|
|
|
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
|
|
|
|
2017-06-09 05:32:58 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha256_ret( src_str->x, src_str->len, output, 0 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2020-06-10 11:03:08 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, 32, hex_hash_string->len ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2019-01-31 14:20:20 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
|
|
|
void sha512_valid_param( )
|
|
|
|
{
|
|
|
|
TEST_VALID_PARAM( mbedtls_sha512_free( NULL ) );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
|
|
|
|
void sha512_invalid_param( )
|
|
|
|
{
|
|
|
|
mbedtls_sha512_context ctx;
|
|
|
|
unsigned char buf[64] = { 0 };
|
|
|
|
size_t const buflen = sizeof( buf );
|
|
|
|
int valid_type = 0;
|
|
|
|
int invalid_type = 42;
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha512_init( NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha512_clone( NULL, &ctx ) );
|
|
|
|
TEST_INVALID_PARAM( mbedtls_sha512_clone( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_starts_ret( NULL, valid_type ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_starts_ret( &ctx, invalid_type ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_update_ret( NULL, buf, buflen ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_update_ret( &ctx, NULL, buflen ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_finish_ret( NULL, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_finish_ret( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_internal_sha512_process( NULL, buf ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_internal_sha512_process( &ctx, NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_ret( NULL, buflen,
|
|
|
|
buf, valid_type ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_ret( buf, buflen,
|
|
|
|
NULL, valid_type ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
|
|
|
mbedtls_sha512_ret( buf, buflen,
|
|
|
|
buf, invalid_type ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
2018-06-29 12:05:32 +02:00
|
|
|
void sha384( data_t * src_str, data_t * hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[97];
|
|
|
|
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
|
|
|
|
2017-06-09 05:32:58 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha512_ret( src_str->x, src_str->len, output, 1 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2020-06-10 11:03:08 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, 48, hex_hash_string->len ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
2018-06-29 12:05:32 +02:00
|
|
|
void mbedtls_sha512( data_t * src_str, data_t * hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[129];
|
|
|
|
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
|
|
|
|
2017-06-09 05:32:58 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha512_ret( src_str->x, src_str->len, output, 0 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2020-06-10 11:03:08 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, 64, hex_hash_string->len ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-07-05 13:30:16 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
|
2017-05-30 15:23:15 +02:00
|
|
|
void sha1_selftest( )
|
2009-07-05 13:30:16 +02:00
|
|
|
{
|
2016-09-09 10:10:28 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
|
2009-07-05 13:30:16 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-07-05 13:30:16 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
|
2017-05-30 15:23:15 +02:00
|
|
|
void sha256_selftest( )
|
2009-07-05 13:30:16 +02:00
|
|
|
{
|
2016-09-09 10:10:28 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
|
2009-07-05 13:30:16 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-07-05 13:30:16 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
|
2017-05-30 15:23:15 +02:00
|
|
|
void sha512_selftest( )
|
2009-07-05 13:30:16 +02:00
|
|
|
{
|
2016-09-09 10:10:28 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
|
2009-07-05 13:30:16 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|