Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 2 | #include "mbedtls/aes.h" |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 3 | /* END_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 4 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 5 | /* BEGIN_DEPENDENCIES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 6 | * depends_on:MBEDTLS_AES_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 7 | * END_DEPENDENCIES |
| 8 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 9 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 10 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 11 | void aes_encrypt_ecb( data_t * key_str, data_t * src_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 12 | data_t * dst, int setkey_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 13 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 14 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 15 | mbedtls_aes_context ctx; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 16 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 17 | memset(output, 0x00, 100); |
| 18 | |
Simon Butcher | 249b3d6 | 2018-12-09 22:18:46 +0000 | [diff] [blame] | 19 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 20 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 21 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 22 | if( setkey_result == 0 ) |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 23 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 24 | TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, src_str->x, output ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 25 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 26 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 27 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 28 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 29 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 30 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 31 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 32 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 33 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 34 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 35 | void aes_decrypt_ecb( data_t * key_str, data_t * src_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 36 | data_t * dst, int setkey_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 37 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 38 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 39 | mbedtls_aes_context ctx; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 40 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 41 | memset(output, 0x00, 100); |
| 42 | |
Simon Butcher | 249b3d6 | 2018-12-09 22:18:46 +0000 | [diff] [blame] | 43 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 44 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 45 | TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 46 | if( setkey_result == 0 ) |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 47 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 48 | TEST_ASSERT( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_DECRYPT, src_str->x, output ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 49 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 50 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 51 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 52 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 53 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 54 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 55 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 56 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 57 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 59 | void aes_encrypt_cbc( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 60 | data_t * src_str, data_t * dst, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 61 | int cbc_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 62 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 63 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 64 | mbedtls_aes_context ctx; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 65 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 66 | memset(output, 0x00, 100); |
| 67 | |
Simon Butcher | 249b3d6 | 2018-12-09 22:18:46 +0000 | [diff] [blame] | 68 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 69 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame^] | 70 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 ); |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 71 | TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 72 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 73 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 74 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 75 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, |
| 76 | src_str->len, dst->len ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 77 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 78 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 79 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 81 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 82 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 83 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 84 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 85 | void aes_decrypt_cbc( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 86 | data_t * src_str, data_t * dst, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 87 | int cbc_result ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 88 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 89 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | mbedtls_aes_context ctx; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 91 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 92 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 94 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame^] | 95 | TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == 0 ); |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 96 | TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 97 | if( cbc_result == 0) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 98 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 99 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 100 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, |
| 101 | src_str->len, dst->len ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 102 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 103 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 104 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 105 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 106 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 107 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 108 | |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 109 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */ |
Jaeden Amero | cd9fc5e | 2018-05-30 15:23:24 +0100 | [diff] [blame] | 110 | void aes_encrypt_xts( char *hex_key_string, char *hex_data_unit_string, |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 111 | char *hex_src_string, char *hex_dst_string ) |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 112 | { |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 113 | enum { AES_BLOCK_SIZE = 16 }; |
| 114 | unsigned char *data_unit = NULL; |
| 115 | unsigned char *key = NULL; |
| 116 | unsigned char *src = NULL; |
| 117 | unsigned char *dst = NULL; |
| 118 | unsigned char *output = NULL; |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 119 | mbedtls_aes_xts_context ctx; |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 120 | size_t key_len, src_len, dst_len, data_unit_len; |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 121 | |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 122 | mbedtls_aes_xts_init( &ctx ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 123 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 124 | data_unit = unhexify_alloc( hex_data_unit_string, &data_unit_len ); |
| 125 | TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 126 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 127 | key = unhexify_alloc( hex_key_string, &key_len ); |
| 128 | TEST_ASSERT( key_len % 2 == 0 ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 129 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 130 | src = unhexify_alloc( hex_src_string, &src_len ); |
| 131 | dst = unhexify_alloc( hex_dst_string, &dst_len ); |
| 132 | TEST_ASSERT( src_len == dst_len ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 133 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 134 | output = zero_alloc( dst_len ); |
| 135 | |
| 136 | TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == 0 ); |
| 137 | TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, src_len, |
| 138 | data_unit, src, output ) == 0 ); |
| 139 | |
| 140 | TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 141 | |
| 142 | exit: |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 143 | mbedtls_aes_xts_free( &ctx ); |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 144 | mbedtls_free( data_unit ); |
| 145 | mbedtls_free( key ); |
| 146 | mbedtls_free( src ); |
| 147 | mbedtls_free( dst ); |
| 148 | mbedtls_free( output ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 149 | } |
| 150 | /* END_CASE */ |
| 151 | |
| 152 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */ |
Jaeden Amero | cd9fc5e | 2018-05-30 15:23:24 +0100 | [diff] [blame] | 153 | void aes_decrypt_xts( char *hex_key_string, char *hex_data_unit_string, |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 154 | char *hex_dst_string, char *hex_src_string ) |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 155 | { |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 156 | enum { AES_BLOCK_SIZE = 16 }; |
| 157 | unsigned char *data_unit = NULL; |
| 158 | unsigned char *key = NULL; |
| 159 | unsigned char *src = NULL; |
| 160 | unsigned char *dst = NULL; |
| 161 | unsigned char *output = NULL; |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 162 | mbedtls_aes_xts_context ctx; |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 163 | size_t key_len, src_len, dst_len, data_unit_len; |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 164 | |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 165 | mbedtls_aes_xts_init( &ctx ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 166 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 167 | data_unit = unhexify_alloc( hex_data_unit_string, &data_unit_len ); |
| 168 | TEST_ASSERT( data_unit_len == AES_BLOCK_SIZE ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 169 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 170 | key = unhexify_alloc( hex_key_string, &key_len ); |
| 171 | TEST_ASSERT( key_len % 2 == 0 ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 172 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 173 | src = unhexify_alloc( hex_src_string, &src_len ); |
| 174 | dst = unhexify_alloc( hex_dst_string, &dst_len ); |
| 175 | TEST_ASSERT( src_len == dst_len ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 176 | |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 177 | output = zero_alloc( dst_len ); |
| 178 | |
| 179 | TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == 0 ); |
| 180 | TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_DECRYPT, src_len, |
| 181 | data_unit, src, output ) == 0 ); |
| 182 | |
| 183 | TEST_ASSERT( memcmp( output, dst, dst_len ) == 0 ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 184 | |
| 185 | exit: |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 186 | mbedtls_aes_xts_free( &ctx ); |
Jaeden Amero | e5c4b07 | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 187 | mbedtls_free( data_unit ); |
| 188 | mbedtls_free( key ); |
| 189 | mbedtls_free( src ); |
| 190 | mbedtls_free( dst ); |
| 191 | mbedtls_free( output ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 192 | } |
| 193 | /* END_CASE */ |
| 194 | |
Jaeden Amero | 425382d | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 195 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */ |
| 196 | void aes_crypt_xts_size( int size, int retval ) |
| 197 | { |
| 198 | mbedtls_aes_xts_context ctx; |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 199 | const unsigned char src[16] = { 0 }; |
| 200 | unsigned char output[16]; |
Jaeden Amero | 425382d | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 201 | unsigned char data_unit[16]; |
| 202 | size_t length = size; |
| 203 | |
| 204 | mbedtls_aes_xts_init( &ctx ); |
| 205 | memset( data_unit, 0x00, sizeof( data_unit ) ); |
| 206 | |
| 207 | |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 208 | /* Valid pointers are passed for builds with MBEDTLS_CHECK_PARAMS, as |
| 209 | * otherwise we wouldn't get to the size check we're interested in. */ |
Jaeden Amero | 425382d | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 210 | TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, length, data_unit, src, output ) == retval ); |
| 211 | } |
| 212 | /* END_CASE */ |
| 213 | |
Jaeden Amero | 142383e | 2018-05-31 10:40:34 +0100 | [diff] [blame] | 214 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */ |
| 215 | void aes_crypt_xts_keysize( int size, int retval ) |
| 216 | { |
| 217 | mbedtls_aes_xts_context ctx; |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 218 | const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; |
Jaeden Amero | 142383e | 2018-05-31 10:40:34 +0100 | [diff] [blame] | 219 | size_t key_len = size; |
| 220 | |
| 221 | mbedtls_aes_xts_init( &ctx ); |
| 222 | |
| 223 | TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == retval ); |
| 224 | TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == retval ); |
| 225 | exit: |
| 226 | mbedtls_aes_xts_free( &ctx ); |
| 227 | } |
| 228 | /* END_CASE */ |
Jaeden Amero | 425382d | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 229 | |
| 230 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 231 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 232 | void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 233 | data_t * src_str, data_t * dst ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 234 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 235 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 236 | mbedtls_aes_context ctx; |
Paul Bakker | cd43a0b | 2011-06-09 13:55:44 +0000 | [diff] [blame] | 237 | size_t iv_offset = 0; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 238 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 239 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 240 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 241 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 242 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame^] | 243 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 ); |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 244 | TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 245 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 246 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 247 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 248 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 249 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 250 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 251 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 252 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 253 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 254 | void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 255 | data_t * src_str, data_t * dst ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 256 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 257 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 258 | mbedtls_aes_context ctx; |
Paul Bakker | cd43a0b | 2011-06-09 13:55:44 +0000 | [diff] [blame] | 259 | size_t iv_offset = 0; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 260 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 261 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 262 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 263 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 264 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame^] | 265 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 ); |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 266 | TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 267 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 268 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 269 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 270 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 271 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 272 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 273 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 274 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 275 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 276 | void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 277 | data_t * src_str, data_t * dst ) |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 278 | { |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 279 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 280 | mbedtls_aes_context ctx; |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 281 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 282 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 283 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 284 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 285 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame^] | 286 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 ); |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 287 | TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 288 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 289 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, |
| 290 | src_str->len, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 291 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 292 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 293 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 294 | } |
| 295 | /* END_CASE */ |
| 296 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 297 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 298 | void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 299 | data_t * src_str, data_t * dst ) |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 300 | { |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 301 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 302 | mbedtls_aes_context ctx; |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 303 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 304 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 305 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 306 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 307 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame^] | 308 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 ); |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 309 | TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 310 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 311 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, |
| 312 | src_str->len, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 313 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 314 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 315 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 316 | } |
| 317 | /* END_CASE */ |
| 318 | |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 319 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */ |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 320 | void aes_encrypt_ofb( int fragment_size, data_t *key_str, |
| 321 | data_t *iv_str, data_t *src_str, |
Ronald Cron | 4bdc13f | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 322 | data_t *expected_output ) |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 323 | { |
Simon Butcher | e416bf9 | 2018-06-02 18:28:32 +0100 | [diff] [blame] | 324 | unsigned char output[32]; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 325 | mbedtls_aes_context ctx; |
| 326 | size_t iv_offset = 0; |
| 327 | int in_buffer_len; |
| 328 | unsigned char* src_str_next; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 329 | |
Simon Butcher | b7836e1 | 2018-06-02 18:36:49 +0100 | [diff] [blame] | 330 | memset( output, 0x00, sizeof( output ) ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 331 | mbedtls_aes_init( &ctx ); |
| 332 | |
Ronald Cron | b2eb38d | 2020-06-25 13:57:05 +0200 | [diff] [blame] | 333 | TEST_ASSERT( (size_t)fragment_size < sizeof( output ) ); |
Simon Butcher | e416bf9 | 2018-06-02 18:28:32 +0100 | [diff] [blame] | 334 | |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 335 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, |
| 336 | key_str->len * 8 ) == 0 ); |
| 337 | in_buffer_len = src_str->len; |
| 338 | src_str_next = src_str->x; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 339 | |
| 340 | while( in_buffer_len > 0 ) |
| 341 | { |
| 342 | TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset, |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 343 | iv_str->x, src_str_next, output ) == 0 ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 344 | |
Ronald Cron | 4bdc13f | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 345 | TEST_ASSERT( memcmp( output, expected_output->x, fragment_size ) == 0 ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 346 | |
| 347 | in_buffer_len -= fragment_size; |
Ronald Cron | 4bdc13f | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 348 | expected_output->x += fragment_size; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 349 | src_str_next += fragment_size; |
| 350 | |
| 351 | if( in_buffer_len < fragment_size ) |
| 352 | fragment_size = in_buffer_len; |
| 353 | } |
| 354 | |
| 355 | exit: |
| 356 | mbedtls_aes_free( &ctx ); |
| 357 | } |
| 358 | /* END_CASE */ |
| 359 | |
Manuel Pégourié-Gonnard | a2b0e27 | 2018-12-10 15:23:58 +0100 | [diff] [blame] | 360 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 361 | void aes_check_params( ) |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 362 | { |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 363 | mbedtls_aes_context aes_ctx; |
| 364 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 365 | mbedtls_aes_xts_context xts_ctx; |
| 366 | #endif |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 367 | const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 368 | const unsigned char in[16] = { 0 }; |
| 369 | unsigned char out[16]; |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 370 | size_t size; |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 371 | const int valid_mode = MBEDTLS_AES_ENCRYPT; |
| 372 | const int invalid_mode = 42; |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 373 | |
| 374 | TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 375 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 376 | TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 377 | #endif |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 378 | |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 379 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 380 | mbedtls_aes_setkey_enc( NULL, key, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 381 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 382 | mbedtls_aes_setkey_enc( &aes_ctx, NULL, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 383 | |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 384 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 385 | mbedtls_aes_setkey_dec( NULL, key, 128 ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 386 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 387 | mbedtls_aes_setkey_dec( &aes_ctx, NULL, 128 ) ); |
| 388 | |
| 389 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 390 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 391 | mbedtls_aes_xts_setkey_enc( NULL, key, 128 ) ); |
| 392 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 393 | mbedtls_aes_xts_setkey_enc( &xts_ctx, NULL, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 394 | |
| 395 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 396 | mbedtls_aes_xts_setkey_dec( NULL, key, 128 ) ); |
| 397 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 398 | mbedtls_aes_xts_setkey_dec( &xts_ctx, NULL, 128 ) ); |
| 399 | #endif |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 400 | |
| 401 | |
| 402 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 403 | mbedtls_aes_crypt_ecb( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 404 | valid_mode, in, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 405 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 406 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 407 | invalid_mode, in, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 408 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 409 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 410 | valid_mode, NULL, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 411 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 412 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 413 | valid_mode, in, NULL ) ); |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 414 | |
| 415 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 416 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 417 | mbedtls_aes_crypt_cbc( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 418 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 419 | out, in, out ) ); |
| 420 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 421 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 422 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 423 | out, in, out ) ); |
| 424 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 425 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 426 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 427 | NULL, in, out ) ); |
| 428 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 429 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 430 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 431 | out, NULL, out ) ); |
| 432 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 433 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 434 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 435 | out, in, NULL ) ); |
| 436 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 437 | |
| 438 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 439 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 440 | mbedtls_aes_crypt_xts( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 441 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 442 | in, in, out ) ); |
| 443 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 444 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 445 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 446 | in, in, out ) ); |
| 447 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 448 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 449 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 450 | NULL, in, out ) ); |
| 451 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 452 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 453 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 454 | in, NULL, out ) ); |
| 455 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 456 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 457 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 458 | in, in, NULL ) ); |
| 459 | #endif /* MBEDTLS_CIPHER_MODE_XTS */ |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 460 | |
| 461 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 462 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 463 | mbedtls_aes_crypt_cfb128( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 464 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 465 | &size, out, in, out ) ); |
| 466 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 467 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 468 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 469 | &size, out, in, out ) ); |
| 470 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 471 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 472 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 473 | NULL, out, in, out ) ); |
| 474 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 475 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 476 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 477 | &size, NULL, in, out ) ); |
| 478 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 479 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 480 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 481 | &size, out, NULL, out ) ); |
| 482 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 483 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 484 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 485 | &size, out, in, NULL ) ); |
| 486 | |
| 487 | |
| 488 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 489 | mbedtls_aes_crypt_cfb8( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 490 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 491 | out, in, out ) ); |
| 492 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 493 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 494 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 495 | out, in, out ) ); |
| 496 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 497 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 498 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 499 | NULL, in, out ) ); |
| 500 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 501 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 502 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 503 | out, NULL, out ) ); |
| 504 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 505 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 506 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 507 | out, in, NULL ) ); |
| 508 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Manuel Pégourié-Gonnard | 8e41eb7 | 2018-12-13 11:00:56 +0100 | [diff] [blame] | 509 | |
| 510 | #if defined(MBEDTLS_CIPHER_MODE_OFB) |
| 511 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 512 | mbedtls_aes_crypt_ofb( NULL, 16, |
| 513 | &size, out, in, out ) ); |
| 514 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 515 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 516 | NULL, out, in, out ) ); |
| 517 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 518 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 519 | &size, NULL, in, out ) ); |
| 520 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 521 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 522 | &size, out, NULL, out ) ); |
| 523 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 524 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 525 | &size, out, in, NULL ) ); |
| 526 | #endif /* MBEDTLS_CIPHER_MODE_OFB */ |
Manuel Pégourié-Gonnard | 2bc535b | 2018-12-13 11:08:36 +0100 | [diff] [blame] | 527 | |
| 528 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 529 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 530 | mbedtls_aes_crypt_ctr( NULL, 16, &size, out, |
| 531 | out, in, out ) ); |
| 532 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 533 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, NULL, out, |
| 534 | out, in, out ) ); |
| 535 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 536 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, NULL, |
| 537 | out, in, out ) ); |
| 538 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 539 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 540 | NULL, in, out ) ); |
| 541 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 542 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 543 | out, NULL, out ) ); |
| 544 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 545 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 546 | out, in, NULL ) ); |
| 547 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 548 | } |
| 549 | /* END_CASE */ |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 550 | |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 551 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 552 | void aes_misc_params( ) |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 553 | { |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 554 | #if defined(MBEDTLS_CIPHER_MODE_CBC) || \ |
| 555 | defined(MBEDTLS_CIPHER_MODE_XTS) || \ |
| 556 | defined(MBEDTLS_CIPHER_MODE_CFB) || \ |
| 557 | defined(MBEDTLS_CIPHER_MODE_OFB) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 558 | mbedtls_aes_context aes_ctx; |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 559 | const unsigned char in[16] = { 0 }; |
| 560 | unsigned char out[16]; |
| 561 | #endif |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 562 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 563 | mbedtls_aes_xts_context xts_ctx; |
| 564 | #endif |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 565 | #if defined(MBEDTLS_CIPHER_MODE_CFB) || \ |
| 566 | defined(MBEDTLS_CIPHER_MODE_OFB) |
Manuel Pégourié-Gonnard | e55e103 | 2018-12-18 12:09:02 +0100 | [diff] [blame] | 567 | size_t size; |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 568 | #endif |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 569 | |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 570 | /* These calls accept NULL */ |
| 571 | TEST_VALID_PARAM( mbedtls_aes_free( NULL ) ); |
Manuel Pégourié-Gonnard | af0c6cb | 2018-12-18 12:02:52 +0100 | [diff] [blame] | 572 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 573 | TEST_VALID_PARAM( mbedtls_aes_xts_free( NULL ) ); |
Manuel Pégourié-Gonnard | af0c6cb | 2018-12-18 12:02:52 +0100 | [diff] [blame] | 574 | #endif |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 575 | |
| 576 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 577 | TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 578 | 15, |
| 579 | out, in, out ) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 580 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 581 | TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 582 | 17, |
| 583 | out, in, out ) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 584 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 585 | #endif |
| 586 | |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 587 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 588 | TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT, |
| 589 | 15, |
| 590 | in, in, out ) |
| 591 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 592 | TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT, |
| 593 | (1 << 24) + 1, |
| 594 | in, in, out ) |
| 595 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 596 | #endif |
Manuel Pégourié-Gonnard | e55e103 | 2018-12-18 12:09:02 +0100 | [diff] [blame] | 597 | |
| 598 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 599 | size = 16; |
| 600 | TEST_ASSERT( mbedtls_aes_crypt_cfb128( &aes_ctx, MBEDTLS_AES_ENCRYPT, 16, |
| 601 | &size, out, in, out ) |
| 602 | == MBEDTLS_ERR_AES_BAD_INPUT_DATA ); |
| 603 | #endif |
| 604 | |
| 605 | #if defined(MBEDTLS_CIPHER_MODE_OFB) |
| 606 | size = 16; |
| 607 | TEST_ASSERT( mbedtls_aes_crypt_ofb( &aes_ctx, 16, &size, out, in, out ) |
| 608 | == MBEDTLS_ERR_AES_BAD_INPUT_DATA ); |
| 609 | #endif |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 610 | } |
| 611 | /* END_CASE */ |
| 612 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 613 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 614 | void aes_selftest( ) |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 615 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 616 | TEST_ASSERT( mbedtls_aes_self_test( 1 ) == 0 ); |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 617 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 618 | /* END_CASE */ |