Skip to content

Commit 0dfba2d

Browse files
Use ASSERT_COMPARE in preference to memcmp in PSA tests
1 parent f812dcf commit 0dfba2d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,8 +1985,8 @@ void mac_sign( int key_type_arg,
19851985
&mac_length ) );
19861986

19871987
/* Compare with the expected value. */
1988-
TEST_EQUAL( mac_length, expected_mac->len );
1989-
TEST_EQUAL( memcmp( actual_mac, expected_mac->x, mac_length ), 0 );
1988+
ASSERT_COMPARE( expected_mac->x, expected_mac->len,
1989+
actual_mac, mac_length );
19901990

19911991
/* Verify that the end of the buffer is untouched. */
19921992
TEST_ASSERT( mem_is_char( actual_mac + mac_length, '+',
@@ -3576,8 +3576,8 @@ void derive_output( int alg_arg,
35763576
/* Success. Check the read data. */
35773577
PSA_ASSERT( status );
35783578
if( output_sizes[i] != 0 )
3579-
TEST_EQUAL( memcmp( output_buffer, expected_outputs[i],
3580-
output_sizes[i] ), 0 );
3579+
ASSERT_COMPARE( output_buffer, output_sizes[i],
3580+
expected_outputs[i], output_sizes[i] );
35813581
/* Check the generator status. */
35823582
expected_capacity -= output_sizes[i];
35833583
PSA_ASSERT( psa_get_generator_capacity( &generator,
@@ -3805,7 +3805,8 @@ void derive_key_export( int alg_arg,
38053805
TEST_EQUAL( length, bytes2 );
38063806

38073807
/* Compare the outputs from the two runs. */
3808-
TEST_EQUAL( memcmp( output_buffer, export_buffer, capacity ), 0 );
3808+
ASSERT_COMPARE( output_buffer, bytes1 + bytes2,
3809+
export_buffer, capacity );
38093810

38103811
exit:
38113812
mbedtls_free( output_buffer );
@@ -3948,15 +3949,15 @@ void key_agreement_output( int alg_arg,
39483949
PSA_ASSERT( psa_generator_read( &generator,
39493950
actual_output,
39503951
expected_output1->len ) );
3951-
TEST_EQUAL( memcmp( actual_output, expected_output1->x,
3952-
expected_output1->len ), 0 );
3952+
ASSERT_COMPARE( actual_output, expected_output1->len,
3953+
expected_output1->x, expected_output1->len );
39533954
if( expected_output2->len != 0 )
39543955
{
39553956
PSA_ASSERT( psa_generator_read( &generator,
39563957
actual_output,
39573958
expected_output2->len ) );
3958-
TEST_EQUAL( memcmp( actual_output, expected_output2->x,
3959-
expected_output2->len ), 0 );
3959+
ASSERT_COMPARE( actual_output, expected_output2->len,
3960+
expected_output2->x, expected_output2->len );
39603961
}
39613962

39623963
exit:
@@ -3993,7 +3994,8 @@ void generate_random( int bytes_arg )
39933994
PSA_ASSERT( psa_generate_random( output, bytes ) );
39943995

39953996
/* Check that no more than bytes have been overwritten */
3996-
TEST_EQUAL( memcmp( output + bytes, trail, sizeof( trail ) ), 0 );
3997+
ASSERT_COMPARE( output + bytes, sizeof( trail ),
3998+
trail, sizeof( trail ) );
39973999

39984000
for( i = 0; i < bytes; i++ )
39994001
{

0 commit comments

Comments
 (0)