generating random with crypto
-
I'm having a trouble generating a random using the crypto module.
I'm following the documentation but I stumble upon an error.
I'm working with the latest firmware (1.2.2.b1)>>> import crypto >>> from crypto import AES >>> iv = crypto.getrandbits(128) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'getrandbits'
Seems like there's no
getrandbits
method on the crypto module.
-
uos.urandom
is based on a linear feedback shift register, that is seeded with a number derived from the MAC address. The values will "look" like random for a whole period, but still easily predictable.crypto.getrandbits
is based on a hardware random number generator that gathers it's bits from random events (noise) received by the WiFi and Bluetooth radios. This source, according to the Espressif, passes randomness tests.@obertuckerz112, needed for writing a few AES examples? probably not. Needed for real life applications? The experts in cryptography say that you need a good source (as in unpredictable) of random numbers for things like the initialization vector (IV). Clearly,
uos.urandom
is not.In order to allow people to construct the best possible applications, we hence provide access to the hardware random number generator
getrandbits
as an usable source and recommend the people to use it instead ofuos.urandom
for cryptography purposes.
-
Do you specifically need it?
-
@abilio Good to know.
-
@Feiko, the result from
uos.urandom
comes from a pseudo random number generator. The one in crypto comes from a hardware number generator, that according to Espressif documents passes the diehard tests. I think that's probably why @iber is interested into it.
-
@ iber
iv = uos.urandom(16)
This should also work right.
-
great, looking forward to it.
I currently moved on using a 'not so random' value ;)
-
@iber, You're totally right. The code for it was merged into master a day after the last release, but with all the restructuring of the documentation, it ended up being published before it was included in a firmware release. I will be available in today's release. Hope you find the addition useful :)