blob: d8f022ff44062e5fa86c46929a09064d196cfd8c [file] [log] [blame]
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include <mbedtls/ssl.h>
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +02003#include <mbedtls/ssl_internal.h>
Hanno Beckera18d1322018-01-03 14:27:32 +00004
5/*
6 * Helper function setting up inverse record transformations
7 * using given cipher, hash, EtM mode, authentication tag length,
8 * and version.
9 */
10
11#define CHK( x ) \
12 do \
13 { \
14 if( !( x ) ) \
Hanno Becker81e16a32019-03-01 11:21:44 +000015 { \
Hanno Beckera5780f12019-04-05 09:55:37 +010016 ret = -1; \
Hanno Becker81e16a32019-03-01 11:21:44 +000017 goto cleanup; \
18 } \
Hanno Beckera18d1322018-01-03 14:27:32 +000019 } while( 0 )
20
21
22static int build_transforms( mbedtls_ssl_transform *t_in,
23 mbedtls_ssl_transform *t_out,
24 int cipher_type, int hash_id,
25 int etm, int tag_mode, int ver )
26{
27 mbedtls_cipher_info_t const *cipher_info;
Hanno Beckera5780f12019-04-05 09:55:37 +010028 int ret = 0;
Hanno Beckera18d1322018-01-03 14:27:32 +000029
30 size_t keylen, maclen, ivlen;
Hanno Becker81e16a32019-03-01 11:21:44 +000031 unsigned char *key0 = NULL, *key1 = NULL;
Hanno Beckera18d1322018-01-03 14:27:32 +000032 unsigned char iv_enc[16], iv_dec[16];
33
34 maclen = 0;
35
36 /* Pick cipher */
37 cipher_info = mbedtls_cipher_info_from_type( cipher_type );
38 CHK( cipher_info != NULL );
39 CHK( cipher_info->iv_size <= 16 );
40 CHK( cipher_info->key_bitlen % 8 == 0 );
41
42 /* Pick keys */
43 keylen = cipher_info->key_bitlen / 8;
Hanno Becker3ee54212019-04-04 16:31:26 +010044 CHK( ( key0 = mbedtls_calloc( 1, keylen ) ) != NULL );
45 CHK( ( key1 = mbedtls_calloc( 1, keylen ) ) != NULL );
Hanno Beckera18d1322018-01-03 14:27:32 +000046 memset( key0, 0x1, keylen );
47 memset( key1, 0x2, keylen );
48
49 /* Setup cipher contexts */
50 CHK( mbedtls_cipher_setup( &t_in->cipher_ctx_enc, cipher_info ) == 0 );
51 CHK( mbedtls_cipher_setup( &t_in->cipher_ctx_dec, cipher_info ) == 0 );
52 CHK( mbedtls_cipher_setup( &t_out->cipher_ctx_enc, cipher_info ) == 0 );
53 CHK( mbedtls_cipher_setup( &t_out->cipher_ctx_dec, cipher_info ) == 0 );
54
55#if defined(MBEDTLS_CIPHER_MODE_CBC)
56 if( cipher_info->mode == MBEDTLS_MODE_CBC )
57 {
58 CHK( mbedtls_cipher_set_padding_mode( &t_in->cipher_ctx_enc,
59 MBEDTLS_PADDING_NONE ) == 0 );
60 CHK( mbedtls_cipher_set_padding_mode( &t_in->cipher_ctx_dec,
61 MBEDTLS_PADDING_NONE ) == 0 );
62 CHK( mbedtls_cipher_set_padding_mode( &t_out->cipher_ctx_enc,
63 MBEDTLS_PADDING_NONE ) == 0 );
64 CHK( mbedtls_cipher_set_padding_mode( &t_out->cipher_ctx_dec,
65 MBEDTLS_PADDING_NONE ) == 0 );
66 }
67#endif /* MBEDTLS_CIPHER_MODE_CBC */
68
69 CHK( mbedtls_cipher_setkey( &t_in->cipher_ctx_enc, key0,
70 keylen << 3, MBEDTLS_ENCRYPT ) == 0 );
71 CHK( mbedtls_cipher_setkey( &t_in->cipher_ctx_dec, key1,
72 keylen << 3, MBEDTLS_DECRYPT ) == 0 );
73 CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_enc, key1,
74 keylen << 3, MBEDTLS_ENCRYPT ) == 0 );
75 CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_dec, key0,
76 keylen << 3, MBEDTLS_DECRYPT ) == 0 );
Hanno Beckera18d1322018-01-03 14:27:32 +000077
78 /* Setup MAC contexts */
79#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
80 if( cipher_info->mode == MBEDTLS_MODE_CBC ||
81 cipher_info->mode == MBEDTLS_MODE_STREAM )
82 {
83 mbedtls_md_info_t const *md_info;
84 unsigned char *md0, *md1;
85
86 /* Pick hash */
87 md_info = mbedtls_md_info_from_type( hash_id );
88 CHK( md_info != NULL );
89
90 /* Pick hash keys */
91 maclen = mbedtls_md_get_size( md_info );
Hanno Becker3ee54212019-04-04 16:31:26 +010092 CHK( ( md0 = mbedtls_calloc( 1, maclen ) ) != NULL );
93 CHK( ( md1 = mbedtls_calloc( 1, maclen ) ) != NULL );
Hanno Beckera18d1322018-01-03 14:27:32 +000094 memset( md0, 0x5, maclen );
95 memset( md1, 0x6, maclen );
96
97 CHK( mbedtls_md_setup( &t_out->md_ctx_enc, md_info, 1 ) == 0 );
98 CHK( mbedtls_md_setup( &t_out->md_ctx_dec, md_info, 1 ) == 0 );
99 CHK( mbedtls_md_setup( &t_in->md_ctx_enc, md_info, 1 ) == 0 );
100 CHK( mbedtls_md_setup( &t_in->md_ctx_dec, md_info, 1 ) == 0 );
101
102 if( ver > MBEDTLS_SSL_MINOR_VERSION_0 )
103 {
104 CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_enc,
105 md0, maclen ) == 0 );
106 CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_dec,
107 md1, maclen ) == 0 );
108 CHK( mbedtls_md_hmac_starts( &t_out->md_ctx_enc,
109 md1, maclen ) == 0 );
110 CHK( mbedtls_md_hmac_starts( &t_out->md_ctx_dec,
111 md0, maclen ) == 0 );
112 }
113#if defined(MBEDTLS_SSL_PROTO_SSL3)
114 else
115 {
116 memcpy( &t_in->mac_enc, md0, maclen );
117 memcpy( &t_in->mac_dec, md1, maclen );
118 memcpy( &t_out->mac_enc, md1, maclen );
119 memcpy( &t_out->mac_dec, md0, maclen );
120 }
121#endif
122
Hanno Becker3ee54212019-04-04 16:31:26 +0100123 mbedtls_free( md0 );
124 mbedtls_free( md1 );
Hanno Beckera18d1322018-01-03 14:27:32 +0000125 }
126#else
127 ((void) hash_id);
128#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
129
130
131 /* Pick IV's (regardless of whether they
132 * are being used by the transform). */
133 ivlen = cipher_info->iv_size;
134 memset( iv_enc, 0x3, sizeof( iv_enc ) );
135 memset( iv_dec, 0x4, sizeof( iv_dec ) );
136
137 /*
138 * Setup transforms
139 */
140
141#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
142 t_out->encrypt_then_mac = etm;
143 t_in->encrypt_then_mac = etm;
144#else
145 ((void) etm);
146#endif
147
148 t_out->minor_ver = ver;
149 t_in->minor_ver = ver;
150 t_out->ivlen = ivlen;
151 t_in->ivlen = ivlen;
152
153 switch( cipher_info->mode )
154 {
155 case MBEDTLS_MODE_GCM:
156 case MBEDTLS_MODE_CCM:
157 t_out->fixed_ivlen = 4;
158 t_in->fixed_ivlen = 4;
159 t_out->maclen = 0;
160 t_in->maclen = 0;
161 switch( tag_mode )
162 {
163 case 0: /* Full tag */
164 t_out->taglen = 16;
165 t_in->taglen = 16;
166 break;
167 case 1: /* Partial tag */
168 t_out->taglen = 8;
169 t_in->taglen = 8;
170 break;
171 default:
172 return( 1 );
173 }
174 break;
175
176 case MBEDTLS_MODE_CHACHAPOLY:
177 t_out->fixed_ivlen = 12;
178 t_in->fixed_ivlen = 12;
179 t_out->maclen = 0;
180 t_in->maclen = 0;
181 switch( tag_mode )
182 {
183 case 0: /* Full tag */
184 t_out->taglen = 16;
185 t_in->taglen = 16;
186 break;
187 case 1: /* Partial tag */
188 t_out->taglen = 8;
189 t_in->taglen = 8;
190 break;
191 default:
192 return( 1 );
193 }
194 break;
195
196 case MBEDTLS_MODE_STREAM:
197 case MBEDTLS_MODE_CBC:
198 t_out->fixed_ivlen = 0; /* redundant, must be 0 */
199 t_in->fixed_ivlen = 0; /* redundant, must be 0 */
200 t_out->taglen = 0;
201 t_in->taglen = 0;
202 switch( tag_mode )
203 {
204 case 0: /* Full tag */
205 t_out->maclen = maclen;
206 t_in->maclen = maclen;
207 break;
208 case 1: /* Partial tag */
209 t_out->maclen = 10;
210 t_in->maclen = 10;
211 break;
212 default:
213 return( 1 );
214 }
215 break;
216 default:
217 return( 1 );
218 break;
219 }
220
221 /* Setup IV's */
222
223 memcpy( &t_in->iv_dec, iv_dec, sizeof( iv_dec ) );
224 memcpy( &t_in->iv_enc, iv_enc, sizeof( iv_enc ) );
225 memcpy( &t_out->iv_dec, iv_enc, sizeof( iv_enc ) );
226 memcpy( &t_out->iv_enc, iv_dec, sizeof( iv_dec ) );
227
Hanno Becker81e16a32019-03-01 11:21:44 +0000228cleanup:
229
Hanno Becker3ee54212019-04-04 16:31:26 +0100230 mbedtls_free( key0 );
231 mbedtls_free( key1 );
Hanno Becker81e16a32019-03-01 11:21:44 +0000232
Hanno Beckera5780f12019-04-05 09:55:37 +0100233 return( ret );
Hanno Beckera18d1322018-01-03 14:27:32 +0000234}
235
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200236/* END_HEADER */
237
238/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239 * depends_on:MBEDTLS_SSL_TLS_C
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200240 * END_DEPENDENCIES
241 */
242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243/* BEGIN_CASE depends_on:MBEDTLS_SSL_DTLS_ANTI_REPLAY */
Azim Khan5fcca462018-06-29 11:05:32 +0100244void ssl_dtls_replay( data_t * prevs, data_t * new, int ret )
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200245{
Azim Khand30ca132017-06-09 04:32:58 +0100246 uint32_t len = 0;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247 mbedtls_ssl_context ssl;
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200248 mbedtls_ssl_config conf;
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200249
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200250 mbedtls_ssl_init( &ssl );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200251 mbedtls_ssl_config_init( &conf );
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200252
Manuel Pégourié-Gonnard419d5ae2015-05-04 19:32:36 +0200253 TEST_ASSERT( mbedtls_ssl_config_defaults( &conf,
254 MBEDTLS_SSL_IS_CLIENT,
Manuel Pégourié-Gonnardb31c5f62015-06-17 13:53:47 +0200255 MBEDTLS_SSL_TRANSPORT_DATAGRAM,
256 MBEDTLS_SSL_PRESET_DEFAULT ) == 0 );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200257 TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200258
259 /* Read previous record numbers */
Azim Khand30ca132017-06-09 04:32:58 +0100260 for( len = 0; len < prevs->len; len += 6 )
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200261 {
Azim Khand30ca132017-06-09 04:32:58 +0100262 memcpy( ssl.in_ctr + 2, prevs->x + len, 6 );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263 mbedtls_ssl_dtls_replay_update( &ssl );
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200264 }
265
266 /* Check new number */
Azim Khand30ca132017-06-09 04:32:58 +0100267 memcpy( ssl.in_ctr + 2, new->x, 6 );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200268 TEST_ASSERT( mbedtls_ssl_dtls_replay_check( &ssl ) == ret );
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270 mbedtls_ssl_free( &ssl );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200271 mbedtls_ssl_config_free( &conf );
Manuel Pégourié-Gonnard4956fd72014-09-24 11:13:44 +0200272}
273/* END_CASE */
Hanno Beckerb25c0c72017-05-05 11:24:30 +0100274
275/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
276void ssl_set_hostname_twice( char *hostname0, char *hostname1 )
277{
278 mbedtls_ssl_context ssl;
279 mbedtls_ssl_init( &ssl );
280
281 TEST_ASSERT( mbedtls_ssl_set_hostname( &ssl, hostname0 ) == 0 );
282 TEST_ASSERT( mbedtls_ssl_set_hostname( &ssl, hostname1 ) == 0 );
283
284 mbedtls_ssl_free( &ssl );
285}
Darryl Green11999bb2018-03-13 15:22:58 +0000286/* END_CASE */
Hanno Beckera18d1322018-01-03 14:27:32 +0000287
288/* BEGIN_CASE */
289void ssl_crypt_record( int cipher_type, int hash_id,
290 int etm, int tag_mode, int ver )
291{
292 /*
293 * Test several record encryptions and decryptions
294 * with plenty of space before and after the data
295 * within the record buffer.
296 */
297
298 int ret;
299 int num_records = 16;
300 mbedtls_ssl_context ssl; /* ONLY for debugging */
301
302 mbedtls_ssl_transform t0, t1;
Hanno Becker81e16a32019-03-01 11:21:44 +0000303 unsigned char *buf = NULL;
Hanno Beckera18d1322018-01-03 14:27:32 +0000304 size_t const buflen = 512;
305 mbedtls_record rec, rec_backup;
306
307 mbedtls_ssl_init( &ssl );
308 mbedtls_ssl_transform_init( &t0 );
309 mbedtls_ssl_transform_init( &t1 );
310 TEST_ASSERT( build_transforms( &t0, &t1, cipher_type, hash_id,
311 etm, tag_mode, ver ) == 0 );
312
Hanno Becker3ee54212019-04-04 16:31:26 +0100313 TEST_ASSERT( ( buf = mbedtls_calloc( 1, buflen ) ) != NULL );
Hanno Beckera18d1322018-01-03 14:27:32 +0000314
315 while( num_records-- > 0 )
316 {
317 mbedtls_ssl_transform *t_dec, *t_enc;
318 /* Take turns in who's sending and who's receiving. */
319 if( num_records % 3 == 0 )
320 {
321 t_dec = &t0;
322 t_enc = &t1;
323 }
324 else
325 {
326 t_dec = &t1;
327 t_enc = &t0;
328 }
329
330 /*
331 * The record header affects the transformation in two ways:
332 * 1) It determines the AEAD additional data
333 * 2) The record counter sometimes determines the IV.
334 *
335 * Apart from that, the fields don't have influence.
336 * In particular, it is currently not the responsibility
337 * of ssl_encrypt/decrypt_buf to check if the transform
338 * version matches the record version, or that the
339 * type is sensible.
340 */
341
342 memset( rec.ctr, num_records, sizeof( rec.ctr ) );
343 rec.type = 42;
344 rec.ver[0] = num_records;
345 rec.ver[1] = num_records;
346
347 rec.buf = buf;
348 rec.buf_len = buflen;
349 rec.data_offset = 16;
350 /* Make sure to vary the length to exercise different
351 * paddings. */
352 rec.data_len = 1 + num_records;
353
354 memset( rec.buf + rec.data_offset, 42, rec.data_len );
355
356 /* Make a copy for later comparison */
357 rec_backup = rec;
358
359 /* Encrypt record */
360 ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec,
361 rnd_std_rand, NULL );
362 TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
363 if( ret != 0 )
364 {
365 continue;
366 }
367
368 /* Decrypt record with t_dec */
369 TEST_ASSERT( mbedtls_ssl_decrypt_buf( &ssl, t_dec, &rec ) == 0 );
370
371 /* Compare results */
372 TEST_ASSERT( rec.type == rec_backup.type );
373 TEST_ASSERT( memcmp( rec.ctr, rec_backup.ctr, 8 ) == 0 );
374 TEST_ASSERT( rec.ver[0] == rec_backup.ver[0] );
375 TEST_ASSERT( rec.ver[1] == rec_backup.ver[1] );
376 TEST_ASSERT( rec.data_len == rec_backup.data_len );
377 TEST_ASSERT( rec.data_offset == rec_backup.data_offset );
378 TEST_ASSERT( memcmp( rec.buf + rec.data_offset,
379 rec_backup.buf + rec_backup.data_offset,
380 rec.data_len ) == 0 );
381 }
382
Hanno Becker81e16a32019-03-01 11:21:44 +0000383exit:
384
Hanno Beckera18d1322018-01-03 14:27:32 +0000385 /* Cleanup */
386 mbedtls_ssl_free( &ssl );
387 mbedtls_ssl_transform_free( &t0 );
388 mbedtls_ssl_transform_free( &t1 );
389
Hanno Becker3ee54212019-04-04 16:31:26 +0100390 mbedtls_free( buf );
Hanno Beckera18d1322018-01-03 14:27:32 +0000391}
392/* END_CASE */
Hanno Beckerb3268da2018-01-05 15:20:24 +0000393
394/* BEGIN_CASE */
395void ssl_crypt_record_small( int cipher_type, int hash_id,
396 int etm, int tag_mode, int ver )
397{
398 /*
399 * Test pairs of encryption and decryption with an increasing
400 * amount of space in the record buffer - in more detail:
401 * 1) Try to encrypt with 0, 1, 2, ... bytes available
402 * in front of the plaintext, and expect the encryption
403 * to succeed starting from some offset. Always keep
404 * enough space in the end of the buffer.
405 * 2) Try to encrypt with 0, 1, 2, ... bytes available
406 * at the end of the plaintext, and expect the encryption
407 * to succeed starting from some offset. Always keep
408 * enough space at the beginning of the buffer.
409 * 3) Try to encrypt with 0, 1, 2, ... bytes available
410 * both at the front and end of the plaintext,
411 * and expect the encryption to succeed starting from
412 * some offset.
413 *
414 * If encryption succeeds, check that decryption succeeds
415 * and yields the original record.
416 */
417
418 mbedtls_ssl_context ssl; /* ONLY for debugging */
419
420 mbedtls_ssl_transform t0, t1;
Hanno Becker81e16a32019-03-01 11:21:44 +0000421 unsigned char *buf = NULL;
Hanno Beckerb3268da2018-01-05 15:20:24 +0000422 size_t const buflen = 150;
423 mbedtls_record rec, rec_backup;
424
425 int ret;
426 int mode; /* Mode 1, 2 or 3 as explained above */
427 size_t offset; /* Available space at beginning/end/both */
428 size_t threshold = 64; /* Maximum offset to test against */
429
430 size_t default_pre_padding = 64; /* Pre-padding to use in mode 2 */
431 size_t default_post_padding = 64; /* Post-padding to use in mode 1 */
432
433 int seen_success; /* Indicates if in the current mode we've
434 * already seen a successful test. */
435
436 mbedtls_ssl_init( &ssl );
437 mbedtls_ssl_transform_init( &t0 );
438 mbedtls_ssl_transform_init( &t1 );
439 TEST_ASSERT( build_transforms( &t0, &t1, cipher_type, hash_id,
440 etm, tag_mode, ver ) == 0 );
441
Hanno Becker3ee54212019-04-04 16:31:26 +0100442 TEST_ASSERT( ( buf = mbedtls_calloc( 1, buflen ) ) != NULL );
Hanno Beckerb3268da2018-01-05 15:20:24 +0000443
444 for( mode=1; mode <= 3; mode++ )
445 {
446 seen_success = 0;
447 for( offset=0; offset <= threshold; offset++ )
448 {
449 mbedtls_ssl_transform *t_dec, *t_enc;
450 /* Take turns in who's sending and who's receiving. */
Hanno Becker907ab202019-03-01 11:21:54 +0000451 if( offset % 2 == 0 )
Hanno Beckerb3268da2018-01-05 15:20:24 +0000452 {
453 t_dec = &t0;
454 t_enc = &t1;
455 }
456 else
457 {
458 t_dec = &t1;
459 t_enc = &t0;
460 }
461
462 memset( rec.ctr, offset, sizeof( rec.ctr ) );
463 rec.type = 42;
464 rec.ver[0] = offset;
465 rec.ver[1] = offset;
466 rec.buf = buf;
467 rec.buf_len = buflen;
468
469 switch( mode )
470 {
471 case 1: /* Space in the beginning */
472 rec.data_offset = offset;
473 rec.data_len = buflen - offset - default_post_padding;
474 break;
475
476 case 2: /* Space in the end */
477 rec.data_offset = default_pre_padding;
478 rec.data_len = buflen - default_pre_padding - offset;
479 break;
480
481 case 3: /* Space in the beginning and end */
482 rec.data_offset = offset;
483 rec.data_len = buflen - 2 * offset;
484 break;
485
486 default:
487 TEST_ASSERT( 0 );
488 break;
489 }
490
491 memset( rec.buf + rec.data_offset, 42, rec.data_len );
492
493 /* Make a copy for later comparison */
494 rec_backup = rec;
495
496 /* Encrypt record */
497 ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec, rnd_std_rand, NULL );
498
499 if( ( mode == 1 || mode == 2 ) && seen_success )
500 {
501 TEST_ASSERT( ret == 0 );
502 }
503 else
504 {
505 TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
506 if( ret == 0 )
507 seen_success = 1;
508 }
509
510 if( ret != 0 )
511 continue;
512
513 /* Decrypt record with t_dec */
514 TEST_ASSERT( mbedtls_ssl_decrypt_buf( &ssl, t_dec, &rec ) == 0 );
515
516 /* Compare results */
517 TEST_ASSERT( rec.type == rec_backup.type );
518 TEST_ASSERT( memcmp( rec.ctr, rec_backup.ctr, 8 ) == 0 );
519 TEST_ASSERT( rec.ver[0] == rec_backup.ver[0] );
520 TEST_ASSERT( rec.ver[1] == rec_backup.ver[1] );
521 TEST_ASSERT( rec.data_len == rec_backup.data_len );
522 TEST_ASSERT( rec.data_offset == rec_backup.data_offset );
523 TEST_ASSERT( memcmp( rec.buf + rec.data_offset,
524 rec_backup.buf + rec_backup.data_offset,
525 rec.data_len ) == 0 );
526 }
527
528 TEST_ASSERT( seen_success == 1 );
529 }
530
Hanno Becker81e16a32019-03-01 11:21:44 +0000531exit:
532
Hanno Beckerb3268da2018-01-05 15:20:24 +0000533 /* Cleanup */
534 mbedtls_ssl_free( &ssl );
535 mbedtls_ssl_transform_free( &t0 );
536 mbedtls_ssl_transform_free( &t1 );
537
Hanno Becker3ee54212019-04-04 16:31:26 +0100538 mbedtls_free( buf );
Hanno Beckerb3268da2018-01-05 15:20:24 +0000539}
540/* END_CASE */