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]; |
| 74 | |
| 75 | memset(src_str, 0x00, 10000); |
| 76 | memset(key_str, 0x00, 10000); |
| 77 | memset(hash_str, 0x00, 10000); |
| 78 | memset(output, 0x00, 33); |
| 79 | |
| 80 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 81 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 82 | |
| 83 | md2_hmac( key_str, key_len, src_str, src_len, output ); |
| 84 | hexify( hash_str, output, 16 ); |
| 85 | |
| 86 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 87 | } |
| 88 | END_CASE |
| 89 | |
| 90 | BEGIN_CASE |
| 91 | md4_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 92 | { |
| 93 | unsigned char src_str[10000]; |
| 94 | unsigned char key_str[10000]; |
| 95 | unsigned char hash_str[10000]; |
| 96 | unsigned char output[33]; |
| 97 | |
| 98 | memset(src_str, 0x00, 10000); |
| 99 | memset(key_str, 0x00, 10000); |
| 100 | memset(hash_str, 0x00, 10000); |
| 101 | memset(output, 0x00, 33); |
| 102 | |
| 103 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 104 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 105 | |
| 106 | md4_hmac( key_str, key_len, src_str, src_len, output ); |
| 107 | hexify( hash_str, output, 16 ); |
| 108 | |
| 109 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 110 | } |
| 111 | END_CASE |
| 112 | |
| 113 | BEGIN_CASE |
| 114 | md5_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string |
| 115 | { |
| 116 | unsigned char src_str[10000]; |
| 117 | unsigned char key_str[10000]; |
| 118 | unsigned char hash_str[10000]; |
| 119 | unsigned char output[33]; |
| 120 | |
| 121 | memset(src_str, 0x00, 10000); |
| 122 | memset(key_str, 0x00, 10000); |
| 123 | memset(hash_str, 0x00, 10000); |
| 124 | memset(output, 0x00, 33); |
| 125 | |
| 126 | int key_len = unhexify( key_str, {hex_key_string} ); |
| 127 | int src_len = unhexify( src_str, {hex_src_string} ); |
| 128 | |
| 129 | md5_hmac( key_str, key_len, src_str, src_len, output ); |
| 130 | hexify( hash_str, output, 16 ); |
| 131 | |
| 132 | TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 ); |
| 133 | } |
| 134 | END_CASE |
| 135 | |
| 136 | BEGIN_CASE |
| 137 | md2_file:filename:hex_hash_string |
| 138 | { |
| 139 | unsigned char hash_str[65]; |
| 140 | unsigned char output[33]; |
| 141 | |
| 142 | memset(hash_str, 0x00, 65); |
| 143 | memset(output, 0x00, 33); |
| 144 | |
| 145 | md2_file( {filename}, output); |
| 146 | hexify( hash_str, output, 16 ); |
| 147 | |
| 148 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 149 | } |
| 150 | END_CASE |
| 151 | |
| 152 | BEGIN_CASE |
| 153 | md4_file:filename:hex_hash_string |
| 154 | { |
| 155 | unsigned char hash_str[65]; |
| 156 | unsigned char output[33]; |
| 157 | |
| 158 | memset(hash_str, 0x00, 65); |
| 159 | memset(output, 0x00, 33); |
| 160 | |
| 161 | md4_file( {filename}, output); |
| 162 | hexify( hash_str, output, 16 ); |
| 163 | |
| 164 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 165 | } |
| 166 | END_CASE |
| 167 | |
| 168 | BEGIN_CASE |
| 169 | md5_file:filename:hex_hash_string |
| 170 | { |
| 171 | unsigned char hash_str[65]; |
| 172 | unsigned char output[33]; |
| 173 | |
| 174 | memset(hash_str, 0x00, 65); |
| 175 | memset(output, 0x00, 33); |
| 176 | |
| 177 | md5_file( {filename}, output); |
| 178 | hexify( hash_str, output, 16 ); |
| 179 | |
| 180 | TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 ); |
| 181 | } |
| 182 | END_CASE |
| 183 | |
| 184 | BEGIN_CASE |
| 185 | md2_selftest: |
| 186 | { |
| 187 | TEST_ASSERT( md2_self_test( 0 ) == 0 ); |
| 188 | } |
| 189 | END_CASE |
| 190 | |
| 191 | BEGIN_CASE |
| 192 | md4_selftest: |
| 193 | { |
| 194 | TEST_ASSERT( md4_self_test( 0 ) == 0 ); |
| 195 | } |
| 196 | END_CASE |
| 197 | |
| 198 | BEGIN_CASE |
| 199 | md5_selftest: |
| 200 | { |
| 201 | TEST_ASSERT( md5_self_test( 0 ) == 0 ); |
| 202 | } |
| 203 | END_CASE |