# Securerandom.rb for 1.8

securerandom.rb e\$B\$re(B 1.8 e\$B\$KDI2C\$7!“e(Bcgi/session.rb
e\$B\$K;H\$o\$;\$?\$\$e(B
e\$B\$N\$G\$9\$,!”\$I\$&\$G\$7\$g\$&\$+!#e(B

e\$B3XE*\$K\$=\$l\$J\$j\$K0BA4\$JMp?t\$,I,MW\$G\$9!#e(B

e\$B\$7\$+\$7!"8=>u\$Ne(B Ruby e\$B\$G\$O\$=\$N\$h\$&\$J0BA4\$JMp?t\$rF@\$k4JC1\$Je(B API
e\$B\$,MQ0U\$5\$l\$F\$\$\$J\$\$\$?\$a!“0BA4\$J\$s\$+\$I\$&\$J\$N\$+\$h\$/\$o\$+\$i\$J\$\$2xe(B

e\$B\$d\$O\$j!"\$=\$&\$\$\$&Fq\$7\$\$0E9f\$NOC\$O!"L_\$OL_20\$H\$\$\$&\$3\$H\$G30Ite(B
(OpenSSL e\$B\$de(B /dev/urandom) e\$B\$K\$^\$+\$;\$k\$N\$,\$\$\$\$\$N\$G\$O\$J\$\$\$G\$7\$ge(B
e\$B\$&\$+!#e(B

# Index: lib/securerandom.rb

— lib/securerandom.rb (e\$B%j%S%8%g%se(B 0)
+++ lib/securerandom.rb (e\$B%j%S%8%g%se(B 0)
@@ -0,0 +1,137 @@
+# = Secure random number generator interface.
+#
+# This library is an interface for secure random number generator which
is
+# suitable for generating session key in HTTP cookies, etc.
+#
+# It supports following secure random number generators.
+#
+# * openssl
+# * /dev/urandom
+#
+# == Example
+#
+# p SecureRandom.hex(10) #=> “52750b30ffbc7de3b362”
+# p SecureRandom.hex(10) #=> “92b15d6c8dc4beb5f559”
+# p SecureRandom.hex(11) #=> “6aca1b5c58e4863e6b81b8”
+# p SecureRandom.hex(12) #=> “94b2fff3e7fd9b9c391a2306”
+# p SecureRandom.hex(13) #=> “39b290146bea6ce975c37cfc23”
+# …
+#
+# # random base64 string.
+# p SecureRandom.base64(10) #=> “EcmTPZwWRAozdA==”
+# p SecureRandom.base64(10) #=> “9b0nsevdwNuM/w==”
+# p SecureRandom.base64(10) #=> “KO1nIU+p9DKxGg==”
+# p SecureRandom.base64(11) #=> “l7XEiFja+8EKEtY=”
+# p SecureRandom.base64(12) #=> “7kJSM/MzBJI+75j8”
+# p SecureRandom.base64(13) #=> “vKLJ0tXBHqQOuIcSIg==”
+# …
+#
+# # random binary string.
+# p SecureRandom.random_bytes(10) #=> “\016\t{\370g\310pbr\301”
+# p SecureRandom.random_bytes(10) #=> “\323U\030TO\234\357\020\a\337”
+# …
+
+begin

• require ‘openssl’
+end

+module SecureRandom

• # NotImplementedError is raised.

• def self.random_bytes(n=nil)
• n ||= 16
• if defined? OpenSSL::Random
• `````` return OpenSSL::Random.random_bytes(n)
``````
• end
• if !defined?(@has_urandom) || @has_urandom
• `````` @has_urandom = false
``````
• `````` flags = File::RDONLY
``````
• `````` flags |= File::NONBLOCK if defined? File::NONBLOCK
``````
• `````` flags |= File::NOCTTY if defined? File::NOCTTY
``````
• `````` flags |= File::NOFOLLOW if defined? File::NOFOLLOW
``````
• `````` begin
``````
• ``````   File.open("/dev/urandom", flags) {|f|
``````
• ``````     unless f.stat.chardev?
``````
• ``````       raise Errno::ENOENT
``````
• ``````     end
``````
• ``````     @has_urandom = true
``````
• ``````     ret = f.readpartial(n)
``````
• ``````     if ret.length != n
``````
• ``````       raise NotImplementedError, "Unexpected partial read from
``````

random device"

• ``````     end
``````
• ``````     return ret
``````
• ``````   }
``````
• `````` rescue Errno::ENOENT
``````
• ``````   raise NotImplementedError, "No random device"
``````
• `````` end
``````
• end
• raise NotImplementedError, “No random device”
• end

• # NotImplementedError is raised.

• def self.hex(n=nil)
• random_bytes(n).unpack(“H*”)[0]
• end

• # NotImplementedError is raised.

• def self.base64(n=nil)
• [random_bytes(n)].pack(“m*”).delete("\n")
• end

• # 0.0 <= SecureRandom.random_number() < 1.0.

• def self.random_number(n=0)
• if 0 < n
• `````` hex = n.to_s(16)
``````
• `````` hex = '0' + hex if (hex.length & 1) == 1
``````
• `````` bin = [hex].pack("H*")
``````
• `````` mask = bin[0]
``````
• `````` mask |= mask >> 1
``````
• `````` mask |= mask >> 2
``````
• `````` mask |= mask >> 4
``````
• `````` begin
``````
• ``````   rnd = SecureRandom.random_bytes(bin.length)
``````
• ``````   rnd[0] = (rnd[0] & mask).chr
``````
• `````` end until rnd < bin
``````
• `````` rnd.unpack("H*")[0].hex
``````
• else
• `````` # assumption: Float::MANT_DIG <= 64
``````
• `````` i64 = SecureRandom.random_bytes(8).unpack("Q")[0]
``````
• `````` Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
``````
• end
• end
+end
Index: lib/cgi/session.rb
===================================================================
— lib/cgi/session.rb (e\$B%j%S%8%g%se(B 13603)
+++ lib/cgi/session.rb (e\$B:n6H%3%T!<e(B)
@@ -174,16 +174,22 @@

# session ids.

def create_new_id
• `````` require 'digest/md5'
``````
• `````` md5 = Digest::MD5::new
``````
• `````` now = Time::now
``````
• `````` md5.update(now.to_s)
``````
• `````` md5.update(String(now.usec))
``````
• `````` md5.update(String(rand(0)))
``````
• `````` md5.update(String(\$\$))
``````
• `````` md5.update('foobar')
``````
• `````` require 'securerandom'
``````
• `````` begin
``````
• ``````   session_id = SecureRandom.hex(16)
``````
• `````` rescue NotImplementedError
``````
• ``````   require 'digest/md5'
``````
• ``````   md5 = Digest::MD5::new
``````
• ``````   now = Time::now
``````
• ``````   md5.update(now.to_s)
``````
• ``````   md5.update(String(now.usec))
``````
• ``````   md5.update(String(rand(0)))
``````
• ``````   md5.update(String(\$\$))
``````
• ``````   md5.update('foobar')
``````
• ``````   session_id = md5.hexdigest
``````
• `````` end
@new_session = true
``````
• `````` md5.hexdigest
``````
• `````` session_id
``````
end
private :create_new_id

At Wed, 3 Oct 2007 12:49:20 +0900,
Tanaka A. wrote:

securerandom.rb ã‚’ 1.8 ã«è¿½åŠ ã—ã€cgi/session.rb ã«ä½¿ã‚ã›ãŸã„

ãƒ¡ã‚½ãƒƒãƒ‰åã« random_ ãŒä»˜ã„ãŸã‚Šä»˜ã‹ãªã‹ã£ãŸã‚Šã™ã‚‹ç‚¹ãŒæ°—ã«ãªã‚Š
ã¾ã™ã€‚

ã€€ruby-dev ã®è­°è«–ã¯èª­ã‚“ã ã‚“ã§ã™ãŒã€ãƒ¡ã‚½ãƒƒãƒ‰åãŒæ±ºã¾ã£ãŸçµŒç·¯ã¯
è¿½ã„åˆ‡ã‚Œã¾ã›ã‚“ã§ã—ãŸã€‚ã“ã†ã„ã†ã®ã¯ã„ã¾ã„ã¡ã§ã—ã‚‡ã†ã‹ã€‚

random_number(i) → integer
random_number(f=1.0) → float
random_bytes(n) → binary_string / string
hex(n) → hex_string
base64(n) → base64_string

å­¦çš„ã«ãã‚Œãªã‚Šã«å®‰å…¨ãªä¹±æ•°ãŒå¿…è¦ã§ã™ã€‚

ã—ã‹ã—ã€ç¾çŠ¶ã® Ruby ã§ã¯ãã®ã‚ˆã†ãªå®‰å…¨ãªä¹±æ•°ã‚’å¾—ã‚‹ç°¡å˜ãª API

(OpenSSL ã‚„ /dev/urandom) ã«ã¾ã‹ã›ã‚‹ã®ãŒã„ã„ã®ã§ã¯ãªã„ã§ã—ã‚‡
ã†ã‹ã€‚

ã€€ãã†ã§ã™ã­ã€‚æœ‰ç”¨ãªå ´é¢ã¯å¤šã„ã¨æ€ã„ã¾ã™ã€‚

/
/__ __ Akinori.org / MUSHA.org
/ ) ) ) ) / FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp

“Different eyes see different things,
Different hearts beat on different strings –
But there are times for you and me when all such things agree”

In article [email protected],
“Akinori MUSHA” [email protected] writes:

hex(n) → hex_string
base64(n) → base64_string

random_number e\$B\$Oe(B rand e\$B8_49\$G!“e(BSecureRandom
e\$B\$,E,@Z\$J%1!<%9\$Ge(B
rand e\$B\$r;H\$C\$F\$\$\$?!”\$H\$\$\$&>l9g\$K5!3#E*\$K=q\$-49\$(\$i\$l\$k\$h\$&\$K!"e(B
e\$B\$H\$\$\$&0U?^\$G\$9!#\$G\$b\$=\$s\$J\$K\$*A&\$a\$G\$O\$J\$/!"e(Bhex e\$B\$de(B base64
e\$B\$re(B
e\$B;H\$C\$F\$[\$7\$\$\$N\$GD9\$\$L>A0\$K\$J\$C\$F\$\$\$^\$9!#e(B

integer e\$B\$O\$"\$C\$F\$\$\$\$\$+\$b\$7\$l\$^\$;\$s\$,!“MQES\$O\$J\$s\$H\$\$\$&\$+e(B
session id e\$B\$H\$+\$h\$j\$O\$b\$C\$H@lLgE*\$J\$b\$N\$K\$J\$k5\$\$,\$7\$^\$9!#e(B
e\$B8+<1\$,\$”\$k\$R\$H\$KI,MW@-\$r@b\$+\$l\$F\$+\$i\$GCY\$/\$J\$\$\$h\$&\$K;W\$\$\$^\$9!#e(B

float e\$B\$Oe(B (e\$B>e5-\$N=q\$-49\$(0J30\$G\$Oe(B)
e\$B\$A\$g\$C\$HMQES\$,;W\$\$Ev\$?\$j\$^e(B
e\$B\$;\$s!#e(B

random_bytes e\$B\$Oe(B OpenSSL::Random.random_bytes e\$B\$KM3Mh\$7\$^\$9!#e(B
bytes e\$B\$K\$7\$h\$&\$+\$H9M\$(\$?\$3\$H\$b\$"\$j\$^\$9\$,!"e(B[ruby-dev:31515]
e\$B\$N\$h\$&\$Ke(B IO#bytes e\$B\$He(B Random#bytes
e\$B\$G0c\$&\$N\$G\$I\$&\$7\$?\$b\$N\$+\$J\$!e(B
e\$B\$H;W\$\$\$D\$D!“e(Brandom_bytes e\$B<+BN\$O\$=\$s\$J\$K;H\$\$\$d\$9\$/\$J\$/\$F\$b\$\$e(B
e\$B\$\$\$+!”\$H\$\$\$&\$3\$H\$G\$=\$N\$^\$^\$K\$J\$C\$F\$\$\$^\$9!#e(B

binary_string, string e\$B\$OJLL>\$H\$7\$F\$"\$j\$&\$k\$H;W\$\$\$^\$9!#e(B

hex e\$B\$He(B base64 e\$B\$,C;\$\$\$N\$O0U?^E*\$G\$9!#\$3\$l\$i\$r;H\$\$\$^\$7\$g\$&\$H\$\$e(B
e\$B\$&?d>)\$r<(\$7\$F\$\$\$^\$9!#e(B

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

1.9e\$B8~\$1\$K=`Hw\$7\$F\$\$\$?!";d\$HEDCf\$5\$s\$,9g0U\$7!“e(Bruby-coree\$B\$G0U8+\$bJg=8\$7\$F\$^e(B
e\$B\$H\$a!“CfED\$5\$s\$&\$5\$5\$s\$N6(NO\$K\$h\$j<BAu\$9\$k\$b!”\$^\$D\$b\$H\$5\$s0l?M\$N!Ve(Bsrand
e\$B\$J\$/\$9\$H\$J\$k\$H\$I\$&\$J\$s\$@\$m\$&\$J\$”!W\$H\$\$\$&M}M3\$,L@3N\$G\$J\$\$H?BP\$K\$h\$j;_\$^\$Ce(B
e\$B\$?e(B(e\$B"(e(B)Randome\$B%/%i%9!"\$N>pJs\$rDs6!!#e(B

Tanaka A. wrote:

hex(n) -> hex_string

float e\$B\$Oe(B (e\$B>e5-\$N=q\$-49\$(0J30\$G\$Oe(B) e\$B\$A\$g\$C\$HMQES\$,;W\$\$Ev\$?\$j\$^e(B
e\$B\$;\$s!#e(B

Randome\$B%/%i%9\$G\$O!"e(BRandom#rande\$B\$K\$J\$C\$F\$\$\$?\$b\$N\$G\$9\$M!#\$3\$A\$i\$NL?L>\$O0\9Te(B
e\$B\$N\$70W\$5M%@h\$GDs0F\$7\$?\$b\$N\$G\$7\$?!#e(B

rand()e\$B\$+\$ie(BSecureRandome\$B\$X\$N0\9T\$rI,MW0J>e\$KB%\$9I,MW\$O\$J\$\$\$G\$9\$+\$i!“e(Brande\$B\$He(B
e\$B\$\$\$&L>>N\$K\$3\$@\$o\$j\$O\$”\$j\$^\$;\$s!#0\9T\$rB%\$9I,MW\$,\$J\$\$!"\$H\$\$\$&4QE@\$+\$i\$9\$ke(B
e\$B\$H!"\$\$\$C\$=\$N\$3\$He(Brandom_numbere\$B\$bITMW\$J\$N\$G\$O!#e(B

random_bytes e\$B\$Oe(B OpenSSL::Random.random_bytes e\$B\$KM3Mh\$7\$^\$9!#e(B
bytes e\$B\$K\$7\$h\$&\$+\$H9M\$(\$?\$3\$H\$b\$"\$j\$^\$9\$,!"e(B[ruby-dev:31515]
e\$B\$N\$h\$&\$Ke(B IO#bytes e\$B\$He(B Random#bytes e\$B\$G0c\$&\$N\$G\$I\$&\$7\$?\$b\$N\$+\$J\$!e(B
e\$B\$H;W\$\$\$D\$D!“e(Brandom_bytes e\$B<+BN\$O\$=\$s\$J\$K;H\$\$\$d\$9\$/\$J\$/\$F\$b\$\$e(B
e\$B\$\$\$+!”\$H\$\$\$&\$3\$H\$G\$=\$N\$^\$^\$K\$J\$C\$F\$\$\$^\$9!#e(B

OpenSSL::Random.random_bytese\$B\$b!"\$=\$l\$[\$I9M\$(\$i\$l\$F:n\$i\$l\$?%a%=%C%I\$8\$c\$Je(B
e\$B\$5\$=\$&\$G\$9\$+\$i!"M3Mh\$H\$\$\$&\$[\$I\$N\$3\$H\$O\$J\$\$\$H;W\$\$\$^\$9!J\$A\$J\$\$Ke(BOpenSSLe\$B\$Ne(B
e\$B4X?tL>\$Oe(BRAND_bytes()e\$B!K!#:G=i\$K<BAu\$7\$?%
%+%m%3\$H\$7\$F\$b!“EDCf\$5\$s\$N;XE&F1e(B
e\$BMM!”!Ve(Bbytese\$B\$8\$c4JC1\$9\$.\$k\$+\$J!W\$H;W\$C\$?\$N\$+\$b\$7\$l\$^\$;\$s!#e(B

e\$B\$?\$@!"8D?ME*\$K\$O!"e(Bhexe\$B!“e(Bbase64e\$B\$,\$”\$^\$j%T%s\$H\$3\$J\$\$\$N\$G!J8e=R!K!“e(B
SecureRandom.bytese\$B\$H\$\$\$&C;\$\$L>>N\$K\$7\$F!”\$3\$A\$i\$3\$=?d>)\$K\$7\$?\$\$\$H\$3\$m\$Ge(B
e\$B\$9!#e(BSecureRandom.random_bytes(256/8)e\$B\$H\$+!"D9\$/\$FHa\$7\$\$!#e(B

binary_string, string e\$B\$OJLL>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$B"(e(B) e\$B\$+\$J\$j:,\$K;}\$C\$F\$\$\$k!#e(B

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRwuFOx9L2jg5EEGlAQJl5ggAsmro4Md2puv+GZaYJbA8OWkUwAVT5BPA
+MxP9YiaPVkFqYFyj1A+52eM1RXCRlpebzIO4t2sSTHoSeJ5m8BwzL+6l6J0n9hm
WreXBRYI5dIKHpy229K4yfH9jgSEo9NXDRoEsWZ0Iy6AbwhdtZNudthFVzPrffw0
5oRVUl9MqYKUnYExY9wpxZDdBJ2G+/5F2nJSdz4I7YGWYHn8L5vNc/8/WVijQ/Be
vS6/H95CK9yMaa8YP/02UyY/SNhbevnWxmzI+B5fW8D6gim4ciyDxA==
=O34I
-----END PGP SIGNATURE-----

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:31993] Re: securerandom.rb for 1.8”
on Tue, 9 Oct 2007 22:43:01 +0900, “NAKAMURA, Hiroshi”
[email protected] writes:

|1.9e\$B8~\$1\$K=`Hw\$7\$F\$\$\$?!“;d\$HEDCf\$5\$s\$,9g0U\$7!“e(Bruby-coree\$B\$G0U8+\$bJg=8\$7\$F\$^e(B
|e\$B\$H\$a!“CfED\$5\$s\$&\$5\$5\$s\$N6(NO\$K\$h\$j<BAu\$9\$k\$b!”\$^\$D\$b\$H\$5\$s0l?M\$N!Ve(Bsrand
|e\$B\$J\$/\$9\$H\$J\$k\$H\$I\$&\$J\$s\$@\$m\$&\$J\$”!W\$H\$\$\$&M}M3\$,L@3N\$G\$J\$\$H?BP\$K\$h\$j;_\$^\$Ce(B
|e\$B\$?e(B(e\$B”(e(B)Randome\$B%/%i%9!"\$N>pJs\$rDs6!!#e(B

e\$B\$(!<\$H!“e(BRandome\$B%/%i%9\$=\$N\$b\$N\$KH?BP\$7\$?3P\$(\$O\$”\$j\$^\$;\$s!#e(B
Randome\$B%/%i%9\$rF3F~\$9\$k\$H\$7\$F!“\$9\$G\$K\$”\$ke(Bsrande\$B\$d\$i\$r:o\$kI,MW\$,e(B
e\$B\$“\$k\$N\$+\$I\$&\$+!”\$HH/8@\$7\$?\$@\$1\$G\$9!#\$3\$l\$r!V;d0l?M\$NM}M3\$,L@e(B
e\$B3N\$G\$J\$\$H?BP!W\$H\$5\$l\$k\$N\$OITK~\$@\$J!#e(B

e\$B5DO@\$NN.\$l\$r0-\$/\$7\$?\$+\$b\$7\$l\$J\$\$\$1\$I!#e(B

``````                            e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$me(B /:|)
``````

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yukihiro M. wrote:

|1.9e\$B8~\$1\$K=`Hw\$7\$F\$\$\$?!";d\$HEDCf\$5\$s\$,9g0U\$7!“e(Bruby-coree\$B\$G0U8+\$bJg=8\$7\$F\$^e(B
|e\$B\$H\$a!“CfED\$5\$s\$&\$5\$5\$s\$N6(NO\$K\$h\$j<BAu\$9\$k\$b!”\$^\$D\$b\$H\$5\$s0l?M\$N!Ve(Bsrand
|e\$B\$J\$/\$9\$H\$J\$k\$H\$I\$&\$J\$s\$@\$m\$&\$J\$”!W\$H\$\$\$&M}M3\$,L@3N\$G\$J\$\$H?BP\$K\$h\$j;_\$^\$Ce(B
|e\$B\$?e(B(e\$B"(e(B)Randome\$B%/%i%9!"\$N>pJs\$rDs6!!#e(B

e\$B\$(!<\$H!“e(BRandome\$B%/%i%9\$=\$N\$b\$N\$KH?BP\$7\$?3P\$(\$O\$”\$j\$^\$;\$s!#e(B
Randome\$B%/%i%9\$rF3F~\$9\$k\$H\$7\$F!"\$9\$G\$K\$"\$ke(Bsrande\$B\$d\$i\$r:o\$kI,MW\$,e(B
e\$B\$"\$k\$N\$+\$I\$&\$+!"\$HH/8@\$7\$?\$@\$1\$G\$9!#\$3\$l\$r!V;d0l?M\$NM}M3\$,L@e(B
e\$B3N\$G\$J\$\$H?BP!W\$H\$5\$l\$k\$N\$O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uWJR9L2jg5EEGlAQIgxAf8C2G/uPQeEIOys/F38WyPyHFQJWsnkcmq
jIE2p5v+4J8/Almu76Bmi+MoFOdUnJ8U+c2urB4XH5byXsuTbKN4sOJI3a7PmxhN
inYuG8D4k9uHPdpJectth5oV6qEBUEw+GoPVGHMZDkSFqYHbV+zWZUaCqsdc+6bc
Kwr8XkB7PEPvAZvSlV/fpDlYo+hCWaU7tvcVgpjcO5e2a+ZTtOkralSXsU/PNcYZ
+/HqBlsS2Af9IT+Jo0sVUKmjFCpidNgWoSdIxwClrEbMCBFtSghI0iEArShui5/9
Z4rL0b+2mYx9gsX3mV2nGgH1HP7haJ/PHj1752cao5osF6kWWKVV9g==
=R1VA
-----END PGP SIGNATURE-----

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:31997] Re: securerandom.rb for 1.8”
on Tue, 9 Oct 2007 23:55:13 +0900, “NAKAMURA, Hiroshi”
[email protected] writes:

|e\$B2sEz\$7\$^\$;\$s\$G\$7\$?\$C\$1!#e(B[ruby-dev:31555]e\$B\$G\$9!#:o\$kI,MW\$,\$“\$k!”\$H\$^\$G\$OFIe(B
|e\$B\$a\$J\$+\$C\$?\$+!#<B:]\$N\$H\$3\$m!“\$”\$N:n6H\$O!"!V%0%m!<%P%k\$J>uBV\$rJQ99\$9\$k\$b\$Ne(B
|e\$B\$O:o=|!W\$N\$?\$a\$K\$d\$C\$F\$\$\$?\$o\$1\$G\$9!#e(B

e\$B\$^\$“!”\$=\$&=q\$\$\$F\$O\$"\$j\$^\$7\$?\$1\$I!“F05!\$,==J,\$KFI\$_<h\$l\$J\$+\$Ce(B
e\$B\$?\$N\$G!#!V\$J\$<:o=|\$7\$?\$\$\$+!W\$H\$\$\$&ItJ,\$G\$9\$h\$M!#8@\$o\$J\$/\$F\$be(B
e\$B\$o\$+\$k\$H;W\$o\$l\$?\$N\$+!”\$A\$c\$s\$H@bL@\$7\$F\$b\$i\$C\$F\$^\$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Je(B
e\$B\$\$\$H\$\$\$&\$H\$3\$m!#e(B

e\$B\$=\$l\$G\$O!“e(BRubyGemse\$B\$He(BRakee\$B\$He(BCSVe\$B\$NOC\$,JRIU\$\$\$F!”\$^\$@e(B1.9.1e\$B\$K4V\$K9g\$&\$h\$&\$G\$“e(B
e\$B\$l\$P!”>x\$7JV\$9\$3\$H\$K\$7\$^\$9!#C/\$+B>\$N?M\$,>x\$7JV\$7\$F\$/\$l\$F\$b9=\$\$\$^\$;\$s\$,!"e(B
e\$B\$\$\$J\$\$\$+\$J!#e(B

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRwv7xh9L2jg5EEGlAQKzKgf/dhOvGKWMnI7/Bq5f0b8ycXSxzpPbwpPI
U+tgYFE0T3G76DkF1u9tb5RumPTj0wWdjRPl30arN1KoTuozIJxxVKyTTkaQcbwt
ReySV5YW3zQnMOuMuJiyc6pE/5c3++7wsWYdRkn4Ttdclf9iiiFrDVc5qQaPau7T
G+7ce/lkDcHLbslZ8GSawiAUch8Ai/okwIdgtr9Cs+m2pdE+Y8KNyC7h7nmqXinS
Om13qJIvTQ0m1sYHznLQ5uFMjX+UwhzgruRIXNhLFFTAQzleUfLaMdO0K51U7Itd
er/+Uc6ShUuS7P3TnMary0JQCgIuzYIgb3t/QklKRvY9EN6bor1uJQ==
=B29k
-----END PGP SIGNATURE-----

In article [email protected],
“NAKAMURA, Hiroshi” [email protected] writes:

e\$B\$J\$k\$[\$I!#\$=\$&8@\$C\$F\$/\$l\$l\$P\$\$\$\$\$N\$K!#\$G\$O!“\$b\$7e(BRandome\$BF3F~\$N5DO@\$r:F3+\$7e(B
e\$B\$?\$/\$J\$C\$?>l9g\$K\$O!”%9%l%C%I\$+\$iF05!\$NItJ,\$r=&\$C\$F\$-\$F@0M}\$7\$^\$9!#:G=ie(B
e\$B\$N!"EDCf\$5\$s\$H\$Ne(Bsecrand.rbe\$B\$K4X\$9\$kOC\$,860x\$N\$O\$:!#e(B
[ruby-dev:30944]e\$B!Je(B6/9e\$B!K!“e(B[ruby-dev:30963]e\$B!Je(B6/12e\$B!K\$”\$?\$j\$+\$Je(B?

srand e\$B\$K4X\$9\$k;d\$N9M\$(\$O;2>H\$5\$l\$F\$\$\$ke(B [ruby-dev:30963] e\$B\$K=qe(B
e\$B\$,F~\$C\$?8e\$G!We(Bsrand
e\$B\$rGQ;_\$9\$k\$N\$b\$\$\$\$\$@\$m\$&!"\$H\$\$\$&\$b\$N\$G\$9!#e(B

e\$B\$J\$N\$G!“8=;~E@\$G9T\$&\$H\$\$\$&\$J\$R\$5\$s\$NH=CG\$KI,\$:\$7\$b;?@.\$9\$k\$oe(B
e\$B\$1\$G\$O\$”\$j\$^\$;\$s!#e(B

e\$B\$^\$!!“\$J\$R\$5\$s\$,<+?H\$NH=CG\$K\$*\$\$\$F\$=\$&\$9\$k\$H\$\$\$&\$N\$G\$”\$l\$PH?e(B
e\$BBP\$9\$k\$[\$I\$G\$b\$"\$j\$^\$;\$s\$,!#e(B

In article [email protected],
“NAKAMURA, Hiroshi” [email protected] writes:

Randome\$B%/%i%9\$G\$O!"e(BRandom#rande\$B\$K\$J\$C\$F\$\$\$?\$b\$N\$G\$9\$M!#\$3\$A\$i\$NL?L>\$O0\9Te(B
e\$B\$N\$70W\$5M%@h\$GDs0F\$7\$?\$b\$N\$G\$7\$?!#e(B

rand()e\$B\$+\$ie(BSecureRandome\$B\$X\$N0\9T\$rI,MW0J>e\$KB%\$9I,MW\$O\$J\$\$\$G\$9\$+\$i!“e(Brande\$B\$He(B
e\$B\$\$\$&L>>N\$K\$3\$@\$o\$j\$O\$”\$j\$^\$;\$s!#0\9T\$rB%\$9I,MW\$,\$J\$\$!“\$H\$\$\$&4QE@\$+\$i\$9\$ke(B
e\$B\$H!”\$\$\$C\$=\$N\$3\$He(Brandom_numbere\$B\$bITMW\$J\$N\$G\$O!#e(B

e\$BI,MW\$,\$“\$kDxEY\$K\$OB%\$9I,MW\$,\$”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I!#M_\$7\$\$?M\$,MW\$k\$N\$KH?BP\$Oe(B
e\$B\$7\$^\$;\$s\$,!”?d>)\$H\$\$\$&\$N\$O\$J\$!!#e(B

e\$B\$J\$s\$Ge(B random_bytes e\$B\$r?d>)\$7\$?\$\$\$s\$G\$9\$+e(B?
e\$B?d>)\$9\$k\$He(B hex e\$B\$de(B base64 e\$B\$h\$j\$bJXMx\$K\$J\$j\$^\$9\$+e(B?

At Tue, 9 Oct 2007 20:09:21 +0900,
Tanaka A. wrote:

random_number(i) → integer
random_number(f=1.0) → float
random_bytes(n) → binary_string / string
hex(n) → hex_string
base64(n) → base64_string

ã¨ã„ã†æ„å›³ã§ã™ã€‚ã§ã‚‚ãã‚“ãªã«ãŠè–¦ã‚ã§ã¯ãªãã€hex ã‚„ base64 ã‚’
ä½¿ã£ã¦ã»ã—ã„ã®ã§é•·ã„åå‰ã«ãªã£ã¦ã„ã¾ã™ã€‚

ãã®ã¾ã¾ã§ã€‚

integer ã¯ã‚ã£ã¦ã„ã„ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“ãŒã€ç”¨é€”ã¯ãªã‚“ã¨ã„ã†ã‹
session id ã¨ã‹ã‚ˆã‚Šã¯ã‚‚ã£ã¨å°‚é–€çš„ãªã‚‚ã®ã«ãªã‚‹æ°—ãŒã—ã¾ã™ã€‚
è¦‹è­˜ãŒã‚ã‚‹ã²ã¨ã«å¿…è¦æ€§ã‚’èª¬ã‹ã‚Œã¦ã‹ã‚‰ã§é…ããªã„ã‚ˆã†ã«æ€ã„ã¾ã™ã€‚

float ã¯ (ä¸Šè¨˜ã®æ›¸ãæ›ãˆä»¥å¤–ã§ã¯) ã¡ã‚‡ã£ã¨ç”¨é€”ãŒæ€ã„å½“ãŸã‚Šã¾
ã›ã‚“ã€‚

ã€€ãã†ã§ã™ã­ã€‚

random_bytes ã¯ OpenSSL::Random.random_bytes ã«ç”±æ¥ã—ã¾ã™ã€‚
bytes ã«ã—ã‚ˆã†ã‹ã¨è€ƒãˆãŸã“ã¨ã‚‚ã‚ã‚Šã¾ã™ãŒã€[ruby-dev:31515]
ã¨æ€ã„ã¤ã¤ã€random_bytes è‡ªä½“ã¯ãã‚“ãªã«ä½¿ã„ã‚„ã™ããªãã¦ã‚‚ã„
ã„ã‹ã€ã¨ã„ã†ã“ã¨ã§ãã®ã¾ã¾ã«ãªã£ã¦ã„ã¾ã™ã€‚

ã€€ã‚ã‹ã‚Šã¾ã—ãŸã€‚

binary_string, string ã¯åˆ¥åã¨ã—ã¦ã‚ã‚Šã†ã‚‹ã¨æ€ã„ã¾ã™ã€‚

ã€€bytes ã¨å‘¼ã¶ã‚‚ã®ã‚’ string ã¨ã‚‚å‘¼ã¹ã‚‹ã„ã†ã®ã¯ã‚„ã¯ã‚Šã‚ˆããªã„ã—ã€
binary_string ã¨è¨€ã†ãã‚‰ã„ãªã‚‰ random_bytes ã§ã„ã„ã®ã§æ’¤å›žã—ã¾ã™ã€‚

hex ã¨ base64 ãŒçŸ­ã„ã®ã¯æ„å›³çš„ã§ã™ã€‚ã“ã‚Œã‚‰ã‚’ä½¿ã„ã¾ã—ã‚‡ã†ã¨ã„
ã†æŽ¨å¥¨ã‚’ç¤ºã—ã¦ã„ã¾ã™ã€‚

ã€€ãŸãã•ã‚“ã®ç®‡æ‰€ã§ä½¿ã†ã‚‚ã®ã§ã‚‚ãªã•ãã†ãªã®ã§é•·ãã¦ã‚‚ã„ã„ã¨æ€ã„
ã¾ã™ãŒã€èª¤è§£ã¯ç”Ÿã˜ãªã„ã¨æ€ã†ã®ã§ç´å¾—ã—ã¾ã—ãŸã€‚

ã€€String#hexencode ã‚„ String#base64encode ãŒçµ„ã¿è¾¼ã¿ã§ã‚ã£ã¦ã‚‚

/
/__ __ Akinori.org / MUSHA.org
/ ) ) ) ) / FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp

“Different eyes see different things,
Different hearts beat on different strings –
But there are times for you and me when all such things agree”

-----BEGIN P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SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRwyQkx9L2jg5EEGlAQI3MAf/Y8mPuUU2vhrNRKKiLHUGDAN2n0f/hFv/
KcSbA44dDhcP9oLlF2uZa2wMYhKppAYNNPBYrmi/BXepS4hFrbqOb2kq5IY7R6gV
yaSHSeY78QfrM+AHAkN7++hPInUal+Ppi78y2QaayNugWVZzueCGbxkDdJC2p/9V
UBN+b1RspIieoiNI59rVlrTrE5795YJmjLhZdLpESXAuKSWJLs4t9HZk6bHT3bIw
dCIqb3kOeAZ9k5SVCv07dJCRYozPbG5Rw1GH/ENAgFBmNEHalhRWB9eLbQzJbEur
Ys/5G8ONW9J32VLWf4mQyi4AcJM1zd9g0upe6sxmlhFW20qvtgOiBQ==
=qd+q
-----END PGP SIGNATURE-----

In article [email protected],
“NAKAMURA, Hiroshi” [email protected] writes:

e\$B!V%_%+%m%3!W\$C\$F\$J\$s\$G\$9\$+e(B?

e\$B1#8l\$G\$7\$?\$9\$\$\$^\$;\$s!#e(BMichal R.e\$B!#:G=i\$Ke(Bext/openssle\$B\$r<BAu\$7\$??M\$G\$9!#e(B

e\$B\$J\$k\$[\$I!#e(B

e\$B;d\$Ne(BOpenSSL::Random.random_bytese\$B\$NMQES\$G\$O!“e(Bhexe\$B\$de(Bbase64e\$B\$K\$9\$k\$3\$H\$O\$[\$He(B
e\$B\$s\$I\$J\$/!”\$=\$N\$^\$^6&M-80\$K\$7\$?\$j!"5pBg@0?t\$H\$_\$J\$7\$Fe(BMPI(*)e\$B\$J\$I\$N5pBg@0?te(B
e\$BI=8=\$KJQ49\$9\$k!#e(B

(*) OpenPGPe\$B\$GDj5A\$5\$l\$?%U%)!<%^%C%H!#e(B

e\$B\$U\$`!#\$=\$&\$\$\$&6qBNE*\$JMQES\$O;29M\$K\$J\$j\$^\$9!#e(B

e\$B\$3\$3\$G\$N;d\$HEDCf\$5\$s\$NG’<1\$N0c\$\$\$O!"e(B[ruby-dev:30939]e\$B!“e(B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$r;H\$&\$h\$&e(B
e\$B\$J7|G0\$OBg\$-\$/\$J\$\$\$h\$&\$K;W\$\$\$^\$9!#e(B

• SecureRandom.random_bytes
• SecureRandom.base64.unpack(“m”)[0]
• [SecureRandom.hex].pack(“H*”)

In article [email protected],
“Akinori MUSHA” [email protected] writes:

binary_string, string e\$B\$OJLL>\$H\$7\$F\$"\$j\$&\$k\$H;W\$\$\$^\$9!#e(B

e\$B!!e(Bbytes e\$B\$H8F\$V\$b\$N\$re(B string e\$B\$H\$b8F\$Y\$k\$\$\$&\$N\$O\$d\$O\$j\$h\$/\$J\$\$\$7!"e(B
binary_string e\$B\$H8@\$&\$/\$i\$\$\$J\$ie(B random_bytes e\$B\$G\$\$\$\$\$N\$GE12s\$7\$^\$9!#e(B

e\$B\$^\$!!"NI\$\$L>A0\$,\$_\$D\$+\$l\$P8e\$+\$i\$G\$be(B alias e\$B\$r\$D\$1\$k\$3\$H\$,\$Ge(B
e\$B\$-\$^\$9!#e(B

e\$B\$=\$NL>A0\$,e(B random_bytes e\$B\$Ne(B
12e\$BJ8;z\$h\$j\$bC;\$\$\$b\$N\$G\$"\$l\$P!“e(B
random_bytes e\$B\$H\$\$\$&L>A0\$,;D\$C\$F\$\$\$F\$b\$=\$s\$J\$K8e2y\$7\$J\$/\$F:Qe(B
e\$B\$_\$^\$9\$N\$G!”\$J\$K\$+;W\$\$\$D\$\$\$?\$i\$^\$?9M\$(\$^\$7\$g\$&!#e(B

e\$B\$H\$\$\$&\$o\$1\$G%3%_%C%H\$7\$^\$7\$?!#e(B

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tanaka A. wrote:

e\$B\$J\$k\$[\$I!#\$=\$&8@\$C\$F\$/\$l\$l\$P\$\$\$\$\$N\$K!#\$G\$O!"\$b\$7e(BRandome\$BF3F~\$N5DO@\$r:F3+\$7e(B
e\$B\$?\$/\$J\$C\$?>l9g\$K\$O!"%9%l%C%I\$+\$iF05!\$NItJ,\$r=&\$C\$F\$-\$F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NfEAsGEiaAZS0pO1MrH3F7pcNSeaBqyL72VD/pSCt7X3s3Y
+f59Z/EmkCjZ5pS44u0DjYg68g/9VcQKfem1MoS9NY3UuKULx6Nz/Ddi4ZdfdfVB
pbyv0AjRPJLRaNU0cj+eKVk4BbtlkTqTyEZppeIt95KEzSHxl/wYGFLFuAOk1YMh
jRqMSsHdaNSj4U9ehkLFoJH2TeCbZ5UJeUfInEjhtxNOcD6IykwbGQ==
=WocP
-----END PGP SIGNATURE-----

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:32001] Re: securerandom.rb for 1.8”
on Wed, 10 Oct 2007 07:10:07 +0900, “NAKAMURA, Hiroshi”
[email protected] writes:

|> e\$B\$^\$“!”\$=\$&=q\$\$\$F\$O\$"\$j\$^\$7\$?\$1\$I!“F05!\$,==J,\$KFI\$_<h\$l\$J\$+\$Ce(B
|> e\$B\$?\$N\$G!#!V\$J\$<:o=|\$7\$?\$\$\$+!W\$H\$\$\$&ItJ,\$G\$9\$h\$M!#8@\$o\$J\$/\$F\$be(B
|> e\$B\$o\$+\$k\$H;W\$o\$l\$?\$N\$+!”\$A\$c\$s\$H@bL@\$7\$F\$b\$i\$C\$F\$^\$;\$s!#!V\$J\$/e(B
|> e\$B\$F\$b\$\$\$\$\$h\$M!W\$/\$i\$\$\$7\$+!#\$=\$l\$H\$b8+Mn\$H\$7\$F\$k\$N\$+\$Je(B(e\$B==J,\$"e(B
|> e\$B\$j\$(\$ke(B)e\$B!#e(B
|
|e\$B\$J\$k\$[\$I!#\$=\$&8@\$C\$F\$/\$l\$l\$P\$\$\$\$\$N\$K!#e(B

e\$B?=\$7Lu\$"\$j\$^\$;\$s!#;d<+?H\$b==J,\$K<+3P\$7\$F\$^\$;\$s\$G\$7\$?!#e(B

|e\$B>e\$NOC\$HF1\$8\$G\$9\$,!“!V%0%m!<%P%k\$J>uBV\$rJQ99\$9\$k\$b\$N\$O:o=|!W\$,A0Ds\$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B\$f\$-\$R\$me(B /:|)
``````

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:32067] Re: securerandom.rb for 1.8”
on Mon, 15 Oct 2007 23:16:36 +0900, “NAKAMURA, Hiroshi”
[email protected] writes:

|e\$B\$^\$D\$b\$H\$5\$s!“e(B[ruby-dev:31972]e\$B\$Ne(BRakee\$B%M%?\$O\$I\$&\$G\$9\$+!#\$?\$V\$s\$^\$@\$I\$A\$i\$He(B
|e\$B\$b7h\$a\$i\$l\$J\$\$!”\$H\$\$\$&\$3\$H\$@\$H;W\$\$\$^\$9\$,!"\$=\$l\$J\$i\$Pe(B

rakee\$B\$r%S%k%I\$K;H\$\$\$?\$\$\$H\$\$\$&%K!<%:\$OM}2r\$G\$-\$^\$9!#\$J\$i!“E:IUe(B
e\$B\$7\$F\$b\$\$\$\$\$s\$8\$c\$J\$\$\$+\$J\$H;W\$C\$F\$\$\$^\$9!#\$G!”\$J\$R\$5\$s\$?\$A\$N@be(B
e\$BL@\$rJ9\$/8B\$j\$O%G%a%j%C%H\$O\$J\$\$\$h\$&\$KJ9\$3\$(\$k\$N\$G\$9\$,!"\$=\$&\$\$e(B
e\$B\$&M}2r\$G9=\$\$\$^\$;\$s\$+!#e(B

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yukihiro M. wrote:

|OT: e\$B:#\$Oe(BRubyGemse\$B\$He(BRakee\$B\$N\$[\$&\$,M%@h!#e(B[ruby-dev:31970]e\$B!“e(B[ruby-dev:31972]e\$B\$Ne(B
|e\$BJV?.\$r\$*BT\$A\$7\$F\$\$\$^\$9!#e(Bruby-coree\$B\$N5DO@\$b!”\$=\$l\$G;_\$a\$F\$\$\$^\$9!#\$b\$7!V\$Ie(B
|e\$B\$&JV?.\$7\$?\$b\$s\$@\$+!W\$N>l9g\$K\$O!"2?\$,ITL@\$+!"2?\$KLB\$C\$F\$\$\$k\$+\$r65\$(\$F\$/\$@e(B
|e\$B\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