Browse Source
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>pull/84400/head
5 changed files with 98 additions and 0 deletions
@ -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. |
@ -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); |
@ -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 new issue