LuckyResistor / SnowFlakeProject

All open source data of the snow flake project.
GNU General Public License v3.0
41 stars 10 forks source link

Pseudo random number generator is not seeded #2

Closed LuckyResistor closed 6 years ago

LuckyResistor commented 6 years ago

Summary

The pseudo random number generator is not properly seeded at the start of the firmware. Therefore the master will cycle always through the exact same sequence of scenes.

Background

It is not trivial to get good entropy from MCUs in a safe way. Just using the ADC to sample the voltage of a unconnected pin can work, but is not reliable. The Atmel SAM D20E can measure the internal temperature reference, which is hopefully a very noisy source. This would be worth a check.

Implementation

All random numbers are generated using the methods in the Helper module. The original is the PRNG engine gRandomGeneratorEngine there. This engine has to be seeded with enough entropy from the hardware in the initialize() method. A call of the seed() function of the engine should be enough.

The hardware related methods to get the actual values have to be placed in the Hardware module so they can be accessed by the Helper module.