title: Does UuidCreate use a CSPRNG?
body: <p>Note that this is not <em>my</em> application, it is an application I am pentesting for a client. I usually ask questions like this on <a href="https://security.stackexchange.com/">https://security.stackexchange.com/</a>, however as this is more programming related I have asked on here.</p>
  
  <p>Granted, <a href="https://www.ietf.org/rfc/rfc4122.txt" rel="noreferrer">RFC 4122</a> for UUIDs does not specify that type 4 UUIDs have to be generated by a Cryptographically Secure Pseudo Random Number Generator (CSPRNG). It simply says</p>
  
  <blockquote>
    <p>Set all the other bits to randomly (or pseudo-randomly) chosen
          values.</p>
  </blockquote>
  
  <p>Although, some implementations of the algorithm, such as <a href="https://stackoverflow.com/a/7532965/413180">this one in Java</a>, do use a CSPRNG.</p>
  
  <p>I was trying to dig into whether Microsoft's implementation does or not. Mainly around how .NET or MSSQL Server generates them.</p>
  
  <p>Checking the <a href="http://referencesource.microsoft.com/#mscorlib/system/guid.cs,b7fae6994c22c22e,references" rel="noreferrer">.NET source</a> we can see this code:</p>
  
  <pre><code> Marshal.ThrowExceptionForHR(Win32Native.CoCreateGuid(out guid), new IntPtr(-1));
   return guid;
  </code></pre>
  
  <p>Checking the <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms688568(v=vs.85).aspx" rel="noreferrer"><code>CoCreateGuid</code></a> docco, it states</p>
  
  <blockquote>
    <p>The CoCreateGuid function calls the RPC function UuidCreate</p>
  </blockquote>
  
  <p>All I can find out about this function is <a href="https://msdn.microsoft.com/en-us/library/aa379205(VS.85).aspx" rel="noreferrer">here</a>. I seem to have reached the end of the rabbit hole.</p>
  
  <p>Now, does anyone have any information on how <code>UuidCreate</code> generates its UUIDs?</p>
  
  <p>I've seen many related posts:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2621563/how-random-is-system-guid-newguid-take-two">How Random is System.Guid.NewGuid()? (Take two)</a></li>
  <li><a href="https://stackoverflow.com/questions/917617/is-using-a-guid-a-valid-way-to-generate-a-random-string-of-characters-and-numbers">Is using a GUID a valid way to generate a random string of characters and numbers?</a></li>
  <li><a href="https://stackoverflow.com/questions/3652944/how-securely-unguessable-are-guids">How securely unguessable are GUIDs?</a></li>
  <li><a href="https://stackoverflow.com/questions/3242287/how-are-guids-generated-in-sql-server/3242328#3242328">how are GUIDs generated in SQL Server?</a></li>
  </ul>
  
  <p>The first of which says:</p>
  
  <blockquote>
    <p>A GUID doesn't make guarantees about randomness, it makes guarantees
    around uniqueness. If you want randomness, use Random to generate a
    string.</p>
  </blockquote>
  
  <p>I agree with this except in my case for random, unpredictable numbers you'd of course use a CSPRNG instead of <code>Random</code> (e.g. <code>RNGCryptoServiceProvider</code>).</p>
  
  <p>And the latter states (actually quoted from Wikipedia):</p>
  
  <blockquote>
    <p>Cryptanalysis of the WinAPI GUID generator shows that, since the
    sequence of V4 GUIDs is pseudo-random; given full knowledge of the
    internal state, it is possible to predict previous and subsequent
    values</p>
  </blockquote>
  
  <p>Now, on the other side of the fence <a href="https://stackoverflow.com/a/817150/413180">this post</a> from Will Dean says</p>
  
  <blockquote>
    <p>The last time I looked into this (a few years ago, probably XP SP2), I
    stepped right down into the OS code to see what was actually
    happening, and it was generating a random number with the secure
    random number generator.</p>
  </blockquote>
  
  <p>Of course, even if it was currently using a CSPRNG this would be implementation specific and subject to change at any point (e.g. any update to Windows). Unlikely, but theoretically possible.</p>
  
  <p>My point is that there's no canonical reference for this, the above was to demonstrate that I've done my research and none of the above posts reference anything authoritative.</p>
  
  <p>The reason is that I'm trying to decide whether a system that uses GUIDs for authentication tokens needs to be changed. From a pure design perspective, the answer is a definite <strong>yes</strong>, however from a practical point of view, if the Windows <code>UuidCreate</code> function does infact use a CSPRNG, then there is no immediate risk to the system. Can anyone shed any light on this?</p>
  
  <p>I'm looking for any answers with a reputable source to back it up.</p>