@@ -117,7 +117,7 @@ static psa_status_t get_encryption_key(const uint8_t *context, uint8_t *key)
117117 psa_set_key_id (& mkek_attr , mbedtls_svc_key_id_make (0 , CRACEN_BUILTIN_MKEK_ID ));
118118 psa_set_key_lifetime (& mkek_attr ,
119119 PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (
120- PSA_KEY_PERSISTENCE_READ_ONLY , PSA_KEY_LOCATION_CRACEN ));
120+ CRACEN_KEY_PERSISTENCE_READ_ONLY , PSA_KEY_LOCATION_CRACEN ));
121121
122122 cracen_key_derivation_operation_t op = {};
123123
@@ -418,13 +418,19 @@ static psa_status_t get_kmu_slot_id_and_count(const psa_key_attributes_t *key_at
418418
419419psa_status_t cracen_kmu_destroy_key (const psa_key_attributes_t * attributes )
420420{
421- psa_key_location_t location =
422- PSA_KEY_LIFETIME_GET_LOCATION (psa_get_key_lifetime (attributes ));
421+ psa_key_lifetime_t lifetime = psa_get_key_lifetime (attributes );
422+
423+ psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION (lifetime );
424+ psa_key_persistence_t persistence = PSA_KEY_LIFETIME_GET_PERSISTENCE (lifetime );
423425
424426 if (location == PSA_KEY_LOCATION_CRACEN_KMU ) {
425427 psa_status_t status ;
426428 unsigned int slot_id , slot_count ;
427429
430+ if (persistence == CRACEN_KEY_PERSISTENCE_READ_ONLY ) {
431+ return PSA_ERROR_NOT_PERMITTED ;
432+ }
433+
428434 status = get_kmu_slot_id_and_count (attributes , & slot_id , & slot_count );
429435 if (status != PSA_SUCCESS ) {
430436 return status ;
@@ -458,7 +464,7 @@ static psa_status_t convert_to_psa_attributes(kmu_metadata *metadata,
458464 key_persistence = CRACEN_KEY_PERSISTENCE_REVOKABLE ;
459465 break ;
460466 case LIB_KMU_REV_POLICY_LOCKED :
461- key_persistence = PSA_KEY_PERSISTENCE_READ_ONLY ;
467+ key_persistence = CRACEN_KEY_PERSISTENCE_READ_ONLY ;
462468 break ;
463469 default :
464470 return PSA_ERROR_STORAGE_FAILURE ;
@@ -783,6 +789,7 @@ static psa_status_t convert_from_psa_attributes(const psa_key_attributes_t *key_
783789
784790 switch (PSA_KEY_LIFETIME_GET_PERSISTENCE (psa_get_key_lifetime (key_attr ))) {
785791 case PSA_KEY_PERSISTENCE_READ_ONLY :
792+ case CRACEN_KEY_PERSISTENCE_READ_ONLY :
786793 metadata -> rpolicy = LIB_KMU_REV_POLICY_LOCKED ;
787794 break ;
788795 case PSA_KEY_PERSISTENCE_DEFAULT :
@@ -936,17 +943,28 @@ psa_status_t cracen_kmu_get_key_slot(mbedtls_svc_key_id_t key_id, psa_key_lifeti
936943 psa_status_t status ;
937944 unsigned int slot_id ;
938945 kmu_metadata metadata ;
946+ psa_key_persistence_t persistence ;
939947
940948 status = get_kmu_slot_id_and_metadata (key_id , & slot_id , & metadata );
941949 if (status != PSA_SUCCESS ) {
942950 return status ;
943951 }
944952
945- psa_key_persistence_t read_only = metadata .rpolicy == LIB_KMU_REV_POLICY_ROTATING
946- ? PSA_KEY_PERSISTENCE_DEFAULT
947- : PSA_KEY_PERSISTENCE_READ_ONLY ;
953+ switch (metadata .rpolicy ) {
954+ case LIB_KMU_REV_POLICY_ROTATING :
955+ persistence = PSA_KEY_PERSISTENCE_DEFAULT ;
956+ break ;
957+ case LIB_KMU_REV_POLICY_REVOKED :
958+ persistence = CRACEN_KEY_PERSISTENCE_REVOKABLE ;
959+ break ;
960+ case LIB_KMU_REV_POLICY_LOCKED :
961+ persistence = CRACEN_KEY_PERSISTENCE_READ_ONLY ;
962+ break ;
963+ default :
964+ return PSA_ERROR_INVALID_ARGUMENT ;
965+ }
948966
949- * lifetime = PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (read_only ,
967+ * lifetime = PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (persistence ,
950968 PSA_KEY_LOCATION_CRACEN_KMU );
951969 * slot_number = slot_id ;
952970
0 commit comments