Fix: TRNG Not Working On Raspberry Pi Pico 2350
Hey everyone,
I've run into a bit of a snag with the True Random Number Generator (TRNG) on my Raspberry Pi Pico 2350, and I wanted to share my experience, the troubleshooting steps I've taken, and hopefully get some insights from you all. It seems like the blocking_next_u64
function just hangs indefinitely, and when I try to use fill_bytes
, I'm flooded with warning messages. Let's dive into the details and see if we can figure this out together!
The Problem: TRNG Autocorrect and CRNGT Errors
So, here's the deal. When I try to use the TRNG, I get stuck. The blocking_next_u64
function, which should return a random 64-bit number, never actually returns. It just sits there, waiting. And when I attempt to fill a buffer with random bytes using fill_bytes
, the console goes crazy with these warnings:
[WARN ] TRNG Autocorrect error! Resetting TRNG. Increase sample count to reduce likelihood (embassy_rp embassy-rp/src/trng.rs:439)
[WARN ] TRNG CRNGT error! Increase sample count to reduce likelihood (embassy_rp embassy-rp/src/trng.rs:423)
These warnings keep popping up endlessly, which definitely isn't the behavior we want from a random number generator. It suggests there are some underlying issues with the TRNG's operation, specifically related to autocorrelation and the Continuous Random Number Generator Test (CRNGT).
Understanding Autocorrelation and CRNGT Errors
Let's break down what these errors might mean. Autocorrelation, in the context of random number generation, refers to the correlation of a signal with a delayed copy of itself as a function of the delay. Ideally, a TRNG should produce a sequence of numbers with minimal autocorrelation, meaning there should be no discernible pattern in the output. The "TRNG Autocorrect error" suggests that the TRNG is failing this test, indicating a potential bias or predictability in the generated numbers. This can happen if the noise source used by the TRNG isn't truly random or if there are issues with the post-processing steps designed to remove bias.
The CRNGT error, on the other hand, relates to a statistical test designed to ensure the continuous randomness of the output. The CRNGT likely involves checking various statistical properties of the generated numbers, such as their distribution and frequency of occurrence. A failure in the CRNGT indicates that the output of the TRNG doesn't meet the expected statistical criteria for randomness, which could be due to various factors, including hardware faults or design flaws in the random number generation process. The error message suggests increasing the sample count, which might help in some cases by providing more data for the statistical tests, but it's not a guaranteed solution.
The Hunt for Solutions: Disabling Autocorrelation
In my quest to get the TRNG working, I stumbled upon a temporary fix: disabling the autocorrelation test. By tweaking the settings, I managed to bypass this specific check, and the TRNG started producing numbers. However, this isn't a true solution, as it merely masks the underlying problem. Disabling the autocorrelation test means we're no longer verifying a crucial aspect of the TRNG's randomness, which could lead to unpredictable and potentially biased results. This workaround should only be used for testing or in situations where absolute randomness isn't critical.
Is This a Hardware Problem?
This is the million-dollar question, isn't it? The warnings and the fact that disabling the autocorrelation test