blob: 6e29e535ffb87f97a225f526e181e42316e05672 [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
36 TEST_INVALID_PARAM( mbedtls_aria_init( NULL ) );
37
38 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
39 mbedtls_aria_setkey_enc( NULL, key,
40 sizeof( key ) ) );
41 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
Hanno Beckerfac1d442018-12-17 12:07:01 +000042 mbedtls_aria_setkey_enc( &ctx, NULL,
43 sizeof( key ) ) );
Hanno Becker9e45c162018-12-11 21:51:38 +000044
45 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
Hanno Beckerfac1d442018-12-17 12:07:01 +000046 mbedtls_aria_setkey_dec( NULL, key,
47 sizeof( key ) ) );
Hanno Becker9e45c162018-12-11 21:51:38 +000048 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
Hanno Beckerfac1d442018-12-17 12:07:01 +000049 mbedtls_aria_setkey_dec( &ctx, NULL,
50 sizeof( key ) ) );
Hanno Becker9e45c162018-12-11 21:51:38 +000051
52 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
53 mbedtls_aria_crypt_ecb( NULL, input, output ) );
54 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
55 mbedtls_aria_crypt_ecb( &ctx, NULL, output ) );
56 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
57 mbedtls_aria_crypt_ecb( &ctx, input, NULL ) );
58
59#if defined(MBEDTLS_CIPHER_MODE_CBC)
60 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
61 mbedtls_aria_crypt_cbc( NULL,
62 MBEDTLS_ARIA_ENCRYPT,
63 sizeof( input ),
64 iv,
65 input,
66 output ) );
67 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
68 mbedtls_aria_crypt_cbc( &ctx,
69 42 /* invalid mode */,
70 sizeof( input ),
71 iv,
72 input,
73 output ) );
74 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
75 mbedtls_aria_crypt_cbc( &ctx,
76 MBEDTLS_ARIA_ENCRYPT,
77 sizeof( input ),
78 NULL,
79 input,
80 output ) );
81 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
82 mbedtls_aria_crypt_cbc( &ctx,
83 MBEDTLS_ARIA_ENCRYPT,
84 sizeof( input ),
85 iv,
86 NULL,
87 output ) );
88 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
89 mbedtls_aria_crypt_cbc( &ctx,
90 MBEDTLS_ARIA_ENCRYPT,
91 sizeof( input ),
92 iv,
93 input,
94 NULL ) );
95#endif /* MBEDTLS_CIPHER_MODE_CBC */
96
97#if defined(MBEDTLS_CIPHER_MODE_CFB)
98 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
99 mbedtls_aria_crypt_cfb128( NULL,
100 MBEDTLS_ARIA_ENCRYPT,
101 sizeof( input ),
102 &iv_off,
103 iv,
104 input,
105 output ) );
106 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
107 mbedtls_aria_crypt_cfb128( &ctx,
108 42, /* invalid mode */
109 sizeof( input ),
110 &iv_off,
111 iv,
112 input,
113 output ) );
114 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
115 mbedtls_aria_crypt_cfb128( &ctx,
116 MBEDTLS_ARIA_ENCRYPT,
117 sizeof( input ),
118 NULL,
119 iv,
120 input,
121 output ) );
122 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
123 mbedtls_aria_crypt_cfb128( &ctx,
124 MBEDTLS_ARIA_ENCRYPT,
125 sizeof( input ),
126 &iv_off,
127 NULL,
128 input,
129 output ) );
130 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
131 mbedtls_aria_crypt_cfb128( &ctx,
132 MBEDTLS_ARIA_ENCRYPT,
133 sizeof( input ),
134 &iv_off,
135 iv,
136 NULL,
137 output ) );
138 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
139 mbedtls_aria_crypt_cfb128( &ctx,
140 MBEDTLS_ARIA_ENCRYPT,
141 sizeof( input ),
142 &iv_off,
143 iv,
144 input,
145 NULL ) );
146#endif /* MBEDTLS_CIPHER_MODE_CFB */
147
148#if defined(MBEDTLS_CIPHER_MODE_CTR)
149 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
150 mbedtls_aria_crypt_ctr( NULL,
151 sizeof( input ),
152 &iv_off,
153 iv,
154 iv,
155 input,
156 output ) );
157 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
158 mbedtls_aria_crypt_ctr( &ctx,
159 sizeof( input ),
160 NULL,
161 iv,
162 iv,
163 input,
164 output ) );
165 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
166 mbedtls_aria_crypt_ctr( &ctx,
167 sizeof( input ),
168 &iv_off,
169 NULL,
170 iv,
171 input,
172 output ) );
173 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
174 mbedtls_aria_crypt_ctr( &ctx,
175 sizeof( input ),
176 &iv_off,
177 iv,
178 NULL,
179 input,
180 output ) );
181 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
182 mbedtls_aria_crypt_ctr( &ctx,
183 sizeof( input ),
184 &iv_off,
185 iv,
186 iv,
187 NULL,
188 output ) );
189 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
190 mbedtls_aria_crypt_ctr( &ctx,
191 sizeof( input ),
192 &iv_off,
193 iv,
194 iv,
195 input,
196 NULL ) );
197#endif /* MBEDTLS_CIPHER_MODE_CTR */
198
199exit:
200 return;
201
202}
203/* END_CASE */
204
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000205/* BEGIN_CASE */
206void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100207 char *hex_dst_string, int setkey_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000208{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100209 unsigned char key_str[ARIA_MAX_KEY_STR];
210 unsigned char src_str[ARIA_MAX_DATA_STR];
211 unsigned char dst_str[ARIA_MAX_DATA_STR];
212 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000213 mbedtls_aria_context ctx;
214 int key_len, data_len, i;
215
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100216 memset( key_str, 0x00, sizeof( key_str ) );
217 memset( src_str, 0x00, sizeof( src_str ) );
218 memset( dst_str, 0x00, sizeof( dst_str ) );
219 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000220 mbedtls_aria_init( &ctx );
221
222 key_len = unhexify( key_str, hex_key_string );
223 data_len = unhexify( src_str, hex_src_string );
224
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100225 TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 )
226 == setkey_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000227 if( setkey_result == 0 )
228 {
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100229 for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000230 {
Simon Butcherd08a2f72018-06-05 15:53:06 +0100231 TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i )
232 == 0 );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000233 }
234 hexify( dst_str, output, data_len );
235
236 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
237 }
238
239exit:
240 mbedtls_aria_free( &ctx );
241}
242/* END_CASE */
243
244/* BEGIN_CASE */
245void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100246 char *hex_dst_string, int setkey_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000247{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100248 unsigned char key_str[ARIA_MAX_KEY_STR];
249 unsigned char src_str[ARIA_MAX_DATA_STR];
250 unsigned char dst_str[ARIA_MAX_DATA_STR];
251 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000252 mbedtls_aria_context ctx;
253 int key_len, data_len, i;
254
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100255 memset( key_str, 0x00, sizeof( key_str ) );
256 memset( src_str, 0x00, sizeof( src_str ) );
257 memset( dst_str, 0x00, sizeof( dst_str ) );
258 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000259 mbedtls_aria_init( &ctx );
260
261 key_len = unhexify( key_str, hex_key_string );
262 data_len = unhexify( src_str, hex_src_string );
263
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100264 TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 )
265 == setkey_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000266 if( setkey_result == 0 )
267 {
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100268 for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000269 {
Simon Butcherd08a2f72018-06-05 15:53:06 +0100270 TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i )
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100271 == 0 );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000272 }
273 hexify( dst_str, output, data_len );
274
275 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
276 }
277
278exit:
279 mbedtls_aria_free( &ctx );
280}
281/* END_CASE */
282
283/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
284void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100285 char *hex_src_string, char *hex_dst_string,
286 int cbc_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000287{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100288 unsigned char key_str[ARIA_MAX_KEY_STR];
289 unsigned char iv_str[ARIA_BLOCK_STR];
290 unsigned char src_str[ARIA_MAX_DATA_STR];
291 unsigned char dst_str[ARIA_MAX_DATA_STR];
292 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000293 mbedtls_aria_context ctx;
294 int key_len, data_len;
295
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100296 memset( key_str, 0x00, sizeof( key_str ) );
297 memset( iv_str, 0x00, sizeof( iv_str ) );
298 memset( src_str, 0x00, sizeof( src_str ) );
299 memset( dst_str, 0x00, sizeof( dst_str ) );
300 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000301 mbedtls_aria_init( &ctx );
302
303 key_len = unhexify( key_str, hex_key_string );
304 unhexify( iv_str, hex_iv_string );
305 data_len = unhexify( src_str, hex_src_string );
306
307 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100308 TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len,
309 iv_str, src_str, output )
310 == cbc_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000311 if( cbc_result == 0 )
312 {
313 hexify( dst_str, output, data_len );
314
315 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
316 }
317
318exit:
319 mbedtls_aria_free( &ctx );
320}
321/* END_CASE */
322
323/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
324void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100325 char *hex_src_string, char *hex_dst_string,
326 int cbc_result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000327{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100328 unsigned char key_str[ARIA_MAX_KEY_STR];
329 unsigned char iv_str[ARIA_BLOCK_STR];
330 unsigned char src_str[ARIA_MAX_DATA_STR];
331 unsigned char dst_str[ARIA_MAX_DATA_STR];
332 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000333 mbedtls_aria_context ctx;
334 int key_len, data_len;
335
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100336 memset( key_str, 0x00, sizeof( key_str ) );
337 memset( iv_str, 0x00, sizeof( iv_str ) );
338 memset( src_str, 0x00, sizeof( src_str ) );
339 memset( dst_str, 0x00, sizeof( dst_str ) );
340 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000341 mbedtls_aria_init( &ctx );
342
343 key_len = unhexify( key_str, hex_key_string );
344 unhexify( iv_str, hex_iv_string );
345 data_len = unhexify( src_str, hex_src_string );
346
347 mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100348 TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len,
349 iv_str, src_str, output )
350 == cbc_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000351 if( cbc_result == 0 )
352 {
353 hexify( dst_str, output, data_len );
354
355 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
356 }
357
358exit:
359 mbedtls_aria_free( &ctx );
360}
361/* END_CASE */
362
363/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
364void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100365 char *hex_src_string, char *hex_dst_string,
366 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000367{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100368 unsigned char key_str[ARIA_MAX_KEY_STR];
369 unsigned char iv_str[ARIA_BLOCK_STR];
370 unsigned char src_str[ARIA_MAX_DATA_STR];
371 unsigned char dst_str[ARIA_MAX_DATA_STR];
372 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000373 mbedtls_aria_context ctx;
374 size_t iv_offset = 0;
375 int key_len, data_len;
376
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100377 memset( key_str, 0x00, sizeof( key_str ) );
378 memset( iv_str, 0x00, sizeof( iv_str ) );
379 memset( src_str, 0x00, sizeof( src_str ) );
380 memset( dst_str, 0x00, sizeof( dst_str ) );
381 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000382 mbedtls_aria_init( &ctx );
383
384 key_len = unhexify( key_str, hex_key_string );
385 unhexify( iv_str, hex_iv_string );
386 data_len = unhexify( src_str, hex_src_string );
387
388 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
389 TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100390 data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100391 src_str, output )
392 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000393 hexify( dst_str, output, data_len );
394
395 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
396
397exit:
398 mbedtls_aria_free( &ctx );
399}
400/* END_CASE */
401
402/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
403void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100404 char *hex_src_string, char *hex_dst_string,
405 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000406{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100407 unsigned char key_str[ARIA_MAX_KEY_STR];
408 unsigned char iv_str[ARIA_BLOCK_STR];
409 unsigned char src_str[ARIA_MAX_DATA_STR];
410 unsigned char dst_str[ARIA_MAX_DATA_STR];
411 unsigned char output[ARIA_MAX_DATASIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000412 mbedtls_aria_context ctx;
413 size_t iv_offset = 0;
414 int key_len, data_len;
415
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100416 memset( key_str, 0x00, sizeof( key_str ) );
417 memset( iv_str, 0x00, sizeof( iv_str ) );
418 memset( src_str, 0x00, sizeof( src_str ) );
419 memset( dst_str, 0x00, sizeof( dst_str ) );
420 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000421 mbedtls_aria_init( &ctx );
422
423 key_len = unhexify( key_str, hex_key_string );
424 unhexify( iv_str, hex_iv_string );
425 data_len = unhexify( src_str, hex_src_string );
426
427 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
428 TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100429 data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100430 src_str, output )
431 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000432 hexify( dst_str, output, data_len );
433
434 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
435
436exit:
437 mbedtls_aria_free( &ctx );
438}
439/* END_CASE */
440
441/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
442void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100443 char *hex_src_string, char *hex_dst_string,
444 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000445{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100446 unsigned char key_str[ARIA_MAX_KEY_STR];
447 unsigned char iv_str[ARIA_BLOCK_STR];
448 unsigned char src_str[ARIA_MAX_DATA_STR];
449 unsigned char dst_str[ARIA_MAX_DATA_STR];
450 unsigned char output[ARIA_MAX_DATASIZE];
451 unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000452 mbedtls_aria_context ctx;
453 size_t iv_offset = 0;
454 int key_len, data_len;
455
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100456 memset( key_str, 0x00, sizeof( key_str ) );
457 memset( iv_str, 0x00, sizeof( iv_str ) );
458 memset( src_str, 0x00, sizeof( src_str ) );
459 memset( dst_str, 0x00, sizeof( dst_str ) );
460 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000461 mbedtls_aria_init( &ctx );
462
463 key_len = unhexify( key_str, hex_key_string );
464 unhexify( iv_str, hex_iv_string );
465 data_len = unhexify( src_str, hex_src_string );
466
467 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100468 TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100469 blk, src_str, output )
470 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000471 hexify( dst_str, output, data_len );
472
473 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
474
475exit:
476 mbedtls_aria_free( &ctx );
477}
478/* END_CASE */
479
480/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
481void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string,
Manuel Pégourié-Gonnardd82d7912018-03-01 09:43:21 +0100482 char *hex_src_string, char *hex_dst_string,
483 int result )
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000484{
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100485 unsigned char key_str[ARIA_MAX_KEY_STR];
486 unsigned char iv_str[ARIA_BLOCK_STR];
487 unsigned char src_str[ARIA_MAX_DATA_STR];
488 unsigned char dst_str[ARIA_MAX_DATA_STR];
489 unsigned char output[ARIA_MAX_DATASIZE];
490 unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000491 mbedtls_aria_context ctx;
492 size_t iv_offset = 0;
493 int key_len, data_len;
494
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +0100495 memset( key_str, 0x00, sizeof( key_str ) );
496 memset( iv_str, 0x00, sizeof( iv_str ) );
497 memset( src_str, 0x00, sizeof( src_str ) );
498 memset( dst_str, 0x00, sizeof( dst_str ) );
499 memset( output, 0x00, sizeof( output ) );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000500 mbedtls_aria_init( &ctx );
501
502 key_len = unhexify( key_str, hex_key_string );
503 unhexify( iv_str, hex_iv_string );
504 data_len = unhexify( src_str, hex_src_string );
505
506 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100507 TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
Manuel Pégourié-Gonnard977dc362018-03-01 13:51:52 +0100508 blk, src_str, output )
509 == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000510 hexify( dst_str, output, data_len );
511
512 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
513
514exit:
515 mbedtls_aria_free( &ctx );
516}
517/* END_CASE */
518
519/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
520void aria_selftest()
521{
522 TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 );
523}
524/* END_CASE */