C++ Microphone Input As A Random Seed
Asked Answered
K

1

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.

Kristopher answered 9/10, 2014 at 4:30 Comment(3)
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.Bronchopneumonia
possible duplicate of C++ random float number generationBronchopneumonia
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.Neutralization
S
0

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.

Sheri answered 9/10, 2014 at 5:25 Comment(1)
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.Elisha

© 2022 - 2024 — McMap. All rights reserved.