blob: 7e35f154b55c97a857a4783ed22a8f230bce2508 [file] [log] [blame]
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +00001/* BEGIN_HEADER */
2#include "mbedtls/aria.h"
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +01003
4/* Maxium size of data used by test vectors
5 * WARNING: to be adapted if and when adding larger test cases */
6#define ARIA_MAX_DATASIZE 160
7
8/* Maximum sizes of hexified things */
9#define ARIA_MAX_KEY_STR ( 2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1 )
10#define ARIA_BLOCK_STR ( 2 * MBEDTLS_ARIA_BLOCKSIZE + 1 )
11#define ARIA_MAX_DATA_STR ( 2 * ARIA_MAX_DATASIZE + 1 )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +000012/* END_HEADER */
13
14/* BEGIN_DEPENDENCIES
15 * depends_on:MBEDTLS_ARIA_C
16 * END_DEPENDENCIES
17 */
18
Hanno Becker14b91e82018-12-17 14:13:36 +000019/* BEGIN_CASE */
20void aria_valid_param( )
21{
22 TEST_VALID_PARAM( mbedtls_aria_free( NULL ) );
23}
24/* END_CASE */
25
Hanno Becker9e45c162018-12-11 21:51:38 +000026/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
27void aria_invalid_param( )
28{
29 mbedtls_aria_context ctx;
30 unsigned char key[128 / 8] = { 0 };
31 unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
32 unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
33 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
34 size_t iv_off = 0;
35
Hanno Becker02940722018-12-18 18:18:45 +000036 ((void) iv_off);
37 ((void) iv);
38
Hanno Becker9e45c162018-12-11 21:51:38 +000039 TEST_INVALID_PARAM( mbedtls_aria_init( NULL ) );
40
41 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
42 mbedtls_aria_setkey_enc( NULL, key,
43 sizeof( key ) ) );
44 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
Hanno Beckerfac1d442018-12-17 12:07:01 +000045 mbedtls_aria_setkey_enc( &ctx, NULL,
46 sizeof( key ) ) );
Hanno Becker9e45c162018-12-11 21:51:38 +000047
48 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
Hanno Beckerfac1d442018-12-17 12:07:01 +000049 mbedtls_aria_setkey_dec( NULL, key,
50 sizeof( key ) ) );
Hanno Becker9e45c162018-12-11 21:51:38 +000051 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
Hanno Beckerfac1d442018-12-17 12:07:01 +000052 mbedtls_aria_setkey_dec( &ctx, NULL,
53 sizeof( key ) ) );
Hanno Becker9e45c162018-12-11 21:51:38 +000054
55 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
56 mbedtls_aria_crypt_ecb( NULL, input, output ) );
57 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
58 mbedtls_aria_crypt_ecb( &ctx, NULL, output ) );
59 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
60 mbedtls_aria_crypt_ecb( &ctx, input, NULL ) );
61
62#if defined(MBEDTLS_CIPHER_MODE_CBC)
63 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
64 mbedtls_aria_crypt_cbc( NULL,
65 MBEDTLS_ARIA_ENCRYPT,
66 sizeof( input ),
67 iv,
68 input,
69 output ) );
70 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
71 mbedtls_aria_crypt_cbc( &ctx,
72 42 /* invalid mode */,
73 sizeof( input ),
74 iv,
75 input,
76 output ) );
77 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
78 mbedtls_aria_crypt_cbc( &ctx,
79 MBEDTLS_ARIA_ENCRYPT,
80 sizeof( input ),
81 NULL,
82 input,
83 output ) );
84 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
85 mbedtls_aria_crypt_cbc( &ctx,
86 MBEDTLS_ARIA_ENCRYPT,
87 sizeof( input ),
88 iv,
89 NULL,
90 output ) );
91 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
92 mbedtls_aria_crypt_cbc( &ctx,
93 MBEDTLS_ARIA_ENCRYPT,
94 sizeof( input ),
95 iv,
96 input,
97 NULL ) );
98#endif /* MBEDTLS_CIPHER_MODE_CBC */
99
100#if defined(MBEDTLS_CIPHER_MODE_CFB)
101 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
102 mbedtls_aria_crypt_cfb128( NULL,
103 MBEDTLS_ARIA_ENCRYPT,
104 sizeof( input ),
105 &iv_off,
106 iv,
107 input,
108 output ) );
109 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
110 mbedtls_aria_crypt_cfb128( &ctx,
111 42, /* invalid mode */
112 sizeof( input ),
113 &iv_off,
114 iv,
115 input,
116 output ) );
117 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
118 mbedtls_aria_crypt_cfb128( &ctx,
119 MBEDTLS_ARIA_ENCRYPT,
120 sizeof( input ),
121 NULL,
122 iv,
123 input,
124 output ) );
125 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
126 mbedtls_aria_crypt_cfb128( &ctx,
127 MBEDTLS_ARIA_ENCRYPT,
128 sizeof( input ),
129 &iv_off,
130 NULL,
131 input,
132 output ) );
133 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
134 mbedtls_aria_crypt_cfb128( &ctx,
135 MBEDTLS_ARIA_ENCRYPT,
136 sizeof( input ),
137 &iv_off,
138 iv,
139 NULL,
140 output ) );
141 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
142 mbedtls_aria_crypt_cfb128( &ctx,
143 MBEDTLS_ARIA_ENCRYPT,
144 sizeof( input ),
145 &iv_off,
146 iv,
147 input,
148 NULL ) );
149#endif /* MBEDTLS_CIPHER_MODE_CFB */
150
151#if defined(MBEDTLS_CIPHER_MODE_CTR)
152 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
153 mbedtls_aria_crypt_ctr( NULL,
154 sizeof( input ),
155 &iv_off,
156 iv,
157 iv,
158 input,
159 output ) );
160 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
161 mbedtls_aria_crypt_ctr( &ctx,
162 sizeof( input ),
163 NULL,
164 iv,
165 iv,
166 input,
167 output ) );
168 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
169 mbedtls_aria_crypt_ctr( &ctx,
170 sizeof( input ),
171 &iv_off,
172 NULL,
173 iv,
174 input,
175 output ) );
176 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
177 mbedtls_aria_crypt_ctr( &ctx,
178 sizeof( input ),
179 &iv_off,
180 iv,
181 NULL,
182 input,
183 output ) );
184 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
185 mbedtls_aria_crypt_ctr( &ctx,
186 sizeof( input ),
187 &iv_off,
188 iv,
189 iv,
190 NULL,
191 output ) );
192 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
193 mbedtls_aria_crypt_ctr( &ctx,
194 sizeof( input ),
195 &iv_off,
196 iv,
197 iv,
198 input,
199 NULL ) );
200#endif /* MBEDTLS_CIPHER_MODE_CTR */
201
202exit:
203 return;
204
205}
206/* END_CASE */
207
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000208/* BEGIN_CASE */
209void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100210 char *hex_dst_string, int setkey_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000211{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100212 unsigned char key_str[ARIA_MAX_KEY_STR];
213 unsigned char src_str[ARIA_MAX_DATA_STR];
214 unsigned char dst_str[ARIA_MAX_DATA_STR];
215 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000216 mbedtls_aria_context ctx;
217 int key_len, data_len, i;
218
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100219 memset( key_str, 0x00, sizeof( key_str ) );
220 memset( src_str, 0x00, sizeof( src_str ) );
221 memset( dst_str, 0x00, sizeof( dst_str ) );
222 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000223 mbedtls_aria_init( &ctx );
224
225 key_len = unhexify( key_str, hex_key_string );
226 data_len = unhexify( src_str, hex_src_string );
227
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100228 TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 )
229 == setkey_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000230 if( setkey_result == 0 )
231 {
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100232 for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000233 {
Simon Butcherd08a2f72018-06-05 15:53:06 +0100234 TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i )
235 == 0 );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000236 }
237 hexify( dst_str, output, data_len );
238
239 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
240 }
241
242exit:
243 mbedtls_aria_free( &ctx );
244}
245/* END_CASE */
246
247/* BEGIN_CASE */
248void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100249 char *hex_dst_string, int setkey_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000250{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100251 unsigned char key_str[ARIA_MAX_KEY_STR];
252 unsigned char src_str[ARIA_MAX_DATA_STR];
253 unsigned char dst_str[ARIA_MAX_DATA_STR];
254 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000255 mbedtls_aria_context ctx;
256 int key_len, data_len, i;
257
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100258 memset( key_str, 0x00, sizeof( key_str ) );
259 memset( src_str, 0x00, sizeof( src_str ) );
260 memset( dst_str, 0x00, sizeof( dst_str ) );
261 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000262 mbedtls_aria_init( &ctx );
263
264 key_len = unhexify( key_str, hex_key_string );
265 data_len = unhexify( src_str, hex_src_string );
266
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100267 TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 )
268 == setkey_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000269 if( setkey_result == 0 )
270 {
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100271 for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000272 {
Simon Butcherd08a2f72018-06-05 15:53:06 +0100273 TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i )
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100274 == 0 );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000275 }
276 hexify( dst_str, output, data_len );
277
278 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
279 }
280
281exit:
282 mbedtls_aria_free( &ctx );
283}
284/* END_CASE */
285
286/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
287void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100288 char *hex_src_string, char *hex_dst_string,
289 int cbc_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000290{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100291 unsigned char key_str[ARIA_MAX_KEY_STR];
292 unsigned char iv_str[ARIA_BLOCK_STR];
293 unsigned char src_str[ARIA_MAX_DATA_STR];
294 unsigned char dst_str[ARIA_MAX_DATA_STR];
295 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000296 mbedtls_aria_context ctx;
297 int key_len, data_len;
298
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100299 memset( key_str, 0x00, sizeof( key_str ) );
300 memset( iv_str, 0x00, sizeof( iv_str ) );
301 memset( src_str, 0x00, sizeof( src_str ) );
302 memset( dst_str, 0x00, sizeof( dst_str ) );
303 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000304 mbedtls_aria_init( &ctx );
305
306 key_len = unhexify( key_str, hex_key_string );
307 unhexify( iv_str, hex_iv_string );
308 data_len = unhexify( src_str, hex_src_string );
309
310 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100311 TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len,
312 iv_str, src_str, output )
313 == cbc_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000314 if( cbc_result == 0 )
315 {
316 hexify( dst_str, output, data_len );
317
318 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
319 }
320
321exit:
322 mbedtls_aria_free( &ctx );
323}
324/* END_CASE */
325
326/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
327void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100328 char *hex_src_string, char *hex_dst_string,
329 int cbc_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000330{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100331 unsigned char key_str[ARIA_MAX_KEY_STR];
332 unsigned char iv_str[ARIA_BLOCK_STR];
333 unsigned char src_str[ARIA_MAX_DATA_STR];
334 unsigned char dst_str[ARIA_MAX_DATA_STR];
335 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000336 mbedtls_aria_context ctx;
337 int key_len, data_len;
338
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100339 memset( key_str, 0x00, sizeof( key_str ) );
340 memset( iv_str, 0x00, sizeof( iv_str ) );
341 memset( src_str, 0x00, sizeof( src_str ) );
342 memset( dst_str, 0x00, sizeof( dst_str ) );
343 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000344 mbedtls_aria_init( &ctx );
345
346 key_len = unhexify( key_str, hex_key_string );
347 unhexify( iv_str, hex_iv_string );
348 data_len = unhexify( src_str, hex_src_string );
349
350 mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100351 TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len,
352 iv_str, src_str, output )
353 == cbc_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000354 if( cbc_result == 0 )
355 {
356 hexify( dst_str, output, data_len );
357
358 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
359 }
360
361exit:
362 mbedtls_aria_free( &ctx );
363}
364/* END_CASE */
365
366/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
367void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100368 char *hex_src_string, char *hex_dst_string,
369 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000370{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100371 unsigned char key_str[ARIA_MAX_KEY_STR];
372 unsigned char iv_str[ARIA_BLOCK_STR];
373 unsigned char src_str[ARIA_MAX_DATA_STR];
374 unsigned char dst_str[ARIA_MAX_DATA_STR];
375 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000376 mbedtls_aria_context ctx;
377 size_t iv_offset = 0;
378 int key_len, data_len;
379
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100380 memset( key_str, 0x00, sizeof( key_str ) );
381 memset( iv_str, 0x00, sizeof( iv_str ) );
382 memset( src_str, 0x00, sizeof( src_str ) );
383 memset( dst_str, 0x00, sizeof( dst_str ) );
384 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000385 mbedtls_aria_init( &ctx );
386
387 key_len = unhexify( key_str, hex_key_string );
388 unhexify( iv_str, hex_iv_string );
389 data_len = unhexify( src_str, hex_src_string );
390
391 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
392 TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100393 data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100394 src_str, output )
395 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000396 hexify( dst_str, output, data_len );
397
398 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
399
400exit:
401 mbedtls_aria_free( &ctx );
402}
403/* END_CASE */
404
405/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
406void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100407 char *hex_src_string, char *hex_dst_string,
408 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000409{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100410 unsigned char key_str[ARIA_MAX_KEY_STR];
411 unsigned char iv_str[ARIA_BLOCK_STR];
412 unsigned char src_str[ARIA_MAX_DATA_STR];
413 unsigned char dst_str[ARIA_MAX_DATA_STR];
414 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000415 mbedtls_aria_context ctx;
416 size_t iv_offset = 0;
417 int key_len, data_len;
418
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100419 memset( key_str, 0x00, sizeof( key_str ) );
420 memset( iv_str, 0x00, sizeof( iv_str ) );
421 memset( src_str, 0x00, sizeof( src_str ) );
422 memset( dst_str, 0x00, sizeof( dst_str ) );
423 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000424 mbedtls_aria_init( &ctx );
425
426 key_len = unhexify( key_str, hex_key_string );
427 unhexify( iv_str, hex_iv_string );
428 data_len = unhexify( src_str, hex_src_string );
429
430 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
431 TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100432 data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100433 src_str, output )
434 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000435 hexify( dst_str, output, data_len );
436
437 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
438
439exit:
440 mbedtls_aria_free( &ctx );
441}
442/* END_CASE */
443
444/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
445void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100446 char *hex_src_string, char *hex_dst_string,
447 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000448{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100449 unsigned char key_str[ARIA_MAX_KEY_STR];
450 unsigned char iv_str[ARIA_BLOCK_STR];
451 unsigned char src_str[ARIA_MAX_DATA_STR];
452 unsigned char dst_str[ARIA_MAX_DATA_STR];
453 unsigned char output[ARIA_MAX_DATASIZE];
454 unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000455 mbedtls_aria_context ctx;
456 size_t iv_offset = 0;
457 int key_len, data_len;
458
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100459 memset( key_str, 0x00, sizeof( key_str ) );
460 memset( iv_str, 0x00, sizeof( iv_str ) );
461 memset( src_str, 0x00, sizeof( src_str ) );
462 memset( dst_str, 0x00, sizeof( dst_str ) );
463 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000464 mbedtls_aria_init( &ctx );
465
466 key_len = unhexify( key_str, hex_key_string );
467 unhexify( iv_str, hex_iv_string );
468 data_len = unhexify( src_str, hex_src_string );
469
470 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100471 TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100472 blk, src_str, output )
473 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000474 hexify( dst_str, output, data_len );
475
476 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
477
478exit:
479 mbedtls_aria_free( &ctx );
480}
481/* END_CASE */
482
483/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
484void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100485 char *hex_src_string, char *hex_dst_string,
486 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000487{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100488 unsigned char key_str[ARIA_MAX_KEY_STR];
489 unsigned char iv_str[ARIA_BLOCK_STR];
490 unsigned char src_str[ARIA_MAX_DATA_STR];
491 unsigned char dst_str[ARIA_MAX_DATA_STR];
492 unsigned char output[ARIA_MAX_DATASIZE];
493 unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000494 mbedtls_aria_context ctx;
495 size_t iv_offset = 0;
496 int key_len, data_len;
497
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100498 memset( key_str, 0x00, sizeof( key_str ) );
499 memset( iv_str, 0x00, sizeof( iv_str ) );
500 memset( src_str, 0x00, sizeof( src_str ) );
501 memset( dst_str, 0x00, sizeof( dst_str ) );
502 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000503 mbedtls_aria_init( &ctx );
504
505 key_len = unhexify( key_str, hex_key_string );
506 unhexify( iv_str, hex_iv_string );
507 data_len = unhexify( src_str, hex_src_string );
508
509 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100510 TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100511 blk, src_str, output )
512 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000513 hexify( dst_str, output, data_len );
514
515 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
516
517exit:
518 mbedtls_aria_free( &ctx );
519}
520/* END_CASE */
521
522/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
523void aria_selftest()
524{
525 TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 );
526}
527/* END_CASE */