diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 8312c0750..a8f36745c 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1000,6 +1000,13 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) { psa_status_t status = psa_remove_key_data_from_memory( slot ); + /* + * As the return error code may not be handled in case of multiple errors, + * do our best to report an unexpected lock counter: if available call + * MBEDTLS_TEST_HOOK_TEST_ASSERT that may terminate execution (if called as + * part of the execution of a test suite this will stop the test suite + * execution). + */ if( slot->lock_count != 1 ) { MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count == 1 ); diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index cb10f6e06..49e6b873b 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -412,6 +412,13 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) return( PSA_SUCCESS ); } + /* + * As the return error code may not be handled in case of multiple errors, + * do our best to report if the lock counter is equal to zero: if available + * call MBEDTLS_TEST_HOOK_TEST_ASSERT that may terminate execution (if called + * as part of the execution of a unit test suite this will stop the test + * suite execution). + */ MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count > 0 ); return( PSA_ERROR_CORRUPTION_DETECTED ); }