Skip to content

Commit da51121

Browse files
greg-ferrlubos
authored andcommitted
doc: crypto: document PSA_NEED selection
Added information about PSA_NEED selection. NCSDK-30024. Signed-off-by: Grzegorz Ferenc <[email protected]>
1 parent 512159a commit da51121

File tree

3 files changed

+310
-42
lines changed

3 files changed

+310
-42
lines changed

doc/nrf/security/crypto/driver_config.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ To use the :ref:`nrf_cc3xx_mbedcrypto_readme` PSA driver, the Arm CryptoCell CC3
5050
The Arm CryptoCell hardware compatible with nrf_cc3xx is initialized in the :file:`hw_cc3xx.c` file, located under :file:`nrf/drivers/hw_cc3xx/`, and is controlled with the :kconfig:option:`CONFIG_HW_CC3XX` Kconfig option.
5151
The Kconfig option has a default value of ``y`` when nrf_cc3xx is available in the SoC.
5252

53-
Enabling the nrf_oberon driver
54-
==============================
55-
56-
To enable the :ref:`nrf_security_drivers_oberon`, set the :kconfig:option:`CONFIG_PSA_CRYPTO_DRIVER_OBERON` Kconfig option.
57-
5853
Enabling the CRACEN driver
5954
==========================
6055

@@ -66,6 +61,19 @@ The nrf_oberon driver may then be disabled by using the Kconfig option :kconfig:
6661
On nRF54L Series devices, CRACEN is the only source of entropy.
6762
Therefore, it is not possible to disable the :kconfig:option:`CONFIG_PSA_CRYPTO_DRIVER_CRACEN` Kconfig option when the Zephyr entropy driver is enabled.
6863

64+
Enabling the nrf_oberon driver
65+
==============================
66+
67+
To enable the :ref:`nrf_security_drivers_oberon`, set the :kconfig:option:`CONFIG_PSA_CRYPTO_DRIVER_OBERON` Kconfig option to ``y``.
68+
Enabling the nrf_oberon driver automatically enables the :ref:`software fallback mechanism to nrf_oberon <crypto_drivers_software_fallback>`.
69+
70+
.. _psa_crypto_support_disable_software_fallback:
71+
72+
Disabling the software fallback
73+
===============================
74+
75+
To disable the :ref:`software fallback mechanism to nrf_oberon <crypto_drivers_software_fallback>`, set the :kconfig:option:`CONFIG_PSA_CRYPTO_DRIVER_OBERON` Kconfig option to ``n``.
76+
6977
.. _psa_crypto_support_multiple_drivers:
7078

7179
Configuring multiple drivers

doc/nrf/security/crypto/drivers.rst

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ The following figure shows a simplified overview of the driver library selection
8080
As shown in this simplified figure, the API calls can go in both directions between the driver wrapper and the drivers.
8181
This represents the following situations:
8282

83-
* Fallback mechanisms - The Oberon PSA Crypto implementation in the |NCS| provides a transparent fallback mechanism that allows applications to use hardware acceleration where available.
84-
If a hardware driver does not support a particular operation or key size, the driver wrapper will redirect the call to a software implementation.
85-
The fallback mechanism is enabled by default, but you can manually disable it.
86-
* Feature selection - Based on hardware capabilities and cryptographic features you have configured, the driver wrapper selects the most appropriate driver for each cryptographic operation.
87-
* Driver chaining - Higher-level drivers (like HMAC) can delegate operations to lower-level drivers (like hash functions).
83+
* `Feature selection`_ - Based on hardware capabilities and cryptographic features you have configured, the driver wrapper selects the most appropriate driver for each cryptographic operation.
84+
* `Software fallback`_ - The Oberon PSA Crypto implementation in the |NCS| provides a transparent fallback mechanism that allows applications to use the software nrf_oberon driver when the hardware acceleration is not available.
85+
* `Driver chaining`_ - Higher-level drivers (like HMAC) can delegate operations to lower-level drivers (like hash functions).
8886
For example, when an HMAC operation is requested, the HMAC driver might call back to the driver wrapper to use a hardware-accelerated hash function.
8987

9088
These situations are explained in more detail in the following sections.
9189

90+
.. _crypto_drivers_example_flow:
91+
9292
Example of driver selection flow
9393
================================
9494

@@ -124,29 +124,31 @@ When an application initiates a cryptographic operation through the PSA Crypto A
124124
#. The driver wrapper selects the appropriate driver and forwards the request to the driver.
125125
Using the example of the three features:
126126

127-
* Feature A - The driver wrapper follows the default configuration process and selects the nrf_cc3xx driver (assuming that the platform supports it).
127+
* Feature A - The driver wrapper follows the default configuration process and selects the nrf_cc3xx driver (assuming that the platform supports it.)
128128
The software nrf_oberon driver could also be chosen, but the nrf_cc3xx driver is given priority because it is hardware-accelerated.
129129
* Feature B - The driver wrapper selects the software nrf_oberon driver.
130130
This is because neither the nrf_cc3xx driver nor the CRACEN driver support Feature B.
131131
* Feature C - The driver wrapper selects the software nrf_oberon driver, following the configuration priority set by the application.
132132
The CRACEN driver supports this feature, but the user has disabled the hardware driver support for Feature C in the application configuration.
133133

134-
Fallback mechanism and feature selection
135-
========================================
134+
.. _crypto_drivers_feature_selection:
135+
136+
Feature selection
137+
=================
136138

137-
The Oberon PSA Crypto implementation provides a mechanism for specifying the cryptographic features and selecting the driver to use for each cryptographic operation.
138-
This mechanism uses the ``PSA_WANT_*`` and ``PSA_USE_*`` directives for these purposes, respectively.
139-
These directives are used by the nRF Security library to select the most appropriate driver for each cryptographic operation.
139+
The Oberon PSA Crypto implementation provides a mechanism for configuring each cryptographic operation.
140+
This mechanism uses the ``PSA_WANT_*`` directives for specifying the cryptographic features and ``PSA_USE_*`` directives for selecting the driver for each cryptographic operation.
141+
The driver wrapper then selects the most appropriate driver for each cryptographic operation.
140142

141143
Feature selection in the |NCS|
142144
------------------------------
143145

144146
In Zephyr and the |NCS|, Oberon's ``PSA_WANT_*`` and ``PSA_USE_*`` directives are integrated into the :ref:`Kconfig configuration system <app_build_system>`.
145147
As a result, Oberon's directives are wrapped by Kconfig options ``CONFIG_PSA_WANT_*`` and ``CONFIG_PSA_USE_*``, respectively.
146-
Some of these Kconfig options are defined in Zephyr, while others are defined in the |NCS|.
147-
This is all done in the :ref:`nrf_security` library.
148+
Some of these Kconfig options are defined in Zephyr, while others are defined in the |NCS| in the :ref:`nrf_security` subsystem.
149+
You only need to set the Kconfig options, not the directives.
148150

149-
The following table provides an overview of the available directives and their corresponding Kconfig options:
151+
The following table provides a brief overview of the available directives and their corresponding Kconfig options that you can set:
150152

151153
.. list-table:: Driver configuration directives
152154
:header-rows: 1
@@ -164,40 +166,63 @@ The following table provides an overview of the available directives and their c
164166
- | :kconfig:option:`CONFIG_PSA_WANT_KEY_TYPE_AES`
165167
| :kconfig:option:`CONFIG_PSA_WANT_ALG_SHA_256`
166168
* - ``PSA_USE_*``
167-
- Select the driver to use for the cryptographic operation (when available).
169+
- Select the driver you prefer to use for the cryptographic operation (when available).
168170
- `CONFIG_PSA_USE_*`_
169171
- | ``PSA_USE_CC310_KEY_MANAGEMENT_DRIVER``
170172
| ``PSA_USE_CC310_HASH_DRIVER``
171173
- | :kconfig:option:`CONFIG_PSA_USE_CC3XX_KEY_MANAGEMENT_DRIVER`
172174
| :kconfig:option:`CONFIG_PSA_USE_CC3XX_HASH_DRIVER`
173175
174176
.. note::
175-
176177
For the complete overview of the available configuration options, see the :ref:`ug_crypto_supported_features` page.
177178

178-
The nRF Security subsystem checks the directives (set through the Kconfig options) to make the optimal driver selection.
179-
The subsystem combines the ``PSA_WANT_*`` and ``PSA_USE_*`` settings in Kconfig to make the appropriate driver selection for the cryptographic operation:
179+
When you select Kconfig options for the wanted features and drivers, nRF Security checks the Oberon directives to make the optimal driver selection.
180+
To combine the settings in Kconfig that represent application requirements (``PSA_WANT_*``) and driver preferences from the user (``PSA_USE_*``), nRF Security uses ``PSA_NEED_*`` macros.
181+
These macros are automatically selected.
182+
They control which drivers are compiled into the build and thus available for use at runtime for software fallback and `Driver chaining`_.
180183

181-
* If hardware acceleration is enabled and available for the requested features, nRF Security selects that driver for performance and security reasons.
182-
* If no hardware driver is enabled and available, or if the hardware or the driver does not support the specific cryptographic operation, nRF Security falls back to the software nrf_oberon driver.
184+
The following figure shows an overview of this process:
183185

184-
For example:
186+
.. figure:: ../images/psa_want_use_need_flow.svg
187+
:alt: Detailed process for feature and driver selection
188+
:align: center
185189

186-
* You can configure the application to use CC310 and require the AES-192 key size through the :kconfig:option:`CONFIG_PSA_WANT_AES_KEY_SIZE_192` and :kconfig:option:`CONFIG_PSA_USE_CC3XX_KEY_MANAGEMENT_DRIVER` Kconfig options.
187-
nRF Security selects the nrf_cc3xx driver if it supports the CCM-AES-192 acceleration with the AES-192 key size.
188-
The CC310 peripheral does not support AES keys larger than 128 bits, so nRF Security selects the nrf_oberon driver instead.
189-
(This is the case of the Feature A in the previous example.)
190-
* You can configure the application to require the SHA-512 hashing functionality through the :kconfig:option:`CONFIG_PSA_WANT_ALG_SHA_512` and :kconfig:option:`CONFIG_PSA_USE_CC3XX_HASH_DRIVER` Kconfig options.
191-
nRF Security selects the nrf_cc3xx driver if it is available for the hardware platform and if it supports the SHA-512 hashing functionality.
192-
The CryptoCell-enabled hardware acceleration does not support the SHA-512 hashing functionality, so nRF Security falls back to the nrf_oberon software implementation.
193-
(This is the case of the Feature B in the previous example.)
194-
* You can configure the application to require the SHA-256 hashing functionality through the :kconfig:option:`CONFIG_PSA_WANT_ALG_SHA_256` Kconfig option, but set the :kconfig:option:`CONFIG_PSA_USE_CRACEN_HASH_DRIVER` Kconfig option to ``n`` so that the CRACEN driver is not used.
195-
nRF Security selects the nrf_oberon software implementation.
196-
(This is the case of the Feature C in the previous example.)
190+
.. _crypto_drivers_software_fallback:
197191

198-
.. note::
199-
You can also manually disable the software fallback mechanism.
200-
For example, you can do that if you want the cryptographic operations to run in hardware only.
192+
Software fallback
193+
=================
194+
195+
The Oberon PSA Crypto implementation in the |NCS| provides a transparent fallback mechanism that allows applications to use the software nrf_oberon driver when the hardware acceleration is not available.
196+
If a hardware driver does not support a particular operation or key size, the driver wrapper will redirect the call to a software implementation.
197+
198+
The software fallback can happen at runtime and works as follows:
199+
200+
* No software fallback required - If hardware acceleration is enabled and available for the requested features, nRF Security selects the preferred driver for performance and security reasons.
201+
* Software fallback required - If no hardware driver is enabled and available, or if the hardware or the preferred driver do not support the specific cryptographic operation, nRF Security falls back to the software nrf_oberon driver.
202+
203+
The software fallback mechanism to the nrf_oberon driver is enabled by default in the |NCS|.
204+
You can :ref:`manually disable the software fallback mechanism <psa_crypto_support_disable_software_fallback>`.
205+
For example, you can do that if you want the cryptographic operations to run in hardware only.
206+
207+
Examples of feature selection and software fallback
208+
===================================================
209+
210+
Click the following expand button to see examples of how nRF Security selects the drivers based on the Kconfig options.
211+
212+
.. toggle::
213+
214+
* You can configure the application to use CC310 and require the AES-192 key size through the :kconfig:option:`CONFIG_PSA_WANT_AES_KEY_SIZE_192` and :kconfig:option:`CONFIG_PSA_USE_CC3XX_KEY_MANAGEMENT_DRIVER` Kconfig options.
215+
nRF Security selects the nrf_cc3xx driver if it supports the CCM-AES-192 acceleration with the AES-192 key size.
216+
The CC310 peripheral does not support AES keys larger than 128 bits, so nRF Security selects the nrf_oberon driver instead, thus automatically setting the ``PSA_NEED_OBERON_KEY_MANAGEMENT_DRIVER`` macro.
217+
(This is the case of the :ref:`Feature A in the example flow <crypto_drivers_example_flow>`.)
218+
* You can configure the application to require the SHA-512 hashing functionality through the :kconfig:option:`CONFIG_PSA_WANT_ALG_SHA_512` and :kconfig:option:`CONFIG_PSA_USE_CC3XX_HASH_DRIVER` Kconfig options.
219+
nRF Security selects the nrf_cc3xx driver if it is available for the hardware platform and if it supports the SHA-512 hashing functionality.
220+
The CryptoCell-enabled hardware acceleration does not support the SHA-512 hashing functionality, so nRF Security falls back to the nrf_oberon software implementation, thus automatically setting the ``PSA_NEED_OBERON_HASH_DRIVER`` macro.
221+
(This is the case of the :ref:`Feature B in the example flow <crypto_drivers_example_flow>`.)
222+
* You can configure the application to require the SHA-256 hashing functionality through the :kconfig:option:`CONFIG_PSA_WANT_ALG_SHA_256` Kconfig option, but set the :kconfig:option:`CONFIG_PSA_USE_CRACEN_HASH_DRIVER` Kconfig option to ``n`` so that the CRACEN driver is not used.
223+
In this case, the conditions for automatically setting the ``PSA_NEED_CRACEN_HASH_DRIVER`` macro are not met.
224+
nRF Security selects the nrf_oberon software implementation, thus automatically setting the ``PSA_NEED_OBERON_HASH_DRIVER`` macro.
225+
(This is the case of the :ref:`Feature C in the example flow <crypto_drivers_example_flow>`.)
201226

202227
Driver chaining
203228
===============
@@ -207,7 +232,7 @@ This mechanism enables optimal use of hardware acceleration by combining softwar
207232
This allows for complex cryptographic operations that may be only partially supported in hardware.
208233

209234
In driver chaining, a driver that implements more complex algorithms (like HMAC) can delegate less complex algorithms (like SHA-256) to another driver.
210-
This delegation happens between the drivers through the driver wrapper, transparently to the application, and in runtime.
235+
This delegation happens between the drivers through the driver wrapper, transparently to the application, and at runtime.
211236
The delegation process follows the same priority rules as the driver selection, preferring hardware implementations when available.
212237

213238
Driver chaining optimizes the mix of software and hardware implementations to achieve the best performance.
@@ -216,7 +241,7 @@ At the same time, it ensures all cryptographic operations are supported across d
216241
Driver chaining in the |NCS|
217242
----------------------------
218243

219-
Driver chaining is handled in the |NCS| in runtime when you :ref:`enable multiple drivers at the same time <psa_crypto_support_multiple_drivers>` and then enable specific :ref:`nrf_oberon driver features in combination with driver features for hardware acceleration <nrf_security_drivers_config_features>`.
244+
Driver chaining is handled in the |NCS| at runtime when you :ref:`enable multiple drivers at the same time <psa_crypto_support_multiple_drivers>` and then enable specific :ref:`nrf_oberon driver features in combination with driver features for hardware acceleration <nrf_security_drivers_config_features>`.
220245

221246
Common driver chains supported in the nrf_oberon driver include the following cases:
222247

@@ -228,6 +253,9 @@ Common driver chains supported in the nrf_oberon driver include the following ca
228253
* Key Derivation → MAC
229254
* MAC → Hash, AES
230255

256+
The set of drivers available for chaining is determined by the ``PSA_NEED_*`` macros automatically set by nRF Security, as described in :ref:`crypto_drivers_feature_selection`.
257+
Only drivers whose ``PSA_NEED_*`` macros are enabled by nRF Security at compile time can participate in driver chaining.
258+
231259
For example, by enabling the nrf_cc3xx driver and the nrf_oberon driver, you can chain the MAC driver and the hash driver.
232260
The drivers handle this requirement as follows:
233261

0 commit comments

Comments
 (0)