blob: 49859dda91f1226426c38d32063871cad3de0187 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/gcm.h"
Gilles Peskine36dd93e2021-04-13 13:02:03 +02003
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. */
7static 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,
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +020014 size_t n1,
15 size_t n1_add)
Gilles Peskine36dd93e2021-04-13 13:02:03 +020016{
17 int ok = 0;
18 uint8_t *output = NULL;
19 size_t n2 = input->len - n1;
Mateusz Starzyk658f4fd2021-05-26 14:26:48 +020020 size_t n2_add = add->len - n1_add;
Gilles Peskinea56c4482021-04-15 17:22:35 +020021 size_t olen;
Gilles Peskine36dd93e2021-04-13 13:02:03 +020022
23 /* Sanity checks on the test data */
24 TEST_ASSERT( n1 <= input->len );
Mateusz Starzyk658f4fd2021-05-26 14:26:48 +020025 TEST_ASSERT( n1_add <= add->len );
Gilles Peskine36dd93e2021-04-13 13:02:03 +020026 TEST_EQUAL( input->len, expected_output->len );
27
28 TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode,
Gilles Peskine295fc132021-04-15 18:32:23 +020029 iv->x, iv->len ) );
Mateusz Starzyk658f4fd2021-05-26 14:26:48 +020030 TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x, n1_add ) );
31 TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x + n1_add, n2_add ) );
Gilles Peskine36dd93e2021-04-13 13:02:03 +020032
33 /* Allocate a tight buffer for each update call. This way, if the function
34 * tries to write beyond the advertised required buffer size, this will
35 * count as an overflow for memory sanitizers and static checkers. */
36 ASSERT_ALLOC( output, n1 );
Gilles Peskinea56c4482021-04-15 17:22:35 +020037 olen = 0xdeadbeef;
38 TEST_EQUAL( 0, mbedtls_gcm_update( ctx, input->x, n1, output, n1, &olen ) );
39 TEST_EQUAL( n1, olen );
40 ASSERT_COMPARE( output, olen, expected_output->x, n1 );
Gilles Peskine36dd93e2021-04-13 13:02:03 +020041 mbedtls_free( output );
42 output = NULL;
43
44 ASSERT_ALLOC( output, n2 );
Gilles Peskinea56c4482021-04-15 17:22:35 +020045 olen = 0xdeadbeef;
46 TEST_EQUAL( 0, mbedtls_gcm_update( ctx, input->x + n1, n2, output, n2, &olen ) );
47 TEST_EQUAL( n2, olen );
48 ASSERT_COMPARE( output, olen, expected_output->x + n1, n2 );
Gilles Peskine36dd93e2021-04-13 13:02:03 +020049 mbedtls_free( output );
50 output = NULL;
51
52 ASSERT_ALLOC( output, tag->len );
Gilles Peskine9461e452021-04-15 16:48:32 +020053 TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, output, tag->len ) );
Gilles Peskine36dd93e2021-04-13 13:02:03 +020054 ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
55 mbedtls_free( output );
56 output = NULL;
57
58 ok = 1;
59exit:
60 mbedtls_free( output );
61 return( ok );
62}
63
Mateusz Starzykfc606222021-06-16 11:04:07 +020064static void check_cipher_with_empty_ad( mbedtls_gcm_context *ctx,
65 int mode,
66 const data_t *iv,
67 const data_t *input,
68 const data_t *expected_output,
69 const data_t *tag,
70 size_t ad_update_count)
71{
72 size_t n;
73 uint8_t *output = NULL;
74 size_t olen;
75
76 /* Sanity checks on the test data */
77 TEST_EQUAL( input->len, expected_output->len );
78
79 TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode,
80 iv->x, iv->len ) );
81
Mateusz Starzyk939a54c2021-06-22 11:12:28 +020082 for( n = 0; n < ad_update_count; n++ )
Mateusz Starzykfc606222021-06-16 11:04:07 +020083 {
84 TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, NULL, 0 ) );
85 }
86
87 /* Allocate a tight buffer for each update call. This way, if the function
88 * tries to write beyond the advertised required buffer size, this will
89 * count as an overflow for memory sanitizers and static checkers. */
90 ASSERT_ALLOC( output, input->len );
91 olen = 0xdeadbeef;
92 TEST_EQUAL( 0, mbedtls_gcm_update( ctx, input->x, input->len, output, input->len, &olen ) );
93 TEST_EQUAL( input->len, olen );
94 ASSERT_COMPARE( output, olen, expected_output->x, input->len );
95 mbedtls_free( output );
96 output = NULL;
97
98 ASSERT_ALLOC( output, tag->len );
99 TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, output, tag->len ) );
100 ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
101
102exit:
103 mbedtls_free( output );
104}
105
106static void check_empty_cipher_with_ad( mbedtls_gcm_context *ctx,
107 int mode,
108 const data_t *iv,
109 const data_t *add,
110 const data_t *tag,
111 size_t cipher_update_count)
112{
113 size_t olen;
114 size_t n;
115 uint8_t* output_tag = NULL;
116
117 TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode, iv->x, iv->len ) );
118 TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x, add->len ) );
119
Mateusz Starzyk939a54c2021-06-22 11:12:28 +0200120 for( n = 0; n < cipher_update_count; n++ )
Mateusz Starzykfc606222021-06-16 11:04:07 +0200121 {
122 olen = 0xdeadbeef;
123 TEST_EQUAL( 0, mbedtls_gcm_update( ctx, NULL, 0, NULL, 0, &olen ) );
124 TEST_EQUAL( 0, olen );
125 }
126
127 ASSERT_ALLOC( output_tag, tag->len );
128 TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, output_tag, tag->len ) );
129 ASSERT_COMPARE( output_tag, tag->len, tag->x, tag->len );
130
131exit:
132 mbedtls_free( output_tag );
133}
134
Mateusz Starzyk469c9f32021-06-18 00:06:52 +0200135static void check_no_cipher_no_ad( mbedtls_gcm_context *ctx,
136 int mode,
137 const data_t *iv,
138 const data_t *tag )
139{
140 uint8_t *output = NULL;
141
142 TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode,
143 iv->x, iv->len ) );
144 ASSERT_ALLOC( output, tag->len );
145 TEST_EQUAL( 0, mbedtls_gcm_finish( ctx, NULL, 0, output, tag->len ) );
146 ASSERT_COMPARE( output, tag->len, tag->x, tag->len );
147
148exit:
149 mbedtls_free( output );
150}
151
Paul Bakker33b43f12013-08-20 11:48:36 +0200152/* END_HEADER */
Paul Bakker89e80c92012-03-20 13:50:09 +0000153
Paul Bakker33b43f12013-08-20 11:48:36 +0200154/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155 * depends_on:MBEDTLS_GCM_C
Paul Bakker33b43f12013-08-20 11:48:36 +0200156 * END_DEPENDENCIES
157 */
Paul Bakker89e80c92012-03-20 13:50:09 +0000158
Paul Bakker33b43f12013-08-20 11:48:36 +0200159/* BEGIN_CASE */
Ron Eldor5a21fd62016-12-16 16:15:56 +0200160void gcm_bad_parameters( int cipher_id, int direction,
Azim Khan5fcca462018-06-29 11:05:32 +0100161 data_t *key_str, data_t *src_str,
162 data_t *iv_str, data_t *add_str,
Ron Eldor5a21fd62016-12-16 16:15:56 +0200163 int tag_len_bits, int gcm_result )
164{
Ron Eldor5a21fd62016-12-16 16:15:56 +0200165 unsigned char output[128];
166 unsigned char tag_output[16];
167 mbedtls_gcm_context ctx;
Azim Khan317efe82017-08-02 17:33:54 +0100168 size_t tag_len = tag_len_bits / 8;
Ron Eldor5a21fd62016-12-16 16:15:56 +0200169
170 mbedtls_gcm_init( &ctx );
171
Ron Eldor5a21fd62016-12-16 16:15:56 +0200172 memset( output, 0x00, sizeof( output ) );
173 memset( tag_output, 0x00, sizeof( tag_output ) );
Darryl Green11999bb2018-03-13 15:22:58 +0000174
Azim Khan317efe82017-08-02 17:33:54 +0100175 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
176 TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, direction, src_str->len, iv_str->x, iv_str->len,
177 add_str->x, add_str->len, src_str->x, output, tag_len, tag_output ) == gcm_result );
Ron Eldor5a21fd62016-12-16 16:15:56 +0200178
179exit:
180 mbedtls_gcm_free( &ctx );
181}
182/* END_CASE */
183
184/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100185void gcm_encrypt_and_tag( int cipher_id, data_t * key_str,
186 data_t * src_str, data_t * iv_str,
Ronald Cronac6ae352020-06-26 14:33:03 +0200187 data_t * add_str, data_t * dst,
188 int tag_len_bits, data_t * tag,
Azim Khand30ca132017-06-09 04:32:58 +0100189 int init_result )
Paul Bakker89e80c92012-03-20 13:50:09 +0000190{
Paul Bakker89e80c92012-03-20 13:50:09 +0000191 unsigned char output[128];
192 unsigned char tag_output[16];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193 mbedtls_gcm_context ctx;
Azim Khanf1aaec92017-05-30 14:23:15 +0100194 size_t tag_len = tag_len_bits / 8;
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200195 size_t n1;
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +0200196 size_t n1_add;
Paul Bakker89e80c92012-03-20 13:50:09 +0000197
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200198 mbedtls_gcm_init( &ctx );
199
Paul Bakker89e80c92012-03-20 13:50:09 +0000200 memset(output, 0x00, 128);
201 memset(tag_output, 0x00, 16);
202
Paul Bakker89e80c92012-03-20 13:50:09 +0000203
Azim Khand30ca132017-06-09 04:32:58 +0100204 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200205 if( init_result == 0 )
Paul Bakker89e80c92012-03-20 13:50:09 +0000206 {
Azim Khand30ca132017-06-09 04:32:58 +0100207 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 Bakker89e80c92012-03-20 13:50:09 +0000208
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200209 ASSERT_COMPARE( output, src_str->len, dst->x, dst->len );
210 ASSERT_COMPARE( tag_output, tag_len, tag->x, tag->len );
211
Gilles Peskine58fc2722021-04-13 15:58:27 +0200212 for( n1 = 0; n1 <= src_str->len; n1 += 1 )
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200213 {
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +0200214 for( n1_add = 0; n1_add <= add_str->len; n1_add += 1 )
215 {
Mateusz Starzykf8a0d4d2021-06-17 11:40:52 +0200216 mbedtls_test_set_step( n1 * 10000 + n1_add );
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +0200217 if( !check_multipart( &ctx, MBEDTLS_GCM_ENCRYPT,
218 iv_str, add_str, src_str,
219 dst, tag,
220 n1, n1_add ) )
221 goto exit;
222 }
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200223 }
Paul Bakker89e80c92012-03-20 13:50:09 +0000224 }
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200225
Paul Bakkerbd51b262014-07-10 15:26:12 +0200226exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227 mbedtls_gcm_free( &ctx );
Paul Bakker89e80c92012-03-20 13:50:09 +0000228}
Paul Bakker33b43f12013-08-20 11:48:36 +0200229/* END_CASE */
Paul Bakker89e80c92012-03-20 13:50:09 +0000230
Paul Bakker33b43f12013-08-20 11:48:36 +0200231/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100232void gcm_decrypt_and_verify( int cipher_id, data_t * key_str,
233 data_t * src_str, data_t * iv_str,
234 data_t * add_str, int tag_len_bits,
235 data_t * tag_str, char * result,
236 data_t * pt_result, int init_result )
Paul Bakker89e80c92012-03-20 13:50:09 +0000237{
Paul Bakker89e80c92012-03-20 13:50:09 +0000238 unsigned char output[128];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239 mbedtls_gcm_context ctx;
Paul Bakker89e80c92012-03-20 13:50:09 +0000240 int ret;
Azim Khanf1aaec92017-05-30 14:23:15 +0100241 size_t tag_len = tag_len_bits / 8;
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200242 size_t n1;
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +0200243 size_t n1_add;
Paul Bakker89e80c92012-03-20 13:50:09 +0000244
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200245 mbedtls_gcm_init( &ctx );
246
Paul Bakker89e80c92012-03-20 13:50:09 +0000247 memset(output, 0x00, 128);
248
Paul Bakker89e80c92012-03-20 13:50:09 +0000249
Azim Khand30ca132017-06-09 04:32:58 +0100250 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == init_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200251 if( init_result == 0 )
Paul Bakker89e80c92012-03-20 13:50:09 +0000252 {
Azim Khand30ca132017-06-09 04:32:58 +0100253 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 Bakker89e80c92012-03-20 13:50:09 +0000254
Azim Khan46c9b1f2017-05-31 20:46:35 +0100255 if( strcmp( "FAIL", result ) == 0 )
Paul Bakker89e80c92012-03-20 13:50:09 +0000256 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257 TEST_ASSERT( ret == MBEDTLS_ERR_GCM_AUTH_FAILED );
Paul Bakker89e80c92012-03-20 13:50:09 +0000258 }
259 else
260 {
Manuel Pégourié-Gonnardf7ce67f2013-09-03 20:17:35 +0200261 TEST_ASSERT( ret == 0 );
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200262 ASSERT_COMPARE( output, src_str->len, pt_result->x, pt_result->len );
Paul Bakker89e80c92012-03-20 13:50:09 +0000263
Gilles Peskine58fc2722021-04-13 15:58:27 +0200264 for( n1 = 0; n1 <= src_str->len; n1 += 1 )
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200265 {
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +0200266 for( n1_add = 0; n1_add <= add_str->len; n1_add += 1 )
267 {
Mateusz Starzykf8a0d4d2021-06-17 11:40:52 +0200268 mbedtls_test_set_step( n1 * 10000 + n1_add );
Mateusz Starzykaf4ecdd2021-06-15 15:29:48 +0200269 if( !check_multipart( &ctx, MBEDTLS_GCM_DECRYPT,
270 iv_str, add_str, src_str,
271 pt_result, tag_str,
272 n1, n1_add ) )
273 goto exit;
274 }
Gilles Peskine36dd93e2021-04-13 13:02:03 +0200275 }
Paul Bakker89e80c92012-03-20 13:50:09 +0000276 }
277 }
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200278
Paul Bakkerbd51b262014-07-10 15:26:12 +0200279exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280 mbedtls_gcm_free( &ctx );
Paul Bakker89e80c92012-03-20 13:50:09 +0000281}
Paul Bakker33b43f12013-08-20 11:48:36 +0200282/* END_CASE */
Paul Bakker89e80c92012-03-20 13:50:09 +0000283
Mateusz Starzykfc606222021-06-16 11:04:07 +0200284/* BEGIN_CASE */
285void gcm_decrypt_and_verify_empty_cipher( int cipher_id,
286 data_t * key_str,
287 data_t * iv_str,
288 data_t * add_str,
289 data_t * tag_str,
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200290 int cipher_update_calls )
Mateusz Starzykfc606222021-06-16 11:04:07 +0200291{
292 mbedtls_gcm_context ctx;
293
294 mbedtls_gcm_init( &ctx );
295
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200296 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
297 check_empty_cipher_with_ad( &ctx, MBEDTLS_GCM_DECRYPT,
298 iv_str, add_str, tag_str,
299 cipher_update_calls );
Mateusz Starzykfc606222021-06-16 11:04:07 +0200300
301 mbedtls_gcm_free( &ctx );
302}
303/* END_CASE */
304
305/* BEGIN_CASE */
306void gcm_decrypt_and_verify_empty_ad( int cipher_id,
307 data_t * key_str,
308 data_t * iv_str,
309 data_t * src_str,
310 data_t * tag_str,
311 data_t * pt_result,
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200312 int ad_update_calls )
Mateusz Starzykfc606222021-06-16 11:04:07 +0200313{
314 mbedtls_gcm_context ctx;
315
316 mbedtls_gcm_init( &ctx );
317
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200318 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
319 check_cipher_with_empty_ad( &ctx, MBEDTLS_GCM_DECRYPT,
320 iv_str, src_str, pt_result, tag_str,
321 ad_update_calls );
Mateusz Starzykfc606222021-06-16 11:04:07 +0200322
323 mbedtls_gcm_free( &ctx );
324}
325/* END_CASE */
326
327/* BEGIN_CASE */
Mateusz Starzyk469c9f32021-06-18 00:06:52 +0200328void gcm_decrypt_and_verify_no_ad_no_cipher( int cipher_id,
329 data_t * key_str,
330 data_t * iv_str,
331 data_t * tag_str )
332{
333 mbedtls_gcm_context ctx;
334
335 mbedtls_gcm_init( &ctx );
336
337 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
338 check_no_cipher_no_ad( &ctx, MBEDTLS_GCM_DECRYPT,
339 iv_str, tag_str );
340
341 mbedtls_gcm_free( &ctx );
342}
343/* END_CASE */
344
345/* BEGIN_CASE */
Mateusz Starzykfc606222021-06-16 11:04:07 +0200346void gcm_encrypt_and_tag_empty_cipher( int cipher_id,
347 data_t * key_str,
348 data_t * iv_str,
349 data_t * add_str,
350 data_t * tag_str,
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200351 int cipher_update_calls )
Mateusz Starzykfc606222021-06-16 11:04:07 +0200352{
353 mbedtls_gcm_context ctx;
354
355 mbedtls_gcm_init( &ctx );
356
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200357 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
358 check_empty_cipher_with_ad( &ctx, MBEDTLS_GCM_ENCRYPT,
359 iv_str, add_str, tag_str,
360 cipher_update_calls );
Mateusz Starzykfc606222021-06-16 11:04:07 +0200361
362exit:
363 mbedtls_gcm_free( &ctx );
364}
365/* END_CASE */
366
367/* BEGIN_CASE */
368void gcm_encrypt_and_tag_empty_ad( int cipher_id,
369 data_t * key_str,
370 data_t * iv_str,
371 data_t * src_str,
372 data_t * dst,
373 data_t * tag_str,
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200374 int ad_update_calls )
Mateusz Starzykfc606222021-06-16 11:04:07 +0200375{
376 mbedtls_gcm_context ctx;
377
378 mbedtls_gcm_init( &ctx );
379
Mateusz Starzyk032a1ce2021-06-17 11:50:26 +0200380 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
381 check_cipher_with_empty_ad( &ctx, MBEDTLS_GCM_ENCRYPT,
382 iv_str, src_str, dst, tag_str,
383 ad_update_calls );
Mateusz Starzykfc606222021-06-16 11:04:07 +0200384
385exit:
386 mbedtls_gcm_free( &ctx );
387}
388/* END_CASE */
389
Mateusz Starzyk469c9f32021-06-18 00:06:52 +0200390/* BEGIN_CASE */
391void gcm_encrypt_and_verify_no_ad_no_cipher( int cipher_id,
392 data_t * key_str,
393 data_t * iv_str,
394 data_t * tag_str )
395{
396 mbedtls_gcm_context ctx;
397
398 mbedtls_gcm_init( &ctx );
399
400 TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str->x, key_str->len * 8 ) == 0 );
401 check_no_cipher_no_ad( &ctx, MBEDTLS_GCM_ENCRYPT,
402 iv_str, tag_str );
403
404 mbedtls_gcm_free( &ctx );
405}
406/* END_CASE */
407
TRodziewicz062f3532021-05-25 15:15:57 +0200408/* BEGIN_CASE depends_on:NOT_DEFINED */
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500409void gcm_invalid_param( )
410{
411 mbedtls_gcm_context ctx;
412 unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
413 mbedtls_cipher_id_t valid_cipher = MBEDTLS_CIPHER_ID_AES;
Ronald Cron875b5fb2021-05-21 08:50:00 +0200414 int invalid_bitlen = 1;
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500415
416 mbedtls_gcm_init( &ctx );
417
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500418 /* mbedtls_gcm_setkey */
Ronald Cron875b5fb2021-05-21 08:50:00 +0200419 TEST_EQUAL(
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500420 MBEDTLS_ERR_GCM_BAD_INPUT,
421 mbedtls_gcm_setkey( &ctx, valid_cipher, valid_buffer, invalid_bitlen ) );
422
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500423exit:
424 mbedtls_gcm_free( &ctx );
425}
426/* END_CASE */
427
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200428/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100429void gcm_selftest( )
Paul Bakker89e80c92012-03-20 13:50:09 +0000430{
Andres AG93012e82016-09-09 09:10:28 +0100431 TEST_ASSERT( mbedtls_gcm_self_test( 1 ) == 0 );
Paul Bakker89e80c92012-03-20 13:50:09 +0000432}
Paul Bakker33b43f12013-08-20 11:48:36 +0200433/* END_CASE */