Hey,
The following is a quick patch for secure pseudorandom number generator on windows. I split the functionality with a brutal ifdef macro. Feedback on the code and suggestions for a nicer implementation is appreciated :). diff --git a/lib/entropy.c b/lib/entropy.c index 02f56e0..ec9d95c 100644 --- a/lib/entropy.c +++ b/lib/entropy.c @@ -20,6 +20,9 @@ #include <errno.h> #include <fcntl.h> #include <unistd.h> +#ifdef _WIN32 +#include <Wincrypt.h> +#endif #include "socket-util.h" #include "vlog.h" @@ -33,6 +36,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 +53,20 @@ get_entropy(void *buffer, size_t n) if (error) { VLOG_ERR("%s: read error (%s)", urandom, ovs_retval_to_string(error)); } +#else + int error = 1; + HCRYPTPROV crypt_prov = 0; + CryptAcquireContext(&crypt_prov, NULL, NULL, PROV_RSA_FULL, 0); + + if (CryptGenRandom(crypt_prov, n, buffer)) { + error = 0; + } + + if (error) { + VLOG_ERR("CryptGenRandom: read error (%s)", urandom, ovs_retval_to_string(error)); + } + CryptReleaseContext(crypt_prov, 0); +#endif return error; } Kind Regards, Alin. _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev