2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/sha1.h"
|
|
|
|
#include "mbedtls/sha256.h"
|
|
|
|
#include "mbedtls/sha512.h"
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_HEADER */
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
2020-06-26 12:33:03 +00:00
|
|
|
void mbedtls_sha1( data_t * src_str, data_t * hash )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char output[41];
|
|
|
|
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
|
|
|
|
2021-06-08 14:45:41 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha1( src_str->x, src_str->len, output ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2020-06-26 12:33:03 +00:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 20, hash->len ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2021-05-25 13:15:57 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:NOT_DEFINED */
|
2019-01-31 13:20:20 +00:00
|
|
|
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;
|
|
|
|
|
2021-05-25 13:15:57 +00:00
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
2021-06-08 14:45:41 +00:00
|
|
|
mbedtls_sha256_starts( &ctx, invalid_type ) );
|
2019-01-31 13:20:20 +00:00
|
|
|
|
2021-05-25 13:15:57 +00:00
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
|
2021-06-08 14:45:41 +00:00
|
|
|
mbedtls_sha256( buf, buflen,
|
2019-01-31 13:20:20 +00:00
|
|
|
buf, invalid_type ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-04-19 14:46:28 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA224_C */
|
2020-06-26 12:33:03 +00:00
|
|
|
void sha224( data_t * src_str, data_t * hash )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char output[57];
|
|
|
|
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
|
|
|
|
2021-06-08 14:45:41 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha256( src_str->x, src_str->len, output, 1 ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2020-06-26 12:33:03 +00:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 28, hash->len ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
2020-06-26 12:33:03 +00:00
|
|
|
void mbedtls_sha256( data_t * src_str, data_t * hash )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char output[65];
|
|
|
|
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
|
|
|
|
2021-06-08 14:45:41 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha256( src_str->x, src_str->len, output, 0 ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2020-06-26 12:33:03 +00:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 32, hash->len ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2021-05-25 13:15:57 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:NOT_DEFINED */
|
2019-01-31 13:20:20 +00:00
|
|
|
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;
|
|
|
|
|
2021-05-25 13:15:57 +00:00
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
2021-06-08 14:45:41 +00:00
|
|
|
mbedtls_sha512_starts( &ctx, invalid_type ) );
|
2019-01-31 13:20:20 +00:00
|
|
|
|
2021-05-25 13:15:57 +00:00
|
|
|
TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
|
2021-06-08 14:45:41 +00:00
|
|
|
mbedtls_sha512( buf, buflen,
|
2019-01-31 13:20:20 +00:00
|
|
|
buf, invalid_type ) );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-05-19 11:31:59 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA384_C */
|
2020-06-26 12:33:03 +00:00
|
|
|
void sha384( data_t * src_str, data_t * hash )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char output[97];
|
|
|
|
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
|
|
|
|
2021-06-08 14:45:41 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha512( src_str->x, src_str->len, output, 1 ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2020-06-26 12:33:03 +00:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 48, hash->len ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
2020-06-26 12:33:03 +00:00
|
|
|
void mbedtls_sha512( data_t * src_str, data_t * hash )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char output[129];
|
|
|
|
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
|
|
|
|
2021-06-08 14:45:41 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha512( src_str->x, src_str->len, output, 0 ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2020-06-26 12:33:03 +00:00
|
|
|
TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x, 64, hash->len ) == 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-07-05 11:30:16 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
|
2017-05-30 13:23:15 +00:00
|
|
|
void sha1_selftest( )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
2016-09-09 08:10:28 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
|
2009-07-05 11:30:16 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-07-05 11:30:16 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
|
2017-05-30 13:23:15 +00:00
|
|
|
void sha256_selftest( )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
2016-09-09 08:10:28 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
|
2009-07-05 11:30:16 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-07-05 11:30:16 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
|
2017-05-30 13:23:15 +00:00
|
|
|
void sha512_selftest( )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
2016-09-09 08:10:28 +00:00
|
|
|
TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
|
2009-07-05 11:30:16 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|