title: Random number generator security: BCryptGenRandom vs RNGCryptoServiceProvider
body: <p><em>For those in a hurry, this is <strong>NOT</strong> related to the controversial <code>Dual_EC_DRBG</code> planted inside NIST's SP800-90A.</em></p>
  
  <p>About the two RNGs:</p>
  
  <ol>
  <li><p>The Microsoft BCRYPT layer based one is over their C API. <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa375458%28v=vs.85%29.aspx" rel="nofollow"><code>BCryptGenRandom</code></a> is following NIST SP800-90A's <code>CTR_DRBG</code> (i.e. uses an approved block cipher, AES, to create random bits). However it is unclear if it uses a hardware random source as seed (or part of the seed)...</p></li>
  <li><p>The Microsoft .NET <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rngcryptoserviceprovider.aspx" rel="nofollow"><code>RNGCryptoServiceProvider</code></a> is C# based. Looking at the <a href="http://referencesource.microsoft.com/netframework.aspx" rel="nofollow">.NET source code</a> (or <a href="http://www.dotnetframework.org/default.aspx/4@0/4@0/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/clr/src/BCL/System/Security/Cryptography/RNGCryptoServiceProvider@cs/1305376/RNGCryptoServiceProvider@cs" rel="nofollow">here</a>), I see it end up calling the C++ method <code>CapiNative.GenerateRandomBytes()</code>. There should have been a P/Invoke stub for the C#=>C++ transition but I couldn't find it anywhere in the framework source. So I have no idea how it's actually implemented.</p></li>
  </ol>
  
  <p>Does anyone have additional information on these two random number generators? Do either/both use HW random seeds (either via diode noise in older intels or the controversial <code>RDRAND</code> in the latest intels).</p>
  
  <p>PS: Not sure it this should be at Security, StackOverflow or Cryptography ...</p>