|
-
Mar 12th, 2017, 10:33 PM
#9
Thread Starter
Frenzied Member
Re: Here's a better way to generate random nums than using Rnd
 Originally Posted by dilettante
CryptGenRandom() wraps a call to RtlGenRandom() which has already been covered to death here.
It is not magical and has few of the amazing attributes you ascribe to it.
According to https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx in the section called "Remarks":
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. In Windows Vista, Windows Storage Server 2003, and Windows XP, the PRNG specified in Federal Information Processing Standard (FIPS) 186-2 is used. If an application has access to a good random source, it can fill the pbBuffer buffer with some random data before calling CryptGenRandom. The CSP then uses this data to further randomize its internal seed. It is acceptable to omit the step of initializing the pbBuffer buffer before calling CryptGenRandom.
Note in particular where it says: "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."
It also states that with Vista SP1 and later it uses a NIST specification for the random generator, and in XP it uses a FIPS specification for the random generator. Both of these are very advanced, and are far more random than VB6's internal Rnd function.
Also note that nowhere does it say that CryptGenRandom is equivalent to RtlGenRandom. In fact, common sense would say they are significantly different. RtlGenRandom does not have an argument to pass the crypto provider's handle (called hProv), but CryptGenRandom does have this function argument. It would seem that the randomness of CryptGenRandom depends on what level of security is required, which is determined by how advanced of a crypto provider you select. Whereas with RtlGenRandom a default level of randomness must be used, because there's no argument to pass an hProv to that function.
In fact, if you look at https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx which provides the documentation for RtlGenRandom, it says to NOT use that function, and to instead use CryptGenRandom, as RtlGenRandom may be removed in future versions of Windows. If CryptGenRandom were just a wrapper function for RtlGenRandom, then removing RtlGenRandom would disable CryptGenRandom's ability to run properly. So these are clearly 2 separate functions, unless you can provide Microsoft documentation that shows that CryptGenRandom actually uses RtlGenRandom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|