@@ -234,6 +234,11 @@ struct _zend_class_entry {
234234 } info ;
235235};
236236
237+ typedef union {
238+ zend_max_align_t align ;
239+ uint64_t opaque [5 ];
240+ } zend_utility_random_bytes_insecure_state ;
241+
237242typedef struct _zend_utility_functions {
238243 void (* error_function )(int type , zend_string * error_filename , const uint32_t error_lineno , zend_string * message );
239244 size_t (* printf_function )(const char * format , ...) ZEND_ATTRIBUTE_PTR_FORMAT (printf , 1 , 2 );
@@ -248,6 +253,8 @@ typedef struct _zend_utility_functions {
248253 void (* printf_to_smart_str_function )(smart_str * buf , const char * format , va_list ap );
249254 char * (* getenv_function )(const char * name , size_t name_len );
250255 zend_string * (* resolve_path_function )(zend_string * filename );
256+ zend_result (* random_bytes_function )(void * bytes , size_t size , char * errstr , size_t errstr_size );
257+ zend_result (* random_bytes_insecure_function )(zend_utility_random_bytes_insecure_state * state , void * bytes , size_t size );
251258} zend_utility_functions ;
252259
253260typedef struct _zend_utility_values {
@@ -340,6 +347,14 @@ extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format
340347extern void (* zend_printf_to_smart_str )(smart_str * buf , const char * format , va_list ap );
341348extern ZEND_API char * (* zend_getenv )(const char * name , size_t name_len );
342349extern ZEND_API zend_string * (* zend_resolve_path )(zend_string * filename );
350+ /* Generate 'size' random bytes into 'bytes' with the OS CSPRNG. */
351+ extern ZEND_ATTRIBUTE_NONNULL ZEND_API zend_result (* zend_random_bytes )(
352+ void * bytes , size_t size , char * errstr , size_t errstr_size );
353+ /* Generate 'size' random bytes into 'bytes' with a general purpose PRNG (not
354+ * crypto safe). 'state' must be zeroed before the first call and can be reused.
355+ */
356+ extern ZEND_ATTRIBUTE_NONNULL ZEND_API zend_result (* zend_random_bytes_insecure )(
357+ zend_utility_random_bytes_insecure_state * state , void * bytes , size_t size );
343358
344359/* These two callbacks are especially for opcache */
345360extern ZEND_API zend_result (* zend_post_startup_cb )(void );
0 commit comments