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