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_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 9 | { |
| 10 | unsigned char src_str[10000]; |
| 11 | unsigned char key_str[10000]; |
| 12 | unsigned char hash_str[10000]; |
| 13 | unsigned char output[41]; |
| 14 | |
| 15 | memset(src_str, 0x00, 10000); |
| 16 | memset(key_str, 0x00, 10000); |
| 17 | memset(hash_str, 0x00, 10000); |
| 18 | memset(output, 0x00, 41); |
| 19 | |
| 20 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 21 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 22 | |
| 23 | sha1_hmac( key_str, key_len, src_str, src_len, output ); |
| 24 | hexify( hash_str, output, 20 ); |
| 25 | |
| 26 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 27 | } |
| 28 | END_CASE |
| 29 | |
| 30 | BEGIN_CASE |
| 31 | sha224_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 32 | { |
| 33 | unsigned char src_str[10000]; |
| 34 | unsigned char key_str[10000]; |
| 35 | unsigned char hash_str[10000]; |
| 36 | unsigned char output[57]; |
| 37 | |
| 38 | memset(src_str, 0x00, 10000); |
| 39 | memset(key_str, 0x00, 10000); |
| 40 | memset(hash_str, 0x00, 10000); |
| 41 | memset(output, 0x00, 57); |
| 42 | |
| 43 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 44 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 45 | |
| 46 | sha2_hmac( key_str, key_len, src_str, src_len, output, 1 ); |
| 47 | hexify( hash_str, output, 28 ); |
| 48 | |
| 49 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 50 | } |
| 51 | END_CASE |
| 52 | |
| 53 | BEGIN_CASE |
| 54 | sha256_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 55 | { |
| 56 | unsigned char src_str[10000]; |
| 57 | unsigned char key_str[10000]; |
| 58 | unsigned char hash_str[10000]; |
| 59 | unsigned char output[65]; |
| 60 | |
| 61 | memset(src_str, 0x00, 10000); |
| 62 | memset(key_str, 0x00, 10000); |
| 63 | memset(hash_str, 0x00, 10000); |
| 64 | memset(output, 0x00, 65); |
| 65 | |
| 66 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 67 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 68 | |
| 69 | sha2_hmac( key_str, key_len, src_str, src_len, output, 0 ); |
| 70 | hexify( hash_str, output, 32 ); |
| 71 | |
| 72 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 73 | } |
| 74 | END_CASE |
| 75 | |
| 76 | BEGIN_CASE |
| 77 | sha384_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 78 | { |
| 79 | unsigned char src_str[10000]; |
| 80 | unsigned char key_str[10000]; |
| 81 | unsigned char hash_str[10000]; |
| 82 | unsigned char output[97]; |
| 83 | |
| 84 | memset(src_str, 0x00, 10000); |
| 85 | memset(key_str, 0x00, 10000); |
| 86 | memset(hash_str, 0x00, 10000); |
| 87 | memset(output, 0x00, 97); |
| 88 | |
| 89 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 90 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 91 | |
| 92 | sha4_hmac( key_str, key_len, src_str, src_len, output, 1 ); |
| 93 | hexify( hash_str, output, 48 ); |
| 94 | |
| 95 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 96 | } |
| 97 | END_CASE |
| 98 | |
| 99 | BEGIN_CASE |
| 100 | sha512_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 101 | { |
| 102 | unsigned char src_str[10000]; |
| 103 | unsigned char key_str[10000]; |
| 104 | unsigned char hash_str[10000]; |
| 105 | unsigned char output[129]; |
| 106 | |
| 107 | memset(src_str, 0x00, 10000); |
| 108 | memset(key_str, 0x00, 10000); |
| 109 | memset(hash_str, 0x00, 10000); |
| 110 | memset(output, 0x00, 129); |
| 111 | |
| 112 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 113 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 114 | |
| 115 | sha4_hmac( key_str, key_len, src_str, src_len, output, 0 ); |
| 116 | hexify( hash_str, output, 64 ); |
| 117 | |
| 118 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 119 | } |
| 120 | END_CASE |