Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/md2.h> |
| 3 | #include <polarssl/md4.h> |
| 4 | #include <polarssl/md5.h> |
| 5 | END_HEADER |
| 6 | |
| 7 | BEGIN_CASE |
| 8 | md2_text:text_src_string:hex_hash_string |
| 9 | { |
| 10 | unsigned char src_str[1000]; |
| 11 | unsigned char hash_str[1000]; |
| 12 | unsigned char output[33]; |
| 13 | |
| 14 | memset(src_str, 0x00, 1000); |
| 15 | memset(hash_str, 0x00, 1000); |
| 16 | memset(output, 0x00, 33); |
| 17 | |
| 18 | strcpy( (char *) src_str, {text_src_string} ); |
| 19 | |
| 20 | md2( src_str, strlen( (char *) src_str ), output ); |
| 21 | hexify( hash_str, output, 16 ); |
| 22 | |
| 23 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 24 | } |
| 25 | END_CASE |
| 26 | |
| 27 | BEGIN_CASE |
| 28 | md4_text:text_src_string:hex_hash_string |
| 29 | { |
| 30 | unsigned char src_str[1000]; |
| 31 | unsigned char hash_str[1000]; |
| 32 | unsigned char output[33]; |
| 33 | |
| 34 | memset(src_str, 0x00, 1000); |
| 35 | memset(hash_str, 0x00, 1000); |
| 36 | memset(output, 0x00, 33); |
| 37 | |
| 38 | strcpy( (char *) src_str, {text_src_string} ); |
| 39 | |
| 40 | md4( src_str, strlen( (char *) src_str ), output ); |
| 41 | hexify( hash_str, output, 16 ); |
| 42 | |
| 43 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 44 | } |
| 45 | END_CASE |
| 46 | |
| 47 | BEGIN_CASE |
| 48 | md5_text:text_src_string:hex_hash_string |
| 49 | { |
| 50 | unsigned char src_str[1000]; |
| 51 | unsigned char hash_str[1000]; |
| 52 | unsigned char output[33]; |
| 53 | |
| 54 | memset(src_str, 0x00, 1000); |
| 55 | memset(hash_str, 0x00, 1000); |
| 56 | memset(output, 0x00, 33); |
| 57 | |
| 58 | strcpy( (char *) src_str, {text_src_string} ); |
| 59 | |
| 60 | md5( src_str, strlen( (char *) src_str ), output ); |
| 61 | hexify( hash_str, output, 16 ); |
| 62 | |
| 63 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 64 | } |
| 65 | END_CASE |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 66 | |
| 67 | BEGIN_CASE |
| 68 | md2_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 69 | { |
| 70 | unsigned char src_str[10000]; |
| 71 | unsigned char key_str[10000]; |
| 72 | unsigned char hash_str[10000]; |
| 73 | unsigned char output[33]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 74 | int key_len, src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 75 | |
| 76 | memset(src_str, 0x00, 10000); |
| 77 | memset(key_str, 0x00, 10000); |
| 78 | memset(hash_str, 0x00, 10000); |
| 79 | memset(output, 0x00, 33); |
| 80 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 81 | key_len = unhexify( key_str, {hex_key_string} ); |
| 82 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 83 | |
| 84 | md2_hmac( key_str, key_len, src_str, src_len, output ); |
| 85 | hexify( hash_str, output, 16 ); |
| 86 | |
| 87 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 88 | } |
| 89 | END_CASE |
| 90 | |
| 91 | BEGIN_CASE |
| 92 | md4_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 93 | { |
| 94 | unsigned char src_str[10000]; |
| 95 | unsigned char key_str[10000]; |
| 96 | unsigned char hash_str[10000]; |
| 97 | unsigned char output[33]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 98 | int key_len, src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 99 | |
| 100 | memset(src_str, 0x00, 10000); |
| 101 | memset(key_str, 0x00, 10000); |
| 102 | memset(hash_str, 0x00, 10000); |
| 103 | memset(output, 0x00, 33); |
| 104 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 105 | key_len = unhexify( key_str, {hex_key_string} ); |
| 106 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 107 | |
| 108 | md4_hmac( key_str, key_len, src_str, src_len, output ); |
| 109 | hexify( hash_str, output, 16 ); |
| 110 | |
| 111 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 112 | } |
| 113 | END_CASE |
| 114 | |
| 115 | BEGIN_CASE |
| 116 | md5_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 117 | { |
| 118 | unsigned char src_str[10000]; |
| 119 | unsigned char key_str[10000]; |
| 120 | unsigned char hash_str[10000]; |
| 121 | unsigned char output[33]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 122 | int key_len, src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 123 | |
| 124 | memset(src_str, 0x00, 10000); |
| 125 | memset(key_str, 0x00, 10000); |
| 126 | memset(hash_str, 0x00, 10000); |
| 127 | memset(output, 0x00, 33); |
| 128 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame^] | 129 | key_len = unhexify( key_str, {hex_key_string} ); |
| 130 | src_len = unhexify( src_str, {hex_src_string} ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 131 | |
| 132 | md5_hmac( key_str, key_len, src_str, src_len, output ); |
| 133 | hexify( hash_str, output, 16 ); |
| 134 | |
| 135 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 136 | } |
| 137 | END_CASE |
| 138 | |
| 139 | BEGIN_CASE |
| 140 | md2_file:filename:hex_hash_string |
| 141 | { |
| 142 | unsigned char hash_str[65]; |
| 143 | unsigned char output[33]; |
| 144 | |
| 145 | memset(hash_str, 0x00, 65); |
| 146 | memset(output, 0x00, 33); |
| 147 | |
| 148 | md2_file( {filename}, output); |
| 149 | hexify( hash_str, output, 16 ); |
| 150 | |
| 151 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 152 | } |
| 153 | END_CASE |
| 154 | |
| 155 | BEGIN_CASE |
| 156 | md4_file:filename:hex_hash_string |
| 157 | { |
| 158 | unsigned char hash_str[65]; |
| 159 | unsigned char output[33]; |
| 160 | |
| 161 | memset(hash_str, 0x00, 65); |
| 162 | memset(output, 0x00, 33); |
| 163 | |
| 164 | md4_file( {filename}, output); |
| 165 | hexify( hash_str, output, 16 ); |
| 166 | |
| 167 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 168 | } |
| 169 | END_CASE |
| 170 | |
| 171 | BEGIN_CASE |
| 172 | md5_file:filename:hex_hash_string |
| 173 | { |
| 174 | unsigned char hash_str[65]; |
| 175 | unsigned char output[33]; |
| 176 | |
| 177 | memset(hash_str, 0x00, 65); |
| 178 | memset(output, 0x00, 33); |
| 179 | |
| 180 | md5_file( {filename}, output); |
| 181 | hexify( hash_str, output, 16 ); |
| 182 | |
| 183 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 184 | } |
| 185 | END_CASE |
| 186 | |
| 187 | BEGIN_CASE |
| 188 | md2_selftest: |
| 189 | { |
| 190 | TEST_ASSERT( md2_self_test( 0 ) == 0 ); |
| 191 | } |
| 192 | END_CASE |
| 193 | |
| 194 | BEGIN_CASE |
| 195 | md4_selftest: |
| 196 | { |
| 197 | TEST_ASSERT( md4_self_test( 0 ) == 0 ); |
| 198 | } |
| 199 | END_CASE |
| 200 | |
| 201 | BEGIN_CASE |
| 202 | md5_selftest: |
| 203 | { |
| 204 | TEST_ASSERT( md5_self_test( 0 ) == 0 ); |
| 205 | } |
| 206 | END_CASE |