Граф коммитов

345 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 5a75151a01
[DOC] Mark up the code for Kernel#rand as the same as Random#rand 2022-01-13 11:34:09 +09:00
Nobuyoshi Nakada fae0b66431 Remove deprecated Random::DEFAULT [Feature #17351] 2022-01-01 18:55:52 +09:00
Chris AtLee 1dd10e1892
[DOC] Add documentation for Random.rand and Random.seed 2021-12-20 00:50:46 +09:00
Nobuyoshi Nakada cf54de637c
[DOC] random number by range 2021-12-16 18:00:23 +09:00
Nobuyoshi Nakada 446a11f2c1
[DOC] Add call sequences of Random using a range 2021-12-13 19:56:11 +09:00
Nobuyoshi Nakada dc490aced3
[DOC] Improve Random::Formatter description and example 2021-12-13 19:55:44 +09:00
Nobuyoshi Nakada bcc2bb28b0 Fix stack buffer overflow
https://hackerone.com/reports/1306859
2021-12-10 01:04:59 +09:00
Nobuyoshi Nakada 66b0847602
Check the reading size range 2021-11-06 17:39:37 +09:00
Kazuki Yamaguchi 9541b3b7c0 random.c: simplify Random object deallocation
This is a follow-up for commit 265c002239 ("Do not allocate
ractor-local storage in dfree function during GC", 2021-02-09).

The comparison with the default rb_random_mt_t is useless in the first
place, since it is never equal: no actual Random object is associated
with it.

[Bug #17653] https://bugs.ruby-lang.org/issues/17653
2021-10-27 15:44:27 +09:00
Nobuyoshi Nakada e0ef4899f3 [Win32] Prefer Cryptography Next Generation API
[BCryptGenRandom] is available since Windows Vista / Windows
Server 2008.

Regarding [CryptGenRandom]:
> This API is deprecated. New and existing software should start
> using Cryptography Next Generation APIs. Microsoft may remove
> this API in future releases.

[BCryptGenRandom]: https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
[CryptGenRandom]: https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom
2021-10-02 21:22:33 +09:00
Nobuyoshi Nakada 0eb679f70c
HCRYPTPROV is not a HANDLE
Even though it is called "handle" and prefixed with "H", and its
value looks like a handle.
2021-09-24 12:12:38 +09:00
S-H-GAMELINKS 83a5e2bb5c Using RB_FLOAT_TYPE_P macro 2021-09-12 11:16:31 +09:00
Nobuyoshi Nakada 04be8e84db
Use C99-defined macros to classify a floating-point number 2021-08-27 12:41:30 +09:00
David Carlier 8d2af51a78 netbsd coroutine uses assembly instead and little build fix. 2021-08-24 10:52:04 +09:00
卜部昌平 0fbdaaf7c9 rand_bytes: prefer rng->get_bytes
Because why not.  There was no use case of rng->get_bytes before this
changeset.
2021-06-24 12:48:17 +09:00
Peter Zhu 3d2e7e2ab5 Fix compilation errors in FreeBSD
__FreeBSD_version is defined in sys/param.h.
2021-05-04 20:38:03 -04:00
Benoit Daloze 0764d323d8 Fix -Wundef warnings for patterns `#if HAVE`
* See [Feature #17752]
* Using this to detect them:
  git grep -P 'if\s+HAVE' | grep -Pv 'HAVE_LONG_LONG|/ChangeLog|HAVE_TYPEOF'
2021-05-04 14:56:55 +02:00
Nobuyoshi Nakada 9e71f1aa4c
Include CommonCrypto/CommonCryptoError.h for old Xcode 2021-03-19 18:56:41 +09:00
Nobuyoshi Nakada 4ea96f1d4f
Use CommonRandom if available 2021-03-19 15:23:03 +09:00
Nobuyoshi Nakada bf089d786a
Fixed syntax error with gcc on macOS
Security/Authorization.h defines AuthorizationExternalForm by
using clang extension which allows variably modified types in a
file scope.  As we just need high-level accessors only, include
Security/SecRandom.h instead.
2021-03-04 11:28:39 +09:00
Nobuyoshi Nakada 265c002239
Do not allocate ractor-local storage in dfree function during GC 2021-02-09 01:00:00 +09:00
Kazuhiro NISHIYAMA 6abf393e8f
OpenBSD has getentropy, but no sys/random.h
https://man.openbsd.org/getentropy

Try to fix https://rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20210118T023008Z.fail.html.gz
```
compiling random.c
random.c:53:11: fatal error: 'sys/random.h' file not found
# include <sys/random.h>
          ^~~~~~~~~~~~~~
1 error generated.
```
2021-01-18 12:43:05 +09:00
David CARLIER 54c91185c9 random generator update for Mac proposal
using getentropy for seeding, reading 256 bytes at a time to avoid
 the EIO errno since this is the maximum.
2021-01-17 18:48:48 +09:00
Nobuyoshi Nakada e033c9d7db
Include missing AvailabilityMacros.h 2021-01-17 18:28:20 +09:00
Nobuyoshi Nakada c63552eab1
Remove possibility of using same seeds 2021-01-10 21:29:07 +09:00
zverok 861dbd9506 Random instance methods 2020-12-21 19:22:38 -05:00
Benoit Daloze f5c89c1660 Deprecate Random::DEFAULT
* Closes [Feature #17351].
2020-12-14 20:29:50 +01:00
Benoit Daloze c183288754 Remove references to Random::DEFAULT in the documentation
* Random::DEFAULT is no longer a Random instance, and referencing it is
  more confusing than helpful. Related to [Feature #17351]
2020-12-14 20:13:48 +01:00
Koichi Sasada 67693d8d80 ractor local storage C-API
To manage ractor-local data for C extension, the following APIs
are defined.

* rb_ractor_local_storage_value_newkey
* rb_ractor_local_storage_value
* rb_ractor_local_storage_value_set
* rb_ractor_local_storage_ptr_newkey
* rb_ractor_local_storage_ptr
* rb_ractor_local_storage_ptr_set

At first, you need to create a key of storage by
rb_ractor_local_(value|ptr)_newkey().
For ptr storage, it accepts the type of storage,
how to mark and how to free with ractor's lifetime.

rb_ractor_local_storage_value/set are used to access a VALUE
and rb_ractor_local_storage_ptr/set are used to access a pointer.

random.c uses this API.
2020-12-01 09:39:30 +09:00
Nobuyoshi Nakada 039ba387aa
Use opaque struct pointer than void 2020-11-27 21:38:08 +09:00
Koichi Sasada 5496415d31 mark default_rand
default_rand can points a Bignum seed, so it should be marked.
2020-11-27 17:36:02 +09:00
Koichi Sasada 2db2fb9f6c per-ractor Random::DEFAULT
Random generators are not Ractor-safe, so we need to prepare
per-ractor default random genearators. This patch set
`Random::DEFAULT = Randm` (not a Random instance, but the Random
class) and singleton methods like `Random.rand()` use a per-ractor
random generator.

[Feature #17322]
2020-11-27 17:03:30 +09:00
Nobuyoshi Nakada eca854041f
[DOC] Mersenne Twister isn't cryptographically secure [ci skip] 2020-11-27 12:47:31 +09:00
Nobuyoshi Nakada 9ee99fbd8a
rb_const_set sets the class path now 2020-10-09 12:03:52 +09:00
Nobuyoshi Nakada 2b07b24bdf Added `rb_random_base_init`
To enclose the initialization of Random::Base part.
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada 4924011262 Added WITH_REAL macros
Added `WITH_REAL` versions to `RB_RANDOM_INTERFACE` macros.  Also
these macros including "without real" versions no longer contain
the terminator (semicolon and comma).
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada d6ec0ef59b Added `get_real` interface 2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada c449b9b02f Added rb_int_pair_to_real 2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada af5e87ab21 separate rb_random_t
* random.c: separate abstract rb_random_t and rb_random_mt_t for
  Mersenne Twister implementation.

* include/ruby/random.h: the interface for extensions of Random
  class.

* DLL imported symbol reference is not constant on Windows.

* check if properly initialized.
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada f4d5273989 Random::Base
* random.c (InitVM_Random): introduce abstract super class
  Random::Base.
2020-09-07 20:08:01 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons.  We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
2020-08-15 12:09:26 +09:00
卜部昌平 cc27cd26d7 rand_range: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 41e547e60c
Fixed constant initializer
An expression using `static const` value seems not considered as
`static const` by Visual C.
2020-05-04 00:27:14 +09:00
Nobuyoshi Nakada 5b28f01d77
Make int-pair-to-real conversion more portable
And utilize more bits even if DBL_MANT_DIG > 53.
2020-05-04 00:00:27 +09:00
Nobuyoshi Nakada e7128aa772
Disable deprecation error on mingw 2020-04-08 22:41:34 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 0a67c21401 Ensure seed data to be cleared
To prevent from leaking the seed data.
2020-01-10 10:28:49 +09:00
Nobuyoshi Nakada 499de0a0f6 Fill siphash salt directly with random data
Expanding less random data with MT is not needed when it
succeeded.
2020-01-10 10:28:49 +09:00