Switch dice RNG - #2473
Conversation
|
Build size and comparison to main:
|
|
@mark9064 Could we just use BT chip RNG? InfiniTime/src/components/ble/NimbleController.cpp Lines 288 to 307 in 8d7a04e I think using BT chip's RNG would need very little code and also would provide a good (more secure) randomness. P.S. We could also XOR "in" the existing seeds from |
|
I don't think this complexity is at all required. I think you'll find that this RNG is perfectly fine Seriously, give it a go if you're worried :) Reaching out to hardware opens up the risk of more problems in terms of correctness, performance and error handling |
|
@mark9064 You are right that tightly-coupling Dice app to BT chip is a very counter-intuitive thing and has a potential of causing issues later (especially when adopting to new hardware). The thing that is worrying me when using a simple (non-secure) PRNG in such application is ability to gather enough data to reconstruct the internal state of PRNG (afaik Could it be possible to reinitialize the PRNG on every roll of the Dice app? It would not only prevent a security issue like this, but also have a pretty cool side effect - the Dice app acting more like a physical dice (being affected by how it is shaken, though in a very hard to predict manner). 😎 |
|
I'm not sure how worried we should be about state recovery attacks on a watch dice app. Isn't the goal to have randomly distributed outputs, not randomly distributed and mathematically unpredictable outputs? Like in any situation where the dice app is going to be used, I'm really struggling to think of a case where being able to predict the RNG is a problem I get it's nice to have things theoretically perfect, but it just seems like extra complexity to me |
|
@mark9064 I think most people imply that a dice roll (even simulated one) is unpredictable. And InfiniTime users might rely on that without even thinking about it. I don't think it is possible to imagine all possible uses of a Dice app in a smartwatch. I definitely can imagine one scenario where predicting the PRNG numbers could be a big problem - if people would do multiple rounds of any "guess the numbers" game without restarting the Dice app. Also in board games like Monopoly predicting the subsequent dice rolls would give player an advantage. Reseeding the PRNG on every roll does not increase complexity at all. The #2478 moves the existing PRNG seeding code from constructor to the P.S. I think reseeding PRNG on every roll is far from perfect - it still doesn't solve at least 2 problems:
However I really like the idea mainly due to its simplicity and my own inability to find any downsides for it. |
The mersenne twister uses multiple KBs of state and is not needed for a dice app in terms of RNG quality
When we pick up GCC16, we can switch to
philox4x32This is an alternative to #2385: while I agree that PR is a better RNG than the one here, I don't think it's worth carrying a new dependency / implementation for it