trezor / trezor-firmware

:lock: Trezor Firmware Monorepo
https://trezor.io
Other
1.36k stars 663 forks source link

Further integration of HMAC DRBG #242

Open andrewkozlik opened 5 years ago

andrewkozlik commented 5 years ago

We would like to use the HMAC DRBG as a source of random numbers in more places than just generating random delays. Eventually we would like to use it for everything, assuming the DRBG would be reseeded before generating security-critical values.

  1. Determine where the DRBG can be used safely as is without reseeding, e.g. generating nonces, and make the replacements.
  2. Ensure periodic reseeding of the DRBG from the TRNG.
  3. Add more sources of randomness. These could be the value of the system clock at certain moments, e.g. user interaction.

As for 1., below is some preliminary research on where we could replace the TRNG with the DRBG right away:

random32():

random_buffer():

random_uniform():

random_permute():

random.uniform():

random.bytes():

keepkeyjon commented 5 years ago

Why is it preferable to use the DRBG over using the TRNG in as many places as possible?

andrewkozlik commented 5 years ago

There are two reasons:

  1. There is the recent freezing bug, which was apparently caused by reading from the TRNG before USB operations. It has something to do with I2C, I am not familiar with the details. To avoid this reocurring, it would be best to limit use of the TRNG especially when generating things like IVs, which do not require secrecy.
  2. The advantage of the DRBG is that you can feed it multiple sources of entropy including the random data from the TRNG. This is a precaution in case the TRNG produces random numbers with lower entropy than it should or if it becomes biased as the hardware ages. It also makes things more difficult for attackers who are aiming to control the random numbers generated by the device. If entropy is taken from a single source such as the TRNG, then the attacker needs to disable only that one source.
keepkeyjon commented 5 years ago

Ah, great points. Thanks for explaining!

alex-jerechinsky commented 3 years ago

ping @onvej-sl