Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions ext/random/php_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@

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)
{
return (zend_long)php_random_generate_fallback_seed();
}

# define PHP_MT_RAND_MAX ((zend_long) (0x7FFFFFFF)) /* (1<<31) - 1 */

enum php_random_mt19937_mode {
Expand All @@ -60,44 +50,44 @@ PHPAPI uint32_t php_mt_rand(void);
PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max);
PHPAPI zend_long php_mt_rand_common(zend_long min, zend_long max);

typedef struct _php_random_status_state_mt19937 {
typedef struct php_random_status_state_mt19937 {
uint32_t count;
enum php_random_mt19937_mode mode;
uint32_t state[624];
} php_random_status_state_mt19937;

typedef struct _php_random_status_state_pcgoneseq128xslrr64 {
typedef struct php_random_status_state_pcgoneseq128xslrr64 {
php_random_uint128_t state;
} php_random_status_state_pcgoneseq128xslrr64;

typedef struct _php_random_status_state_xoshiro256starstar {
typedef struct php_random_status_state_xoshiro256starstar {
uint64_t state[4];
} php_random_status_state_xoshiro256starstar;

typedef struct _php_random_status_state_user {
typedef struct php_random_status_state_user {
zend_object *object;
zend_function *generate_method;
} php_random_status_state_user;

typedef struct _php_random_result {
typedef struct php_random_result {
uint64_t result;
size_t size;
} php_random_result;

typedef struct _php_random_algo {
typedef struct php_random_algo {
const size_t state_size;
php_random_result (*generate)(void *state);
zend_long (*range)(void *state, zend_long min, zend_long max);
bool (*serialize)(void *state, HashTable *data);
bool (*unserialize)(void *state, HashTable *data);
} php_random_algo;

typedef struct _php_random_algo_with_state {
typedef struct php_random_algo_with_state {
const php_random_algo *algo;
void *state;
} php_random_algo_with_state;

typedef struct _php_random_fallback_seed_state {
typedef struct php_random_fallback_seed_state {
bool initialized;
unsigned char seed[20];
} php_random_fallback_seed_state;
Expand All @@ -108,12 +98,12 @@ extern PHPAPI const php_random_algo php_random_algo_xoshiro256starstar;
extern PHPAPI const php_random_algo php_random_algo_secure;
extern PHPAPI const php_random_algo php_random_algo_user;

typedef struct _php_random_engine {
typedef struct php_random_engine {
php_random_algo_with_state engine;
zend_object std;
} php_random_engine;

typedef struct _php_random_randomizer {
typedef struct php_random_randomizer {
php_random_algo_with_state engine;
bool is_userland_algo;
zend_object std;
Expand Down Expand Up @@ -147,6 +137,14 @@ static inline php_random_randomizer *php_random_randomizer_from_obj(zend_object

# define Z_RANDOM_RANDOMIZER_P(zval) php_random_randomizer_from_obj(Z_OBJ_P(zval));

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)
{
return (zend_long)php_random_generate_fallback_seed();
}

PHPAPI void *php_random_status_alloc(const php_random_algo *algo, const bool persistent);
PHPAPI void *php_random_status_copy(const php_random_algo *algo, void *old_status, void *new_status);
PHPAPI void php_random_status_free(void *status, const bool persistent);
Expand Down
2 changes: 1 addition & 1 deletion ext/random/php_random_uint128.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# include <stdint.h>

# if !defined(__SIZEOF_INT128__) || defined(PHP_RANDOM_FORCE_EMULATE_128)
typedef struct _php_random_uint128_t {
typedef struct php_random_uint128_t {
uint64_t hi;
uint64_t lo;
} php_random_uint128_t;
Expand Down
2 changes: 1 addition & 1 deletion ext/random/php_random_zend_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# include "php_random.h"
# include "zend.h"

typedef struct _php_random_bytes_insecure_state_for_zend {
typedef struct php_random_bytes_insecure_state_for_zend {
bool initialized;
php_random_status_state_xoshiro256starstar xoshiro256starstar_state;
} php_random_bytes_insecure_state_for_zend;
Expand Down
Loading