Author Topic: True RNG in STM32F0  (Read 955 times)

0 Members and 1 Guest are viewing this topic.

Offline danilsTopic starter

  • Contributor
  • Posts: 35
  • Country: it
True RNG in STM32F0
« on: April 22, 2025, 11:49:51 pm »
Hi,

A customer asked me to implement a webserver on a STM32F0 that, as you know, lacks a RNG peripheral. Replacing the MCU at this stage of the project is impractical. I was thinking about adding a RNG IC like https://www.microchip.com/en-us/product/rng90#Overview.

Yet, in order to save BOM cost and PCB space, I was thinking about using an ADC channel reading a temperature sensor mounted on the PCB (unfortunately I have not spare ADC channels to read its random noise - but the temperature sensor should exhibit some random noise too) and I was thinking to use its data to seed this library:
https://github.com/Oryx-Embedded/CycloneCRYPTO/tree/master/rng

Would it make a robust true randomness implementation for feeding the TLS library?

Thanks

D.





« Last Edit: April 22, 2025, 11:58:09 pm by danils »
 

Online incf

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: us
  • ASCII > UTF8
Re: True RNG in STM32F0
« Reply #1 on: April 22, 2025, 11:57:57 pm »
I don't think so.

Consider using a well behaved noise source like a reverse biased BJT.

But if you don't need security you could just fake it with a psudorandom generator.
Test
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 4632
  • Country: gb
  • Doing electronics since the 1960s...
Re: True RNG in STM32F0
« Reply #2 on: April 23, 2025, 07:59:40 am »
Assuming the RTC is running, just read all the registers, add them up, and do a CRC32 on them :)

If this is a security risk, the attacker is already running his code in your product ;)
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Online woofy

  • Frequent Contributor
  • **
  • Posts: 416
  • Country: gb
    • Woofys Place
Re: True RNG in STM32F0
« Reply #3 on: April 23, 2025, 08:10:41 am »
Pretty much anything which introduces randomness will do.
Try reading a time server for example, then using sysclk for the seed.

Offline MT

  • Super Contributor
  • ***
  • Posts: 1759
  • Country: aq
Re: True RNG in STM32F0
« Reply #4 on: April 23, 2025, 06:47:13 pm »
Hi,

A customer asked me to implement a webserver on a STM32F0 that, as you know, lacks a RNG peripheral. Replacing the MCU at this stage of the project is impractical. I was thinking about adding a RNG IC like https://www.microchip.com/en-us/product/rng90#Overview.

Yet, in order to save BOM cost and PCB space, I was thinking about using an ADC channel reading a temperature sensor mounted on the PCB (unfortunately I have not spare ADC channels to read its random noise - but the temperature sensor should exhibit some random noise too) and I was thinking to use its data to seed this library:
https://github.com/Oryx-Embedded/CycloneCRYPTO/tree/master/rng

Would it make a robust true randomness implementation for feeding the TLS library?
Thanks D.

Certain STM32F models have a terrible ADC which some folks here are using as noise source. There are entire threads about that.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2576
  • Country: us
Re: True RNG in STM32F0
« Reply #5 on: April 23, 2025, 09:00:51 pm »
Fill a block of memory from the ADC and hash it with MD5 or the like.  The noise level of the ADC just determines the size of the block you need, but with cryptographic hashes in general changing a single bit on the input on average changes half the bits on the output, so it doesn't require much in the way of randomness to generate good seed.  (I assume this is to seed an RNG to be used later.)

Edit: 100 random bits out of 8192 16-bit samples, where there are up to 512 random LSBs would give 2859462363045362175889689804776516690968873940358319686157275755047898300652764867714064617203401346847080320 possible random combinations, so still plenty to seed any RNG (including cryptographic ones).
« Last Edit: April 23, 2025, 09:08:00 pm by bson »
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4357
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: True RNG in STM32F0
« Reply #6 on: April 23, 2025, 09:10:49 pm »
If you're doing a respin of the board anyway, I wouldn't add another IC - I'd replace the STM32 with one that has the RNG integrated.

Take the opportunity to migrate to a newer device. I hear the C series is cheap.

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 8155
  • Country: ca
  • Non-expert
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Online __george__

  • Contributor
  • Posts: 24
  • Country: no
Re: True RNG in STM32F0
« Reply #8 on: April 23, 2025, 11:50:45 pm »
If your customer wants to implement a webserver with TLS and you are considering the ADC or any other solution discussed here for random numbers I hope you understand that you will implement a (at least cryptographically) broken TLS essentially.

If this is not the use case and the random numbers are just needed for other reasons you can also just store true random numbers (taken from a PC or something) in flash and use them as a seed for some sort of pseudorandom generation function.
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 4632
  • Country: gb
  • Doing electronics since the 1960s...
Re: True RNG in STM32F0
« Reply #9 on: April 24, 2025, 09:05:24 am »
Quote
you will implement a (at least cryptographically) broken TLS essentially.

In theory, but in practice if you implement an HTTPS server, on an open port, in an embedded box like this, having possibly ever so slightly less than "perfect" RNG will be the least of your problems ;)

Give it a few hours and you will have a sizeable chunk of china and russia hitting this server...


Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6571
  • Country: es
Re: True RNG in STM32F0
« Reply #10 on: May 03, 2025, 07:32:49 pm »
Upgrade to a G0, they have TRNG...
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf