| /* BEGIN_HEADER */ |
| #include <polarssl/sha1.h> |
| #include <polarssl/sha256.h> |
| #include <polarssl/sha512.h> |
| /* END_HEADER */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA1_C */ |
| void sha1( char *hex_src_string, char *hex_hash_string ) |
| { |
| unsigned char src_str[10000]; |
| unsigned char hash_str[10000]; |
| unsigned char output[41]; |
| int src_len; |
| |
| memset(src_str, 0x00, 10000); |
| memset(hash_str, 0x00, 10000); |
| memset(output, 0x00, 41); |
| |
| src_len = unhexify( src_str, hex_src_string ); |
| |
| sha1( src_str, src_len, output ); |
| hexify( hash_str, output, 20 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA256_C */ |
| void sha224(char *hex_src_string, char *hex_hash_string ) |
| { |
| unsigned char src_str[10000]; |
| unsigned char hash_str[10000]; |
| unsigned char output[57]; |
| int src_len; |
| |
| memset(src_str, 0x00, 10000); |
| memset(hash_str, 0x00, 10000); |
| memset(output, 0x00, 57); |
| |
| src_len = unhexify( src_str, hex_src_string ); |
| |
| sha256( src_str, src_len, output, 1 ); |
| hexify( hash_str, output, 28 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA256_C */ |
| void sha256(char *hex_src_string, char *hex_hash_string ) |
| { |
| unsigned char src_str[10000]; |
| unsigned char hash_str[10000]; |
| unsigned char output[65]; |
| int src_len; |
| |
| memset(src_str, 0x00, 10000); |
| memset(hash_str, 0x00, 10000); |
| memset(output, 0x00, 65); |
| |
| src_len = unhexify( src_str, hex_src_string ); |
| |
| sha256( src_str, src_len, output, 0 ); |
| hexify( hash_str, output, 32 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA512_C */ |
| void sha384(char *hex_src_string, char *hex_hash_string ) |
| { |
| unsigned char src_str[10000]; |
| unsigned char hash_str[10000]; |
| unsigned char output[97]; |
| int src_len; |
| |
| memset(src_str, 0x00, 10000); |
| memset(hash_str, 0x00, 10000); |
| memset(output, 0x00, 97); |
| |
| src_len = unhexify( src_str, hex_src_string ); |
| |
| sha512( src_str, src_len, output, 1 ); |
| hexify( hash_str, output, 48 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA512_C */ |
| void sha512(char *hex_src_string, char *hex_hash_string ) |
| { |
| unsigned char src_str[10000]; |
| unsigned char hash_str[10000]; |
| unsigned char output[129]; |
| int src_len; |
| |
| memset(src_str, 0x00, 10000); |
| memset(hash_str, 0x00, 10000); |
| memset(output, 0x00, 129); |
| |
| src_len = unhexify( src_str, hex_src_string ); |
| |
| sha512( src_str, src_len, output, 0); |
| hexify( hash_str, output, 64 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA1_C:POLARSSL_FS_IO */ |
| void sha1_file( char *filename, char *hex_hash_string ) |
| { |
| unsigned char hash_str[41]; |
| unsigned char output[21]; |
| |
| memset(hash_str, 0x00, 41); |
| memset(output, 0x00, 21); |
| |
| sha1_file( filename, output); |
| hexify( hash_str, output, 20 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA256_C:POLARSSL_FS_IO */ |
| void sha224_file( char *filename, char *hex_hash_string ) |
| { |
| unsigned char hash_str[57]; |
| unsigned char output[29]; |
| |
| memset(hash_str, 0x00, 57); |
| memset(output, 0x00, 29); |
| |
| sha256_file( filename, output, 1); |
| hexify( hash_str, output, 28 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA256_C:POLARSSL_FS_IO */ |
| void sha256_file( char *filename, char *hex_hash_string ) |
| { |
| unsigned char hash_str[65]; |
| unsigned char output[33]; |
| |
| memset(hash_str, 0x00, 65); |
| memset(output, 0x00, 33); |
| |
| sha256_file( filename, output, 0); |
| hexify( hash_str, output, 32 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA512_C:POLARSSL_FS_IO */ |
| void sha384_file( char *filename, char *hex_hash_string ) |
| { |
| unsigned char hash_str[97]; |
| unsigned char output[49]; |
| |
| memset(hash_str, 0x00, 97); |
| memset(output, 0x00, 49); |
| |
| sha512_file( filename, output, 1); |
| hexify( hash_str, output, 48 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA512_C:POLARSSL_FS_IO */ |
| void sha512_file( char *filename, char *hex_hash_string ) |
| { |
| unsigned char hash_str[129]; |
| unsigned char output[65]; |
| |
| memset(hash_str, 0x00, 129); |
| memset(output, 0x00, 65); |
| |
| sha512_file( filename, output, 0); |
| hexify( hash_str, output, 64 ); |
| |
| TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA1_C:POLARSSL_SELF_TEST */ |
| void sha1_selftest() |
| { |
| TEST_ASSERT( sha1_self_test( 0 ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA256_C:POLARSSL_SELF_TEST */ |
| void sha256_selftest() |
| { |
| TEST_ASSERT( sha256_self_test( 0 ) == 0 ); |
| } |
| /* END_CASE */ |
| |
| /* BEGIN_CASE depends_on:POLARSSL_SHA512_C:POLARSSL_SELF_TEST */ |
| void sha512_selftest() |
| { |
| TEST_ASSERT( sha512_self_test( 0 ) == 0 ); |
| } |
| /* END_CASE */ |