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_slot_management.c b/library/psa_crypto_slot_management.c
index 4846e33..a21388a 100644
--- a/library/psa_crypto_slot_management.c
+++ b/library/psa_crypto_slot_management.c
@@ -539,11 +539,14 @@
 
         return status;
     }
-    if (slot->lock_count <= 1) {
-        return psa_wipe_key_slot(slot);
-    } else {
-        return psa_unlock_key_slot(slot);
+    if (slot->registered_readers == 1) {
+        status = psa_key_slot_state_transition(slot, PSA_SLOT_FULL,
+                                               PSA_SLOT_PENDING_DELETION);
+        if (status != PSA_SUCCESS) {
+            return status;
+        }
     }
+    return psa_unregister_read(slot);
 }
 
 psa_status_t psa_purge_key(mbedtls_svc_key_id_t key)
@@ -557,11 +560,11 @@
     }
 
     if ((!PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) &&
-        (slot->lock_count <= 1)) {
-        return psa_wipe_key_slot(slot);
-    } else {
-        return psa_unlock_key_slot(slot);
+        (slot->registered_readers == 1)) {
+        psa_key_slot_state_transition(slot, PSA_SLOT_FULL,
+                                      PSA_SLOT_PENDING_DELETION);
     }
+    return psa_unregister_read(slot);
 }
 
 void mbedtls_psa_get_stats(mbedtls_psa_stats_t *stats)