Skip to content

Mix entropy in Dice PRNG on every Roll - #2502

Open
DavisNT wants to merge 1 commit into
InfiniTimeOrg:mainfrom
DavisNT:dice2
Open

DavisNT wants to merge 1 commit into
InfiniTimeOrg:mainfrom
DavisNT:dice2

Conversation

@DavisNT

@DavisNT DavisNT commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This is an improved version of #2478 - this preserves PRNG existing entropy when re-seeding.

This improves entropy of Dice and makes PRNG state recovery harder.
As a pleasant side effect this also makes the Dice app more like a physical dice - dependent on how it is shaken, but in a hard to predict manner.
Using PRNG output as one of the seeds preserves 32-bits of previous PRNG entropy when reseeding. For std::minstd_rand that means - its entire entropy.

This PR:

  • Is almost free
    • Needs no additional RAM
    • Increases code size only by around 32 bytes
    • Only moves a few lines of code and adds only static_cast<uint32_t>(gen())
  • Makes PRNG state recovery attacks incomparably harder. Recent demonstrations of LLM capabilities suggest such attacks might in a couple years be available to anyone using publicly available AI tools.
  • Fixes the main drawback of Reseed Dice RNG on every Roll #2478 - discardation of the existing PRNG state/entropy during re-seeding. I.e. with this PR it should be much harder (especially if multiple independent people do turns with the Dice app) to fixate a certain output from PRNG by manipulating timing and position (or accelerometer saturation) of the watch.

TL;DR I think this could be a good addition to #2473 and a pretty cool thing on it's own as it makes the Dice app more like a real physical dice. 😎 🎲
This PR provides better security than #2478 at virtually no cost.

This improves entropy of Dice and makes PRNG state recovery harder.
As a pleasant side effect this also makes the Dice app more like a
physical dice - dependent on how it is shaken, but in a hard to predict
manner.
Using PRNG output as one of the seeds preserves 32-bits of previous PRNG
entropy when reseeding. For std::minstd_rand that means entire entropy.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Build size and comparison to main:

Section Size Difference
text 393264B 32B
data 936B 0B
bss 22920B 0B

Run in InfiniEmu

@DavisNT DavisNT mentioned this pull request Nov 5, 2026
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.

1 participant