@@ -27,53 +27,53 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | if (!is_callable('random_bytes')) { |
30 | - /** |
|
31 | - * Powered by ext/mcrypt (and thankfully NOT libmcrypt) |
|
32 | - * |
|
33 | - * @ref https://bugs.php.net/bug.php?id=55169 |
|
34 | - * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386 |
|
35 | - * |
|
36 | - * @param int $bytes |
|
37 | - * |
|
38 | - * @throws Exception |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - function random_bytes($bytes) |
|
43 | - { |
|
44 | - try { |
|
45 | - /** @var int $bytes */ |
|
46 | - $bytes = RandomCompat_intval($bytes); |
|
47 | - } catch (TypeError $ex) { |
|
48 | - throw new TypeError( |
|
49 | - 'random_bytes(): $bytes must be an integer' |
|
50 | - ); |
|
51 | - } |
|
30 | + /** |
|
31 | + * Powered by ext/mcrypt (and thankfully NOT libmcrypt) |
|
32 | + * |
|
33 | + * @ref https://bugs.php.net/bug.php?id=55169 |
|
34 | + * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386 |
|
35 | + * |
|
36 | + * @param int $bytes |
|
37 | + * |
|
38 | + * @throws Exception |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + function random_bytes($bytes) |
|
43 | + { |
|
44 | + try { |
|
45 | + /** @var int $bytes */ |
|
46 | + $bytes = RandomCompat_intval($bytes); |
|
47 | + } catch (TypeError $ex) { |
|
48 | + throw new TypeError( |
|
49 | + 'random_bytes(): $bytes must be an integer' |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - if ($bytes < 1) { |
|
54 | - throw new Error( |
|
55 | - 'Length must be greater than 0' |
|
56 | - ); |
|
57 | - } |
|
53 | + if ($bytes < 1) { |
|
54 | + throw new Error( |
|
55 | + 'Length must be greater than 0' |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** @var string|bool $buf */ |
|
60 | - $buf = @mcrypt_create_iv((int) $bytes, (int) MCRYPT_DEV_URANDOM); |
|
61 | - if ( |
|
62 | - is_string($buf) |
|
63 | - && |
|
64 | - RandomCompat_strlen($buf) === $bytes |
|
65 | - ) { |
|
66 | - /** |
|
67 | - * Return our random entropy buffer here: |
|
68 | - */ |
|
69 | - return $buf; |
|
70 | - } |
|
59 | + /** @var string|bool $buf */ |
|
60 | + $buf = @mcrypt_create_iv((int) $bytes, (int) MCRYPT_DEV_URANDOM); |
|
61 | + if ( |
|
62 | + is_string($buf) |
|
63 | + && |
|
64 | + RandomCompat_strlen($buf) === $bytes |
|
65 | + ) { |
|
66 | + /** |
|
67 | + * Return our random entropy buffer here: |
|
68 | + */ |
|
69 | + return $buf; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * If we reach here, PHP has failed us. |
|
74 | - */ |
|
75 | - throw new Exception( |
|
76 | - 'Could not gather sufficient random data' |
|
77 | - ); |
|
78 | - } |
|
72 | + /** |
|
73 | + * If we reach here, PHP has failed us. |
|
74 | + */ |
|
75 | + throw new Exception( |
|
76 | + 'Could not gather sufficient random data' |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | } |
@@ -27,65 +27,65 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | if (!is_callable('random_bytes')) { |
30 | - /** |
|
31 | - * If the libsodium PHP extension is loaded, we'll use it above any other |
|
32 | - * solution. |
|
33 | - * |
|
34 | - * libsodium-php project: |
|
35 | - * @ref https://github.com/jedisct1/libsodium-php |
|
36 | - * |
|
37 | - * @param int $bytes |
|
38 | - * |
|
39 | - * @throws Exception |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - function random_bytes($bytes) |
|
44 | - { |
|
45 | - try { |
|
46 | - /** @var int $bytes */ |
|
47 | - $bytes = RandomCompat_intval($bytes); |
|
48 | - } catch (TypeError $ex) { |
|
49 | - throw new TypeError( |
|
50 | - 'random_bytes(): $bytes must be an integer' |
|
51 | - ); |
|
52 | - } |
|
30 | + /** |
|
31 | + * If the libsodium PHP extension is loaded, we'll use it above any other |
|
32 | + * solution. |
|
33 | + * |
|
34 | + * libsodium-php project: |
|
35 | + * @ref https://github.com/jedisct1/libsodium-php |
|
36 | + * |
|
37 | + * @param int $bytes |
|
38 | + * |
|
39 | + * @throws Exception |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + function random_bytes($bytes) |
|
44 | + { |
|
45 | + try { |
|
46 | + /** @var int $bytes */ |
|
47 | + $bytes = RandomCompat_intval($bytes); |
|
48 | + } catch (TypeError $ex) { |
|
49 | + throw new TypeError( |
|
50 | + 'random_bytes(): $bytes must be an integer' |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | |
54 | - if ($bytes < 1) { |
|
55 | - throw new Error( |
|
56 | - 'Length must be greater than 0' |
|
57 | - ); |
|
58 | - } |
|
54 | + if ($bytes < 1) { |
|
55 | + throw new Error( |
|
56 | + 'Length must be greater than 0' |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be |
|
62 | - * generated in one invocation. |
|
63 | - */ |
|
64 | - /** @var string|bool $buf */ |
|
65 | - if ($bytes > 2147483647) { |
|
66 | - $buf = ''; |
|
67 | - for ($i = 0; $i < $bytes; $i += 1073741824) { |
|
68 | - $n = ($bytes - $i) > 1073741824 |
|
69 | - ? 1073741824 |
|
70 | - : $bytes - $i; |
|
71 | - $buf .= \Sodium\randombytes_buf($n); |
|
72 | - } |
|
73 | - } else { |
|
74 | - /** @var string|bool $buf */ |
|
75 | - $buf = \Sodium\randombytes_buf($bytes); |
|
76 | - } |
|
60 | + /** |
|
61 | + * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be |
|
62 | + * generated in one invocation. |
|
63 | + */ |
|
64 | + /** @var string|bool $buf */ |
|
65 | + if ($bytes > 2147483647) { |
|
66 | + $buf = ''; |
|
67 | + for ($i = 0; $i < $bytes; $i += 1073741824) { |
|
68 | + $n = ($bytes - $i) > 1073741824 |
|
69 | + ? 1073741824 |
|
70 | + : $bytes - $i; |
|
71 | + $buf .= \Sodium\randombytes_buf($n); |
|
72 | + } |
|
73 | + } else { |
|
74 | + /** @var string|bool $buf */ |
|
75 | + $buf = \Sodium\randombytes_buf($bytes); |
|
76 | + } |
|
77 | 77 | |
78 | - if (is_string($buf)) { |
|
79 | - if (RandomCompat_strlen($buf) === $bytes) { |
|
80 | - return $buf; |
|
81 | - } |
|
82 | - } |
|
78 | + if (is_string($buf)) { |
|
79 | + if (RandomCompat_strlen($buf) === $bytes) { |
|
80 | + return $buf; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * If we reach here, PHP has failed us. |
|
86 | - */ |
|
87 | - throw new Exception( |
|
88 | - 'Could not gather sufficient random data' |
|
89 | - ); |
|
90 | - } |
|
84 | + /** |
|
85 | + * If we reach here, PHP has failed us. |
|
86 | + */ |
|
87 | + throw new Exception( |
|
88 | + 'Could not gather sufficient random data' |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -30,26 +30,26 @@ discard block |
||
30 | 30 | */ |
31 | 31 | |
32 | 32 | if (!defined('PHP_VERSION_ID')) { |
33 | - // This constant was introduced in PHP 5.2.7 |
|
34 | - $RandomCompatversion = array_map('intval', explode('.', PHP_VERSION)); |
|
35 | - define( |
|
36 | - 'PHP_VERSION_ID', |
|
37 | - $RandomCompatversion[0] * 10000 |
|
38 | - + $RandomCompatversion[1] * 100 |
|
39 | - + $RandomCompatversion[2] |
|
40 | - ); |
|
41 | - $RandomCompatversion = null; |
|
33 | + // This constant was introduced in PHP 5.2.7 |
|
34 | + $RandomCompatversion = array_map('intval', explode('.', PHP_VERSION)); |
|
35 | + define( |
|
36 | + 'PHP_VERSION_ID', |
|
37 | + $RandomCompatversion[0] * 10000 |
|
38 | + + $RandomCompatversion[1] * 100 |
|
39 | + + $RandomCompatversion[2] |
|
40 | + ); |
|
41 | + $RandomCompatversion = null; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * PHP 7.0.0 and newer have these functions natively. |
46 | 46 | */ |
47 | 47 | if (PHP_VERSION_ID >= 70000) { |
48 | - return; |
|
48 | + return; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | if (!defined('RANDOM_COMPAT_READ_BUFFER')) { |
52 | - define('RANDOM_COMPAT_READ_BUFFER', 8); |
|
52 | + define('RANDOM_COMPAT_READ_BUFFER', 8); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | $RandomCompatDIR = dirname(__FILE__); |
@@ -59,168 +59,168 @@ discard block |
||
59 | 59 | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'error_polyfill.php'; |
60 | 60 | |
61 | 61 | if (!is_callable('random_bytes')) { |
62 | - /** |
|
63 | - * PHP 5.2.0 - 5.6.x way to implement random_bytes() |
|
64 | - * |
|
65 | - * We use conditional statements here to define the function in accordance |
|
66 | - * to the operating environment. It's a micro-optimization. |
|
67 | - * |
|
68 | - * In order of preference: |
|
69 | - * 1. Use libsodium if available. |
|
70 | - * 2. fread() /dev/urandom if available (never on Windows) |
|
71 | - * 3. mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM) |
|
72 | - * 4. COM('CAPICOM.Utilities.1')->GetRandom() |
|
73 | - * |
|
74 | - * See RATIONALE.md for our reasoning behind this particular order |
|
75 | - */ |
|
76 | - if (extension_loaded('libsodium')) { |
|
77 | - // See random_bytes_libsodium.php |
|
78 | - if (PHP_VERSION_ID >= 50300 && is_callable('\\Sodium\\randombytes_buf')) { |
|
79 | - require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_libsodium.php'; |
|
80 | - } elseif (method_exists('Sodium', 'randombytes_buf')) { |
|
81 | - require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_libsodium_legacy.php'; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Reading directly from /dev/urandom: |
|
87 | - */ |
|
88 | - if (DIRECTORY_SEPARATOR === '/') { |
|
89 | - // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast |
|
90 | - // way to exclude Windows. |
|
91 | - $RandomCompatUrandom = true; |
|
92 | - $RandomCompat_basedir = ini_get('open_basedir'); |
|
93 | - |
|
94 | - if (!empty($RandomCompat_basedir)) { |
|
95 | - $RandomCompat_open_basedir = explode( |
|
96 | - PATH_SEPARATOR, |
|
97 | - strtolower($RandomCompat_basedir) |
|
98 | - ); |
|
99 | - $RandomCompatUrandom = (array() !== array_intersect( |
|
100 | - array('/dev', '/dev/', '/dev/urandom'), |
|
101 | - $RandomCompat_open_basedir |
|
102 | - )); |
|
103 | - $RandomCompat_open_basedir = null; |
|
104 | - } |
|
105 | - |
|
106 | - if ( |
|
107 | - !is_callable('random_bytes') |
|
108 | - && |
|
109 | - $RandomCompatUrandom |
|
110 | - && |
|
111 | - @is_readable('/dev/urandom') |
|
112 | - ) { |
|
113 | - // Error suppression on is_readable() in case of an open_basedir |
|
114 | - // or safe_mode failure. All we care about is whether or not we |
|
115 | - // can read it at this point. If the PHP environment is going to |
|
116 | - // panic over trying to see if the file can be read in the first |
|
117 | - // place, that is not helpful to us here. |
|
118 | - |
|
119 | - // See random_bytes_dev_urandom.php |
|
120 | - require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_dev_urandom.php'; |
|
121 | - } |
|
122 | - // Unset variables after use |
|
123 | - $RandomCompat_basedir = null; |
|
124 | - } else { |
|
125 | - $RandomCompatUrandom = false; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * mcrypt_create_iv() |
|
130 | - * |
|
131 | - * We only want to use mcypt_create_iv() if: |
|
132 | - * |
|
133 | - * - random_bytes() hasn't already been defined |
|
134 | - * - the mcrypt extensions is loaded |
|
135 | - * - One of these two conditions is true: |
|
136 | - * - We're on Windows (DIRECTORY_SEPARATOR !== '/') |
|
137 | - * - We're not on Windows and /dev/urandom is readabale |
|
138 | - * (i.e. we're not in a chroot jail) |
|
139 | - * - Special case: |
|
140 | - * - If we're not on Windows, but the PHP version is between |
|
141 | - * 5.6.10 and 5.6.12, we don't want to use mcrypt. It will |
|
142 | - * hang indefinitely. This is bad. |
|
143 | - * - If we're on Windows, we want to use PHP >= 5.3.7 or else |
|
144 | - * we get insufficient entropy errors. |
|
145 | - */ |
|
146 | - if ( |
|
147 | - !is_callable('random_bytes') |
|
148 | - && |
|
149 | - // Windows on PHP < 5.3.7 is broken, but non-Windows is not known to be. |
|
150 | - (DIRECTORY_SEPARATOR === '/' || PHP_VERSION_ID >= 50307) |
|
151 | - && |
|
152 | - // Prevent this code from hanging indefinitely on non-Windows; |
|
153 | - // see https://bugs.php.net/bug.php?id=69833 |
|
154 | - ( |
|
155 | - DIRECTORY_SEPARATOR !== '/' || |
|
156 | - (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613) |
|
157 | - ) |
|
158 | - && |
|
159 | - extension_loaded('mcrypt') |
|
160 | - ) { |
|
161 | - // See random_bytes_mcrypt.php |
|
162 | - require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_mcrypt.php'; |
|
163 | - } |
|
164 | - $RandomCompatUrandom = null; |
|
165 | - |
|
166 | - /** |
|
167 | - * This is a Windows-specific fallback, for when the mcrypt extension |
|
168 | - * isn't loaded. |
|
169 | - */ |
|
170 | - if ( |
|
171 | - !is_callable('random_bytes') |
|
172 | - && |
|
173 | - extension_loaded('com_dotnet') |
|
174 | - && |
|
175 | - class_exists('COM') |
|
176 | - ) { |
|
177 | - $RandomCompat_disabled_classes = preg_split( |
|
178 | - '#\s*,\s*#', |
|
179 | - strtolower(ini_get('disable_classes')) |
|
180 | - ); |
|
181 | - |
|
182 | - if (!in_array('com', $RandomCompat_disabled_classes)) { |
|
183 | - try { |
|
184 | - $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); |
|
185 | - /** @psalm-suppress TypeDoesNotContainType */ |
|
186 | - if (method_exists($RandomCompatCOMtest, 'GetRandom')) { |
|
187 | - // See random_bytes_com_dotnet.php |
|
188 | - require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_com_dotnet.php'; |
|
189 | - } |
|
190 | - } catch (com_exception $e) { |
|
191 | - // Don't try to use it. |
|
192 | - } |
|
193 | - } |
|
194 | - $RandomCompat_disabled_classes = null; |
|
195 | - $RandomCompatCOMtest = null; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * throw new Exception |
|
200 | - */ |
|
201 | - if (!is_callable('random_bytes')) { |
|
202 | - /** |
|
203 | - * We don't have any more options, so let's throw an exception right now |
|
204 | - * and hope the developer won't let it fail silently. |
|
205 | - * |
|
206 | - * @param mixed $length |
|
207 | - * @psalm-suppress InvalidReturnType |
|
208 | - * @throws Exception |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - function random_bytes($length) |
|
212 | - { |
|
213 | - unset($length); // Suppress "variable not used" warnings. |
|
214 | - throw new Exception( |
|
215 | - 'There is no suitable CSPRNG installed on your system' |
|
216 | - ); |
|
217 | - return ''; |
|
218 | - } |
|
219 | - } |
|
62 | + /** |
|
63 | + * PHP 5.2.0 - 5.6.x way to implement random_bytes() |
|
64 | + * |
|
65 | + * We use conditional statements here to define the function in accordance |
|
66 | + * to the operating environment. It's a micro-optimization. |
|
67 | + * |
|
68 | + * In order of preference: |
|
69 | + * 1. Use libsodium if available. |
|
70 | + * 2. fread() /dev/urandom if available (never on Windows) |
|
71 | + * 3. mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM) |
|
72 | + * 4. COM('CAPICOM.Utilities.1')->GetRandom() |
|
73 | + * |
|
74 | + * See RATIONALE.md for our reasoning behind this particular order |
|
75 | + */ |
|
76 | + if (extension_loaded('libsodium')) { |
|
77 | + // See random_bytes_libsodium.php |
|
78 | + if (PHP_VERSION_ID >= 50300 && is_callable('\\Sodium\\randombytes_buf')) { |
|
79 | + require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_libsodium.php'; |
|
80 | + } elseif (method_exists('Sodium', 'randombytes_buf')) { |
|
81 | + require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_libsodium_legacy.php'; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Reading directly from /dev/urandom: |
|
87 | + */ |
|
88 | + if (DIRECTORY_SEPARATOR === '/') { |
|
89 | + // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast |
|
90 | + // way to exclude Windows. |
|
91 | + $RandomCompatUrandom = true; |
|
92 | + $RandomCompat_basedir = ini_get('open_basedir'); |
|
93 | + |
|
94 | + if (!empty($RandomCompat_basedir)) { |
|
95 | + $RandomCompat_open_basedir = explode( |
|
96 | + PATH_SEPARATOR, |
|
97 | + strtolower($RandomCompat_basedir) |
|
98 | + ); |
|
99 | + $RandomCompatUrandom = (array() !== array_intersect( |
|
100 | + array('/dev', '/dev/', '/dev/urandom'), |
|
101 | + $RandomCompat_open_basedir |
|
102 | + )); |
|
103 | + $RandomCompat_open_basedir = null; |
|
104 | + } |
|
105 | + |
|
106 | + if ( |
|
107 | + !is_callable('random_bytes') |
|
108 | + && |
|
109 | + $RandomCompatUrandom |
|
110 | + && |
|
111 | + @is_readable('/dev/urandom') |
|
112 | + ) { |
|
113 | + // Error suppression on is_readable() in case of an open_basedir |
|
114 | + // or safe_mode failure. All we care about is whether or not we |
|
115 | + // can read it at this point. If the PHP environment is going to |
|
116 | + // panic over trying to see if the file can be read in the first |
|
117 | + // place, that is not helpful to us here. |
|
118 | + |
|
119 | + // See random_bytes_dev_urandom.php |
|
120 | + require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_dev_urandom.php'; |
|
121 | + } |
|
122 | + // Unset variables after use |
|
123 | + $RandomCompat_basedir = null; |
|
124 | + } else { |
|
125 | + $RandomCompatUrandom = false; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * mcrypt_create_iv() |
|
130 | + * |
|
131 | + * We only want to use mcypt_create_iv() if: |
|
132 | + * |
|
133 | + * - random_bytes() hasn't already been defined |
|
134 | + * - the mcrypt extensions is loaded |
|
135 | + * - One of these two conditions is true: |
|
136 | + * - We're on Windows (DIRECTORY_SEPARATOR !== '/') |
|
137 | + * - We're not on Windows and /dev/urandom is readabale |
|
138 | + * (i.e. we're not in a chroot jail) |
|
139 | + * - Special case: |
|
140 | + * - If we're not on Windows, but the PHP version is between |
|
141 | + * 5.6.10 and 5.6.12, we don't want to use mcrypt. It will |
|
142 | + * hang indefinitely. This is bad. |
|
143 | + * - If we're on Windows, we want to use PHP >= 5.3.7 or else |
|
144 | + * we get insufficient entropy errors. |
|
145 | + */ |
|
146 | + if ( |
|
147 | + !is_callable('random_bytes') |
|
148 | + && |
|
149 | + // Windows on PHP < 5.3.7 is broken, but non-Windows is not known to be. |
|
150 | + (DIRECTORY_SEPARATOR === '/' || PHP_VERSION_ID >= 50307) |
|
151 | + && |
|
152 | + // Prevent this code from hanging indefinitely on non-Windows; |
|
153 | + // see https://bugs.php.net/bug.php?id=69833 |
|
154 | + ( |
|
155 | + DIRECTORY_SEPARATOR !== '/' || |
|
156 | + (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613) |
|
157 | + ) |
|
158 | + && |
|
159 | + extension_loaded('mcrypt') |
|
160 | + ) { |
|
161 | + // See random_bytes_mcrypt.php |
|
162 | + require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_mcrypt.php'; |
|
163 | + } |
|
164 | + $RandomCompatUrandom = null; |
|
165 | + |
|
166 | + /** |
|
167 | + * This is a Windows-specific fallback, for when the mcrypt extension |
|
168 | + * isn't loaded. |
|
169 | + */ |
|
170 | + if ( |
|
171 | + !is_callable('random_bytes') |
|
172 | + && |
|
173 | + extension_loaded('com_dotnet') |
|
174 | + && |
|
175 | + class_exists('COM') |
|
176 | + ) { |
|
177 | + $RandomCompat_disabled_classes = preg_split( |
|
178 | + '#\s*,\s*#', |
|
179 | + strtolower(ini_get('disable_classes')) |
|
180 | + ); |
|
181 | + |
|
182 | + if (!in_array('com', $RandomCompat_disabled_classes)) { |
|
183 | + try { |
|
184 | + $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); |
|
185 | + /** @psalm-suppress TypeDoesNotContainType */ |
|
186 | + if (method_exists($RandomCompatCOMtest, 'GetRandom')) { |
|
187 | + // See random_bytes_com_dotnet.php |
|
188 | + require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_com_dotnet.php'; |
|
189 | + } |
|
190 | + } catch (com_exception $e) { |
|
191 | + // Don't try to use it. |
|
192 | + } |
|
193 | + } |
|
194 | + $RandomCompat_disabled_classes = null; |
|
195 | + $RandomCompatCOMtest = null; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * throw new Exception |
|
200 | + */ |
|
201 | + if (!is_callable('random_bytes')) { |
|
202 | + /** |
|
203 | + * We don't have any more options, so let's throw an exception right now |
|
204 | + * and hope the developer won't let it fail silently. |
|
205 | + * |
|
206 | + * @param mixed $length |
|
207 | + * @psalm-suppress InvalidReturnType |
|
208 | + * @throws Exception |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + function random_bytes($length) |
|
212 | + { |
|
213 | + unset($length); // Suppress "variable not used" warnings. |
|
214 | + throw new Exception( |
|
215 | + 'There is no suitable CSPRNG installed on your system' |
|
216 | + ); |
|
217 | + return ''; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | if (!is_callable('random_int')) { |
223 | - require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_int.php'; |
|
223 | + require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_int.php'; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $RandomCompatDIR = null; |
@@ -27,23 +27,23 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | if (!class_exists('Error', false)) { |
30 | - // We can't really avoid making this extend Exception in PHP 5. |
|
31 | - class Error extends Exception |
|
32 | - { |
|
30 | + // We can't really avoid making this extend Exception in PHP 5. |
|
31 | + class Error extends Exception |
|
32 | + { |
|
33 | 33 | |
34 | - } |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | if (!class_exists('TypeError', false)) { |
38 | - if (is_subclass_of('Error', 'Exception')) { |
|
39 | - class TypeError extends Error |
|
40 | - { |
|
38 | + if (is_subclass_of('Error', 'Exception')) { |
|
39 | + class TypeError extends Error |
|
40 | + { |
|
41 | 41 | |
42 | - } |
|
43 | - } else { |
|
44 | - class TypeError extends Exception |
|
45 | - { |
|
42 | + } |
|
43 | + } else { |
|
44 | + class TypeError extends Exception |
|
45 | + { |
|
46 | 46 | |
47 | - } |
|
48 | - } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -27,169 +27,169 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | if (!is_callable('RandomCompat_strlen')) { |
30 | - if ( |
|
31 | - defined('MB_OVERLOAD_STRING') |
|
32 | - && |
|
33 | - ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING |
|
34 | - ) { |
|
35 | - /** |
|
36 | - * strlen() implementation that isn't brittle to mbstring.func_overload |
|
37 | - * |
|
38 | - * This version uses mb_strlen() in '8bit' mode to treat strings as raw |
|
39 | - * binary rather than UTF-8, ISO-8859-1, etc |
|
40 | - * |
|
41 | - * @param string $binary_string |
|
42 | - * |
|
43 | - * @throws TypeError |
|
44 | - * |
|
45 | - * @return int |
|
46 | - */ |
|
47 | - function RandomCompat_strlen($binary_string) |
|
48 | - { |
|
49 | - if (!is_string($binary_string)) { |
|
50 | - throw new TypeError( |
|
51 | - 'RandomCompat_strlen() expects a string' |
|
52 | - ); |
|
53 | - } |
|
30 | + if ( |
|
31 | + defined('MB_OVERLOAD_STRING') |
|
32 | + && |
|
33 | + ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING |
|
34 | + ) { |
|
35 | + /** |
|
36 | + * strlen() implementation that isn't brittle to mbstring.func_overload |
|
37 | + * |
|
38 | + * This version uses mb_strlen() in '8bit' mode to treat strings as raw |
|
39 | + * binary rather than UTF-8, ISO-8859-1, etc |
|
40 | + * |
|
41 | + * @param string $binary_string |
|
42 | + * |
|
43 | + * @throws TypeError |
|
44 | + * |
|
45 | + * @return int |
|
46 | + */ |
|
47 | + function RandomCompat_strlen($binary_string) |
|
48 | + { |
|
49 | + if (!is_string($binary_string)) { |
|
50 | + throw new TypeError( |
|
51 | + 'RandomCompat_strlen() expects a string' |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - return (int) mb_strlen($binary_string, '8bit'); |
|
56 | - } |
|
55 | + return (int) mb_strlen($binary_string, '8bit'); |
|
56 | + } |
|
57 | 57 | |
58 | - } else { |
|
59 | - /** |
|
60 | - * strlen() implementation that isn't brittle to mbstring.func_overload |
|
61 | - * |
|
62 | - * This version just used the default strlen() |
|
63 | - * |
|
64 | - * @param string $binary_string |
|
65 | - * |
|
66 | - * @throws TypeError |
|
67 | - * |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - function RandomCompat_strlen($binary_string) |
|
71 | - { |
|
72 | - if (!is_string($binary_string)) { |
|
73 | - throw new TypeError( |
|
74 | - 'RandomCompat_strlen() expects a string' |
|
75 | - ); |
|
76 | - } |
|
77 | - return (int) strlen($binary_string); |
|
78 | - } |
|
79 | - } |
|
58 | + } else { |
|
59 | + /** |
|
60 | + * strlen() implementation that isn't brittle to mbstring.func_overload |
|
61 | + * |
|
62 | + * This version just used the default strlen() |
|
63 | + * |
|
64 | + * @param string $binary_string |
|
65 | + * |
|
66 | + * @throws TypeError |
|
67 | + * |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + function RandomCompat_strlen($binary_string) |
|
71 | + { |
|
72 | + if (!is_string($binary_string)) { |
|
73 | + throw new TypeError( |
|
74 | + 'RandomCompat_strlen() expects a string' |
|
75 | + ); |
|
76 | + } |
|
77 | + return (int) strlen($binary_string); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | if (!is_callable('RandomCompat_substr')) { |
83 | 83 | |
84 | - if ( |
|
85 | - defined('MB_OVERLOAD_STRING') |
|
86 | - && |
|
87 | - ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING |
|
88 | - ) { |
|
89 | - /** |
|
90 | - * substr() implementation that isn't brittle to mbstring.func_overload |
|
91 | - * |
|
92 | - * This version uses mb_substr() in '8bit' mode to treat strings as raw |
|
93 | - * binary rather than UTF-8, ISO-8859-1, etc |
|
94 | - * |
|
95 | - * @param string $binary_string |
|
96 | - * @param int $start |
|
97 | - * @param int|null $length (optional) |
|
98 | - * |
|
99 | - * @throws TypeError |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function RandomCompat_substr($binary_string, $start, $length = null) |
|
104 | - { |
|
105 | - if (!is_string($binary_string)) { |
|
106 | - throw new TypeError( |
|
107 | - 'RandomCompat_substr(): First argument should be a string' |
|
108 | - ); |
|
109 | - } |
|
84 | + if ( |
|
85 | + defined('MB_OVERLOAD_STRING') |
|
86 | + && |
|
87 | + ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING |
|
88 | + ) { |
|
89 | + /** |
|
90 | + * substr() implementation that isn't brittle to mbstring.func_overload |
|
91 | + * |
|
92 | + * This version uses mb_substr() in '8bit' mode to treat strings as raw |
|
93 | + * binary rather than UTF-8, ISO-8859-1, etc |
|
94 | + * |
|
95 | + * @param string $binary_string |
|
96 | + * @param int $start |
|
97 | + * @param int|null $length (optional) |
|
98 | + * |
|
99 | + * @throws TypeError |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function RandomCompat_substr($binary_string, $start, $length = null) |
|
104 | + { |
|
105 | + if (!is_string($binary_string)) { |
|
106 | + throw new TypeError( |
|
107 | + 'RandomCompat_substr(): First argument should be a string' |
|
108 | + ); |
|
109 | + } |
|
110 | 110 | |
111 | - if (!is_int($start)) { |
|
112 | - throw new TypeError( |
|
113 | - 'RandomCompat_substr(): Second argument should be an integer' |
|
114 | - ); |
|
115 | - } |
|
111 | + if (!is_int($start)) { |
|
112 | + throw new TypeError( |
|
113 | + 'RandomCompat_substr(): Second argument should be an integer' |
|
114 | + ); |
|
115 | + } |
|
116 | 116 | |
117 | - if ($length === null) { |
|
118 | - /** |
|
119 | - * mb_substr($str, 0, NULL, '8bit') returns an empty string on |
|
120 | - * PHP 5.3, so we have to find the length ourselves. |
|
121 | - */ |
|
122 | - /** @var int $length */ |
|
123 | - $length = RandomCompat_strlen($binary_string) - $start; |
|
124 | - } elseif (!is_int($length)) { |
|
125 | - throw new TypeError( |
|
126 | - 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
|
127 | - ); |
|
128 | - } |
|
117 | + if ($length === null) { |
|
118 | + /** |
|
119 | + * mb_substr($str, 0, NULL, '8bit') returns an empty string on |
|
120 | + * PHP 5.3, so we have to find the length ourselves. |
|
121 | + */ |
|
122 | + /** @var int $length */ |
|
123 | + $length = RandomCompat_strlen($binary_string) - $start; |
|
124 | + } elseif (!is_int($length)) { |
|
125 | + throw new TypeError( |
|
126 | + 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
|
127 | + ); |
|
128 | + } |
|
129 | 129 | |
130 | - // Consistency with PHP's behavior |
|
131 | - if ($start === RandomCompat_strlen($binary_string) && $length === 0) { |
|
132 | - return ''; |
|
133 | - } |
|
134 | - if ($start > RandomCompat_strlen($binary_string)) { |
|
135 | - return ''; |
|
136 | - } |
|
130 | + // Consistency with PHP's behavior |
|
131 | + if ($start === RandomCompat_strlen($binary_string) && $length === 0) { |
|
132 | + return ''; |
|
133 | + } |
|
134 | + if ($start > RandomCompat_strlen($binary_string)) { |
|
135 | + return ''; |
|
136 | + } |
|
137 | 137 | |
138 | - return (string) mb_substr( |
|
139 | - (string) $binary_string, |
|
140 | - (int) $start, |
|
141 | - (int) $length, |
|
142 | - '8bit' |
|
143 | - ); |
|
144 | - } |
|
138 | + return (string) mb_substr( |
|
139 | + (string) $binary_string, |
|
140 | + (int) $start, |
|
141 | + (int) $length, |
|
142 | + '8bit' |
|
143 | + ); |
|
144 | + } |
|
145 | 145 | |
146 | - } else { |
|
146 | + } else { |
|
147 | 147 | |
148 | - /** |
|
149 | - * substr() implementation that isn't brittle to mbstring.func_overload |
|
150 | - * |
|
151 | - * This version just uses the default substr() |
|
152 | - * |
|
153 | - * @param string $binary_string |
|
154 | - * @param int $start |
|
155 | - * @param int|null $length (optional) |
|
156 | - * |
|
157 | - * @throws TypeError |
|
158 | - * |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - function RandomCompat_substr($binary_string, $start, $length = null) |
|
162 | - { |
|
163 | - if (!is_string($binary_string)) { |
|
164 | - throw new TypeError( |
|
165 | - 'RandomCompat_substr(): First argument should be a string' |
|
166 | - ); |
|
167 | - } |
|
148 | + /** |
|
149 | + * substr() implementation that isn't brittle to mbstring.func_overload |
|
150 | + * |
|
151 | + * This version just uses the default substr() |
|
152 | + * |
|
153 | + * @param string $binary_string |
|
154 | + * @param int $start |
|
155 | + * @param int|null $length (optional) |
|
156 | + * |
|
157 | + * @throws TypeError |
|
158 | + * |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + function RandomCompat_substr($binary_string, $start, $length = null) |
|
162 | + { |
|
163 | + if (!is_string($binary_string)) { |
|
164 | + throw new TypeError( |
|
165 | + 'RandomCompat_substr(): First argument should be a string' |
|
166 | + ); |
|
167 | + } |
|
168 | 168 | |
169 | - if (!is_int($start)) { |
|
170 | - throw new TypeError( |
|
171 | - 'RandomCompat_substr(): Second argument should be an integer' |
|
172 | - ); |
|
173 | - } |
|
169 | + if (!is_int($start)) { |
|
170 | + throw new TypeError( |
|
171 | + 'RandomCompat_substr(): Second argument should be an integer' |
|
172 | + ); |
|
173 | + } |
|
174 | 174 | |
175 | - if ($length !== null) { |
|
176 | - if (!is_int($length)) { |
|
177 | - throw new TypeError( |
|
178 | - 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
|
179 | - ); |
|
180 | - } |
|
175 | + if ($length !== null) { |
|
176 | + if (!is_int($length)) { |
|
177 | + throw new TypeError( |
|
178 | + 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
|
179 | + ); |
|
180 | + } |
|
181 | 181 | |
182 | - return (string) substr( |
|
183 | - (string )$binary_string, |
|
184 | - (int) $start, |
|
185 | - (int) $length |
|
186 | - ); |
|
187 | - } |
|
182 | + return (string) substr( |
|
183 | + (string )$binary_string, |
|
184 | + (int) $start, |
|
185 | + (int) $length |
|
186 | + ); |
|
187 | + } |
|
188 | 188 | |
189 | - return (string) substr( |
|
190 | - (string) $binary_string, |
|
191 | - (int) $start |
|
192 | - ); |
|
193 | - } |
|
194 | - } |
|
189 | + return (string) substr( |
|
190 | + (string) $binary_string, |
|
191 | + (int) $start |
|
192 | + ); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | } |
@@ -27,65 +27,65 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | if (!is_callable('random_bytes')) { |
30 | - /** |
|
31 | - * Windows with PHP < 5.3.0 will not have the function |
|
32 | - * openssl_random_pseudo_bytes() available, so let's use |
|
33 | - * CAPICOM to work around this deficiency. |
|
34 | - * |
|
35 | - * @param int $bytes |
|
36 | - * |
|
37 | - * @throws Exception |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - function random_bytes($bytes) |
|
42 | - { |
|
43 | - try { |
|
44 | - /** @var int $bytes */ |
|
45 | - $bytes = RandomCompat_intval($bytes); |
|
46 | - } catch (TypeError $ex) { |
|
47 | - throw new TypeError( |
|
48 | - 'random_bytes(): $bytes must be an integer' |
|
49 | - ); |
|
50 | - } |
|
30 | + /** |
|
31 | + * Windows with PHP < 5.3.0 will not have the function |
|
32 | + * openssl_random_pseudo_bytes() available, so let's use |
|
33 | + * CAPICOM to work around this deficiency. |
|
34 | + * |
|
35 | + * @param int $bytes |
|
36 | + * |
|
37 | + * @throws Exception |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + function random_bytes($bytes) |
|
42 | + { |
|
43 | + try { |
|
44 | + /** @var int $bytes */ |
|
45 | + $bytes = RandomCompat_intval($bytes); |
|
46 | + } catch (TypeError $ex) { |
|
47 | + throw new TypeError( |
|
48 | + 'random_bytes(): $bytes must be an integer' |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | |
52 | - if ($bytes < 1) { |
|
53 | - throw new Error( |
|
54 | - 'Length must be greater than 0' |
|
55 | - ); |
|
56 | - } |
|
52 | + if ($bytes < 1) { |
|
53 | + throw new Error( |
|
54 | + 'Length must be greater than 0' |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** @var string $buf */ |
|
59 | - $buf = ''; |
|
60 | - if (!class_exists('COM')) { |
|
61 | - throw new Error( |
|
62 | - 'COM does not exist' |
|
63 | - ); |
|
64 | - } |
|
65 | - /** @var COM $util */ |
|
66 | - $util = new COM('CAPICOM.Utilities.1'); |
|
67 | - $execCount = 0; |
|
58 | + /** @var string $buf */ |
|
59 | + $buf = ''; |
|
60 | + if (!class_exists('COM')) { |
|
61 | + throw new Error( |
|
62 | + 'COM does not exist' |
|
63 | + ); |
|
64 | + } |
|
65 | + /** @var COM $util */ |
|
66 | + $util = new COM('CAPICOM.Utilities.1'); |
|
67 | + $execCount = 0; |
|
68 | 68 | |
69 | - /** |
|
70 | - * Let's not let it loop forever. If we run N times and fail to |
|
71 | - * get N bytes of random data, then CAPICOM has failed us. |
|
72 | - */ |
|
73 | - do { |
|
74 | - $buf .= base64_decode((string) $util->GetRandom($bytes, 0)); |
|
75 | - if (RandomCompat_strlen($buf) >= $bytes) { |
|
76 | - /** |
|
77 | - * Return our random entropy buffer here: |
|
78 | - */ |
|
79 | - return (string) RandomCompat_substr($buf, 0, $bytes); |
|
80 | - } |
|
81 | - ++$execCount; |
|
82 | - } while ($execCount < $bytes); |
|
69 | + /** |
|
70 | + * Let's not let it loop forever. If we run N times and fail to |
|
71 | + * get N bytes of random data, then CAPICOM has failed us. |
|
72 | + */ |
|
73 | + do { |
|
74 | + $buf .= base64_decode((string) $util->GetRandom($bytes, 0)); |
|
75 | + if (RandomCompat_strlen($buf) >= $bytes) { |
|
76 | + /** |
|
77 | + * Return our random entropy buffer here: |
|
78 | + */ |
|
79 | + return (string) RandomCompat_substr($buf, 0, $bytes); |
|
80 | + } |
|
81 | + ++$execCount; |
|
82 | + } while ($execCount < $bytes); |
|
83 | 83 | |
84 | - /** |
|
85 | - * If we reach here, PHP has failed us. |
|
86 | - */ |
|
87 | - throw new Exception( |
|
88 | - 'Could not gather sufficient random data' |
|
89 | - ); |
|
90 | - } |
|
84 | + /** |
|
85 | + * If we reach here, PHP has failed us. |
|
86 | + */ |
|
87 | + throw new Exception( |
|
88 | + 'Could not gather sufficient random data' |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -13,815 +13,815 @@ |
||
13 | 13 | * method. |
14 | 14 | */ |
15 | 15 | if (!is_callable('\\Sodium\\bin2hex')) { |
16 | - /** |
|
17 | - * @see ParagonIE_Sodium_Compat::bin2hex() |
|
18 | - * @param string $string |
|
19 | - * @return string |
|
20 | - * @throws \SodiumException |
|
21 | - * @throws \TypeError |
|
22 | - */ |
|
23 | - function bin2hex($string) |
|
24 | - { |
|
25 | - return ParagonIE_Sodium_Compat::bin2hex($string); |
|
26 | - } |
|
16 | + /** |
|
17 | + * @see ParagonIE_Sodium_Compat::bin2hex() |
|
18 | + * @param string $string |
|
19 | + * @return string |
|
20 | + * @throws \SodiumException |
|
21 | + * @throws \TypeError |
|
22 | + */ |
|
23 | + function bin2hex($string) |
|
24 | + { |
|
25 | + return ParagonIE_Sodium_Compat::bin2hex($string); |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | if (!is_callable('\\Sodium\\compare')) { |
29 | - /** |
|
30 | - * @see ParagonIE_Sodium_Compat::compare() |
|
31 | - * @param string $a |
|
32 | - * @param string $b |
|
33 | - * @return int |
|
34 | - * @throws \SodiumException |
|
35 | - * @throws \TypeError |
|
36 | - */ |
|
37 | - function compare($a, $b) |
|
38 | - { |
|
39 | - return ParagonIE_Sodium_Compat::compare($a, $b); |
|
40 | - } |
|
29 | + /** |
|
30 | + * @see ParagonIE_Sodium_Compat::compare() |
|
31 | + * @param string $a |
|
32 | + * @param string $b |
|
33 | + * @return int |
|
34 | + * @throws \SodiumException |
|
35 | + * @throws \TypeError |
|
36 | + */ |
|
37 | + function compare($a, $b) |
|
38 | + { |
|
39 | + return ParagonIE_Sodium_Compat::compare($a, $b); |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_decrypt')) { |
43 | - /** |
|
44 | - * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() |
|
45 | - * @param string $message |
|
46 | - * @param string $assocData |
|
47 | - * @param string $nonce |
|
48 | - * @param string $key |
|
49 | - * @return string|bool |
|
50 | - */ |
|
51 | - function crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) |
|
52 | - { |
|
53 | - try { |
|
54 | - return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); |
|
55 | - } catch (\TypeError $ex) { |
|
56 | - return false; |
|
57 | - } catch (\SodiumException $ex) { |
|
58 | - return false; |
|
59 | - } |
|
60 | - } |
|
43 | + /** |
|
44 | + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() |
|
45 | + * @param string $message |
|
46 | + * @param string $assocData |
|
47 | + * @param string $nonce |
|
48 | + * @param string $key |
|
49 | + * @return string|bool |
|
50 | + */ |
|
51 | + function crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) |
|
52 | + { |
|
53 | + try { |
|
54 | + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); |
|
55 | + } catch (\TypeError $ex) { |
|
56 | + return false; |
|
57 | + } catch (\SodiumException $ex) { |
|
58 | + return false; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_encrypt')) { |
63 | - /** |
|
64 | - * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() |
|
65 | - * @param string $message |
|
66 | - * @param string $assocData |
|
67 | - * @param string $nonce |
|
68 | - * @param string $key |
|
69 | - * @return string |
|
70 | - * @throws \SodiumException |
|
71 | - * @throws \TypeError |
|
72 | - */ |
|
73 | - function crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key) |
|
74 | - { |
|
75 | - return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); |
|
76 | - } |
|
63 | + /** |
|
64 | + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() |
|
65 | + * @param string $message |
|
66 | + * @param string $assocData |
|
67 | + * @param string $nonce |
|
68 | + * @param string $key |
|
69 | + * @return string |
|
70 | + * @throws \SodiumException |
|
71 | + * @throws \TypeError |
|
72 | + */ |
|
73 | + function crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key) |
|
74 | + { |
|
75 | + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); |
|
76 | + } |
|
77 | 77 | } |
78 | 78 | if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_is_available')) { |
79 | - /** |
|
80 | - * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - function crypto_aead_aes256gcm_is_available() |
|
84 | - { |
|
85 | - return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); |
|
86 | - } |
|
79 | + /** |
|
80 | + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + function crypto_aead_aes256gcm_is_available() |
|
84 | + { |
|
85 | + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_decrypt')) { |
89 | - /** |
|
90 | - * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() |
|
91 | - * @param string $message |
|
92 | - * @param string $assocData |
|
93 | - * @param string $nonce |
|
94 | - * @param string $key |
|
95 | - * @return string|bool |
|
96 | - */ |
|
97 | - function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) |
|
98 | - { |
|
99 | - try { |
|
100 | - return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key); |
|
101 | - } catch (\TypeError $ex) { |
|
102 | - return false; |
|
103 | - } catch (\SodiumException $ex) { |
|
104 | - return false; |
|
105 | - } |
|
106 | - } |
|
89 | + /** |
|
90 | + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() |
|
91 | + * @param string $message |
|
92 | + * @param string $assocData |
|
93 | + * @param string $nonce |
|
94 | + * @param string $key |
|
95 | + * @return string|bool |
|
96 | + */ |
|
97 | + function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) |
|
98 | + { |
|
99 | + try { |
|
100 | + return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key); |
|
101 | + } catch (\TypeError $ex) { |
|
102 | + return false; |
|
103 | + } catch (\SodiumException $ex) { |
|
104 | + return false; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | } |
108 | 108 | if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_encrypt')) { |
109 | - /** |
|
110 | - * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() |
|
111 | - * @param string $message |
|
112 | - * @param string $assocData |
|
113 | - * @param string $nonce |
|
114 | - * @param string $key |
|
115 | - * @return string |
|
116 | - * @throws \SodiumException |
|
117 | - * @throws \TypeError |
|
118 | - */ |
|
119 | - function crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key) |
|
120 | - { |
|
121 | - return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key); |
|
122 | - } |
|
109 | + /** |
|
110 | + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() |
|
111 | + * @param string $message |
|
112 | + * @param string $assocData |
|
113 | + * @param string $nonce |
|
114 | + * @param string $key |
|
115 | + * @return string |
|
116 | + * @throws \SodiumException |
|
117 | + * @throws \TypeError |
|
118 | + */ |
|
119 | + function crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key) |
|
120 | + { |
|
121 | + return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key); |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_decrypt')) { |
125 | - /** |
|
126 | - * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() |
|
127 | - * @param string $message |
|
128 | - * @param string $assocData |
|
129 | - * @param string $nonce |
|
130 | - * @param string $key |
|
131 | - * @return string|bool |
|
132 | - */ |
|
133 | - function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) |
|
134 | - { |
|
135 | - try { |
|
136 | - return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key); |
|
137 | - } catch (\TypeError $ex) { |
|
138 | - return false; |
|
139 | - } catch (\SodiumException $ex) { |
|
140 | - return false; |
|
141 | - } |
|
142 | - } |
|
125 | + /** |
|
126 | + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() |
|
127 | + * @param string $message |
|
128 | + * @param string $assocData |
|
129 | + * @param string $nonce |
|
130 | + * @param string $key |
|
131 | + * @return string|bool |
|
132 | + */ |
|
133 | + function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) |
|
134 | + { |
|
135 | + try { |
|
136 | + return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key); |
|
137 | + } catch (\TypeError $ex) { |
|
138 | + return false; |
|
139 | + } catch (\SodiumException $ex) { |
|
140 | + return false; |
|
141 | + } |
|
142 | + } |
|
143 | 143 | } |
144 | 144 | if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_encrypt')) { |
145 | - /** |
|
146 | - * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() |
|
147 | - * @param string $message |
|
148 | - * @param string $assocData |
|
149 | - * @param string $nonce |
|
150 | - * @param string $key |
|
151 | - * @return string |
|
152 | - * @throws \SodiumException |
|
153 | - * @throws \TypeError |
|
154 | - */ |
|
155 | - function crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) |
|
156 | - { |
|
157 | - return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); |
|
158 | - } |
|
145 | + /** |
|
146 | + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() |
|
147 | + * @param string $message |
|
148 | + * @param string $assocData |
|
149 | + * @param string $nonce |
|
150 | + * @param string $key |
|
151 | + * @return string |
|
152 | + * @throws \SodiumException |
|
153 | + * @throws \TypeError |
|
154 | + */ |
|
155 | + function crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) |
|
156 | + { |
|
157 | + return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | if (!is_callable('\\Sodium\\crypto_auth')) { |
161 | - /** |
|
162 | - * @see ParagonIE_Sodium_Compat::crypto_auth() |
|
163 | - * @param string $message |
|
164 | - * @param string $key |
|
165 | - * @return string |
|
166 | - * @throws \SodiumException |
|
167 | - * @throws \TypeError |
|
168 | - */ |
|
169 | - function crypto_auth($message, $key) |
|
170 | - { |
|
171 | - return ParagonIE_Sodium_Compat::crypto_auth($message, $key); |
|
172 | - } |
|
161 | + /** |
|
162 | + * @see ParagonIE_Sodium_Compat::crypto_auth() |
|
163 | + * @param string $message |
|
164 | + * @param string $key |
|
165 | + * @return string |
|
166 | + * @throws \SodiumException |
|
167 | + * @throws \TypeError |
|
168 | + */ |
|
169 | + function crypto_auth($message, $key) |
|
170 | + { |
|
171 | + return ParagonIE_Sodium_Compat::crypto_auth($message, $key); |
|
172 | + } |
|
173 | 173 | } |
174 | 174 | if (!is_callable('\\Sodium\\crypto_auth_verify')) { |
175 | - /** |
|
176 | - * @see ParagonIE_Sodium_Compat::crypto_auth_verify() |
|
177 | - * @param string $mac |
|
178 | - * @param string $message |
|
179 | - * @param string $key |
|
180 | - * @return bool |
|
181 | - * @throws \SodiumException |
|
182 | - * @throws \TypeError |
|
183 | - */ |
|
184 | - function crypto_auth_verify($mac, $message, $key) |
|
185 | - { |
|
186 | - return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); |
|
187 | - } |
|
175 | + /** |
|
176 | + * @see ParagonIE_Sodium_Compat::crypto_auth_verify() |
|
177 | + * @param string $mac |
|
178 | + * @param string $message |
|
179 | + * @param string $key |
|
180 | + * @return bool |
|
181 | + * @throws \SodiumException |
|
182 | + * @throws \TypeError |
|
183 | + */ |
|
184 | + function crypto_auth_verify($mac, $message, $key) |
|
185 | + { |
|
186 | + return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); |
|
187 | + } |
|
188 | 188 | } |
189 | 189 | if (!is_callable('\\Sodium\\crypto_box')) { |
190 | - /** |
|
191 | - * @see ParagonIE_Sodium_Compat::crypto_box() |
|
192 | - * @param string $message |
|
193 | - * @param string $nonce |
|
194 | - * @param string $kp |
|
195 | - * @return string |
|
196 | - * @throws \SodiumException |
|
197 | - * @throws \TypeError |
|
198 | - */ |
|
199 | - function crypto_box($message, $nonce, $kp) |
|
200 | - { |
|
201 | - return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp); |
|
202 | - } |
|
190 | + /** |
|
191 | + * @see ParagonIE_Sodium_Compat::crypto_box() |
|
192 | + * @param string $message |
|
193 | + * @param string $nonce |
|
194 | + * @param string $kp |
|
195 | + * @return string |
|
196 | + * @throws \SodiumException |
|
197 | + * @throws \TypeError |
|
198 | + */ |
|
199 | + function crypto_box($message, $nonce, $kp) |
|
200 | + { |
|
201 | + return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp); |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | if (!is_callable('\\Sodium\\crypto_box_keypair')) { |
205 | - /** |
|
206 | - * @see ParagonIE_Sodium_Compat::crypto_box_keypair() |
|
207 | - * @return string |
|
208 | - * @throws \SodiumException |
|
209 | - * @throws \TypeError |
|
210 | - */ |
|
211 | - function crypto_box_keypair() |
|
212 | - { |
|
213 | - return ParagonIE_Sodium_Compat::crypto_box_keypair(); |
|
214 | - } |
|
205 | + /** |
|
206 | + * @see ParagonIE_Sodium_Compat::crypto_box_keypair() |
|
207 | + * @return string |
|
208 | + * @throws \SodiumException |
|
209 | + * @throws \TypeError |
|
210 | + */ |
|
211 | + function crypto_box_keypair() |
|
212 | + { |
|
213 | + return ParagonIE_Sodium_Compat::crypto_box_keypair(); |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | if (!is_callable('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey')) { |
217 | - /** |
|
218 | - * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() |
|
219 | - * @param string $sk |
|
220 | - * @param string $pk |
|
221 | - * @return string |
|
222 | - * @throws \SodiumException |
|
223 | - * @throws \TypeError |
|
224 | - */ |
|
225 | - function crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) |
|
226 | - { |
|
227 | - return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk); |
|
228 | - } |
|
217 | + /** |
|
218 | + * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() |
|
219 | + * @param string $sk |
|
220 | + * @param string $pk |
|
221 | + * @return string |
|
222 | + * @throws \SodiumException |
|
223 | + * @throws \TypeError |
|
224 | + */ |
|
225 | + function crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) |
|
226 | + { |
|
227 | + return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk); |
|
228 | + } |
|
229 | 229 | } |
230 | 230 | if (!is_callable('\\Sodium\\crypto_box_open')) { |
231 | - /** |
|
232 | - * @see ParagonIE_Sodium_Compat::crypto_box_open() |
|
233 | - * @param string $message |
|
234 | - * @param string $nonce |
|
235 | - * @param string $kp |
|
236 | - * @return string|bool |
|
237 | - */ |
|
238 | - function crypto_box_open($message, $nonce, $kp) |
|
239 | - { |
|
240 | - try { |
|
241 | - return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp); |
|
242 | - } catch (\TypeError $ex) { |
|
243 | - return false; |
|
244 | - } catch (\SodiumException $ex) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - } |
|
231 | + /** |
|
232 | + * @see ParagonIE_Sodium_Compat::crypto_box_open() |
|
233 | + * @param string $message |
|
234 | + * @param string $nonce |
|
235 | + * @param string $kp |
|
236 | + * @return string|bool |
|
237 | + */ |
|
238 | + function crypto_box_open($message, $nonce, $kp) |
|
239 | + { |
|
240 | + try { |
|
241 | + return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp); |
|
242 | + } catch (\TypeError $ex) { |
|
243 | + return false; |
|
244 | + } catch (\SodiumException $ex) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + } |
|
248 | 248 | } |
249 | 249 | if (!is_callable('\\Sodium\\crypto_box_publickey')) { |
250 | - /** |
|
251 | - * @see ParagonIE_Sodium_Compat::crypto_box_publickey() |
|
252 | - * @param string $keypair |
|
253 | - * @return string |
|
254 | - * @throws \SodiumException |
|
255 | - * @throws \TypeError |
|
256 | - */ |
|
257 | - function crypto_box_publickey($keypair) |
|
258 | - { |
|
259 | - return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair); |
|
260 | - } |
|
250 | + /** |
|
251 | + * @see ParagonIE_Sodium_Compat::crypto_box_publickey() |
|
252 | + * @param string $keypair |
|
253 | + * @return string |
|
254 | + * @throws \SodiumException |
|
255 | + * @throws \TypeError |
|
256 | + */ |
|
257 | + function crypto_box_publickey($keypair) |
|
258 | + { |
|
259 | + return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair); |
|
260 | + } |
|
261 | 261 | } |
262 | 262 | if (!is_callable('\\Sodium\\crypto_box_publickey_from_secretkey')) { |
263 | - /** |
|
264 | - * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() |
|
265 | - * @param string $sk |
|
266 | - * @return string |
|
267 | - * @throws \SodiumException |
|
268 | - * @throws \TypeError |
|
269 | - */ |
|
270 | - function crypto_box_publickey_from_secretkey($sk) |
|
271 | - { |
|
272 | - return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk); |
|
273 | - } |
|
263 | + /** |
|
264 | + * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() |
|
265 | + * @param string $sk |
|
266 | + * @return string |
|
267 | + * @throws \SodiumException |
|
268 | + * @throws \TypeError |
|
269 | + */ |
|
270 | + function crypto_box_publickey_from_secretkey($sk) |
|
271 | + { |
|
272 | + return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk); |
|
273 | + } |
|
274 | 274 | } |
275 | 275 | if (!is_callable('\\Sodium\\crypto_box_seal')) { |
276 | - /** |
|
277 | - * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
278 | - * @param string $message |
|
279 | - * @param string $publicKey |
|
280 | - * @return string |
|
281 | - * @throws \SodiumException |
|
282 | - * @throws \TypeError |
|
283 | - */ |
|
284 | - function crypto_box_seal($message, $publicKey) |
|
285 | - { |
|
286 | - return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey); |
|
287 | - } |
|
276 | + /** |
|
277 | + * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
278 | + * @param string $message |
|
279 | + * @param string $publicKey |
|
280 | + * @return string |
|
281 | + * @throws \SodiumException |
|
282 | + * @throws \TypeError |
|
283 | + */ |
|
284 | + function crypto_box_seal($message, $publicKey) |
|
285 | + { |
|
286 | + return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey); |
|
287 | + } |
|
288 | 288 | } |
289 | 289 | if (!is_callable('\\Sodium\\crypto_box_seal_open')) { |
290 | - /** |
|
291 | - * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
292 | - * @param string $message |
|
293 | - * @param string $kp |
|
294 | - * @return string|bool |
|
295 | - */ |
|
296 | - function crypto_box_seal_open($message, $kp) |
|
297 | - { |
|
298 | - try { |
|
299 | - return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp); |
|
300 | - } catch (\TypeError $ex) { |
|
301 | - return false; |
|
302 | - } catch (\SodiumException $ex) { |
|
303 | - return false; |
|
304 | - } |
|
305 | - } |
|
290 | + /** |
|
291 | + * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
292 | + * @param string $message |
|
293 | + * @param string $kp |
|
294 | + * @return string|bool |
|
295 | + */ |
|
296 | + function crypto_box_seal_open($message, $kp) |
|
297 | + { |
|
298 | + try { |
|
299 | + return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp); |
|
300 | + } catch (\TypeError $ex) { |
|
301 | + return false; |
|
302 | + } catch (\SodiumException $ex) { |
|
303 | + return false; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | } |
307 | 307 | if (!is_callable('\\Sodium\\crypto_box_secretkey')) { |
308 | - /** |
|
309 | - * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() |
|
310 | - * @param string $keypair |
|
311 | - * @return string |
|
312 | - * @throws \SodiumException |
|
313 | - * @throws \TypeError |
|
314 | - */ |
|
315 | - function crypto_box_secretkey($keypair) |
|
316 | - { |
|
317 | - return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair); |
|
318 | - } |
|
308 | + /** |
|
309 | + * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() |
|
310 | + * @param string $keypair |
|
311 | + * @return string |
|
312 | + * @throws \SodiumException |
|
313 | + * @throws \TypeError |
|
314 | + */ |
|
315 | + function crypto_box_secretkey($keypair) |
|
316 | + { |
|
317 | + return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair); |
|
318 | + } |
|
319 | 319 | } |
320 | 320 | if (!is_callable('\\Sodium\\crypto_generichash')) { |
321 | - /** |
|
322 | - * @see ParagonIE_Sodium_Compat::crypto_generichash() |
|
323 | - * @param string $message |
|
324 | - * @param string|null $key |
|
325 | - * @param int $outLen |
|
326 | - * @return string |
|
327 | - * @throws \SodiumException |
|
328 | - * @throws \TypeError |
|
329 | - */ |
|
330 | - function crypto_generichash($message, $key = null, $outLen = 32) |
|
331 | - { |
|
332 | - return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen); |
|
333 | - } |
|
321 | + /** |
|
322 | + * @see ParagonIE_Sodium_Compat::crypto_generichash() |
|
323 | + * @param string $message |
|
324 | + * @param string|null $key |
|
325 | + * @param int $outLen |
|
326 | + * @return string |
|
327 | + * @throws \SodiumException |
|
328 | + * @throws \TypeError |
|
329 | + */ |
|
330 | + function crypto_generichash($message, $key = null, $outLen = 32) |
|
331 | + { |
|
332 | + return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen); |
|
333 | + } |
|
334 | 334 | } |
335 | 335 | if (!is_callable('\\Sodium\\crypto_generichash_final')) { |
336 | - /** |
|
337 | - * @see ParagonIE_Sodium_Compat::crypto_generichash_final() |
|
338 | - * @param string|null $ctx |
|
339 | - * @param int $outputLength |
|
340 | - * @return string |
|
341 | - * @throws \SodiumException |
|
342 | - * @throws \TypeError |
|
343 | - */ |
|
344 | - function crypto_generichash_final(&$ctx, $outputLength = 32) |
|
345 | - { |
|
346 | - return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength); |
|
347 | - } |
|
336 | + /** |
|
337 | + * @see ParagonIE_Sodium_Compat::crypto_generichash_final() |
|
338 | + * @param string|null $ctx |
|
339 | + * @param int $outputLength |
|
340 | + * @return string |
|
341 | + * @throws \SodiumException |
|
342 | + * @throws \TypeError |
|
343 | + */ |
|
344 | + function crypto_generichash_final(&$ctx, $outputLength = 32) |
|
345 | + { |
|
346 | + return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength); |
|
347 | + } |
|
348 | 348 | } |
349 | 349 | if (!is_callable('\\Sodium\\crypto_generichash_init')) { |
350 | - /** |
|
351 | - * @see ParagonIE_Sodium_Compat::crypto_generichash_init() |
|
352 | - * @param string|null $key |
|
353 | - * @param int $outLen |
|
354 | - * @return string |
|
355 | - * @throws \SodiumException |
|
356 | - * @throws \TypeError |
|
357 | - */ |
|
358 | - function crypto_generichash_init($key = null, $outLen = 32) |
|
359 | - { |
|
360 | - return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen); |
|
361 | - } |
|
350 | + /** |
|
351 | + * @see ParagonIE_Sodium_Compat::crypto_generichash_init() |
|
352 | + * @param string|null $key |
|
353 | + * @param int $outLen |
|
354 | + * @return string |
|
355 | + * @throws \SodiumException |
|
356 | + * @throws \TypeError |
|
357 | + */ |
|
358 | + function crypto_generichash_init($key = null, $outLen = 32) |
|
359 | + { |
|
360 | + return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen); |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | if (!is_callable('\\Sodium\\crypto_generichash_update')) { |
364 | - /** |
|
365 | - * @see ParagonIE_Sodium_Compat::crypto_generichash_update() |
|
366 | - * @param string|null $ctx |
|
367 | - * @param string $message |
|
368 | - * @return void |
|
369 | - * @throws \SodiumException |
|
370 | - * @throws \TypeError |
|
371 | - */ |
|
372 | - function crypto_generichash_update(&$ctx, $message = '') |
|
373 | - { |
|
374 | - ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message); |
|
375 | - } |
|
364 | + /** |
|
365 | + * @see ParagonIE_Sodium_Compat::crypto_generichash_update() |
|
366 | + * @param string|null $ctx |
|
367 | + * @param string $message |
|
368 | + * @return void |
|
369 | + * @throws \SodiumException |
|
370 | + * @throws \TypeError |
|
371 | + */ |
|
372 | + function crypto_generichash_update(&$ctx, $message = '') |
|
373 | + { |
|
374 | + ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message); |
|
375 | + } |
|
376 | 376 | } |
377 | 377 | if (!is_callable('\\Sodium\\crypto_kx')) { |
378 | - /** |
|
379 | - * @see ParagonIE_Sodium_Compat::crypto_kx() |
|
380 | - * @param string $my_secret |
|
381 | - * @param string $their_public |
|
382 | - * @param string $client_public |
|
383 | - * @param string $server_public |
|
384 | - * @return string |
|
385 | - * @throws \SodiumException |
|
386 | - * @throws \TypeError |
|
387 | - */ |
|
388 | - function crypto_kx($my_secret, $their_public, $client_public, $server_public) |
|
389 | - { |
|
390 | - return ParagonIE_Sodium_Compat::crypto_kx( |
|
391 | - $my_secret, |
|
392 | - $their_public, |
|
393 | - $client_public, |
|
394 | - $server_public, |
|
395 | - true |
|
396 | - ); |
|
397 | - } |
|
378 | + /** |
|
379 | + * @see ParagonIE_Sodium_Compat::crypto_kx() |
|
380 | + * @param string $my_secret |
|
381 | + * @param string $their_public |
|
382 | + * @param string $client_public |
|
383 | + * @param string $server_public |
|
384 | + * @return string |
|
385 | + * @throws \SodiumException |
|
386 | + * @throws \TypeError |
|
387 | + */ |
|
388 | + function crypto_kx($my_secret, $their_public, $client_public, $server_public) |
|
389 | + { |
|
390 | + return ParagonIE_Sodium_Compat::crypto_kx( |
|
391 | + $my_secret, |
|
392 | + $their_public, |
|
393 | + $client_public, |
|
394 | + $server_public, |
|
395 | + true |
|
396 | + ); |
|
397 | + } |
|
398 | 398 | } |
399 | 399 | if (!is_callable('\\Sodium\\crypto_pwhash')) { |
400 | - /** |
|
401 | - * @see ParagonIE_Sodium_Compat::crypto_pwhash() |
|
402 | - * @param int $outlen |
|
403 | - * @param string $passwd |
|
404 | - * @param string $salt |
|
405 | - * @param int $opslimit |
|
406 | - * @param int $memlimit |
|
407 | - * @return string |
|
408 | - * @throws \SodiumException |
|
409 | - * @throws \TypeError |
|
410 | - */ |
|
411 | - function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) |
|
412 | - { |
|
413 | - return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit); |
|
414 | - } |
|
400 | + /** |
|
401 | + * @see ParagonIE_Sodium_Compat::crypto_pwhash() |
|
402 | + * @param int $outlen |
|
403 | + * @param string $passwd |
|
404 | + * @param string $salt |
|
405 | + * @param int $opslimit |
|
406 | + * @param int $memlimit |
|
407 | + * @return string |
|
408 | + * @throws \SodiumException |
|
409 | + * @throws \TypeError |
|
410 | + */ |
|
411 | + function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) |
|
412 | + { |
|
413 | + return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit); |
|
414 | + } |
|
415 | 415 | } |
416 | 416 | if (!is_callable('\\Sodium\\crypto_pwhash_str')) { |
417 | - /** |
|
418 | - * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() |
|
419 | - * @param string $passwd |
|
420 | - * @param int $opslimit |
|
421 | - * @param int $memlimit |
|
422 | - * @return string |
|
423 | - * @throws \SodiumException |
|
424 | - * @throws \TypeError |
|
425 | - */ |
|
426 | - function crypto_pwhash_str($passwd, $opslimit, $memlimit) |
|
427 | - { |
|
428 | - return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit); |
|
429 | - } |
|
417 | + /** |
|
418 | + * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() |
|
419 | + * @param string $passwd |
|
420 | + * @param int $opslimit |
|
421 | + * @param int $memlimit |
|
422 | + * @return string |
|
423 | + * @throws \SodiumException |
|
424 | + * @throws \TypeError |
|
425 | + */ |
|
426 | + function crypto_pwhash_str($passwd, $opslimit, $memlimit) |
|
427 | + { |
|
428 | + return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit); |
|
429 | + } |
|
430 | 430 | } |
431 | 431 | if (!is_callable('\\Sodium\\crypto_pwhash_str_verify')) { |
432 | - /** |
|
433 | - * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() |
|
434 | - * @param string $passwd |
|
435 | - * @param string $hash |
|
436 | - * @return bool |
|
437 | - * @throws \SodiumException |
|
438 | - * @throws \TypeError |
|
439 | - */ |
|
440 | - function crypto_pwhash_str_verify($passwd, $hash) |
|
441 | - { |
|
442 | - return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash); |
|
443 | - } |
|
432 | + /** |
|
433 | + * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() |
|
434 | + * @param string $passwd |
|
435 | + * @param string $hash |
|
436 | + * @return bool |
|
437 | + * @throws \SodiumException |
|
438 | + * @throws \TypeError |
|
439 | + */ |
|
440 | + function crypto_pwhash_str_verify($passwd, $hash) |
|
441 | + { |
|
442 | + return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash); |
|
443 | + } |
|
444 | 444 | } |
445 | 445 | if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256')) { |
446 | - /** |
|
447 | - * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() |
|
448 | - * @param int $outlen |
|
449 | - * @param string $passwd |
|
450 | - * @param string $salt |
|
451 | - * @param int $opslimit |
|
452 | - * @param int $memlimit |
|
453 | - * @return string |
|
454 | - * @throws \SodiumException |
|
455 | - * @throws \TypeError |
|
456 | - */ |
|
457 | - function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) |
|
458 | - { |
|
459 | - return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); |
|
460 | - } |
|
446 | + /** |
|
447 | + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() |
|
448 | + * @param int $outlen |
|
449 | + * @param string $passwd |
|
450 | + * @param string $salt |
|
451 | + * @param int $opslimit |
|
452 | + * @param int $memlimit |
|
453 | + * @return string |
|
454 | + * @throws \SodiumException |
|
455 | + * @throws \TypeError |
|
456 | + */ |
|
457 | + function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) |
|
458 | + { |
|
459 | + return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); |
|
460 | + } |
|
461 | 461 | } |
462 | 462 | if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str')) { |
463 | - /** |
|
464 | - * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() |
|
465 | - * @param string $passwd |
|
466 | - * @param int $opslimit |
|
467 | - * @param int $memlimit |
|
468 | - * @return string |
|
469 | - * @throws \SodiumException |
|
470 | - * @throws \TypeError |
|
471 | - */ |
|
472 | - function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) |
|
473 | - { |
|
474 | - return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); |
|
475 | - } |
|
463 | + /** |
|
464 | + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() |
|
465 | + * @param string $passwd |
|
466 | + * @param int $opslimit |
|
467 | + * @param int $memlimit |
|
468 | + * @return string |
|
469 | + * @throws \SodiumException |
|
470 | + * @throws \TypeError |
|
471 | + */ |
|
472 | + function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) |
|
473 | + { |
|
474 | + return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); |
|
475 | + } |
|
476 | 476 | } |
477 | 477 | if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str_verify')) { |
478 | - /** |
|
479 | - * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() |
|
480 | - * @param string $passwd |
|
481 | - * @param string $hash |
|
482 | - * @return bool |
|
483 | - * @throws \SodiumException |
|
484 | - * @throws \TypeError |
|
485 | - */ |
|
486 | - function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) |
|
487 | - { |
|
488 | - return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); |
|
489 | - } |
|
478 | + /** |
|
479 | + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() |
|
480 | + * @param string $passwd |
|
481 | + * @param string $hash |
|
482 | + * @return bool |
|
483 | + * @throws \SodiumException |
|
484 | + * @throws \TypeError |
|
485 | + */ |
|
486 | + function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) |
|
487 | + { |
|
488 | + return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); |
|
489 | + } |
|
490 | 490 | } |
491 | 491 | if (!is_callable('\\Sodium\\crypto_scalarmult')) { |
492 | - /** |
|
493 | - * @see ParagonIE_Sodium_Compat::crypto_scalarmult() |
|
494 | - * @param string $n |
|
495 | - * @param string $p |
|
496 | - * @return string |
|
497 | - * @throws \SodiumException |
|
498 | - * @throws \TypeError |
|
499 | - */ |
|
500 | - function crypto_scalarmult($n, $p) |
|
501 | - { |
|
502 | - return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p); |
|
503 | - } |
|
492 | + /** |
|
493 | + * @see ParagonIE_Sodium_Compat::crypto_scalarmult() |
|
494 | + * @param string $n |
|
495 | + * @param string $p |
|
496 | + * @return string |
|
497 | + * @throws \SodiumException |
|
498 | + * @throws \TypeError |
|
499 | + */ |
|
500 | + function crypto_scalarmult($n, $p) |
|
501 | + { |
|
502 | + return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p); |
|
503 | + } |
|
504 | 504 | } |
505 | 505 | if (!is_callable('\\Sodium\\crypto_scalarmult_base')) { |
506 | - /** |
|
507 | - * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() |
|
508 | - * @param string $n |
|
509 | - * @return string |
|
510 | - * @throws \SodiumException |
|
511 | - * @throws \TypeError |
|
512 | - */ |
|
513 | - function crypto_scalarmult_base($n) |
|
514 | - { |
|
515 | - return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n); |
|
516 | - } |
|
506 | + /** |
|
507 | + * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() |
|
508 | + * @param string $n |
|
509 | + * @return string |
|
510 | + * @throws \SodiumException |
|
511 | + * @throws \TypeError |
|
512 | + */ |
|
513 | + function crypto_scalarmult_base($n) |
|
514 | + { |
|
515 | + return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n); |
|
516 | + } |
|
517 | 517 | } |
518 | 518 | if (!is_callable('\\Sodium\\crypto_secretbox')) { |
519 | - /** |
|
520 | - * @see ParagonIE_Sodium_Compat::crypto_secretbox() |
|
521 | - * @param string $message |
|
522 | - * @param string $nonce |
|
523 | - * @param string $key |
|
524 | - * @return string |
|
525 | - * @throws \SodiumException |
|
526 | - * @throws \TypeError |
|
527 | - */ |
|
528 | - function crypto_secretbox($message, $nonce, $key) |
|
529 | - { |
|
530 | - return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key); |
|
531 | - } |
|
519 | + /** |
|
520 | + * @see ParagonIE_Sodium_Compat::crypto_secretbox() |
|
521 | + * @param string $message |
|
522 | + * @param string $nonce |
|
523 | + * @param string $key |
|
524 | + * @return string |
|
525 | + * @throws \SodiumException |
|
526 | + * @throws \TypeError |
|
527 | + */ |
|
528 | + function crypto_secretbox($message, $nonce, $key) |
|
529 | + { |
|
530 | + return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key); |
|
531 | + } |
|
532 | 532 | } |
533 | 533 | if (!is_callable('\\Sodium\\crypto_secretbox_open')) { |
534 | - /** |
|
535 | - * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() |
|
536 | - * @param string $message |
|
537 | - * @param string $nonce |
|
538 | - * @param string $key |
|
539 | - * @return string|bool |
|
540 | - */ |
|
541 | - function crypto_secretbox_open($message, $nonce, $key) |
|
542 | - { |
|
543 | - try { |
|
544 | - return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key); |
|
545 | - } catch (\TypeError $ex) { |
|
546 | - return false; |
|
547 | - } catch (\SodiumException $ex) { |
|
548 | - return false; |
|
549 | - } |
|
550 | - } |
|
534 | + /** |
|
535 | + * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() |
|
536 | + * @param string $message |
|
537 | + * @param string $nonce |
|
538 | + * @param string $key |
|
539 | + * @return string|bool |
|
540 | + */ |
|
541 | + function crypto_secretbox_open($message, $nonce, $key) |
|
542 | + { |
|
543 | + try { |
|
544 | + return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key); |
|
545 | + } catch (\TypeError $ex) { |
|
546 | + return false; |
|
547 | + } catch (\SodiumException $ex) { |
|
548 | + return false; |
|
549 | + } |
|
550 | + } |
|
551 | 551 | } |
552 | 552 | if (!is_callable('\\Sodium\\crypto_shorthash')) { |
553 | - /** |
|
554 | - * @see ParagonIE_Sodium_Compat::crypto_shorthash() |
|
555 | - * @param string $message |
|
556 | - * @param string $key |
|
557 | - * @return string |
|
558 | - * @throws \SodiumException |
|
559 | - * @throws \TypeError |
|
560 | - */ |
|
561 | - function crypto_shorthash($message, $key = '') |
|
562 | - { |
|
563 | - return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key); |
|
564 | - } |
|
553 | + /** |
|
554 | + * @see ParagonIE_Sodium_Compat::crypto_shorthash() |
|
555 | + * @param string $message |
|
556 | + * @param string $key |
|
557 | + * @return string |
|
558 | + * @throws \SodiumException |
|
559 | + * @throws \TypeError |
|
560 | + */ |
|
561 | + function crypto_shorthash($message, $key = '') |
|
562 | + { |
|
563 | + return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key); |
|
564 | + } |
|
565 | 565 | } |
566 | 566 | if (!is_callable('\\Sodium\\crypto_sign')) { |
567 | - /** |
|
568 | - * @see ParagonIE_Sodium_Compat::crypto_sign() |
|
569 | - * @param string $message |
|
570 | - * @param string $sk |
|
571 | - * @return string |
|
572 | - * @throws \SodiumException |
|
573 | - * @throws \TypeError |
|
574 | - */ |
|
575 | - function crypto_sign($message, $sk) |
|
576 | - { |
|
577 | - return ParagonIE_Sodium_Compat::crypto_sign($message, $sk); |
|
578 | - } |
|
567 | + /** |
|
568 | + * @see ParagonIE_Sodium_Compat::crypto_sign() |
|
569 | + * @param string $message |
|
570 | + * @param string $sk |
|
571 | + * @return string |
|
572 | + * @throws \SodiumException |
|
573 | + * @throws \TypeError |
|
574 | + */ |
|
575 | + function crypto_sign($message, $sk) |
|
576 | + { |
|
577 | + return ParagonIE_Sodium_Compat::crypto_sign($message, $sk); |
|
578 | + } |
|
579 | 579 | } |
580 | 580 | if (!is_callable('\\Sodium\\crypto_sign_detached')) { |
581 | - /** |
|
582 | - * @see ParagonIE_Sodium_Compat::crypto_sign_detached() |
|
583 | - * @param string $message |
|
584 | - * @param string $sk |
|
585 | - * @return string |
|
586 | - * @throws \SodiumException |
|
587 | - * @throws \TypeError |
|
588 | - */ |
|
589 | - function crypto_sign_detached($message, $sk) |
|
590 | - { |
|
591 | - return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk); |
|
592 | - } |
|
581 | + /** |
|
582 | + * @see ParagonIE_Sodium_Compat::crypto_sign_detached() |
|
583 | + * @param string $message |
|
584 | + * @param string $sk |
|
585 | + * @return string |
|
586 | + * @throws \SodiumException |
|
587 | + * @throws \TypeError |
|
588 | + */ |
|
589 | + function crypto_sign_detached($message, $sk) |
|
590 | + { |
|
591 | + return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk); |
|
592 | + } |
|
593 | 593 | } |
594 | 594 | if (!is_callable('\\Sodium\\crypto_sign_keypair')) { |
595 | - /** |
|
596 | - * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() |
|
597 | - * @return string |
|
598 | - * @throws \SodiumException |
|
599 | - * @throws \TypeError |
|
600 | - */ |
|
601 | - function crypto_sign_keypair() |
|
602 | - { |
|
603 | - return ParagonIE_Sodium_Compat::crypto_sign_keypair(); |
|
604 | - } |
|
595 | + /** |
|
596 | + * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() |
|
597 | + * @return string |
|
598 | + * @throws \SodiumException |
|
599 | + * @throws \TypeError |
|
600 | + */ |
|
601 | + function crypto_sign_keypair() |
|
602 | + { |
|
603 | + return ParagonIE_Sodium_Compat::crypto_sign_keypair(); |
|
604 | + } |
|
605 | 605 | } |
606 | 606 | if (!is_callable('\\Sodium\\crypto_sign_open')) { |
607 | - /** |
|
608 | - * @see ParagonIE_Sodium_Compat::crypto_sign_open() |
|
609 | - * @param string $signedMessage |
|
610 | - * @param string $pk |
|
611 | - * @return string|bool |
|
612 | - */ |
|
613 | - function crypto_sign_open($signedMessage, $pk) |
|
614 | - { |
|
615 | - try { |
|
616 | - return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk); |
|
617 | - } catch (\TypeError $ex) { |
|
618 | - return false; |
|
619 | - } catch (\SodiumException $ex) { |
|
620 | - return false; |
|
621 | - } |
|
622 | - } |
|
607 | + /** |
|
608 | + * @see ParagonIE_Sodium_Compat::crypto_sign_open() |
|
609 | + * @param string $signedMessage |
|
610 | + * @param string $pk |
|
611 | + * @return string|bool |
|
612 | + */ |
|
613 | + function crypto_sign_open($signedMessage, $pk) |
|
614 | + { |
|
615 | + try { |
|
616 | + return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk); |
|
617 | + } catch (\TypeError $ex) { |
|
618 | + return false; |
|
619 | + } catch (\SodiumException $ex) { |
|
620 | + return false; |
|
621 | + } |
|
622 | + } |
|
623 | 623 | } |
624 | 624 | if (!is_callable('\\Sodium\\crypto_sign_publickey')) { |
625 | - /** |
|
626 | - * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() |
|
627 | - * @param string $keypair |
|
628 | - * @return string |
|
629 | - * @throws \SodiumException |
|
630 | - * @throws \TypeError |
|
631 | - */ |
|
632 | - function crypto_sign_publickey($keypair) |
|
633 | - { |
|
634 | - return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair); |
|
635 | - } |
|
625 | + /** |
|
626 | + * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() |
|
627 | + * @param string $keypair |
|
628 | + * @return string |
|
629 | + * @throws \SodiumException |
|
630 | + * @throws \TypeError |
|
631 | + */ |
|
632 | + function crypto_sign_publickey($keypair) |
|
633 | + { |
|
634 | + return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair); |
|
635 | + } |
|
636 | 636 | } |
637 | 637 | if (!is_callable('\\Sodium\\crypto_sign_publickey_from_secretkey')) { |
638 | - /** |
|
639 | - * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() |
|
640 | - * @param string $sk |
|
641 | - * @return string |
|
642 | - * @throws \SodiumException |
|
643 | - * @throws \TypeError |
|
644 | - */ |
|
645 | - function crypto_sign_publickey_from_secretkey($sk) |
|
646 | - { |
|
647 | - return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk); |
|
648 | - } |
|
638 | + /** |
|
639 | + * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() |
|
640 | + * @param string $sk |
|
641 | + * @return string |
|
642 | + * @throws \SodiumException |
|
643 | + * @throws \TypeError |
|
644 | + */ |
|
645 | + function crypto_sign_publickey_from_secretkey($sk) |
|
646 | + { |
|
647 | + return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk); |
|
648 | + } |
|
649 | 649 | } |
650 | 650 | if (!is_callable('\\Sodium\\crypto_sign_secretkey')) { |
651 | - /** |
|
652 | - * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() |
|
653 | - * @param string $keypair |
|
654 | - * @return string |
|
655 | - * @throws \SodiumException |
|
656 | - * @throws \TypeError |
|
657 | - */ |
|
658 | - function crypto_sign_secretkey($keypair) |
|
659 | - { |
|
660 | - return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair); |
|
661 | - } |
|
651 | + /** |
|
652 | + * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() |
|
653 | + * @param string $keypair |
|
654 | + * @return string |
|
655 | + * @throws \SodiumException |
|
656 | + * @throws \TypeError |
|
657 | + */ |
|
658 | + function crypto_sign_secretkey($keypair) |
|
659 | + { |
|
660 | + return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair); |
|
661 | + } |
|
662 | 662 | } |
663 | 663 | if (!is_callable('\\Sodium\\crypto_sign_seed_keypair')) { |
664 | - /** |
|
665 | - * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() |
|
666 | - * @param string $seed |
|
667 | - * @return string |
|
668 | - * @throws \SodiumException |
|
669 | - * @throws \TypeError |
|
670 | - */ |
|
671 | - function crypto_sign_seed_keypair($seed) |
|
672 | - { |
|
673 | - return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed); |
|
674 | - } |
|
664 | + /** |
|
665 | + * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() |
|
666 | + * @param string $seed |
|
667 | + * @return string |
|
668 | + * @throws \SodiumException |
|
669 | + * @throws \TypeError |
|
670 | + */ |
|
671 | + function crypto_sign_seed_keypair($seed) |
|
672 | + { |
|
673 | + return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed); |
|
674 | + } |
|
675 | 675 | } |
676 | 676 | if (!is_callable('\\Sodium\\crypto_sign_verify_detached')) { |
677 | - /** |
|
678 | - * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() |
|
679 | - * @param string $signature |
|
680 | - * @param string $message |
|
681 | - * @param string $pk |
|
682 | - * @return bool |
|
683 | - * @throws \SodiumException |
|
684 | - * @throws \TypeError |
|
685 | - */ |
|
686 | - function crypto_sign_verify_detached($signature, $message, $pk) |
|
687 | - { |
|
688 | - return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); |
|
689 | - } |
|
677 | + /** |
|
678 | + * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() |
|
679 | + * @param string $signature |
|
680 | + * @param string $message |
|
681 | + * @param string $pk |
|
682 | + * @return bool |
|
683 | + * @throws \SodiumException |
|
684 | + * @throws \TypeError |
|
685 | + */ |
|
686 | + function crypto_sign_verify_detached($signature, $message, $pk) |
|
687 | + { |
|
688 | + return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); |
|
689 | + } |
|
690 | 690 | } |
691 | 691 | if (!is_callable('\\Sodium\\crypto_sign_ed25519_pk_to_curve25519')) { |
692 | - /** |
|
693 | - * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() |
|
694 | - * @param string $pk |
|
695 | - * @return string |
|
696 | - * @throws \SodiumException |
|
697 | - * @throws \TypeError |
|
698 | - */ |
|
699 | - function crypto_sign_ed25519_pk_to_curve25519($pk) |
|
700 | - { |
|
701 | - return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); |
|
702 | - } |
|
692 | + /** |
|
693 | + * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() |
|
694 | + * @param string $pk |
|
695 | + * @return string |
|
696 | + * @throws \SodiumException |
|
697 | + * @throws \TypeError |
|
698 | + */ |
|
699 | + function crypto_sign_ed25519_pk_to_curve25519($pk) |
|
700 | + { |
|
701 | + return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); |
|
702 | + } |
|
703 | 703 | } |
704 | 704 | if (!is_callable('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519')) { |
705 | - /** |
|
706 | - * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() |
|
707 | - * @param string $sk |
|
708 | - * @return string |
|
709 | - * @throws \SodiumException |
|
710 | - * @throws \TypeError |
|
711 | - */ |
|
712 | - function crypto_sign_ed25519_sk_to_curve25519($sk) |
|
713 | - { |
|
714 | - return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk); |
|
715 | - } |
|
705 | + /** |
|
706 | + * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() |
|
707 | + * @param string $sk |
|
708 | + * @return string |
|
709 | + * @throws \SodiumException |
|
710 | + * @throws \TypeError |
|
711 | + */ |
|
712 | + function crypto_sign_ed25519_sk_to_curve25519($sk) |
|
713 | + { |
|
714 | + return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk); |
|
715 | + } |
|
716 | 716 | } |
717 | 717 | if (!is_callable('\\Sodium\\crypto_stream')) { |
718 | - /** |
|
719 | - * @see ParagonIE_Sodium_Compat::crypto_stream() |
|
720 | - * @param int $len |
|
721 | - * @param string $nonce |
|
722 | - * @param string $key |
|
723 | - * @return string |
|
724 | - * @throws \SodiumException |
|
725 | - * @throws \TypeError |
|
726 | - */ |
|
727 | - function crypto_stream($len, $nonce, $key) |
|
728 | - { |
|
729 | - return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key); |
|
730 | - } |
|
718 | + /** |
|
719 | + * @see ParagonIE_Sodium_Compat::crypto_stream() |
|
720 | + * @param int $len |
|
721 | + * @param string $nonce |
|
722 | + * @param string $key |
|
723 | + * @return string |
|
724 | + * @throws \SodiumException |
|
725 | + * @throws \TypeError |
|
726 | + */ |
|
727 | + function crypto_stream($len, $nonce, $key) |
|
728 | + { |
|
729 | + return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key); |
|
730 | + } |
|
731 | 731 | } |
732 | 732 | if (!is_callable('\\Sodium\\crypto_stream_xor')) { |
733 | - /** |
|
734 | - * @see ParagonIE_Sodium_Compat::crypto_stream_xor() |
|
735 | - * @param string $message |
|
736 | - * @param string $nonce |
|
737 | - * @param string $key |
|
738 | - * @return string |
|
739 | - * @throws \SodiumException |
|
740 | - * @throws \TypeError |
|
741 | - */ |
|
742 | - function crypto_stream_xor($message, $nonce, $key) |
|
743 | - { |
|
744 | - return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key); |
|
745 | - } |
|
733 | + /** |
|
734 | + * @see ParagonIE_Sodium_Compat::crypto_stream_xor() |
|
735 | + * @param string $message |
|
736 | + * @param string $nonce |
|
737 | + * @param string $key |
|
738 | + * @return string |
|
739 | + * @throws \SodiumException |
|
740 | + * @throws \TypeError |
|
741 | + */ |
|
742 | + function crypto_stream_xor($message, $nonce, $key) |
|
743 | + { |
|
744 | + return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key); |
|
745 | + } |
|
746 | 746 | } |
747 | 747 | if (!is_callable('\\Sodium\\hex2bin')) { |
748 | - /** |
|
749 | - * @see ParagonIE_Sodium_Compat::hex2bin() |
|
750 | - * @param string $string |
|
751 | - * @return string |
|
752 | - * @throws \SodiumException |
|
753 | - * @throws \TypeError |
|
754 | - */ |
|
755 | - function hex2bin($string) |
|
756 | - { |
|
757 | - return ParagonIE_Sodium_Compat::hex2bin($string); |
|
758 | - } |
|
748 | + /** |
|
749 | + * @see ParagonIE_Sodium_Compat::hex2bin() |
|
750 | + * @param string $string |
|
751 | + * @return string |
|
752 | + * @throws \SodiumException |
|
753 | + * @throws \TypeError |
|
754 | + */ |
|
755 | + function hex2bin($string) |
|
756 | + { |
|
757 | + return ParagonIE_Sodium_Compat::hex2bin($string); |
|
758 | + } |
|
759 | 759 | } |
760 | 760 | if (!is_callable('\\Sodium\\memcmp')) { |
761 | - /** |
|
762 | - * @see ParagonIE_Sodium_Compat::memcmp() |
|
763 | - * @param string $a |
|
764 | - * @param string $b |
|
765 | - * @return int |
|
766 | - * @throws \SodiumException |
|
767 | - * @throws \TypeError |
|
768 | - */ |
|
769 | - function memcmp($a, $b) |
|
770 | - { |
|
771 | - return ParagonIE_Sodium_Compat::memcmp($a, $b); |
|
772 | - } |
|
761 | + /** |
|
762 | + * @see ParagonIE_Sodium_Compat::memcmp() |
|
763 | + * @param string $a |
|
764 | + * @param string $b |
|
765 | + * @return int |
|
766 | + * @throws \SodiumException |
|
767 | + * @throws \TypeError |
|
768 | + */ |
|
769 | + function memcmp($a, $b) |
|
770 | + { |
|
771 | + return ParagonIE_Sodium_Compat::memcmp($a, $b); |
|
772 | + } |
|
773 | 773 | } |
774 | 774 | if (!is_callable('\\Sodium\\memzero')) { |
775 | - /** |
|
776 | - * @see ParagonIE_Sodium_Compat::memzero() |
|
777 | - * @param string $str |
|
778 | - * @return void |
|
779 | - * @throws \SodiumException |
|
780 | - * @throws \TypeError |
|
781 | - */ |
|
782 | - function memzero(&$str) |
|
783 | - { |
|
784 | - ParagonIE_Sodium_Compat::memzero($str); |
|
785 | - } |
|
775 | + /** |
|
776 | + * @see ParagonIE_Sodium_Compat::memzero() |
|
777 | + * @param string $str |
|
778 | + * @return void |
|
779 | + * @throws \SodiumException |
|
780 | + * @throws \TypeError |
|
781 | + */ |
|
782 | + function memzero(&$str) |
|
783 | + { |
|
784 | + ParagonIE_Sodium_Compat::memzero($str); |
|
785 | + } |
|
786 | 786 | } |
787 | 787 | if (!is_callable('\\Sodium\\randombytes_buf')) { |
788 | - /** |
|
789 | - * @see ParagonIE_Sodium_Compat::randombytes_buf() |
|
790 | - * @param int $amount |
|
791 | - * @return string |
|
792 | - * @throws \TypeError |
|
793 | - */ |
|
794 | - function randombytes_buf($amount) |
|
795 | - { |
|
796 | - return ParagonIE_Sodium_Compat::randombytes_buf($amount); |
|
797 | - } |
|
788 | + /** |
|
789 | + * @see ParagonIE_Sodium_Compat::randombytes_buf() |
|
790 | + * @param int $amount |
|
791 | + * @return string |
|
792 | + * @throws \TypeError |
|
793 | + */ |
|
794 | + function randombytes_buf($amount) |
|
795 | + { |
|
796 | + return ParagonIE_Sodium_Compat::randombytes_buf($amount); |
|
797 | + } |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | if (!is_callable('\\Sodium\\randombytes_uniform')) { |
801 | - /** |
|
802 | - * @see ParagonIE_Sodium_Compat::randombytes_uniform() |
|
803 | - * @param int $upperLimit |
|
804 | - * @return int |
|
805 | - * @throws \SodiumException |
|
806 | - * @throws \Error |
|
807 | - */ |
|
808 | - function randombytes_uniform($upperLimit) |
|
809 | - { |
|
810 | - return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit); |
|
811 | - } |
|
801 | + /** |
|
802 | + * @see ParagonIE_Sodium_Compat::randombytes_uniform() |
|
803 | + * @param int $upperLimit |
|
804 | + * @return int |
|
805 | + * @throws \SodiumException |
|
806 | + * @throws \Error |
|
807 | + */ |
|
808 | + function randombytes_uniform($upperLimit) |
|
809 | + { |
|
810 | + return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit); |
|
811 | + } |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | if (!is_callable('\\Sodium\\randombytes_random16')) { |
815 | - /** |
|
816 | - * @see ParagonIE_Sodium_Compat::randombytes_random16() |
|
817 | - * @return int |
|
818 | - */ |
|
819 | - function randombytes_random16() |
|
820 | - { |
|
821 | - return ParagonIE_Sodium_Compat::randombytes_random16(); |
|
822 | - } |
|
815 | + /** |
|
816 | + * @see ParagonIE_Sodium_Compat::randombytes_random16() |
|
817 | + * @return int |
|
818 | + */ |
|
819 | + function randombytes_random16() |
|
820 | + { |
|
821 | + return ParagonIE_Sodium_Compat::randombytes_random16(); |
|
822 | + } |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | if (!defined('\\Sodium\\CRYPTO_AUTH_BYTES')) { |
826 | - require_once dirname(__FILE__) . '/constants.php'; |
|
826 | + require_once dirname(__FILE__) . '/constants.php'; |
|
827 | 827 | } |
@@ -1,239 +1,239 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES')) { |
4 | - define( |
|
5 | - 'SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES', |
|
6 | - ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_BYTES |
|
7 | - ); |
|
8 | - define('SODIUM_COMPAT_POLYFILLED_RISTRETTO255', true); |
|
4 | + define( |
|
5 | + 'SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES', |
|
6 | + ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_BYTES |
|
7 | + ); |
|
8 | + define('SODIUM_COMPAT_POLYFILLED_RISTRETTO255', true); |
|
9 | 9 | } |
10 | 10 | if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES')) { |
11 | - define( |
|
12 | - 'SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES', |
|
13 | - ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_HASHBYTES |
|
14 | - ); |
|
11 | + define( |
|
12 | + 'SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES', |
|
13 | + ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_HASHBYTES |
|
14 | + ); |
|
15 | 15 | } |
16 | 16 | if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES')) { |
17 | - define( |
|
18 | - 'SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES', |
|
19 | - ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_SCALARBYTES |
|
20 | - ); |
|
17 | + define( |
|
18 | + 'SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES', |
|
19 | + ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_SCALARBYTES |
|
20 | + ); |
|
21 | 21 | } |
22 | 22 | if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES')) { |
23 | - define( |
|
24 | - 'SODIUM_CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES', |
|
25 | - ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES |
|
26 | - ); |
|
23 | + define( |
|
24 | + 'SODIUM_CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES', |
|
25 | + ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES |
|
26 | + ); |
|
27 | 27 | } |
28 | 28 | if (!defined('SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES')) { |
29 | - define( |
|
30 | - 'SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES', |
|
31 | - ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES |
|
32 | - ); |
|
29 | + define( |
|
30 | + 'SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES', |
|
31 | + ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES |
|
32 | + ); |
|
33 | 33 | } |
34 | 34 | if (!defined('SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_BYTES')) { |
35 | - define( |
|
36 | - 'SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_BYTES', |
|
37 | - ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_RISTRETTO255_BYTES |
|
38 | - ); |
|
35 | + define( |
|
36 | + 'SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_BYTES', |
|
37 | + ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_RISTRETTO255_BYTES |
|
38 | + ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | if (!is_callable('sodium_crypto_core_ristretto255_add')) { |
42 | - /** |
|
43 | - * @see ParagonIE_Sodium_Compat::ristretto255_add() |
|
44 | - * |
|
45 | - * @param string $p |
|
46 | - * @param string $q |
|
47 | - * @return string |
|
48 | - * @throws SodiumException |
|
49 | - */ |
|
50 | - function sodium_crypto_core_ristretto255_add($p, $q) |
|
51 | - { |
|
52 | - return ParagonIE_Sodium_Compat::ristretto255_add($p, $q, true); |
|
53 | - } |
|
42 | + /** |
|
43 | + * @see ParagonIE_Sodium_Compat::ristretto255_add() |
|
44 | + * |
|
45 | + * @param string $p |
|
46 | + * @param string $q |
|
47 | + * @return string |
|
48 | + * @throws SodiumException |
|
49 | + */ |
|
50 | + function sodium_crypto_core_ristretto255_add($p, $q) |
|
51 | + { |
|
52 | + return ParagonIE_Sodium_Compat::ristretto255_add($p, $q, true); |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | if (!is_callable('sodium_crypto_core_ristretto255_from_hash')) { |
56 | - /** |
|
57 | - * @see ParagonIE_Sodium_Compat::ristretto255_from_hash() |
|
58 | - * |
|
59 | - * @param string $r |
|
60 | - * @return string |
|
61 | - * @throws SodiumException |
|
62 | - */ |
|
63 | - function sodium_crypto_core_ristretto255_from_hash($r) |
|
64 | - { |
|
65 | - return ParagonIE_Sodium_Compat::ristretto255_from_hash($r, true); |
|
66 | - } |
|
56 | + /** |
|
57 | + * @see ParagonIE_Sodium_Compat::ristretto255_from_hash() |
|
58 | + * |
|
59 | + * @param string $r |
|
60 | + * @return string |
|
61 | + * @throws SodiumException |
|
62 | + */ |
|
63 | + function sodium_crypto_core_ristretto255_from_hash($r) |
|
64 | + { |
|
65 | + return ParagonIE_Sodium_Compat::ristretto255_from_hash($r, true); |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | if (!is_callable('sodium_crypto_core_ristretto255_is_valid_point')) { |
69 | - /** |
|
70 | - * @see ParagonIE_Sodium_Compat::ristretto255_is_valid_point() |
|
71 | - * |
|
72 | - * @param string $p |
|
73 | - * @return bool |
|
74 | - * @throws SodiumException |
|
75 | - */ |
|
76 | - function sodium_crypto_core_ristretto255_is_valid_point($p) |
|
77 | - { |
|
78 | - return ParagonIE_Sodium_Compat::ristretto255_is_valid_point($p, true); |
|
79 | - } |
|
69 | + /** |
|
70 | + * @see ParagonIE_Sodium_Compat::ristretto255_is_valid_point() |
|
71 | + * |
|
72 | + * @param string $p |
|
73 | + * @return bool |
|
74 | + * @throws SodiumException |
|
75 | + */ |
|
76 | + function sodium_crypto_core_ristretto255_is_valid_point($p) |
|
77 | + { |
|
78 | + return ParagonIE_Sodium_Compat::ristretto255_is_valid_point($p, true); |
|
79 | + } |
|
80 | 80 | } |
81 | 81 | if (!is_callable('sodium_crypto_core_ristretto255_random')) { |
82 | - /** |
|
83 | - * @see ParagonIE_Sodium_Compat::ristretto255_random() |
|
84 | - * |
|
85 | - * @return string |
|
86 | - * @throws SodiumException |
|
87 | - */ |
|
88 | - function sodium_crypto_core_ristretto255_random() |
|
89 | - { |
|
90 | - return ParagonIE_Sodium_Compat::ristretto255_random(true); |
|
91 | - } |
|
82 | + /** |
|
83 | + * @see ParagonIE_Sodium_Compat::ristretto255_random() |
|
84 | + * |
|
85 | + * @return string |
|
86 | + * @throws SodiumException |
|
87 | + */ |
|
88 | + function sodium_crypto_core_ristretto255_random() |
|
89 | + { |
|
90 | + return ParagonIE_Sodium_Compat::ristretto255_random(true); |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_add')) { |
94 | - /** |
|
95 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_add() |
|
96 | - * |
|
97 | - * @param string $p |
|
98 | - * @param string $q |
|
99 | - * @return string |
|
100 | - * @throws SodiumException |
|
101 | - */ |
|
102 | - function sodium_crypto_core_ristretto255_scalar_add($p, $q) |
|
103 | - { |
|
104 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_add($p, $q, true); |
|
105 | - } |
|
94 | + /** |
|
95 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_add() |
|
96 | + * |
|
97 | + * @param string $p |
|
98 | + * @param string $q |
|
99 | + * @return string |
|
100 | + * @throws SodiumException |
|
101 | + */ |
|
102 | + function sodium_crypto_core_ristretto255_scalar_add($p, $q) |
|
103 | + { |
|
104 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_add($p, $q, true); |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_complement')) { |
108 | - /** |
|
109 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_complement() |
|
110 | - * |
|
111 | - * @param string $p |
|
112 | - * @return string |
|
113 | - * @throws SodiumException |
|
114 | - */ |
|
115 | - function sodium_crypto_core_ristretto255_scalar_complement($p) |
|
116 | - { |
|
117 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_complement($p, true); |
|
118 | - } |
|
108 | + /** |
|
109 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_complement() |
|
110 | + * |
|
111 | + * @param string $p |
|
112 | + * @return string |
|
113 | + * @throws SodiumException |
|
114 | + */ |
|
115 | + function sodium_crypto_core_ristretto255_scalar_complement($p) |
|
116 | + { |
|
117 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_complement($p, true); |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_invert')) { |
121 | - /** |
|
122 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_invert() |
|
123 | - * |
|
124 | - * @param string $p |
|
125 | - * @return string |
|
126 | - * @throws SodiumException |
|
127 | - */ |
|
128 | - function sodium_crypto_core_ristretto255_scalar_invert($p) |
|
129 | - { |
|
130 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_invert($p, true); |
|
131 | - } |
|
121 | + /** |
|
122 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_invert() |
|
123 | + * |
|
124 | + * @param string $p |
|
125 | + * @return string |
|
126 | + * @throws SodiumException |
|
127 | + */ |
|
128 | + function sodium_crypto_core_ristretto255_scalar_invert($p) |
|
129 | + { |
|
130 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_invert($p, true); |
|
131 | + } |
|
132 | 132 | } |
133 | 133 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_mul')) { |
134 | - /** |
|
135 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_mul() |
|
136 | - * |
|
137 | - * @param string $p |
|
138 | - * @param string $q |
|
139 | - * @return string |
|
140 | - * @throws SodiumException |
|
141 | - */ |
|
142 | - function sodium_crypto_core_ristretto255_scalar_mul($p, $q) |
|
143 | - { |
|
144 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_mul($p, $q, true); |
|
145 | - } |
|
134 | + /** |
|
135 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_mul() |
|
136 | + * |
|
137 | + * @param string $p |
|
138 | + * @param string $q |
|
139 | + * @return string |
|
140 | + * @throws SodiumException |
|
141 | + */ |
|
142 | + function sodium_crypto_core_ristretto255_scalar_mul($p, $q) |
|
143 | + { |
|
144 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_mul($p, $q, true); |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_negate')) { |
148 | - /** |
|
149 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_negate() |
|
150 | - * |
|
151 | - * @param string $p |
|
152 | - * @return string |
|
153 | - * @throws SodiumException |
|
154 | - */ |
|
155 | - function sodium_crypto_core_ristretto255_scalar_negate($p) |
|
156 | - { |
|
157 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_negate($p, true); |
|
158 | - } |
|
148 | + /** |
|
149 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_negate() |
|
150 | + * |
|
151 | + * @param string $p |
|
152 | + * @return string |
|
153 | + * @throws SodiumException |
|
154 | + */ |
|
155 | + function sodium_crypto_core_ristretto255_scalar_negate($p) |
|
156 | + { |
|
157 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_negate($p, true); |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_random')) { |
161 | - /** |
|
162 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_random() |
|
163 | - * |
|
164 | - * @return string |
|
165 | - * @throws SodiumException |
|
166 | - */ |
|
167 | - function sodium_crypto_core_ristretto255_scalar_random() |
|
168 | - { |
|
169 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_random(true); |
|
170 | - } |
|
161 | + /** |
|
162 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_random() |
|
163 | + * |
|
164 | + * @return string |
|
165 | + * @throws SodiumException |
|
166 | + */ |
|
167 | + function sodium_crypto_core_ristretto255_scalar_random() |
|
168 | + { |
|
169 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_random(true); |
|
170 | + } |
|
171 | 171 | } |
172 | 172 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_reduce')) { |
173 | - /** |
|
174 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_reduce() |
|
175 | - * |
|
176 | - * @param string $p |
|
177 | - * @return string |
|
178 | - * @throws SodiumException |
|
179 | - */ |
|
180 | - function sodium_crypto_core_ristretto255_scalar_reduce($p) |
|
181 | - { |
|
182 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_reduce($p, true); |
|
183 | - } |
|
173 | + /** |
|
174 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_reduce() |
|
175 | + * |
|
176 | + * @param string $p |
|
177 | + * @return string |
|
178 | + * @throws SodiumException |
|
179 | + */ |
|
180 | + function sodium_crypto_core_ristretto255_scalar_reduce($p) |
|
181 | + { |
|
182 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_reduce($p, true); |
|
183 | + } |
|
184 | 184 | } |
185 | 185 | if (!is_callable('sodium_crypto_core_ristretto255_scalar_sub')) { |
186 | - /** |
|
187 | - * @see ParagonIE_Sodium_Compat::ristretto255_scalar_sub() |
|
188 | - * |
|
189 | - * @param string $p |
|
190 | - * @param string $q |
|
191 | - * @return string |
|
192 | - * @throws SodiumException |
|
193 | - */ |
|
194 | - function sodium_crypto_core_ristretto255_scalar_sub($p, $q) |
|
195 | - { |
|
196 | - return ParagonIE_Sodium_Compat::ristretto255_scalar_sub($p, $q, true); |
|
197 | - } |
|
186 | + /** |
|
187 | + * @see ParagonIE_Sodium_Compat::ristretto255_scalar_sub() |
|
188 | + * |
|
189 | + * @param string $p |
|
190 | + * @param string $q |
|
191 | + * @return string |
|
192 | + * @throws SodiumException |
|
193 | + */ |
|
194 | + function sodium_crypto_core_ristretto255_scalar_sub($p, $q) |
|
195 | + { |
|
196 | + return ParagonIE_Sodium_Compat::ristretto255_scalar_sub($p, $q, true); |
|
197 | + } |
|
198 | 198 | } |
199 | 199 | if (!is_callable('sodium_crypto_core_ristretto255_sub')) { |
200 | - /** |
|
201 | - * @see ParagonIE_Sodium_Compat::ristretto255_sub() |
|
202 | - * |
|
203 | - * @param string $p |
|
204 | - * @param string $q |
|
205 | - * @return string |
|
206 | - * @throws SodiumException |
|
207 | - */ |
|
208 | - function sodium_crypto_core_ristretto255_sub($p, $q) |
|
209 | - { |
|
210 | - return ParagonIE_Sodium_Compat::ristretto255_sub($p, $q, true); |
|
211 | - } |
|
200 | + /** |
|
201 | + * @see ParagonIE_Sodium_Compat::ristretto255_sub() |
|
202 | + * |
|
203 | + * @param string $p |
|
204 | + * @param string $q |
|
205 | + * @return string |
|
206 | + * @throws SodiumException |
|
207 | + */ |
|
208 | + function sodium_crypto_core_ristretto255_sub($p, $q) |
|
209 | + { |
|
210 | + return ParagonIE_Sodium_Compat::ristretto255_sub($p, $q, true); |
|
211 | + } |
|
212 | 212 | } |
213 | 213 | if (!is_callable('sodium_crypto_scalarmult_ristretto255')) { |
214 | - /** |
|
215 | - * @see ParagonIE_Sodium_Compat::crypto_scalarmult_ristretto255() |
|
216 | - * @param string $n |
|
217 | - * @param string $p |
|
218 | - * @return string |
|
219 | - * @throws SodiumException |
|
220 | - * @throws TypeError |
|
221 | - */ |
|
222 | - function sodium_crypto_scalarmult_ristretto255($n, $p) |
|
223 | - { |
|
224 | - return ParagonIE_Sodium_Compat::scalarmult_ristretto255($n, $p, true); |
|
225 | - } |
|
214 | + /** |
|
215 | + * @see ParagonIE_Sodium_Compat::crypto_scalarmult_ristretto255() |
|
216 | + * @param string $n |
|
217 | + * @param string $p |
|
218 | + * @return string |
|
219 | + * @throws SodiumException |
|
220 | + * @throws TypeError |
|
221 | + */ |
|
222 | + function sodium_crypto_scalarmult_ristretto255($n, $p) |
|
223 | + { |
|
224 | + return ParagonIE_Sodium_Compat::scalarmult_ristretto255($n, $p, true); |
|
225 | + } |
|
226 | 226 | } |
227 | 227 | if (!is_callable('sodium_crypto_scalarmult_ristretto255_base')) { |
228 | - /** |
|
229 | - * @see ParagonIE_Sodium_Compat::crypto_scalarmult_ristretto255_base() |
|
230 | - * @param string $n |
|
231 | - * @return string |
|
232 | - * @throws SodiumException |
|
233 | - * @throws TypeError |
|
234 | - */ |
|
235 | - function sodium_crypto_scalarmult_ristretto255_base($n) |
|
236 | - { |
|
237 | - return ParagonIE_Sodium_Compat::scalarmult_ristretto255_base($n, true); |
|
238 | - } |
|
228 | + /** |
|
229 | + * @see ParagonIE_Sodium_Compat::crypto_scalarmult_ristretto255_base() |
|
230 | + * @param string $n |
|
231 | + * @return string |
|
232 | + * @throws SodiumException |
|
233 | + * @throws TypeError |
|
234 | + */ |
|
235 | + function sodium_crypto_scalarmult_ristretto255_base($n) |
|
236 | + { |
|
237 | + return ParagonIE_Sodium_Compat::scalarmult_ristretto255_base($n, true); |
|
238 | + } |
|
239 | 239 | } |
240 | 240 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | require_once dirname(dirname(__FILE__)) . '/autoload.php'; |
4 | 4 | |
5 | 5 | if (PHP_VERSION_ID < 50300) { |
6 | - return; |
|
6 | + return; |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /* |
@@ -21,28 +21,28 @@ discard block |
||
21 | 21 | * $x = Compat::crypto_aead_xchacha20poly1305_encrypt(...$args); |
22 | 22 | */ |
23 | 23 | spl_autoload_register(function ($class) { |
24 | - if ($class[0] === '\\') { |
|
25 | - $class = substr($class, 1); |
|
26 | - } |
|
27 | - $namespace = 'ParagonIE\\Sodium'; |
|
28 | - // Does the class use the namespace prefix? |
|
29 | - $len = strlen($namespace); |
|
30 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
31 | - // no, move to the next registered autoloader |
|
32 | - return false; |
|
33 | - } |
|
24 | + if ($class[0] === '\\') { |
|
25 | + $class = substr($class, 1); |
|
26 | + } |
|
27 | + $namespace = 'ParagonIE\\Sodium'; |
|
28 | + // Does the class use the namespace prefix? |
|
29 | + $len = strlen($namespace); |
|
30 | + if (strncmp($namespace, $class, $len) !== 0) { |
|
31 | + // no, move to the next registered autoloader |
|
32 | + return false; |
|
33 | + } |
|
34 | 34 | |
35 | - // Get the relative class name |
|
36 | - $relative_class = substr($class, $len); |
|
35 | + // Get the relative class name |
|
36 | + $relative_class = substr($class, $len); |
|
37 | 37 | |
38 | - // Replace the namespace prefix with the base directory, replace namespace |
|
39 | - // separators with directory separators in the relative class name, append |
|
40 | - // with .php |
|
41 | - $file = dirname(dirname(__FILE__)) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; |
|
42 | - // if the file exists, require it |
|
43 | - if (file_exists($file)) { |
|
44 | - require_once $file; |
|
45 | - return true; |
|
46 | - } |
|
47 | - return false; |
|
38 | + // Replace the namespace prefix with the base directory, replace namespace |
|
39 | + // separators with directory separators in the relative class name, append |
|
40 | + // with .php |
|
41 | + $file = dirname(dirname(__FILE__)) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; |
|
42 | + // if the file exists, require it |
|
43 | + if (file_exists($file)) { |
|
44 | + require_once $file; |
|
45 | + return true; |
|
46 | + } |
|
47 | + return false; |
|
48 | 48 | }); |