rp23xx: add TRNG driver (hardware /dev/random and /dev/urandom)#19400
Open
ricardgb wants to merge 1 commit into
Open
rp23xx: add TRNG driver (hardware /dev/random and /dev/urandom)#19400ricardgb wants to merge 1 commit into
ricardgb wants to merge 1 commit into
Conversation
65925e5 to
27e4ec0
Compare
The RP2350 embeds an Arm CryptoCell-style true random number generator: a sampled ring oscillator conditioned by von-Neumann, CRNGT and autocorrelation health tests, presenting 192 bits in the six EHR_DATA words. Add a polling driver that serves those conditioned bits as /dev/random and /dev/urandom. Entropy is drawn rarely (an mbedtls CTR_DRBG seeds once and reseeds occasionally), so a blocking poll is used rather than interrupt plumbing; the hardware health-test failures discard the block and re-arm the source, so only conditioned entropy is returned. A startup self-test gates the source before it is trusted: it draws a sample of the conditioned output and rejects a stuck source (identical consecutive 192-bit blocks), a constant byte, or an absurd run of equal bytes. On failure the source is marked unhealthy and every read returns -EIO, so an entropy consumer fail-stops rather than minting keys on a broken source. (The statistical quality is covered by the hardware VN/CRNGT/autocorr tests; this catches the gross, silent failure modes.) New CONFIG_RP23XX_TRNG selects ARCH_HAVE_RNG, which switches /dev/urandom from the software xorshift PRNG to the hardware source (backing getrandom() and thus any entropy consumer such as mbedtls). Tested on a Raspberry Pi Pico 2 W: /dev/random and /dev/urandom register, the startup self-test passes, a read returns at real ring- oscillator sampling latency (~10 ms / 32 B), two independent samples differ, and mbedtls seeds its CTR_DRBG from /dev/urandom successfully. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Ricard Rosson <ricard@groundbits.com>
27e4ec0 to
d2531b2
Compare
Contributor
Author
|
Thanks for the review @xiaoxiang781216 — all four points addressed in d2531b2:
Also fixed the (As before: this change was made with the help of an AI agent and human-reviewed before pushing.) |
xiaoxiang781216
approved these changes
Jul 11, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The RP2350 (rp23xx) embeds an Arm CryptoCell-style true random number
generator — a sampled ring oscillator conditioned by von-Neumann, CRNGT and
autocorrelation health tests, presenting 192 bits in the six
EHR_DATAwords —but there is no driver for it, so
/dev/urandomon rp23xx is the softwarexorshift PRNG.
This adds
arch/arm/src/rp23xx/rp23xx_rng.c, a polling driver that serves theconditioned hardware bits as
/dev/randomand/dev/urandom. Entropy is drawnrarely (an mbedtls CTR_DRBG seeds once and reseeds occasionally), so a blocking
poll is used rather than interrupt plumbing; health-test failures discard the
block and re-arm the source, so only conditioned entropy is ever returned.
New
CONFIG_RP23XX_TRNGselectsARCH_HAVE_RNG, which switches/dev/urandomfrom the software PRNG to the hardware source (backing
getrandom()and thus anyentropy consumer, e.g. mbedtls).
Impact
CONFIG_RP23XX_TRNG.n).Testing
Tested on a Raspberry Pi Pico 2 W:
/dev/randomand/dev/urandomregister from the TRNG;passes, and mbedtls seeds its CTR_DRBG from
/dev/urandomsuccessfully.Disclosure: this change was prepared by an AI agent (Claude Code) at the
direction of the author, who reviewed and tested it on hardware before
submission.
🤖 Generated with Claude Code