0
$\begingroup$

I am trying to implement a TRNG on Windows and among other entropy sources, I want to extract raw bytes from various kinds of CPU and process info.

As per my knowledge, BCryptGenRandom is a CRNG in the Windows API that uses this kind of noise to generate entropy. Do files like /dev/random exist on Windows and if so how can I directly access these files from my client code? I have read that it isn't as straightforward as in UNIX systems.

$\endgroup$
3

1 Answer 1

5
$\begingroup$

There are three of them:

  1. RtlGenRandom a.k.a. SystemFunction036 in advapi32.dll. This is the oldest one, and is hacky, but it does work and won't be going away any time soon.
  2. CryptGenRandom, the older CryptoAPI in Windows. Crypt32 is obsolete, but current versions will accept it though might be slow.
  3. BCryptGenRandom, the BCrypt library added in Windows Vista, is the current most supported one.

BCryptGenRandom is the one I would recommend.

Windows does not have a pseudo-file like /dev/urandom. The NT path \Device\KsecDD is the kernel driver behind these GenRandom functions, but accessing the generator is done via DeviceIoControl rather than direct read operations.

$\endgroup$
1
  • $\begingroup$ Is there any solid documentation for the working of BCryptGenRandom? I don't understand if it directly provides raw noise from the system environment or manipulates and conditions the entropy (health checks, mixing, hashing, etc.) to generate cryptographically secure random bitstreams. $\endgroup$
    – vibhav950
    Sep 15 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.