Cipher tests: calculate and verify the actual output size
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index bee64ef..6be41c3 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -285,6 +285,7 @@
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
+ size_t total_output_length = 0;
psa_cipher_operation_t operation;
@@ -314,17 +315,22 @@
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
status = psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length );
+ total_output_length += function_output_length;
+
TEST_ASSERT( status == (psa_status_t) expected_status );
if( expected_status == PSA_SUCCESS )
{
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
+ TEST_ASSERT( total_output_length == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output,
expected_output_size ) == 0 );
}
+
exit:
mbedtls_free( key );
mbedtls_free( input );
@@ -352,9 +358,9 @@
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
+ size_t total_output_length = 0;
psa_cipher_operation_t operation;
-
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
@@ -382,19 +388,21 @@
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
TEST_ASSERT( psa_cipher_update( &operation,
input + first_part_size,
input_size - first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
TEST_ASSERT( psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
-
+ total_output_length += function_output_length;
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
- TEST_ASSERT( input_size == expected_output_size );
+ TEST_ASSERT( total_output_length == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 );
exit:
@@ -425,9 +433,9 @@
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
+ size_t total_output_length = 0;
psa_cipher_operation_t operation;
-
key = unhexify_alloc( key_hex, &key_size );
TEST_ASSERT( key != NULL );
@@ -456,18 +464,21 @@
TEST_ASSERT( psa_cipher_update( &operation, input, first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
TEST_ASSERT( psa_cipher_update( &operation,
input + first_part_size,
input_size - first_part_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
TEST_ASSERT( psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
- TEST_ASSERT( input_size == expected_output_size );
+ TEST_ASSERT( total_output_length == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output, expected_output_size ) == 0 );
exit:
@@ -499,6 +510,7 @@
size_t expected_output_size;
size_t output_buffer_size = 0;
size_t function_output_length = 0;
+ size_t total_output_length = 0;
psa_cipher_operation_t operation;
@@ -529,15 +541,18 @@
TEST_ASSERT( psa_cipher_update( &operation, input, input_size,
output, output_buffer_size,
&function_output_length ) == PSA_SUCCESS );
+ total_output_length += function_output_length;
status = psa_cipher_finish( &operation,
output + function_output_length,
output_buffer_size,
&function_output_length );
+ total_output_length += function_output_length;
TEST_ASSERT( status == (psa_status_t) expected_status );
if( expected_status == PSA_SUCCESS )
{
TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS );
+ TEST_ASSERT( total_output_length == expected_output_size );
TEST_ASSERT( memcmp( expected_output, output,
expected_output_size ) == 0 );
}