summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Bosmans <mkbosmans@gmail.com>2011-01-18 11:28:13 +0100
committerMaarten Bosmans <mkbosmans@gmail.com>2011-02-17 12:02:31 +0100
commit5205e6a85ac8699c464e2d676c4d8b1c2b7989e5 (patch)
tree06b58dc08835e11ebc611d4842d3b3b14e4db05d
parenta39a83665f07a0819a31ee2d1ab60210a67c47a2 (diff)
win32: Implement pa_random
-rw-r--r--src/pulsecore/random.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c
index 3d159bf2..bdbc1437 100644
--- a/src/pulsecore/random.c
+++ b/src/pulsecore/random.c
@@ -31,6 +31,11 @@
#include <stdlib.h>
#include <time.h>
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#include <wincrypt.h>
+#endif
+
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
@@ -43,10 +48,20 @@ static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL };
static int random_proper(void *ret_data, size_t length) {
#ifdef OS_IS_WIN32
+ int ret = -1;
+
pa_assert(ret_data);
pa_assert(length > 0);
- return -1;
+ HCRYPTPROV hCryptProv = NULL;
+
+ if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
+ if(CryptGenRandom(hCryptProv, length, ret_data))
+ ret = 0;
+ CryptReleaseContext(hCryptProv, 0);
+ }
+
+ return ret;
#else /* OS_IS_WIN32 */