123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- BEGIN_HEADER
- #include <polarssl/sha1.h>
- #include <polarssl/sha2.h>
- #include <polarssl/sha4.h>
- END_HEADER
- BEGIN_CASE
- sha1:hex_src_string: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
- sha224:hex_src_string: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} );
- sha2( 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
- sha256:hex_src_string: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} );
- sha2( 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
- sha384:hex_src_string: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} );
- sha4( 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
- sha512:hex_src_string: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} );
- sha4( 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
- sha1_file:filename: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
- sha224_file:filename:hex_hash_string
- {
- unsigned char hash_str[57];
- unsigned char output[29];
- memset(hash_str, 0x00, 57);
- memset(output, 0x00, 29);
- sha2_file( {filename}, output, 1);
- hexify( hash_str, output, 28 );
- TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
- }
- END_CASE
- BEGIN_CASE
- sha256_file:filename:hex_hash_string
- {
- unsigned char hash_str[65];
- unsigned char output[33];
- memset(hash_str, 0x00, 65);
- memset(output, 0x00, 33);
- sha2_file( {filename}, output, 0);
- hexify( hash_str, output, 32 );
- TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
- }
- END_CASE
- BEGIN_CASE
- sha384_file:filename:hex_hash_string
- {
- unsigned char hash_str[97];
- unsigned char output[49];
- memset(hash_str, 0x00, 97);
- memset(output, 0x00, 49);
- sha4_file( {filename}, output, 1);
- hexify( hash_str, output, 48 );
- TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
- }
- END_CASE
- BEGIN_CASE
- sha512_file:filename:hex_hash_string
- {
- unsigned char hash_str[129];
- unsigned char output[65];
- memset(hash_str, 0x00, 129);
- memset(output, 0x00, 65);
- sha4_file( {filename}, output, 0);
- hexify( hash_str, output, 64 );
- TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
- }
- END_CASE
- BEGIN_CASE
- sha1_selftest:
- {
- TEST_ASSERT( sha1_self_test( 0 ) == 0 );
- }
- END_CASE
- BEGIN_CASE
- sha2_selftest:
- {
- TEST_ASSERT( sha2_self_test( 0 ) == 0 );
- }
- END_CASE
- BEGIN_CASE
- sha4_selftest:
- {
- TEST_ASSERT( sha4_self_test( 0 ) == 0 );
- }
- END_CASE
|