Skip to content

Commit 807524d

Browse files
authored
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.
1 parent 5b7d458 commit 807524d

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

ext/random/engine_combinedlcg.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,12 @@ const php_random_algo php_random_algo_combinedlcg = {
107107
/* {{{ php_random_combinedlcg_seed_default */
108108
PHPAPI void php_random_combinedlcg_seed_default(php_random_status_state_combinedlcg *state)
109109
{
110-
struct timeval tv;
110+
uint64_t seed = 0;
111111

112-
if (gettimeofday(&tv, NULL) == 0) {
113-
state->state[0] = tv.tv_usec ^ (tv.tv_usec << 11);
114-
} else {
115-
state->state[0] = 1;
112+
if (php_random_bytes_silent(&seed, sizeof(seed)) == FAILURE) {
113+
seed = php_random_generate_fallback_seed();
116114
}
117115

118-
#ifdef ZTS
119-
state->state[1] = (zend_long) tsrm_thread_id();
120-
#else
121-
state->state[1] = (zend_long) getpid();
122-
#endif
123-
124-
/* Add entropy to s2 by calling gettimeofday() again */
125-
if (gettimeofday(&tv, NULL) == 0) {
126-
state->state[1] ^= (tv.tv_usec << 11);
127-
}
116+
php_random_combinedlcg_seed64(state, seed);
128117
}
129118
/* }}} */

0 commit comments

Comments
 (0)