Search code examples
c++randomcryptographymicrophone

C++ Microphone Input As A Random Seed


I am currently playing around with some cryptography (RSA Public Key, in this case) and in order to generate a random key I need a random input. I figured the microphone would be a good source for relatively unreplicatable data. Is there any way to read the raw data out of a microphone in a way that can be used as to seed srand? Is there a better way to get a purely random seed and if so how would I do it?

I am running Windows 8 on a laptop with a built in mic and I am using the g++ compiler.


Solution

  • Do not try to get seed from hardware yourself. The OS knows a lot more than you about how to get quality randomness.

    On Linux, the correct way is to read /dev/urandom (not /dev/random; it is actually worthless)

    On Windows, Google indicates that you should use the CryptGenRandom function.