diff --git a/drivers/entropy/CMakeLists.txt b/drivers/entropy/CMakeLists.txt index d5588378f6f..68cd0f7003c 100644 --- a/drivers/entropy/CMakeLists.txt +++ b/drivers/entropy/CMakeLists.txt @@ -12,6 +12,7 @@ zephyr_library_sources_ifdef(CONFIG_ENTROPY_MCUX_RNGA entropy_mcux_rnga zephyr_library_sources_ifdef(CONFIG_ENTROPY_MCUX_TRNG entropy_mcux_trng.c) zephyr_library_sources_ifdef(CONFIG_ENTROPY_MCUX_CAAM entropy_mcux_caam.c) zephyr_library_sources_ifdef(CONFIG_ENTROPY_NRF5_RNG entropy_nrf5.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_NRF_CRACEN_CTR_DRBG entropy_nrf_cracen.c) zephyr_library_sources_ifdef(CONFIG_ENTROPY_SAM_RNG entropy_sam.c) zephyr_library_sources_ifdef(CONFIG_ENTROPY_SMARTBOND_TRNG entropy_smartbond.c) zephyr_library_sources_ifdef(CONFIG_ENTROPY_STM32_RNG entropy_stm32.c) diff --git a/drivers/entropy/Kconfig b/drivers/entropy/Kconfig index debd0f8d7a1..f63c815edc7 100644 --- a/drivers/entropy/Kconfig +++ b/drivers/entropy/Kconfig @@ -26,6 +26,7 @@ source "drivers/entropy/Kconfig.mcux" source "drivers/entropy/Kconfig.stm32" source "drivers/entropy/Kconfig.esp32" source "drivers/entropy/Kconfig.nrf5" +source "drivers/entropy/Kconfig.nrf_cracen" source "drivers/entropy/Kconfig.sam" source "drivers/entropy/Kconfig.smartbond" source "drivers/entropy/Kconfig.native_posix" diff --git a/drivers/entropy/Kconfig.nrf_cracen b/drivers/entropy/Kconfig.nrf_cracen new file mode 100644 index 00000000000..8941096a126 --- /dev/null +++ b/drivers/entropy/Kconfig.nrf_cracen @@ -0,0 +1,17 @@ +# Copyright (c) 2025 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config ENTROPY_NRF_CRACEN_CTR_DRBG + bool "nRF entropy driver based on the CRACEN CTR_DRBG driver" + default y + depends on DT_HAS_NORDIC_NRF_CRACEN_CTRDRBG_ENABLED + depends on SOC_COMPATIBLE_NRF54LX + select ENTROPY_HAS_DRIVER + select NRFX_CRACEN + help + This option enables the 54L CRACEN based entropy driver, based on the nrfx CRACEN CTR_DRBG + random driver. + Notes: This driver is only compatible with 54L devices, and may only be used from one processor + core. This driver cannot be used in conjunction with the nRF security PSA solution, as both + would attempt to use the CRACEN HW exclusively; When that is enabled, the PSA crypto entropy + driver should be selected instead. diff --git a/drivers/entropy/entropy_nrf_cracen.c b/drivers/entropy/entropy_nrf_cracen.c new file mode 100644 index 00000000000..3856173ccf6 --- /dev/null +++ b/drivers/entropy/entropy_nrf_cracen.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define DT_DRV_COMPAT nordic_nrf_cracen_ctrdrbg + +static int nrf_cracen_get_entropy_isr(const struct device *dev, uint8_t *buf, uint16_t len, + uint32_t flags) +{ + (void)dev; + (void)flags; + + unsigned int key = irq_lock(); + + /* This will be done in less than 1 microsecond */ + int ret = nrfx_cracen_ctr_drbg_random_get(buf, len); + + irq_unlock(key); + + if (likely(ret == NRFX_SUCCESS)) { + return len; + } else if (ret == NRFX_ERROR_INVALID_PARAM) { + return -EINVAL; + } else { + return -EAGAIN; + } +} + +static int nrf_cracen_get_entropy(const struct device *dev, uint8_t *buf, uint16_t len) +{ + int ret = nrf_cracen_get_entropy_isr(dev, buf, len, 0); + + if (ret < 0) { + return ret; + } else { + return 0; + } +} + +static int nrf_cracen_cracen_init(const struct device *dev) +{ + (void)dev; + + int ret = nrfx_cracen_ctr_drbg_init(); + + if (ret == NRFX_SUCCESS) { + return 0; + } else { + return -EIO; + } +} + +static DEVICE_API(entropy, nrf_cracen_api_funcs) = { + .get_entropy = nrf_cracen_get_entropy, + .get_entropy_isr = nrf_cracen_get_entropy_isr +}; + +DEVICE_DT_INST_DEFINE(0, nrf_cracen_cracen_init, NULL, NULL, NULL, PRE_KERNEL_1, + CONFIG_ENTROPY_INIT_PRIORITY, &nrf_cracen_api_funcs); diff --git a/dts/bindings/rng/nordic,nrf-cracen-ctrdrbg.yaml b/dts/bindings/rng/nordic,nrf-cracen-ctrdrbg.yaml new file mode 100644 index 00000000000..820178b975a --- /dev/null +++ b/dts/bindings/rng/nordic,nrf-cracen-ctrdrbg.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2025, Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic nRF CRACEN CTR_DRBG based (Random Number Generator) + + This driver is only compatible with 54L devices, and may only be used from one processor + core. This driver cannot be used in conjunction with the nRF security PSA solution, as both + would attempt to use the CRACEN HW exclusively; When that is enabled, zephyr,psa-crypto-rng + should be selected instead. + +compatible: "nordic,nrf-cracen-ctrdrbg" + +include: base.yaml