Skip to content

Add Vorago VA416x0 hardware TRNG support#10671

Draft
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:va416xx_trng
Draft

Add Vorago VA416x0 hardware TRNG support#10671
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:va416xx_trng

Conversation

@dgarske

@dgarske dgarske commented Jun 11, 2026

Copy link
Copy Markdown
Member

Add Vorago VA416x0 hardware TRNG support

Adds a wc_GenerateSeed() implementation for the Vorago VA416x0 (Cortex-M4F) on-chip True Random Number Generator, gated by a new WOLFSSL_VA416X0_TRNG build macro. The TRNG is an Arm CryptoCell-style entropy block (192-bit EHR, ring-oscillator source, Von-Neumann / CRNGT / autocorrelation health tests), accessed register-only via the VA416xx SDK (va416xx.h); no SDK HAL driver exists for it.

Because the TRNG produces only ~1.25 kb/s of entropy, it is used as a seed source for the SP800-90A Hash-DRBG (keep HAVE_HASHDRBG on), not for bulk generation.

Usage

#define WOLFSSL_VA416X0_TRNG   /* in user_settings.h; needs va416xx.h on the include path */

Optional tuning defines (with defaults): WOLFSSL_VA416X0_TRNG_SAMPLE_CNT (1000), WOLFSSL_VA416X0_TRNG_MAX_RETRY (10), WOLFSSL_VA416X0_TRNG_TIMEOUT (1000000).

Notes

  • Releases the TRNG from PERIPHERAL_RESET (active-low) before use; without this, all TRNG register writes are silently ignored.
  • Health tests stay enabled: a health-test error re-collects up to MAX_RETRY times; a per-block poll cap returns RNG_FAILURE_E instead of hanging.
  • Seed material is scrubbed from the stack with ForceZero().

Testing

Validated on the VA416XX EVK (J-Link/SWD) via the wolfBoot test-app with WOLFCRYPT_TEST=1: wolfCrypt RANDOM test passed! (DRBG instantiate + SP800-90A health checks), alongside the SHA and ECC self-tests.

@dgarske dgarske self-assigned this Jun 11, 2026
Copilot AI review requested due to automatic review settings June 11, 2026 23:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new hardware-entropy backend for Vorago VA416x0 by implementing wc_GenerateSeed() using the on-chip TRNG, gated behind WOLFSSL_VA416X0_TRNG, and documents the new build macro.

Changes:

  • Add a VA416x0 TRNG-based wc_GenerateSeed() implementation with retry/timeout behavior and stack scrubbing.
  • Document the new WOLFSSL_VA416X0_TRNG macro in random.c and register it in .wolfssl_known_macro_extras.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
wolfcrypt/src/random.c Adds the VA416x0 TRNG seed generator implementation and documents the new macro/tuning defines.
.wolfssl_known_macro_extras Adds WOLFSSL_VA416X0_TRNG to the known macro list (and also removes two existing macros in the same hunk).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wolfcrypt/src/random.c
Comment on lines +5287 to +5299
/* health-test failure: stop, clear, re-collect */
VOR_TRNG->RND_SOURCE_ENABLE = 0;
VOR_TRNG->ICR = TRNG_ICR_AUTOCORR_ERR_Msk |
TRNG_ICR_CRNGT_ERR_Msk |
TRNG_ICR_VN_ERR_Msk;
if (++retry > WOLFSSL_VA416X0_TRNG_MAX_RETRY) {
ForceZero(ehr, sizeof(ehr));
return RNG_FAILURE_E;
}
timeout = WOLFSSL_VA416X0_TRNG_TIMEOUT;
VOR_TRNG->RND_SOURCE_ENABLE =
TRNG_RND_SOURCE_ENABLE_RND_SRC_EN_Msk;
continue;
Comment thread wolfcrypt/src/random.c
* entropy block before failing
* default: 1000000
*/
#include "va416xx.h"
Comment thread wolfcrypt/src/random.c
Comment on lines +5226 to +5228
#ifndef WOLFSSL_VA416X0_TRNG_SAMPLE_CNT
#define WOLFSSL_VA416X0_TRNG_SAMPLE_CNT 1000
#endif
Comment on lines 972 to 974
WOLF_CRYPTO_CB_CMD
WOLF_CRYPTO_CB_NO_SHA512_FALLBACK
WOLF_CRYPTO_CB_ONLY_SHA512
WOLF_CRYPTO_DEV
WOLF_NO_TRAILING_ENUM_COMMAS
@dgarske dgarske requested a review from Copilot June 12, 2026 00:11
@dgarske dgarske marked this pull request as draft June 12, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread wolfcrypt/src/random.c
Comment on lines +5269 to +5286
if ((reg & (TRNG_ISR_AUTOCORR_ERR_Msk |
TRNG_ISR_CRNGT_ERR_Msk |
TRNG_ISR_VN_ERR_Msk)) != 0) {
/* health-test failure: stop, clear, re-collect */
VOR_TRNG->RND_SOURCE_ENABLE = 0;
VOR_TRNG->ICR = TRNG_ICR_AUTOCORR_ERR_Msk |
TRNG_ICR_CRNGT_ERR_Msk |
TRNG_ICR_VN_ERR_Msk;
if (++retry > WOLFSSL_VA416X0_TRNG_MAX_RETRY) {
ForceZero(ehr, sizeof(ehr));
wolfSSL_CryptHwMutexUnLock();
return RNG_FAILURE_E;
}
timeout = WOLFSSL_VA416X0_TRNG_TIMEOUT;
VOR_TRNG->RND_SOURCE_ENABLE =
TRNG_RND_SOURCE_ENABLE_RND_SRC_EN_Msk;
continue;
}
Comment thread wolfcrypt/src/random.c
Comment on lines +5188 to +5190
* it is accessed at the register level below. The tuning macros
* (WOLFSSL_VA416X0_TRNG_SAMPLE_CNT / _MAX_RETRY / _TIMEOUT) are documented
* with the other Hardware RNG build options at the top of this file.
Comment thread wolfcrypt/src/random.c
Comment on lines +5253 to +5257
/* select ring-oscillator source, set sample rate, keep health
* tests enabled (no DEBUG_CONTROL bypass) */
VOR_TRNG->CONFIG = 0;
VOR_TRNG->SAMPLE_CNT1 = WOLFSSL_VA416X0_TRNG_SAMPLE_CNT;
VOR_TRNG->DEBUG_CONTROL = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants