summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 09:17:57 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 09:17:57 +0000
commitcb66eaab150fe8687c3b7b5bdd082c9016223b87 (patch)
treef0e7656009603f5fd3e3611d074ac095f5e54c57 /lib
parent34a72a75aed9ff814a8b24a72193ba93f3217790 (diff)
merge revision(s) 54144: [Backport #12139]
* lib/securerandom.rb (gen_random): to avoid blocking on Windows. On Windows OpenSSL RAND_bytes (underlying implementation is RAND_poll in crypto/rand/rand_win.c) may be blocked at NetStatisticsGet. https://wiki.openssl.org/index.php/Random_Numbers#Windows_Issues Instead of this, use Random.raw_seed directory (whose implementation CryptGenRandom is one of the source of entropy of RAND_poll on Windows). https://wiki.openssl.org/index.php/Random_Numbers Note: CryptGenRandom function is PRNG and doesn't check its entropy, so it won't block. [Bug #12139] https://msdn.microsoft.com/ja-jp/library/windows/desktop/aa379942.aspx https://tools.ietf.org/html/rfc4086#section-7.1.3 https://eprint.iacr.org/2007/419.pdf http://www.cs.huji.ac.il/~dolev/pubs/thesis/msc-thesis-leo.pdf git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/securerandom.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index c26bf50b02..9c258603a6 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -40,7 +40,7 @@ end
# p SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301"
# p SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
module SecureRandom
- if !defined?(OpenSSL::Random) && /mswin|mingw/ =~ RUBY_PLATFORM
+ if /mswin|mingw/ =~ RUBY_PLATFORM
require "fiddle/import"
module AdvApi32 # :nodoc:
@@ -110,7 +110,7 @@ module SecureRandom
gen_random(n)
end
- if defined? OpenSSL::Random
+ if defined?(OpenSSL::Random) && !defined?(AdvApi32)
def self.gen_random(n)
@pid = 0 unless defined?(@pid)
pid = $$