Refactoring: create mbedtls_test_ssl_prepare_record_mac()
No semantic change.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/suites/test_suite_ssl_decrypt.function b/tests/suites/test_suite_ssl_decrypt.function
index 5fbf110..a7104bf 100644
--- a/tests/suites/test_suite_ssl_decrypt.function
+++ b/tests/suites/test_suite_ssl_decrypt.function
@@ -107,30 +107,7 @@
/*
* Prepare a pre-encryption record (with MAC and padding), and save it.
*/
- mbedtls_ssl_transform *transform_out = &t0;
- mbedtls_record *record = &rec;
-
- /* Serialized version of record header for MAC purposes */
- unsigned char add_data[13];
- memcpy(add_data, record->ctr, 8);
- add_data[8] = record->type;
- add_data[9] = record->ver[0];
- add_data[10] = record->ver[1];
- add_data[11] = (record->data_len >> 8) & 0xff;
- add_data[12] = (record->data_len >> 0) & 0xff;
-
- /* MAC with additional data */
- TEST_EQUAL(0, mbedtls_md_hmac_update(&transform_out->md_ctx_enc, add_data, 13));
- TEST_EQUAL(0, mbedtls_md_hmac_update(&transform_out->md_ctx_enc,
- record->buf + record->data_offset,
- record->data_len));
- /* Use a temporary buffer for the MAC, because with the truncated HMAC
- * extension, there might not be enough room in the record for the
- * full-length MAC. */
- unsigned char mac[MBEDTLS_MD_MAX_SIZE];
- TEST_EQUAL(0, mbedtls_md_hmac_finish(&transform_out->md_ctx_enc, mac));
- memcpy(record->buf + record->data_offset + record->data_len, mac, transform_out->maclen);
- record->data_len += transform_out->maclen;
+ TEST_EQUAL(0, mbedtls_test_ssl_prepare_record_mac(&rec, &t0));
/* Pad */
memset(rec.buf + rec.data_offset + rec.data_len, padlen, padlen + 1);