Skip to content

Commit 6558266

Browse files
greg-ferrlubos
authored andcommitted
doc: nrf54l: kmu production programming
Added a section in the nRF54L dev guide about KMU provisioning for production. NCSDK-35877. Signed-off-by: Grzegorz Ferenc <[email protected]>
1 parent 00c893a commit 6558266

File tree

6 files changed

+386
-37
lines changed

6 files changed

+386
-37
lines changed

doc/nrf/app_dev/device_guides/nrf54l/cryptography.rst

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ On nRF54L Series devices, the CRACEN cryptographic driver provides entropy and h
1414
The CRACEN driver supports the following features:
1515

1616
* Executing :ref:`cryptographic operations <ug_crypto_supported_features>` using the CRACEN hardware peripheral.
17-
* Importing, using, and revoking keys stored in the :ref:`Key Management Unit (KMU) <ug_nrf54l_developing_basics_kmu>`.
17+
* Importing, using, and revoking keys stored in the Key Management Unit (KMU) hardware peripheral.
1818
* Pushing symmetric keys directly from the KMU to the CRACEN symmetric engine, without exposing the key material to the CPU.
1919
* Using isolated keys derived from CRACEN's Isolated Key Generator (IKG) for encryption and signing purposes.
2020

@@ -26,11 +26,15 @@ KMU and CRACEN peripherals
2626
**************************
2727

2828
The CRACEN and the KMU hardware peripherals, along with the CRACEN driver, are central when ensuring that the assets of an nRF54L device are protected.
29-
While CRACEN is not accessed by the CPU and typically not directly used by the end-users and their applications, the KMU provides operations to import, use, revoke, or delete assets.
29+
30+
The CRACEN hardware peripheral is not accessed by the CPU and typically not directly used by the end-users and their applications.
31+
32+
The KMU acts as an intermediary between the CPU and the CRACEN hardware peripheral.
33+
It is designed to hide information from the CPU, while providing operations to import, use, revoke, or delete assets (keys and metadata).
3034
Only the KMU is able to push assets to CRACEN's protected RAM and the SEED register.
3135

3236
.. note::
33-
CRACEN relies on microcode for asymmetric cryptography operations like signature validation.
37+
The CRACEN hardware peripheral relies on microcode for asymmetric cryptography operations like signature validation.
3438
On the nRF54L15, nRF54L10, and nRF54L05 devices, this microcode must be uploaded to a special CRACEN RAM area before first use and after each reset.
3539

3640
If a bootloader uploads this microcode, there is no need to re-upload it for application use.
@@ -39,7 +43,7 @@ Only the KMU is able to push assets to CRACEN's protected RAM and the SEED regis
3943

4044
The KMU can store cryptographic keys and 384-bit random seeds for the IKG in key storage slots.
4145
The CRACEN driver exposes the KMU operations through standard PSA Crypto API calls, with some vendor-specific extensions.
42-
The following KMU operations are supported:
46+
The following KMU operations are supported by the driver:
4347

4448
* Importing/provisioning keys to KMU slots.
4549
* Deleting a key from the KMU, allowing the underlying storage location to be reused.
@@ -50,15 +54,20 @@ The following KMU operations are supported:
5054

5155
Additionally, the CRACEN driver supports storing encrypted keys in KMU slots, transparently decrypting them to a temporary RAM location before using them in cryptographic operations.
5256

57+
For more information about these hardware peripherals, see the related pages in the device datasheet, for example `KMU - Key management unit <nRF54L15 Key management unit_>`_ and `CRACEN - Crypto accelerator engine <nRF54L15 CRACEN_>`_ in the nRF54L15 datasheet.
58+
5359
.. _ug_nrf54l_crypto_kmu_slots:
5460

5561
KMU slots
5662
=========
5763

58-
The KMU is partitioned into 256 numbered slots, each capable of storing 128 bits of key material, a 32-bit target push address and 32 bits of metadata.
64+
The KMU is partitioned into 256 numbered slots.
65+
Each KMU slot is capable of storing 128 bits of key material, a 32-bit destination address (``kmu_push_area``), and 32 bits of KMU metadata (:c:struct:`kmu_metadata`).
5966
Storing keys that are larger than 128 bits is supported by using multiple, consecutive slots.
6067

61-
The application can use the KMU slots to store key data for their own purposes.
68+
See the device datasheet, for example `KMU - Key management unit <nRF54L15 Key management unit_>`_ in the nRF54L15 datasheet.
69+
70+
The application can use the KMU slots to store key data for its own purposes.
6271
Some KMU slots are reserved for current and future |NCS| use cases.
6372
The following table gives an overview of the KMU slots and their usage:
6473

@@ -151,12 +160,12 @@ The keys are not exportable, except for the public key associated with the asymm
151160

152161
.. _ug_nrf54l_crypto_kmu_key_programming_model:
153162

154-
Programming model for referencing keys
155-
**************************************
163+
PSA Crypto API programming model for KMU keys
164+
*********************************************
156165

157166
The keys that are stored in the KMU can be used by most cryptographic functions and key management functions in the PSA Crypto API (see `PSA Certified Crypto API 1.3.1`_), with a built-in key ID representing a particular KMU slot.
158167

159-
To identify that the KMU is used as a persistent storage backend for a specific ``psa_key_id_t``, you need to create a ``psa_key_attributes_t`` structure and set the required attributes from the list below.
168+
To identify that the KMU is used as a persistent storage backend for a specific ``psa_key_id_t``, you need to create a :c:struct:`psa_key_attributes_t` structure and set the required attributes from the following list.
160169

161170
+----------------------------------------------+-----------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
162171
| Attribute (setter function) | Parameters | Description |
@@ -169,7 +178,7 @@ To identify that the KMU is used as a persistent storage backend for a specific
169178
| | | |
170179
| | | See :ref:`ug_nrf54l_crypto_kmu_supported_key_types` for overview of the supported key types for each driver. |
171180
+----------------------------------------------+-----------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
172-
| ``key lifetime`` (``psa_set_key_lifetime``) | ``PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location)`` | ``CRACEN_KEY_PERSISTENCE_REVOKABLE`` is a custom persistence mode, which will revoke the key slots when the key is destroyed. |
181+
| ``key_lifetime`` (``psa_set_key_lifetime``) | ``PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location)`` | ``CRACEN_KEY_PERSISTENCE_REVOKABLE`` is a custom persistence mode, which will revoke the key slots when the key is destroyed. |
173182
| | where persistence is set to one of the following: | |
174183
| | ``PSA_KEY_PERSISTENCE_DEFAULT``, | ``PSA_KEY_PERSISTENCE_DEFAULT`` should be used by applications that have no specific needs beyond what is met by implementation-specific features. |
175184
| | ``CRACEN_KEY_PERSISTENCE_READ_ONLY``, | |
@@ -181,7 +190,7 @@ To identify that the KMU is used as a persistent storage backend for a specific
181190
| | | |
182191
| | | For correct ``kmu_slot_nr`` values, see :ref:`ug_nrf54l_crypto_kmu_slots`. |
183192
+----------------------------------------------+-----------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
184-
| ``key_usage`` (``psa_set_key_usage_flags``) | Standard PSA Crypto key usage flags | ``PSA_KEY_USAGE_EXPORT`` and ``PSA_KEY_USAGE_COPY`` are not allowed for keys with the usage scheme ``CRACEN_KEY_USAGE_SCHEME_PROTECTED``. |
193+
| ``key_usage`` (``psa_set_key_usage_flags``) | Standard PSA Crypto key usage flags. | ``PSA_KEY_USAGE_EXPORT`` and ``PSA_KEY_USAGE_COPY`` are not allowed for keys with the usage scheme ``CRACEN_KEY_USAGE_SCHEME_PROTECTED``. |
185194
+----------------------------------------------+-----------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
186195

187196
.. _ug_nrf54l_crypto_kmu_key_usage_schemes:
@@ -336,14 +345,17 @@ For each key type, the table lists the supported algorithms and indicates which
336345
- Yes
337346
.. [1] Store each key with only one algorithm to follow PSA Crypto best practices.
338347
.. [2] Keys with the Encrypted usage scheme (``CRACEN_KMU_KEY_USAGE_SCHEME_ENCRYPTED``) will require two additional KMU slots to store the nonce and the authentication tag.
339-
.. [3] 192-bit key size is not supported on nRF54LM20.
348+
.. [3] 192-bit key size is not supported on nRF54LM20A.
340349
.. [4] ECDH not supported for key derivation.
341350
351+
.. _ug_nrf54l_crypto_kmu_storing_keys:
352+
342353
Storing keys in KMU
343354
===================
344355

345-
Applications can store keys in KMU slots using the standard PSA cryptographic key management operations ``psa_import_key``, ``psa_generate_key`` or ``psa_copy_key``.
346-
Additionally, the KMU slots can be provisioned :ref:`using the nRF Util development tool <ug_nrf54l_developing_provision_kmu_provisioning>`.
356+
Applications can store keys in KMU slots using the standard PSA Crypto API key management operations, such as ``psa_import_key``, ``psa_generate_key``, or ``psa_copy_key``.
357+
Additionally, the KMU slots can be provisioned :ref:`for development or for production <ug_nrf54l_developing_provision_kmu_provisioning>`.
358+
Provisioning for production requires manually setting up the :c:struct:`kmu_metadata` data structure for each key slot.
347359

348360
.. note::
349361
If a power failure occurs during provisioning of a key with persistence ``CRACEN_KEY_PERSISTENCE_READ_ONLY`` or ``CRACEN_KEY_PERSISTENCE_REVOKABLE``, it might not be possible to recover the key slot.
@@ -354,6 +366,47 @@ You might encounter the following KMU-specific error codes when storing keys in
354366
* ``PSA_ERROR_ALREADY_EXIST``: One of the required key slots has already been provisioned.
355367
* ``PSA_ERROR_NOT_SUPPORTED``: Unsupported key type.
356368

369+
.. _ug_nrf54l_crypto_kmu_metadata:
370+
371+
KMU metadata
372+
------------
373+
374+
After you store the keys in KMU, you need the CRACEN driver to be able to verify some properties of the key and its intended usage.
375+
The driver can then use the key material for different operations, such as a decryption or a signature verification.
376+
377+
For the verification of the key, the CRACEN driver requires information from the METADATA field of the SRC data struct, as explained in the device datasheet (for example, `KMU - Key management unit <nRF54L15 Key management unit_>`_ in the nRF54L15 datasheet).
378+
The encoding of information in the METADATA field is detailed in the :c:struct:`kmu_metadata` structure, a 32-bit bitfield defined in the CRACEN driver source code (:file:`nrf/subsys/nrf_security/src/drivers/cracen/cracenpsa/src/kmu.c`).
379+
380+
When the application uses ``psa_import_key`` or ``psa_generate_key`` to store a key in KMU slots, the CRACEN driver encodes :c:struct:`kmu_metadata` with the appropriate values based on the :ref:`PSA key attributes given to the functions <ug_nrf54l_crypto_kmu_key_programming_model>` (:c:struct:`psa_key_attributes_t`).
381+
The CRACEN driver performs the following steps:
382+
383+
1. Checks ``key_id`` to determine the KMU slot usage.
384+
#. Converts PSA key attributes to :c:struct:`kmu_metadata` bitfields.
385+
#. Sets the KMU slot's RPOLICY field (whether the key should be revokable, read-only, or deletable).
386+
#. Sets the KMU slot's DEST address to one of the following locations:
387+
388+
* CRACEN's protected RAM if the key is a symmetric key (has the usage scheme set to :ref:`Protected <ug_nrf54l_crypto_kmu_key_usage_schemes>`)
389+
* CRACEN's SEED register (for IKG keys)
390+
* The reserved RAM area ``kmu_push_area`` (0x20000000-0x20000064) for other keys
391+
392+
#. Stores the :c:struct:`kmu_metadata` information in the KMU slot's METADATA field.
393+
#. Stores the key material in the KMU slot's VALUE field.
394+
395+
When the keys are larger than 128 bits and span several consecutive KMU slots, the following rules apply:
396+
397+
* Only the first slot (primary slot) contains the complete :c:struct:`kmu_metadata` structure.
398+
* Secondary slots have their METADATA field set to ``0xffffffff`` (``SECONDARY_SLOT_METADATA_VALUE``).
399+
* Each secondary slot's DEST address is incremented by 16 bytes (128 bits) compared to the previous slot.
400+
* All slots used by a key must have the same RPOLICY value.
401+
402+
KMU metadata handling in development and production
403+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404+
405+
During development, you can use the tools for :ref:`ug_nrf54l_developing_provision_kmu_development` to automatically set up and encode the :c:struct:`kmu_metadata` data structure based on :c:struct:`psa_key_attributes_t` in a way that they match the required values for different key types and CRACEN driver's own requirements.
406+
407+
When programming for production, you need to manually make sure that the values set in the :c:struct:`kmu_metadata` data structure's bitfields match the required values.
408+
See :ref:`ug_nrf54l_developing_provision_kmu_production` for more information.
409+
357410
Removing or revoking keys from KMU
358411
==================================
359412

@@ -363,7 +416,7 @@ Calling the ``psa_destroy_key`` function on keys that have the persistence ``CRA
363416
Using KMU keys
364417
==============
365418

366-
Keys stored in the KMU can be used in standard PSA Crypto operations for encryption, decryption, signing a hash or a message, and verifying a hash or a message, given that the corresponding ``PSA_KEY_USAGE_*`` flags are set.
419+
Keys stored in the KMU can be used in standard PSA Crypto API operations for encryption, decryption, signing a hash or a message, and verifying a hash or a message, given that the corresponding ``PSA_KEY_USAGE_*`` flags are set.
367420

368421
Depending on the usage scheme:
369422

doc/nrf/app_dev/device_guides/nrf54l/kmu_basics.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Introduction to KMU key provisioning
77
:local:
88
:depth: 2
99

10-
The nRF54L devices are equipped with a Key Management Unit (KMU) that facilitates secure and confidential storage of keys.
10+
The nRF54L devices are equipped with a Key Management Unit (KMU) that facilitates secure and confidential storage of keys in a dedicated region of RRAM (secure information configuration region, or SICR).
11+
The process of storing a key and its metadata in a key slot in SICR is known as the KMU provisioning.
12+
1113
This feature is crucial not only for private keys but also for public keys, as the :ref:`KMU can directly transfer a key to the CRACEN RAM<ug_nrf54l_crypto_kmu_cracen_peripherals>`.
1214
Even when keys must pass through addressable RAM, the KMU significantly reduces the risk of key exposure.
1315
Therefore, you should use KMU for managing secrets whenever possible.
@@ -16,7 +18,9 @@ When using an nRF54L device with Trusted Firmware-M, you can use the KMU to stor
1618
For this to work, you need to enable the :ref:`tfm_partition_crypto`, which enables the :ref:`ug_tfm_services_its` by default.
1719
You can then manually disable the ITS service and start using KMU instead.
1820

19-
Key Types
21+
.. _ug_nrf54l_developing_basics_kmu_key_types:
22+
23+
Key types
2024
*********
2125

2226
Different types of keys, such as revocable and locked keys, serve distinct purposes and have unique policies associated with their use and management.
@@ -79,3 +83,10 @@ You can consider the following options:
7983
The disadvantage is that the method does not support multiple generations of keys.
8084

8185
Always consider the specific security needs of your application and choose the most appropriate key management approach to safeguard your digital assets.
86+
87+
More information
88+
****************
89+
90+
For more conceptual information about the KMU hardware peripheral, see the page about KMU in the device datasheet, for example `KMU - Key management unit <nRF54L15 Key management unit_>`_ in the nRF54L15 datasheet.
91+
92+
For the description of the KMU provisioning procedure, see :ref:`ug_nrf54l_developing_provision_kmu` in the |NCS| documentation and the `Provisioning KMU data`_ page in the `nRF54L Series Production Programming`_ guide.

0 commit comments

Comments
 (0)