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

Pseudo-random number generator #965

Closed
pfalcon opened this Issue Nov 8, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@pfalcon
Member

pfalcon commented Nov 8, 2014

It's nice that stmhal port has hw random generator, but we really should implement port-independent reproducible PRNG. I can think of following choices:

  1. Implement exact same algo as in CPython. This will help achieve 100% reproducibility for testing, etc.
  2. Implement the smallest (by code size) reasonable PRNG.
  3. Implement cryptographically-secure PRNG.
@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Nov 15, 2014

Contributor

CPython uses Mersenne Twister which has a large state (2496 bytes). This is pretty large for "micro". So -1 for CPython compat.

Smallest by code size would be to write no code, and this can be achieved by reusing AES cipher: your key is the seed and you generate raw AES blocks which are the pseudo random numbers. This has the advantage of being cryptographically secure. (I assume here we have implemented AES for SSL.)

Contributor

dpgeorge commented Nov 15, 2014

CPython uses Mersenne Twister which has a large state (2496 bytes). This is pretty large for "micro". So -1 for CPython compat.

Smallest by code size would be to write no code, and this can be achieved by reusing AES cipher: your key is the seed and you generate raw AES blocks which are the pseudo random numbers. This has the advantage of being cryptographically secure. (I assume here we have implemented AES for SSL.)

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Nov 15, 2014

Contributor

The AES implementation I wrote uses 208 bytes of state for AES 128, and 272 bytes for AES 256.

Contributor

dpgeorge commented Nov 15, 2014

The AES implementation I wrote uses 208 bytes of state for AES 128, and 272 bytes for AES 256.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Dec 12, 2014

Contributor

I just learned that the Python ssl module has a set of functions for crypto-secure PRNG: https://docs.python.org/3/library/ssl.html#ssl.RAND_bytes

Contributor

dpgeorge commented Dec 12, 2014

I just learned that the Python ssl module has a set of functions for crypto-secure PRNG: https://docs.python.org/3/library/ssl.html#ssl.RAND_bytes

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge May 6, 2016

Contributor

Point 2 above (Implement the smallest (by code size) reasonable PRNG) was implemened in a58a91e using Yasmarang generator.

Contributor

dpgeorge commented May 6, 2016

Point 2 above (Implement the smallest (by code size) reasonable PRNG) was implemened in a58a91e using Yasmarang generator.

@dpgeorge dpgeorge closed this May 6, 2016

tannewt added a commit to tannewt/circuitpython that referenced this issue Jul 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment