mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

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
.
46 lines
1.9 KiB
C
46 lines
1.9 KiB
C
/*
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) The PHP Group |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| https://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
| Authors: Tim Düsterhus <timwolla@php.net> |
|
|
| Go Kudo <zeriyoshi@php.net> |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#ifndef PHP_RANDOM_CSPRNG_H
|
|
# define PHP_RANDOM_CSPRNG_H
|
|
|
|
# include "php.h"
|
|
|
|
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);
|
|
}
|
|
|
|
#endif /* PHP_RANDOM_CSPRNG_H */
|