2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_HEADER */
|
2009-06-28 21:50:27 +00:00
|
|
|
#include <polarssl/sha1.h>
|
2013-06-30 12:49:12 +00:00
|
|
|
#include <polarssl/sha256.h>
|
|
|
|
#include <polarssl/sha512.h>
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_HEADER */
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2013-08-20 10:42:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA1_C */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha1( char *hex_src_string, char *hex_hash_string )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[41];
|
2009-07-11 19:15:20 +00:00
|
|
|
int src_len;
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
sha1( src_str, src_len, output );
|
|
|
|
hexify( hash_str, output, 20 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-08-20 10:42:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha224(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[57];
|
2009-07-11 19:15:20 +00:00
|
|
|
int src_len;
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2013-06-30 12:34:05 +00:00
|
|
|
sha256( src_str, src_len, output, 1 );
|
2009-06-28 21:50:27 +00:00
|
|
|
hexify( hash_str, output, 28 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-08-20 10:42:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha256(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[65];
|
2009-07-11 19:15:20 +00:00
|
|
|
int src_len;
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2013-06-30 12:34:05 +00:00
|
|
|
sha256( src_str, src_len, output, 0 );
|
2009-06-28 21:50:27 +00:00
|
|
|
hexify( hash_str, output, 32 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-08-20 10:42:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha384(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[97];
|
2009-07-11 19:15:20 +00:00
|
|
|
int src_len;
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2013-06-30 12:34:05 +00:00
|
|
|
sha512( src_str, src_len, output, 1 );
|
2009-06-28 21:50:27 +00:00
|
|
|
hexify( hash_str, output, 48 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-08-20 10:42:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha512(char *hex_src_string, char *hex_hash_string )
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[129];
|
2009-07-11 19:15:20 +00:00
|
|
|
int src_len;
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2013-06-30 12:34:05 +00:00
|
|
|
sha512( src_str, src_len, output, 0);
|
2009-06-28 21:50:27 +00:00
|
|
|
hexify( hash_str, output, 64 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-09-15 13:20:37 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA1_C:POLARSSL_FS_IO */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha1_file( char *filename, char *hex_hash_string )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
|
|
|
unsigned char hash_str[41];
|
|
|
|
unsigned char output[21];
|
|
|
|
|
|
|
|
memset(hash_str, 0x00, 41);
|
|
|
|
memset(output, 0x00, 21);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
sha1_file( filename, output);
|
2009-07-05 11:30:16 +00:00
|
|
|
hexify( hash_str, output, 20 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-09-15 13:20:37 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C:POLARSSL_FS_IO */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha224_file( char *filename, char *hex_hash_string )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
|
|
|
unsigned char hash_str[57];
|
|
|
|
unsigned char output[29];
|
|
|
|
|
|
|
|
memset(hash_str, 0x00, 57);
|
|
|
|
memset(output, 0x00, 29);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
sha256_file( filename, output, 1);
|
2009-07-05 11:30:16 +00:00
|
|
|
hexify( hash_str, output, 28 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-09-15 13:20:37 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C:POLARSSL_FS_IO */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha256_file( char *filename, char *hex_hash_string )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
|
|
|
unsigned char hash_str[65];
|
|
|
|
unsigned char output[33];
|
|
|
|
|
|
|
|
memset(hash_str, 0x00, 65);
|
|
|
|
memset(output, 0x00, 33);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
sha256_file( filename, output, 0);
|
2009-07-05 11:30:16 +00:00
|
|
|
hexify( hash_str, output, 32 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-09-15 13:20:37 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C:POLARSSL_FS_IO */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha384_file( char *filename, char *hex_hash_string )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
|
|
|
unsigned char hash_str[97];
|
|
|
|
unsigned char output[49];
|
|
|
|
|
|
|
|
memset(hash_str, 0x00, 97);
|
|
|
|
memset(output, 0x00, 49);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
sha512_file( filename, output, 1);
|
2009-07-05 11:30:16 +00:00
|
|
|
hexify( hash_str, output, 48 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-09-15 13:20:37 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C:POLARSSL_FS_IO */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha512_file( char *filename, char *hex_hash_string )
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
|
|
|
unsigned char hash_str[129];
|
|
|
|
unsigned char output[65];
|
|
|
|
|
|
|
|
memset(hash_str, 0x00, 129);
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
sha512_file( filename, output, 0);
|
2009-07-05 11:30:16 +00:00
|
|
|
hexify( hash_str, output, 64 );
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 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
|
|
|
|
2013-10-10 10:48:03 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA1_C:POLARSSL_SELF_TEST */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha1_selftest()
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
|
|
|
TEST_ASSERT( sha1_self_test( 0 ) == 0 );
|
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2009-07-05 11:30:16 +00:00
|
|
|
|
2013-10-10 10:48:03 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C:POLARSSL_SELF_TEST */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha256_selftest()
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
2013-06-30 12:34:05 +00:00
|
|
|
TEST_ASSERT( sha256_self_test( 0 ) == 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
|
|
|
|
2013-10-10 10:48:03 +00:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C:POLARSSL_SELF_TEST */
|
2013-08-20 09:48:36 +00:00
|
|
|
void sha512_selftest()
|
2009-07-05 11:30:16 +00:00
|
|
|
{
|
2013-06-30 12:34:05 +00:00
|
|
|
TEST_ASSERT( sha512_self_test( 0 ) == 0 );
|
2009-07-05 11:30:16 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|