summaryrefslogtreecommitdiff
path: root/random.c
AgeCommit message (Collapse)Author
2016-05-06random.c: prefer rb_check_aritynobu
* random.c: use rb_check_arity instead of rb_scan_args for simple optional arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06random.c: sipseed_keys_tnobu
* random.c (sipseed): separate type of keys to reduce use of the magic number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06random.c: default seed marknobu
* random.c (Init_Random_default): since seed is marked by random_mark, no needs to mark itself as a global variable. allocate Random instance before making the seed value, to get rid of the potential risk of GC during the allocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06random.c: return value is not GCednobu
* random.c (rand_init): since seed is the return value, no needs to be volatile to prevent from GC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-05random.c: use uint32_tnobu
* random.c (struct MT, next_state): use uint32_t for the state vector. * random.c (init_by_array, rand_init): ditto for initializing keys. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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