xref: /aosp_15_r20/external/mbedtls/tests/suites/test_suite_aes.function (revision 62c56f9862f102b96d72393aff6076c951fb8148)
1/* BEGIN_HEADER */
2#include "mbedtls/aes.h"
3
4/* Test AES with a copied context.
5 *
6 * master, enc and dec must be AES context objects. They don't need to
7 * be initialized, and are left freed.
8 */
9static int test_copy(const data_t *key,
10                     mbedtls_aes_context *master,
11                     mbedtls_aes_context *enc,
12                     mbedtls_aes_context *dec)
13{
14    unsigned char plaintext[16] = {
15        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
16        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
17    };
18    unsigned char ciphertext[16];
19    unsigned char output[16];
20
21    // Set key and encrypt with original context
22    mbedtls_aes_init(master);
23    TEST_ASSERT(mbedtls_aes_setkey_enc(master, key->x,
24                                       key->len * 8) == 0);
25    TEST_ASSERT(mbedtls_aes_crypt_ecb(master, MBEDTLS_AES_ENCRYPT,
26                                      plaintext, ciphertext) == 0);
27    *enc = *master;
28
29    // Set key for decryption with original context
30    mbedtls_aes_init(master);
31    TEST_ASSERT(mbedtls_aes_setkey_dec(master, key->x,
32                                       key->len * 8) == 0);
33    *dec = *master;
34
35    // Wipe the original context to make sure nothing from it is used
36    memset(master, 0, sizeof(*master));
37
38    // Encrypt with copied context
39    TEST_ASSERT(mbedtls_aes_crypt_ecb(enc, MBEDTLS_AES_ENCRYPT,
40                                      plaintext, output) == 0);
41    TEST_MEMORY_COMPARE(ciphertext, 16, output, 16);
42    mbedtls_aes_free(enc);
43
44    // Decrypt with copied context
45    TEST_ASSERT(mbedtls_aes_crypt_ecb(dec, MBEDTLS_AES_DECRYPT,
46                                      ciphertext, output) == 0);
47    TEST_MEMORY_COMPARE(plaintext, 16, output, 16);
48    mbedtls_aes_free(dec);
49
50    return 1;
51
52exit:
53    /* Bug: we may be leaving something unfreed. This is harmless
54     * in our built-in implementations, but might cause a memory leak
55     * with alternative implementations. */
56    return 0;
57}
58
59/* END_HEADER */
60
61/* BEGIN_DEPENDENCIES
62 * depends_on:MBEDTLS_AES_C
63 * END_DEPENDENCIES
64 */
65
66/* BEGIN_CASE */
67void aes_encrypt_ecb(data_t *key_str, data_t *src_str,
68                     data_t *dst, int setkey_result)
69{
70    unsigned char output[100];
71    mbedtls_aes_context ctx;
72
73    memset(output, 0x00, 100);
74
75    mbedtls_aes_init(&ctx);
76
77    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == setkey_result);
78    if (setkey_result == 0) {
79        TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output) == 0);
80
81        TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
82    }
83
84exit:
85    mbedtls_aes_free(&ctx);
86}
87/* END_CASE */
88
89/* BEGIN_CASE */
90void aes_decrypt_ecb(data_t *key_str, data_t *src_str,
91                     data_t *dst, int setkey_result)
92{
93    unsigned char output[100];
94    mbedtls_aes_context ctx;
95
96    memset(output, 0x00, 100);
97
98    mbedtls_aes_init(&ctx);
99
100    TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx, key_str->x, key_str->len * 8) == setkey_result);
101    if (setkey_result == 0) {
102        TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_DECRYPT, src_str->x, output) == 0);
103
104        TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
105    }
106
107exit:
108    mbedtls_aes_free(&ctx);
109}
110/* END_CASE */
111
112/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
113void aes_encrypt_cbc(data_t *key_str, data_t *iv_str,
114                     data_t *src_str, data_t *dst,
115                     int cbc_result)
116{
117    unsigned char output[100];
118    mbedtls_aes_context ctx;
119
120    memset(output, 0x00, 100);
121
122    mbedtls_aes_init(&ctx);
123
124    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
125    TEST_ASSERT(mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x,
126                                      src_str->x, output) == cbc_result);
127    if (cbc_result == 0) {
128
129        TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
130                                        src_str->len, dst->len) == 0);
131    }
132
133exit:
134    mbedtls_aes_free(&ctx);
135}
136/* END_CASE */
137
138/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
139void aes_decrypt_cbc(data_t *key_str, data_t *iv_str,
140                     data_t *src_str, data_t *dst,
141                     int cbc_result)
142{
143    unsigned char output[100];
144    mbedtls_aes_context ctx;
145
146    memset(output, 0x00, 100);
147    mbedtls_aes_init(&ctx);
148
149    TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx, key_str->x, key_str->len * 8) == 0);
150    TEST_ASSERT(mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x,
151                                      src_str->x, output) == cbc_result);
152    if (cbc_result == 0) {
153
154        TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
155                                        src_str->len, dst->len) == 0);
156    }
157
158exit:
159    mbedtls_aes_free(&ctx);
160}
161/* END_CASE */
162
163/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
164void aes_encrypt_xts(char *hex_key_string, char *hex_data_unit_string,
165                     char *hex_src_string, char *hex_dst_string)
166{
167    enum { AES_BLOCK_SIZE = 16 };
168    unsigned char *data_unit = NULL;
169    unsigned char *key = NULL;
170    unsigned char *src = NULL;
171    unsigned char *dst = NULL;
172    unsigned char *output = NULL;
173    mbedtls_aes_xts_context ctx;
174    size_t key_len, src_len, dst_len, data_unit_len;
175
176    mbedtls_aes_xts_init(&ctx);
177
178    data_unit = mbedtls_test_unhexify_alloc(hex_data_unit_string,
179                                            &data_unit_len);
180    TEST_ASSERT(data_unit_len == AES_BLOCK_SIZE);
181
182    key = mbedtls_test_unhexify_alloc(hex_key_string, &key_len);
183    TEST_ASSERT(key_len % 2 == 0);
184
185    src = mbedtls_test_unhexify_alloc(hex_src_string, &src_len);
186    dst = mbedtls_test_unhexify_alloc(hex_dst_string, &dst_len);
187    TEST_ASSERT(src_len == dst_len);
188
189    output = mbedtls_test_zero_alloc(dst_len);
190
191    TEST_ASSERT(mbedtls_aes_xts_setkey_enc(&ctx, key, key_len * 8) == 0);
192    TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT, src_len,
193                                      data_unit, src, output) == 0);
194
195    TEST_ASSERT(memcmp(output, dst, dst_len) == 0);
196
197exit:
198    mbedtls_aes_xts_free(&ctx);
199    mbedtls_free(data_unit);
200    mbedtls_free(key);
201    mbedtls_free(src);
202    mbedtls_free(dst);
203    mbedtls_free(output);
204}
205/* END_CASE */
206
207/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
208void aes_decrypt_xts(char *hex_key_string, char *hex_data_unit_string,
209                     char *hex_dst_string, char *hex_src_string)
210{
211    enum { AES_BLOCK_SIZE = 16 };
212    unsigned char *data_unit = NULL;
213    unsigned char *key = NULL;
214    unsigned char *src = NULL;
215    unsigned char *dst = NULL;
216    unsigned char *output = NULL;
217    mbedtls_aes_xts_context ctx;
218    size_t key_len, src_len, dst_len, data_unit_len;
219
220    mbedtls_aes_xts_init(&ctx);
221
222    data_unit = mbedtls_test_unhexify_alloc(hex_data_unit_string,
223                                            &data_unit_len);
224    TEST_ASSERT(data_unit_len == AES_BLOCK_SIZE);
225
226    key = mbedtls_test_unhexify_alloc(hex_key_string, &key_len);
227    TEST_ASSERT(key_len % 2 == 0);
228
229    src = mbedtls_test_unhexify_alloc(hex_src_string, &src_len);
230    dst = mbedtls_test_unhexify_alloc(hex_dst_string, &dst_len);
231    TEST_ASSERT(src_len == dst_len);
232
233    output = mbedtls_test_zero_alloc(dst_len);
234
235    TEST_ASSERT(mbedtls_aes_xts_setkey_dec(&ctx, key, key_len * 8) == 0);
236    TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_DECRYPT, src_len,
237                                      data_unit, src, output) == 0);
238
239    TEST_ASSERT(memcmp(output, dst, dst_len) == 0);
240
241exit:
242    mbedtls_aes_xts_free(&ctx);
243    mbedtls_free(data_unit);
244    mbedtls_free(key);
245    mbedtls_free(src);
246    mbedtls_free(dst);
247    mbedtls_free(output);
248}
249/* END_CASE */
250
251/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
252void aes_crypt_xts_size(int size, int retval)
253{
254    mbedtls_aes_xts_context ctx;
255    const unsigned char src[16] = { 0 };
256    unsigned char output[16];
257    unsigned char data_unit[16];
258    size_t length = size;
259
260    mbedtls_aes_xts_init(&ctx);
261    memset(data_unit, 0x00, sizeof(data_unit));
262
263    TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT, length, data_unit, src,
264                                      output) == retval);
265exit:
266    mbedtls_aes_xts_free(&ctx);
267}
268/* END_CASE */
269
270/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
271void aes_crypt_xts_keysize(int size, int retval)
272{
273    mbedtls_aes_xts_context ctx;
274    const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
275    size_t key_len = size;
276
277    mbedtls_aes_xts_init(&ctx);
278
279    TEST_ASSERT(mbedtls_aes_xts_setkey_enc(&ctx, key, key_len * 8) == retval);
280    TEST_ASSERT(mbedtls_aes_xts_setkey_dec(&ctx, key, key_len * 8) == retval);
281exit:
282    mbedtls_aes_xts_free(&ctx);
283}
284/* END_CASE */
285
286
287/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
288void aes_encrypt_cfb128(data_t *key_str, data_t *iv_str,
289                        data_t *src_str, data_t *dst)
290{
291    unsigned char output[100];
292    mbedtls_aes_context ctx;
293    size_t iv_offset = 0;
294
295    memset(output, 0x00, 100);
296    mbedtls_aes_init(&ctx);
297
298
299    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
300    TEST_ASSERT(mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x,
301                                         src_str->x, output) == 0);
302
303    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
304
305exit:
306    mbedtls_aes_free(&ctx);
307}
308/* END_CASE */
309
310/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
311void aes_decrypt_cfb128(data_t *key_str, data_t *iv_str,
312                        data_t *src_str, data_t *dst)
313{
314    unsigned char output[100];
315    mbedtls_aes_context ctx;
316    size_t iv_offset = 0;
317
318    memset(output, 0x00, 100);
319    mbedtls_aes_init(&ctx);
320
321
322    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
323    TEST_ASSERT(mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x,
324                                         src_str->x, output) == 0);
325
326    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x, 16, dst->len) == 0);
327
328exit:
329    mbedtls_aes_free(&ctx);
330}
331/* END_CASE */
332
333/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
334void aes_encrypt_cfb8(data_t *key_str, data_t *iv_str,
335                      data_t *src_str, data_t *dst)
336{
337    unsigned char output[100];
338    mbedtls_aes_context ctx;
339
340    memset(output, 0x00, 100);
341    mbedtls_aes_init(&ctx);
342
343
344    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
345    TEST_ASSERT(mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x,
346                                       src_str->x, output) == 0);
347
348    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
349                                    src_str->len, dst->len) == 0);
350
351exit:
352    mbedtls_aes_free(&ctx);
353}
354/* END_CASE */
355
356/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
357void aes_decrypt_cfb8(data_t *key_str, data_t *iv_str,
358                      data_t *src_str, data_t *dst)
359{
360    unsigned char output[100];
361    mbedtls_aes_context ctx;
362
363    memset(output, 0x00, 100);
364    mbedtls_aes_init(&ctx);
365
366
367    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x, key_str->len * 8) == 0);
368    TEST_ASSERT(mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x,
369                                       src_str->x, output) == 0);
370
371    TEST_ASSERT(mbedtls_test_hexcmp(output, dst->x,
372                                    src_str->len, dst->len) == 0);
373
374exit:
375    mbedtls_aes_free(&ctx);
376}
377/* END_CASE */
378
379/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */
380void aes_encrypt_ofb(int fragment_size, data_t *key_str,
381                     data_t *iv_str, data_t *src_str,
382                     data_t *expected_output)
383{
384    unsigned char output[32];
385    mbedtls_aes_context ctx;
386    size_t iv_offset = 0;
387    int in_buffer_len;
388    unsigned char *src_str_next;
389
390    memset(output, 0x00, sizeof(output));
391    mbedtls_aes_init(&ctx);
392
393    TEST_ASSERT((size_t) fragment_size < sizeof(output));
394
395    TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx, key_str->x,
396                                       key_str->len * 8) == 0);
397    in_buffer_len = src_str->len;
398    src_str_next = src_str->x;
399
400    while (in_buffer_len > 0) {
401        TEST_ASSERT(mbedtls_aes_crypt_ofb(&ctx, fragment_size, &iv_offset,
402                                          iv_str->x, src_str_next, output) == 0);
403
404        TEST_ASSERT(memcmp(output, expected_output->x, fragment_size) == 0);
405
406        in_buffer_len -= fragment_size;
407        expected_output->x += fragment_size;
408        src_str_next += fragment_size;
409
410        if (in_buffer_len < fragment_size) {
411            fragment_size = in_buffer_len;
412        }
413    }
414
415exit:
416    mbedtls_aes_free(&ctx);
417}
418/* END_CASE */
419
420/* BEGIN_CASE */
421void aes_invalid_mode()
422{
423    mbedtls_aes_context aes_ctx;
424    const unsigned char in[16] = { 0 };
425    unsigned char out[16];
426    const int invalid_mode = 42;
427
428    TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
429               mbedtls_aes_crypt_ecb(&aes_ctx, invalid_mode, in, out));
430
431#if defined(MBEDTLS_CIPHER_MODE_CBC)
432    TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
433               mbedtls_aes_crypt_cbc(&aes_ctx, invalid_mode, 16,
434                                     out, in, out));
435#endif /* MBEDTLS_CIPHER_MODE_CBC */
436
437#if defined(MBEDTLS_CIPHER_MODE_XTS)
438    mbedtls_aes_xts_context xts_ctx;
439
440    TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
441               mbedtls_aes_crypt_xts(&xts_ctx, invalid_mode, 16,
442                                     in, in, out));
443#endif /* MBEDTLS_CIPHER_MODE_XTS */
444
445#if defined(MBEDTLS_CIPHER_MODE_CFB)
446    size_t size;
447
448    TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
449               mbedtls_aes_crypt_cfb128(&aes_ctx, invalid_mode, 16,
450                                        &size, out, in, out));
451    TEST_EQUAL(MBEDTLS_ERR_AES_BAD_INPUT_DATA,
452               mbedtls_aes_crypt_cfb8(&aes_ctx, invalid_mode, 16,
453                                      out, in, out));
454#endif /* MBEDTLS_CIPHER_MODE_CFB */
455}
456/* END_CASE */
457
458/* BEGIN_CASE */
459void aes_misc_params()
460{
461#if defined(MBEDTLS_CIPHER_MODE_CBC) || \
462    defined(MBEDTLS_CIPHER_MODE_XTS) || \
463    defined(MBEDTLS_CIPHER_MODE_CFB) || \
464    defined(MBEDTLS_CIPHER_MODE_OFB)
465    const unsigned char in[16] = { 0 };
466    unsigned char out[16];
467#endif
468#if defined(MBEDTLS_CIPHER_MODE_CBC) || \
469    defined(MBEDTLS_CIPHER_MODE_CFB) || \
470    defined(MBEDTLS_CIPHER_MODE_OFB)
471    mbedtls_aes_context aes_ctx;
472#endif
473#if defined(MBEDTLS_CIPHER_MODE_XTS)
474    mbedtls_aes_xts_context xts_ctx;
475#endif
476#if defined(MBEDTLS_CIPHER_MODE_CFB) || \
477    defined(MBEDTLS_CIPHER_MODE_OFB)
478    size_t size;
479#endif
480
481#if defined(MBEDTLS_CIPHER_MODE_CBC)
482    TEST_ASSERT(mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_ENCRYPT,
483                                      15,
484                                      out, in, out)
485                == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
486    TEST_ASSERT(mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_ENCRYPT,
487                                      17,
488                                      out, in, out)
489                == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
490#endif
491
492#if defined(MBEDTLS_CIPHER_MODE_XTS)
493    TEST_ASSERT(mbedtls_aes_crypt_xts(&xts_ctx, MBEDTLS_AES_ENCRYPT,
494                                      15,
495                                      in, in, out)
496                == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
497    TEST_ASSERT(mbedtls_aes_crypt_xts(&xts_ctx, MBEDTLS_AES_ENCRYPT,
498                                      (1 << 24) + 1,
499                                      in, in, out)
500                == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH);
501#endif
502
503#if defined(MBEDTLS_CIPHER_MODE_CFB)
504    size = 16;
505    TEST_ASSERT(mbedtls_aes_crypt_cfb128(&aes_ctx, MBEDTLS_AES_ENCRYPT, 16,
506                                         &size, out, in, out)
507                == MBEDTLS_ERR_AES_BAD_INPUT_DATA);
508#endif
509
510#if defined(MBEDTLS_CIPHER_MODE_OFB)
511    size = 16;
512    TEST_ASSERT(mbedtls_aes_crypt_ofb(&aes_ctx, 16, &size, out, in, out)
513                == MBEDTLS_ERR_AES_BAD_INPUT_DATA);
514#endif
515
516/*
517 * The following line needs to be added to make the code compilable
518 * when all the conditions above will be not define in a specific
519 * choice of features.
520 */
521    TEST_ASSERT(1);
522/* TODO: It will be removed when the whole test will be reworked */
523}
524/* END_CASE */
525
526/* BEGIN_CASE */
527void aes_ecb_copy_context(data_t *key)
528{
529    /* We test context copying multiple times, with different alignments
530     * of the original and of the copies. */
531
532    struct align0 {
533        mbedtls_aes_context ctx;
534    };
535    struct align0 *src0 = NULL;
536    struct align0 *enc0 = NULL;
537    struct align0 *dec0 = NULL;
538
539    struct align1 {
540        char bump;
541        mbedtls_aes_context ctx;
542    };
543    struct align1 *src1 = NULL;
544    struct align1 *enc1 = NULL;
545    struct align1 *dec1 = NULL;
546
547    /* All peak alignment */
548    TEST_CALLOC(src0, 1);
549    TEST_CALLOC(enc0, 1);
550    TEST_CALLOC(dec0, 1);
551    if (!test_copy(key, &src0->ctx, &enc0->ctx, &dec0->ctx)) {
552        goto exit;
553    }
554    mbedtls_free(src0);
555    src0 = NULL;
556    mbedtls_free(enc0);
557    enc0 = NULL;
558    mbedtls_free(dec0);
559    dec0 = NULL;
560
561    /* Original shifted */
562    TEST_CALLOC(src1, 1);
563    TEST_CALLOC(enc0, 1);
564    TEST_CALLOC(dec0, 1);
565    if (!test_copy(key, &src1->ctx, &enc0->ctx, &dec0->ctx)) {
566        goto exit;
567    }
568    mbedtls_free(src1);
569    src1 = NULL;
570    mbedtls_free(enc0);
571    enc0 = NULL;
572    mbedtls_free(dec0);
573    dec0 = NULL;
574
575    /* Copies shifted */
576    TEST_CALLOC(src0, 1);
577    TEST_CALLOC(enc1, 1);
578    TEST_CALLOC(dec1, 1);
579    if (!test_copy(key, &src0->ctx, &enc1->ctx, &dec1->ctx)) {
580        goto exit;
581    }
582    mbedtls_free(src0);
583    src0 = NULL;
584    mbedtls_free(enc1);
585    enc1 = NULL;
586    mbedtls_free(dec1);
587    dec1 = NULL;
588
589    /* Source and copies shifted */
590    TEST_CALLOC(src1, 1);
591    TEST_CALLOC(enc1, 1);
592    TEST_CALLOC(dec1, 1);
593    if (!test_copy(key, &src1->ctx, &enc1->ctx, &dec1->ctx)) {
594        goto exit;
595    }
596    mbedtls_free(src1);
597    src1 = NULL;
598    mbedtls_free(enc1);
599    enc1 = NULL;
600    mbedtls_free(dec1);
601    dec1 = NULL;
602
603exit:
604    mbedtls_free(src0);
605    mbedtls_free(enc0);
606    mbedtls_free(dec0);
607    mbedtls_free(src1);
608    mbedtls_free(enc1);
609    mbedtls_free(dec1);
610}
611/* END_CASE */
612
613/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
614void aes_selftest()
615{
616    TEST_ASSERT(mbedtls_aes_self_test(1) == 0);
617}
618/* END_CASE */
619