50#ifdef HAVE_SYS_PARAM_H
51# include <sys/param.h>
83 void *
state = engine.state;
97 }
while (total_size <
sizeof(uint32_t));
108 if ((umax & (umax - 1)) == 0) {
109 return result & (umax - 1);
129 total_size += r.
size;
133 }
while (total_size <
sizeof(uint32_t));
142 void *
state = engine.state;
152 total_size += r.
size;
156 }
while (total_size <
sizeof(uint64_t));
167 if ((umax & (umax - 1)) == 0) {
168 return result & (umax - 1);
172 uint64_t limit = UINT64_MAX - (UINT64_MAX % umax) - 1;
188 total_size += r.
size;
192 }
while (total_size <
sizeof(uint64_t));
225 return &randomizer->
std;
228static void randomizer_free_obj(
zend_object *
object) {
289 return &new_engine->
std;
337 str = zend_string_safe_alloc(
len, 2 *
sizeof(
char), 0, 0);
340#ifdef WORDS_BIGENDIAN
342 for (
size_t h =
len; 0 < h; h--) {
345 for (
size_t j = 0;
j <
len;
j++) {
347 ZSTR_VAL(str)[i++] = hexconvtab[((
unsigned char *)
ptr)[
j] >> 4];
348 ZSTR_VAL(str)[i++] = hexconvtab[((
unsigned char *)
ptr)[
j] & 15];
360 size_t len = hexstr->
len >> 1;
361 unsigned char *str = (
unsigned char *) hexstr->
val, c, l, d;
362 unsigned char *
ptr = (
unsigned char *) dest;
363 int is_letter, i = 0;
365#ifdef WORDS_BIGENDIAN
367 for (
size_t h =
len; 0 < h; h--) {
370 for (
size_t j = 0;
j <
len;
j++) {
374 is_letter = ((uint32_t) ((l -
'A') ^ (l -
'F' - 1))) >> (8 *
sizeof(uint32_t) - 1);
377 if (
EXPECTED((((c ^
'0') - 10) >> (8 *
sizeof(uint32_t) - 1)) | is_letter)) {
378 d = (l - 0x10 - 0x27 * is_letter) << 4;
384 is_letter = ((uint32_t) ((l -
'A') ^ (l -
'F' - 1))) >> (8 *
sizeof(uint32_t) - 1);
385 if (
EXPECTED((((c ^
'0') - 10) >> (8 *
sizeof(uint32_t) - 1)) | is_letter)) {
386 d |= l - 0x10 - 0x27 * is_letter;
404 if (php_random_bytes_silent(&seed,
sizeof(seed)) ==
FAILURE) {
408 state[0] = seed & 0xffffffffU;
409 state[1] = seed >> 32;
422#define PHP_COMBINED_LCG_MODMULT(a, b, c, m, s) q = s / a; s = b * (s - a * q) - c * q; if (s < 0) s += m
436 return ((uint64_t)z) * 4.656613e-10;
495 bool seed_is_null =
true;
600 bytes = zend_string_alloc(
size, 0);
636static inline void fallback_seed_add(
PHP_SHA1_CTX *c,
void *
p,
size_t l){
662 if (!
state->initialized) {
665 fallback_seed_add(&c, &
tv,
sizeof(
tv));
668 fallback_seed_add(&c, &pid,
sizeof(pid));
671 fallback_seed_add(&c, &pid,
sizeof(pid));
674 tid = tsrm_thread_id();
675 fallback_seed_add(&c, &tid,
sizeof(tid));
679 fallback_seed_add(&c, &pointer,
sizeof(pointer));
681 fallback_seed_add(&c, &pointer,
sizeof(pointer));
684 fallback_seed_add(&c, &
tv,
sizeof(
tv));
691 if (php_random_bytes_silent(
buf, 16) ==
SUCCESS) {
692 fallback_seed_add(&c,
buf, 16);
696 fallback_seed_add(&c, &
tv,
sizeof(
tv));
700 fallback_seed_add(&c, &
tv,
sizeof(
tv));
702 fallback_seed_add(&c,
state->seed, 20);
705 state->initialized =
true;
709 for (
size_t i = 0; i <
sizeof(
result); i++) {
724 random_globals->fallback_seed_state.initialized =
false;
784 random_randomizer_object_handlers.
free_obj = randomizer_free_obj;
790 register_random_symbols(module_number);
gettimeofday(bool $as_float=false)
count(Countable|array $value, int $mode=COUNT_NORMAL)
PHPAPI void php_random_csprng_shutdown(void)
PHPAPI void php_random_mt19937_seed32(php_random_status_state_mt19937 *state, uint32_t seed)
PHPAPI const php_random_algo php_random_algo_mt19937
PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *state)
PHPAPI const php_random_algo php_random_algo_pcgoneseq128xslrr64
PHPAPI const php_random_algo php_random_algo_secure
PHPAPI const php_random_algo php_random_algo_xoshiro256starstar
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_GINIT_FUNCTION
#define PHP_RINIT_FUNCTION
#define PHP_MODULE_GLOBALS
PHPAPI zend_class_entry * random_ce_Random_Engine
PHPAPI zend_object * php_random_engine_common_clone_object(zend_object *object)
PHPAPI zend_class_entry * random_ce_Random_RandomError
PHPAPI zend_class_entry * random_ce_Random_Engine_PcgOneseq128XslRr64
PHPAPI zend_class_entry * random_ce_Random_Randomizer
php_random_fallback_seed_state fallback_seed_state
struct _php_random_algo_with_state php_random_algo_with_state
PHPAPI zend_class_entry * random_ce_Random_Engine_Mt19937
php_random_status_state_mt19937 mt19937
PHPAPI zend_class_entry * random_ce_Random_RandomException
PHPAPI void php_random_engine_common_free_object(zend_object *object)
struct _php_random_status_state_mt19937 php_random_status_state_mt19937
PHPAPI zend_class_entry * random_ce_Random_CryptoSafeEngine
PHPAPI zend_class_entry * random_ce_Random_IntervalBoundary
PHPAPI zend_class_entry * random_ce_Random_Engine_Xoshiro256StarStar
struct _php_random_fallback_seed_state php_random_fallback_seed_state
struct _php_random_engine php_random_engine
PHPAPI zend_class_entry * random_ce_Random_Engine_Secure
struct _php_random_algo php_random_algo
#define PHP_RANDOM_RANGE_ATTEMPTS
struct _php_random_randomizer php_random_randomizer
PHPAPI zend_class_entry * random_ce_Random_BrokenRandomEngineError
zend_module_entry random_module_entry
struct _php_random_result php_random_result
PHPAPI uint32_t php_random_range32(php_random_algo_with_state engine, uint32_t umax)
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 zend_long php_mt_rand_common(zend_long min, zend_long max)
PHPAPI zend_object * php_random_engine_common_clone_object(zend_object *object)
PHPAPI php_random_engine * php_random_engine_common_init(zend_class_entry *ce, zend_object_handlers *handlers, const php_random_algo *algo)
PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max)
PHPAPI void * php_random_status_alloc(const php_random_algo *algo, const bool persistent)
PHPAPI void php_mt_srand(uint32_t seed)
PHPAPI uint64_t php_random_generate_fallback_seed(void)
PHPAPI uint64_t php_random_generate_fallback_seed_ex(php_random_fallback_seed_state *state)
PHPAPI void php_random_engine_common_free_object(zend_object *object)
PHPAPI const php_random_algo * php_random_default_algo(void)
#define PHP_COMBINED_LCG_MODMULT(a, b, c, m, s)
PHPAPI void * php_random_status_copy(const php_random_algo *algo, void *old_status, void *new_status)
PHPAPI uint32_t php_mt_rand(void)
PHPAPI zend_long php_random_range(php_random_algo_with_state engine, zend_long min, zend_long max)
PHPAPI double php_combined_lcg(void)
PHPAPI uint64_t php_random_range64(php_random_algo_with_state engine, uint64_t umax)
PHPAPI void * php_random_default_status(void)
PHPAPI void php_random_status_free(void *status, const bool persistent)
mt_srand(?int $seed=null, int $mode=MT_RAND_MT19937)
mt_rand(int $min=UNKNOWN, int $max=UNKNOWN)
random_bytes(int $length)
random_int(int $min, int $max)
rand(int $min=UNKNOWN, int $max=UNKNOWN)
PHPAPI void PHP_SHA1Final(unsigned char digest[20], PHP_SHA1_CTX *context)
PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX *context, const unsigned char *input, size_t inputLen)
#define PHP_SHA1Init(ctx)
const php_random_algo * algo
php_random_result(* generate)(void *state)
php_random_algo_with_state engine
php_random_algo_with_state engine
zend_object *(* create_object)(zend_class_entry *class_type)
zend_object_free_obj_t free_obj
zend_object_clone_obj_t clone_obj
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
ZEND_API ZEND_COLD void zend_error(int type, const char *format,...)
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
#define ZEND_PARSE_PARAMETERS_END()
#define ZEND_PARSE_PARAMETERS_NONE()
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define Z_PARAM_LONG(dest)
#define Z_PARAM_LONG_OR_NULL(dest, is_null)
#define pefree(ptr, persistent)
#define pecalloc(nmemb, size, persistent)
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API zend_class_entry * zend_ce_exception
ZEND_API zend_class_entry * zend_ce_error
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES_EX
#define zend_get_std_object_handlers()
ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, zend_object *old_object)
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
#define EXPECTED(condition)
#define XtOffsetOf(s_type, field)
#define ZEND_SET_ALIGNED(alignment, decl)
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_object_handlers zend_object_handlers