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
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
2017-05-30 15:23:15 +02:00
|
|
|
void mbedtls_sha1( uint8_t * src_str, uint32_t src_len,
|
|
|
|
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[41];
|
|
|
|
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
|
|
|
|
2018-01-22 11:48:08 +01:00
|
|
|
TEST_ASSERT( mbedtls_sha1_ret( src_str, src_len, output ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-05-30 15:23:15 +02:00
|
|
|
TEST_ASSERT( hexcmp( output, hex_hash_string, 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
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
2017-05-30 15:23:15 +02:00
|
|
|
void sha224( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string,
|
|
|
|
uint32_t hex_hash_string_len )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[57];
|
|
|
|
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
|
|
|
|
2018-01-22 11:48:08 +01:00
|
|
|
TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 1 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-05-30 15:23:15 +02:00
|
|
|
TEST_ASSERT( hexcmp( output, hex_hash_string, 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 */
|
2017-05-30 15:23:15 +02:00
|
|
|
void mbedtls_sha256( uint8_t * src_str, uint32_t src_len,
|
|
|
|
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[65];
|
|
|
|
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
|
|
|
|
2018-01-22 11:48:08 +01:00
|
|
|
TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 0 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-05-30 15:23:15 +02:00
|
|
|
TEST_ASSERT( hexcmp( output, hex_hash_string, 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
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
2017-05-30 15:23:15 +02:00
|
|
|
void sha384( uint8_t * src_str, uint32_t src_len, uint8_t * hex_hash_string,
|
|
|
|
uint32_t hex_hash_string_len )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[97];
|
|
|
|
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
|
|
|
|
2018-01-22 11:48:08 +01:00
|
|
|
TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 1 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-05-30 15:23:15 +02:00
|
|
|
TEST_ASSERT( hexcmp( output, hex_hash_string, 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 */
|
2017-05-30 15:23:15 +02:00
|
|
|
void mbedtls_sha512( uint8_t * src_str, uint32_t src_len,
|
|
|
|
uint8_t * hex_hash_string, uint32_t hex_hash_string_len )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char output[129];
|
|
|
|
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
|
|
|
|
2018-01-22 11:48:08 +01:00
|
|
|
TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 0 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-05-30 15:23:15 +02:00
|
|
|
TEST_ASSERT( hexcmp( output, hex_hash_string, 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 */
|