From b12c5a85b47c55d94b5baace09ad668ce610f716 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 18 Jul 2009 00:07:07 +0000 Subject: [PATCH] * random.c (fill_random_seed): use cryptographic service on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ random.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index eae337562e..4f0131cf58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Jul 18 09:07:00 2009 Nobuyoshi Nakada + + * random.c (fill_random_seed): use cryptographic service on Windows. + Sat Jul 18 07:56:00 2009 Hidetoshi NAGAI * ext/tk/lib/tk.rb: fail to create a widget object for an unknown diff --git a/random.c b/random.c index f67b65f2be..8013a51d01 100644 --- a/random.c +++ b/random.c @@ -389,6 +389,8 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT]) #if USE_DEV_URANDOM int fd; struct stat statbuf; +#elif defined(_WIN32) + HCRYPTPROV prov; #endif memset(seed, 0, DEFAULT_SEED_LEN); @@ -410,6 +412,11 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT]) } close(fd); } +#elif defined(_WIN32) + if (CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { + CryptGenRandom(prov, DEFAULT_SEED_LEN, seed); + CryptReleaseContext(prov, 0); + } #endif gettimeofday(&tv, 0);