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 to 45f8cfaf10,
2b30f18708, and
b14dd85dca.
This commit is contained in:
Tim Düsterhus 2024-02-01 19:09:35 +01:00 committed by GitHub
parent 77bc863e50
commit 97b3b4552d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 64 additions and 28 deletions

View file

@ -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;