18
$\begingroup$

Where does the entropy that cryptographic .NET libraries use for encryption come from? I know with Linux you can use /dev/random, but does a similar pool exist within Windows?

$\endgroup$
2
  • 10
    $\begingroup$ Maybe from the file copy dialogue? Sorry, couldn't resist... $\endgroup$
    – KlaymenDK
    Aug 24, 2016 at 20:25
  • $\begingroup$ This whitepaper directly from Niels Ferguson / Microsoft would explain everything quite well. $\endgroup$
    – Maarten Bodewes
    Dec 7, 2020 at 14:52

1 Answer 1

19
$\begingroup$

Update: Since I wrote this post, CryptGenRandom has been deprecated. Apparently it is now recommended to use BCryptGenRandom from the "Cryptography Next Generation" API.

(Confusingly, it has nothing to do with bcrypt.)


Yes, Windows has something similar. It can be accessed through CryptGenRandom.

With Microsoft CSPs, CryptGenRandom uses the same random number generator used by other security components. This allows numerous processes to contribute to a system-wide seed. CryptoAPI stores an intermediate random seed with every user. To form the seed for the random number generator, a calling application supplies bits it might have—for instance, mouse or keyboard timing input—that are then combined with both the stored seed and various system data and user data such as the process ID and thread ID, the system clock, the system time, the system counter, memory status, free disk clusters, the hashed user environment block. This result is used to seed the pseudorandom number generator (PRNG). In Windows Vista with Service Pack 1 (SP1) and later, an implementation of the AES counter-mode based PRNG specified in NIST Special Publication 800-90 is used.

Technically this is closer to /dev/urandom than /dev/random, but in practice the fact that you get cryptographically random numbers rather than "pure entropy" does not matter.

$\endgroup$
4
  • 1
    $\begingroup$ off-topic comment: where do you people read up such advanced things? $\endgroup$
    – Spandan
    Sep 2, 2016 at 13:07
  • 1
    $\begingroup$ @Spandan, I gave the link or what do you mean? $\endgroup$
    – otus
    Sep 2, 2016 at 13:20
  • $\begingroup$ Page 11 of this PDF has some more information: csrc.nist.gov/CSRC/media/projects/… $\endgroup$
    – Marc
    Oct 21, 2019 at 14:19
  • $\begingroup$ This implementation could mean that all instances of a Windows VM taken from a same snapshot will share the same PRNG state, without live update from the environment. (Compared to Linux with "continuous" reseeding from RDSEED and CPU jitters.) This might cause issues, like duplicated nonces or reduced effective entropy in key generation. I hope the implementation is more complex and robust than described. $\endgroup$
    – A. Hersean
    Mar 2, 2022 at 9:40

Your Answer

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

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