Page 1 of 1

Random Generator in the DM42

Posted: Wed Sep 22, 2021 1:03 pm
by Nissen
Hello friends
The STM32L476 microcontroller used in the DM42 includes a TRUE random generator according to ST Microelectronics specifications.
The generator in the DM42 is only a PSEUDO-random generator.
Is it possible, to activate the TRUE random generator in the DM42?
Just curious :D
Regards, Nissen

Re: Random Generator in the DM42

Posted: Wed Sep 22, 2021 3:58 pm
by reavy
Do they claim how it’s a TRNG? Does it have an antenna for picking up background radio waves or something?

Re: Random Generator in the DM42

Posted: Wed Sep 22, 2021 4:57 pm
by Nissen
The Random Numbers are generated from the noise from a Zener diode.

Re: Random Generator in the DM42

Posted: Wed Sep 22, 2021 5:08 pm
by newbrain
There's a definite advantage in using a (good) PRNG, namely the reproducibility of results.
This is the reason for the SEED function - when seeded with the same starting number, the sequence will be the same.
For example when testing two different algorithms or simulations using the same sequence remove the possible bias due to "luck".

So the usage of the TRNG should be limited to the cases of cold startup and '0 SEED', which currently use the time of day as random number seed.

At first glance*, the changes needed would, at least, be:
  • DMCP would need to provide a new service call to read the TRNG
  • Function shell_random_seed in dm42_fns.cc should be changed to use the new service (instead of rtc_read)
For someone so inclined, it might be feasible to cobble up a prototype using direct register access to the TRNG in dm42_fns, without the need for a modified DMCP.
Only a few register accesses are needed, and nothing that might interfere with other things.

* No guarantee this is complete and correct, I'm not that familiar with DM43 codebase.
The Random Numbers are generated from the noise from a Zener diode.
What?
No, the TRNG in STM32L476 is based on XORing three free running ring oscillators, plus post processing stages to even out 0 and 1 distribution and "whiten" the distribution. See the RM, chapter 27.3.3.