summaryrefslogtreecommitdiff
path: root/random.c
AgeCommit message (Collapse)Author
2016-05-05random.c: use arc4random_bufnobu
* random.c (fill_random_bytes_syscall): use arc4random_buf if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-01* cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4usa
support leftovers. [fix GH-1328] patched by @cremno git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-24* random.c (limited_rand): Add a specialized path for the limit fits in 32 bit.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09* *.c (*_memsize): do not check ptr.ko1
NULL checking is finished Before call of memsize functions. See r52979. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-05random.c: fix filling sizenobu
* random.c (fill_random_seed): fix the size to be filled, not the size of element, but the whole size of array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-01explicit_bzero.c: needs windows.hnobu
* missing/explicit_bzero.c, random.c (explicit_bzero): SecureZeroMemory() needs windows.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* random.c (InitVM_Random): move Random::DEFAULT initializationkosaki
bits to Init_Random_default. * random.c (Init_Random_default): renamed from Init_Rndom2. * random.c (Init_RandomSeedCore): renamed from Init_Random. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* random.c (Init_RandomSeed): move all Random::DEFAULTkosaki
construction bits to Init_RandomSeed2. Random::DEFAULT and Ruby internal hashes are no longer shared their seed. * random.c (Init_RandomSeed2): ditto. And, kill evil rb_obj_reveal() stuff. * random.c (init_hashseed): add MT argument. * random.c: (init_siphash): ditto. * test/ruby/test_rand.rb (TestRand#test_default_seed): new test for Random::DEFAULT::seed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* random.c (init_hashseed, init_siphash): extract initializekosaki
functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* random.c (init_randomseed): remove "initial" argument. It neverkosaki
be used from outside of this function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* random.c: random_raw_seed don't use GRND_NONBLOCK. GRND_NONBLOCKkosaki
mean the result might not have an enough cryptic strength and easy predictable. That's no good for SecureRandom. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* missing/explicit_bzero.c: new file. define explicit_bzero.kosaki
* common.mk: add a rule for explicit.o. * configure.in: detect explicit_bzero and memset_s. * include/ruby/missing.h: add explicit_bzero. * random.c (init_randomseed): use explicit_bzero() instead of memset(). memset could be eliminated by compiler optimization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18random.c: comment [ci skip]nobu
* random.c (fill_random_bytes_urandom): fix comment typos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18Revert r52180kosaki
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18* random.c (fill_random_bytes_urandom): add a comment why usingkosaki
O_NONBLOCK and O_NOCTTY. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18* random.c (fill_random_bytes_syscall): don't use GRND_NONBLOCK.kosaki
It is meaningless. If SYS_getrandom(GRND_NONBLOCK) return EAGAIN, we eventually call fill_random_bytes_urandom() and it block such as SYS_getrandom() without GRND_NONBLOCK. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18* random.c (fill_random_bytes_syscall): use ATOMIC_SET() forkosaki
updating try_syscall. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-25random.c: get rid of blockingnobu
* random.c (fill_random_bytes_syscall): get rid of blocking when no entropy is available. based on the patch by mame in [ruby-core:70114]. [Bug #11395] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-14fix compile error with clangkazu
* random.c (fill_random_bytes_syscall): fix compile error with clang. [ruby-core:69931] [Bug #11343] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07* random.c (fill_random_bytes_syscall): fix compile error.kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07random.c: fix failures on old Linuxnormal
This follows the behavior of fill_random_bytes_urandom and fixes the following failures I encountered on my old machine: 1) Error: TestSecureRandom#test_s_random_bytes_without_openssl: NotImplementedError: No random device $RUBYDIR/lib/securerandom.rb:66:in `gen_random' $RUBYDIR/lib/securerandom.rb:94:in `random_bytes' $RUBYDIR/test/test_securerandom.rb:12:in `test_s_random_bytes' $RUBYDIR/test/test_securerandom.rb:97:in `block in test_s_random_bytes_without_openssl' $RUBYDIR/lib/tmpdir.rb:88:in `mktmpdir' $RUBYDIR/test/test_securerandom.rb:85:in `test_s_random_bytes_without_openssl' 2) Error: TestSecureRandom#test_s_urlsafe_base64: NotImplementedError: No random device $RUBYDIR/lib/securerandom.rb:66:in `gen_random' $RUBYDIR/lib/securerandom.rb:94:in `random_bytes' $RUBYDIR/lib/securerandom.rb:164:in `urlsafe_base64' $RUBYDIR/test/test_securerandom.rb:131:in `block in test_s_urlsafe_base64' $RUBYDIR/test/test_securerandom.rb:130:in `times' $RUBYDIR/test/test_securerandom.rb:130:in `test_s_urlsafe_base64' 3) Error: TestSecureRandom#test_uuid: NotImplementedError: No random device $RUBYDIR/lib/securerandom.rb:66:in `gen_random' $RUBYDIR/lib/securerandom.rb:94:in `random_bytes' $RUBYDIR/lib/securerandom.rb:230:in `uuid' $RUBYDIR/test/test_securerandom.rb:160:in `test_uuid' * random.c (fill_random_bytes_syscall): return -1 for error * random.c (fill_random_bytes): try urandom on syscall failure git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07random.c: try getrandomnobu
* random.c (fill_random_bytes_syscall): try getrandom system call on Linux if supported by the kernel. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07random.c: separate fill_random_bytesnobu
* random.c (fill_random_bytes): separate into functions by system call and by direct read of urandom device. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-25random.c: refactornobu
* random.c (fill_random_bytes): separate non-raced and raced conditions, on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-19random.c: fix handle to releasenobu
* random.c (fill_random_bytes): release the handle in the static variable, not a local variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-16ruby.h: suppress false warningsnobu
* include/ruby/ruby.h (rb_data_object_alloc_warning): enable only if __builtin_choose_expr works with __builtin_constant_p so that warnings will be suppressed if klass is 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-16ruby.h: suppress false warningsnobu
* include/ruby/ruby.h (rb_data_object_alloc_warning): enable only if __builtin_choose_expr works with __builtin_constant_p so that warnings will be suppressed if klass is 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-04* random.c (random_raw_seed): Avoid calling fill_random_bytes()odaira
if the requested size is 0. AIX returns -1 for 0-byte read from /dev/urandom, while other UNIX returns 0. With this change, Random.raw_seed(0) consistently retuns "" in any UNIX. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-15random.c: suppress a warningnobu
* random.c (fill_random_bytes): use ATOMIC_SIZE_CAS to suppress a strict-aliasing warning by gcc 4.9 for mingw. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-14random.c: ArgumentError for invalid argumentnobu
* random.c (rand_random_number): raise ArgumentError for invalid argument like as SecureRandom.random_number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-14random.c: allow negative argument to random_numbernobu
* random.c (rand_random_number): allow negative argument as it is allowed by SecureRandom.random_number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-14random.c: rand_random_numbernobu
* random.c (rand_random_number): add a method to return a random number like SecureRandom to Random::Formatter. * lib/securerandom.rb (random_bytes): move to Random::Formatter, the base method of the module. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-14random.c: use PRIsVALUEnobu
* random.c (rand_random): use PRIsVALUE to format an error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-14random.c: Random.raw_seednobu
* random.c (random_raw_seed): extract platform dependent random seed initialization function as a new method Random.raw_seed. * lib/securerandom.rb (SecureRandom): use Random.raw_seed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01use 0 for reservednobu
use 0 for rb_data_type_t::reserved instead of NULL, since its type may be changed in the future and possibly not a pointer type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15* internal.h: Include ruby.h and ruby/encoding.h to beakr
includable without prior inclusion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-09random.c: fix castsnobu
* random.c (fill_random_seed): fix type to cast. this may or may not suppress warnings by icc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-03Init functions don't need ID cachesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-15* internal.h: Rename macro names: RBIGNUM_FOO to BIGNUM_FOO.akr
(BIGNUM_EMBED_LEN_NUMBITS): Renamed from RBIGNUM_EMBED_LEN_NUMBITS. (BIGNUM_EMBED_LEN_MAX): Renamed from RBIGNUM_EMBED_LEN_MAX. (BIGNUM_SIGN_BIT): Renamed from RBIGNUM_SIGN_BIT. (BIGNUM_SIGN): Renamed from RBIGNUM_SIGN. (BIGNUM_SET_SIGN): Renamed from RBIGNUM_SET_SIGN. (BIGNUM_POSITIVE_P): Renamed from RBIGNUM_POSITIVE_P. (BIGNUM_NEGATIVE_P): Renamed from RBIGNUM_NEGATIVE_P. (BIGNUM_EMBED_FLAG): Renamed from RBIGNUM_EMBED_FLAG. (BIGNUM_EMBED_LEN_MASK): Renamed from RBIGNUM_EMBED_LEN_MASK. (BIGNUM_EMBED_LEN_SHIFT): Renamed from RBIGNUM_EMBED_LEN_SHIFT. (BIGNUM_LEN): Renamed from RBIGNUM_LEN. (RBIGNUM_DIGITS): Renamed from RBIGNUM_DIGITS. (BIGNUM_LENINT): Renamed from RBIGNUM_LENINT. * bignum.c: Follow the above change. * gc.c: Ditto. * marshal.c: Ditto. * math.c: Ditto. * numeric.c: Ditto. * random.c: Ditto. * rational.c: Ditto. * sprintf.c: Ditto. * ext/-test-/bignum/bigzero.c: Ditto. * ext/-test-/bignum/intpack.c: Ditto. * ext/bigdecimal/bigdecimal.c: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-20* random.c (rand_init): Make it possible to specify arbitrary arrayakr
for init_genrand(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29* add RUBY_TYPED_FREE_IMMEDIATELY to data types which only useko1
safe functions during garbage collection such as xfree(). On default, T_DATA objects are freed at same points as fianlizers. This approach protects issues such as reported by [ruby-dev:35578]. However, freeing T_DATA objects immediately helps heap usage. Most of T_DATA (in other words, most of dfree functions) are safe. However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default for safety. * cont.c: ditto. * dir.c: ditto. * encoding.c: ditto. * enumerator.c: ditto. * error.c: ditto. * file.c: ditto. * gc.c: ditto. * io.c: ditto. * iseq.c: ditto. * marshal.c: ditto. * parse.y: ditto. * proc.c: ditto. * process.c: ditto. * random.c: ditto. * thread.c: ditto. * time.c: ditto. * transcode.c: ditto. * variable.c: ditto. * vm.c: ditto. * vm_backtrace.c: ditto. * vm_trace.c: ditto. * ext/bigdecimal/bigdecimal.c: ditto. * ext/objspace/objspace.c: ditto. * ext/stringio/stringio.c: ditto. * ext/strscan/strscan.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-02* random.c (make_seed_value): a local array declaration was accessedmame
out of scope. Coverity Scan found this bug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-25* include/ruby/ruby.h: rename RARRAY_RAWPTR() to RARRAY_CONST_PTR().ko1
RARRAY_RAWPTR(ary) returns (const VALUE *) type pointer and usecase of this macro is not acquire raw pointer, but acquire read-only pointer. So we rename to better name. RSTRUCT_RAWPTR() is also renamed to RSTRUCT_CONST_PTR() (I expect that nobody use it). * array.c, compile.c, cont.c, enumerator.c, gc.c, proc.c, random.c, string.c, struct.c, thread.c, vm_eval.c, vm_insnhelper.c: catch up this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13random.c: coerce before check negativenobu
* random.c (rb_random_ulong_limited): coerce before check negative. [Fixes GH-379] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-07* random.c (random_load): use RARRAY_RAWPTR() instead ofko1
RARRAY_PTR() because there is no new reference. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentErrorshugo
when $SAFE is set to 4. $SAFE=4 is now obsolete. [ruby-core:55222] [Feature #8468] * object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust): Kernel#untrusted?, untrust, and trust are now deprecated. Their behavior is same as tainted?, taint, and untaint, respectively. * include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED() and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(), respectively. * array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c, ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c, ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c, ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c, ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c, ext/socket/socket.c, ext/socket/udpsocket.c, ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c, ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c, load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c, safe.c, string.c, thread.c, transcode.c, variable.c, vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for $SAFE=4. * test/dl/test_dl2.rb, test/erb/test_erb.rb, test/readline/test_readline.rb, test/readline/test_readline_history.rb, test/ruby/test_alias.rb, test/ruby/test_array.rb, test/ruby/test_dir.rb, test/ruby/test_encoding.rb, test/ruby/test_env.rb, test/ruby/test_eval.rb, test/ruby/test_exception.rb, test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb, test/ruby/test_io.rb, test/ruby/test_method.rb, test/ruby/test_module.rb, test/ruby/test_object.rb, test/ruby/test_pack.rb, test/ruby/test_rand.rb, test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb, test/ruby/test_struct.rb, test/ruby/test_thread.rb, test/ruby/test_time.rb: remove tests for $SAFE=4. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11* random.c (rand_int): Use rb_big_uminus.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11* internal.h (INTEGER_PACK_NEGATIVE): Defined.akr
(rb_integer_unpack): sign argument removed. * bignum.c (rb_integer_unpack): sign argument removed. Non-negative integers generated by default. INTEGER_PACK_NEGATIVE flag is used to generate non-positive integers. * pack.c (pack_unpack): Follow the above change. * random.c (int_pair_to_real_inclusive): Ditto. (make_seed_value): Ditto. (mt_state): Ditto. (limited_big_rand): Ditto. * marshal.c (r_object0): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-10* bignum.c (rb_integer_pack): Returns sign instead of words.akr
(absint_numwords_generic): Follow the above change. (big2str_base_powerof2): Follow the above change. * internal.h: Ditto. * hash.c (rb_hash): Ditto. * pack.c (pack_pack): Ditto. * random.c (int_pair_to_real_inclusive): Ditto. (rand_init): Ditto. (random_load): Ditto. (limited_big_rand): Ditto. * time.c (v2w_bignum): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-09* bignum.c (rb_absint_numwords): Renamed from rb_absint_size_in_word.akr
* internal.h (rb_absint_numwords): Follow the above change. * pack.c (pack_pack): Ditto. * random.c (rand_init): Ditto. (limited_big_rand): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e