forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Signed-off-by: Valerio Setti <[email protected]>
- Loading branch information
1 parent
e1429d7
commit 3b407a1
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |