Coverage Report

Created: 2026-06-02 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/random/engine_secure.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Authors: Sammy Kaye Powers <me@sammyk.me>                            |
12
   |          Go Kudo <zeriyoshi@php.net>                                 |
13
   +----------------------------------------------------------------------+
14
*/
15
16
#ifdef HAVE_CONFIG_H
17
# include "config.h"
18
#endif
19
20
#include "php.h"
21
#include "php_random.h"
22
#include "php_random_csprng.h"
23
24
#include "Zend/zend_exceptions.h"
25
26
static php_random_result generate(void *state)
27
0
{
28
0
  zend_ulong r = 0;
29
30
0
  php_random_bytes_throw(&r, sizeof(r));
31
32
0
  return (php_random_result){
33
0
    .size = sizeof(zend_ulong),
34
0
    .result = r,
35
0
  };
36
0
}
37
38
static zend_long range(void *state, zend_long min, zend_long max)
39
0
{
40
0
  zend_long result = 0;
41
42
0
  php_random_int_throw(min, max, &result);
43
44
0
  return result;
45
0
}
46
47
PHPAPI const php_random_algo php_random_algo_secure = {
48
  0,
49
  generate,
50
  range,
51
  NULL,
52
  NULL
53
};