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 */
|
|
|
|
void mbedtls_sha1( char *hex_src_string, char *hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[41];
|
2009-07-11 21:15:20 +02:00
|
|
|
int src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-06-28 11:51:17 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha1_ext( src_str, src_len, output ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 20 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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 */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha224(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[57];
|
2009-07-11 21:15:20 +02:00
|
|
|
int src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-06-28 11:51:17 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha256_ext( src_str, src_len, output, 1 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 28 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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 */
|
|
|
|
void mbedtls_sha256(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[65];
|
2009-07-11 21:15:20 +02:00
|
|
|
int src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-06-28 11:51:17 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha256_ext( src_str, src_len, output, 0 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 32 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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 */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha384(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[97];
|
2009-07-11 21:15:20 +02:00
|
|
|
int src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-06-28 11:51:17 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha512_ext( src_str, src_len, output, 1 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 48 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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 */
|
|
|
|
void mbedtls_sha512(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[129];
|
2009-07-11 21:15:20 +02:00
|
|
|
int src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2017-06-28 11:51:17 +02:00
|
|
|
TEST_ASSERT( mbedtls_sha512_ext( src_str, src_len, output, 0 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 64 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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 */
|
2013-08-20 11:48:36 +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 */
|
2013-08-20 11:48:36 +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 */
|
2013-08-20 11:48:36 +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 */
|