Skip to content

Commit adcaf09

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Allow importing the nRF54L PROT_RAM invalidation slots
Add a Kconfig option to allow performing a psa_import_key in order to provision the KMU slots used for invalidating the protected RAM content. With this change a psa_import_key with KMU slot 248 will populate the KMU invilidation slots with random data so that it can be used later. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent dbf4028 commit adcaf09

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

subsys/nrf_security/src/drivers/cracen/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ config CRACEN_PROVISION_PROT_RAM_INV_SLOTS_ON_INIT
7575
When disabled the application is expected to provision the reserved KMU slots 248 and 249
7676
manually, otherwise the protected RAM keys will not be usable.
7777

78+
config CRACEN_PROVISION_PROT_RAM_INV_SLOTS_WITH_IMPORT
79+
bool "Provision protected RAM invalidation slots using psa_import_key"
80+
depends on CRACEN_LIB_KMU
81+
depends on !CRACEN_PROVISION_PROT_RAM_INV_SLOTS_ON_INIT
82+
help
83+
Provision the protected RAM invalidation KMU slots (248,249) in the KMU using a
84+
psa_import_key call. The application is required to call psa_import_key with the
85+
KMU slot 248. The key material provided is ignored and random data is generated to
86+
populate the slots.
87+
This is meant to be used by a provisioning image that runs once before the application
88+
image is flashed. This is not meant to be used by user applications.
89+
7890
config CRACEN_IKG
7991
bool "CRACEN IKG"
8092
help

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,14 @@ psa_status_t cracen_import_key(const psa_key_attributes_t *attributes, const uin
954954
MBEDTLS_SVC_KEY_ID_GET_KEY_ID(psa_get_key_id(attributes)));
955955
psa_key_attributes_t stored_attributes;
956956

957+
#ifdef CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_WITH_IMPORT
958+
if (slot_id == PROTECTED_RAM_INVALIDATION_DATA_SLOT1) {
959+
/* The key bits are required for the psa_import_key to succeed */
960+
*key_bits = 256;
961+
return cracen_provision_prot_ram_inv_slots();
962+
}
963+
#endif
964+
957965
size_t opaque_key_size;
958966
psa_status_t status = cracen_get_opaque_size(attributes, &opaque_key_size);
959967

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ static psa_status_t cracen_kmu_decrypt(kmu_metadata *metadata, size_t number_of_
206206

207207
#endif /* PSA_NEED_CRACEN_KMU_ENCRYPTED_KEYS */
208208

209-
#ifdef CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_ON_INIT
209+
#if defined(CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_ON_INIT) || \
210+
defined(CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_WITH_IMPORT)
210211
psa_status_t cracen_provision_prot_ram_inv_slots(void)
211212
{
212213
uint8_t rng_buffer[2 * CRACEN_KMU_SLOT_KEY_SIZE];
@@ -254,9 +255,9 @@ psa_status_t cracen_provision_prot_ram_inv_slots(void)
254255
safe_memzero(rng_buffer, sizeof(rng_buffer));
255256
return psa_status;
256257
}
257-
#endif /* CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_ON_INIT */
258-
259-
258+
#endif /* CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_ON_INIT ||
259+
* CONFIG_CRACEN_PROVISION_PROT_RAM_INV_SLOTS_WITH_IMPORT
260+
*/
260261
/* Used internally in sxsymcrypt so we use sx return codes here. */
261262
int cracen_kmu_prepare_key(const uint8_t *user_data)
262263
{

0 commit comments

Comments
 (0)