rng: discard 12 words after SEIS clear per RM0432 32.3.7
What changed, and why it matters
This commit changes how the COLDCARD hardware wallet's random-number generator (RNG) recovers from a rare 'seed error' condition. The manufacturer is now following an STMicroelectronics guideline to throw away the first 12 random numbers after clearing the error, because those values could be left over from before the error and might be predictable. Random numbers are critical for creating private keys and transaction signatures, so using weak or stale randomness could in theory weaken security. The patch is defensive and does not by itself prove an attack exists.
Treat as a defensive hardening patch. Review whether any earlier firmware versions could have produced keys or nonces from RNG output immediately following a SEIS recovery, and consider re-deriving or rotating highly sensitive material if such an event can be correlated with logs or fault indicators. No immediate emergency response is indicated by the diff alone.
Security signals we found
RNG recovery routine previously did not discard post-recovery output
New behavior follows vendor reference-manual recommendation (RM0432 32.3.7)
Randomness is used for cryptographic key material in a hardware wallet
Bootloader variant remains unbounded on DRDY wait, a hard fail-closed behavior
No explicit CVE, advisory, or researcher attribution in commit or references
Evidence from the diff
The patch modifies rng_recover() in both the MK4 firmware and bootloader. Previously the function cleared the RNG_SR_SEIS sticky flag and toggled RNGEN. The new code adds a loop that reads and discards 12 words from RNG_DR after recovery, matching RM0432 section 32.3.7 guidance for the STM32L4 RNG peripheral. The firmware version bounds the DRDY wait with a timeout; the bootloader version keeps the wait unbounded (consistent with its existing rng_sample()). The change is a hardening measure against possible pre-error residual pipeline data being used as entropy.
Changed components
stm32/COLDCARD_MK4/rng.cstm32/mk4-bootloader/rng.cSTM32L4 RNG peripheral recovery pathInspect captured patch +33 / −2
### stm32/COLDCARD_MK4/rng.c
@@ -70,10 +70,29 @@ static void rng_recover(void)
// Ensure the peripheral is clocked before touching its registers.
__HAL_RCC_RNG_CLK_ENABLE();
- // Clear sticky SEIS, then cycle RNGEN per the STM32L4 recovery sequence.
+ // Clear sticky SEIS and cycle RNGEN (ST HAL recommendation).
RNG->SR &= ~RNG_SR_SEIS;
RNG->CR &= ~RNG_CR_RNGEN;
RNG->CR |= RNG_CR_RNGEN;
+
+ // RM0432 32.3.7: after clearing SEIS, read out 12 words from RNG_DR and
+ // discard each of them to clean the pipeline of pre-error residue.
+ // Bounded: if the error recurs or DRDY stops arriving, bail out and let
+ // the next attempt's flag checks and DRDY timeout handle it.
+ for (int i = 0; i < 12; i++) {
+ uint32_t start = HAL_GetTick();
+
+ while (!(RNG->SR & RNG_SR_DRDY)) {
+ if (RNG->SR & RNG_SEED_ERROR_MASK) {
+ return;
+ }
+ if (HAL_GetTick() - start >= RNG_TIMEOUT_MS) {
+ return;
+ }
+ }
+
+ (void)RNG->DR;
+ }
}
// Make one bounded attempt to obtain a trustworthy, non-zero word.
### stm32/mk4-bootloader/rng.c
@@ -24,10 +24,22 @@ rng_recover(void)
// Ensure the peripheral is clocked before touching its registers.
__HAL_RCC_RNG_CLK_ENABLE();
- // Clear sticky SEIS, then cycle RNGEN per the STM32L4 recovery sequence.
+ // Clear sticky SEIS and cycle RNGEN (ST HAL recommendation).
RNG->SR &= ~RNG_SR_SEIS;
RNG->CR &= ~RNG_CR_RNGEN;
RNG->CR |= RNG_CR_RNGEN;
+
+ // RM0432 32.3.7: discard 12 words to clean the pipeline. The DRDY wait
+ // stays unbounded like rng_sample(): a dead clock remains a hard
+ // fail-closed wait; a recurring seed error bails to the next attempt.
+ for(int i = 0; i < 12; i++) {
+ while(!(RNG->SR & RNG_FLAG_DRDY)) {
+ if(RNG->SR & RNG_SEED_ERROR_MASK) {
+ return;
+ }
+ }
+ (void)RNG->DR;
+ }
}
// rng_setup()Why this scored 61/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.