aboutsummaryrefslogtreecommitdiffstats
path: root/random.c
Commit message (Collapse)AuthorAgeFilesLines
* random.c: pack hash seedsnobu2016-12-061-30/+14
| | | | | | | * random.c (seed_keys_t, init_seed): pack seed for rb_hash_start and rb_memhash, and fill them at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: private randnobu2016-12-051-1/+1
| | | | | | | * random.c (rb_random_ulong_limited): do not call private method rand. [ruby-dev:49892] [Misc #13003] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rb_funcallvnobu2016-07-291-4/+4
| | | | | | | * *.c: rename rb_funcall2 to rb_funcallv, except for extensions which are/will be/may be gems. [Fix GH-1406] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_ulong_limited): avoid left shift count >= width ofnaruse2016-07-041-2/+0
| | | | | | type on 32bit environment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* VC6 errornobu2016-06-291-1/+1
| | | | | | | | * random.c (int_pair_to_real_inclusive): get rid of VC6 compile error C2520: conversion from unsigned __int64 to double not implemented. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: suppress a warningnobu2016-05-151-1/+5
| | | | | | | * random.c (random_ulong_limited): suppress a shift count warning when unsigned long is 32bits. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: clear seednobu2016-05-141-0/+1
| | | | | | * random.c (rand_init): clear packed seed value explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: no local copy of the seednobu2016-05-131-15/+7
| | | | | | | * random.c (make_seed_value): append leading-zero-guard and get rid of making a local copy of the seed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fill_random_seed sizenobu2016-05-131-6/+7
| | | | | | * random.c (fill_random_seed): move the seed size to an argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: clear bufnobu2016-05-131-1/+4
| | | | | | * random.c (random_seed): clear temporary buffer explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: reuse bitsnobu2016-05-101-2/+14
| | | | | | | * random.c (random_ulong_limited): reduce calling bytes methods by reusing dropped bits. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: use bytesnobu2016-05-101-29/+58
| | | | | | | * random.c (obj_random_bytes): base on bytes method instead of rand method, not to call toplevel rand method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: compare by rb_equalnobu2016-05-091-2/+1
| | | | | | * random.c (random_equal): compare seeds by rb_equal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: consitifynobu2016-05-091-1/+1
| | | | | | * random.c (init_by_array): consitify initializing keys. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: seed conversionnobu2016-05-091-3/+2
| | | | | | | | | | * random.c (rand_init): random_seed() always returns an Integer, no conversion for it. * random.c (random_init, rb_f_srand): convert the given seed to an Integer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: optimize int_pair_to_real_inclusivenobu2016-05-071-32/+14
| | | | | | | * random.c (int_pair_to_real_inclusive): optimize to multiply without Bignum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: split random_int32nobu2016-05-071-10/+25
| | | | | | | * random.c (random_int32): split the cases of rb_random_t and other objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: unnecessary declarationsnobu2016-05-071-2/+0
| | | | | | | | * random.c (random_ulong_limited, random_ulong_limited_big): remove unnecessary extern declarations. rb_num_negative_p is declared in internal.h now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fill_random_bytes_syscall functionnobu2016-05-061-1/+6
| | | | | | | | * random.c (fill_random_bytes_syscall): turned into a static function, to be inlined probably, so that it is unavailable if it is a preprocessor macro. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: refactornobu2016-05-061-42/+24
| | | | | | | * random.c (rand_random, rb_f_rand): refactor, split condition expressions, and return in the precedence. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: use rb_check_to_intnobu2016-05-061-2/+2
| | | | | | | * random.c (rand_range, rand_random): use rb_check_to_int instead of rb_check_to_integer with the same conversion method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: prefer rb_check_aritynobu2016-05-061-6/+6
| | | | | | | * 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
* random.c: sipseed_keys_tnobu2016-05-061-2/+3
| | | | | | | * 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
* random.c: default seed marknobu2016-05-061-5/+2
| | | | | | | | | * 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
* random.c: return value is not GCednobu2016-05-061-3/+2
| | | | | | | * 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
* random.c: use uint32_tnobu2016-05-051-5/+5
| | | | | | | | | | * 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
* random.c: use arc4random_bufnobu2016-05-051-1/+4
| | | | | | | * 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
* * cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4usa2016-05-011-5/+0
| | | | | | | | 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
* * random.c (limited_rand): Add a specialized path for the limit fits in 32 bit.akr2016-02-241-9/+19
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * *.c (*_memsize): do not check ptr.ko12015-12-091-1/+1
| | | | | | | | | | 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
* random.c: fix filling sizenobu2015-12-051-1/+1
| | | | | | | * 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
* explicit_bzero.c: needs windows.hnobu2015-12-011-0/+1
| | | | | | | * 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
* * random.c (InitVM_Random): move Random::DEFAULT initializationkosaki2015-11-301-7/+12
| | | | | | | | 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
* * random.c (Init_RandomSeed): move all Random::DEFAULTkosaki2015-11-301-29/+33
| | | | | | | | | | | | | 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
* * random.c (init_hashseed, init_siphash): extract initializekosaki2015-11-301-9/+24
| | | | | | functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (init_randomseed): remove "initial" argument. It neverkosaki2015-11-301-3/+4
| | | | | | be used from outside of this function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c: random_raw_seed don't use GRND_NONBLOCK. GRND_NONBLOCKkosaki2015-11-301-8/+11
| | | | | | | 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
* * missing/explicit_bzero.c: new file. define explicit_bzero.kosaki2015-11-301-1/+1
| | | | | | | | | | * 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
* random.c: comment [ci skip]nobu2015-10-181-3/+3
| | | | | | * 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
* Revert r52180kosaki2015-10-181-1/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (fill_random_bytes_urandom): add a comment why usingkosaki2015-10-181-0/+5
| | | | | | O_NONBLOCK and O_NOCTTY. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (fill_random_bytes_syscall): don't use GRND_NONBLOCK.kosaki2015-10-181-5/+1
| | | | | | | | 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
* * random.c (fill_random_bytes_syscall): use ATOMIC_SET() forkosaki2015-10-181-1/+1
| | | | | | updating try_syscall. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: get rid of blockingnobu2015-07-251-1/+7
| | | | | | | | * 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
* fix compile error with clangkazu2015-07-141-1/+1
| | | | | | | * 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
* * random.c (fill_random_bytes_syscall): fix compile error.kazu2015-07-071-5/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fix failures on old Linuxnormal2015-07-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* random.c: try getrandomnobu2015-07-071-1/+23
| | | | | | | * 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
* random.c: separate fill_random_bytesnobu2015-07-071-15/+32
| | | | | | | * 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
* random.c: refactornobu2015-06-251-7/+6
| | | | | | | * 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