I am working on the STM32L152xx that has a peripheral to perform AES128 (CBC) encryption. However, to initialize a random IV I am looking for a good scheme to create cryptographically secure random number sequence. I'm using a simple LCRG (linear congruential generator) as a place holder for now, but this is weak.
I am new to implementing encryption on an embedded platform, so I wonder what's the common practice out there to generate cryptographic PRNG? Or what is a good strategy for choosing the key and the IV?
Most of the answers on StackOverflow for cryptographic PRNG refers to 3rd party library that isn't available on this platform. However, if it's worth the try, I can attempt to port it. Links and pointers to resources would be helpful too!
I have access to the system clock and accelerometers on board. I'm running FreeRTOS. Thanks!
You're probably going to need to define "Cryptographically Secure" or your application a little better. If this were for a game on a mobile phone, you could probably use the accelerometer as a source of randomness. If you're trying to sign x.509 certificates, you would might consider some attached hardware that measures radioactive decay.
In all seriousness, depending on the strength of the "Randomness" that you need consider the following:
Any of the above methods may need to have some sort of de-bias algorithm applied to them. The simplest one is to consider your input 2-bits at a time. If the 2 bits are equal, discard them. 0b10 becomes 1 and 0b01 becomes 0. That will ensure that you get more-or-less the same number of 1s and 0s in your final random value.
Finally, if this is for something serious you should disregard all of the above advice and NOT ROLL YOUR OWN CRYPTO. Find some API for your platform that has been vetted already and use that. Testing an algorithm for randomness is very difficult to do.
Perhaps consider the F‑2 series of the STM32 core which apparently contains a hardware RNG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With