From 8f0235fb8f2d46ee6ca6309f8c365ad57e3a1565 Mon Sep 17 00:00:00 2001 From: Leo Yan Date: Fri, 31 Jan 2025 10:20:28 +0000 Subject: [PATCH] feat(tc): get entropy with PSA Crypto API The PSA Crypto API is available with sending messages to RSE. Change to invoke PSA Crypto API for getting entropy. Change-Id: I4b2dc4eb99606c2425b64949d9c3f5c576883758 Signed-off-by: Leo Yan Signed-off-by: Icen Zeyada --- plat/arm/board/tc/platform.mk | 3 ++- plat/arm/board/tc/tc_trng.c | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plat/arm/board/tc/platform.mk b/plat/arm/board/tc/platform.mk index 8b15a6f23..21d712221 100644 --- a/plat/arm/board/tc/platform.mk +++ b/plat/arm/board/tc/platform.mk @@ -248,7 +248,8 @@ include drivers/arm/rse/rse_comms.mk BL1_SOURCES += ${RSE_COMMS_SOURCES} BL2_SOURCES += ${RSE_COMMS_SOURCES} -BL31_SOURCES += ${RSE_COMMS_SOURCES} +BL31_SOURCES += ${RSE_COMMS_SOURCES} \ + lib/psa/rse_platform.c # Include Measured Boot makefile before any Crypto library makefile. # Crypto library makefile may need default definitions of Measured Boot build diff --git a/plat/arm/board/tc/tc_trng.c b/plat/arm/board/tc/tc_trng.c index e5ec48a1a..793a90fbc 100644 --- a/plat/arm/board/tc/tc_trng.c +++ b/plat/arm/board/tc/tc_trng.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -24,20 +25,33 @@ DEFINE_SVC_UUID2(_plat_trng_uuid, ); uuid_t plat_trng_uuid; -/* Dummy implementation */ bool plat_get_entropy(uint64_t *out) { +#if CRYPTO_SUPPORT + psa_status_t status; + + status = rse_platform_get_entropy((uint8_t *)out, sizeof(*out)); + if (status != PSA_SUCCESS) { + printf("Failed for entropy read, psa_status=%d\n", status); + return false; + } +#else + /* Dummy value */ *out = 0xABBAEDDAACDCDEAD; +#endif return true; } void plat_entropy_setup(void) { - uint64_t dummy; + uint64_t entropy; plat_trng_uuid = _plat_trng_uuid; /* Initialise the entropy source and trigger RNG generation */ - plat_get_entropy(&dummy); + if (!plat_get_entropy(&entropy)) { + ERROR("Failed to setup entropy\n"); + panic(); + } }