Skip to content

Commit 3ce31aa

Browse files
authored
Merge pull request #378 from ronald-cron-arm/psa_crypto_metadata-test_parity
Fix useless calls in PSA crypto metadata tests
2 parents 9928805 + 3876f4a commit 3ce31aa

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tests/suites/test_suite_psa_crypto_metadata.function

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@
5656
#define TEST_CLASSIFICATION_MACRO( flag, alg, flags ) \
5757
TEST_ASSERT( PSA_##flag( alg ) == !! ( ( flags ) & flag ) )
5858

59-
/* Check the parity of value.
60-
* Return 0 if value has even parity and a nonzero value otherwise. */
59+
/* Test the parity of value.
60+
* Numerical encodings of key types and related values such as EC curves and
61+
* DH groups should all have the same parity. This guarantees that a
62+
* single-bit error will be detected.
63+
* The expected parity is even because this makes all-bits-zero valid.
64+
* The function returns a nonzero value if the parity is even, zero otherwise.
65+
*/
6166
int test_parity( uint32_t value )
6267
{
6368
value ^= value >> 16;
6469
value ^= value >> 8;
6570
value ^= value >> 4;
6671
return( 0x9669 & 1 << ( value & 0xf ) );
6772
}
68-
#define TEST_PARITY( value ) \
69-
TEST_ASSERT( test_parity( value ) )
7073

7174
void algorithm_classification( psa_algorithm_t alg, unsigned flags )
7275
{
@@ -125,7 +128,7 @@ void key_type_classification( psa_key_type_t type, unsigned flags )
125128
( PSA_KEY_TYPE_IS_DH( type ) &&
126129
PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) );
127130

128-
TEST_PARITY( type );
131+
TEST_ASSERT( test_parity( type ) );
129132

130133
exit: ;
131134
}
@@ -497,7 +500,7 @@ void ecc_key_family( int curve_arg )
497500
psa_key_type_t public_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY( curve );
498501
psa_key_type_t pair_type = PSA_KEY_TYPE_ECC_KEY_PAIR( curve );
499502

500-
test_parity( curve );
503+
TEST_ASSERT( test_parity( curve ) );
501504

502505
test_key_type( public_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_PUBLIC_KEY );
503506
test_key_type( pair_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_KEY_PAIR );
@@ -514,7 +517,7 @@ void dh_key_family( int group_arg )
514517
psa_key_type_t public_type = PSA_KEY_TYPE_DH_PUBLIC_KEY( group );
515518
psa_key_type_t pair_type = PSA_KEY_TYPE_DH_KEY_PAIR( group );
516519

517-
test_parity( group );
520+
TEST_ASSERT( test_parity( group ) );
518521

519522
test_key_type( public_type, KEY_TYPE_IS_DH | KEY_TYPE_IS_PUBLIC_KEY );
520523
test_key_type( pair_type, KEY_TYPE_IS_DH | KEY_TYPE_IS_KEY_PAIR );

0 commit comments

Comments
 (0)