Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of /dev/urandom on Windows?

Tags:

random

windows

My application would like to get a random number, preferably with entropy if available, but does not need cryptographic quality, and would like to do ensure that the call does not block if the system entropy pool is depleted (e.g. on a server in a farm).

I am aware of CryptGenRandom, but its behaviour with respect to blocking under adverse entropy conditions is not specified.

On Unix, /dev/urandom supports this use case. Is there equivalent functionality available on Windows? I would prefer to avoid using a non-system RNG simply to get non-blocking semantics.

like image 534
mabraham Avatar asked Feb 26 '14 17:02

mabraham


People also ask

Does Windows have dev random?

Yes, it's called Microsoft CryptoAPI. Show activity on this post. Microsoft C++ Visual Studio since 2005 offers rand_s() which works on Windows XP and up. It is based on RtlGenRandom (as are CryptoAPI's PRNG functions), whose inner workings are not made public.

What is file Dev urandom?

The /dev/random and /dev/urandom files are special files that are a source for random bytes generated by the kernel random number generator device. The /dev/random and /dev/urandom files are suitable for applications requiring high quality random numbers for cryptographic purposes.

What is the difference between Dev random and Dev urandom?

'Urandom' is used where there is constant need of random numbers and its randomness is not much important while 'random' is used where there is a security concern and its randomness should be reliable as it blocks outputting random numbers if entropy is not up to the mark.

What does Dev urandom do?

When read, the /dev/urandom device returns random bytes using a pseudorandom number generator seeded from the entropy pool. Reads from this device do not block (i.e., the CPU is not yielded), but can incur an appreciable delay when requesting large amounts of data.


1 Answers

For a toy application, you could use the standard library function rand(), but the implementation on Windows is of notoriously poor quality. For cryptographically secure random numbers, you can use the rand_s() standard library function.

A better bet is simply to include a suitable pseudo-random number generator in your program. The Mersenne Twister is a good choice IMO, particularly as there are plenty of available implementations (including in the C++11 standard library and in Boost).

like image 188
al45tair Avatar answered Sep 21 '22 02:09

al45tair