-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[discussion] Random number generator API #1710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe we need to maintain compatibility with the Arduino APIs. So having the default set for software is my belief. I like the concept of having a "system.config" concept that a sketch can call that would switch the underlying random functions. This way libraries written to work across platforms will still function and now function with more security. Also instead of saying hardware, maybe use security/encryption so its obvious why you would use one over the other. PRNG_Compatibile, PRNG_Secure? There will always be an issue where one library relied on compatibile and another would benefit from secure and both being used in the same sketch. The best way to solve this is really having Arduino API changed to include two APIs or have the library smart enough to use a custom one for Esp. Which then means we should expose the SecureRandom in some way still for when you need to mix. |
If someone is into security, he will for sure research how random() works on this platform. Every time after an update/change. So document the behavior and done. If I call randomseed(), there are two situations: with a fixed value or a "pseudo random" value. both init the sw random generator. From the fixed value I expect repeatable numbers every time when calling random(). from the pseudo random seed value I expect it to be random. Both situations are granted when the first call of randomseed() turns off the hardware random generator and switch to the old software rg for following random()-calls. If I only call random() and never randomseed() I obviously didn't care. Expose the underlaying functions, too. |
I think we should make it as secure as possible, most users not think about how secure / real random is the random number they get. The problem starts when the not really random behavior is used as "function", for example to generate every time the same "predictional" numbers after reboot. i can think of two concepts: to maintain best compatibility to Arduino: most security (prefered one): Independent of this we can add a functions for HW and SW rnd. |
@Links2004 You solution on your first suggestion won't work. Not everyone uses analogRead(A0) directly and if you did it never worked that well. (see GitHub\Makuna\RandomSeed as example of a better seeding and a method that breaks your assumption here). |
yes more advanced seeding processes are not detectable, |
We should try not to break Arduino APIs or break default Arduino assumptions. If calling randomSeed() with the same seed value EVER returns a different series of random numbers "by default" we have BROKEN the Arduino API. Unless its unavoidable due to situations outside our control, I believe we can't do this. It is documented as a feature and almost every OS out there, random is documented and supported this same way. The random api was never meant to be secure; most OS API expose a second API for encryption level random and point developers to it. |
If compatibility is a goal (sounds like it is), then I agree with having a configuration option, like Is there no way to implement a better SW PRNG, like Mersenne Twister or SFMT? Initializing that with the HW RNG would be an even better "compatible" default. |
What holgerlembke and makuna said. Secure random, reproducible and bakcward compatible seed behavior. If i call random i expect random, if i first called seed then i expect special random, if i seeded with some random source then i probably didnt read the docs or expected something better that was never actually true. |
#2142 implements proposed changes. |
Arduino API has several functions exposing PRNG functionality:
randomSeed
,random(howbig)
, andrandom(howsmall, howbig)
. Normally these functions call software PRNG provided by libc.Recently we have made a change (bf067f7) which modified behaviour of these Arduino functions. These functions now mix the values from software PRNG and ESP8266 internal hardware RNG. This change raised a few questions on gitter which I'm moving here for better discussion.
randomSeed
function with the same seed each time to produce a repeatable pseudo-random sequence (like some games do). By altering the values with HW PRNG we are breaking compatibility for this application.random()
and use it to generate nonces, keys, and other values which need better randomness than newlib'srand
can provide. If we modify behaviour ofrandom
to use HW PRNG, we can improve security of these applications.randomSeed(someFunc(analogRead(A0)))
. Clearly they are trying to get good random values, so probably the call torandomSeed
function can not serve as a good indicator that user wants a SW PRNG behaviour.secureRandom()
is one of the options. But we try to be compatible with Arduino libraries, and Arduino-compatible libraries will not be usingsecureRandom()
unless it becomes part of the official Arduino API.setPRNG(PRNG_SOFTWARE)
/setPRNG(PRNG_HARDWARE)
is yet another option. The trouble is, we still need to pick one of them as the default one. I.e. we need to choose between compatibility and security.Please drop your thoughts/suggestions on this matter so that we can improve this feature for the next release.
/cc @skorokithakis @Makuna @Links2004 @holgerlembke who participated in the initial discussion on Gitter.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: