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 ); |
JoeSubbiani | 2f28c6b | 2021-06-18 11:03:57 +0100 | [diff] [blame] | 211 | exit: |
| 212 | mbedtls_aes_xts_free( &ctx ); |
Jaeden Amero | 425382d | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 213 | } |
| 214 | /* END_CASE */ |
| 215 | |
Jaeden Amero | 142383e | 2018-05-31 10:40:34 +0100 | [diff] [blame] | 216 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */ |
| 217 | void aes_crypt_xts_keysize( int size, int retval ) |
| 218 | { |
| 219 | mbedtls_aes_xts_context ctx; |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 220 | const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; |
Jaeden Amero | 142383e | 2018-05-31 10:40:34 +0100 | [diff] [blame] | 221 | size_t key_len = size; |
| 222 | |
| 223 | mbedtls_aes_xts_init( &ctx ); |
| 224 | |
| 225 | TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == retval ); |
| 226 | TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == retval ); |
| 227 | exit: |
| 228 | mbedtls_aes_xts_free( &ctx ); |
| 229 | } |
| 230 | /* END_CASE */ |
Jaeden Amero | 425382d | 2018-04-28 17:26:25 +0100 | [diff] [blame] | 231 | |
| 232 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 233 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 234 | void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 235 | data_t * src_str, data_t * dst ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 236 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 237 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 238 | mbedtls_aes_context ctx; |
Paul Bakker | cd43a0b | 2011-06-09 13:55:44 +0000 | [diff] [blame] | 239 | size_t iv_offset = 0; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 240 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 241 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 242 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 243 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 244 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame] | 245 | 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] | 246 | 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] | 247 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 248 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 249 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 250 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 251 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 252 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 253 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 254 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 256 | void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 257 | data_t * src_str, data_t * dst ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 258 | { |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 259 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 260 | mbedtls_aes_context ctx; |
Paul Bakker | cd43a0b | 2011-06-09 13:55:44 +0000 | [diff] [blame] | 261 | size_t iv_offset = 0; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 262 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 263 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 264 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 265 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 266 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame] | 267 | 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] | 268 | 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] | 269 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 270 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 271 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 272 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 273 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 274 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 275 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 276 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 277 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 278 | void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 279 | data_t * src_str, data_t * dst ) |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 280 | { |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 281 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 282 | mbedtls_aes_context ctx; |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 283 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 284 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 285 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 286 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 287 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame] | 288 | 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] | 289 | 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] | 290 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 291 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, |
| 292 | src_str->len, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 293 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 294 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 295 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 296 | } |
| 297 | /* END_CASE */ |
| 298 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 299 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 300 | void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str, |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 301 | data_t * src_str, data_t * dst ) |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 302 | { |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 303 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 304 | mbedtls_aes_context ctx; |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 305 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 306 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 307 | mbedtls_aes_init( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 308 | |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 309 | |
Gilles Peskine | 621333f | 2021-07-07 21:08:28 +0200 | [diff] [blame] | 310 | 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] | 311 | 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] | 312 | |
Ronald Cron | aea41df | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 313 | TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, |
| 314 | src_str->len, dst->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 315 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 316 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 317 | mbedtls_aes_free( &ctx ); |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 318 | } |
| 319 | /* END_CASE */ |
| 320 | |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 321 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_OFB */ |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 322 | void aes_encrypt_ofb( int fragment_size, data_t *key_str, |
| 323 | data_t *iv_str, data_t *src_str, |
Ronald Cron | 4bdc13f | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 324 | data_t *expected_output ) |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 325 | { |
Simon Butcher | e416bf9 | 2018-06-02 18:28:32 +0100 | [diff] [blame] | 326 | unsigned char output[32]; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 327 | mbedtls_aes_context ctx; |
| 328 | size_t iv_offset = 0; |
| 329 | int in_buffer_len; |
| 330 | unsigned char* src_str_next; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 331 | |
Simon Butcher | b7836e1 | 2018-06-02 18:36:49 +0100 | [diff] [blame] | 332 | memset( output, 0x00, sizeof( output ) ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 333 | mbedtls_aes_init( &ctx ); |
| 334 | |
Ronald Cron | b2eb38d | 2020-06-25 13:57:05 +0200 | [diff] [blame] | 335 | TEST_ASSERT( (size_t)fragment_size < sizeof( output ) ); |
Simon Butcher | e416bf9 | 2018-06-02 18:28:32 +0100 | [diff] [blame] | 336 | |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 337 | TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, |
| 338 | key_str->len * 8 ) == 0 ); |
| 339 | in_buffer_len = src_str->len; |
| 340 | src_str_next = src_str->x; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 341 | |
| 342 | while( in_buffer_len > 0 ) |
| 343 | { |
| 344 | TEST_ASSERT( mbedtls_aes_crypt_ofb( &ctx, fragment_size, &iv_offset, |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 345 | iv_str->x, src_str_next, output ) == 0 ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 346 | |
Ronald Cron | 4bdc13f | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 347 | TEST_ASSERT( memcmp( output, expected_output->x, fragment_size ) == 0 ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 348 | |
| 349 | in_buffer_len -= fragment_size; |
Ronald Cron | 4bdc13f | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 350 | expected_output->x += fragment_size; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 351 | src_str_next += fragment_size; |
| 352 | |
| 353 | if( in_buffer_len < fragment_size ) |
| 354 | fragment_size = in_buffer_len; |
| 355 | } |
| 356 | |
| 357 | exit: |
| 358 | mbedtls_aes_free( &ctx ); |
| 359 | } |
| 360 | /* END_CASE */ |
| 361 | |
Manuel Pégourié-Gonnard | a2b0e27 | 2018-12-10 15:23:58 +0100 | [diff] [blame] | 362 | /* 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] | 363 | void aes_check_params( ) |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 364 | { |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 365 | mbedtls_aes_context aes_ctx; |
| 366 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 367 | mbedtls_aes_xts_context xts_ctx; |
| 368 | #endif |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 369 | const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 370 | const unsigned char in[16] = { 0 }; |
| 371 | unsigned char out[16]; |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 372 | size_t size; |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 373 | const int valid_mode = MBEDTLS_AES_ENCRYPT; |
| 374 | const int invalid_mode = 42; |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 375 | |
| 376 | TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 377 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 378 | TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 379 | #endif |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 380 | |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 381 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 382 | mbedtls_aes_setkey_enc( NULL, key, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 383 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 384 | mbedtls_aes_setkey_enc( &aes_ctx, NULL, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 385 | |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 386 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 387 | mbedtls_aes_setkey_dec( NULL, key, 128 ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 388 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 389 | mbedtls_aes_setkey_dec( &aes_ctx, NULL, 128 ) ); |
| 390 | |
| 391 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 392 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 393 | mbedtls_aes_xts_setkey_enc( NULL, key, 128 ) ); |
| 394 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 395 | mbedtls_aes_xts_setkey_enc( &xts_ctx, NULL, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 396 | |
| 397 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 398 | mbedtls_aes_xts_setkey_dec( NULL, key, 128 ) ); |
| 399 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 400 | mbedtls_aes_xts_setkey_dec( &xts_ctx, NULL, 128 ) ); |
| 401 | #endif |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 402 | |
| 403 | |
| 404 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 405 | mbedtls_aes_crypt_ecb( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 406 | valid_mode, in, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 407 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 408 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 409 | invalid_mode, in, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 410 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 411 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 412 | valid_mode, NULL, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 413 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 414 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 415 | valid_mode, in, NULL ) ); |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 416 | |
| 417 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 418 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 419 | mbedtls_aes_crypt_cbc( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 420 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 421 | out, in, out ) ); |
| 422 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 423 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 424 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 425 | out, in, out ) ); |
| 426 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 427 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 428 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 429 | NULL, in, out ) ); |
| 430 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 431 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 432 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 433 | out, NULL, out ) ); |
| 434 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 435 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 436 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 437 | out, in, NULL ) ); |
| 438 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 439 | |
| 440 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 441 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 442 | mbedtls_aes_crypt_xts( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 443 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 444 | in, in, out ) ); |
| 445 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 446 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 447 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 448 | in, in, out ) ); |
| 449 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 450 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 451 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 452 | NULL, in, out ) ); |
| 453 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 454 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 455 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 456 | in, NULL, out ) ); |
| 457 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 458 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 459 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 460 | in, in, NULL ) ); |
| 461 | #endif /* MBEDTLS_CIPHER_MODE_XTS */ |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 462 | |
| 463 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 464 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 465 | mbedtls_aes_crypt_cfb128( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 466 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 467 | &size, out, in, out ) ); |
| 468 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 469 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 470 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 471 | &size, out, in, out ) ); |
| 472 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 473 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 474 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 475 | NULL, out, in, out ) ); |
| 476 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 477 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 478 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 479 | &size, NULL, in, out ) ); |
| 480 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 481 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 482 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 483 | &size, out, NULL, out ) ); |
| 484 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 485 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 486 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 487 | &size, out, in, NULL ) ); |
| 488 | |
| 489 | |
| 490 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 491 | mbedtls_aes_crypt_cfb8( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 492 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 493 | out, in, out ) ); |
| 494 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 495 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 496 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 497 | out, in, out ) ); |
| 498 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 499 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 500 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 501 | NULL, in, out ) ); |
| 502 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 503 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 504 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 505 | out, NULL, out ) ); |
| 506 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 507 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 508 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 509 | out, in, NULL ) ); |
| 510 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Manuel Pégourié-Gonnard | 8e41eb7 | 2018-12-13 11:00:56 +0100 | [diff] [blame] | 511 | |
| 512 | #if defined(MBEDTLS_CIPHER_MODE_OFB) |
| 513 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 514 | mbedtls_aes_crypt_ofb( NULL, 16, |
| 515 | &size, out, in, out ) ); |
| 516 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 517 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 518 | NULL, out, in, out ) ); |
| 519 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 520 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 521 | &size, NULL, in, out ) ); |
| 522 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 523 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 524 | &size, out, NULL, out ) ); |
| 525 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 526 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 527 | &size, out, in, NULL ) ); |
| 528 | #endif /* MBEDTLS_CIPHER_MODE_OFB */ |
Manuel Pégourié-Gonnard | 2bc535b | 2018-12-13 11:08:36 +0100 | [diff] [blame] | 529 | |
| 530 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 531 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 532 | mbedtls_aes_crypt_ctr( NULL, 16, &size, out, |
| 533 | out, in, out ) ); |
| 534 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 535 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, NULL, out, |
| 536 | out, in, out ) ); |
| 537 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 538 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, NULL, |
| 539 | out, in, out ) ); |
| 540 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 541 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 542 | NULL, in, out ) ); |
| 543 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 544 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 545 | out, NULL, out ) ); |
| 546 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 547 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 548 | out, in, NULL ) ); |
| 549 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 550 | } |
| 551 | /* END_CASE */ |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 552 | |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 553 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 554 | void aes_misc_params( ) |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 555 | { |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 556 | #if defined(MBEDTLS_CIPHER_MODE_CBC) || \ |
| 557 | defined(MBEDTLS_CIPHER_MODE_XTS) || \ |
| 558 | defined(MBEDTLS_CIPHER_MODE_CFB) || \ |
| 559 | defined(MBEDTLS_CIPHER_MODE_OFB) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 560 | mbedtls_aes_context aes_ctx; |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 561 | const unsigned char in[16] = { 0 }; |
| 562 | unsigned char out[16]; |
| 563 | #endif |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 564 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 565 | mbedtls_aes_xts_context xts_ctx; |
| 566 | #endif |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 567 | #if defined(MBEDTLS_CIPHER_MODE_CFB) || \ |
| 568 | defined(MBEDTLS_CIPHER_MODE_OFB) |
Manuel Pégourié-Gonnard | e55e103 | 2018-12-18 12:09:02 +0100 | [diff] [blame] | 569 | size_t size; |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 570 | #endif |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 571 | |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 572 | /* These calls accept NULL */ |
| 573 | TEST_VALID_PARAM( mbedtls_aes_free( NULL ) ); |
Manuel Pégourié-Gonnard | af0c6cb | 2018-12-18 12:02:52 +0100 | [diff] [blame] | 574 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 575 | TEST_VALID_PARAM( mbedtls_aes_xts_free( NULL ) ); |
Manuel Pégourié-Gonnard | af0c6cb | 2018-12-18 12:02:52 +0100 | [diff] [blame] | 576 | #endif |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 577 | |
| 578 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 579 | 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] | 580 | 15, |
| 581 | out, in, out ) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 582 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 583 | 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] | 584 | 17, |
| 585 | out, in, out ) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 586 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 587 | #endif |
| 588 | |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 589 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 590 | TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT, |
| 591 | 15, |
| 592 | in, in, out ) |
| 593 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 594 | TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT, |
| 595 | (1 << 24) + 1, |
| 596 | in, in, out ) |
| 597 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 598 | #endif |
Manuel Pégourié-Gonnard | e55e103 | 2018-12-18 12:09:02 +0100 | [diff] [blame] | 599 | |
| 600 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 601 | size = 16; |
| 602 | TEST_ASSERT( mbedtls_aes_crypt_cfb128( &aes_ctx, MBEDTLS_AES_ENCRYPT, 16, |
| 603 | &size, out, in, out ) |
| 604 | == MBEDTLS_ERR_AES_BAD_INPUT_DATA ); |
| 605 | #endif |
| 606 | |
| 607 | #if defined(MBEDTLS_CIPHER_MODE_OFB) |
| 608 | size = 16; |
| 609 | TEST_ASSERT( mbedtls_aes_crypt_ofb( &aes_ctx, 16, &size, out, in, out ) |
| 610 | == MBEDTLS_ERR_AES_BAD_INPUT_DATA ); |
| 611 | #endif |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 612 | } |
| 613 | /* END_CASE */ |
| 614 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 615 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 616 | void aes_selftest( ) |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 617 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 618 | TEST_ASSERT( mbedtls_aes_self_test( 1 ) == 0 ); |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 619 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 620 | /* END_CASE */ |