From 8c6d6e2fc66b5a96d6e2c7e303e3201b0051a7d7 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Sun, 12 Apr 2026 12:28:45 -0400 Subject: [PATCH] Better hook rng into wolfCrypt --- arch.mk | 11 ++++++----- hal/lpc55s69.c | 12 ++++++++++-- test-app/Makefile | 13 +++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/arch.mk b/arch.mk index 474ce3e1..198637c7 100644 --- a/arch.mk +++ b/arch.mk @@ -1244,15 +1244,16 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o endif ifeq ($(PKA),1) - CFLAGS+=-DWOLFSSL_NXP_CASPER -DWOLFSSL_NXP_HASHCRYPT + CFLAGS+=-DWOLFSSL_NXP_LPC55S69 OBJS+=\ $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o - endif - ifeq ($(WOLFCRYPT_TZ),1) - OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + else + CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif endif diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index 2c13bb99..24116914 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -71,6 +71,10 @@ static void hal_sau_init(void) static void periph_unsecure(void) { +#ifdef WOLFSSL_NXP_RNG_1 + CLOCK_EnableClock(kCLOCK_Rng); + RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); +#endif CLOCK_EnableClock(kCLOCK_Iocon); CLOCK_EnableClock(kCLOCK_Gpio1); } @@ -225,11 +229,13 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len) #ifdef WOLFCRYPT_SECURE_MODE void hal_trng_init(void) { -#ifdef __WOLFBOOT +#ifdef WOLFSSL_NXP_RNG_1 +# ifdef __WOLFBOOT CLOCK_EnableClock(kCLOCK_Rng); RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); -#endif +# endif RNG_Init(RNG); +#endif } void hal_trng_fini(void) @@ -238,8 +244,10 @@ void hal_trng_fini(void) int hal_trng_get_entropy(unsigned char *out, unsigned int len) { +#ifdef WOLFSSL_NXP_RNG_1 if (RNG_GetRandomData(RNG, out, len) == kStatus_Success) return 0; +#endif return -1; } diff --git a/test-app/Makefile b/test-app/Makefile index d60b6953..c9e4da86 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -725,8 +725,17 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o - ifeq ($(WOLFCRYPT_TZ),1) - APP_OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o + ifeq ($(PKA),1) + CFLAGS+=-DWOLFSSL_NXP_LPC55S69 + APP_OBJS+=\ + $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ + $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + else + CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif ifeq (,$(findstring nosys.specs,$(LDFLAGS))) LDFLAGS+=--specs=nosys.specs