File: libsodium.php

package info (click to toggle)
php-random-compat 2.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 368 kB
  • sloc: php: 1,104; sh: 48; xml: 30; makefile: 4
file content (90 lines) | stat: -rw-r--r-- 1,885 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

/**
 * This does nothing if the libsodium extension is loaded, so it's harmless.
 *
 * This file alone is released under CC0 and WTFPL dual licensing.
 */
namespace Sodium {
    if (!extension_loaded('libsodium')) {

        /**
         * Generate a string of random bytes
         * /dev/urandom
         *
         * @param int $length
         * @return string
         */
        function randombytes_buf(
            $length
        )
        {
            return '';
        }

        /**
         * Generate a 16-bit integer
         * /dev/urandom
         *
         * @return int
         */
        function randombytes_random16()
        {
            return '';
        }

        /**
         * Generate an unbiased random integer between 0 and a specified value
         * /dev/urandom
         *
         * @param int $upperBoundNonInclusive
         * @return int
         */
        function randombytes_uniform(
            $upperBoundNonInclusive
        )
        {
            return 0;
        }
    }
}
namespace {
    class Sodium
    {

        /**
         * Generate a string of random bytes
         * /dev/urandom
         *
         * @param int $length
         * @return string
         */
        public static function randombytes_buf($length)
        {
            return '';
        }

        /**
         * Generate a 16-bit integer
         * /dev/urandom
         *
         * @return int
         */
        public static function randombytes_random16()
        {
            return '';
        }

        /**
         * Generate an unbiased random integer between 0 and a specified value
         * /dev/urandom
         *
         * @param int $upperBoundNonInclusive
         * @return int
         */
        public static function randombytes_uniform($upperBoundNonInclusive = 0)
        {
            return 0;
        }
    }
}