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?
-
10$\begingroup$ Maybe from the file copy dialogue? Sorry, couldn't resist... $\endgroup$ – KlaymenDK Aug 24 '16 at 20:25
-
$\begingroup$ This whitepaper directly from Niels Ferguson / Microsoft would explain everything quite well. $\endgroup$ – Maarten Bodewes♦ Dec 7 '20 at 14:52
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.
-
1$\begingroup$ off-topic comment: where do you people read up such advanced things? $\endgroup$ – Spandan Sep 2 '16 at 13:07
-
1
-
$\begingroup$ Page 11 of this PDF has some more information: csrc.nist.gov/CSRC/media/projects/… $\endgroup$ – Marc Oct 21 '19 at 14:19