Skip to content

Commit b4516cf

Browse files
degjorvarlubos
authored andcommitted
nrf_security: cracen_trng: add support for nRF54LS05B
nRF54LS05B uses a version of CRACEN that only supports TRNG and no other cryptographic functionality. As such it will only use OBERON as the crypto driver. Add support for seeding the OBERON CTR-DRBG from the CRACEN trng. Update configs to add support for nRF54LS05B Signed-off-by: Dag Erik Gjørvad <[email protected]>
1 parent 06bf1ea commit b4516cf

File tree

12 files changed

+139
-7
lines changed

12 files changed

+139
-7
lines changed

dts/arm/nordic/nrf54ls05b_enga_cpuapp.dtsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nvic: &cpuapp_nvic {};
1212

1313
/ {
1414
chosen {
15-
zephyr,entropy = &rng;
15+
zephyr,entropy = &psa_rng;
1616
};
1717

1818
soc {
@@ -23,7 +23,7 @@ nvic: &cpuapp_nvic {};
2323

2424
psa_rng: psa-rng {
2525
compatible = "zephyr,psa-crypto-rng";
26-
status = "disabled";
26+
status = "okay";
2727
};
2828

2929
prng: prng {
@@ -33,7 +33,7 @@ nvic: &cpuapp_nvic {};
3333

3434
rng: rng {
3535
compatible = "nordic,nrf-cracen-ctrdrbg";
36-
status = "okay";
36+
status = "disabled";
3737
};
3838
};
3939

subsys/nrf_security/cmake/psa_crypto_config.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ kconfig_check_and_set_base_to_one(PSA_NEED_OBERON_XMSS_VERIFY)
494494

495495
# Convert NRF_RNG driver configuration
496496
kconfig_check_and_set_base_to_one(PSA_NEED_NRF_RNG_ENTROPY_DRIVER)
497+
kconfig_check_and_set_base_to_one(PSA_NEED_CRACEN_TRNG_DRIVER)
497498

498499
# Nordic specific
499500
kconfig_check_and_set_base_to_one(PSA_CRYPTO_DRIVER_ALG_PRNG_TEST)

subsys/nrf_security/configs/psa_crypto_config.h.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
#cmakedefine PSA_NEED_OBERON_XMSS_VERIFY @PSA_NEED_OBERON_XMSS_VERIFY@
253253

254254
#cmakedefine PSA_NEED_NRF_RNG_ENTROPY_DRIVER @PSA_NEED_NRF_RNG_ENTROPY_DRIVER@
255+
#cmakedefine PSA_NEED_CRACEN_TRNG_DRIVER @PSA_NEED_CRACEN_TRNG_DRIVER@
255256

256257
/*
257258
* CRACEN driver configuration

subsys/nrf_security/src/drivers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if(TARGET nrf_cc3xx_platform)
1010
add_subdirectory(nrf_cc3xx_platform)
1111
endif()
1212

13-
# Only build the PSA crypto drivers when Oberon
13+
# Only build the PSA crypto drivers when Oberon
1414
if(CONFIG_MBEDTLS_PSA_CRYPTO_C)
1515
if(CONFIG_PSA_CRYPTO_DRIVER_CC3XX)
1616
add_subdirectory(nrf_cc3xx)

subsys/nrf_security/src/drivers/cracen/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
config CRACEN_HW_PRESENT
8-
def_bool SOC_SERIES_NRF54LX || SOC_SERIES_NRF92X || SOC_SERIES_NRF71X
8+
def_bool (SOC_SERIES_NRF54LX && !SOC_NRF54LS05B) || SOC_SERIES_NRF92X || SOC_SERIES_NRF71X
99

1010
config CRACEN_HW_VERSION_BASE
1111
def_bool SOC_SERIES_NRF54HX || SOC_NRF54L15 || SOC_NRF54L10 || SOC_NRF54L05

subsys/nrf_security/src/drivers/nrf_oberon/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
# Build Oberon PSA crypto driver
7+
# Build Oberon PSA crypto driver
88
set(drivers_path ${OBERON_PSA_CORE_PATH}/oberon/drivers)
99

1010
target_include_directories(psa_crypto_library_config
@@ -74,6 +74,9 @@ target_link_libraries(oberon_psa_driver
7474
psa_interface
7575
)
7676

77+
if(CONFIG_PSA_NEED_CRACEN_TRNG_DRIVER)
78+
add_subdirectory(cracen_trng)
79+
endif()
7780

7881
# Link to imported libraries for Oberon APIs.
7982
target_link_libraries(oberon_psa_driver

subsys/nrf_security/src/drivers/nrf_oberon/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,3 +1737,6 @@ config PSA_NEED_OBERON_HMAC_DRBG_DRIVER
17371737

17381738
endif # PSA_CRYPTO_DRIVER_OBERON
17391739
endmenu
1740+
1741+
# Include CRACEN TRNG driver config
1742+
rsource "cracen_trng/Kconfig"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
if (PSA_NEED_CRACEN_TRNG_DRIVER)
8+
target_sources(psa_core
9+
PRIVATE
10+
cracen_trng.c
11+
)
12+
target_include_directories(psa_core
13+
PRIVATE
14+
${CMAKE_CURRENT_LIST_DIR}/..
15+
)
16+
endif()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config PSA_NEED_CRACEN_TRNG_DRIVER
8+
bool
9+
depends on !PSA_CRYPTO_DRIVER_CRACEN
10+
default y if SOC_NRF54LS05B
11+
select PSA_ACCEL_GET_ENTROPY
12+
select NRFX_CRACEN
13+
help
14+
PSA crypto driver for CRACEN True Random Number Generator.
15+
This driver provides entropy functionality for nRF54LS05B devices
16+
using direct access to the CRACEN TRNG hardware via nrfx.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <nrfx_cracen.h>
9+
10+
#include "psa/crypto.h"
11+
12+
/* This file exists to provide TRNG to seed the PRNG in OBERON on devices that only support TRNG */
13+
14+
static psa_status_t cracen_trng_init(void)
15+
{
16+
nrfx_err_t nrfx_error;
17+
18+
/* This is TRNG even though the naming states otherwise.
19+
* On devices that don't support hardware crypto it will default to trng
20+
*/
21+
nrfx_error = nrfx_cracen_ctr_drbg_init();
22+
if (nrfx_error != NRFX_SUCCESS) {
23+
return PSA_ERROR_HARDWARE_FAILURE;
24+
}
25+
26+
return PSA_SUCCESS;
27+
}
28+
29+
psa_status_t cracen_trng_get_entropy(uint32_t flags, size_t *estimate_bits,
30+
uint8_t *output, size_t output_size)
31+
{
32+
uint16_t request_len = MIN(UINT16_MAX, output_size);
33+
psa_status_t status;
34+
nrfx_err_t nrfx_error;
35+
36+
/* Ignore flags as CRACEN TRNG doesn't support entropy generation flags */
37+
(void)flags;
38+
39+
if (output == NULL || estimate_bits == NULL || output_size == 0) {
40+
return PSA_ERROR_INVALID_ARGUMENT;
41+
}
42+
43+
status = cracen_trng_init();
44+
if (status != PSA_SUCCESS) {
45+
return status;
46+
}
47+
48+
/* This is TRNG even though the naming states otherwise.
49+
* On devices that don't support hardware crypto it will default to trng
50+
*/
51+
nrfx_error = nrfx_cracen_ctr_drbg_random_get(output, request_len);
52+
if (nrfx_error != NRFX_SUCCESS) {
53+
return PSA_ERROR_HARDWARE_FAILURE;
54+
}
55+
56+
*estimate_bits = PSA_BYTES_TO_BITS(request_len);
57+
58+
return PSA_SUCCESS;
59+
}

0 commit comments

Comments
 (0)