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