1
$\begingroup$

I'm looking for commonly used and proven CPRNG implementation in C. What to use? ChaCha20 like in Linux Kernel? Does anybody know other implementations? PS: I don't want to implement by itself because it requires high accuracy and later must be verified by security experts to make sure all works correctly. Also I plan to use it on embedded device which OS doesn't have random system calls

$\endgroup$
0
$\begingroup$

commonly used and proven CPRNG implementation in C

An alternative would be knocking off Microsoft's CryptGenRandom. That's the old CSPRNG build into the WinNT family of OSes. Essentially it's SHA1(RC4) and has FIPS certification so should be okay for you. There's enough detail in On the (in)security of the random number generators of Linux and Windows and Cryptanalysis of the Windows Random Number Generator for you to be able to reconstruct it. SHA1 and RC4 details are everywhere. Do not be alarmed at the bias issues with RC4. Those occur natively before the hash function is applied.

You will note a valid forward security attack on CryptGenRandom. It only requires $ 2^{32} $ work effort which is quite low and therefore serious. However that requires knowledge of the internal state. Whether an attacker can know the internal state of anything is a huge can of worms, and only you can decide if this is a likely scenario.

Whopping great caveat: You need entropy to initialise (and perhaps reseed) your RNG. To be honest this is the hardest part. Generating cryptographically secure numbers is easy if you just use a library implementation of a CSPRNG. Similarly, a bit of ChaCha is easy, but you still require an initial seeded state. Seeding is the problem. Since we don't know your electronic environment, my advice can't be specific at this time. Have a look through the two links, try to identify any similarities (particularly related to the state) and come back with any further questions.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.