aboutsummaryrefslogtreecommitdiffstats
path: root/random.c
Commit message (Collapse)AuthorAgeFilesLines
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Fixed constant initializerNobuyoshi Nakada2020-05-041-1/+1
| | | | | An expression using `static const` value seems not considered as `static const` by Visual C.
* Make int-pair-to-real conversion more portableNobuyoshi Nakada2020-05-041-5/+16
| | | | And utilize more bits even if DBL_MANT_DIG > 53.
* Disable deprecation error on mingwNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-2/+1
| | | Split ruby.h
* Ensure seed data to be clearedNobuyoshi Nakada2020-01-101-23/+14
| | | | To prevent from leaking the seed data.
* Fill siphash salt directly with random dataNobuyoshi Nakada2020-01-101-0/+6
| | | | | Expanding less random data with MT is not needed when it succeeded.
* Renamed `init_seed` as `init_hash_salt` tooNobuyoshi Nakada2020-01-091-2/+2
|
* Renamed `seed` as `hash_salt`Nobuyoshi Nakada2020-01-091-8/+8
| | | | | The role of this is a so-called "salt" but not "seed", rename to get rid of confusion with other "seed" of PRNG.
* Also clear MT to initialize the siphash seedNobuyoshi Nakada2020-01-091-0/+1
|
* decouple internal.h headers卜部昌平2019-12-261-18/+32
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* add several __has_something macro卜部昌平2019-12-261-1/+1
| | | | | | | With these macros implemented we can write codes just like we can assume the compiler being clang. MSC_VERSION_SINCE is defined to implement those macros, but turned out to be handy for other places. The -fdeclspec compiler flag is necessary for clang to properly handle __has_declspec().
* rand(beginless_range) raise Errno::EDOM instead of TypeErrorKazuhiro NISHIYAMA2019-12-151-2/+4
| | | | | | | | | | | | | | | | | | | | | same as `rand(endless_range)` Before: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 2: from -e:1:in `<main>' 1: from -e:1:in `rand' -e:1:in `-': nil can't be coerced into Integer (TypeError) ``` After: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 1: from -e:1:in `<main>' -e:1:in `rand': Numerical argument out of domain (Errno::EDOM) ```
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-2/+2
|
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-5/+5
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* * expand tabs.git2019-06-041-1/+1
|
* random_mt_typeNobuyoshi Nakada2019-06-041-8/+8
| | | | | * random.c: renamed random_data_type as random_mt_type, and append "MT" to `wrap_struct_name`, respecting the implementation.
* random.c: unify syscall with getrandomnobu2019-02-101-34/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-02-101-15/+15
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: use getrandom() if available.glass2019-02-101-0/+26
| | | | | | getrandom() is supported by glibc 2.25 or later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Split mt19937.cnobu2019-02-071-158/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix Random.urandom in a chroot on OpenBSDnobu2019-01-031-0/+5
| | | | | | | | [ruby-core:90850] [Bug #15494] From: jeremyevans0 (Jeremy Evans) <merch-redmine@jeremyevans.net> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* suppress integer overflow warningsshyouhei2018-11-131-0/+1
| | | | | | | | | | | | | * random.c: annotate rb_hash_start with NO_SANITIZE (seed.key.hash + h overflows and that seems intentional) * bignum.c: avoid (size_t)-- * cont.c: ditto * util.c: ditto * vm_insnhelper.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* blacklist UBSAN's unsigned integer overflowshyouhei2018-11-071-0/+3
| | | | | | | | | | | | Integer overflow for unsigned types are fully defined in C. They are not always problematic (but not always OK). These functions in this changeset intentionally utilizes that behaviour. Blacklist from UBSAN checks for better output. See also: https://travis-ci.org/ruby/ruby/jobs/451624829 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2018-10-301-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko12018-10-301-5/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: prefixed fill_random_bytesnobu2018-09-111-1/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add new instruction attribute called leafshyouhei2018-09-111-1/+1
| | | | | | | | | | | An instruction is leaf if it has no rb_funcall inside. In order to check this property, we introduce stack canary which is a random number collected at runtime. Stack top is always filled with this number and checked for stack smashing operations, when VM_CHECK_MODE. [GH-1947] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fix up r64596nobu2018-09-041-1/+1
| | | | | | | * random.c (fill_random_bytes_syscall): check if the version macro is defined, for very old Mac OS X development tools. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* avoid fork-unsafe arc4random implementationsshyouhei2018-09-041-0/+6
| | | | | | | | | | | Some old implementaions of arc4random_buf(3) were ARC4 based, or unsafe when forked, or both. Resort to /dev/urandom for those known problematic cases. Fix [Bug #15039] Patch from Thomas Hurst <tom@hur.st> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: SecRandomCopyBytesnobu2018-08-311-0/+20
| | | | | | | * random.c (fill_random_bytes_syscall): use SecRandomCopyBytes in Security framework on macOS 10.7 or later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fix fallback valuenobu2018-08-031-4/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: use rb_check_funcallnobu2018-08-031-2/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: moved domain errornobu2018-08-031-1/+2
| | | | | | | * random.c (rand_range): moved call of domain_error(), not to raise an exception in range_values(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: endless range randomnobu2018-08-031-1/+2
| | | | | | | * random.c (range_values): cannot determine the domain of an endless range. [ruby-core:88261] [Bug #14958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* prefer clock_gettimenobu2018-06-141-0/+9
| | | | | | | | | | | * configure.ac: clock_gettime or gettimeofday must exist. * process.c (rb_clock_gettime): prefer clock_gettime over gettimeofday, as the latter is obsolete in SUSv4. * random.c (fill_random_seed): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fix need_secure flagsnobu2018-06-101-2/+2
| | | | | | | | | | | * random.c (fill_random_seed): do not need to be secure, to get rid of blocking at the start-up time. [ruby-core:87462] [Bug #14837] * random.c (random_raw_seed): expected to be a cryptographically secure, as documented. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: improve docs for Random.bytesstomar2018-04-141-4/+4
| | | | | | | * random.c: [DOC] improve language and RDoc markup in Random.bytes docs; also adjust call-seq style of Random.bytes and Random#bytes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: Random.extend Formatternobu2018-02-271-0/+1
| | | | | | | | * random.c (InitVM_Random): extend Random itself by Formatter module, as well as the `bytes` method used by the module. [Feature #4938] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] missing docs at toplevelnobu2018-02-231-0/+13
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: Random.bytesnobu2018-02-201-0/+14
| | | | | | | * random.c (random_s_bytes): new method Random.bytes, which is equivalent to Random::DEFAULT.bytes. [Feature #4938] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix typos.hsbt2018-01-171-2/+2
| | | | | | | | * node.c: strucutre -> structure * random.c: acquried -> acquired * thread.c: accross -> across git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: make sure that Random.urandom returns required-length buffermame2017-12-161-9/+20
| | | | | | | | getrandom(2) and read(2) (from /dev/urandom) may return a random buffer whose length is shorter than required. This change makes sure that they get enough buffer by using a loop. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Random.urandom raises RuntimeError instead of returning nilkazu2017-09-131-1/+1
| | | | | | [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Random.urandom raises an exception instead of returning nil when failedmame2017-09-121-1/+2
| | | | | | Early failure looks better in this case. Refs [Bugs #13885]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a note to Random.urandommame2017-09-091-1/+3
| | | | | | The method may return nil for some reasons. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: ensure initializednobu2017-07-191-2/+2
| | | | | | | * random.c (get_rnd, try_get_rnd): ensure initialized to get rid of crash in forked processes. [ruby-core:82100] [Bug #13753] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* SecureRandom should try /dev/urandom first [Bug #9569]shyouhei2017-01-201-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* switch SipHash from SipHash24 to SipHash13 variantshyouhei2017-01-201-2/+2
| | | | | | | | | | | | | | | | | | | SipHash13 is secure enough to be used in hash-tables, and SipHash's author confirms that. Rust already considered switch to SipHash13: https://github.com/rust-lang/rust/issues/29754#issue-116174313 Jean-Philippe Aumasson confirmation: https://github.com/rust-lang/rust/issues/29754#issuecomment-156073946 Merged pull request: https://github.com/rust-lang/rust/pull/33940 From: Sokolov Yura aka funny_falcon <funny.falcon@gmail.com> Date: Thu, 8 Dec 2016 20:31:29 +0300 Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> Fixes: [Feature #13017] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e