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 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 70 | mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 71 | TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); |
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 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 95 | mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); |
| 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 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 243 | mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 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 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 265 | mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 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 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 286 | mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 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 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 308 | mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 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, |
| 322 | char *expected_output_string) |
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]; |
Ronald Cron | b2eb38d | 2020-06-25 13:57:05 +0200 | [diff] [blame] | 325 | unsigned char output_string[65]; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 326 | mbedtls_aes_context ctx; |
| 327 | size_t iv_offset = 0; |
| 328 | int in_buffer_len; |
| 329 | unsigned char* src_str_next; |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 330 | |
Simon Butcher | b7836e1 | 2018-06-02 18:36:49 +0100 | [diff] [blame] | 331 | memset( output, 0x00, sizeof( output ) ); |
Ronald Cron | b2eb38d | 2020-06-25 13:57:05 +0200 | [diff] [blame] | 332 | memset( output_string, 0x00, sizeof( output_string ) ); |
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 | b2eb38d | 2020-06-25 13:57:05 +0200 | [diff] [blame] | 347 | mbedtls_test_hexify( output_string, output, fragment_size ); |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 348 | TEST_ASSERT( strncmp( (char *) output_string, expected_output_string, |
Simon Butcher | 0013144 | 2018-05-22 22:40:36 +0100 | [diff] [blame] | 349 | ( 2 * fragment_size ) ) == 0 ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 350 | |
| 351 | in_buffer_len -= fragment_size; |
Ronald Cron | 14a5645 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 352 | expected_output_string += ( fragment_size * 2 ); |
Simon Butcher | 0301884 | 2018-04-22 22:57:58 +0100 | [diff] [blame] | 353 | src_str_next += fragment_size; |
| 354 | |
| 355 | if( in_buffer_len < fragment_size ) |
| 356 | fragment_size = in_buffer_len; |
| 357 | } |
| 358 | |
| 359 | exit: |
| 360 | mbedtls_aes_free( &ctx ); |
| 361 | } |
| 362 | /* END_CASE */ |
| 363 | |
Manuel Pégourié-Gonnard | a2b0e27 | 2018-12-10 15:23:58 +0100 | [diff] [blame] | 364 | /* 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] | 365 | void aes_check_params( ) |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 366 | { |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 367 | mbedtls_aes_context aes_ctx; |
| 368 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 369 | mbedtls_aes_xts_context xts_ctx; |
| 370 | #endif |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 371 | const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 372 | const unsigned char in[16] = { 0 }; |
| 373 | unsigned char out[16]; |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 374 | size_t size; |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 375 | const int valid_mode = MBEDTLS_AES_ENCRYPT; |
| 376 | const int invalid_mode = 42; |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 377 | |
| 378 | TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 379 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 380 | TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 381 | #endif |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 382 | |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 383 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 384 | mbedtls_aes_setkey_enc( NULL, key, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 385 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 386 | mbedtls_aes_setkey_enc( &aes_ctx, NULL, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 387 | |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 388 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 389 | mbedtls_aes_setkey_dec( NULL, key, 128 ) ); |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 390 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 391 | mbedtls_aes_setkey_dec( &aes_ctx, NULL, 128 ) ); |
| 392 | |
| 393 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 394 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 395 | mbedtls_aes_xts_setkey_enc( NULL, key, 128 ) ); |
| 396 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 397 | mbedtls_aes_xts_setkey_enc( &xts_ctx, NULL, 128 ) ); |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 398 | |
| 399 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
Manuel Pégourié-Gonnard | 68e3dff | 2018-12-12 12:48:04 +0100 | [diff] [blame] | 400 | mbedtls_aes_xts_setkey_dec( NULL, key, 128 ) ); |
| 401 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 402 | mbedtls_aes_xts_setkey_dec( &xts_ctx, NULL, 128 ) ); |
| 403 | #endif |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 404 | |
| 405 | |
| 406 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 407 | mbedtls_aes_crypt_ecb( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 408 | valid_mode, in, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 409 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 410 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 411 | invalid_mode, in, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 412 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 413 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 414 | valid_mode, NULL, out ) ); |
Manuel Pégourié-Gonnard | 1aca260 | 2018-12-12 12:56:55 +0100 | [diff] [blame] | 415 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 416 | mbedtls_aes_crypt_ecb( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 417 | valid_mode, in, NULL ) ); |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 418 | |
| 419 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 420 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 421 | mbedtls_aes_crypt_cbc( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 422 | valid_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 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 427 | out, 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 | NULL, in, 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, NULL, out ) ); |
| 436 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 437 | mbedtls_aes_crypt_cbc( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 438 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 439 | out, in, NULL ) ); |
| 440 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 441 | |
| 442 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 443 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 444 | mbedtls_aes_crypt_xts( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 445 | valid_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 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 450 | in, 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 | NULL, in, 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, NULL, out ) ); |
| 459 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 460 | mbedtls_aes_crypt_xts( &xts_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 461 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 462 | in, in, NULL ) ); |
| 463 | #endif /* MBEDTLS_CIPHER_MODE_XTS */ |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 464 | |
| 465 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 466 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 467 | mbedtls_aes_crypt_cfb128( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 468 | valid_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 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 473 | &size, 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 | NULL, out, 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, NULL, in, 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, NULL, out ) ); |
| 486 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 487 | mbedtls_aes_crypt_cfb128( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 488 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 489 | &size, out, in, NULL ) ); |
| 490 | |
| 491 | |
| 492 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 493 | mbedtls_aes_crypt_cfb8( NULL, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 494 | valid_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 | invalid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 499 | out, 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 | NULL, in, 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, NULL, out ) ); |
| 508 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 509 | mbedtls_aes_crypt_cfb8( &aes_ctx, |
Manuel Pégourié-Gonnard | ab6b975 | 2018-12-18 09:58:18 +0100 | [diff] [blame] | 510 | valid_mode, 16, |
Manuel Pégourié-Gonnard | 1677cca | 2018-12-13 10:27:13 +0100 | [diff] [blame] | 511 | out, in, NULL ) ); |
| 512 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Manuel Pégourié-Gonnard | 8e41eb7 | 2018-12-13 11:00:56 +0100 | [diff] [blame] | 513 | |
| 514 | #if defined(MBEDTLS_CIPHER_MODE_OFB) |
| 515 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 516 | mbedtls_aes_crypt_ofb( NULL, 16, |
| 517 | &size, out, in, out ) ); |
| 518 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 519 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 520 | NULL, out, in, out ) ); |
| 521 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 522 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 523 | &size, NULL, in, out ) ); |
| 524 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 525 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 526 | &size, out, NULL, out ) ); |
| 527 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 528 | mbedtls_aes_crypt_ofb( &aes_ctx, 16, |
| 529 | &size, out, in, NULL ) ); |
| 530 | #endif /* MBEDTLS_CIPHER_MODE_OFB */ |
Manuel Pégourié-Gonnard | 2bc535b | 2018-12-13 11:08:36 +0100 | [diff] [blame] | 531 | |
| 532 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 533 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 534 | mbedtls_aes_crypt_ctr( NULL, 16, &size, out, |
| 535 | out, in, out ) ); |
| 536 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 537 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, NULL, out, |
| 538 | out, in, out ) ); |
| 539 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 540 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, NULL, |
| 541 | out, in, out ) ); |
| 542 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 543 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 544 | NULL, in, out ) ); |
| 545 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 546 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 547 | out, NULL, out ) ); |
| 548 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA, |
| 549 | mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out, |
| 550 | out, in, NULL ) ); |
| 551 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 552 | } |
| 553 | /* END_CASE */ |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 554 | |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 555 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 556 | void aes_misc_params( ) |
Manuel Pégourié-Gonnard | a4251f4 | 2018-12-12 12:04:51 +0100 | [diff] [blame] | 557 | { |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 558 | #if defined(MBEDTLS_CIPHER_MODE_CBC) || \ |
| 559 | defined(MBEDTLS_CIPHER_MODE_XTS) || \ |
| 560 | defined(MBEDTLS_CIPHER_MODE_CFB) || \ |
| 561 | defined(MBEDTLS_CIPHER_MODE_OFB) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 562 | mbedtls_aes_context aes_ctx; |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 563 | const unsigned char in[16] = { 0 }; |
| 564 | unsigned char out[16]; |
| 565 | #endif |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 566 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 567 | mbedtls_aes_xts_context xts_ctx; |
| 568 | #endif |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 569 | #if defined(MBEDTLS_CIPHER_MODE_CFB) || \ |
| 570 | defined(MBEDTLS_CIPHER_MODE_OFB) |
Manuel Pégourié-Gonnard | e55e103 | 2018-12-18 12:09:02 +0100 | [diff] [blame] | 571 | size_t size; |
Manuel Pégourié-Gonnard | 488d930 | 2018-12-18 13:05:49 +0100 | [diff] [blame] | 572 | #endif |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 573 | |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 574 | /* These calls accept NULL */ |
| 575 | TEST_VALID_PARAM( mbedtls_aes_free( NULL ) ); |
Manuel Pégourié-Gonnard | af0c6cb | 2018-12-18 12:02:52 +0100 | [diff] [blame] | 576 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
Manuel Pégourié-Gonnard | 44c5d58 | 2018-12-10 16:56:14 +0100 | [diff] [blame] | 577 | TEST_VALID_PARAM( mbedtls_aes_xts_free( NULL ) ); |
Manuel Pégourié-Gonnard | af0c6cb | 2018-12-18 12:02:52 +0100 | [diff] [blame] | 578 | #endif |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 579 | |
| 580 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 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 | 15, |
| 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 | 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] | 586 | 17, |
| 587 | out, in, out ) |
Manuel Pégourié-Gonnard | 3178d1a | 2018-12-12 13:05:00 +0100 | [diff] [blame] | 588 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 589 | #endif |
| 590 | |
Manuel Pégourié-Gonnard | 191af13 | 2018-12-13 10:15:30 +0100 | [diff] [blame] | 591 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 592 | TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT, |
| 593 | 15, |
| 594 | in, in, out ) |
| 595 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 596 | TEST_ASSERT( mbedtls_aes_crypt_xts( &xts_ctx, MBEDTLS_AES_ENCRYPT, |
| 597 | (1 << 24) + 1, |
| 598 | in, in, out ) |
| 599 | == MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); |
| 600 | #endif |
Manuel Pégourié-Gonnard | e55e103 | 2018-12-18 12:09:02 +0100 | [diff] [blame] | 601 | |
| 602 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 603 | size = 16; |
| 604 | TEST_ASSERT( mbedtls_aes_crypt_cfb128( &aes_ctx, MBEDTLS_AES_ENCRYPT, 16, |
| 605 | &size, out, in, out ) |
| 606 | == MBEDTLS_ERR_AES_BAD_INPUT_DATA ); |
| 607 | #endif |
| 608 | |
| 609 | #if defined(MBEDTLS_CIPHER_MODE_OFB) |
| 610 | size = 16; |
| 611 | TEST_ASSERT( mbedtls_aes_crypt_ofb( &aes_ctx, 16, &size, out, in, out ) |
| 612 | == MBEDTLS_ERR_AES_BAD_INPUT_DATA ); |
| 613 | #endif |
Simon Butcher | a646345 | 2018-12-06 17:41:56 +0000 | [diff] [blame] | 614 | } |
| 615 | /* END_CASE */ |
| 616 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 617 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 618 | void aes_selftest( ) |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 619 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 620 | TEST_ASSERT( mbedtls_aes_self_test( 1 ) == 0 ); |
Paul Bakker | 3d36082 | 2009-07-05 11:29:38 +0000 | [diff] [blame] | 621 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 622 | /* END_CASE */ |