2 #include "mbedtls/aes.h"
6 * depends_on:MBEDTLS_AES_C
11 void aes_encrypt_ecb( data_t * key_str, data_t * src_str,
12 data_t * hex_dst_string, int setkey_result )
14 unsigned char output[100];
15 mbedtls_aes_context ctx;
17 memset(output, 0x00, 100);
19 mbedtls_aes_init( &ctx );
21 TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
22 if( setkey_result == 0 )
24 TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output ) == 0 );
26 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
30 mbedtls_aes_free( &ctx );
35 void aes_decrypt_ecb( data_t * key_str, data_t * src_str,
36 data_t * hex_dst_string, int setkey_result )
38 unsigned char output[100];
39 mbedtls_aes_context ctx;
41 memset(output, 0x00, 100);
43 mbedtls_aes_init( &ctx );
45 TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
46 if( setkey_result == 0 )
48 TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str->x, output ) == 0 );
50 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
54 mbedtls_aes_free( &ctx );
58 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
59 void aes_encrypt_cbc( data_t * key_str, data_t * iv_str,
60 data_t * src_str, data_t * hex_dst_string,
63 unsigned char output[100];
64 mbedtls_aes_context ctx;
66 memset(output, 0x00, 100);
68 mbedtls_aes_init( &ctx );
70 mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
71 TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
75 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
79 mbedtls_aes_free( &ctx );
83 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
84 void aes_decrypt_cbc( data_t * key_str, data_t * iv_str,
85 data_t * src_str, data_t * hex_dst_string,
88 unsigned char output[100];
89 mbedtls_aes_context ctx;
91 memset(output, 0x00, 100);
92 mbedtls_aes_init( &ctx );
94 mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
95 TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
99 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
103 mbedtls_aes_free( &ctx );
107 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
108 void aes_encrypt_xts( char *hex_key_string, char *hex_data_unit_string,
109 char *hex_src_string, char *hex_dst_string )
111 enum { AES_BLOCK_SIZE = 16 };
112 unsigned char *data_unit = NULL;
113 unsigned char *key = NULL;
114 unsigned char *src = NULL;
115 unsigned char *dst = NULL;
116 unsigned char *output = NULL;
117 mbedtls_aes_xts_context ctx;
118 size_t key_len, src_len, dst_len, data_unit_len;
120 mbedtls_aes_xts_init( &ctx );
122 data_unit = unhexify_alloc( hex_data_unit_string, &data_unit_len );
123 TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE );
125 key = unhexify_alloc( hex_key_string, &key_len );
126 TEST_ASSERT( key_len % 2 == 0 );
128 src = unhexify_alloc( hex_src_string, &src_len );
129 dst = unhexify_alloc( hex_dst_string, &dst_len );
130 TEST_ASSERT( src_len == dst_len );
132 output = zero_alloc( dst_len );
134 TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == 0 );
135 TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, src_len,
136 data_unit, src, output ) == 0 );
138 TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 );
141 mbedtls_aes_xts_free( &ctx );
142 mbedtls_free( data_unit );
146 mbedtls_free( output );
150 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
151 void aes_decrypt_xts( char *hex_key_string, char *hex_data_unit_string,
152 char *hex_dst_string, char *hex_src_string )
154 enum { AES_BLOCK_SIZE = 16 };
155 unsigned char *data_unit = NULL;
156 unsigned char *key = NULL;
157 unsigned char *src = NULL;
158 unsigned char *dst = NULL;
159 unsigned char *output = NULL;
160 mbedtls_aes_xts_context ctx;
161 size_t key_len, src_len, dst_len, data_unit_len;
163 mbedtls_aes_xts_init( &ctx );
165 data_unit = unhexify_alloc( hex_data_unit_string, &data_unit_len );
166 TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE );
168 key = unhexify_alloc( hex_key_string, &key_len );
169 TEST_ASSERT( key_len % 2 == 0 );
171 src = unhexify_alloc( hex_src_string, &src_len );
172 dst = unhexify_alloc( hex_dst_string, &dst_len );
173 TEST_ASSERT( src_len == dst_len );
175 output = zero_alloc( dst_len );
177 TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == 0 );
178 TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_DECRYPT, src_len,
179 data_unit, src, output ) == 0 );
181 TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 );
184 mbedtls_aes_xts_free( &ctx );
185 mbedtls_free( data_unit );
189 mbedtls_free( output );
193 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
194 void aes_crypt_xts_size( int size, int retval )
196 mbedtls_aes_xts_context ctx;
197 const unsigned char src[16] = { 0 };
198 unsigned char output[16];
199 unsigned char data_unit[16];
200 size_t length = size;
202 mbedtls_aes_xts_init( &ctx );
203 memset( data_unit, 0x00, sizeof( data_unit ) );
206 /* Valid pointers are passed for builds with MBEDTLS_CHECK_PARAMS, as
207 * otherwise we wouldn't get to the size check we're interested in. */
208 TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, length, data_unit, src, output ) == retval );
212 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */
213 void aes_crypt_xts_keysize( int size, int retval )
215 mbedtls_aes_xts_context ctx;
216 const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
217 size_t key_len = size;
219 mbedtls_aes_xts_init( &ctx );
221 TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == retval );
222 TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == retval );
224 mbedtls_aes_xts_free( &ctx );
229 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
230 void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str,
231 data_t * src_str, data_t * hex_dst_string )
233 unsigned char output[100];
234 mbedtls_aes_context ctx;
235 size_t iv_offset = 0;
237 memset(output, 0x00, 100);
238 mbedtls_aes_init( &ctx );
241 mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
242 TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
244 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
247 mbedtls_aes_free( &ctx );
251 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
252 void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str,
253 data_t * src_str, data_t * hex_dst_string )
255 unsigned char output[100];
256 mbedtls_aes_context ctx;
257 size_t iv_offset = 0;
259 memset(output, 0x00, 100);
260 mbedtls_aes_init( &ctx );
263 mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
264 TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
266 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
269 mbedtls_aes_free( &ctx );
273 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
274 void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str,
275 data_t * src_str, data_t * hex_dst_string )
277 unsigned char output[100];
278 mbedtls_aes_context ctx;
280 memset(output, 0x00, 100);
281 mbedtls_aes_init( &ctx );
284 mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
285 TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
287 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
290 mbedtls_aes_free( &ctx );
294 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
295 void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str,
296 data_t * src_str, data_t * hex_dst_string )
298 unsigned char output[100];
299 mbedtls_aes_context ctx;
301 memset(output, 0x00, 100);
302 mbedtls_aes_init( &ctx );
305 mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
306 TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
308 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
311 mbedtls_aes_free( &ctx );
315 /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */
316 void aes_encrypt_ofb( int fragment_size, char *hex_key_string,
317 char *hex_iv_string, char *hex_src_string,
318 char *hex_dst_string )
320 unsigned char key_str[32];
321 unsigned char iv_str[16];
322 unsigned char src_str[64];
323 unsigned char dst_str[64];
324 unsigned char output[32];
325 mbedtls_aes_context ctx;
326 size_t iv_offset = 0;
328 unsigned char* src_str_next;
331 memset( key_str, 0x00, sizeof( key_str ) );
332 memset( iv_str, 0x00, sizeof( iv_str ) );
333 memset( src_str, 0x00, sizeof( src_str ) );
334 memset( dst_str, 0x00, sizeof( dst_str ) );
335 memset( output, 0x00, sizeof( output ) );
336 mbedtls_aes_init( &ctx );
338 TEST_ASSERT( strlen( hex_key_string ) <= ( 32 * 2 ) );
339 TEST_ASSERT( strlen( hex_iv_string ) <= ( 16 * 2 ) );
340 TEST_ASSERT( strlen( hex_src_string ) <= ( 64 * 2 ) );
341 TEST_ASSERT( strlen( hex_dst_string ) <= ( 64 * 2 ) );
343 key_len = unhexify( key_str, hex_key_string );
344 unhexify( iv_str, hex_iv_string );
345 in_buffer_len = unhexify( src_str, hex_src_string );
347 TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
348 src_str_next = src_str;
350 while( in_buffer_len > 0 )
352 TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset,
353 iv_str, src_str_next, output ) == 0 );
355 hexify( dst_str, output, fragment_size );
356 TEST_ASSERT( strncmp( (char *) dst_str, hex_dst_string,
357 ( 2 * fragment_size ) ) == 0 );
359 in_buffer_len -= fragment_size;
360 hex_dst_string += ( fragment_size * 2 );
361 src_str_next += fragment_size;
363 if( in_buffer_len < fragment_size )
364 fragment_size = in_buffer_len;
368 mbedtls_aes_free( &ctx );
372 /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
373 void aes_check_params( )
375 mbedtls_aes_context aes_ctx;
376 #if defined(MBEDTLS_CIPHER_MODE_XTS)
377 mbedtls_aes_xts_context xts_ctx;
379 const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
380 const unsigned char in[16] = { 0 };
381 unsigned char out[16];
383 const int valid_mode = MBEDTLS_AES_ENCRYPT;
384 const int invalid_mode = 42;
386 TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) );
387 #if defined(MBEDTLS_CIPHER_MODE_XTS)
388 TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) );
391 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
392 mbedtls_aes_setkey_enc( NULL, key, 128 ) );
393 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
394 mbedtls_aes_setkey_enc( &aes_ctx, NULL, 128 ) );
396 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
397 mbedtls_aes_setkey_dec( NULL, key, 128 ) );
398 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
399 mbedtls_aes_setkey_dec( &aes_ctx, NULL, 128 ) );
401 #if defined(MBEDTLS_CIPHER_MODE_XTS)
402 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
403 mbedtls_aes_xts_setkey_enc( NULL, key, 128 ) );
404 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
405 mbedtls_aes_xts_setkey_enc( &xts_ctx, NULL, 128 ) );
407 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
408 mbedtls_aes_xts_setkey_dec( NULL, key, 128 ) );
409 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
410 mbedtls_aes_xts_setkey_dec( &xts_ctx, NULL, 128 ) );
414 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
415 mbedtls_aes_crypt_ecb( NULL,
416 valid_mode, in, out ) );
417 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
418 mbedtls_aes_crypt_ecb( &aes_ctx,
419 invalid_mode, in, out ) );
420 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
421 mbedtls_aes_crypt_ecb( &aes_ctx,
422 valid_mode, NULL, out ) );
423 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
424 mbedtls_aes_crypt_ecb( &aes_ctx,
425 valid_mode, in, NULL ) );
427 #if defined(MBEDTLS_CIPHER_MODE_CBC)
428 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
429 mbedtls_aes_crypt_cbc( NULL,
432 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
433 mbedtls_aes_crypt_cbc( &aes_ctx,
436 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
437 mbedtls_aes_crypt_cbc( &aes_ctx,
440 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
441 mbedtls_aes_crypt_cbc( &aes_ctx,
444 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
445 mbedtls_aes_crypt_cbc( &aes_ctx,
448 #endif /* MBEDTLS_CIPHER_MODE_CBC */
450 #if defined(MBEDTLS_CIPHER_MODE_XTS)
451 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
452 mbedtls_aes_crypt_xts( NULL,
455 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
456 mbedtls_aes_crypt_xts( &xts_ctx,
459 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
460 mbedtls_aes_crypt_xts( &xts_ctx,
463 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
464 mbedtls_aes_crypt_xts( &xts_ctx,
467 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
468 mbedtls_aes_crypt_xts( &xts_ctx,
471 #endif /* MBEDTLS_CIPHER_MODE_XTS */
473 #if defined(MBEDTLS_CIPHER_MODE_CFB)
474 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
475 mbedtls_aes_crypt_cfb128( NULL,
477 &size, out, in, out ) );
478 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
479 mbedtls_aes_crypt_cfb128( &aes_ctx,
481 &size, out, in, out ) );
482 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
483 mbedtls_aes_crypt_cfb128( &aes_ctx,
485 NULL, out, in, out ) );
486 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
487 mbedtls_aes_crypt_cfb128( &aes_ctx,
489 &size, NULL, in, out ) );
490 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
491 mbedtls_aes_crypt_cfb128( &aes_ctx,
493 &size, out, NULL, out ) );
494 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
495 mbedtls_aes_crypt_cfb128( &aes_ctx,
497 &size, out, in, NULL ) );
500 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
501 mbedtls_aes_crypt_cfb8( NULL,
504 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
505 mbedtls_aes_crypt_cfb8( &aes_ctx,
508 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
509 mbedtls_aes_crypt_cfb8( &aes_ctx,
512 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
513 mbedtls_aes_crypt_cfb8( &aes_ctx,
516 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
517 mbedtls_aes_crypt_cfb8( &aes_ctx,
520 #endif /* MBEDTLS_CIPHER_MODE_CFB */
522 #if defined(MBEDTLS_CIPHER_MODE_OFB)
523 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
524 mbedtls_aes_crypt_ofb( NULL, 16,
525 &size, out, in, out ) );
526 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
527 mbedtls_aes_crypt_ofb( &aes_ctx, 16,
528 NULL, out, in, out ) );
529 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
530 mbedtls_aes_crypt_ofb( &aes_ctx, 16,
531 &size, NULL, in, out ) );
532 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
533 mbedtls_aes_crypt_ofb( &aes_ctx, 16,
534 &size, out, NULL, out ) );
535 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
536 mbedtls_aes_crypt_ofb( &aes_ctx, 16,
537 &size, out, in, NULL ) );
538 #endif /* MBEDTLS_CIPHER_MODE_OFB */
540 #if defined(MBEDTLS_CIPHER_MODE_CTR)
541 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
542 mbedtls_aes_crypt_ctr( NULL, 16, &size, out,
544 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
545 mbedtls_aes_crypt_ctr( &aes_ctx, 16, NULL, out,
547 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
548 mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, NULL,
550 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
551 mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out,
553 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
554 mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out,
556 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
557 mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out,
559 #endif /* MBEDTLS_CIPHER_MODE_CTR */
564 void aes_misc_params( )
566 #if defined(MBEDTLS_CIPHER_MODE_CBC) || \
567 defined(MBEDTLS_CIPHER_MODE_XTS) || \
568 defined(MBEDTLS_CIPHER_MODE_CFB) || \
569 defined(MBEDTLS_CIPHER_MODE_OFB)
570 mbedtls_aes_context aes_ctx;
571 const unsigned char in[16] = { 0 };
572 unsigned char out[16];
574 #if defined(MBEDTLS_CIPHER_MODE_XTS)
575 mbedtls_aes_xts_context xts_ctx;
577 #if defined(MBEDTLS_CIPHER_MODE_CFB) || \
578 defined(MBEDTLS_CIPHER_MODE_OFB)
582 /* These calls accept NULL */
583 TEST_VALID_PARAM( mbedtls_aes_free( NULL ) );
584 #if defined(MBEDTLS_CIPHER_MODE_XTS)
585 TEST_VALID_PARAM( mbedtls_aes_xts_free( NULL ) );
588 #if defined(MBEDTLS_CIPHER_MODE_CBC)
589 TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT,
592 == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
593 TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT,
596 == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
599 #if defined(MBEDTLS_CIPHER_MODE_XTS)
600 TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT,
603 == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
604 TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT,
607 == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
610 #if defined(MBEDTLS_CIPHER_MODE_CFB)
612 TEST_ASSERT( mbedtls_aes_crypt_cfb128( &aes_ctx, MBEDTLS_AES_ENCRYPT, 16,
613 &size, out, in, out )
614 == MBEDTLS_ERR_AES_BAD_INPUT_DATA );
617 #if defined(MBEDTLS_CIPHER_MODE_OFB)
619 TEST_ASSERT( mbedtls_aes_crypt_ofb( &aes_ctx, 16, &size, out, in, out )
620 == MBEDTLS_ERR_AES_BAD_INPUT_DATA );
625 /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
628 TEST_ASSERT( mbedtls_aes_self_test( 1 ) == 0 );