From abae70d6ed63054d7d01bd6cd80c1b5b98b93ba3 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Fri, 20 Jan 2017 08:00:00 +0000 Subject: SecureRandom should try /dev/urandom first [Bug #9569] * random.c (InitVM_Random): rename Random.raw_seed to Random.urandom. A quick search seems there are no practical use of this method than securerandom.rb so I think it's OK to rename but if there are users of it, this hunk is subject to revert. * test/ruby/test_rand.rb (TestRand#test_urandom): test for it. * lib/securerandom.rb (SecureRandom.gen_random): Prefer OS- provided CSPRNG if available. Otherwise falls back to OpenSSL. Current preference is: 1. CSPRNG routine that the OS has; one of - getrandom(2), - arc4random(3), or - CryptGenRandom() 2. /dev/urandom device 3. OpenSSL's RAND_bytes(3) If none of above random number generators are available, you cannot use this module. An exception is raised that case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_rand.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index 46d10f8386..79befa8f04 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -550,9 +550,9 @@ END End end - def test_raw_seed + def test_urandom [0, 1, 100].each do |size| - v = Random.raw_seed(size) + v = Random.urandom(size) assert_kind_of(String, v) assert_equal(size, v.bytesize) end -- cgit v1.2.3