by ryuuchin · 10y ago · 0 comments
#include <windows.h>
#define SystemFunction036 NTAPI SystemFunction036
#include <ntsecapi.h>
#undef SystemFunction036
RtlGenRandom(buf, size);
This is more convenient than both rand_s[3] and CryptGenRandom[4]. The former can only generate one byte per call and the latter requires you to create a CSP (cryptographic service provider) before you can call it (which means you have to destroy the CSP when you're done using it). In the end these all call RtlGenRandom.RtlGenRandom uses a CSPRNG specified in NIST 800-90[4]. It uses AES256 in CTR mode AFAIK.
[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...
[2] https://boringssl.googlesource.com/boringssl/+/master/crypto...
[3] https://msdn.microsoft.com/en-us/library/sxtz2fa8.aspx
[4] https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...