Skip to content

[discussion] Random number generator API #1710

Closed
@igrr

Description

@igrr

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.

  1. 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.
  2. Some users will take random() and use it to generate nonces, keys, and other values which need better randomness than newlib's rand can provide. If we modify behaviour of random to use HW PRNG, we can improve security of these applications.
  3. 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 to randomSeed function can not serve as a good indicator that user wants a SW PRNG behaviour.
  4. 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 using secureRandom() unless it becomes part of the official Arduino API.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions