From c92a3bb9e10deb8156caeefdb08153e94b3570b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 20:48:29 +0100 Subject: [PATCH 1/9] random: Expose xoshiro256**'s seeding functions --- ext/random/engine_xoshiro256starstar.c | 22 +++++++++++----------- ext/random/php_random.h | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ext/random/engine_xoshiro256starstar.c b/ext/random/engine_xoshiro256starstar.c index f581471e4ece..9e6f5c285829 100644 --- a/ext/random/engine_xoshiro256starstar.c +++ b/ext/random/engine_xoshiro256starstar.c @@ -82,15 +82,15 @@ static inline void jump(php_random_status_state_xoshiro256starstar *state, const state->state[3] = s3; } -static inline void seed256(php_random_status_state_xoshiro256starstar *s, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3) +PHPAPI inline void php_random_xoshiro256starstar_seed256(php_random_status_state_xoshiro256starstar *state, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3) { - s->state[0] = s0; - s->state[1] = s1; - s->state[2] = s2; - s->state[3] = s3; + state->state[0] = s0; + state->state[1] = s1; + state->state[2] = s2; + state->state[3] = s3; } -static inline void seed64(php_random_status_state_xoshiro256starstar *state, uint64_t seed) +PHPAPI inline void php_random_xoshiro256starstar_seed64(php_random_status_state_xoshiro256starstar *state, uint64_t seed) { uint64_t s[4]; @@ -99,12 +99,12 @@ static inline void seed64(php_random_status_state_xoshiro256starstar *state, uin s[2] = splitmix64(&seed); s[3] = splitmix64(&seed); - seed256(state, s[0], s[1], s[2], s[3]); + php_random_xoshiro256starstar_seed256(state, s[0], s[1], s[2], s[3]); } static void seed(void *state, uint64_t seed) { - seed64(state, seed); + php_random_xoshiro256starstar_seed64(state, seed); } static php_random_result generate(void *state) @@ -228,7 +228,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct) } } while (UNEXPECTED(t[0] == 0 && t[1] == 0 && t[2] == 0 && t[3] == 0)); - seed256(state, t[0], t[1], t[2], t[3]); + php_random_xoshiro256starstar_seed256(state, t[0], t[1], t[2], t[3]); } else { if (str_seed) { /* char (byte: 8 bit) * 32 = 256 bits */ @@ -248,13 +248,13 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct) RETURN_THROWS(); } - seed256(state, t[0], t[1], t[2], t[3]); + php_random_xoshiro256starstar_seed256(state, t[0], t[1], t[2], t[3]); } else { zend_argument_value_error(1, "must be a 32 byte (256 bit) string"); RETURN_THROWS(); } } else { - seed64(state, (uint64_t) int_seed); + php_random_xoshiro256starstar_seed64(state, (uint64_t) int_seed); } } } diff --git a/ext/random/php_random.h b/ext/random/php_random.h index 34dc7eb89dd7..1d0998f19fe1 100644 --- a/ext/random/php_random.h +++ b/ext/random/php_random.h @@ -183,6 +183,8 @@ PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *sta PHPAPI void php_random_pcgoneseq128xslrr64_advance(php_random_status_state_pcgoneseq128xslrr64 *state, uint64_t advance); +PHPAPI void php_random_xoshiro256starstar_seed64(php_random_status_state_xoshiro256starstar *state, uint64_t seed); +PHPAPI void php_random_xoshiro256starstar_seed256(php_random_status_state_xoshiro256starstar *state, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3); PHPAPI void php_random_xoshiro256starstar_jump(php_random_status_state_xoshiro256starstar *state); PHPAPI void php_random_xoshiro256starstar_jump_long(php_random_status_state_xoshiro256starstar *state); From 04cbee6514c016e7958b76d11e48323bfd890602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 20:52:18 +0100 Subject: [PATCH 2/9] random: Expose pcgoneseq128xslrr64's seeding functions --- ext/random/engine_pcgoneseq128xslrr64.c | 10 +++++----- ext/random/php_random.h | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ext/random/engine_pcgoneseq128xslrr64.c b/ext/random/engine_pcgoneseq128xslrr64.c index b95dd9f55c21..318bb17ec61c 100644 --- a/ext/random/engine_pcgoneseq128xslrr64.c +++ b/ext/random/engine_pcgoneseq128xslrr64.c @@ -35,7 +35,7 @@ static inline void step(php_random_status_state_pcgoneseq128xslrr64 *s) ); } -static inline void seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_random_uint128_t seed) +PHPAPI inline void php_random_pcgoneseq128xslrr64_seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_random_uint128_t seed) { s->state = php_random_uint128_constant(0ULL, 0ULL); step(s); @@ -45,7 +45,7 @@ static inline void seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_r static void seed(void *state, uint64_t seed) { - seed128(state, php_random_uint128_constant(0ULL, seed)); + php_random_pcgoneseq128xslrr64_seed128(state, php_random_uint128_constant(0ULL, seed)); } static php_random_result generate(void *state) @@ -164,7 +164,7 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct) RETURN_THROWS(); } - seed128(state, s); + php_random_pcgoneseq128xslrr64_seed128(state, s); } else { if (str_seed) { /* char (byte: 8 bit) * 16 = 128 bits */ @@ -179,13 +179,13 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct) } } - seed128(state, php_random_uint128_constant(t[0], t[1])); + php_random_pcgoneseq128xslrr64_seed128(state, php_random_uint128_constant(t[0], t[1])); } else { zend_argument_value_error(1, "must be a 16 byte (128 bit) string"); RETURN_THROWS(); } } else { - seed128(state, php_random_uint128_constant(0ULL, (uint64_t) int_seed)); + php_random_pcgoneseq128xslrr64_seed128(state, php_random_uint128_constant(0ULL, (uint64_t) int_seed)); } } } diff --git a/ext/random/php_random.h b/ext/random/php_random.h index 1d0998f19fe1..e0e524a1724f 100644 --- a/ext/random/php_random.h +++ b/ext/random/php_random.h @@ -181,6 +181,7 @@ PHPAPI void php_random_combinedlcg_seed_default(php_random_status_state_combined PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *state); +PHPAPI void php_random_pcgoneseq128xslrr64_seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_random_uint128_t seed); PHPAPI void php_random_pcgoneseq128xslrr64_advance(php_random_status_state_pcgoneseq128xslrr64 *state, uint64_t advance); PHPAPI void php_random_xoshiro256starstar_seed64(php_random_status_state_xoshiro256starstar *state, uint64_t seed); From c63d81fb7932f2dcb5357ad8d4c3b6facdb08d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 20:57:32 +0100 Subject: [PATCH 3/9] random: Expose Mt19937's seeding functions --- ext/random/engine_mt19937.c | 12 ++++++------ ext/random/php_random.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/random/engine_mt19937.c b/ext/random/engine_mt19937.c index ceb81e24a997..3eb1e8b83de3 100644 --- a/ext/random/engine_mt19937.c +++ b/ext/random/engine_mt19937.c @@ -121,7 +121,7 @@ static inline void mt19937_reload(php_random_status_state_mt19937 *state) state->count = 0; } -static inline void mt19937_seed_state(php_random_status_state_mt19937 *state, uint64_t seed) +PHPAPI inline void php_random_mt19937_seed32(php_random_status_state_mt19937 *state, uint32_t seed) { uint32_t i, prev_state; @@ -129,7 +129,7 @@ static inline void mt19937_seed_state(php_random_status_state_mt19937 *state, ui See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier. In previous versions, most significant bits (MSBs) of the seed affect only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. */ - state->state[0] = seed & 0xffffffffU; + state->state[0] = seed; for (i = 1; i < MT_N; i++) { prev_state = state->state[i - 1]; state->state[i] = (1812433253U * (prev_state ^ (prev_state >> 30)) + i) & 0xffffffffU; @@ -141,7 +141,7 @@ static inline void mt19937_seed_state(php_random_status_state_mt19937 *state, ui static void seed(void *state, uint64_t seed) { - mt19937_seed_state(state, seed); + php_random_mt19937_seed32(state, seed & 0xffffffffU); } static php_random_result generate(void *state) @@ -241,13 +241,13 @@ const php_random_algo php_random_algo_mt19937 = { /* {{{ php_random_mt19937_seed_default */ PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *state) { - zend_long seed = 0; + uint32_t seed = 0; if (php_random_bytes_silent(&seed, sizeof(seed)) == FAILURE) { seed = GENERATE_SEED(); } - mt19937_seed_state(state, (uint64_t) seed); + php_random_mt19937_seed32(state, seed); } /* }}} */ @@ -286,7 +286,7 @@ PHP_METHOD(Random_Engine_Mt19937, __construct) } } - mt19937_seed_state(state, seed); + php_random_mt19937_seed32(state, seed); } /* }}} */ diff --git a/ext/random/php_random.h b/ext/random/php_random.h index e0e524a1724f..592b52661eb3 100644 --- a/ext/random/php_random.h +++ b/ext/random/php_random.h @@ -179,6 +179,7 @@ PHPAPI bool php_random_hex2bin_le(zend_string *hexstr, void *dest); PHPAPI void php_random_combinedlcg_seed_default(php_random_status_state_combinedlcg *state); +PHPAPI void php_random_mt19937_seed32(php_random_status_state_mt19937 *state, uint32_t seed); PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *state); PHPAPI void php_random_pcgoneseq128xslrr64_seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_random_uint128_t seed); From 305f8808fa7acf94275a46b5602143040aa02adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 21:02:45 +0100 Subject: [PATCH 4/9] random: Expose CombinedLCG's seeding functions --- ext/random/engine_combinedlcg.c | 11 +++++++---- ext/random/php_random.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ext/random/engine_combinedlcg.c b/ext/random/engine_combinedlcg.c index a37882689114..a0b1f01f5632 100644 --- a/ext/random/engine_combinedlcg.c +++ b/ext/random/engine_combinedlcg.c @@ -32,12 +32,15 @@ */ #define MODMULT(a, b, c, m, s) q = s / a; s = b * (s - a * q) - c * q; if (s < 0) s += m -static void seed(void *state, uint64_t seed) +PHPAPI inline void php_random_combinedlcg_seed64(php_random_status_state_combinedlcg *state, uint64_t seed) { - php_random_status_state_combinedlcg *s = state; + state->state[0] = seed & 0xffffffffU; + state->state[1] = seed >> 32; +} - s->state[0] = seed & 0xffffffffU; - s->state[1] = seed >> 32; +static void seed(void *state, uint64_t seed) +{ + php_random_combinedlcg_seed64(state, seed); } static php_random_result generate(void *state) diff --git a/ext/random/php_random.h b/ext/random/php_random.h index 592b52661eb3..9b1e7687cd25 100644 --- a/ext/random/php_random.h +++ b/ext/random/php_random.h @@ -177,6 +177,7 @@ static inline php_random_algo_with_state php_random_default_engine(void) PHPAPI zend_string *php_random_bin2hex_le(const void *ptr, const size_t len); PHPAPI bool php_random_hex2bin_le(zend_string *hexstr, void *dest); +PHPAPI void php_random_combinedlcg_seed64(php_random_status_state_combinedlcg *state, uint64_t seed); PHPAPI void php_random_combinedlcg_seed_default(php_random_status_state_combinedlcg *state); PHPAPI void php_random_mt19937_seed32(php_random_status_state_mt19937 *state, uint32_t seed); From 164692bb8079b51c7acf4da8ea51cad44c0bcee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 21:04:58 +0100 Subject: [PATCH 5/9] random: Call php_random_mt19937_seed32 to seed the global Mt19937 This avoids the function pointer indirection and improves type safety. --- ext/random/random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/random/random.c b/ext/random/random.c index 706be3b1551d..a49b373aa0c9 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -405,7 +405,7 @@ PHPAPI double php_combined_lcg(void) PHPAPI void php_mt_srand(uint32_t seed) { /* Seed the generator with a simple uint32 */ - php_random_algo_mt19937.seed(php_random_default_status(), (zend_long) seed); + php_random_mt19937_seed32(php_random_default_status(), (zend_long) seed); } /* }}} */ @@ -491,7 +491,7 @@ PHP_FUNCTION(mt_srand) if (seed_is_null) { php_random_mt19937_seed_default(state); } else { - php_random_algo_mt19937.seed(state, (uint64_t) seed); + php_random_mt19937_seed32(state, (uint64_t) seed); } RANDOM_G(mt19937_seeded) = true; } From e365e70f9cffab50afa3d6f88088665fed1283c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 21:09:57 +0100 Subject: [PATCH 6/9] random: NULL the generic seeding function Different engines work quite differently, it is not useful to attempt to seed them in a generic way using a 64 bit integer. As an example Mt19937 completely ignores the upper 32 bits. --- ext/random/engine_combinedlcg.c | 9 ++------- ext/random/engine_mt19937.c | 7 +------ ext/random/engine_pcgoneseq128xslrr64.c | 7 +------ ext/random/engine_xoshiro256starstar.c | 7 +------ 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/ext/random/engine_combinedlcg.c b/ext/random/engine_combinedlcg.c index a0b1f01f5632..d1068ff8268d 100644 --- a/ext/random/engine_combinedlcg.c +++ b/ext/random/engine_combinedlcg.c @@ -32,17 +32,12 @@ */ #define MODMULT(a, b, c, m, s) q = s / a; s = b * (s - a * q) - c * q; if (s < 0) s += m -PHPAPI inline void php_random_combinedlcg_seed64(php_random_status_state_combinedlcg *state, uint64_t seed) +PHPAPI void php_random_combinedlcg_seed64(php_random_status_state_combinedlcg *state, uint64_t seed) { state->state[0] = seed & 0xffffffffU; state->state[1] = seed >> 32; } -static void seed(void *state, uint64_t seed) -{ - php_random_combinedlcg_seed64(state, seed); -} - static php_random_result generate(void *state) { php_random_status_state_combinedlcg *s = state; @@ -103,7 +98,7 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_combinedlcg = { sizeof(php_random_status_state_combinedlcg), - seed, + NULL, generate, range, serialize, diff --git a/ext/random/engine_mt19937.c b/ext/random/engine_mt19937.c index 3eb1e8b83de3..33a072882f61 100644 --- a/ext/random/engine_mt19937.c +++ b/ext/random/engine_mt19937.c @@ -139,11 +139,6 @@ PHPAPI inline void php_random_mt19937_seed32(php_random_status_state_mt19937 *st mt19937_reload(state); } -static void seed(void *state, uint64_t seed) -{ - php_random_mt19937_seed32(state, seed & 0xffffffffU); -} - static php_random_result generate(void *state) { php_random_status_state_mt19937 *s = state; @@ -231,7 +226,7 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_mt19937 = { sizeof(php_random_status_state_mt19937), - seed, + NULL, generate, range, serialize, diff --git a/ext/random/engine_pcgoneseq128xslrr64.c b/ext/random/engine_pcgoneseq128xslrr64.c index 318bb17ec61c..fa1068652577 100644 --- a/ext/random/engine_pcgoneseq128xslrr64.c +++ b/ext/random/engine_pcgoneseq128xslrr64.c @@ -43,11 +43,6 @@ PHPAPI inline void php_random_pcgoneseq128xslrr64_seed128(php_random_status_stat step(s); } -static void seed(void *state, uint64_t seed) -{ - php_random_pcgoneseq128xslrr64_seed128(state, php_random_uint128_constant(0ULL, seed)); -} - static php_random_result generate(void *state) { php_random_status_state_pcgoneseq128xslrr64 *s = state; @@ -112,7 +107,7 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_pcgoneseq128xslrr64 = { sizeof(php_random_status_state_pcgoneseq128xslrr64), - seed, + NULL, generate, range, serialize, diff --git a/ext/random/engine_xoshiro256starstar.c b/ext/random/engine_xoshiro256starstar.c index 9e6f5c285829..c6be8b74219f 100644 --- a/ext/random/engine_xoshiro256starstar.c +++ b/ext/random/engine_xoshiro256starstar.c @@ -102,11 +102,6 @@ PHPAPI inline void php_random_xoshiro256starstar_seed64(php_random_status_state_ php_random_xoshiro256starstar_seed256(state, s[0], s[1], s[2], s[3]); } -static void seed(void *state, uint64_t seed) -{ - php_random_xoshiro256starstar_seed64(state, seed); -} - static php_random_result generate(void *state) { return (php_random_result){ @@ -161,7 +156,7 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_xoshiro256starstar = { sizeof(php_random_status_state_xoshiro256starstar), - seed, + NULL, generate, range, serialize, From ad1fd44005cf2417a56d8078a823cc2e40911612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 21:15:34 +0100 Subject: [PATCH 7/9] random: Remove the `seed` member from `php_random_algo` See the explanation in the previous commit for the reasoning. This member is unused since the previous commit and was not consistently available even before that (specifically for the Secure engine). --- ext/random/engine_combinedlcg.c | 1 - ext/random/engine_mt19937.c | 1 - ext/random/engine_pcgoneseq128xslrr64.c | 1 - ext/random/engine_secure.c | 1 - ext/random/engine_user.c | 1 - ext/random/engine_xoshiro256starstar.c | 1 - ext/random/php_random.h | 1 - 7 files changed, 7 deletions(-) diff --git a/ext/random/engine_combinedlcg.c b/ext/random/engine_combinedlcg.c index d1068ff8268d..8874998f3323 100644 --- a/ext/random/engine_combinedlcg.c +++ b/ext/random/engine_combinedlcg.c @@ -98,7 +98,6 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_combinedlcg = { sizeof(php_random_status_state_combinedlcg), - NULL, generate, range, serialize, diff --git a/ext/random/engine_mt19937.c b/ext/random/engine_mt19937.c index 33a072882f61..1034fdf39a4c 100644 --- a/ext/random/engine_mt19937.c +++ b/ext/random/engine_mt19937.c @@ -226,7 +226,6 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_mt19937 = { sizeof(php_random_status_state_mt19937), - NULL, generate, range, serialize, diff --git a/ext/random/engine_pcgoneseq128xslrr64.c b/ext/random/engine_pcgoneseq128xslrr64.c index fa1068652577..4d288f5793eb 100644 --- a/ext/random/engine_pcgoneseq128xslrr64.c +++ b/ext/random/engine_pcgoneseq128xslrr64.c @@ -107,7 +107,6 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_pcgoneseq128xslrr64 = { sizeof(php_random_status_state_pcgoneseq128xslrr64), - NULL, generate, range, serialize, diff --git a/ext/random/engine_secure.c b/ext/random/engine_secure.c index 8d99cd07818b..e55b98469399 100644 --- a/ext/random/engine_secure.c +++ b/ext/random/engine_secure.c @@ -48,7 +48,6 @@ static zend_long range(void *state, zend_long min, zend_long max) const php_random_algo php_random_algo_secure = { 0, - NULL, generate, range, NULL, diff --git a/ext/random/engine_user.c b/ext/random/engine_user.c index 25bd86bfb0c4..d8c6909d1db8 100644 --- a/ext/random/engine_user.c +++ b/ext/random/engine_user.c @@ -75,7 +75,6 @@ static zend_long range(void *state, zend_long min, zend_long max) const php_random_algo php_random_algo_user = { sizeof(php_random_status_state_user), - NULL, generate, range, NULL, diff --git a/ext/random/engine_xoshiro256starstar.c b/ext/random/engine_xoshiro256starstar.c index c6be8b74219f..fba834ebcd5e 100644 --- a/ext/random/engine_xoshiro256starstar.c +++ b/ext/random/engine_xoshiro256starstar.c @@ -156,7 +156,6 @@ static bool unserialize(void *state, HashTable *data) const php_random_algo php_random_algo_xoshiro256starstar = { sizeof(php_random_status_state_xoshiro256starstar), - NULL, generate, range, serialize, diff --git a/ext/random/php_random.h b/ext/random/php_random.h index 9b1e7687cd25..c62761029ddc 100644 --- a/ext/random/php_random.h +++ b/ext/random/php_random.h @@ -96,7 +96,6 @@ typedef struct _php_random_result { typedef struct _php_random_algo { const size_t state_size; - void (*seed)(void *state, uint64_t seed); php_random_result (*generate)(void *state); zend_long (*range)(void *state, zend_long min, zend_long max); bool (*serialize)(void *state, HashTable *data); From cbcaa055a8605234647ff6ca934347992f354510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 21:27:26 +0100 Subject: [PATCH 8/9] UPGRADING.INTERNALS --- UPGRADING.INTERNALS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index fb22b733c365..217d86809ad4 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -156,6 +156,11 @@ PHP 8.4 INTERNALS UPGRADE NOTES single php_random_algo_with_state struct by value, making it easier to pass around the state with its associated algorithm and thus reducing the chance for mistakes. + - The seed member of a php_random_algo has been removed. As a replacement + engine-specific seeding functions are now exposed. This change allows + users to better take engine-specific behavior into account. As an example + Mt19937 ignored the upper half of the seed parameter of the generic + seeding function. - The CSPRNG API (php_random_(bytes|int)_*) is now provided by the new and much smaller php_random_csprng.h header. The new header is included in php_random.h for compatibility with existing users. From ed18365ad81e0768aa000bf06a6f43c8830f75e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Feb 2024 21:42:33 +0100 Subject: [PATCH 9/9] random: Remove useless cast in `php_mt_srand()` --- ext/random/random.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/random/random.c b/ext/random/random.c index a49b373aa0c9..afd4cc1a77bb 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -404,8 +404,7 @@ PHPAPI double php_combined_lcg(void) /* {{{ php_mt_srand */ PHPAPI void php_mt_srand(uint32_t seed) { - /* Seed the generator with a simple uint32 */ - php_random_mt19937_seed32(php_random_default_status(), (zend_long) seed); + php_random_mt19937_seed32(php_random_default_status(), seed); } /* }}} */