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