From 5205e6a85ac8699c464e2d676c4d8b1c2b7989e5 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 18 Jan 2011 11:28:13 +0100 Subject: win32: Implement pa_random --- src/pulsecore/random.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/pulsecore/random.c') 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 #include +#ifdef HAVE_WINDOWS_H +#include +#include +#endif + #include #include #include @@ -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 */ -- cgit