blob: d3d8ebeeadbc91627d636000fe3bb829d3eeff5e [file] [log] [blame]
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +00001/* BEGIN_HEADER */
2#include "mbedtls/aria.h"
3/* END_HEADER */
4
5/* BEGIN_DEPENDENCIES
6 * depends_on:MBEDTLS_ARIA_C
7 * END_DEPENDENCIES
8 */
9
10/* BEGIN_CASE */
11void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string,
12 char *hex_dst_string, int setkey_result )
13{
14 unsigned char key_str[1000];
15 unsigned char src_str[1000];
16 unsigned char dst_str[1000];
17 unsigned char output[1000];
18 mbedtls_aria_context ctx;
19 int key_len, data_len, i;
20
21 memset( key_str, 0x00, 1000 );
22 memset( src_str, 0x00, 1000 );
23 memset( dst_str, 0x00, 1000 );
24 memset( output, 0x00, 1000 );
25 mbedtls_aria_init( &ctx );
26
27 key_len = unhexify( key_str, hex_key_string );
28 data_len = unhexify( src_str, hex_src_string );
29
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +010030 TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 )
31 == setkey_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +000032 if( setkey_result == 0 )
33 {
34 for( i = 0; i < data_len; i += 16 )
35 {
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +010036 TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, MBEDTLS_ARIA_ENCRYPT,
37 src_str + i, output + i ) == 0 );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +000038 }
39 hexify( dst_str, output, data_len );
40
41 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
42 }
43
44exit:
45 mbedtls_aria_free( &ctx );
46}
47/* END_CASE */
48
49/* BEGIN_CASE */
50void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string,
51 char *hex_dst_string, int setkey_result )
52{
53 unsigned char key_str[1000];
54 unsigned char src_str[1000];
55 unsigned char dst_str[1000];
56 unsigned char output[1000];
57 mbedtls_aria_context ctx;
58 int key_len, data_len, i;
59
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +010060 memset( key_str, 0x00, 1000 );
61 memset( src_str, 0x00, 1000 );
62 memset( dst_str, 0x00, 1000 );
63 memset( output, 0x00, 1000 );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +000064 mbedtls_aria_init( &ctx );
65
66 key_len = unhexify( key_str, hex_key_string );
67 data_len = unhexify( src_str, hex_src_string );
68
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +010069 TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 )
70 == setkey_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +000071 if( setkey_result == 0 )
72 {
73 for( i = 0; i < data_len; i += 16 )
74 {
75 TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, MBEDTLS_ARIA_DECRYPT,
76 src_str + i, output + i ) == 0 );
77 }
78 hexify( dst_str, output, data_len );
79
80 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
81 }
82
83exit:
84 mbedtls_aria_free( &ctx );
85}
86/* END_CASE */
87
88/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
89void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
90 char *hex_src_string, char *hex_dst_string,
91 int cbc_result )
92{
93 unsigned char key_str[1000];
94 unsigned char iv_str[1000];
95 unsigned char src_str[1000];
96 unsigned char dst_str[1000];
97 unsigned char output[1000];
98 mbedtls_aria_context ctx;
99 int key_len, data_len;
100
101 memset( key_str, 0x00, 1000 );
102 memset( iv_str, 0x00, 1000 );
103 memset( src_str, 0x00, 1000 );
104 memset( dst_str, 0x00, 1000 );
105 memset( output, 0x00, 1000 );
106 mbedtls_aria_init( &ctx );
107
108 key_len = unhexify( key_str, hex_key_string );
109 unhexify( iv_str, hex_iv_string );
110 data_len = unhexify( src_str, hex_src_string );
111
112 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100113 TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len,
114 iv_str, src_str, output )
115 == cbc_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000116 if( cbc_result == 0 )
117 {
118 hexify( dst_str, output, data_len );
119
120 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
121 }
122
123exit:
124 mbedtls_aria_free( &ctx );
125}
126/* END_CASE */
127
128/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
129void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
130 char *hex_src_string, char *hex_dst_string,
131 int cbc_result )
132{
133 unsigned char key_str[1000];
134 unsigned char iv_str[1000];
135 unsigned char src_str[1000];
136 unsigned char dst_str[1000];
137 unsigned char output[1000];
138 mbedtls_aria_context ctx;
139 int key_len, data_len;
140
141 memset( key_str, 0x00, 1000 );
142 memset( iv_str, 0x00, 1000 );
143 memset( src_str, 0x00, 1000 );
144 memset( dst_str, 0x00, 1000 );
145 memset( output, 0x00, 1000 );
146 mbedtls_aria_init( &ctx );
147
148 key_len = unhexify( key_str, hex_key_string );
149 unhexify( iv_str, hex_iv_string );
150 data_len = unhexify( src_str, hex_src_string );
151
152 mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100153 TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len,
154 iv_str, src_str, output )
155 == cbc_result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000156 if( cbc_result == 0 )
157 {
158 hexify( dst_str, output, data_len );
159
160 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
161 }
162
163exit:
164 mbedtls_aria_free( &ctx );
165}
166/* END_CASE */
167
168/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
169void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
170 char *hex_src_string, char *hex_dst_string,
171 int result )
172{
173 unsigned char key_str[1000];
174 unsigned char iv_str[1000];
175 unsigned char src_str[1000];
176 unsigned char dst_str[1000];
177 unsigned char output[1000];
178 mbedtls_aria_context ctx;
179 size_t iv_offset = 0;
180 int key_len, data_len;
181
182 memset( key_str, 0x00, 1000 );
183 memset( iv_str, 0x00, 1000 );
184 memset( src_str, 0x00, 1000 );
185 memset( dst_str, 0x00, 1000 );
186 memset( output, 0x00, 1000 );
187 mbedtls_aria_init( &ctx );
188
189 key_len = unhexify( key_str, hex_key_string );
190 unhexify( iv_str, hex_iv_string );
191 data_len = unhexify( src_str, hex_src_string );
192
193 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
194 TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100195 data_len, &iv_offset, iv_str,
196 src_str, output ) == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000197 hexify( dst_str, output, data_len );
198
199 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
200
201exit:
202 mbedtls_aria_free( &ctx );
203}
204/* END_CASE */
205
206/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
207void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
208 char *hex_src_string, char *hex_dst_string,
209 int result )
210{
211 unsigned char key_str[1000];
212 unsigned char iv_str[1000];
213 unsigned char src_str[1000];
214 unsigned char dst_str[1000];
215 unsigned char output[1000];
216 mbedtls_aria_context ctx;
217 size_t iv_offset = 0;
218 int key_len, data_len;
219
220 memset( key_str, 0x00, 1000 );
221 memset( iv_str, 0x00, 1000 );
222 memset( src_str, 0x00, 1000 );
223 memset( dst_str, 0x00, 1000 );
224 memset( output, 0x00, 1000 );
225 mbedtls_aria_init( &ctx );
226
227 key_len = unhexify( key_str, hex_key_string );
228 unhexify( iv_str, hex_iv_string );
229 data_len = unhexify( src_str, hex_src_string );
230
231 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
232 TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100233 data_len, &iv_offset, iv_str,
234 src_str, output ) == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000235 hexify( dst_str, output, data_len );
236
237 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
238
239exit:
240 mbedtls_aria_free( &ctx );
241}
242/* END_CASE */
243
244/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
245void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
246 char *hex_src_string, char *hex_dst_string,
247 int result )
248{
249 unsigned char key_str[1000];
250 unsigned char iv_str[1000];
251 unsigned char src_str[1000];
252 unsigned char dst_str[1000];
253 unsigned char output[1000];
254 unsigned char blk[16];
255 mbedtls_aria_context ctx;
256 size_t iv_offset = 0;
257 int key_len, data_len;
258
259 memset( key_str, 0x00, 1000 );
260 memset( iv_str, 0x00, 1000 );
261 memset( src_str, 0x00, 1000 );
262 memset( dst_str, 0x00, 1000 );
263 memset( output, 0x00, 1000 );
264 mbedtls_aria_init( &ctx );
265
266 key_len = unhexify( key_str, hex_key_string );
267 unhexify( iv_str, hex_iv_string );
268 data_len = unhexify( src_str, hex_src_string );
269
270 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100271 TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
272 blk, src_str, output ) == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000273 hexify( dst_str, output, data_len );
274
275 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
276
277exit:
278 mbedtls_aria_free( &ctx );
279}
280/* END_CASE */
281
282/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
283void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string,
284 char *hex_src_string, char *hex_dst_string,
285 int result )
286{
287 unsigned char key_str[1000];
288 unsigned char iv_str[1000];
289 unsigned char src_str[1000];
290 unsigned char dst_str[1000];
291 unsigned char output[1000];
292 unsigned char blk[16];
293 mbedtls_aria_context ctx;
294 size_t iv_offset = 0;
295 int key_len, data_len;
296
297 memset( key_str, 0x00, 1000 );
298 memset( iv_str, 0x00, 1000 );
299 memset( src_str, 0x00, 1000 );
300 memset( dst_str, 0x00, 1000 );
301 memset( output, 0x00, 1000 );
302 mbedtls_aria_init( &ctx );
303
304 key_len = unhexify( key_str, hex_key_string );
305 unhexify( iv_str, hex_iv_string );
306 data_len = unhexify( src_str, hex_src_string );
307
308 mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100309 TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
310 blk, src_str, output ) == result );
Markku-Juhani O. Saarinen8df81e02017-12-01 14:26:40 +0000311 hexify( dst_str, output, data_len );
312
313 TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
314
315exit:
316 mbedtls_aria_free( &ctx );
317}
318/* END_CASE */
319
320/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
321void aria_selftest()
322{
323 TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 );
324}
325/* END_CASE */