mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 18:55:40 +01:00
Add test for one-shot MAC functions
Tests for psa_mac_compute and psa_mac_verify functions. Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com> Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
a00616fc6b
commit
a93e423739
@ -2048,7 +2048,21 @@ void mac_sign( int key_type_arg,
|
|||||||
mbedtls_test_set_step( output_size );
|
mbedtls_test_set_step( output_size );
|
||||||
ASSERT_ALLOC( actual_mac, output_size );
|
ASSERT_ALLOC( actual_mac, output_size );
|
||||||
|
|
||||||
/* Calculate the MAC. */
|
/* Calculate the MAC, one-shot case. */
|
||||||
|
TEST_EQUAL( psa_mac_compute( key, alg,
|
||||||
|
input->x, input->len,
|
||||||
|
actual_mac, output_size, &mac_length ),
|
||||||
|
expected_status );
|
||||||
|
if( expected_status == PSA_SUCCESS )
|
||||||
|
{
|
||||||
|
ASSERT_COMPARE( expected_mac->x, expected_mac->len,
|
||||||
|
actual_mac, mac_length );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( output_size > 0 )
|
||||||
|
memset( actual_mac, 0, output_size );
|
||||||
|
|
||||||
|
/* Calculate the MAC, multi-part case. */
|
||||||
PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
|
||||||
PSA_ASSERT( psa_mac_update( &operation,
|
PSA_ASSERT( psa_mac_update( &operation,
|
||||||
input->x, input->len ) );
|
input->x, input->len ) );
|
||||||
@ -2100,7 +2114,11 @@ void mac_verify( int key_type_arg,
|
|||||||
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
||||||
&key ) );
|
&key ) );
|
||||||
|
|
||||||
/* Test the correct MAC. */
|
/* Verify correct MAC, one-shot case. */
|
||||||
|
PSA_ASSERT( psa_mac_verify( key, alg, input->x, input->len,
|
||||||
|
expected_mac->x, expected_mac->len ) );
|
||||||
|
|
||||||
|
/* Verify correct MAC, multi-part case. */
|
||||||
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
||||||
PSA_ASSERT( psa_mac_update( &operation,
|
PSA_ASSERT( psa_mac_update( &operation,
|
||||||
input->x, input->len ) );
|
input->x, input->len ) );
|
||||||
@ -2108,7 +2126,14 @@ void mac_verify( int key_type_arg,
|
|||||||
expected_mac->x,
|
expected_mac->x,
|
||||||
expected_mac->len ) );
|
expected_mac->len ) );
|
||||||
|
|
||||||
/* Test a MAC that's too short. */
|
/* Test a MAC that's too short, one-shot case. */
|
||||||
|
TEST_EQUAL( psa_mac_verify( key, alg,
|
||||||
|
input->x, input->len,
|
||||||
|
expected_mac->x,
|
||||||
|
expected_mac->len - 1 ),
|
||||||
|
PSA_ERROR_INVALID_SIGNATURE );
|
||||||
|
|
||||||
|
/* Test a MAC that's too short, multi-part case. */
|
||||||
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
||||||
PSA_ASSERT( psa_mac_update( &operation,
|
PSA_ASSERT( psa_mac_update( &operation,
|
||||||
input->x, input->len ) );
|
input->x, input->len ) );
|
||||||
@ -2117,9 +2142,15 @@ void mac_verify( int key_type_arg,
|
|||||||
expected_mac->len - 1 ),
|
expected_mac->len - 1 ),
|
||||||
PSA_ERROR_INVALID_SIGNATURE );
|
PSA_ERROR_INVALID_SIGNATURE );
|
||||||
|
|
||||||
/* Test a MAC that's too long. */
|
/* Test a MAC that's too long, one-shot case. */
|
||||||
ASSERT_ALLOC( perturbed_mac, expected_mac->len + 1 );
|
ASSERT_ALLOC( perturbed_mac, expected_mac->len + 1 );
|
||||||
memcpy( perturbed_mac, expected_mac->x, expected_mac->len );
|
memcpy( perturbed_mac, expected_mac->x, expected_mac->len );
|
||||||
|
TEST_EQUAL( psa_mac_verify( key, alg,
|
||||||
|
input->x, input->len,
|
||||||
|
perturbed_mac, expected_mac->len + 1 ),
|
||||||
|
PSA_ERROR_INVALID_SIGNATURE );
|
||||||
|
|
||||||
|
/* Test a MAC that's too long, multi-part case. */
|
||||||
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
||||||
PSA_ASSERT( psa_mac_update( &operation,
|
PSA_ASSERT( psa_mac_update( &operation,
|
||||||
input->x, input->len ) );
|
input->x, input->len ) );
|
||||||
@ -2133,6 +2164,12 @@ void mac_verify( int key_type_arg,
|
|||||||
{
|
{
|
||||||
mbedtls_test_set_step( i );
|
mbedtls_test_set_step( i );
|
||||||
perturbed_mac[i] ^= 1;
|
perturbed_mac[i] ^= 1;
|
||||||
|
|
||||||
|
TEST_EQUAL( psa_mac_verify( key, alg,
|
||||||
|
input->x, input->len,
|
||||||
|
perturbed_mac, expected_mac->len ),
|
||||||
|
PSA_ERROR_INVALID_SIGNATURE );
|
||||||
|
|
||||||
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
PSA_ASSERT( psa_mac_verify_setup( &operation, key, alg ) );
|
||||||
PSA_ASSERT( psa_mac_update( &operation,
|
PSA_ASSERT( psa_mac_update( &operation,
|
||||||
input->x, input->len ) );
|
input->x, input->len ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user