Description
Arduino API has several functions exposing PRNG functionality: randomSeed
, random(howbig)
, and random(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.
- Should we revert to the old behaviour to maintain compatibility? Assume that some sketch calls
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. - Some users will take
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. - Yet another bunch of users (and some libraries) will do things like
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. - Adding a new API like
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. - Adding configuration function like
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.