Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 2 | #include <polarssl/md2.h> |
| 3 | #include <polarssl/md4.h> |
| 4 | #include <polarssl/md5.h> |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame^] | 5 | #include <polarssl/rmd160.h> |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 6 | /* END_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 7 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 8 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C */ |
| 9 | void md2_text( char *text_src_string, char *hex_hash_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 19 | strcpy( (char *) src_str, text_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 20 | |
| 21 | md2( src_str, strlen( (char *) src_str ), output ); |
| 22 | hexify( hash_str, output, 16 ); |
| 23 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 24 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 25 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 26 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 27 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 28 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C */ |
| 29 | void md4_text( char *text_src_string, char *hex_hash_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 39 | strcpy( (char *) src_str, text_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 40 | |
| 41 | md4( src_str, strlen( (char *) src_str ), output ); |
| 42 | hexify( hash_str, output, 16 ); |
| 43 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 44 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 45 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 46 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 47 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 48 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C */ |
| 49 | void md5_text( char *text_src_string, char *hex_hash_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 59 | strcpy( (char *) src_str, text_src_string ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 60 | |
| 61 | md5( src_str, strlen( (char *) src_str ), output ); |
| 62 | hexify( hash_str, output, 16 ); |
| 63 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 64 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 65 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 66 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame^] | 68 | /* BEGIN_CASE depends_on:POLARSSL_RMD160_C */ |
| 69 | void rmd160_text( char *text_src_string, char *hex_hash_string ) |
| 70 | { |
| 71 | unsigned char src_str[1000]; |
| 72 | unsigned char hash_str[41]; |
| 73 | unsigned char output[20]; |
| 74 | |
| 75 | memset(src_str, 0x00, sizeof src_str); |
| 76 | memset(hash_str, 0x00, sizeof hash_str); |
| 77 | memset(output, 0x00, sizeof output); |
| 78 | |
| 79 | strcpy( (char *) src_str, text_src_string ); |
| 80 | |
| 81 | rmd160( src_str, strlen( (char *) src_str ), output ); |
| 82 | hexify( hash_str, output, sizeof output ); |
| 83 | |
| 84 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| 85 | } |
| 86 | /* END_CASE */ |
| 87 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 88 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C */ |
| 89 | void md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 90 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 91 | { |
| 92 | unsigned char src_str[10000]; |
| 93 | unsigned char key_str[10000]; |
| 94 | unsigned char hash_str[10000]; |
| 95 | unsigned char output[33]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 96 | int key_len, src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 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 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 103 | key_len = unhexify( key_str, hex_key_string ); |
| 104 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 105 | |
| 106 | md2_hmac( key_str, key_len, src_str, src_len, output ); |
| 107 | hexify( hash_str, output, 16 ); |
| 108 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 109 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 110 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 111 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 112 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 113 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C */ |
| 114 | void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 115 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 116 | { |
| 117 | unsigned char src_str[10000]; |
| 118 | unsigned char key_str[10000]; |
| 119 | unsigned char hash_str[10000]; |
| 120 | unsigned char output[33]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 121 | int key_len, src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 122 | |
| 123 | memset(src_str, 0x00, 10000); |
| 124 | memset(key_str, 0x00, 10000); |
| 125 | memset(hash_str, 0x00, 10000); |
| 126 | memset(output, 0x00, 33); |
| 127 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 128 | key_len = unhexify( key_str, hex_key_string ); |
| 129 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 130 | |
| 131 | md4_hmac( key_str, key_len, src_str, src_len, output ); |
| 132 | hexify( hash_str, output, 16 ); |
| 133 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 134 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 135 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 136 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 137 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 138 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C */ |
| 139 | void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 140 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 141 | { |
| 142 | unsigned char src_str[10000]; |
| 143 | unsigned char key_str[10000]; |
| 144 | unsigned char hash_str[10000]; |
| 145 | unsigned char output[33]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 146 | int key_len, src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 147 | |
| 148 | memset(src_str, 0x00, 10000); |
| 149 | memset(key_str, 0x00, 10000); |
| 150 | memset(hash_str, 0x00, 10000); |
| 151 | memset(output, 0x00, 33); |
| 152 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 153 | key_len = unhexify( key_str, hex_key_string ); |
| 154 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 155 | |
| 156 | md5_hmac( key_str, key_len, src_str, src_len, output ); |
| 157 | hexify( hash_str, output, 16 ); |
| 158 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 159 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 160 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 161 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 162 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 163 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 164 | void md2_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 165 | { |
| 166 | unsigned char hash_str[65]; |
| 167 | unsigned char output[33]; |
| 168 | |
| 169 | memset(hash_str, 0x00, 65); |
| 170 | memset(output, 0x00, 33); |
| 171 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 172 | md2_file( filename, output); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 173 | hexify( hash_str, output, 16 ); |
| 174 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 175 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 176 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 177 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 178 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 179 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 180 | void md4_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 181 | { |
| 182 | unsigned char hash_str[65]; |
| 183 | unsigned char output[33]; |
| 184 | |
| 185 | memset(hash_str, 0x00, 65); |
| 186 | memset(output, 0x00, 33); |
| 187 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 188 | md4_file( filename, output); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 189 | hexify( hash_str, output, 16 ); |
| 190 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 191 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 192 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 193 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 194 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 195 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 196 | void md5_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 197 | { |
| 198 | unsigned char hash_str[65]; |
| 199 | unsigned char output[33]; |
| 200 | |
| 201 | memset(hash_str, 0x00, 65); |
| 202 | memset(output, 0x00, 33); |
| 203 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 204 | md5_file( filename, output); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 205 | hexify( hash_str, output, 16 ); |
| 206 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 207 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 208 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 209 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 210 | |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame^] | 211 | /* BEGIN_CASE depends_on:POLARSSL_RMD160_C:POLARSSL_FS_IO */ |
| 212 | void rmd160_file( char *filename, char *hex_hash_string ) |
| 213 | { |
| 214 | unsigned char hash_str[41]; |
| 215 | unsigned char output[20]; |
| 216 | |
| 217 | memset(hash_str, 0x00, sizeof hash_str ); |
| 218 | memset(output, 0x00, sizeof output ); |
| 219 | |
| 220 | rmd160_file( filename, output); |
| 221 | hexify( hash_str, output, 20 ); |
| 222 | |
| 223 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| 224 | } |
| 225 | /* END_CASE */ |
| 226 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 227 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 228 | void md2_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 229 | { |
| 230 | TEST_ASSERT( md2_self_test( 0 ) == 0 ); |
| 231 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 232 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 233 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 234 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 235 | void md4_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 236 | { |
| 237 | TEST_ASSERT( md4_self_test( 0 ) == 0 ); |
| 238 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 239 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 240 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 241 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 242 | void md5_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 243 | { |
| 244 | TEST_ASSERT( md5_self_test( 0 ) == 0 ); |
| 245 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 246 | /* END_CASE */ |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame^] | 247 | |
| 248 | /* BEGIN_CASE depends_on:POLARSSL_RMD160_C:POLARSSL_SELF_TEST */ |
| 249 | void rmd160_selftest() |
| 250 | { |
| 251 | TEST_ASSERT( rmd160_self_test( 0 ) == 0 ); |
| 252 | } |
| 253 | /* END_CASE */ |