Skip to content

Commit 5716767

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Add platform key revocation support for SICR keys
Adds support of key revocation using the psa_destroy_key API. The value 0xfa50 is used in the key type in order to mark an revoked key. The return code PSA_ERROR_NOT_PERMITTED is returned for revoked keys for all the functions in the PSA crypto driver wrapper. This error code seems OK since it mentions platform specific policies for not permitted an operation. Ref: NCSDK-30076 Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent fe5f682 commit 5716767

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/key_management.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,9 @@ psa_status_t cracen_destroy_key(const psa_key_attributes_t *attributes)
14061406
#ifdef CONFIG_PSA_NEED_CRACEN_KMU_DRIVER
14071407
return cracen_kmu_destroy_key(attributes);
14081408
#endif
1409+
#ifdef CONFIG_PSA_NEED_CRACEN_PLATFORM_KEYS
1410+
return cracen_platform_destroy_key(attributes);
1411+
#endif
14091412

14101413
return PSA_ERROR_DOES_NOT_EXIST;
14111414
}

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/platform_keys/platform_keys.c

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#define PLATFORM_KEY_GET_DOMAIN(x) (((x) >> 16) & 0xff)
3838
#define PLATFORM_KEY_GET_ACCESS(x) (((x) >> 24) & 0xf)
3939

40+
#define PLATFORM_KEY_REVOKED_FLAG (0xFA50)
41+
4042
#define MAX_KEY_SIZE 32
4143

4244
static struct {
@@ -144,6 +146,7 @@ typedef enum {
144146
DERIVED,
145147
SICR,
146148
IKG,
149+
REVOKED
147150
} key_type;
148151

149152
#define APPEND_STR(str, end, part) \
@@ -176,7 +179,7 @@ static key_type find_key(uint32_t id, platform_key *key)
176179
key->sicr.key_buffer_max_length = sizeof((x)[gen].CIPHERTEXT); \
177180
key->sicr.mac = (uint8_t *)(x)[gen].MAC; \
178181
key->sicr.mac_size = sizeof((x)[gen].MAC); \
179-
return SICR; \
182+
return (key->sicr.type == PLATFORM_KEY_REVOKED_FLAG) ? REVOKED : SICR; \
180183
} \
181184
break;
182185

@@ -194,7 +197,7 @@ static key_type find_key(uint32_t id, platform_key *key)
194197
key->sicr.key_buffer_max_length = sizeof((x)[gen].PUBKEY); \
195198
key->sicr.mac = (uint8_t *)(x)[gen].MAC; \
196199
key->sicr.mac_size = sizeof((x)[gen].MAC); \
197-
return SICR; \
200+
return (key->sicr.type == PLATFORM_KEY_REVOKED_FLAG) ? REVOKED : SICR; \
198201
} \
199202
break;
200203

@@ -378,6 +381,10 @@ psa_status_t cracen_platform_get_builtin_key(psa_drv_slot_number_t slot_number,
378381
platform_key key;
379382
key_type type = find_key((uint32_t)slot_number, &key);
380383

384+
if (type == REVOKED) {
385+
return PSA_ERROR_NOT_PERMITTED;
386+
}
387+
381388
if (type == SICR) {
382389
uint32_t key_id = (uint32_t)slot_number;
383390
uint32_t domain = PLATFORM_KEY_GET_DOMAIN(key_id);
@@ -567,13 +574,13 @@ psa_status_t cracen_platform_keys_get_size(psa_key_attributes_t const *attribute
567574
key_type type = find_key(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(attributes)), &key);
568575
psa_key_type_t key_type = psa_get_key_type(attributes);
569576

570-
if (type == IKG) {
577+
if (type == REVOKED) {
578+
return PSA_ERROR_NOT_PERMITTED;
579+
} else if (type == IKG) {
571580
*key_size = sizeof(ikg_opaque_key);
572581
return PSA_SUCCESS;
573-
}
574-
575-
if (key_type == PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_TWISTED_EDWARDS) ||
576-
key_type == PSA_KEY_TYPE_AES) {
582+
} else if (key_type == PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_TWISTED_EDWARDS) ||
583+
key_type == PSA_KEY_TYPE_AES) {
577584
*key_size = PSA_BITS_TO_BYTES(psa_get_key_bits(attributes));
578585
return PSA_SUCCESS;
579586
}
@@ -587,6 +594,10 @@ psa_status_t cracen_platform_get_key_slot(mbedtls_svc_key_id_t key_id, psa_key_l
587594
platform_key key;
588595
key_type type = find_key(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key_id), &key);
589596

597+
if (type == REVOKED) {
598+
return PSA_ERROR_NOT_PERMITTED;
599+
}
600+
590601
psa_status_t status = verify_access(MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(key_id),
591602
MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key_id));
592603
if (status != PSA_SUCCESS) {
@@ -625,7 +636,9 @@ psa_status_t cracen_platform_keys_provision(const psa_key_attributes_t *attribut
625636
uint8_t encrypted_key[MAX_KEY_SIZE];
626637
size_t outlen;
627638

628-
if (type != SICR) {
639+
if (type == REVOKED) {
640+
return PSA_ERROR_NOT_PERMITTED;
641+
} else if (type != SICR) {
629642
return PSA_ERROR_INVALID_ARGUMENT;
630643
}
631644

@@ -712,3 +725,37 @@ psa_status_t cracen_platform_keys_provision(const psa_key_attributes_t *attribut
712725

713726
return status;
714727
}
728+
729+
psa_status_t cracen_platform_destroy_key(const psa_key_attributes_t *attributes)
730+
{
731+
platform_key key;
732+
key_type type = find_key(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(attributes)), &key);
733+
/* The value 0x00 was chosen arbitrarily here, 0xFF was not used to distinguish revoked keys
734+
* from keys not yet written.
735+
*/
736+
static const uint8_t revoked_key_val[MAX_KEY_SIZE] = {0x0};
737+
738+
if (type == REVOKED) {
739+
return PSA_ERROR_NOT_PERMITTED;
740+
} else if (type != SICR) {
741+
return PSA_ERROR_INVALID_ARGUMENT;
742+
}
743+
744+
psa_status_t status =
745+
verify_access(MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(psa_get_key_id(attributes)),
746+
MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(attributes)));
747+
748+
if (status != PSA_SUCCESS) {
749+
return status;
750+
}
751+
752+
uint32_t revoked_key_attr = (key.sicr.bits << 16) | PLATFORM_KEY_REVOKED_FLAG;
753+
754+
/* The nonce will be written to MRAM based on the buffer in the platform_key, so we
755+
* set it here before the call to write function.
756+
*/
757+
key.sicr.nonce[0] = 0x0;
758+
write_sicr_key_to_mram(&key, revoked_key_attr, revoked_key_val, sizeof(revoked_key_val));
759+
760+
return PSA_SUCCESS;
761+
}

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/platform_keys/platform_keys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ psa_status_t cracen_platform_get_key_slot(mbedtls_svc_key_id_t key_id, psa_key_l
2222
psa_status_t cracen_platform_keys_provision(const psa_key_attributes_t *attributes,
2323
const uint8_t *key_buffer, size_t key_buffer_size);
2424

25+
psa_status_t cracen_platform_destroy_key(const psa_key_attributes_t *attributes);
26+
2527
#endif /* CRACEN_PLATFORM_KEYS_H */

0 commit comments

Comments
 (0)