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> |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 5 | #include <polarssl/ripemd160.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 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 11 | unsigned char src_str[100]; |
| 12 | unsigned char hash_str[33]; |
| 13 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 14 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 15 | memset( src_str, 0x00, sizeof src_str ); |
| 16 | memset( hash_str, 0x00, sizeof hash_str ); |
| 17 | memset( output, 0x00, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 ); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 22 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 31 | unsigned char src_str[100]; |
| 32 | unsigned char hash_str[33]; |
| 33 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 34 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 35 | memset( src_str, 0x00, sizeof src_str ); |
| 36 | memset( hash_str, 0x00, sizeof hash_str ); |
| 37 | memset( output, 0x00, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 ); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 42 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 51 | unsigned char src_str[100]; |
| 52 | unsigned char hash_str[33]; |
| 53 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 55 | memset( src_str, 0x00, sizeof src_str ); |
| 56 | memset( hash_str, 0x00, sizeof hash_str ); |
| 57 | memset( output, 0x00, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 ); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 62 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 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 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 68 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C */ |
| 69 | void ripemd160_text( char *text_src_string, char *hex_hash_string ) |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 70 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 71 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 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 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 81 | ripemd160( src_str, strlen( (char *) src_str ), output ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 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 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 92 | unsigned char src_str[200]; |
| 93 | unsigned char key_str[200]; |
| 94 | unsigned char hash_str[33]; |
| 95 | unsigned char output[16]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 96 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 97 | md2_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 98 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 99 | memset( src_str, 0x00, sizeof src_str ); |
| 100 | memset( key_str, 0x00, sizeof key_str ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 101 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 102 | key_len = unhexify( key_str, hex_key_string ); |
| 103 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 104 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 105 | /* Test the all-in-one interface */ |
| 106 | memset( hash_str, 0x00, sizeof hash_str ); |
| 107 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 108 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 109 | md2_hmac( key_str, key_len, src_str, src_len, output ); |
| 110 | |
| 111 | hexify( hash_str, output, sizeof output ); |
| 112 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 113 | |
| 114 | /* Also test the "streaming" interface */ |
| 115 | memset( hash_str, 0x00, sizeof hash_str ); |
| 116 | memset( output, 0x00, sizeof output ); |
| 117 | memset( &ctx, 0x00, sizeof ctx ); |
| 118 | |
| 119 | md2_hmac_starts( &ctx, key_str, key_len ); |
| 120 | md2_hmac_update( &ctx, src_str, 0 ); |
| 121 | md2_hmac_update( &ctx, src_str, src_len / 2 ); |
| 122 | md2_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 123 | md2_hmac_update( &ctx, src_str + src_len, 0 ); |
| 124 | md2_hmac_finish( &ctx, output ); |
| 125 | |
| 126 | hexify( hash_str, output, sizeof output ); |
| 127 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 128 | |
| 129 | /* Again, to test hmac_reset() */ |
| 130 | memset( hash_str, 0x00, sizeof hash_str ); |
| 131 | memset( output, 0x00, sizeof output ); |
| 132 | |
| 133 | md2_hmac_reset( &ctx ); |
| 134 | md2_hmac_update( &ctx, src_str, src_len / 2 ); |
| 135 | md2_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 136 | md2_hmac_finish( &ctx, output ); |
| 137 | |
| 138 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 139 | 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] | 140 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 141 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 142 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 143 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C */ |
| 144 | void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 145 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 146 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 147 | unsigned char src_str[200]; |
| 148 | unsigned char key_str[200]; |
| 149 | unsigned char hash_str[33]; |
| 150 | unsigned char output[16]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 151 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 152 | md4_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 153 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 154 | memset( src_str, 0x00, sizeof src_str ); |
| 155 | memset( key_str, 0x00, sizeof key_str ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 156 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 157 | key_len = unhexify( key_str, hex_key_string ); |
| 158 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 159 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 160 | /* Test the all-in-one interface */ |
| 161 | memset( hash_str, 0x00, sizeof hash_str ); |
| 162 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 163 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 164 | md4_hmac( key_str, key_len, src_str, src_len, output ); |
| 165 | |
| 166 | hexify( hash_str, output, sizeof output ); |
| 167 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 168 | |
| 169 | /* Also test the "streaming" interface */ |
| 170 | memset( hash_str, 0x00, sizeof hash_str ); |
| 171 | memset( output, 0x00, sizeof output ); |
| 172 | memset( &ctx, 0x00, sizeof ctx ); |
| 173 | |
| 174 | md4_hmac_starts( &ctx, key_str, key_len ); |
| 175 | md4_hmac_update( &ctx, src_str, 0 ); |
| 176 | md4_hmac_update( &ctx, src_str, src_len / 2 ); |
| 177 | md4_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 178 | md4_hmac_update( &ctx, src_str + src_len, 0 ); |
| 179 | md4_hmac_finish( &ctx, output ); |
| 180 | |
| 181 | hexify( hash_str, output, sizeof output ); |
| 182 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 183 | |
| 184 | /* Again, to test hmac_reset() */ |
| 185 | memset( hash_str, 0x00, sizeof hash_str ); |
| 186 | memset( output, 0x00, sizeof output ); |
| 187 | |
| 188 | md4_hmac_reset( &ctx ); |
| 189 | md4_hmac_update( &ctx, src_str, src_len / 2 ); |
| 190 | md4_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 191 | md4_hmac_finish( &ctx, output ); |
| 192 | |
| 193 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 194 | 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] | 195 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 196 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 197 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 198 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C */ |
| 199 | void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 200 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 201 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 202 | unsigned char src_str[200]; |
| 203 | unsigned char key_str[200]; |
| 204 | unsigned char hash_str[33]; |
| 205 | unsigned char output[16]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 206 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 207 | md5_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 208 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 209 | memset( src_str, 0x00, sizeof src_str ); |
| 210 | memset( key_str, 0x00, sizeof key_str ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 211 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 212 | key_len = unhexify( key_str, hex_key_string ); |
| 213 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 214 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 215 | /* Test the all-in-one interface */ |
| 216 | memset( hash_str, 0x00, sizeof hash_str ); |
| 217 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 218 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 219 | md5_hmac( key_str, key_len, src_str, src_len, output ); |
| 220 | |
| 221 | hexify( hash_str, output, sizeof output ); |
| 222 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 223 | |
| 224 | /* Also test the "streaming" interface */ |
| 225 | memset( hash_str, 0x00, sizeof hash_str ); |
| 226 | memset( output, 0x00, sizeof output ); |
| 227 | memset( &ctx, 0x00, sizeof ctx ); |
| 228 | |
| 229 | md5_hmac_starts( &ctx, key_str, key_len ); |
| 230 | md5_hmac_update( &ctx, src_str, 0 ); |
| 231 | md5_hmac_update( &ctx, src_str, src_len / 2 ); |
| 232 | md5_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 233 | md5_hmac_update( &ctx, src_str + src_len, 0 ); |
| 234 | md5_hmac_finish( &ctx, output ); |
| 235 | |
| 236 | hexify( hash_str, output, sizeof output ); |
| 237 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 238 | |
| 239 | /* Again, to test hmac_reset() */ |
| 240 | memset( hash_str, 0x00, sizeof hash_str ); |
| 241 | memset( output, 0x00, sizeof output ); |
| 242 | |
| 243 | md5_hmac_reset( &ctx ); |
| 244 | md5_hmac_update( &ctx, src_str, src_len / 2 ); |
| 245 | md5_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 246 | md5_hmac_finish( &ctx, output ); |
| 247 | |
| 248 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 249 | 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] | 250 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 251 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 252 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 253 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C */ |
| 254 | void ripemd160_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 255 | char *hex_hash_string ) |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 256 | { |
| 257 | unsigned char src_str[200]; |
| 258 | unsigned char key_str[200]; |
| 259 | unsigned char hash_str[41]; |
| 260 | unsigned char output[20]; |
| 261 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 262 | ripemd160_context ctx; |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 263 | |
| 264 | memset( src_str, 0x00, sizeof src_str ); |
| 265 | memset( key_str, 0x00, sizeof key_str ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 266 | |
| 267 | key_len = unhexify( key_str, hex_key_string ); |
| 268 | src_len = unhexify( src_str, hex_src_string ); |
| 269 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 270 | /* Test the all-in-one interface */ |
| 271 | memset( hash_str, 0x00, sizeof hash_str ); |
| 272 | memset( output, 0x00, sizeof output ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 273 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame^] | 274 | ripemd160_hmac( key_str, key_len, src_str, src_len, output ); |
| 275 | |
| 276 | hexify( hash_str, output, sizeof output ); |
| 277 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 278 | |
| 279 | /* Also test the "streaming" interface */ |
| 280 | memset( hash_str, 0x00, sizeof hash_str ); |
| 281 | memset( output, 0x00, sizeof output ); |
| 282 | memset( &ctx, 0x00, sizeof ctx ); |
| 283 | |
| 284 | ripemd160_hmac_starts( &ctx, key_str, key_len ); |
| 285 | ripemd160_hmac_update( &ctx, src_str, 0 ); |
| 286 | ripemd160_hmac_update( &ctx, src_str, src_len / 2 ); |
| 287 | ripemd160_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 288 | ripemd160_hmac_update( &ctx, src_str + src_len, 0 ); |
| 289 | ripemd160_hmac_finish( &ctx, output ); |
| 290 | |
| 291 | hexify( hash_str, output, sizeof output ); |
| 292 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 293 | |
| 294 | /* Again, to test hmac_reset() */ |
| 295 | memset( hash_str, 0x00, sizeof hash_str ); |
| 296 | memset( output, 0x00, sizeof output ); |
| 297 | |
| 298 | ripemd160_hmac_reset( &ctx ); |
| 299 | ripemd160_hmac_update( &ctx, src_str, src_len / 2 ); |
| 300 | ripemd160_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 301 | ripemd160_hmac_finish( &ctx, output ); |
| 302 | |
| 303 | hexify( hash_str, output, sizeof output ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 304 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 305 | } |
| 306 | /* END_CASE */ |
| 307 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 308 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 309 | void md2_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 310 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 311 | unsigned char hash_str[33]; |
| 312 | unsigned char output[16]; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 313 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 314 | memset( hash_str, 0x00, sizeof hash_str ); |
| 315 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 316 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 317 | md2_file( filename, output); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 318 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 319 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 320 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 321 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 322 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 323 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 324 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 325 | void md4_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 326 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 327 | unsigned char hash_str[33]; |
| 328 | unsigned char output[16]; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 329 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 330 | memset( hash_str, 0x00, sizeof hash_str ); |
| 331 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 332 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 333 | md4_file( filename, output); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 334 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 335 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 336 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 337 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 338 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 339 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 340 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 341 | void md5_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 342 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 343 | unsigned char hash_str[33]; |
| 344 | unsigned char output[16]; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 345 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 346 | memset( hash_str, 0x00, sizeof hash_str ); |
| 347 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 348 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 349 | md5_file( filename, output); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 350 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 351 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 352 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 353 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 354 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 355 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 356 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_FS_IO */ |
| 357 | void ripemd160_file( char *filename, char *hex_hash_string ) |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 358 | { |
| 359 | unsigned char hash_str[41]; |
| 360 | unsigned char output[20]; |
| 361 | |
| 362 | memset(hash_str, 0x00, sizeof hash_str ); |
| 363 | memset(output, 0x00, sizeof output ); |
| 364 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 365 | ripemd160_file( filename, output); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 366 | hexify( hash_str, output, sizeof output ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 367 | |
| 368 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| 369 | } |
| 370 | /* END_CASE */ |
| 371 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 372 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 373 | void md2_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 374 | { |
| 375 | TEST_ASSERT( md2_self_test( 0 ) == 0 ); |
| 376 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 377 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 378 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 379 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 380 | void md4_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 381 | { |
| 382 | TEST_ASSERT( md4_self_test( 0 ) == 0 ); |
| 383 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 384 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 385 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 386 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 387 | void md5_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 388 | { |
| 389 | TEST_ASSERT( md5_self_test( 0 ) == 0 ); |
| 390 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 391 | /* END_CASE */ |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 392 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 393 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_SELF_TEST */ |
| 394 | void ripemd160_selftest() |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 395 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 396 | TEST_ASSERT( ripemd160_self_test( 0 ) == 0 ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 397 | } |
| 398 | /* END_CASE */ |