[php-src] master: random: Use CSPRNG for CombinedLCG seeding (#13748)
| From: | Tim Düsterhus via GitHub | Date: | Tue, 19 Mar 2024 19:27:33 +0000 |
| Subject: | [php-src] master: random: Use CSPRNG for CombinedLCG seeding (#13748) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127797@lists.php.net to get a copy of this message | ||
Author: Tim Düsterhus (TimWolla)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2024-03-19T20:13:44+01:00
Commit: https://github.com/php/php-src/commit/807524d61cc37b2d088e0cd7333e887fa607e56d
Raw diff: https://github.com/php/php-src/commit/807524d61cc37b2d088e0cd7333e887fa607e56d.diff
random: Use CSPRNG for CombinedLCG seeding (#13748)
Now that the CombinedLCG is no longer used within GENERATE_SEED(), we can
safely use the CSPRNG with a php_random_generate_fallback_seed() fallback to
seed the CombinedLCG.
Changed paths:
M ext/random/engine_combinedlcg.c
Diff:
diff --git a/ext/random/engine_combinedlcg.c b/ext/random/engine_combinedlcg.c
index 8874998f3323..ebecf9975f9c 100644
--- a/ext/random/engine_combinedlcg.c
+++ b/ext/random/engine_combinedlcg.c
@@ -107,23 +107,12 @@ const php_random_algo php_random_algo_combinedlcg = {
/* {{{ php_random_combinedlcg_seed_default */
PHPAPI void php_random_combinedlcg_seed_default(php_random_status_state_combinedlcg *state)
{
- struct timeval tv;
+ uint64_t seed = 0;
- if (gettimeofday(&tv, NULL) == 0) {
- state->state[0] = tv.tv_usec ^ (tv.tv_usec << 11);
- } else {
- state->state[0] = 1;
+ if (php_random_bytes_silent(&seed, sizeof(seed)) == FAILURE) {
+ seed = php_random_generate_fallback_seed();
}
-#ifdef ZTS
- state->state[1] = (zend_long) tsrm_thread_id();
-#else
- state->state[1] = (zend_long) getpid();
-#endif
-
- /* Add entropy to s2 by calling gettimeofday() again */
- if (gettimeofday(&tv, NULL) == 0) {
- state->state[1] ^= (tv.tv_usec << 11);
- }
+ php_random_combinedlcg_seed64(state, seed);
}
/* }}} */