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 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame^] | 142 | exit: |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 143 | md2_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 144 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 145 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 146 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 147 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C */ |
| 148 | void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 149 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 150 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 151 | unsigned char src_str[200]; |
| 152 | unsigned char key_str[200]; |
| 153 | unsigned char hash_str[33]; |
| 154 | unsigned char output[16]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 155 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 156 | md4_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 157 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 158 | memset( src_str, 0x00, sizeof src_str ); |
| 159 | memset( key_str, 0x00, sizeof key_str ); |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 160 | md4_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 161 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 162 | key_len = unhexify( key_str, hex_key_string ); |
| 163 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 164 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 165 | /* Test the all-in-one interface */ |
| 166 | memset( hash_str, 0x00, sizeof hash_str ); |
| 167 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 168 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 169 | md4_hmac( key_str, key_len, src_str, src_len, output ); |
| 170 | |
| 171 | hexify( hash_str, output, sizeof output ); |
| 172 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 173 | |
| 174 | /* Also test the "streaming" interface */ |
| 175 | memset( hash_str, 0x00, sizeof hash_str ); |
| 176 | memset( output, 0x00, sizeof output ); |
| 177 | memset( &ctx, 0x00, sizeof ctx ); |
| 178 | |
| 179 | md4_hmac_starts( &ctx, key_str, key_len ); |
| 180 | md4_hmac_update( &ctx, src_str, 0 ); |
| 181 | md4_hmac_update( &ctx, src_str, src_len / 2 ); |
| 182 | md4_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 183 | md4_hmac_update( &ctx, src_str + src_len, 0 ); |
| 184 | md4_hmac_finish( &ctx, output ); |
| 185 | |
| 186 | hexify( hash_str, output, sizeof output ); |
| 187 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 188 | |
| 189 | /* Again, to test hmac_reset() */ |
| 190 | memset( hash_str, 0x00, sizeof hash_str ); |
| 191 | memset( output, 0x00, sizeof output ); |
| 192 | |
| 193 | md4_hmac_reset( &ctx ); |
| 194 | md4_hmac_update( &ctx, src_str, src_len / 2 ); |
| 195 | md4_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 196 | md4_hmac_finish( &ctx, output ); |
| 197 | |
| 198 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 199 | 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] | 200 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame^] | 201 | exit: |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 202 | md4_free( &ctx ); |
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 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 205 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 206 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C */ |
| 207 | void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 208 | char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 209 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 210 | unsigned char src_str[200]; |
| 211 | unsigned char key_str[200]; |
| 212 | unsigned char hash_str[33]; |
| 213 | unsigned char output[16]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 214 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 215 | md5_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 216 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 217 | memset( src_str, 0x00, sizeof src_str ); |
| 218 | memset( key_str, 0x00, sizeof key_str ); |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 219 | md5_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 220 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 221 | key_len = unhexify( key_str, hex_key_string ); |
| 222 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 223 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 224 | /* Test the all-in-one interface */ |
| 225 | memset( hash_str, 0x00, sizeof hash_str ); |
| 226 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 227 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 228 | md5_hmac( key_str, key_len, src_str, src_len, output ); |
| 229 | |
| 230 | hexify( hash_str, output, sizeof output ); |
| 231 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 232 | |
| 233 | /* Also test the "streaming" interface */ |
| 234 | memset( hash_str, 0x00, sizeof hash_str ); |
| 235 | memset( output, 0x00, sizeof output ); |
| 236 | memset( &ctx, 0x00, sizeof ctx ); |
| 237 | |
| 238 | md5_hmac_starts( &ctx, key_str, key_len ); |
| 239 | md5_hmac_update( &ctx, src_str, 0 ); |
| 240 | md5_hmac_update( &ctx, src_str, src_len / 2 ); |
| 241 | md5_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 242 | md5_hmac_update( &ctx, src_str + src_len, 0 ); |
| 243 | md5_hmac_finish( &ctx, output ); |
| 244 | |
| 245 | hexify( hash_str, output, sizeof output ); |
| 246 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 247 | |
| 248 | /* Again, to test hmac_reset() */ |
| 249 | memset( hash_str, 0x00, sizeof hash_str ); |
| 250 | memset( output, 0x00, sizeof output ); |
| 251 | |
| 252 | md5_hmac_reset( &ctx ); |
| 253 | md5_hmac_update( &ctx, src_str, src_len / 2 ); |
| 254 | md5_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 255 | md5_hmac_finish( &ctx, output ); |
| 256 | |
| 257 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 258 | 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] | 259 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame^] | 260 | exit: |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 261 | md5_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 262 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 263 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 264 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 265 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C */ |
| 266 | void ripemd160_hmac( int trunc_size, char *hex_key_string, char *hex_src_string, |
| 267 | char *hex_hash_string ) |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 268 | { |
| 269 | unsigned char src_str[200]; |
| 270 | unsigned char key_str[200]; |
| 271 | unsigned char hash_str[41]; |
| 272 | unsigned char output[20]; |
| 273 | int key_len, src_len; |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 274 | ripemd160_context ctx; |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 275 | |
| 276 | memset( src_str, 0x00, sizeof src_str ); |
| 277 | memset( key_str, 0x00, sizeof key_str ); |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 278 | ripemd160_init( &ctx ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 279 | |
| 280 | key_len = unhexify( key_str, hex_key_string ); |
| 281 | src_len = unhexify( src_str, hex_src_string ); |
| 282 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 283 | /* Test the all-in-one interface */ |
| 284 | memset( hash_str, 0x00, sizeof hash_str ); |
| 285 | memset( output, 0x00, sizeof output ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 286 | |
Manuel Pégourié-Gonnard | 58319e7 | 2014-03-29 14:05:06 +0100 | [diff] [blame] | 287 | ripemd160_hmac( key_str, key_len, src_str, src_len, output ); |
| 288 | |
| 289 | hexify( hash_str, output, sizeof output ); |
| 290 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 291 | |
| 292 | /* Also test the "streaming" interface */ |
| 293 | memset( hash_str, 0x00, sizeof hash_str ); |
| 294 | memset( output, 0x00, sizeof output ); |
| 295 | memset( &ctx, 0x00, sizeof ctx ); |
| 296 | |
| 297 | ripemd160_hmac_starts( &ctx, key_str, key_len ); |
| 298 | ripemd160_hmac_update( &ctx, src_str, 0 ); |
| 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_update( &ctx, src_str + src_len, 0 ); |
| 302 | ripemd160_hmac_finish( &ctx, output ); |
| 303 | |
| 304 | hexify( hash_str, output, sizeof output ); |
| 305 | TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 ); |
| 306 | |
| 307 | /* Again, to test hmac_reset() */ |
| 308 | memset( hash_str, 0x00, sizeof hash_str ); |
| 309 | memset( output, 0x00, sizeof output ); |
| 310 | |
| 311 | ripemd160_hmac_reset( &ctx ); |
| 312 | ripemd160_hmac_update( &ctx, src_str, src_len / 2 ); |
| 313 | ripemd160_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 ); |
| 314 | ripemd160_hmac_finish( &ctx, output ); |
| 315 | |
| 316 | hexify( hash_str, output, sizeof output ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 317 | 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] | 318 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame^] | 319 | exit: |
Paul Bakker | 14e8be4 | 2014-06-26 12:25:06 +0200 | [diff] [blame] | 320 | ripemd160_free( &ctx ); |
Manuel Pégourié-Gonnard | ff40c3a | 2014-01-17 19:49:15 +0100 | [diff] [blame] | 321 | } |
| 322 | /* END_CASE */ |
| 323 | |
Paul Bakker | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 324 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 325 | void md2_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 | md2_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_MD4_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 341 | void md4_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 | md4_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 | 428b9ba | 2013-09-15 15:20:37 +0200 | [diff] [blame] | 356 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_FS_IO */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 357 | void md5_file( char *filename, char *hex_hash_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 358 | { |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 359 | unsigned char hash_str[33]; |
| 360 | unsigned char output[16]; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 361 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 362 | memset( hash_str, 0x00, sizeof hash_str ); |
| 363 | memset( output, 0x00, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 364 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 365 | md5_file( filename, output); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 366 | hexify( hash_str, output, sizeof output ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 367 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 368 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 369 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 370 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 371 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 372 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_FS_IO */ |
| 373 | void ripemd160_file( char *filename, char *hex_hash_string ) |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 374 | { |
| 375 | unsigned char hash_str[41]; |
| 376 | unsigned char output[20]; |
| 377 | |
| 378 | memset(hash_str, 0x00, sizeof hash_str ); |
| 379 | memset(output, 0x00, sizeof output ); |
| 380 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 381 | ripemd160_file( filename, output); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 382 | hexify( hash_str, output, sizeof output ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 383 | |
| 384 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
| 385 | } |
| 386 | /* END_CASE */ |
| 387 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 388 | /* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 389 | void md2_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 390 | { |
| 391 | TEST_ASSERT( md2_self_test( 0 ) == 0 ); |
| 392 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 393 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 394 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 395 | /* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 396 | void md4_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 397 | { |
| 398 | TEST_ASSERT( md4_self_test( 0 ) == 0 ); |
| 399 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 400 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 401 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 402 | /* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 403 | void md5_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 404 | { |
| 405 | TEST_ASSERT( md5_self_test( 0 ) == 0 ); |
| 406 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 407 | /* END_CASE */ |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 408 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 409 | /* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_SELF_TEST */ |
| 410 | void ripemd160_selftest() |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 411 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 412 | TEST_ASSERT( ripemd160_self_test( 0 ) == 0 ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 413 | } |
| 414 | /* END_CASE */ |