diff --git a/tests/suites/test_suite_gcm.function b/tests/suites/test_suite_gcm.function index a6b0a4c119..c7942f81a7 100644 --- a/tests/suites/test_suite_gcm.function +++ b/tests/suites/test_suite_gcm.function @@ -16,15 +16,19 @@ static int check_multipart( mbedtls_gcm_context *ctx, int ok = 0; uint8_t *output = NULL; size_t n2 = input->len - n1; + size_t n1_add = n1 < add->len ? add->len - n1 : add->len; + size_t n2_add = add->len - n1_add; size_t olen; /* Sanity checks on the test data */ TEST_ASSERT( n1 <= input->len ); + TEST_ASSERT( n1_add <= add->len ); TEST_EQUAL( input->len, expected_output->len ); TEST_EQUAL( 0, mbedtls_gcm_starts( ctx, mode, iv->x, iv->len ) ); - TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x, add->len ) ); + TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x, n1_add ) ); + TEST_EQUAL( 0, mbedtls_gcm_update_ad( ctx, add->x + n1_add, n2_add ) ); /* Allocate a tight buffer for each update call. This way, if the function * tries to write beyond the advertised required buffer size, this will