History log of /PHP-8.3/ext/random/random.c (Results 1 – 25 of 37)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 5c9c2757 13-Aug-2024 David Carlier

Checks getrandom availability on solaris.

To fix part of GH-15381.
gcc nor clang provides a constant to distinguish illumos and solaris
not the system provides a kernel version stamp

Checks getrandom availability on solaris.

To fix part of GH-15381.
gcc nor clang provides a constant to distinguish illumos and solaris
not the system provides a kernel version stamp like the BSD.
thus, we simply check the symbol and remaing purposely conservative in
the existing logic, using it only for solaris to avoid unexpected
breakages for other systems. would need a different fix for higher
branches.

Close GH-15390

show more ...


# f34721ca 13-Mar-2024 Tim Düsterhus

random: Initialize the `mode` field when seeding in `php_random_default_status()` (#13690)

This is not just an issue due to missing initialization since moving the state
struct directly

random: Initialize the `mode` field when seeding in `php_random_default_status()` (#13690)

This is not just an issue due to missing initialization since moving the state
struct directly into the module globals. In earlier versions changing the mode
to `MT_RAND_PHP` within a single request would also affect the mode for
subsequent requests.

Original commit message follows:

This is a follow-up fix for GH-13579. The issue was detected in the nightly
MSAN build.

(cherry picked from commit bf0abd1629291c193064a9cb95a2da3565decc38)

show more ...


# e059498c 29-Feb-2024 Tim Düsterhus

random: Fix unknown `mt_srand()` compatibility for unknown modes (#13544)

PHP 8.1 and below interpreted unknown modes as `MT_RAND_MT19937`, but PHP 8.2+
interprets them as `MT_RAND_PHP`.

random: Fix unknown `mt_srand()` compatibility for unknown modes (#13544)

PHP 8.1 and below interpreted unknown modes as `MT_RAND_MT19937`, but PHP 8.2+
interprets them as `MT_RAND_PHP`.

Align the behavior with PHP 8.1 and below, because folks should be steered
towards the standard mode.

show more ...


# 61251093 07-Jul-2023 Tim Düsterhus

Deprecate MT_RAND_PHP (#11560)

see https://wiki.php.net/rfc/deprecations_php_8_3#mt_rand_php


# b14dd85d 23-Feb-2023 Tim Düsterhus

random: Move the CSPRNG implementation into a separate C file (#10668)

The CSPRNG is a delicate and security relevant piece of code and having it in
the giant random.c makes it much hard

random: Move the CSPRNG implementation into a separate C file (#10668)

The CSPRNG is a delicate and security relevant piece of code and having it in
the giant random.c makes it much harder to verify changes to it. Split it into
a separate file.

show more ...


# 6c8ef1d9 25-Jan-2023 Tim Düsterhus

random: Reduce variable scopes in CSPRNG (#10426)

* random: Convert the urandom loop into a while() loop

This allows us to more easily reduce the scope of `n` in a future commit and

random: Reduce variable scopes in CSPRNG (#10426)

* random: Convert the urandom loop into a while() loop

This allows us to more easily reduce the scope of `n` in a future commit and
now matches the getrandom(2) loop.

* random: Move the errno reset immediately above the getrandom(2) call

* random: Reduce the scope of `n` in the CSPRNG

* random: Declare `n` outside of preprocessor branch

show more ...


# 2740920a 23-Jan-2023 David Carlier

random disable arc4random_buf for glibc, merge mistake


# 948cb470 15-Jan-2023 David Carlier

random netbsd 10 update finally supporting getrandom syscall properly.

Close GH-10327.


# a7998fda 23-Jan-2023 Tim Düsterhus

random: Simplify control flow for handling /dev/urandom errors (#10392)

The only way the previous `if (read_bytes < size)` branch could be taken is
when the loop was exited by the `break

random: Simplify control flow for handling /dev/urandom errors (#10392)

The only way the previous `if (read_bytes < size)` branch could be taken is
when the loop was exited by the `break;` statement. We can just merge this into
the loop to make the code more obvious.

show more ...


# 57b362b7 23-Jan-2023 Tim Düsterhus

random: Do not trust arc4random_buf() on glibc (#10390)

This effectively reverts #8984.

As discussed in #10327 which will enable the use of the getrandom(2) syscall on
NetBSD in

random: Do not trust arc4random_buf() on glibc (#10390)

This effectively reverts #8984.

As discussed in #10327 which will enable the use of the getrandom(2) syscall on
NetBSD instead of relying on the userland arc4random_buf(), the CSPRNG should
prioritize security over speed [1] and history has shown that userland
implementations unavoidably fall short on the security side. In fact the glibc
implementation is a thin wrapper around the syscall due to security concerns
and thus does not provide any benefit over just calling getrandom(2) ourselves.

Even without any performance optimizations the CSPRNG should be plenty fast for
the vast majority of applications, because they often only need a few bytes of
randomness to generate a session ID. If speed is desired, the OO API offers
faster, but non-cryptographically secure engines.

show more ...


# 2b395f7b 20-Jan-2023 Tim Düsterhus

random: Remove check for HAVE_DEV_URANDOM

It cannot be decided whether the device is available at build time, PHP might
run in a container or chroot that does not expose the device. Simp

random: Remove check for HAVE_DEV_URANDOM

It cannot be decided whether the device is available at build time, PHP might
run in a container or chroot that does not expose the device. Simply attempt to
open it, if it does not exist it will fail.

This improves readability of php_random_bytes() by removing one layer of
preprocessor conditions.

show more ...


# 1f05d6ef 20-Jan-2023 Máté Kocsis

Fix GH-10292 make the default value of the first parame of srand() and mt_srand() nullable (#10380)

Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>


# c8955c07 16-Jan-2023 Christoph M. Becker

Revert GH-10220

Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491d66081298a16634629f149459706a9.
This reverts commit 588a07

Revert GH-10220

Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491d66081298a16634629f149459706a9.
This reverts commit 588a07f7371ee2b5fac17de147926780e427fae6.
This reverts commit f377e15751d3aa48b69cd9bcc366ede7803d511f.
This reverts commit b4ba16fe189b109144aff669e11d81365160104b.
This reverts commit 694ec1deea36e366b28b6349a52be49824e1a1a8.
This reverts commit 6b34de8eba9f66882ae16e6073af28783670ac53.
This reverts commit aa1cd02a4367834026ea2205ea13a2f904455aa1.
This reverts commit 308fd311ea6fcf3094b448df7f2b264f08e4fe4f.
This reverts commit 16203b53e1822a37b6ba6f2ab198bb435d05fdad.
This reverts commit 738fb5ca5412f5e833a7fab82b11519e635a3357.
This reverts commit 9fdbefacd3c382d731aa175b7bdc002ec9cb2b30.
This reverts commit cd4a7c1d90562ebb5f89caf94d00d579631b9fbe.
This reverts commit 928685eba2b2f0ded90e7f78fd806ea164002f6e.
This reverts commit 01e5ffc85cd4357fd7b5b7ceefa29f2d10ca26b7.

show more ...


# e7c0f4e8 10-Jan-2023 Tim Düsterhus

random: Rely on `free(NULL)` being safe for random status freeing (#10246)

* random: Rely on `free(NULL)` being safe for random status freeing

* random: Restructure `php_random_stat

random: Rely on `free(NULL)` being safe for random status freeing (#10246)

* random: Rely on `free(NULL)` being safe for random status freeing

* random: Restructure `php_random_status_free()` to not early-return

show more ...


# 308fd311 04-Jan-2023 Max Kellermann

ext/{standard,json,random,...}: add missing includes


# 32f503e4 07-Jan-2023 Tim Düsterhus

random: Fix check before closing `random_fd` (#10247)

If, for whatever reason, the random_fd has been assigned file descriptor `0` it
previously failed to close during module shutdown, t

random: Fix check before closing `random_fd` (#10247)

If, for whatever reason, the random_fd has been assigned file descriptor `0` it
previously failed to close during module shutdown, thus leaking the descriptor.

show more ...


# f9a1a903 14-Dec-2022 Tim Düsterhus

Add Randomizer::nextFloat() and Randomizer::getFloat() (#9679)

* random: Add Randomizer::nextFloat()

* random: Check that doubles are IEEE-754 in Randomizer::nextFloat()

*

Add Randomizer::nextFloat() and Randomizer::getFloat() (#9679)

* random: Add Randomizer::nextFloat()

* random: Check that doubles are IEEE-754 in Randomizer::nextFloat()

* random: Add Randomizer::nextFloat() tests

* random: Add Randomizer::getFloat() implementing the y-section algorithm

The algorithm is published in:

Drawing Random Floating-Point Numbers from an Interval. Frédéric
Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022.
https://doi.org/10.1145/3503512

* random: Implement getFloat_gamma() optimization

see https://github.com/php/php-src/pull/9679/files#r994668327

* random: Add Random\IntervalBoundary

* random: Split the implementation of γ-section into its own file

* random: Add tests for Randomizer::getFloat()

* random: Fix γ-section for 32-bit systems

* random: Replace check for __STDC_IEC_559__ by compile-time check for DBL_MANT_DIG

* random: Drop nextFloat_spacing.phpt

* random: Optimize Randomizer::getFloat() implementation

* random: Reject non-finite parameters in Randomizer::getFloat()

* random: Add NEWS/UPGRADING for Randomizer’s float functionality

show more ...


# ac3ecd03 09-Dec-2022 Joshua Rüsweg

Add `Randomizer::getBytesFromString()` method (#9664)

* Add `Randomizer::getBytesFromAlphabet()` method

* Rename `getBytesFromAlphabet` to `getBytesFromString`

* [ci skip]

Add `Randomizer::getBytesFromString()` method (#9664)

* Add `Randomizer::getBytesFromAlphabet()` method

* Rename `getBytesFromAlphabet` to `getBytesFromString`

* [ci skip] Add NEWS/UPGRADING for Randomizer::getBytesFromString()

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>

show more ...


# 7f0b228f 28-Oct-2022 Tim Düsterhus

Fix pre-PHP 8.2 compatibility for php_mt_rand_range() with MT_RAND_PHP (#9839)

* Fix pre-PHP 8.2 compatibility for php_mt_rand_range() with MT_RAND_PHP

As some left-over comments in

Fix pre-PHP 8.2 compatibility for php_mt_rand_range() with MT_RAND_PHP (#9839)

* Fix pre-PHP 8.2 compatibility for php_mt_rand_range() with MT_RAND_PHP

As some left-over comments indicated:

> Legacy mode deliberately not inside php_mt_rand_range()
> to prevent other functions being affected

The broken scaler was only used for `php_mt_rand_common()`, not
`php_mt_rand_range()`. The former is only used for `mt_rand()`, whereas the
latter is used for `array_rand()` and others.

With the refactoring for the introduction of ext/random `php_mt_rand_common()`
and `php_mt_rand_range()` were accidentally unified, thus introducing a
behavioral change that was reported in FakerPHP/Faker#528.

This commit moves the checks for `MT_RAND_PHP` from the general-purpose
`range()` function back into `php_mt_rand_common()` and also into
`Randomizer::getInt()` for drop-in compatibility with `mt_rand()`.

* [ci skip] NEWS for `MT_RAND_PHP` compatibility

show more ...


# 59a19d71 06-Oct-2022 Tim Düsterhus

Reduce scope of `r` in rand_rangeXX (#9678)

This variable is only accessed within a single iteration of the expansion loop.


# 28a4d767 19-Sep-2022 Remi Collet

declare random globals as public API


# a01dd9fe 14-Sep-2022 Bob Weinand

Revert "Port all internally used classes to use default_object_handlers"

This reverts commit 94ee4f9834743ca74f6c9653863273277ce6c61a.

The commit was a bit too late to be included i

Revert "Port all internally used classes to use default_object_handlers"

This reverts commit 94ee4f9834743ca74f6c9653863273277ce6c61a.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.

show more ...


Revision tags: php-8.2.0RC1, php-8.1.10, php-8.0.23
# 94ee4f98 24-Aug-2022 Bob Weinand

Port all internally used classes to use default_object_handlers

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>


# cbb024cb 25-Aug-2022 Tim Düsterhus

Select `rand_rangeXX()` variant only based on the requested range (#9418)

This fixes an incompatibility when wrapping native 32-bit engines with a userland
engine. The latter always used

Select `rand_rangeXX()` variant only based on the requested range (#9418)

This fixes an incompatibility when wrapping native 32-bit engines with a userland
engine. The latter always used the 64-bit range function which then used two
32-bit numbers from the underlying engine to fill the 64-bit range, whereas the
native implementation used only one.

Now the selection of the range variant only depends on the requested range. A
32-bit range uses the 32-bit variant (even for 64-bit engines), whereas a
larger range uses the 64-bit variant.

This was found in https://github.com/php/php-src/pull/9410#discussion_r953213000

show more ...


# 0f696e29 24-Aug-2022 Tim Düsterhus

Fix rand_range32() for umax = UINT32_MAX (#9416)

* Fix rand_range32() for umax = UINT32_MAX

This was introduced in the commit that added the random extension:
4d8dd8d258ff365b14

Fix rand_range32() for umax = UINT32_MAX (#9416)

* Fix rand_range32() for umax = UINT32_MAX

This was introduced in the commit that added the random extension:
4d8dd8d258ff365b146bcadcb277ede8992706d0.

Resolves GH-9415

* [ci skip] Rename `$r` to `$randomizer` in gh9415.phpt

* Make gh9415.phpt deterministic

* Make gh9415.phpt compatible with 32-bit

show more ...


12