True RNG in STM32F0 - Page 1
Forum section: electronics / general

author: danils
author_rank: Contributor
timestamp: April 22, 2025, 11:49:51 pm
content: 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 likehttps://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/rngWould it make a robust true randomness implementation for feeding the TLS library?ThanksD.

author: incf
author_rank: Frequent Contributor
timestamp: April 22, 2025, 11:57:57 pm
content: 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.

author: peter-h
author_rank: Super Contributor
timestamp: April 23, 2025, 07:59:40 am
content: Assuming the RTC is running, just read all the registers, add them up, and do a CRC32 on themIf this is a security risk, the attacker is already running his code in your product

author: woofy
author_rank: Frequent Contributor
timestamp: April 23, 2025, 08:10:41 am
content: Pretty much anything which introduces randomness will do.Try reading a time server for example, then using sysclk for the seed.

author: MT
author_rank: Super Contributor
timestamp: April 23, 2025, 06:47:13 pm
content: Quote from: danils on April 22, 2025, 11:49:51 pmCertain STM32F models have a terrible ADC which some folks here are using as noise source. There are entire threads about that.

author: bson
author_rank: Unknown
timestamp: April 23, 2025, 09:00:51 pm
content: 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).

author: AndyC_772
author_rank: Super Contributor
timestamp: April 23, 2025, 09:10:49 pm
content: 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.

author: thm_w
author_rank: Super Contributor
timestamp: April 23, 2025, 11:10:55 pm
content: https://www.reddit.com/r/embedded/comments/14s4utm/random_number_generation_on_an_stm32_using_dual/https://community.st.com/t5/stm32-mcus-products/generate-random-number-for-stm32f030/td-p/360838

author: __george__
author_rank: Contributor
timestamp: April 23, 2025, 11:50:45 pm
content: 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.

author: peter-h
author_rank: Super Contributor
timestamp: April 24, 2025, 09:05:24 am
content: QuoteIn 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 problemsGive it a few hours and you will have a sizeable chunk of china and russia hitting this server...

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 03, 2025, 07:32:49 pm
content: Upgrade to a G0, they have TRNG...