drivers: entropy: Add the PSA Crypto Random entropy driver
This adds an entropy driver calling the PSA Crypto psa_generate_random() API to get random bytes. Currently this only uses the TFM provided psa_generate_random(). Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This commit is contained in:
parent
e1429d7897
commit
3b407a1987
4 changed files with 70 additions and 0 deletions
|
@ -20,3 +20,10 @@ zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_TRNG entropy_gecko_trn
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_NEORV32_TRNG entropy_neorv32_trng.c)
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_NEORV32_TRNG entropy_neorv32_trng.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_BT_HCI entropy_bt_hci.c)
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_BT_HCI entropy_bt_hci.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_SE entropy_gecko_se.c)
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_SE entropy_gecko_se.c)
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_PSA_CRYPTO_RNG entropy_psa_crypto.c)
|
||||||
|
|
||||||
|
if (CONFIG_BUILD_WITH_TFM)
|
||||||
|
target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE
|
||||||
|
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/install/interface/include
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
|
@ -33,6 +33,7 @@ source "drivers/entropy/Kconfig.litex"
|
||||||
source "drivers/entropy/Kconfig.gecko"
|
source "drivers/entropy/Kconfig.gecko"
|
||||||
source "drivers/entropy/Kconfig.neorv32"
|
source "drivers/entropy/Kconfig.neorv32"
|
||||||
source "drivers/entropy/Kconfig.bt_hci"
|
source "drivers/entropy/Kconfig.bt_hci"
|
||||||
|
source "drivers/entropy/Kconfig.psa_crypto"
|
||||||
|
|
||||||
config ENTROPY_HAS_DRIVER
|
config ENTROPY_HAS_DRIVER
|
||||||
bool
|
bool
|
||||||
|
|
11
drivers/entropy/Kconfig.psa_crypto
Normal file
11
drivers/entropy/Kconfig.psa_crypto
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# PSA Crypto Random source configuration options
|
||||||
|
|
||||||
|
config ENTROPY_PSA_CRYPTO_RNG
|
||||||
|
bool "PSA Crypto Random source Entropy driver"
|
||||||
|
depends on BUILD_WITH_TFM
|
||||||
|
select ENTROPY_HAS_DRIVER
|
||||||
|
help
|
||||||
|
Enable the PSA Crypto source Entropy driver.
|
51
drivers/entropy/entropy_psa_crypto.c
Normal file
51
drivers/entropy/entropy_psa_crypto.c
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zephyr_psa_crypto_rng
|
||||||
|
|
||||||
|
#include <zephyr/drivers/entropy.h>
|
||||||
|
#include <psa/crypto.h>
|
||||||
|
|
||||||
|
/* API implementation: PSA Crypto initialization */
|
||||||
|
static int entropy_psa_crypto_rng_init(const struct device *dev)
|
||||||
|
{
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
|
status = psa_crypto_init();
|
||||||
|
if (status != PSA_SUCCESS) {
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* API implementation: get_entropy */
|
||||||
|
static int entropy_psa_crypto_rng_get_entropy(const struct device *dev,
|
||||||
|
uint8_t *buffer, uint16_t length)
|
||||||
|
{
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
|
status = psa_generate_random(buffer, length);
|
||||||
|
if (status != PSA_SUCCESS) {
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Entropy driver APIs structure */
|
||||||
|
static const struct entropy_driver_api entropy_psa_crypto_rng_api = {
|
||||||
|
.get_entropy = entropy_psa_crypto_rng_get_entropy,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Entropy driver registration */
|
||||||
|
DEVICE_DT_INST_DEFINE(0, entropy_psa_crypto_rng_init, NULL, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY,
|
||||||
|
&entropy_psa_crypto_rng_api);
|
Loading…
Add table
Add a link
Reference in a new issue