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/gcm.h" |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 3 | |
| 4 | /* Use the multipart interface to process the encrypted data in two parts |
| 5 | * and check that the output matches the expected output. |
| 6 | * The context must have been set up with the key. */ |
| 7 | static int check_multipart( mbedtls_gcm_context *ctx, |
| 8 | int mode, |
| 9 | const data_t *iv, |
| 10 | const data_t *add, |
| 11 | const data_t *input, |
| 12 | const data_t *expected_output, |
| 13 | const data_t *tag, |
| 14 | size_t n1 ) |
| 15 | { |
| 16 | int ok = 0; |
| 17 | uint8_t *output = NULL; |
| 18 | size_t n2 = input->len - n1; |
| 19 | |
| 20 | /* Sanity checks on the test data */ |
| 21 | TEST_ASSERT( n1 <= input->len ); |
| 22 | TEST_EQUAL( input->len, expected_output->len ); |
| 23 | |
| 24 | TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode, |
| 25 | iv->x, iv->len, |
| 26 | add->x, add->len ) ); |
| 27 | |
| 28 | /* Allocate a tight buffer for each update call. This way, if the function |
| 29 | * tries to write beyond the advertised required buffer size, this will |
| 30 | * count as an overflow for memory sanitizers and static checkers. */ |
| 31 | ASSERT_ALLOC( output, n1 ); |
| 32 | TEST_EQUAL( 0, mbedtls_gcm_update( ctx, n1, input->x, output ) ); |
| 33 | ASSERT_COMPARE( output, n1, expected_output->x, n1 ); |
| 34 | mbedtls_free( output ); |
| 35 | output = NULL; |
| 36 | |
| 37 | ASSERT_ALLOC( output, n2 ); |
| 38 | TEST_EQUAL( 0, mbedtls_gcm_update( ctx, n2, input->x + n1, output ) ); |
| 39 | ASSERT_COMPARE( output, n2, expected_output->x + n1, n2 ); |
| 40 | mbedtls_free( output ); |
| 41 | output = NULL; |
| 42 | |
| 43 | ASSERT_ALLOC( output, tag->len ); |
| 44 | TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, output, tag->len ) ); |
| 45 | ASSERT_COMPARE( output, tag->len, tag->x, tag->len ); |
| 46 | mbedtls_free( output ); |
| 47 | output = NULL; |
| 48 | |
| 49 | ok = 1; |
| 50 | exit: |
| 51 | mbedtls_free( output ); |
| 52 | return( ok ); |
| 53 | } |
| 54 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 55 | /* END_HEADER */ |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 56 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 57 | /* BEGIN_DEPENDENCIES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | * depends_on:MBEDTLS_GCM_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 59 | * END_DEPENDENCIES |
| 60 | */ |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 61 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 62 | /* BEGIN_CASE */ |
Ron Eldor | 5a21fd6 | 2016-12-16 16:15:56 +0200 | [diff] [blame] | 63 | void gcm_bad_parameters( int cipher_id, int direction, |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 64 | data_t *key_str, data_t *src_str, |
| 65 | data_t *iv_str, data_t *add_str, |
Ron Eldor | 5a21fd6 | 2016-12-16 16:15:56 +0200 | [diff] [blame] | 66 | int tag_len_bits, int gcm_result ) |
| 67 | { |
Ron Eldor | 5a21fd6 | 2016-12-16 16:15:56 +0200 | [diff] [blame] | 68 | unsigned char output[128]; |
| 69 | unsigned char tag_output[16]; |
| 70 | mbedtls_gcm_context ctx; |
Azim Khan | 317efe8 | 2017-08-02 17:33:54 +0100 | [diff] [blame] | 71 | size_t tag_len = tag_len_bits / 8; |
Ron Eldor | 5a21fd6 | 2016-12-16 16:15:56 +0200 | [diff] [blame] | 72 | |
| 73 | mbedtls_gcm_init( &ctx ); |
| 74 | |
Ron Eldor | 5a21fd6 | 2016-12-16 16:15:56 +0200 | [diff] [blame] | 75 | memset( output, 0x00, sizeof( output ) ); |
| 76 | memset( tag_output, 0x00, sizeof( tag_output ) ); |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 77 | |
Azim Khan | 317efe8 | 2017-08-02 17:33:54 +0100 | [diff] [blame] | 78 | TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 ); |
| 79 | TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, direction, src_str->len, iv_str->x, iv_str->len, |
| 80 | add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == gcm_result ); |
Ron Eldor | 5a21fd6 | 2016-12-16 16:15:56 +0200 | [diff] [blame] | 81 | |
| 82 | exit: |
| 83 | mbedtls_gcm_free( &ctx ); |
| 84 | } |
| 85 | /* END_CASE */ |
| 86 | |
| 87 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 88 | void gcm_encrypt_and_tag( int cipher_id, data_t * key_str, |
| 89 | data_t * src_str, data_t * iv_str, |
Ronald Cron | ac6ae35 | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 90 | data_t * add_str, data_t * dst, |
| 91 | int tag_len_bits, data_t * tag, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 92 | int init_result ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 93 | { |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 94 | unsigned char output[128]; |
| 95 | unsigned char tag_output[16]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 96 | mbedtls_gcm_context ctx; |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 97 | size_t tag_len = tag_len_bits / 8; |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 98 | size_t n1; |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 99 | |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 100 | mbedtls_gcm_init( &ctx ); |
| 101 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 102 | memset(output, 0x00, 128); |
| 103 | memset(tag_output, 0x00, 16); |
| 104 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 105 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 106 | TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 107 | if( init_result == 0 ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 108 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 109 | TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == 0 ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 110 | |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 111 | ASSERT_COMPARE( output, src_str->len, dst->x, dst->len ); |
| 112 | ASSERT_COMPARE( tag_output, tag_len, tag->x, tag->len ); |
| 113 | |
Gilles Peskine | 58fc272 | 2021-04-13 15:58:27 +0200 | [diff] [blame^] | 114 | for( n1 = 0; n1 <= src_str->len; n1 += 1 ) |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 115 | { |
| 116 | mbedtls_test_set_step( n1 ); |
| 117 | if( !check_multipart( &ctx, MBEDTLS_GCM_ENCRYPT, |
| 118 | iv_str, add_str, src_str, |
| 119 | dst, tag, |
| 120 | n1 ) ) |
| 121 | goto exit; |
| 122 | } |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 123 | } |
Manuel Pégourié-Gonnard | 4fe9200 | 2013-09-13 13:45:58 +0200 | [diff] [blame] | 124 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 125 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 126 | mbedtls_gcm_free( &ctx ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 127 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 128 | /* END_CASE */ |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 129 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 130 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 131 | void gcm_decrypt_and_verify( int cipher_id, data_t * key_str, |
| 132 | data_t * src_str, data_t * iv_str, |
| 133 | data_t * add_str, int tag_len_bits, |
| 134 | data_t * tag_str, char * result, |
| 135 | data_t * pt_result, int init_result ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 136 | { |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 137 | unsigned char output[128]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 138 | mbedtls_gcm_context ctx; |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 139 | int ret; |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 140 | size_t tag_len = tag_len_bits / 8; |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 141 | size_t n1; |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 142 | |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 143 | mbedtls_gcm_init( &ctx ); |
| 144 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 145 | memset(output, 0x00, 128); |
| 146 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 147 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 148 | TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 149 | if( init_result == 0 ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 150 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 151 | ret = mbedtls_gcm_auth_decrypt( &ctx, src_str->len, iv_str->x, iv_str->len, add_str->x, add_str->len, tag_str->x, tag_len, src_str->x, output ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 152 | |
Azim Khan | 46c9b1f | 2017-05-31 20:46:35 +0100 | [diff] [blame] | 153 | if( strcmp( "FAIL", result ) == 0 ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 154 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 155 | TEST_ASSERT( ret == MBEDTLS_ERR_GCM_AUTH_FAILED ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 156 | } |
| 157 | else |
| 158 | { |
Manuel Pégourié-Gonnard | f7ce67f | 2013-09-03 20:17:35 +0200 | [diff] [blame] | 159 | TEST_ASSERT( ret == 0 ); |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 160 | ASSERT_COMPARE( output, src_str->len, pt_result->x, pt_result->len ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 161 | |
Gilles Peskine | 58fc272 | 2021-04-13 15:58:27 +0200 | [diff] [blame^] | 162 | for( n1 = 0; n1 <= src_str->len; n1 += 1 ) |
Gilles Peskine | 36dd93e | 2021-04-13 13:02:03 +0200 | [diff] [blame] | 163 | { |
| 164 | mbedtls_test_set_step( n1 ); |
| 165 | if( !check_multipart( &ctx, MBEDTLS_GCM_DECRYPT, |
| 166 | iv_str, add_str, src_str, |
| 167 | pt_result, tag_str, |
| 168 | n1 ) ) |
| 169 | goto exit; |
| 170 | } |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
Manuel Pégourié-Gonnard | 4fe9200 | 2013-09-13 13:45:58 +0200 | [diff] [blame] | 173 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 174 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 175 | mbedtls_gcm_free( &ctx ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 176 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 177 | /* END_CASE */ |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 178 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 179 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
| 180 | void gcm_invalid_param( ) |
| 181 | { |
| 182 | mbedtls_gcm_context ctx; |
| 183 | unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; |
| 184 | mbedtls_cipher_id_t valid_cipher = MBEDTLS_CIPHER_ID_AES; |
| 185 | int valid_mode = MBEDTLS_GCM_ENCRYPT; |
| 186 | int valid_len = sizeof(valid_buffer); |
| 187 | int valid_bitlen = 128, invalid_bitlen = 1; |
| 188 | |
| 189 | mbedtls_gcm_init( &ctx ); |
| 190 | |
| 191 | /* mbedtls_gcm_init() */ |
| 192 | TEST_INVALID_PARAM( mbedtls_gcm_init( NULL ) ); |
| 193 | |
| 194 | /* mbedtls_gcm_setkey */ |
| 195 | TEST_INVALID_PARAM_RET( |
| 196 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 197 | mbedtls_gcm_setkey( NULL, valid_cipher, valid_buffer, valid_bitlen ) ); |
| 198 | TEST_INVALID_PARAM_RET( |
| 199 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 200 | mbedtls_gcm_setkey( &ctx, valid_cipher, NULL, valid_bitlen ) ); |
| 201 | TEST_INVALID_PARAM_RET( |
| 202 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 203 | mbedtls_gcm_setkey( &ctx, valid_cipher, valid_buffer, invalid_bitlen ) ); |
| 204 | |
| 205 | /* mbedtls_gcm_crypt_and_tag() */ |
| 206 | TEST_INVALID_PARAM_RET( |
| 207 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 208 | mbedtls_gcm_crypt_and_tag( NULL, valid_mode, valid_len, |
| 209 | valid_buffer, valid_len, |
| 210 | valid_buffer, valid_len, |
| 211 | valid_buffer, valid_buffer, |
| 212 | valid_len, valid_buffer ) ); |
| 213 | TEST_INVALID_PARAM_RET( |
| 214 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 215 | mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len, |
| 216 | NULL, valid_len, |
| 217 | valid_buffer, valid_len, |
| 218 | valid_buffer, valid_buffer, |
| 219 | valid_len, valid_buffer ) ); |
| 220 | TEST_INVALID_PARAM_RET( |
| 221 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 222 | mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len, |
| 223 | valid_buffer, valid_len, |
| 224 | NULL, valid_len, |
| 225 | valid_buffer, valid_buffer, |
| 226 | valid_len, valid_buffer ) ); |
| 227 | TEST_INVALID_PARAM_RET( |
| 228 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 229 | mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len, |
| 230 | valid_buffer, valid_len, |
| 231 | valid_buffer, valid_len, |
| 232 | NULL, valid_buffer, |
| 233 | valid_len, valid_buffer ) ); |
| 234 | TEST_INVALID_PARAM_RET( |
| 235 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 236 | mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len, |
| 237 | valid_buffer, valid_len, |
| 238 | valid_buffer, valid_len, |
| 239 | valid_buffer, NULL, |
| 240 | valid_len, valid_buffer ) ); |
| 241 | TEST_INVALID_PARAM_RET( |
| 242 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 243 | mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len, |
| 244 | valid_buffer, valid_len, |
| 245 | valid_buffer, valid_len, |
| 246 | valid_buffer, valid_buffer, |
| 247 | valid_len, NULL ) ); |
| 248 | |
| 249 | /* mbedtls_gcm_auth_decrypt() */ |
| 250 | TEST_INVALID_PARAM_RET( |
| 251 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 252 | mbedtls_gcm_auth_decrypt( NULL, valid_len, |
| 253 | valid_buffer, valid_len, |
| 254 | valid_buffer, valid_len, |
| 255 | valid_buffer, valid_len, |
| 256 | valid_buffer, valid_buffer) ); |
| 257 | TEST_INVALID_PARAM_RET( |
| 258 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 259 | mbedtls_gcm_auth_decrypt( &ctx, valid_len, |
| 260 | NULL, valid_len, |
| 261 | valid_buffer, valid_len, |
| 262 | valid_buffer, valid_len, |
| 263 | valid_buffer, valid_buffer) ); |
| 264 | TEST_INVALID_PARAM_RET( |
| 265 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 266 | mbedtls_gcm_auth_decrypt( &ctx, valid_len, |
| 267 | valid_buffer, valid_len, |
| 268 | NULL, valid_len, |
| 269 | valid_buffer, valid_len, |
| 270 | valid_buffer, valid_buffer) ); |
| 271 | TEST_INVALID_PARAM_RET( |
| 272 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 273 | mbedtls_gcm_auth_decrypt( &ctx, valid_len, |
| 274 | valid_buffer, valid_len, |
| 275 | valid_buffer, valid_len, |
| 276 | NULL, valid_len, |
| 277 | valid_buffer, valid_buffer) ); |
| 278 | TEST_INVALID_PARAM_RET( |
| 279 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 280 | mbedtls_gcm_auth_decrypt( &ctx, valid_len, |
| 281 | valid_buffer, valid_len, |
| 282 | valid_buffer, valid_len, |
| 283 | valid_buffer, valid_len, |
| 284 | NULL, valid_buffer) ); |
| 285 | TEST_INVALID_PARAM_RET( |
| 286 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 287 | mbedtls_gcm_auth_decrypt( &ctx, valid_len, |
| 288 | valid_buffer, valid_len, |
| 289 | valid_buffer, valid_len, |
| 290 | valid_buffer, valid_len, |
| 291 | valid_buffer, NULL) ); |
| 292 | |
| 293 | /* mbedtls_gcm_starts() */ |
| 294 | TEST_INVALID_PARAM_RET( |
| 295 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 296 | mbedtls_gcm_starts( NULL, valid_mode, |
| 297 | valid_buffer, valid_len, |
| 298 | valid_buffer, valid_len ) ); |
| 299 | |
| 300 | TEST_INVALID_PARAM_RET( |
| 301 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 302 | mbedtls_gcm_starts( &ctx, valid_mode, |
| 303 | NULL, valid_len, |
| 304 | valid_buffer, valid_len ) ); |
| 305 | |
| 306 | TEST_INVALID_PARAM_RET( |
| 307 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 308 | mbedtls_gcm_starts( &ctx, valid_mode, |
| 309 | valid_buffer, valid_len, |
| 310 | NULL, valid_len ) ); |
| 311 | |
| 312 | /* mbedtls_gcm_update() */ |
| 313 | TEST_INVALID_PARAM_RET( |
| 314 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 315 | mbedtls_gcm_update( NULL, valid_len, |
| 316 | valid_buffer, valid_buffer ) ); |
| 317 | TEST_INVALID_PARAM_RET( |
| 318 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 319 | mbedtls_gcm_update( &ctx, valid_len, |
| 320 | NULL, valid_buffer ) ); |
| 321 | TEST_INVALID_PARAM_RET( |
| 322 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 323 | mbedtls_gcm_update( &ctx, valid_len, |
| 324 | valid_buffer, NULL ) ); |
| 325 | |
| 326 | /* mbedtls_gcm_finish() */ |
| 327 | TEST_INVALID_PARAM_RET( |
| 328 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 329 | mbedtls_gcm_finish( NULL, valid_buffer, valid_len ) ); |
| 330 | TEST_INVALID_PARAM_RET( |
| 331 | MBEDTLS_ERR_GCM_BAD_INPUT, |
| 332 | mbedtls_gcm_finish( &ctx, NULL, valid_len ) ); |
| 333 | |
| 334 | exit: |
| 335 | mbedtls_gcm_free( &ctx ); |
| 336 | } |
| 337 | /* END_CASE */ |
| 338 | |
| 339 | /* BEGIN_CASE */ |
| 340 | void gcm_valid_param( ) |
| 341 | { |
| 342 | TEST_VALID_PARAM( mbedtls_gcm_free( NULL ) ); |
| 343 | exit: |
| 344 | return; |
| 345 | } |
| 346 | /* END_CASE */ |
| 347 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 348 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 349 | void gcm_selftest( ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 350 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 351 | TEST_ASSERT( mbedtls_gcm_self_test( 1 ) == 0 ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 352 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 353 | /* END_CASE */ |