Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame^] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/sha1.h> |
| 3 | #include <polarssl/sha2.h> |
| 4 | #include <polarssl/sha4.h> |
| 5 | END_HEADER |
| 6 | |
| 7 | BEGIN_CASE |
| 8 | sha1:hex_src_string:hex_hash_string |
| 9 | { |
| 10 | unsigned char src_str[10000]; |
| 11 | unsigned char hash_str[10000]; |
| 12 | unsigned char output[41]; |
| 13 | |
| 14 | memset(src_str, 0x00, 10000); |
| 15 | memset(hash_str, 0x00, 10000); |
| 16 | memset(output, 0x00, 41); |
| 17 | |
| 18 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 19 | |
| 20 | sha1( src_str, src_len, output ); |
| 21 | hexify( hash_str, output, 20 ); |
| 22 | |
| 23 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 24 | } |
| 25 | END_CASE |
| 26 | |
| 27 | BEGIN_CASE |
| 28 | sha224:hex_src_string:hex_hash_string |
| 29 | { |
| 30 | unsigned char src_str[10000]; |
| 31 | unsigned char hash_str[10000]; |
| 32 | unsigned char output[57]; |
| 33 | |
| 34 | memset(src_str, 0x00, 10000); |
| 35 | memset(hash_str, 0x00, 10000); |
| 36 | memset(output, 0x00, 57); |
| 37 | |
| 38 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 39 | |
| 40 | sha2( src_str, src_len, output, 1 ); |
| 41 | hexify( hash_str, output, 28 ); |
| 42 | |
| 43 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 44 | } |
| 45 | END_CASE |
| 46 | |
| 47 | BEGIN_CASE |
| 48 | sha256:hex_src_string:hex_hash_string |
| 49 | { |
| 50 | unsigned char src_str[10000]; |
| 51 | unsigned char hash_str[10000]; |
| 52 | unsigned char output[65]; |
| 53 | |
| 54 | memset(src_str, 0x00, 10000); |
| 55 | memset(hash_str, 0x00, 10000); |
| 56 | memset(output, 0x00, 65); |
| 57 | |
| 58 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 59 | |
| 60 | sha2( src_str, src_len, output, 0 ); |
| 61 | hexify( hash_str, output, 32 ); |
| 62 | |
| 63 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 64 | } |
| 65 | END_CASE |
| 66 | |
| 67 | BEGIN_CASE |
| 68 | sha384:hex_src_string:hex_hash_string |
| 69 | { |
| 70 | unsigned char src_str[10000]; |
| 71 | unsigned char hash_str[10000]; |
| 72 | unsigned char output[97]; |
| 73 | |
| 74 | memset(src_str, 0x00, 10000); |
| 75 | memset(hash_str, 0x00, 10000); |
| 76 | memset(output, 0x00, 97); |
| 77 | |
| 78 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 79 | |
| 80 | sha4( src_str, src_len, output, 1 ); |
| 81 | hexify( hash_str, output, 48 ); |
| 82 | |
| 83 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 84 | } |
| 85 | END_CASE |
| 86 | |
| 87 | BEGIN_CASE |
| 88 | sha512:hex_src_string:hex_hash_string |
| 89 | { |
| 90 | unsigned char src_str[10000]; |
| 91 | unsigned char hash_str[10000]; |
| 92 | unsigned char output[129]; |
| 93 | |
| 94 | memset(src_str, 0x00, 10000); |
| 95 | memset(hash_str, 0x00, 10000); |
| 96 | memset(output, 0x00, 129); |
| 97 | |
| 98 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 99 | |
| 100 | sha4( src_str, src_len, output, 0); |
| 101 | hexify( hash_str, output, 64 ); |
| 102 | |
| 103 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 104 | } |
| 105 | END_CASE |