summaryrefslogtreecommitdiffstats
path: root/src/os_mswin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_mswin.c')
-rw-r--r--src/os_mswin.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/os_mswin.c b/src/os_mswin.c
index 9d0e1a08a4..df760fd5ec 100644
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -830,6 +830,40 @@ mch_icon_load(HANDLE *iconp)
0, mch_icon_load_cb, iconp);
}
+/*
+ * Fill the buffer 'buf' with 'len' random bytes.
+ * Returns FAIL if the OS PRNG is not available or something went wrong.
+ */
+ int
+mch_get_random(char_u *buf, int len)
+{
+ static int initialized = NOTDONE;
+ static HINSTANCE hInstLib;
+ static BOOL (WINAPI *pProcessPrng)(PUCHAR, ULONG);
+
+ if (initialized == NOTDONE)
+ {
+ hInstLib = vimLoadLib("bcryptprimitives.dll");
+ if (hInstLib != NULL)
+ pProcessPrng = (void *)GetProcAddress(hInstLib, "ProcessPrng");
+ if (hInstLib == NULL || pProcessPrng == NULL)
+ {
+ FreeLibrary(hInstLib);
+ initialized = FAIL;
+ }
+ else
+ initialized = OK;
+ }
+
+ if (initialized == FAIL)
+ return FAIL;
+
+ // According to the documentation this call cannot fail.
+ pProcessPrng(buf, len);
+
+ return OK;
+}
+
int
mch_libcall(
char_u *libname,