Windows/Path.inc: Move <shlobj.h> after "Windows.h" for some API available.
[oota-llvm.git] / lib / Support / Windows / Process.inc
index 750097eecf48677e741e255fb8897bf5ea9e2316..a0e3bc413a3f2c32d9de0fc28fafeefc5b1337c7 100644 (file)
@@ -360,3 +360,17 @@ const char *Process::ResetColor() {
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
   return 0;
 }
+
+unsigned Process::GetRandomNumber() {
+  HCRYPTPROV HCPC;
+  if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
+                              CRYPT_VERIFYCONTEXT))
+    assert(false && "Could not acquire a cryptographic context");
+
+  ScopedCryptContext CryptoProvider(HCPC);
+  unsigned Ret;
+  if (!::CryptGenRandom(CryptoProvider, sizeof(Ret),
+                        reinterpret_cast<BYTE *>(&Ret)))
+    assert(false && "Could not generate a random number");
+  return Ret;
+}