" Is there any hope for strong portable randomness in the future? There might be. All that's needed is a physical source of unpredictable numbers. A thermal noise or 

radioactive decay source and a fast, free-running oscillator would do the trick directly. This is a trivial amount of hardware, and could easily be included as a standard part 

of a computer system's architecture… All that's needed is the common perception among computer vendors that this small additional hardware and the software to access 

it is necessary and useful. Eastlake, Crocker, Schiller, “RFC 1750: Randomness Recommendations for Security.” IETF Network Working Group, December 1994.    

   I recently bought four of the the STM32F4DISCOVERY boards @ $15 a piece. Astounding value for money, when you consider all the built-in goodies you're getting.


What caught my glance and helped fire my imagination was the True Random Number Generator peripheral on board. 32-Bits wide, with built-in error checking 


mechanisms and with an operating bitrate of upto 660 Kbps. Wow, the mind boggles, the soul weeps for joy ! In the past, I've often used PRNG routines to generate 


random sequences for various apps I've developed and have always longed for the day to come, when I could afford to integrate a TRNG into my projects. That day 


arrived at the beginning of this week as the postman, at last, delivered my four brand new, shiny Discovery kits :-) 


   " The random number generator is implemented by an analog circuit. This circuit generates seeds that feed a linear feedback shift register (RNG_LFSR) in order 


to produce 32-bit random numbers. The analog circuit is made of several ring oscillators whose outputs are XORed to generate the seeds. The RNG_LFSR is clocked 


by a dedicated clock (PLL48CLK) at a constant  frequency, so that the quality of the random number is independent of the HCLK frequency. The contents of the 


RNG_LFSR are transferred into the data register (RNG_DR) when a significant number of seeds have been introduced into the RNG_LFSR." 



   How the embedded analog/digital hardware functions remains something of a mystery, but perhaps this article may shed  some light on this question, especially 


when one considers that, the development was, in part, sponsored by Arm Ltd? Ok, that's enough then with the theory ; it's high time to test it out now in practice.


   I decided to design the first TRNG app to simply output the contents of the random generator in the RNG_DR  data register directly to the four user leds onboard  


every 100 mS. With such a clock signal, the maximum bit rate output corresponds to a princely 10 Bps! Slow to be sure, but more than adequate for our needs, 


and as an added bonus, we don't need to use the error checking mechanisms in the RNG_SR status register. Good then, let's move on now to the implementation.


   In Start we firstly enable the clock for the the RNG in register RCC_AHB2ENR, followed by  the clock for the GPIOD in register RCC_AHB1ENR. GPIOD pins 15,14,13,12 


are then configured as General Purpose Push-Pull OutPuts with a maximum bandwidth of 2Mhz in register GPIOD_MODER. Next we move onto setting the SysTick  


interrupt to 10 Hz and as the last act in the Start routine,  we enable the Random Number Generator in register RNG_CR


   In Main the STM32F4 sleeps for more than 99% of the time until the SysTick register overflows and triggers an interrupt. The DRDY bit in the RNG_SR status register 


is read, and if it is set, the Barrel Shifter in the STM32F4  will process the next three conditional instructions. If not, it simply ignores these three instructions and instead 


loops back to Main. The random data is read into register R0 from the RNG_DR data register and register R0 is then shifted right by sixteen bits in the next instruction. 


This shift instruction also fills the upper 16-bits with all Zeros and,  this is necessary before storing the result into the GPIOD output register GPIOD_ODR.The top 16-bits


of this register are reserved and the reset value of all 0's must be used. The random light show repeats endlessly and is truly a joy to watch, especially in the dark ;-) 


   " Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin."  John von Neumann.