Add zend_random_bytes(), zend_random_bytes_insecure() functions (#14054)

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
This commit is contained in:
Arnaud Le Blanc 2024-06-12 13:57:54 +02:00
parent d545b1d643
commit d1048a0869
No known key found for this signature in database
GPG key ID: 0098C05DD15ABC13
10 changed files with 169 additions and 12 deletions

View file

@ -37,7 +37,10 @@
PHPAPI double php_combined_lcg(void);
typedef struct _php_random_fallback_seed_state php_random_fallback_seed_state;
PHPAPI uint64_t php_random_generate_fallback_seed(void);
PHPAPI uint64_t php_random_generate_fallback_seed_ex(php_random_fallback_seed_state *state);
static inline zend_long GENERATE_SEED(void)
{
@ -99,6 +102,11 @@ typedef struct _php_random_algo_with_state {
void *state;
} php_random_algo_with_state;
typedef struct _php_random_fallback_seed_state {
bool initialized;
unsigned char seed[20];
} php_random_fallback_seed_state;
extern PHPAPI const php_random_algo php_random_algo_combinedlcg;
extern PHPAPI const php_random_algo php_random_algo_mt19937;
extern PHPAPI const php_random_algo php_random_algo_pcgoneseq128xslrr64;
@ -197,8 +205,7 @@ PHP_RINIT_FUNCTION(random);
ZEND_BEGIN_MODULE_GLOBALS(random)
bool combined_lcg_seeded;
bool mt19937_seeded;
bool fallback_seed_initialized;
unsigned char fallback_seed[20];
php_random_fallback_seed_state fallback_seed_state;
php_random_status_state_combinedlcg combined_lcg;
php_random_status_state_mt19937 mt19937;
ZEND_END_MODULE_GLOBALS(random)