@@ -168,14 +168,12 @@ PHPAPI zend_class_entry *random_ce_Random_Engine_CombinedLCG;
168168PHPAPI zend_class_entry * random_ce_Random_Engine_MersenneTwister ;
169169PHPAPI zend_class_entry * random_ce_Random_Engine_PCG64 ;
170170PHPAPI zend_class_entry * random_ce_Random_Engine_Secure ;
171- PHPAPI zend_class_entry * random_ce_Random_Engine_Xoshiro256StarStar ;
172171PHPAPI zend_class_entry * random_ce_Random_Randomizer ;
173172
174173static zend_object_handlers random_engine_combinedlcg_object_handlers ;
175174static zend_object_handlers random_engine_mersennetwister_object_handlers ;
176175static zend_object_handlers random_engine_pcg64_object_handlers ;
177176static zend_object_handlers random_engine_secure_object_handlers ;
178- static zend_object_handlers random_engine_xoshiro256starstar_object_handlers ;
179177static zend_object_handlers random_randomizer_object_handlers ;
180178
181179static uint32_t rand_range32 (const php_random_engine_algo * algo , void * state , uint32_t umax , bool * engine_unsafe ) {
@@ -281,19 +279,6 @@ static uint64_t rand_range64(const php_random_engine_algo *algo, void *state, ui
281279}
282280#endif
283281
284- static inline uint64_t splitmix64 (uint64_t * seed ) {
285- uint64_t r ;
286-
287- r = (* seed += 0x9e3779b97f4a7c15ULL );
288- r = (r ^ (r >> 30 )) * 0xbf58476d1ce4e5b9ULL ;
289- r = (r ^ (r >> 27 )) * 0x94d049bb133111ebULL ;
290- return (r ^ (r >> 31 ));
291- }
292-
293- static inline uint64_t rotl (const uint64_t x , int k ) {
294- return (x << k ) | (x >> (64 - k ));
295- }
296-
297282static inline zend_object * php_random_engine_common_init (zend_class_entry * ce , const php_random_engine_algo * algo , const zend_object_handlers * handlers ) {
298283 php_random_engine * engine = zend_object_alloc (sizeof (php_random_engine ), ce );
299284
@@ -766,85 +751,6 @@ const php_random_engine_algo php_random_engine_algo_user = {
766751
767752/* User end */
768753
769- /* Xoshiro256StarStar start */
770-
771- static inline size_t xoshiro256starstar_dynamic_generate_size (void * state ) {
772- return sizeof (uint64_t );
773- }
774-
775- static uint64_t xoshiro256starstar_generate (void * state , bool * engine_unsafe ) {
776- php_random_engine_state_xoshiro256starstar * s = state ;
777- const uint64_t result = rotl (s -> s [1 ] * 5 , 7 ) * 9 ;
778- const uint64_t t = s -> s [1 ] << 17 ;
779-
780- s -> s [2 ] ^= s -> s [0 ];
781- s -> s [3 ] ^= s -> s [1 ];
782- s -> s [1 ] ^= s -> s [2 ];
783- s -> s [0 ] ^= s -> s [3 ];
784-
785- s -> s [2 ] ^= t ;
786-
787- s -> s [3 ] = rotl (s -> s [3 ], 45 );
788-
789- return result ;
790- }
791-
792- static void xoshiro256starstar_seed (void * state , const uint64_t seed ) {
793- php_random_engine_state_xoshiro256starstar * s = state ;
794- uint64_t sd = seed ;
795-
796- s -> s [0 ] = splitmix64 (& sd );
797- s -> s [1 ] = splitmix64 (& sd );
798- s -> s [2 ] = splitmix64 (& sd );
799- s -> s [3 ] = splitmix64 (& sd );
800- }
801-
802- static int xoshiro256starstar_serialize (void * state , HashTable * data ) {
803- php_random_engine_state_xoshiro256starstar * s = state ;
804- zval tmp ;
805- int i ;
806-
807- for (i = 0 ; i < 4 ; i ++ ) {
808- ZVAL_STR (& tmp , zend_strpprintf (0 , "%" PRIu64 , s -> s [i ]));
809- zend_hash_next_index_insert (data , & tmp );
810- }
811-
812- return SUCCESS ;
813- }
814-
815- static int xoshiro256starstar_unserialize (void * state , HashTable * data ) {
816- php_random_engine_state_xoshiro256starstar * s = state ;
817- zval * tmp ;
818- int i ;
819-
820- for (i = 0 ; i < 4 ; i ++ ) {
821- tmp = zend_hash_index_find (data , i );
822- if (!tmp || Z_TYPE_P (tmp ) != IS_STRING ) {
823- return FAILURE ;
824- }
825-
826- s -> s [i ] = strtoull (ZSTR_VAL (Z_STR_P (tmp )), NULL , 10 );
827- }
828-
829- return SUCCESS ;
830- }
831-
832- static zend_object * php_random_engine_xoshiro256starstar_new (zend_class_entry * ce ) {
833- return php_random_engine_common_init (ce , & php_random_engine_algo_xoshiro256starstar , & random_engine_xoshiro256starstar_object_handlers );
834- }
835-
836- const php_random_engine_algo php_random_engine_algo_xoshiro256starstar = {
837- sizeof (uint64_t ),
838- xoshiro256starstar_dynamic_generate_size ,
839- sizeof (php_random_engine_state_xoshiro256starstar ),
840- xoshiro256starstar_generate ,
841- xoshiro256starstar_seed ,
842- xoshiro256starstar_serialize ,
843- xoshiro256starstar_unserialize
844- };
845-
846- /* Xoshiro256StarStar end */
847-
848754static zend_object * php_random_randomizer_new (zend_class_entry * ce ) {
849755 php_random_randomizer * randomizer = zend_object_alloc (sizeof (php_random_randomizer ), ce );
850756
@@ -1566,110 +1472,6 @@ PHP_METHOD(Random_Engine_PCG64, jump)
15661472}
15671473/* }}} */
15681474
1569- /* {{{ Construct object */
1570- PHP_METHOD (Random_Engine_Xoshiro256StarStar , __construct )
1571- {
1572- php_random_engine * engine = Z_RANDOM_ENGINE_P (ZEND_THIS );
1573- php_random_engine_state_xoshiro256starstar * state = engine -> state ;
1574- zend_string * str_seed = NULL ;
1575- zend_long int_seed = 0 ;
1576- bool seed_is_null = true;
1577- int i , j ;
1578-
1579- ZEND_PARSE_PARAMETERS_START (0 , 1 )
1580- Z_PARAM_OPTIONAL ;
1581- Z_PARAM_STR_OR_LONG_OR_NULL (str_seed , int_seed , seed_is_null );
1582- ZEND_PARSE_PARAMETERS_END ();
1583-
1584- if (seed_is_null ) {
1585- for (i = 0 ; i < 4 ; i ++ ) {
1586- if (php_random_bytes_silent (& state -> s [i ], sizeof (uint64_t )) == FAILURE ) {
1587- zend_throw_exception (spl_ce_RuntimeException , "Random number generate failed" , 0 );
1588- RETURN_THROWS ();
1589- }
1590- }
1591- } else {
1592- if (str_seed ) {
1593- /* char (8 bit) * 32 = 256 bits */
1594- if (ZSTR_LEN (str_seed ) == 32 ) {
1595- /* Endianness safe copy */
1596- for (i = 0 ; i < 4 ; i ++ ) {
1597- state -> s [i ] = 0 ;
1598- for (j = 0 ; j < 8 ; j ++ ) {
1599- state -> s [i ] += ((uint64_t ) (unsigned char ) ZSTR_VAL (str_seed )[(i * 8 ) + j ]) << (j * 8 );
1600- }
1601- }
1602- } else {
1603- zend_argument_value_error (1 , "state strings must be 32 bytes" );
1604- RETURN_THROWS ();
1605- }
1606- } else {
1607- engine -> algo -> seed (state , int_seed );
1608- }
1609- }
1610- }
1611- /* }}} */
1612-
1613- /* {{{ Jump a state */
1614- PHP_METHOD (Random_Engine_Xoshiro256StarStar , jump )
1615- {
1616- php_random_engine * engine = Z_RANDOM_ENGINE_P (ZEND_THIS );
1617- php_random_engine_state_xoshiro256starstar * s = engine -> state ;
1618- static const uint64_t jmp [] = { 0x180ec6d33cfd0aba , 0xd5a61266f0c9392c , 0xa9582618e03fc9aa , 0x39abdc4529b1661c };
1619- uint64_t s0 = 0 , s1 = 0 , s2 = 0 , s3 = 0 ;
1620- int i , j ;
1621-
1622- ZEND_PARSE_PARAMETERS_NONE ();
1623-
1624- for (i = 0 ; i < sizeof (jmp ) / sizeof (* jmp ); i ++ ) {
1625- for (j = 0 ; j < 64 ; j ++ ) {
1626- if (jmp [i ] & 1ULL << j ) {
1627- s0 ^= s -> s [0 ];
1628- s1 ^= s -> s [1 ];
1629- s2 ^= s -> s [2 ];
1630- s3 ^= s -> s [3 ];
1631- }
1632- engine -> algo -> generate (engine -> state , NULL );
1633- }
1634- }
1635-
1636- s -> s [0 ] = s0 ;
1637- s -> s [1 ] = s1 ;
1638- s -> s [2 ] = s2 ;
1639- s -> s [3 ] = s3 ;
1640- }
1641- /* }}} */
1642-
1643- /* {{{ Jump a long state */
1644- PHP_METHOD (Random_Engine_Xoshiro256StarStar , jumpLong )
1645- {
1646- php_random_engine * engine = Z_RANDOM_ENGINE_P (ZEND_THIS );
1647- php_random_engine_state_xoshiro256starstar * s = engine -> state ;
1648- static const uint64_t jmp [] = { 0x76e15d3efefdcbbf , 0xc5004e441c522fb3 , 0x77710069854ee241 , 0x39109bb02acbe635 };
1649- uint64_t s0 = 0 , s1 = 0 , s2 = 0 , s3 = 0 ;
1650- int i , j ;
1651-
1652- ZEND_PARSE_PARAMETERS_NONE ();
1653-
1654- for (i = 0 ; i < sizeof (jmp ) / sizeof (* jmp ); i ++ ) {
1655- for (j = 0 ; j < 64 ; j ++ ) {
1656- if (jmp [i ] & 1ULL << j ) {
1657- s0 ^= s -> s [0 ];
1658- s1 ^= s -> s [1 ];
1659- s2 ^= s -> s [2 ];
1660- s3 ^= s -> s [3 ];
1661- }
1662- engine -> algo -> generate (engine -> state , NULL );
1663- }
1664- }
1665-
1666- s -> s [0 ] = s0 ;
1667- s -> s [1 ] = s1 ;
1668- s -> s [2 ] = s2 ;
1669- s -> s [3 ] = s3 ;
1670- }
1671- /* }}} */
1672-
16731475/* {{{ Construct object */
16741476PHP_METHOD (Random_Randomizer , __construct )
16751477{
@@ -1914,14 +1716,6 @@ PHP_MINIT_FUNCTION(random)
19141716 random_engine_secure_object_handlers .offset = XtOffsetOf (php_random_engine , std );
19151717 random_engine_secure_object_handlers .free_obj = php_random_engine_common_free_obj ;
19161718 random_engine_secure_object_handlers .clone_obj = NULL ;
1917-
1918- /* Random\Engine\Xoshiro256StarStar */
1919- random_ce_Random_Engine_Xoshiro256StarStar = register_class_Random_Engine_Xoshiro256StarStar (random_ce_Random_SeedableEngine , random_ce_Random_SerializableEngine );
1920- random_ce_Random_Engine_Xoshiro256StarStar -> create_object = php_random_engine_xoshiro256starstar_new ;
1921- memcpy (& random_engine_xoshiro256starstar_object_handlers , zend_get_std_object_handlers (), sizeof (zend_object_handlers ));
1922- random_engine_xoshiro256starstar_object_handlers .offset = XtOffsetOf (php_random_engine , std );
1923- random_engine_xoshiro256starstar_object_handlers .free_obj = php_random_engine_common_free_obj ;
1924- random_engine_xoshiro256starstar_object_handlers .clone_obj = php_random_engine_common_clone_obj ;
19251719
19261720 /* Random\Randomizer */
19271721 random_ce_Random_Randomizer = register_class_Random_Randomizer ();
0 commit comments