[ovs-dev] [PATCH] windows pseudorandom number generator

Alin Serdean aserdean at cloudbasesolutions.com
Sat Dec 14 01:20:31 UTC 2013


This patch is to add for secure pseudorandom number generator on windows.

Signed-off-by: Alin Serdean <aserdean at cloudbasesolutions.com>
---
 lib/entropy.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
 diff --git a/lib/entropy.c b/lib/entropy.c
index 02f56e0..45e83ec 100644
--- a/lib/entropy.c
+++ b/lib/entropy.c
@@ -33,6 +33,7 @@ static const char urandom[] = "/dev/urandom";
 int
 get_entropy(void *buffer, size_t n)
 {
+#ifndef _WIN32
     size_t bytes_read;
     int error;
     int fd;
@@ -49,6 +50,18 @@ get_entropy(void *buffer, size_t n)
     if (error) {
         VLOG_ERR("%s: read error (%s)", urandom, ovs_retval_to_string(error));
     }
+#else
+       int error = 0;
+       HCRYPTPROV   crypt_prov = 0;
+       CryptAcquireContext(&crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
+
+       if (!CryptGenRandom(crypt_prov, n, buffer)) {
+               error = GetLastError();
+               VLOG_ERR("CryptGenRandom: read error (%s)", ovs_retval_to_string(error));
+       }
+
+       CryptReleaseContext(crypt_prov, 0);
+#endif
     return error;
 }
---



More information about the dev mailing list