mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 09:35:39 +00: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 =
|
size_t mac_buffer_size =
|
||||||
PSA_MAC_FINAL_SIZE( key_type, PSA_BYTES_TO_BITS( key->len ), alg );
|
PSA_MAC_FINAL_SIZE( key_type, PSA_BYTES_TO_BITS( key->len ), alg );
|
||||||
size_t mac_length = 0;
|
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 );
|
TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
|
||||||
/* We expect PSA_MAC_FINAL_SIZE to be exact. */
|
/* 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 ) );
|
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 );
|
||||||
|
|
||||||
/* Calculate the MAC. */
|
test_set_step( output_size );
|
||||||
PSA_ASSERT( psa_mac_sign_setup( &operation,
|
ASSERT_ALLOC( actual_mac, output_size );
|
||||||
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 ) );
|
|
||||||
|
|
||||||
/* Compare with the expected value. */
|
/* Calculate the MAC. */
|
||||||
ASSERT_COMPARE( expected_mac->x, expected_mac->len,
|
PSA_ASSERT( psa_mac_sign_setup( &operation,
|
||||||
actual_mac, mac_length );
|
handle, alg ) );
|
||||||
|
PSA_ASSERT( psa_mac_update( &operation,
|
||||||
|
input->x, input->len ) );
|
||||||
|
TEST_EQUAL( psa_mac_sign_finish( &operation,
|
||||||
|
actual_mac, output_size,
|
||||||
|
&mac_length ),
|
||||||
|
expected_status );
|
||||||
|
PSA_ASSERT( psa_mac_abort( &operation ) );
|
||||||
|
|
||||||
|
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:
|
exit:
|
||||||
psa_destroy_key( handle );
|
psa_destroy_key( handle );
|
||||||
|
|
Loading…
Reference in a new issue