Update psa_destroy_key, psa_purge_key and psa_close_key
This does not yet implement destruction while a key is in use for psa_destroy_key;
that will be implemented in a separate pr.
(I am not sure if I am allowed to change the documentation in the include files.)
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index a27fd42..3e49d0a 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1048,11 +1048,13 @@
* implemented), the key should be destroyed when all accesses have
* stopped.
*/
- if (slot->lock_count > 1) {
- psa_unlock_key_slot(slot);
+ if (slot->registered_readers > 1) {
+ psa_unregister_read(slot);
return PSA_ERROR_GENERIC_ERROR;
}
+ slot->state = PSA_SLOT_PENDING_DELETION;
+
if (PSA_KEY_LIFETIME_IS_READ_ONLY(slot->attr.lifetime)) {
/* Refuse the destruction of a read-only key (which may or may not work
* if we attempt it, depending on whether the key is merely read-only
@@ -1126,7 +1128,7 @@
exit:
status = psa_wipe_key_slot(slot);
- /* Prioritize CORRUPTION_DETECTED from wiping over a storage error */
+ /* Prioritize an error from wiping over a storage error */
if (status != PSA_SUCCESS) {
overall_status = status;
}