1

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.

Medynsky
  • 159
  • 12
  • There are lots of posts about generate random numbers. Try searching for them first. If you are intent on using the microphone, there seem to be plenty of posts about reading microphone input as well. When you've tried to put them together, then update this question or post another one with any remaining specific issues. – simo.3792 Oct 09 '14 at 04:35
  • possible duplicate of [C++ random float number generation](http://stackoverflow.com/questions/686353/c-random-float-number-generation) – simo.3792 Oct 09 '14 at 04:37
  • if by `srand` you mean the c standard library function, then don't use it. c's `rand` sucks even when you only need statistically good random numbers, not to speak of security. – CodesInChaos Oct 09 '14 at 12:30

1 Answers1

1

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.

o11c
  • 15,265
  • 4
  • 50
  • 75
  • There is little harm in adding some additional entropy from e.g. a microphone to the entropy `CryptGenRandom` provides. Look at the code for the Fortuna CSRNG for how to mix entropy from different sources. Do take the time to check just how random your proposed source is. – rossum Oct 10 '14 at 11:44