1

When generating RSA keys using OpenSSL, if I want to use an external source of randomness (e.g an HSM that can provide random numbers), is the best way to get a new random number (for every generation), dump it to a file, and then use that file in the OpenSSL command line with -rand?

Is it necessary to balloon that file with several kBs of random numbers?

1 Answer 1

2

OpenSSL will use /dev/random if available. And: that is an excellent source of entropy, especially when used with a hardware source of entropy. I'd recommend you watch the excellent lecture held at 32c3 on misunderstandings and reality of /dev/random:

Screenshot of lecture

So: Use your hardware generator to feed your operating system's entropy pool, and let OpenSSL feed off that. Directly feeding OpenSSL from your hardware might work, but is not really any better – and more importantly, you eliminate the intermediate step of dumping randomness to a file, which might leave traces that could later on be used to reconstruct key generation.

4
  • Thanks, however this is on Windows, so I suspect implementing the same is going to be very difficult vs the simplicity of going via a file. Good point regarding the key reconstruction - can ensure the file will be memory mapped/ similar to ensure its lifetime is short.
    – Nik
    Commented Nov 19, 2016 at 18:14
  • You're right, I don't really know how openSSL gets entropy on Windows, but I'm 100% sure windows does have functions to give programs random numbers – the question is how to fill Window's random pool. But I guess that is something that manufacturers of hardware randomness generators solve! Commented Nov 19, 2016 at 18:38
  • en.wikipedia.org/wiki/CryptGenRandom Commented Nov 19, 2016 at 18:42
  • Thanks yeah - doesn't seem like something that can be very easily receive input. So my core question remains - from a cryptographic and openssl point of view, is there any problem with using -rand with a file, if we guaranteed that file had random bytes (by whatever means)?
    – Nik
    Commented Nov 20, 2016 at 11:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .