mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
random: Move CSPRNG API into php_random_csprng.h (#13290)
This allows consumers of just the CSPRNG to include a much smaller header. It also allows to verify at a glance whether a source file might use non-secure randomness. This commit includes the new header wherever the CSPRNG is used, possibly replacing the inclusion of php_random.h if nothing else is used, but also includes it in the main php_random.h header for compatibility. Somewhat related to45f8cfaf10
,2b30f18708
, andb14dd85dca
.
This commit is contained in:
parent
77bc863e50
commit
97b3b4552d
17 changed files with 64 additions and 28 deletions
|
@ -32,6 +32,7 @@
|
|||
# define PHP_RANDOM_H
|
||||
|
||||
# include "php.h"
|
||||
# include "php_random_csprng.h"
|
||||
# include "php_random_uint128.h"
|
||||
|
||||
PHPAPI double php_combined_lcg(void);
|
||||
|
@ -65,29 +66,6 @@ PHPAPI zend_long php_mt_rand_common(zend_long min, zend_long max);
|
|||
PHPAPI void php_srand(zend_long seed);
|
||||
PHPAPI zend_long php_rand(void);
|
||||
|
||||
PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw);
|
||||
PHPAPI zend_result php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw);
|
||||
|
||||
static inline zend_result php_random_bytes_throw(void *bytes, size_t size)
|
||||
{
|
||||
return php_random_bytes(bytes, size, true);
|
||||
}
|
||||
|
||||
static inline zend_result php_random_bytes_silent(void *bytes, size_t size)
|
||||
{
|
||||
return php_random_bytes(bytes, size, false);
|
||||
}
|
||||
|
||||
static inline zend_result php_random_int_throw(zend_long min, zend_long max, zend_long *result)
|
||||
{
|
||||
return php_random_int(min, max, result, true);
|
||||
}
|
||||
|
||||
static inline zend_result php_random_int_silent(zend_long min, zend_long max, zend_long *result)
|
||||
{
|
||||
return php_random_int(min, max, result, false);
|
||||
}
|
||||
|
||||
typedef struct _php_random_status_ {
|
||||
void *state;
|
||||
} php_random_status;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue