drivers: entropy: Add new driver based on nrf54l cracen driver
Add a new entropy driver based on the nrf HAL CRACEN CTR DRBG driver Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
4b56c74e1c
commit
b151cd6bc7
5 changed files with 98 additions and 0 deletions
|
|
@ -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_TRNG entropy_mcux_trng.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_MCUX_CAAM entropy_mcux_caam.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_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_SAM_RNG entropy_sam.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_SMARTBOND_TRNG entropy_smartbond.c)
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_SMARTBOND_TRNG entropy_smartbond.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_STM32_RNG entropy_stm32.c)
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_STM32_RNG entropy_stm32.c)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ source "drivers/entropy/Kconfig.mcux"
|
||||||
source "drivers/entropy/Kconfig.stm32"
|
source "drivers/entropy/Kconfig.stm32"
|
||||||
source "drivers/entropy/Kconfig.esp32"
|
source "drivers/entropy/Kconfig.esp32"
|
||||||
source "drivers/entropy/Kconfig.nrf5"
|
source "drivers/entropy/Kconfig.nrf5"
|
||||||
|
source "drivers/entropy/Kconfig.nrf_cracen"
|
||||||
source "drivers/entropy/Kconfig.sam"
|
source "drivers/entropy/Kconfig.sam"
|
||||||
source "drivers/entropy/Kconfig.smartbond"
|
source "drivers/entropy/Kconfig.smartbond"
|
||||||
source "drivers/entropy/Kconfig.native_posix"
|
source "drivers/entropy/Kconfig.native_posix"
|
||||||
|
|
|
||||||
17
drivers/entropy/Kconfig.nrf_cracen
Normal file
17
drivers/entropy/Kconfig.nrf_cracen
Normal file
|
|
@ -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.
|
||||||
65
drivers/entropy/entropy_nrf_cracen.c
Normal file
65
drivers/entropy/entropy_nrf_cracen.c
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nrfx_cracen.h>
|
||||||
|
#include <zephyr/irq.h>
|
||||||
|
#include <zephyr/drivers/entropy.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
14
dts/bindings/rng/nordic,nrf-cracen-ctrdrbg.yaml
Normal file
14
dts/bindings/rng/nordic,nrf-cracen-ctrdrbg.yaml
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue