mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 00:55:39 +01:00
Test other output sizes for psa_mac_sign_finish
Test psa_mac_sign_finish with a smaller or larger buffer. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
5e65cec5e8
commit
8b356b5652
@ -3032,6 +3032,13 @@ void mac_sign( int key_type_arg,
|
||||
size_t mac_buffer_size =
|
||||
PSA_MAC_FINAL_SIZE( key_type, PSA_BYTES_TO_BITS( key->len ), alg );
|
||||
size_t mac_length = 0;
|
||||
const size_t output_sizes_to_test[] = {
|
||||
0,
|
||||
1,
|
||||
expected_mac->len - 1,
|
||||
expected_mac->len,
|
||||
expected_mac->len + 1,
|
||||
};
|
||||
|
||||
TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
|
||||
/* We expect PSA_MAC_FINAL_SIZE to be exact. */
|
||||
@ -3045,20 +3052,35 @@ void mac_sign( int key_type_arg,
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes, key->x, key->len, &handle ) );
|
||||
|
||||
ASSERT_ALLOC( actual_mac, mac_buffer_size );
|
||||
for( size_t i = 0; i < ARRAY_LENGTH( output_sizes_to_test ); i++ )
|
||||
{
|
||||
const size_t output_size = output_sizes_to_test[i];
|
||||
psa_status_t expected_status =
|
||||
( output_size >= expected_mac->len ? PSA_SUCCESS :
|
||||
PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
|
||||
test_set_step( output_size );
|
||||
ASSERT_ALLOC( actual_mac, output_size );
|
||||
|
||||
/* Calculate the MAC. */
|
||||
PSA_ASSERT( psa_mac_sign_setup( &operation,
|
||||
handle, alg ) );
|
||||
PSA_ASSERT( psa_mac_update( &operation,
|
||||
input->x, input->len ) );
|
||||
PSA_ASSERT( psa_mac_sign_finish( &operation,
|
||||
actual_mac, mac_buffer_size,
|
||||
&mac_length ) );
|
||||
TEST_EQUAL( psa_mac_sign_finish( &operation,
|
||||
actual_mac, output_size,
|
||||
&mac_length ),
|
||||
expected_status );
|
||||
PSA_ASSERT( psa_mac_abort( &operation ) );
|
||||
|
||||
/* Compare with the expected value. */
|
||||
if( expected_status == PSA_SUCCESS )
|
||||
{
|
||||
ASSERT_COMPARE( expected_mac->x, expected_mac->len,
|
||||
actual_mac, mac_length );
|
||||
}
|
||||
mbedtls_free( actual_mac );
|
||||
actual_mac = NULL;
|
||||
}
|
||||
|
||||
exit:
|
||||
psa_destroy_key( handle );
|
||||
|
Loading…
Reference in New Issue
Block a user