From 47a85614eda27fb0f8bb929bfe458f9b47e100ba Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 1 Sep 2020 09:02:08 +0200 Subject: [PATCH] Introduce psa_key_handle_equal inline function Signed-off-by: Ronald Cron --- include/psa/crypto_platform.h | 13 +++++++++++++ .../test_suite_psa_crypto_slot_management.function | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/psa/crypto_platform.h b/include/psa/crypto_platform.h index a27136d5aa..9cc27f6798 100644 --- a/include/psa/crypto_platform.h +++ b/include/psa/crypto_platform.h @@ -64,6 +64,19 @@ static inline int psa_key_handle_is_null( psa_key_handle_t handle ) return( handle == 0 ); } +/** Compare two handles. + * + * \param handle1 First handle. + * \param handle2 Second handle. + * + * \return Non-zero if the two handles are equal, zero otherwise. + */ +static inline int psa_key_handle_equal( psa_key_handle_t handle1, + psa_key_handle_t handle2 ) +{ + return( handle1 == handle2 ); +} + #if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) /* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 39491a0b04..a99f7de5ed 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -659,7 +659,7 @@ void copy_to_occupied( int source_lifetime_arg, int source_id_arg, } PSA_ASSERT( psa_destroy_key( source_handle ) ); - if( target_handle != source_handle ) + if( ! psa_key_handle_equal( target_handle, source_handle ) ) PSA_ASSERT( psa_destroy_key( target_handle ) ); exit: @@ -768,7 +768,7 @@ void many_transient_handles( int max_handles_arg ) PSA_ASSERT( status ); TEST_ASSERT( ! psa_key_handle_is_null( handles[i] ) ); for( j = 0; j < i; j++ ) - TEST_ASSERT( handles[i] != handles[j] ); + TEST_ASSERT( ! psa_key_handle_equal( handles[i], handles[j] ) ); } max_handles = i;