@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * SOFTWARE. |
27 | 27 | */ |
28 | 28 | |
29 | -if (!is_callable('random_bytes')) { |
|
29 | +if ( ! is_callable( 'random_bytes' ) ) { |
|
30 | 30 | /** |
31 | 31 | * If the libsodium PHP extension is loaded, we'll use it above any other |
32 | 32 | * solution. |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - function random_bytes($bytes) |
|
43 | + function random_bytes( $bytes ) |
|
44 | 44 | { |
45 | 45 | try { |
46 | 46 | /** @var int $bytes */ |
47 | - $bytes = RandomCompat_intval($bytes); |
|
48 | - } catch (TypeError $ex) { |
|
47 | + $bytes = RandomCompat_intval( $bytes ); |
|
48 | + } catch ( TypeError $ex ) { |
|
49 | 49 | throw new TypeError( |
50 | 50 | 'random_bytes(): $bytes must be an integer' |
51 | 51 | ); |
52 | 52 | } |
53 | 53 | |
54 | - if ($bytes < 1) { |
|
54 | + if ( $bytes < 1 ) { |
|
55 | 55 | throw new Error( |
56 | 56 | 'Length must be greater than 0' |
57 | 57 | ); |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | * generated in one invocation. |
63 | 63 | */ |
64 | 64 | /** @var string|bool $buf */ |
65 | - if ($bytes > 2147483647) { |
|
65 | + if ( $bytes > 2147483647 ) { |
|
66 | 66 | $buf = ''; |
67 | - for ($i = 0; $i < $bytes; $i += 1073741824) { |
|
68 | - $n = ($bytes - $i) > 1073741824 |
|
67 | + for ( $i = 0; $i < $bytes; $i += 1073741824 ) { |
|
68 | + $n = ( $bytes - $i ) > 1073741824 |
|
69 | 69 | ? 1073741824 |
70 | 70 | : $bytes - $i; |
71 | - $buf .= \Sodium\randombytes_buf($n); |
|
71 | + $buf .= \Sodium\randombytes_buf( $n ); |
|
72 | 72 | } |
73 | 73 | } else { |
74 | 74 | /** @var string|bool $buf */ |
75 | - $buf = \Sodium\randombytes_buf($bytes); |
|
75 | + $buf = \Sodium\randombytes_buf( $bytes ); |
|
76 | 76 | } |
77 | 77 | |
78 | - if (is_string($buf)) { |
|
79 | - if (RandomCompat_strlen($buf) === $bytes) { |
|
78 | + if ( is_string( $buf ) ) { |
|
79 | + if ( RandomCompat_strlen( $buf ) === $bytes ) { |
|
80 | 80 | return $buf; |
81 | 81 | } |
82 | 82 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * SOFTWARE. |
27 | 27 | */ |
28 | 28 | |
29 | -if (!class_exists('Error', false)) { |
|
29 | +if ( ! class_exists( 'Error', false ) ) { |
|
30 | 30 | // We can't really avoid making this extend Exception in PHP 5. |
31 | 31 | class Error extends Exception |
32 | 32 | { |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | -if (!class_exists('TypeError', false)) { |
|
38 | - if (is_subclass_of('Error', 'Exception')) { |
|
37 | +if ( ! class_exists( 'TypeError', false ) ) { |
|
38 | + if ( is_subclass_of( 'Error', 'Exception' ) ) { |
|
39 | 39 | class TypeError extends Error |
40 | 40 | { |
41 | 41 |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | * SOFTWARE. |
27 | 27 | */ |
28 | 28 | |
29 | -if (!is_callable('RandomCompat_strlen')) { |
|
29 | +if ( ! is_callable( 'RandomCompat_strlen' ) ) { |
|
30 | 30 | if ( |
31 | - defined('MB_OVERLOAD_STRING') |
|
31 | + defined( 'MB_OVERLOAD_STRING' ) |
|
32 | 32 | && |
33 | - ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING |
|
33 | + ( (int)ini_get( 'mbstring.func_overload' ) ) & MB_OVERLOAD_STRING |
|
34 | 34 | ) { |
35 | 35 | /** |
36 | 36 | * strlen() implementation that isn't brittle to mbstring.func_overload |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return int |
46 | 46 | */ |
47 | - function RandomCompat_strlen($binary_string) |
|
47 | + function RandomCompat_strlen( $binary_string ) |
|
48 | 48 | { |
49 | - if (!is_string($binary_string)) { |
|
49 | + if ( ! is_string( $binary_string ) ) { |
|
50 | 50 | throw new TypeError( |
51 | 51 | 'RandomCompat_strlen() expects a string' |
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
55 | - return (int) mb_strlen($binary_string, '8bit'); |
|
55 | + return (int)mb_strlen( $binary_string, '8bit' ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | } else { |
@@ -67,24 +67,24 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return int |
69 | 69 | */ |
70 | - function RandomCompat_strlen($binary_string) |
|
70 | + function RandomCompat_strlen( $binary_string ) |
|
71 | 71 | { |
72 | - if (!is_string($binary_string)) { |
|
72 | + if ( ! is_string( $binary_string ) ) { |
|
73 | 73 | throw new TypeError( |
74 | 74 | 'RandomCompat_strlen() expects a string' |
75 | 75 | ); |
76 | 76 | } |
77 | - return (int) strlen($binary_string); |
|
77 | + return (int)strlen( $binary_string ); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | -if (!is_callable('RandomCompat_substr')) { |
|
82 | +if ( ! is_callable( 'RandomCompat_substr' ) ) { |
|
83 | 83 | |
84 | 84 | if ( |
85 | - defined('MB_OVERLOAD_STRING') |
|
85 | + defined( 'MB_OVERLOAD_STRING' ) |
|
86 | 86 | && |
87 | - ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING |
|
87 | + ( (int)ini_get( 'mbstring.func_overload' ) ) & MB_OVERLOAD_STRING |
|
88 | 88 | ) { |
89 | 89 | /** |
90 | 90 | * substr() implementation that isn't brittle to mbstring.func_overload |
@@ -100,45 +100,45 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return string |
102 | 102 | */ |
103 | - function RandomCompat_substr($binary_string, $start, $length = null) |
|
103 | + function RandomCompat_substr( $binary_string, $start, $length = null ) |
|
104 | 104 | { |
105 | - if (!is_string($binary_string)) { |
|
105 | + if ( ! is_string( $binary_string ) ) { |
|
106 | 106 | throw new TypeError( |
107 | 107 | 'RandomCompat_substr(): First argument should be a string' |
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | - if (!is_int($start)) { |
|
111 | + if ( ! is_int( $start ) ) { |
|
112 | 112 | throw new TypeError( |
113 | 113 | 'RandomCompat_substr(): Second argument should be an integer' |
114 | 114 | ); |
115 | 115 | } |
116 | 116 | |
117 | - if ($length === null) { |
|
117 | + if ( $length === null ) { |
|
118 | 118 | /** |
119 | 119 | * mb_substr($str, 0, NULL, '8bit') returns an empty string on |
120 | 120 | * PHP 5.3, so we have to find the length ourselves. |
121 | 121 | */ |
122 | 122 | /** @var int $length */ |
123 | - $length = RandomCompat_strlen($binary_string) - $start; |
|
124 | - } elseif (!is_int($length)) { |
|
123 | + $length = RandomCompat_strlen( $binary_string ) - $start; |
|
124 | + } elseif ( ! is_int( $length ) ) { |
|
125 | 125 | throw new TypeError( |
126 | 126 | 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
127 | 127 | ); |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Consistency with PHP's behavior |
131 | - if ($start === RandomCompat_strlen($binary_string) && $length === 0) { |
|
131 | + if ( $start === RandomCompat_strlen( $binary_string ) && $length === 0 ) { |
|
132 | 132 | return ''; |
133 | 133 | } |
134 | - if ($start > RandomCompat_strlen($binary_string)) { |
|
134 | + if ( $start > RandomCompat_strlen( $binary_string ) ) { |
|
135 | 135 | return ''; |
136 | 136 | } |
137 | 137 | |
138 | - return (string) mb_substr( |
|
139 | - (string) $binary_string, |
|
140 | - (int) $start, |
|
141 | - (int) $length, |
|
138 | + return (string)mb_substr( |
|
139 | + (string)$binary_string, |
|
140 | + (int)$start, |
|
141 | + (int)$length, |
|
142 | 142 | '8bit' |
143 | 143 | ); |
144 | 144 | } |
@@ -158,37 +158,37 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - function RandomCompat_substr($binary_string, $start, $length = null) |
|
161 | + function RandomCompat_substr( $binary_string, $start, $length = null ) |
|
162 | 162 | { |
163 | - if (!is_string($binary_string)) { |
|
163 | + if ( ! is_string( $binary_string ) ) { |
|
164 | 164 | throw new TypeError( |
165 | 165 | 'RandomCompat_substr(): First argument should be a string' |
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
169 | - if (!is_int($start)) { |
|
169 | + if ( ! is_int( $start ) ) { |
|
170 | 170 | throw new TypeError( |
171 | 171 | 'RandomCompat_substr(): Second argument should be an integer' |
172 | 172 | ); |
173 | 173 | } |
174 | 174 | |
175 | - if ($length !== null) { |
|
176 | - if (!is_int($length)) { |
|
175 | + if ( $length !== null ) { |
|
176 | + if ( ! is_int( $length ) ) { |
|
177 | 177 | throw new TypeError( |
178 | 178 | 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
179 | 179 | ); |
180 | 180 | } |
181 | 181 | |
182 | - return (string) substr( |
|
183 | - (string )$binary_string, |
|
184 | - (int) $start, |
|
185 | - (int) $length |
|
182 | + return (string)substr( |
|
183 | + (string)$binary_string, |
|
184 | + (int)$start, |
|
185 | + (int)$length |
|
186 | 186 | ); |
187 | 187 | } |
188 | 188 | |
189 | - return (string) substr( |
|
190 | - (string) $binary_string, |
|
191 | - (int) $start |
|
189 | + return (string)substr( |
|
190 | + (string)$binary_string, |
|
191 | + (int)$start |
|
192 | 192 | ); |
193 | 193 | } |
194 | 194 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * SOFTWARE. |
27 | 27 | */ |
28 | 28 | |
29 | -if (!is_callable('random_bytes')) { |
|
29 | +if ( ! is_callable( 'random_bytes' ) ) { |
|
30 | 30 | /** |
31 | 31 | * Windows with PHP < 5.3.0 will not have the function |
32 | 32 | * openssl_random_pseudo_bytes() available, so let's use |
@@ -38,18 +38,18 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - function random_bytes($bytes) |
|
41 | + function random_bytes( $bytes ) |
|
42 | 42 | { |
43 | 43 | try { |
44 | 44 | /** @var int $bytes */ |
45 | - $bytes = RandomCompat_intval($bytes); |
|
46 | - } catch (TypeError $ex) { |
|
45 | + $bytes = RandomCompat_intval( $bytes ); |
|
46 | + } catch ( TypeError $ex ) { |
|
47 | 47 | throw new TypeError( |
48 | 48 | 'random_bytes(): $bytes must be an integer' |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - if ($bytes < 1) { |
|
52 | + if ( $bytes < 1 ) { |
|
53 | 53 | throw new Error( |
54 | 54 | 'Length must be greater than 0' |
55 | 55 | ); |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | |
58 | 58 | /** @var string $buf */ |
59 | 59 | $buf = ''; |
60 | - if (!class_exists('COM')) { |
|
60 | + if ( ! class_exists( 'COM' ) ) { |
|
61 | 61 | throw new Error( |
62 | 62 | 'COM does not exist' |
63 | 63 | ); |
64 | 64 | } |
65 | 65 | /** @var COM $util */ |
66 | - $util = new COM('CAPICOM.Utilities.1'); |
|
66 | + $util = new COM( 'CAPICOM.Utilities.1' ); |
|
67 | 67 | $execCount = 0; |
68 | 68 | |
69 | 69 | /** |
@@ -71,15 +71,15 @@ discard block |
||
71 | 71 | * get N bytes of random data, then CAPICOM has failed us. |
72 | 72 | */ |
73 | 73 | do { |
74 | - $buf .= base64_decode((string) $util->GetRandom($bytes, 0)); |
|
75 | - if (RandomCompat_strlen($buf) >= $bytes) { |
|
74 | + $buf .= base64_decode( (string)$util->GetRandom( $bytes, 0 ) ); |
|
75 | + if ( RandomCompat_strlen( $buf ) >= $bytes ) { |
|
76 | 76 | /** |
77 | 77 | * Return our random entropy buffer here: |
78 | 78 | */ |
79 | - return (string) RandomCompat_substr($buf, 0, $bytes); |
|
79 | + return (string)RandomCompat_substr( $buf, 0, $bytes ); |
|
80 | 80 | } |
81 | 81 | ++$execCount; |
82 | - } while ($execCount < $bytes); |
|
82 | + } while ( $execCount < $bytes ); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * If we reach here, PHP has failed us. |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Sodium; |
3 | 3 | |
4 | -require_once dirname(dirname(__FILE__)) . '/autoload.php'; |
|
4 | +require_once dirname( dirname( __FILE__ ) ) . '/autoload.php'; |
|
5 | 5 | |
6 | 6 | use ParagonIE_Sodium_Compat; |
7 | 7 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once dirname(dirname(__FILE__)) . '/autoload.php'; |
|
3 | +require_once dirname( dirname( __FILE__ ) ) . '/autoload.php'; |
|
4 | 4 | |
5 | -if (PHP_VERSION_ID < 50300) { |
|
5 | +if ( PHP_VERSION_ID < 50300 ) { |
|
6 | 6 | return; |
7 | 7 | } |
8 | 8 | |
@@ -20,27 +20,27 @@ discard block |
||
20 | 20 | * |
21 | 21 | * $x = Compat::crypto_aead_xchacha20poly1305_encrypt(...$args); |
22 | 22 | */ |
23 | -spl_autoload_register(function ($class) { |
|
24 | - if ($class[0] === '\\') { |
|
25 | - $class = substr($class, 1); |
|
23 | +spl_autoload_register( function( $class ) { |
|
24 | + if ( $class[ 0 ] === '\\' ) { |
|
25 | + $class = substr( $class, 1 ); |
|
26 | 26 | } |
27 | 27 | $namespace = 'ParagonIE\\Sodium'; |
28 | 28 | // Does the class use the namespace prefix? |
29 | - $len = strlen($namespace); |
|
30 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
29 | + $len = strlen( $namespace ); |
|
30 | + if ( strncmp( $namespace, $class, $len ) !== 0 ) { |
|
31 | 31 | // no, move to the next registered autoloader |
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | |
35 | 35 | // Get the relative class name |
36 | - $relative_class = substr($class, $len); |
|
36 | + $relative_class = substr( $class, $len ); |
|
37 | 37 | |
38 | 38 | // Replace the namespace prefix with the base directory, replace namespace |
39 | 39 | // separators with directory separators in the relative class name, append |
40 | 40 | // with .php |
41 | - $file = dirname(dirname(__FILE__)) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; |
|
41 | + $file = dirname( dirname( __FILE__ ) ) . '/namespaced/' . str_replace( '\\', '/', $relative_class ) . '.php'; |
|
42 | 42 | // if the file exists, require it |
43 | - if (file_exists($file)) { |
|
43 | + if ( file_exists( $file ) ) { |
|
44 | 44 | require_once $file; |
45 | 45 | return true; |
46 | 46 | } |
@@ -2,28 +2,28 @@ |
||
2 | 2 | /* |
3 | 3 | This file should only ever be loaded on PHP 7+ |
4 | 4 | */ |
5 | -if (PHP_VERSION_ID < 70000) { |
|
5 | +if ( PHP_VERSION_ID < 70000 ) { |
|
6 | 6 | return; |
7 | 7 | } |
8 | 8 | |
9 | -spl_autoload_register(function ($class) { |
|
9 | +spl_autoload_register( function( $class ) { |
|
10 | 10 | $namespace = 'ParagonIE_Sodium_'; |
11 | 11 | // Does the class use the namespace prefix? |
12 | - $len = strlen($namespace); |
|
13 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
12 | + $len = strlen( $namespace ); |
|
13 | + if ( strncmp( $namespace, $class, $len ) !== 0 ) { |
|
14 | 14 | // no, move to the next registered autoloader |
15 | 15 | return false; |
16 | 16 | } |
17 | 17 | |
18 | 18 | // Get the relative class name |
19 | - $relative_class = substr($class, $len); |
|
19 | + $relative_class = substr( $class, $len ); |
|
20 | 20 | |
21 | 21 | // Replace the namespace prefix with the base directory, replace namespace |
22 | 22 | // separators with directory separators in the relative class name, append |
23 | 23 | // with .php |
24 | - $file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
|
24 | + $file = dirname( __FILE__ ) . '/src/' . str_replace( '_', '/', $relative_class ) . '.php'; |
|
25 | 25 | // if the file exists, require it |
26 | - if (file_exists($file)) { |
|
26 | + if ( file_exists( $file ) ) { |
|
27 | 27 | require_once $file; |
28 | 28 | return true; |
29 | 29 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Crypto', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Crypto', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | $key = '' |
76 | 76 | ) { |
77 | 77 | /** @var int $len - Length of message (ciphertext + MAC) */ |
78 | - $len = ParagonIE_Sodium_Core_Util::strlen($message); |
|
78 | + $len = ParagonIE_Sodium_Core_Util::strlen( $message ); |
|
79 | 79 | |
80 | 80 | /** @var int $clen - Length of ciphertext */ |
81 | 81 | $clen = $len - self::aead_chacha20poly1305_ABYTES; |
82 | 82 | |
83 | 83 | /** @var int $adlen - Length of associated data */ |
84 | - $adlen = ParagonIE_Sodium_Core_Util::strlen($ad); |
|
84 | + $adlen = ParagonIE_Sodium_Core_Util::strlen( $ad ); |
|
85 | 85 | |
86 | 86 | /** @var string $mac - Message authentication code */ |
87 | 87 | $mac = ParagonIE_Sodium_Core_Util::substr( |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | ); |
92 | 92 | |
93 | 93 | /** @var string $ciphertext - The encrypted message (sans MAC) */ |
94 | - $ciphertext = ParagonIE_Sodium_Core_Util::substr($message, 0, $clen); |
|
94 | + $ciphertext = ParagonIE_Sodium_Core_Util::substr( $message, 0, $clen ); |
|
95 | 95 | |
96 | 96 | /** @var string The first block of the chacha20 keystream, used as a poly1305 key */ |
97 | 97 | $block0 = ParagonIE_Sodium_Core_ChaCha20::stream( |
@@ -101,21 +101,21 @@ discard block |
||
101 | 101 | ); |
102 | 102 | |
103 | 103 | /* Recalculate the Poly1305 authentication tag (MAC): */ |
104 | - $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); |
|
104 | + $state = new ParagonIE_Sodium_Core_Poly1305_State( $block0 ); |
|
105 | 105 | try { |
106 | - ParagonIE_Sodium_Compat::memzero($block0); |
|
107 | - } catch (SodiumException $ex) { |
|
106 | + ParagonIE_Sodium_Compat::memzero( $block0 ); |
|
107 | + } catch ( SodiumException $ex ) { |
|
108 | 108 | $block0 = null; |
109 | 109 | } |
110 | - $state->update($ad); |
|
111 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($adlen)); |
|
112 | - $state->update($ciphertext); |
|
113 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($clen)); |
|
110 | + $state->update( $ad ); |
|
111 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $adlen ) ); |
|
112 | + $state->update( $ciphertext ); |
|
113 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $clen ) ); |
|
114 | 114 | $computed_mac = $state->finish(); |
115 | 115 | |
116 | 116 | /* Compare the given MAC with the recalculated MAC: */ |
117 | - if (!ParagonIE_Sodium_Core_Util::verify_16($computed_mac, $mac)) { |
|
118 | - throw new SodiumException('Invalid MAC'); |
|
117 | + if ( ! ParagonIE_Sodium_Core_Util::verify_16( $computed_mac, $mac ) ) { |
|
118 | + throw new SodiumException( 'Invalid MAC' ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | // Here, we know that the MAC is valid, so we decrypt and return the plaintext |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $ciphertext, |
124 | 124 | $nonce, |
125 | 125 | $key, |
126 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
126 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
127 | 127 | ); |
128 | 128 | } |
129 | 129 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | $key = '' |
148 | 148 | ) { |
149 | 149 | /** @var int $len - Length of the plaintext message */ |
150 | - $len = ParagonIE_Sodium_Core_Util::strlen($message); |
|
150 | + $len = ParagonIE_Sodium_Core_Util::strlen( $message ); |
|
151 | 151 | |
152 | 152 | /** @var int $adlen - Length of the associated data */ |
153 | - $adlen = ParagonIE_Sodium_Core_Util::strlen($ad); |
|
153 | + $adlen = ParagonIE_Sodium_Core_Util::strlen( $ad ); |
|
154 | 154 | |
155 | 155 | /** @var string The first block of the chacha20 keystream, used as a poly1305 key */ |
156 | 156 | $block0 = ParagonIE_Sodium_Core_ChaCha20::stream( |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | $nonce, |
159 | 159 | $key |
160 | 160 | ); |
161 | - $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); |
|
161 | + $state = new ParagonIE_Sodium_Core_Poly1305_State( $block0 ); |
|
162 | 162 | try { |
163 | - ParagonIE_Sodium_Compat::memzero($block0); |
|
164 | - } catch (SodiumException $ex) { |
|
163 | + ParagonIE_Sodium_Compat::memzero( $block0 ); |
|
164 | + } catch ( SodiumException $ex ) { |
|
165 | 165 | $block0 = null; |
166 | 166 | } |
167 | 167 | |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $message, |
171 | 171 | $nonce, |
172 | 172 | $key, |
173 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
173 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
174 | 174 | ); |
175 | 175 | |
176 | - $state->update($ad); |
|
177 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($adlen)); |
|
178 | - $state->update($ciphertext); |
|
179 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($len)); |
|
176 | + $state->update( $ad ); |
|
177 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $adlen ) ); |
|
178 | + $state->update( $ciphertext ); |
|
179 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $len ) ); |
|
180 | 180 | return $ciphertext . $state->finish(); |
181 | 181 | } |
182 | 182 | |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | $key = '' |
201 | 201 | ) { |
202 | 202 | /** @var int $adlen - Length of associated data */ |
203 | - $adlen = ParagonIE_Sodium_Core_Util::strlen($ad); |
|
203 | + $adlen = ParagonIE_Sodium_Core_Util::strlen( $ad ); |
|
204 | 204 | |
205 | 205 | /** @var int $len - Length of message (ciphertext + MAC) */ |
206 | - $len = ParagonIE_Sodium_Core_Util::strlen($message); |
|
206 | + $len = ParagonIE_Sodium_Core_Util::strlen( $message ); |
|
207 | 207 | |
208 | 208 | /** @var int $clen - Length of ciphertext */ |
209 | 209 | $clen = $len - self::aead_chacha20poly1305_IETF_ABYTES; |
@@ -230,23 +230,23 @@ discard block |
||
230 | 230 | ); |
231 | 231 | |
232 | 232 | /* Recalculate the Poly1305 authentication tag (MAC): */ |
233 | - $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); |
|
233 | + $state = new ParagonIE_Sodium_Core_Poly1305_State( $block0 ); |
|
234 | 234 | try { |
235 | - ParagonIE_Sodium_Compat::memzero($block0); |
|
236 | - } catch (SodiumException $ex) { |
|
235 | + ParagonIE_Sodium_Compat::memzero( $block0 ); |
|
236 | + } catch ( SodiumException $ex ) { |
|
237 | 237 | $block0 = null; |
238 | 238 | } |
239 | - $state->update($ad); |
|
240 | - $state->update(str_repeat("\x00", ((0x10 - $adlen) & 0xf))); |
|
241 | - $state->update($ciphertext); |
|
242 | - $state->update(str_repeat("\x00", (0x10 - $clen) & 0xf)); |
|
243 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($adlen)); |
|
244 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($clen)); |
|
239 | + $state->update( $ad ); |
|
240 | + $state->update( str_repeat( "\x00", ( ( 0x10 - $adlen ) & 0xf ) ) ); |
|
241 | + $state->update( $ciphertext ); |
|
242 | + $state->update( str_repeat( "\x00", ( 0x10 - $clen ) & 0xf ) ); |
|
243 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $adlen ) ); |
|
244 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $clen ) ); |
|
245 | 245 | $computed_mac = $state->finish(); |
246 | 246 | |
247 | 247 | /* Compare the given MAC with the recalculated MAC: */ |
248 | - if (!ParagonIE_Sodium_Core_Util::verify_16($computed_mac, $mac)) { |
|
249 | - throw new SodiumException('Invalid MAC'); |
|
248 | + if ( ! ParagonIE_Sodium_Core_Util::verify_16( $computed_mac, $mac ) ) { |
|
249 | + throw new SodiumException( 'Invalid MAC' ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | // Here, we know that the MAC is valid, so we decrypt and return the plaintext |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $ciphertext, |
255 | 255 | $nonce, |
256 | 256 | $key, |
257 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
257 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
258 | 258 | ); |
259 | 259 | } |
260 | 260 | |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | $key = '' |
279 | 279 | ) { |
280 | 280 | /** @var int $len - Length of the plaintext message */ |
281 | - $len = ParagonIE_Sodium_Core_Util::strlen($message); |
|
281 | + $len = ParagonIE_Sodium_Core_Util::strlen( $message ); |
|
282 | 282 | |
283 | 283 | /** @var int $adlen - Length of the associated data */ |
284 | - $adlen = ParagonIE_Sodium_Core_Util::strlen($ad); |
|
284 | + $adlen = ParagonIE_Sodium_Core_Util::strlen( $ad ); |
|
285 | 285 | |
286 | 286 | /** @var string The first block of the chacha20 keystream, used as a poly1305 key */ |
287 | 287 | $block0 = ParagonIE_Sodium_Core_ChaCha20::ietfStream( |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | $nonce, |
290 | 290 | $key |
291 | 291 | ); |
292 | - $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); |
|
292 | + $state = new ParagonIE_Sodium_Core_Poly1305_State( $block0 ); |
|
293 | 293 | try { |
294 | - ParagonIE_Sodium_Compat::memzero($block0); |
|
295 | - } catch (SodiumException $ex) { |
|
294 | + ParagonIE_Sodium_Compat::memzero( $block0 ); |
|
295 | + } catch ( SodiumException $ex ) { |
|
296 | 296 | $block0 = null; |
297 | 297 | } |
298 | 298 | |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | $message, |
302 | 302 | $nonce, |
303 | 303 | $key, |
304 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
304 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
305 | 305 | ); |
306 | 306 | |
307 | - $state->update($ad); |
|
308 | - $state->update(str_repeat("\x00", ((0x10 - $adlen) & 0xf))); |
|
309 | - $state->update($ciphertext); |
|
310 | - $state->update(str_repeat("\x00", ((0x10 - $len) & 0xf))); |
|
311 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($adlen)); |
|
312 | - $state->update(ParagonIE_Sodium_Core_Util::store64_le($len)); |
|
307 | + $state->update( $ad ); |
|
308 | + $state->update( str_repeat( "\x00", ( ( 0x10 - $adlen ) & 0xf ) ) ); |
|
309 | + $state->update( $ciphertext ); |
|
310 | + $state->update( str_repeat( "\x00", ( ( 0x10 - $len ) & 0xf ) ) ); |
|
311 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $adlen ) ); |
|
312 | + $state->update( ParagonIE_Sodium_Core_Util::store64_le( $len ) ); |
|
313 | 313 | return $ciphertext . $state->finish(); |
314 | 314 | } |
315 | 315 | |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | $key = '' |
334 | 334 | ) { |
335 | 335 | $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( |
336 | - ParagonIE_Sodium_Core_Util::substr($nonce, 0, 16), |
|
336 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 0, 16 ), |
|
337 | 337 | $key |
338 | 338 | ); |
339 | 339 | $nonceLast = "\x00\x00\x00\x00" . |
340 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8); |
|
340 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ); |
|
341 | 341 | |
342 | - return self::aead_chacha20poly1305_ietf_decrypt($message, $ad, $nonceLast, $subkey); |
|
342 | + return self::aead_chacha20poly1305_ietf_decrypt( $message, $ad, $nonceLast, $subkey ); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -362,13 +362,13 @@ discard block |
||
362 | 362 | $key = '' |
363 | 363 | ) { |
364 | 364 | $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( |
365 | - ParagonIE_Sodium_Core_Util::substr($nonce, 0, 16), |
|
365 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 0, 16 ), |
|
366 | 366 | $key |
367 | 367 | ); |
368 | 368 | $nonceLast = "\x00\x00\x00\x00" . |
369 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8); |
|
369 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ); |
|
370 | 370 | |
371 | - return self::aead_chacha20poly1305_ietf_encrypt($message, $ad, $nonceLast, $subkey); |
|
371 | + return self::aead_chacha20poly1305_ietf_encrypt( $message, $ad, $nonceLast, $subkey ); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -381,10 +381,10 @@ discard block |
||
381 | 381 | * @return string |
382 | 382 | * @throws TypeError |
383 | 383 | */ |
384 | - public static function auth($message, $key) |
|
384 | + public static function auth( $message, $key ) |
|
385 | 385 | { |
386 | 386 | return ParagonIE_Sodium_Core_Util::substr( |
387 | - hash_hmac('sha512', $message, $key, true), |
|
387 | + hash_hmac( 'sha512', $message, $key, true ), |
|
388 | 388 | 0, |
389 | 389 | 32 |
390 | 390 | ); |
@@ -402,11 +402,11 @@ discard block |
||
402 | 402 | * @throws SodiumException |
403 | 403 | * @throws TypeError |
404 | 404 | */ |
405 | - public static function auth_verify($mac, $message, $key) |
|
405 | + public static function auth_verify( $mac, $message, $key ) |
|
406 | 406 | { |
407 | 407 | return ParagonIE_Sodium_Core_Util::hashEquals( |
408 | 408 | $mac, |
409 | - self::auth($message, $key) |
|
409 | + self::auth( $message, $key ) |
|
410 | 410 | ); |
411 | 411 | } |
412 | 412 | |
@@ -422,14 +422,14 @@ discard block |
||
422 | 422 | * @throws SodiumException |
423 | 423 | * @throws TypeError |
424 | 424 | */ |
425 | - public static function box($plaintext, $nonce, $keypair) |
|
425 | + public static function box( $plaintext, $nonce, $keypair ) |
|
426 | 426 | { |
427 | 427 | $c = self::secretbox( |
428 | 428 | $plaintext, |
429 | 429 | $nonce, |
430 | 430 | self::box_beforenm( |
431 | - self::box_secretkey($keypair), |
|
432 | - self::box_publickey($keypair) |
|
431 | + self::box_secretkey( $keypair ), |
|
432 | + self::box_publickey( $keypair ) |
|
433 | 433 | ) |
434 | 434 | ); |
435 | 435 | return $c; |
@@ -446,16 +446,16 @@ discard block |
||
446 | 446 | * @throws SodiumException |
447 | 447 | * @throws TypeError |
448 | 448 | */ |
449 | - public static function box_seal($message, $publicKey) |
|
449 | + public static function box_seal( $message, $publicKey ) |
|
450 | 450 | { |
451 | 451 | /** @var string $ephemeralKeypair */ |
452 | 452 | $ephemeralKeypair = self::box_keypair(); |
453 | 453 | |
454 | 454 | /** @var string $ephemeralSK */ |
455 | - $ephemeralSK = self::box_secretkey($ephemeralKeypair); |
|
455 | + $ephemeralSK = self::box_secretkey( $ephemeralKeypair ); |
|
456 | 456 | |
457 | 457 | /** @var string $ephemeralPK */ |
458 | - $ephemeralPK = self::box_publickey($ephemeralKeypair); |
|
458 | + $ephemeralPK = self::box_publickey( $ephemeralKeypair ); |
|
459 | 459 | |
460 | 460 | /** @var string $nonce */ |
461 | 461 | $nonce = self::generichash( |
@@ -465,15 +465,15 @@ discard block |
||
465 | 465 | ); |
466 | 466 | |
467 | 467 | /** @var string $keypair - The combined keypair used in crypto_box() */ |
468 | - $keypair = self::box_keypair_from_secretkey_and_publickey($ephemeralSK, $publicKey); |
|
468 | + $keypair = self::box_keypair_from_secretkey_and_publickey( $ephemeralSK, $publicKey ); |
|
469 | 469 | |
470 | 470 | /** @var string $ciphertext Ciphertext + MAC from crypto_box */ |
471 | - $ciphertext = self::box($message, $nonce, $keypair); |
|
471 | + $ciphertext = self::box( $message, $nonce, $keypair ); |
|
472 | 472 | try { |
473 | - ParagonIE_Sodium_Compat::memzero($ephemeralKeypair); |
|
474 | - ParagonIE_Sodium_Compat::memzero($ephemeralSK); |
|
475 | - ParagonIE_Sodium_Compat::memzero($nonce); |
|
476 | - } catch (SodiumException $ex) { |
|
473 | + ParagonIE_Sodium_Compat::memzero( $ephemeralKeypair ); |
|
474 | + ParagonIE_Sodium_Compat::memzero( $ephemeralSK ); |
|
475 | + ParagonIE_Sodium_Compat::memzero( $nonce ); |
|
476 | + } catch ( SodiumException $ex ) { |
|
477 | 477 | $ephemeralKeypair = null; |
478 | 478 | $ephemeralSK = null; |
479 | 479 | $nonce = null; |
@@ -492,19 +492,19 @@ discard block |
||
492 | 492 | * @throws SodiumException |
493 | 493 | * @throws TypeError |
494 | 494 | */ |
495 | - public static function box_seal_open($message, $keypair) |
|
495 | + public static function box_seal_open( $message, $keypair ) |
|
496 | 496 | { |
497 | 497 | /** @var string $ephemeralPK */ |
498 | - $ephemeralPK = ParagonIE_Sodium_Core_Util::substr($message, 0, 32); |
|
498 | + $ephemeralPK = ParagonIE_Sodium_Core_Util::substr( $message, 0, 32 ); |
|
499 | 499 | |
500 | 500 | /** @var string $ciphertext (ciphertext + MAC) */ |
501 | - $ciphertext = ParagonIE_Sodium_Core_Util::substr($message, 32); |
|
501 | + $ciphertext = ParagonIE_Sodium_Core_Util::substr( $message, 32 ); |
|
502 | 502 | |
503 | 503 | /** @var string $secretKey */ |
504 | - $secretKey = self::box_secretkey($keypair); |
|
504 | + $secretKey = self::box_secretkey( $keypair ); |
|
505 | 505 | |
506 | 506 | /** @var string $publicKey */ |
507 | - $publicKey = self::box_publickey($keypair); |
|
507 | + $publicKey = self::box_publickey( $keypair ); |
|
508 | 508 | |
509 | 509 | /** @var string $nonce */ |
510 | 510 | $nonce = self::generichash( |
@@ -514,15 +514,15 @@ discard block |
||
514 | 514 | ); |
515 | 515 | |
516 | 516 | /** @var string $keypair */ |
517 | - $keypair = self::box_keypair_from_secretkey_and_publickey($secretKey, $ephemeralPK); |
|
517 | + $keypair = self::box_keypair_from_secretkey_and_publickey( $secretKey, $ephemeralPK ); |
|
518 | 518 | |
519 | 519 | /** @var string $m */ |
520 | - $m = self::box_open($ciphertext, $nonce, $keypair); |
|
520 | + $m = self::box_open( $ciphertext, $nonce, $keypair ); |
|
521 | 521 | try { |
522 | - ParagonIE_Sodium_Compat::memzero($secretKey); |
|
523 | - ParagonIE_Sodium_Compat::memzero($ephemeralPK); |
|
524 | - ParagonIE_Sodium_Compat::memzero($nonce); |
|
525 | - } catch (SodiumException $ex) { |
|
522 | + ParagonIE_Sodium_Compat::memzero( $secretKey ); |
|
523 | + ParagonIE_Sodium_Compat::memzero( $ephemeralPK ); |
|
524 | + ParagonIE_Sodium_Compat::memzero( $nonce ); |
|
525 | + } catch ( SodiumException $ex ) { |
|
526 | 526 | $secretKey = null; |
527 | 527 | $ephemeralPK = null; |
528 | 528 | $nonce = null; |
@@ -541,11 +541,11 @@ discard block |
||
541 | 541 | * @throws SodiumException |
542 | 542 | * @throws TypeError |
543 | 543 | */ |
544 | - public static function box_beforenm($sk, $pk) |
|
544 | + public static function box_beforenm( $sk, $pk ) |
|
545 | 545 | { |
546 | 546 | return ParagonIE_Sodium_Core_HSalsa20::hsalsa20( |
547 | - str_repeat("\x00", 16), |
|
548 | - self::scalarmult($sk, $pk) |
|
547 | + str_repeat( "\x00", 16 ), |
|
548 | + self::scalarmult( $sk, $pk ) |
|
549 | 549 | ); |
550 | 550 | } |
551 | 551 | |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | */ |
560 | 560 | public static function box_keypair() |
561 | 561 | { |
562 | - $sKey = random_bytes(32); |
|
563 | - $pKey = self::scalarmult_base($sKey); |
|
562 | + $sKey = random_bytes( 32 ); |
|
563 | + $pKey = self::scalarmult_base( $sKey ); |
|
564 | 564 | return $sKey . $pKey; |
565 | 565 | } |
566 | 566 | |
@@ -570,14 +570,14 @@ discard block |
||
570 | 570 | * @throws SodiumException |
571 | 571 | * @throws TypeError |
572 | 572 | */ |
573 | - public static function box_seed_keypair($seed) |
|
573 | + public static function box_seed_keypair( $seed ) |
|
574 | 574 | { |
575 | 575 | $sKey = ParagonIE_Sodium_Core_Util::substr( |
576 | - hash('sha512', $seed, true), |
|
576 | + hash( 'sha512', $seed, true ), |
|
577 | 577 | 0, |
578 | 578 | 32 |
579 | 579 | ); |
580 | - $pKey = self::scalarmult_base($sKey); |
|
580 | + $pKey = self::scalarmult_base( $sKey ); |
|
581 | 581 | return $sKey . $pKey; |
582 | 582 | } |
583 | 583 | |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | * @return string |
590 | 590 | * @throws TypeError |
591 | 591 | */ |
592 | - public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) |
|
592 | + public static function box_keypair_from_secretkey_and_publickey( $sKey, $pKey ) |
|
593 | 593 | { |
594 | - return ParagonIE_Sodium_Core_Util::substr($sKey, 0, 32) . |
|
595 | - ParagonIE_Sodium_Core_Util::substr($pKey, 0, 32); |
|
594 | + return ParagonIE_Sodium_Core_Util::substr( $sKey, 0, 32 ) . |
|
595 | + ParagonIE_Sodium_Core_Util::substr( $pKey, 0, 32 ); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,14 +603,14 @@ discard block |
||
603 | 603 | * @throws RangeException |
604 | 604 | * @throws TypeError |
605 | 605 | */ |
606 | - public static function box_secretkey($keypair) |
|
606 | + public static function box_secretkey( $keypair ) |
|
607 | 607 | { |
608 | - if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== 64) { |
|
608 | + if ( ParagonIE_Sodium_Core_Util::strlen( $keypair ) !== 64 ) { |
|
609 | 609 | throw new RangeException( |
610 | 610 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' |
611 | 611 | ); |
612 | 612 | } |
613 | - return ParagonIE_Sodium_Core_Util::substr($keypair, 0, 32); |
|
613 | + return ParagonIE_Sodium_Core_Util::substr( $keypair, 0, 32 ); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | /** |
@@ -621,14 +621,14 @@ discard block |
||
621 | 621 | * @throws RangeException |
622 | 622 | * @throws TypeError |
623 | 623 | */ |
624 | - public static function box_publickey($keypair) |
|
624 | + public static function box_publickey( $keypair ) |
|
625 | 625 | { |
626 | - if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) { |
|
626 | + if ( ParagonIE_Sodium_Core_Util::strlen( $keypair ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES ) { |
|
627 | 627 | throw new RangeException( |
628 | 628 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' |
629 | 629 | ); |
630 | 630 | } |
631 | - return ParagonIE_Sodium_Core_Util::substr($keypair, 32, 32); |
|
631 | + return ParagonIE_Sodium_Core_Util::substr( $keypair, 32, 32 ); |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | /** |
@@ -640,14 +640,14 @@ discard block |
||
640 | 640 | * @throws SodiumException |
641 | 641 | * @throws TypeError |
642 | 642 | */ |
643 | - public static function box_publickey_from_secretkey($sKey) |
|
643 | + public static function box_publickey_from_secretkey( $sKey ) |
|
644 | 644 | { |
645 | - if (ParagonIE_Sodium_Core_Util::strlen($sKey) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES) { |
|
645 | + if ( ParagonIE_Sodium_Core_Util::strlen( $sKey ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES ) { |
|
646 | 646 | throw new RangeException( |
647 | 647 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES bytes long.' |
648 | 648 | ); |
649 | 649 | } |
650 | - return self::scalarmult_base($sKey); |
|
650 | + return self::scalarmult_base( $sKey ); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | /** |
@@ -662,14 +662,14 @@ discard block |
||
662 | 662 | * @throws SodiumException |
663 | 663 | * @throws TypeError |
664 | 664 | */ |
665 | - public static function box_open($ciphertext, $nonce, $keypair) |
|
665 | + public static function box_open( $ciphertext, $nonce, $keypair ) |
|
666 | 666 | { |
667 | 667 | return self::secretbox_open( |
668 | 668 | $ciphertext, |
669 | 669 | $nonce, |
670 | 670 | self::box_beforenm( |
671 | - self::box_secretkey($keypair), |
|
672 | - self::box_publickey($keypair) |
|
671 | + self::box_secretkey( $keypair ), |
|
672 | + self::box_publickey( $keypair ) |
|
673 | 673 | ) |
674 | 674 | ); |
675 | 675 | } |
@@ -687,34 +687,34 @@ discard block |
||
687 | 687 | * @throws SodiumException |
688 | 688 | * @throws TypeError |
689 | 689 | */ |
690 | - public static function generichash($message, $key = '', $outlen = 32) |
|
690 | + public static function generichash( $message, $key = '', $outlen = 32 ) |
|
691 | 691 | { |
692 | 692 | // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized |
693 | 693 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
694 | 694 | |
695 | 695 | $k = null; |
696 | - if (!empty($key)) { |
|
696 | + if ( ! empty( $key ) ) { |
|
697 | 697 | /** @var SplFixedArray $k */ |
698 | - $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($key); |
|
699 | - if ($k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES) { |
|
700 | - throw new RangeException('Invalid key size'); |
|
698 | + $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $key ); |
|
699 | + if ( $k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES ) { |
|
700 | + throw new RangeException( 'Invalid key size' ); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | 704 | /** @var SplFixedArray $in */ |
705 | - $in = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($message); |
|
705 | + $in = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $message ); |
|
706 | 706 | |
707 | 707 | /** @var SplFixedArray $ctx */ |
708 | - $ctx = ParagonIE_Sodium_Core_BLAKE2b::init($k, $outlen); |
|
709 | - ParagonIE_Sodium_Core_BLAKE2b::update($ctx, $in, $in->count()); |
|
708 | + $ctx = ParagonIE_Sodium_Core_BLAKE2b::init( $k, $outlen ); |
|
709 | + ParagonIE_Sodium_Core_BLAKE2b::update( $ctx, $in, $in->count() ); |
|
710 | 710 | |
711 | 711 | /** @var SplFixedArray $out */ |
712 | - $out = new SplFixedArray($outlen); |
|
713 | - $out = ParagonIE_Sodium_Core_BLAKE2b::finish($ctx, $out); |
|
712 | + $out = new SplFixedArray( $outlen ); |
|
713 | + $out = ParagonIE_Sodium_Core_BLAKE2b::finish( $ctx, $out ); |
|
714 | 714 | |
715 | 715 | /** @var array<int, int> */ |
716 | 716 | $outArray = $out->toArray(); |
717 | - return ParagonIE_Sodium_Core_Util::intArrayToString($outArray); |
|
717 | + return ParagonIE_Sodium_Core_Util::intArrayToString( $outArray ); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -728,22 +728,22 @@ discard block |
||
728 | 728 | * @throws SodiumException |
729 | 729 | * @throws TypeError |
730 | 730 | */ |
731 | - public static function generichash_final($ctx, $outlen = 32) |
|
731 | + public static function generichash_final( $ctx, $outlen = 32 ) |
|
732 | 732 | { |
733 | - if (!is_string($ctx)) { |
|
734 | - throw new TypeError('Context must be a string'); |
|
733 | + if ( ! is_string( $ctx ) ) { |
|
734 | + throw new TypeError( 'Context must be a string' ); |
|
735 | 735 | } |
736 | - $out = new SplFixedArray($outlen); |
|
736 | + $out = new SplFixedArray( $outlen ); |
|
737 | 737 | |
738 | 738 | /** @var SplFixedArray $context */ |
739 | - $context = ParagonIE_Sodium_Core_BLAKE2b::stringToContext($ctx); |
|
739 | + $context = ParagonIE_Sodium_Core_BLAKE2b::stringToContext( $ctx ); |
|
740 | 740 | |
741 | 741 | /** @var SplFixedArray $out */ |
742 | - $out = ParagonIE_Sodium_Core_BLAKE2b::finish($context, $out); |
|
742 | + $out = ParagonIE_Sodium_Core_BLAKE2b::finish( $context, $out ); |
|
743 | 743 | |
744 | 744 | /** @var array<int, int> */ |
745 | 745 | $outArray = $out->toArray(); |
746 | - return ParagonIE_Sodium_Core_Util::intArrayToString($outArray); |
|
746 | + return ParagonIE_Sodium_Core_Util::intArrayToString( $outArray ); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
@@ -758,23 +758,23 @@ discard block |
||
758 | 758 | * @throws SodiumException |
759 | 759 | * @throws TypeError |
760 | 760 | */ |
761 | - public static function generichash_init($key = '', $outputLength = 32) |
|
761 | + public static function generichash_init( $key = '', $outputLength = 32 ) |
|
762 | 762 | { |
763 | 763 | // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized |
764 | 764 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
765 | 765 | |
766 | 766 | $k = null; |
767 | - if (!empty($key)) { |
|
768 | - $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($key); |
|
769 | - if ($k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES) { |
|
770 | - throw new RangeException('Invalid key size'); |
|
767 | + if ( ! empty( $key ) ) { |
|
768 | + $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $key ); |
|
769 | + if ( $k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES ) { |
|
770 | + throw new RangeException( 'Invalid key size' ); |
|
771 | 771 | } |
772 | 772 | } |
773 | 773 | |
774 | 774 | /** @var SplFixedArray $ctx */ |
775 | - $ctx = ParagonIE_Sodium_Core_BLAKE2b::init($k, $outputLength); |
|
775 | + $ctx = ParagonIE_Sodium_Core_BLAKE2b::init( $k, $outputLength ); |
|
776 | 776 | |
777 | - return ParagonIE_Sodium_Core_BLAKE2b::contextToString($ctx); |
|
777 | + return ParagonIE_Sodium_Core_BLAKE2b::contextToString( $ctx ); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | /** |
@@ -801,27 +801,27 @@ discard block |
||
801 | 801 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
802 | 802 | |
803 | 803 | $k = null; |
804 | - if (!empty($key)) { |
|
805 | - $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($key); |
|
806 | - if ($k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES) { |
|
807 | - throw new RangeException('Invalid key size'); |
|
804 | + if ( ! empty( $key ) ) { |
|
805 | + $k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $key ); |
|
806 | + if ( $k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES ) { |
|
807 | + throw new RangeException( 'Invalid key size' ); |
|
808 | 808 | } |
809 | 809 | } |
810 | - if (!empty($salt)) { |
|
811 | - $s = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($salt); |
|
810 | + if ( ! empty( $salt ) ) { |
|
811 | + $s = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $salt ); |
|
812 | 812 | } else { |
813 | 813 | $s = null; |
814 | 814 | } |
815 | - if (!empty($salt)) { |
|
816 | - $p = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($personal); |
|
815 | + if ( ! empty( $salt ) ) { |
|
816 | + $p = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $personal ); |
|
817 | 817 | } else { |
818 | 818 | $p = null; |
819 | 819 | } |
820 | 820 | |
821 | 821 | /** @var SplFixedArray $ctx */ |
822 | - $ctx = ParagonIE_Sodium_Core_BLAKE2b::init($k, $outputLength, $s, $p); |
|
822 | + $ctx = ParagonIE_Sodium_Core_BLAKE2b::init( $k, $outputLength, $s, $p ); |
|
823 | 823 | |
824 | - return ParagonIE_Sodium_Core_BLAKE2b::contextToString($ctx); |
|
824 | + return ParagonIE_Sodium_Core_BLAKE2b::contextToString( $ctx ); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -835,20 +835,20 @@ discard block |
||
835 | 835 | * @throws SodiumException |
836 | 836 | * @throws TypeError |
837 | 837 | */ |
838 | - public static function generichash_update($ctx, $message) |
|
838 | + public static function generichash_update( $ctx, $message ) |
|
839 | 839 | { |
840 | 840 | // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized |
841 | 841 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
842 | 842 | |
843 | 843 | /** @var SplFixedArray $context */ |
844 | - $context = ParagonIE_Sodium_Core_BLAKE2b::stringToContext($ctx); |
|
844 | + $context = ParagonIE_Sodium_Core_BLAKE2b::stringToContext( $ctx ); |
|
845 | 845 | |
846 | 846 | /** @var SplFixedArray $in */ |
847 | - $in = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($message); |
|
847 | + $in = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray( $message ); |
|
848 | 848 | |
849 | - ParagonIE_Sodium_Core_BLAKE2b::update($context, $in, $in->count()); |
|
849 | + ParagonIE_Sodium_Core_BLAKE2b::update( $context, $in, $in->count() ); |
|
850 | 850 | |
851 | - return ParagonIE_Sodium_Core_BLAKE2b::contextToString($context); |
|
851 | + return ParagonIE_Sodium_Core_BLAKE2b::contextToString( $context ); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -864,10 +864,10 @@ discard block |
||
864 | 864 | * @throws SodiumException |
865 | 865 | * @throws TypeError |
866 | 866 | */ |
867 | - public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) |
|
867 | + public static function keyExchange( $my_sk, $their_pk, $client_pk, $server_pk ) |
|
868 | 868 | { |
869 | 869 | return ParagonIE_Sodium_Compat::crypto_generichash( |
870 | - ParagonIE_Sodium_Compat::crypto_scalarmult($my_sk, $their_pk) . |
|
870 | + ParagonIE_Sodium_Compat::crypto_scalarmult( $my_sk, $their_pk ) . |
|
871 | 871 | $client_pk . |
872 | 872 | $server_pk |
873 | 873 | ); |
@@ -885,10 +885,10 @@ discard block |
||
885 | 885 | * @throws SodiumException |
886 | 886 | * @throws TypeError |
887 | 887 | */ |
888 | - public static function scalarmult($sKey, $pKey) |
|
888 | + public static function scalarmult( $sKey, $pKey ) |
|
889 | 889 | { |
890 | - $q = ParagonIE_Sodium_Core_X25519::crypto_scalarmult_curve25519_ref10($sKey, $pKey); |
|
891 | - self::scalarmult_throw_if_zero($q); |
|
890 | + $q = ParagonIE_Sodium_Core_X25519::crypto_scalarmult_curve25519_ref10( $sKey, $pKey ); |
|
891 | + self::scalarmult_throw_if_zero( $q ); |
|
892 | 892 | return $q; |
893 | 893 | } |
894 | 894 | |
@@ -902,10 +902,10 @@ discard block |
||
902 | 902 | * @throws SodiumException |
903 | 903 | * @throws TypeError |
904 | 904 | */ |
905 | - public static function scalarmult_base($secret) |
|
905 | + public static function scalarmult_base( $secret ) |
|
906 | 906 | { |
907 | - $q = ParagonIE_Sodium_Core_X25519::crypto_scalarmult_curve25519_ref10_base($secret); |
|
908 | - self::scalarmult_throw_if_zero($q); |
|
907 | + $q = ParagonIE_Sodium_Core_X25519::crypto_scalarmult_curve25519_ref10_base( $secret ); |
|
908 | + self::scalarmult_throw_if_zero( $q ); |
|
909 | 909 | return $q; |
910 | 910 | } |
911 | 911 | |
@@ -917,16 +917,16 @@ discard block |
||
917 | 917 | * @throws SodiumException |
918 | 918 | * @throws TypeError |
919 | 919 | */ |
920 | - protected static function scalarmult_throw_if_zero($q) |
|
920 | + protected static function scalarmult_throw_if_zero( $q ) |
|
921 | 921 | { |
922 | 922 | $d = 0; |
923 | - for ($i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i) { |
|
924 | - $d |= ParagonIE_Sodium_Core_Util::chrToInt($q[$i]); |
|
923 | + for ( $i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i ) { |
|
924 | + $d |= ParagonIE_Sodium_Core_Util::chrToInt( $q[ $i ] ); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /* branch-free variant of === 0 */ |
928 | - if (-(1 & (($d - 1) >> 8))) { |
|
929 | - throw new SodiumException('Zero public key is not allowed'); |
|
928 | + if (-( 1 & ( ( $d - 1 ) >> 8 ) )) { |
|
929 | + throw new SodiumException( 'Zero public key is not allowed' ); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
@@ -942,26 +942,26 @@ discard block |
||
942 | 942 | * @throws SodiumException |
943 | 943 | * @throws TypeError |
944 | 944 | */ |
945 | - public static function secretbox($plaintext, $nonce, $key) |
|
945 | + public static function secretbox( $plaintext, $nonce, $key ) |
|
946 | 946 | { |
947 | 947 | /** @var string $subkey */ |
948 | - $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20($nonce, $key); |
|
948 | + $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20( $nonce, $key ); |
|
949 | 949 | |
950 | 950 | /** @var string $block0 */ |
951 | - $block0 = str_repeat("\x00", 32); |
|
951 | + $block0 = str_repeat( "\x00", 32 ); |
|
952 | 952 | |
953 | 953 | /** @var int $mlen - Length of the plaintext message */ |
954 | - $mlen = ParagonIE_Sodium_Core_Util::strlen($plaintext); |
|
954 | + $mlen = ParagonIE_Sodium_Core_Util::strlen( $plaintext ); |
|
955 | 955 | $mlen0 = $mlen; |
956 | - if ($mlen0 > 64 - self::secretbox_xsalsa20poly1305_ZEROBYTES) { |
|
956 | + if ( $mlen0 > 64 - self::secretbox_xsalsa20poly1305_ZEROBYTES ) { |
|
957 | 957 | $mlen0 = 64 - self::secretbox_xsalsa20poly1305_ZEROBYTES; |
958 | 958 | } |
959 | - $block0 .= ParagonIE_Sodium_Core_Util::substr($plaintext, 0, $mlen0); |
|
959 | + $block0 .= ParagonIE_Sodium_Core_Util::substr( $plaintext, 0, $mlen0 ); |
|
960 | 960 | |
961 | 961 | /** @var string $block0 */ |
962 | 962 | $block0 = ParagonIE_Sodium_Core_Salsa20::salsa20_xor( |
963 | 963 | $block0, |
964 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), |
|
964 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ), |
|
965 | 965 | $subkey |
966 | 966 | ); |
967 | 967 | |
@@ -970,13 +970,13 @@ discard block |
||
970 | 970 | $block0, |
971 | 971 | self::secretbox_xsalsa20poly1305_ZEROBYTES |
972 | 972 | ); |
973 | - if ($mlen > $mlen0) { |
|
973 | + if ( $mlen > $mlen0 ) { |
|
974 | 974 | $c .= ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic( |
975 | 975 | ParagonIE_Sodium_Core_Util::substr( |
976 | 976 | $plaintext, |
977 | 977 | self::secretbox_xsalsa20poly1305_ZEROBYTES |
978 | 978 | ), |
979 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), |
|
979 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ), |
|
980 | 980 | 1, |
981 | 981 | $subkey |
982 | 982 | ); |
@@ -989,18 +989,18 @@ discard block |
||
989 | 989 | ) |
990 | 990 | ); |
991 | 991 | try { |
992 | - ParagonIE_Sodium_Compat::memzero($block0); |
|
993 | - ParagonIE_Sodium_Compat::memzero($subkey); |
|
994 | - } catch (SodiumException $ex) { |
|
992 | + ParagonIE_Sodium_Compat::memzero( $block0 ); |
|
993 | + ParagonIE_Sodium_Compat::memzero( $subkey ); |
|
994 | + } catch ( SodiumException $ex ) { |
|
995 | 995 | $block0 = null; |
996 | 996 | $subkey = null; |
997 | 997 | } |
998 | 998 | |
999 | - $state->update($c); |
|
999 | + $state->update( $c ); |
|
1000 | 1000 | |
1001 | 1001 | /** @var string $c - MAC || ciphertext */ |
1002 | 1002 | $c = $state->finish() . $c; |
1003 | - unset($state); |
|
1003 | + unset( $state ); |
|
1004 | 1004 | |
1005 | 1005 | return $c; |
1006 | 1006 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | * @throws SodiumException |
1018 | 1018 | * @throws TypeError |
1019 | 1019 | */ |
1020 | - public static function secretbox_open($ciphertext, $nonce, $key) |
|
1020 | + public static function secretbox_open( $ciphertext, $nonce, $key ) |
|
1021 | 1021 | { |
1022 | 1022 | /** @var string $mac */ |
1023 | 1023 | $mac = ParagonIE_Sodium_Core_Util::substr( |
@@ -1033,46 +1033,46 @@ discard block |
||
1033 | 1033 | ); |
1034 | 1034 | |
1035 | 1035 | /** @var int $clen */ |
1036 | - $clen = ParagonIE_Sodium_Core_Util::strlen($c); |
|
1036 | + $clen = ParagonIE_Sodium_Core_Util::strlen( $c ); |
|
1037 | 1037 | |
1038 | 1038 | /** @var string $subkey */ |
1039 | - $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20($nonce, $key); |
|
1039 | + $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20( $nonce, $key ); |
|
1040 | 1040 | |
1041 | 1041 | /** @var string $block0 */ |
1042 | 1042 | $block0 = ParagonIE_Sodium_Core_Salsa20::salsa20( |
1043 | 1043 | 64, |
1044 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), |
|
1044 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ), |
|
1045 | 1045 | $subkey |
1046 | 1046 | ); |
1047 | 1047 | $verified = ParagonIE_Sodium_Core_Poly1305::onetimeauth_verify( |
1048 | 1048 | $mac, |
1049 | 1049 | $c, |
1050 | - ParagonIE_Sodium_Core_Util::substr($block0, 0, 32) |
|
1050 | + ParagonIE_Sodium_Core_Util::substr( $block0, 0, 32 ) |
|
1051 | 1051 | ); |
1052 | - if (!$verified) { |
|
1052 | + if ( ! $verified ) { |
|
1053 | 1053 | try { |
1054 | - ParagonIE_Sodium_Compat::memzero($subkey); |
|
1055 | - } catch (SodiumException $ex) { |
|
1054 | + ParagonIE_Sodium_Compat::memzero( $subkey ); |
|
1055 | + } catch ( SodiumException $ex ) { |
|
1056 | 1056 | $subkey = null; |
1057 | 1057 | } |
1058 | - throw new SodiumException('Invalid MAC'); |
|
1058 | + throw new SodiumException( 'Invalid MAC' ); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | /** @var string $m - Decrypted message */ |
1062 | 1062 | $m = ParagonIE_Sodium_Core_Util::xorStrings( |
1063 | - ParagonIE_Sodium_Core_Util::substr($block0, self::secretbox_xsalsa20poly1305_ZEROBYTES), |
|
1064 | - ParagonIE_Sodium_Core_Util::substr($c, 0, self::secretbox_xsalsa20poly1305_ZEROBYTES) |
|
1063 | + ParagonIE_Sodium_Core_Util::substr( $block0, self::secretbox_xsalsa20poly1305_ZEROBYTES ), |
|
1064 | + ParagonIE_Sodium_Core_Util::substr( $c, 0, self::secretbox_xsalsa20poly1305_ZEROBYTES ) |
|
1065 | 1065 | ); |
1066 | - if ($clen > self::secretbox_xsalsa20poly1305_ZEROBYTES) { |
|
1066 | + if ( $clen > self::secretbox_xsalsa20poly1305_ZEROBYTES ) { |
|
1067 | 1067 | // We had more than 1 block, so let's continue to decrypt the rest. |
1068 | 1068 | $m .= ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic( |
1069 | 1069 | ParagonIE_Sodium_Core_Util::substr( |
1070 | 1070 | $c, |
1071 | 1071 | self::secretbox_xsalsa20poly1305_ZEROBYTES |
1072 | 1072 | ), |
1073 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), |
|
1073 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ), |
|
1074 | 1074 | 1, |
1075 | - (string) $subkey |
|
1075 | + (string)$subkey |
|
1076 | 1076 | ); |
1077 | 1077 | } |
1078 | 1078 | return $m; |
@@ -1090,25 +1090,25 @@ discard block |
||
1090 | 1090 | * @throws SodiumException |
1091 | 1091 | * @throws TypeError |
1092 | 1092 | */ |
1093 | - public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) |
|
1093 | + public static function secretbox_xchacha20poly1305( $plaintext, $nonce, $key ) |
|
1094 | 1094 | { |
1095 | 1095 | /** @var string $subkey */ |
1096 | 1096 | $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( |
1097 | - ParagonIE_Sodium_Core_Util::substr($nonce, 0, 16), |
|
1097 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 0, 16 ), |
|
1098 | 1098 | $key |
1099 | 1099 | ); |
1100 | - $nonceLast = ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8); |
|
1100 | + $nonceLast = ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ); |
|
1101 | 1101 | |
1102 | 1102 | /** @var string $block0 */ |
1103 | - $block0 = str_repeat("\x00", 32); |
|
1103 | + $block0 = str_repeat( "\x00", 32 ); |
|
1104 | 1104 | |
1105 | 1105 | /** @var int $mlen - Length of the plaintext message */ |
1106 | - $mlen = ParagonIE_Sodium_Core_Util::strlen($plaintext); |
|
1106 | + $mlen = ParagonIE_Sodium_Core_Util::strlen( $plaintext ); |
|
1107 | 1107 | $mlen0 = $mlen; |
1108 | - if ($mlen0 > 64 - self::secretbox_xchacha20poly1305_ZEROBYTES) { |
|
1108 | + if ( $mlen0 > 64 - self::secretbox_xchacha20poly1305_ZEROBYTES ) { |
|
1109 | 1109 | $mlen0 = 64 - self::secretbox_xchacha20poly1305_ZEROBYTES; |
1110 | 1110 | } |
1111 | - $block0 .= ParagonIE_Sodium_Core_Util::substr($plaintext, 0, $mlen0); |
|
1111 | + $block0 .= ParagonIE_Sodium_Core_Util::substr( $plaintext, 0, $mlen0 ); |
|
1112 | 1112 | |
1113 | 1113 | /** @var string $block0 */ |
1114 | 1114 | $block0 = ParagonIE_Sodium_Core_ChaCha20::streamXorIc( |
@@ -1122,7 +1122,7 @@ discard block |
||
1122 | 1122 | $block0, |
1123 | 1123 | self::secretbox_xchacha20poly1305_ZEROBYTES |
1124 | 1124 | ); |
1125 | - if ($mlen > $mlen0) { |
|
1125 | + if ( $mlen > $mlen0 ) { |
|
1126 | 1126 | $c .= ParagonIE_Sodium_Core_ChaCha20::streamXorIc( |
1127 | 1127 | ParagonIE_Sodium_Core_Util::substr( |
1128 | 1128 | $plaintext, |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | ), |
1131 | 1131 | $nonceLast, |
1132 | 1132 | $subkey, |
1133 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
1133 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
1134 | 1134 | ); |
1135 | 1135 | } |
1136 | 1136 | $state = new ParagonIE_Sodium_Core_Poly1305_State( |
@@ -1141,18 +1141,18 @@ discard block |
||
1141 | 1141 | ) |
1142 | 1142 | ); |
1143 | 1143 | try { |
1144 | - ParagonIE_Sodium_Compat::memzero($block0); |
|
1145 | - ParagonIE_Sodium_Compat::memzero($subkey); |
|
1146 | - } catch (SodiumException $ex) { |
|
1144 | + ParagonIE_Sodium_Compat::memzero( $block0 ); |
|
1145 | + ParagonIE_Sodium_Compat::memzero( $subkey ); |
|
1146 | + } catch ( SodiumException $ex ) { |
|
1147 | 1147 | $block0 = null; |
1148 | 1148 | $subkey = null; |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - $state->update($c); |
|
1151 | + $state->update( $c ); |
|
1152 | 1152 | |
1153 | 1153 | /** @var string $c - MAC || ciphertext */ |
1154 | 1154 | $c = $state->finish() . $c; |
1155 | - unset($state); |
|
1155 | + unset( $state ); |
|
1156 | 1156 | |
1157 | 1157 | return $c; |
1158 | 1158 | } |
@@ -1169,7 +1169,7 @@ discard block |
||
1169 | 1169 | * @throws SodiumException |
1170 | 1170 | * @throws TypeError |
1171 | 1171 | */ |
1172 | - public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) |
|
1172 | + public static function secretbox_xchacha20poly1305_open( $ciphertext, $nonce, $key ) |
|
1173 | 1173 | { |
1174 | 1174 | /** @var string $mac */ |
1175 | 1175 | $mac = ParagonIE_Sodium_Core_Util::substr( |
@@ -1185,48 +1185,48 @@ discard block |
||
1185 | 1185 | ); |
1186 | 1186 | |
1187 | 1187 | /** @var int $clen */ |
1188 | - $clen = ParagonIE_Sodium_Core_Util::strlen($c); |
|
1188 | + $clen = ParagonIE_Sodium_Core_Util::strlen( $c ); |
|
1189 | 1189 | |
1190 | 1190 | /** @var string $subkey */ |
1191 | - $subkey = ParagonIE_Sodium_Core_HChaCha20::hchacha20($nonce, $key); |
|
1191 | + $subkey = ParagonIE_Sodium_Core_HChaCha20::hchacha20( $nonce, $key ); |
|
1192 | 1192 | |
1193 | 1193 | /** @var string $block0 */ |
1194 | 1194 | $block0 = ParagonIE_Sodium_Core_ChaCha20::stream( |
1195 | 1195 | 64, |
1196 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), |
|
1196 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ), |
|
1197 | 1197 | $subkey |
1198 | 1198 | ); |
1199 | 1199 | $verified = ParagonIE_Sodium_Core_Poly1305::onetimeauth_verify( |
1200 | 1200 | $mac, |
1201 | 1201 | $c, |
1202 | - ParagonIE_Sodium_Core_Util::substr($block0, 0, 32) |
|
1202 | + ParagonIE_Sodium_Core_Util::substr( $block0, 0, 32 ) |
|
1203 | 1203 | ); |
1204 | 1204 | |
1205 | - if (!$verified) { |
|
1205 | + if ( ! $verified ) { |
|
1206 | 1206 | try { |
1207 | - ParagonIE_Sodium_Compat::memzero($subkey); |
|
1208 | - } catch (SodiumException $ex) { |
|
1207 | + ParagonIE_Sodium_Compat::memzero( $subkey ); |
|
1208 | + } catch ( SodiumException $ex ) { |
|
1209 | 1209 | $subkey = null; |
1210 | 1210 | } |
1211 | - throw new SodiumException('Invalid MAC'); |
|
1211 | + throw new SodiumException( 'Invalid MAC' ); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** @var string $m - Decrypted message */ |
1215 | 1215 | $m = ParagonIE_Sodium_Core_Util::xorStrings( |
1216 | - ParagonIE_Sodium_Core_Util::substr($block0, self::secretbox_xchacha20poly1305_ZEROBYTES), |
|
1217 | - ParagonIE_Sodium_Core_Util::substr($c, 0, self::secretbox_xchacha20poly1305_ZEROBYTES) |
|
1216 | + ParagonIE_Sodium_Core_Util::substr( $block0, self::secretbox_xchacha20poly1305_ZEROBYTES ), |
|
1217 | + ParagonIE_Sodium_Core_Util::substr( $c, 0, self::secretbox_xchacha20poly1305_ZEROBYTES ) |
|
1218 | 1218 | ); |
1219 | 1219 | |
1220 | - if ($clen > self::secretbox_xchacha20poly1305_ZEROBYTES) { |
|
1220 | + if ( $clen > self::secretbox_xchacha20poly1305_ZEROBYTES ) { |
|
1221 | 1221 | // We had more than 1 block, so let's continue to decrypt the rest. |
1222 | 1222 | $m .= ParagonIE_Sodium_Core_ChaCha20::streamXorIc( |
1223 | 1223 | ParagonIE_Sodium_Core_Util::substr( |
1224 | 1224 | $c, |
1225 | 1225 | self::secretbox_xchacha20poly1305_ZEROBYTES |
1226 | 1226 | ), |
1227 | - ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), |
|
1228 | - (string) $subkey, |
|
1229 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
1227 | + ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ), |
|
1228 | + (string)$subkey, |
|
1229 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
1230 | 1230 | ); |
1231 | 1231 | } |
1232 | 1232 | return $m; |
@@ -1238,16 +1238,16 @@ discard block |
||
1238 | 1238 | * @throws Exception |
1239 | 1239 | * @throws SodiumException |
1240 | 1240 | */ |
1241 | - public static function secretstream_xchacha20poly1305_init_push($key) |
|
1241 | + public static function secretstream_xchacha20poly1305_init_push( $key ) |
|
1242 | 1242 | { |
1243 | 1243 | # randombytes_buf(out, crypto_secretstream_xchacha20poly1305_HEADERBYTES); |
1244 | - $out = random_bytes(24); |
|
1244 | + $out = random_bytes( 24 ); |
|
1245 | 1245 | |
1246 | 1246 | # crypto_core_hchacha20(state->k, out, k, NULL); |
1247 | - $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20($out, $key); |
|
1247 | + $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( $out, $key ); |
|
1248 | 1248 | $state = new ParagonIE_Sodium_Core_SecretStream_State( |
1249 | 1249 | $subkey, |
1250 | - ParagonIE_Sodium_Core_Util::substr($out, 16, 8) . str_repeat("\0", 4) |
|
1250 | + ParagonIE_Sodium_Core_Util::substr( $out, 16, 8 ) . str_repeat( "\0", 4 ) |
|
1251 | 1251 | ); |
1252 | 1252 | |
1253 | 1253 | # _crypto_secretstream_xchacha20poly1305_counter_reset(state); |
@@ -1268,16 +1268,16 @@ discard block |
||
1268 | 1268 | * @return string Returns a state. |
1269 | 1269 | * @throws Exception |
1270 | 1270 | */ |
1271 | - public static function secretstream_xchacha20poly1305_init_pull($key, $header) |
|
1271 | + public static function secretstream_xchacha20poly1305_init_pull( $key, $header ) |
|
1272 | 1272 | { |
1273 | 1273 | # crypto_core_hchacha20(state->k, in, k, NULL); |
1274 | 1274 | $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( |
1275 | - ParagonIE_Sodium_Core_Util::substr($header, 0, 16), |
|
1275 | + ParagonIE_Sodium_Core_Util::substr( $header, 0, 16 ), |
|
1276 | 1276 | $key |
1277 | 1277 | ); |
1278 | 1278 | $state = new ParagonIE_Sodium_Core_SecretStream_State( |
1279 | 1279 | $subkey, |
1280 | - ParagonIE_Sodium_Core_Util::substr($header, 16) |
|
1280 | + ParagonIE_Sodium_Core_Util::substr( $header, 16 ) |
|
1281 | 1281 | ); |
1282 | 1282 | $state->counterReset(); |
1283 | 1283 | # memcpy(STATE_INONCE(state), in + crypto_core_hchacha20_INPUTBYTES, |
@@ -1295,19 +1295,19 @@ discard block |
||
1295 | 1295 | * @return string |
1296 | 1296 | * @throws SodiumException |
1297 | 1297 | */ |
1298 | - public static function secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) |
|
1298 | + public static function secretstream_xchacha20poly1305_push( &$state, $msg, $aad = '', $tag = 0 ) |
|
1299 | 1299 | { |
1300 | - $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state); |
|
1300 | + $st = ParagonIE_Sodium_Core_SecretStream_State::fromString( $state ); |
|
1301 | 1301 | # crypto_onetimeauth_poly1305_state poly1305_state; |
1302 | 1302 | # unsigned char block[64U]; |
1303 | 1303 | # unsigned char slen[8U]; |
1304 | 1304 | # unsigned char *c; |
1305 | 1305 | # unsigned char *mac; |
1306 | 1306 | |
1307 | - $msglen = ParagonIE_Sodium_Core_Util::strlen($msg); |
|
1308 | - $aadlen = ParagonIE_Sodium_Core_Util::strlen($aad); |
|
1307 | + $msglen = ParagonIE_Sodium_Core_Util::strlen( $msg ); |
|
1308 | + $aadlen = ParagonIE_Sodium_Core_Util::strlen( $aad ); |
|
1309 | 1309 | |
1310 | - if ((($msglen + 63) >> 6) > 0xfffffffe) { |
|
1310 | + if ( ( ( $msglen + 63 ) >> 6 ) > 0xfffffffe ) { |
|
1311 | 1311 | throw new SodiumException( |
1312 | 1312 | 'message cannot be larger than SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX bytes' |
1313 | 1313 | ); |
@@ -1324,62 +1324,62 @@ discard block |
||
1324 | 1324 | # crypto_onetimeauth_poly1305_init(&poly1305_state, block); |
1325 | 1325 | # sodium_memzero(block, sizeof block); |
1326 | 1326 | $auth = new ParagonIE_Sodium_Core_Poly1305_State( |
1327 | - ParagonIE_Sodium_Core_ChaCha20::ietfStream(32, $st->getCombinedNonce(), $st->getKey()) |
|
1327 | + ParagonIE_Sodium_Core_ChaCha20::ietfStream( 32, $st->getCombinedNonce(), $st->getKey() ) |
|
1328 | 1328 | ); |
1329 | 1329 | |
1330 | 1330 | # crypto_onetimeauth_poly1305_update(&poly1305_state, ad, adlen); |
1331 | - $auth->update($aad); |
|
1331 | + $auth->update( $aad ); |
|
1332 | 1332 | |
1333 | 1333 | # crypto_onetimeauth_poly1305_update(&poly1305_state, _pad0, |
1334 | 1334 | # (0x10 - adlen) & 0xf); |
1335 | - $auth->update(str_repeat("\0", ((0x10 - $aadlen) & 0xf))); |
|
1335 | + $auth->update( str_repeat( "\0", ( ( 0x10 - $aadlen ) & 0xf ) ) ); |
|
1336 | 1336 | |
1337 | 1337 | # memset(block, 0, sizeof block); |
1338 | 1338 | # block[0] = tag; |
1339 | 1339 | # crypto_stream_chacha20_ietf_xor_ic(block, block, sizeof block, |
1340 | 1340 | # state->nonce, 1U, state->k); |
1341 | 1341 | $block = ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc( |
1342 | - ParagonIE_Sodium_Core_Util::intToChr($tag) . str_repeat("\0", 63), |
|
1342 | + ParagonIE_Sodium_Core_Util::intToChr( $tag ) . str_repeat( "\0", 63 ), |
|
1343 | 1343 | $st->getCombinedNonce(), |
1344 | 1344 | $st->getKey(), |
1345 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
1345 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
1346 | 1346 | ); |
1347 | 1347 | |
1348 | 1348 | # crypto_onetimeauth_poly1305_update(&poly1305_state, block, sizeof block); |
1349 | - $auth->update($block); |
|
1349 | + $auth->update( $block ); |
|
1350 | 1350 | |
1351 | 1351 | # out[0] = block[0]; |
1352 | - $out = $block[0]; |
|
1352 | + $out = $block[ 0 ]; |
|
1353 | 1353 | # c = out + (sizeof tag); |
1354 | 1354 | # crypto_stream_chacha20_ietf_xor_ic(c, m, mlen, state->nonce, 2U, state->k); |
1355 | 1355 | $cipher = ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc( |
1356 | 1356 | $msg, |
1357 | 1357 | $st->getCombinedNonce(), |
1358 | 1358 | $st->getKey(), |
1359 | - ParagonIE_Sodium_Core_Util::store64_le(2) |
|
1359 | + ParagonIE_Sodium_Core_Util::store64_le( 2 ) |
|
1360 | 1360 | ); |
1361 | 1361 | |
1362 | 1362 | # crypto_onetimeauth_poly1305_update(&poly1305_state, c, mlen); |
1363 | - $auth->update($cipher); |
|
1363 | + $auth->update( $cipher ); |
|
1364 | 1364 | |
1365 | 1365 | $out .= $cipher; |
1366 | - unset($cipher); |
|
1366 | + unset( $cipher ); |
|
1367 | 1367 | |
1368 | 1368 | # crypto_onetimeauth_poly1305_update |
1369 | 1369 | # (&poly1305_state, _pad0, (0x10 - (sizeof block) + mlen) & 0xf); |
1370 | - $auth->update(str_repeat("\0", ((0x10 - 64 + $msglen) & 0xf))); |
|
1370 | + $auth->update( str_repeat( "\0", ( ( 0x10 - 64 + $msglen ) & 0xf ) ) ); |
|
1371 | 1371 | |
1372 | 1372 | # STORE64_LE(slen, (uint64_t) adlen); |
1373 | - $slen = ParagonIE_Sodium_Core_Util::store64_le($aadlen); |
|
1373 | + $slen = ParagonIE_Sodium_Core_Util::store64_le( $aadlen ); |
|
1374 | 1374 | |
1375 | 1375 | # crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen); |
1376 | - $auth->update($slen); |
|
1376 | + $auth->update( $slen ); |
|
1377 | 1377 | |
1378 | 1378 | # STORE64_LE(slen, (sizeof block) + mlen); |
1379 | - $slen = ParagonIE_Sodium_Core_Util::store64_le(64 + $msglen); |
|
1379 | + $slen = ParagonIE_Sodium_Core_Util::store64_le( 64 + $msglen ); |
|
1380 | 1380 | |
1381 | 1381 | # crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen); |
1382 | - $auth->update($slen); |
|
1382 | + $auth->update( $slen ); |
|
1383 | 1383 | |
1384 | 1384 | # mac = c + mlen; |
1385 | 1385 | # crypto_onetimeauth_poly1305_final(&poly1305_state, mac); |
@@ -1387,12 +1387,12 @@ discard block |
||
1387 | 1387 | $out .= $mac; |
1388 | 1388 | |
1389 | 1389 | # sodium_memzero(&poly1305_state, sizeof poly1305_state); |
1390 | - unset($auth); |
|
1390 | + unset( $auth ); |
|
1391 | 1391 | |
1392 | 1392 | |
1393 | 1393 | # XOR_BUF(STATE_INONCE(state), mac, |
1394 | 1394 | # crypto_secretstream_xchacha20poly1305_INONCEBYTES); |
1395 | - $st->xorNonce($mac); |
|
1395 | + $st->xorNonce( $mac ); |
|
1396 | 1396 | |
1397 | 1397 | # sodium_increment(STATE_COUNTER(state), |
1398 | 1398 | # crypto_secretstream_xchacha20poly1305_COUNTERBYTES); |
@@ -1401,15 +1401,15 @@ discard block |
||
1401 | 1401 | $state = $st->toString(); |
1402 | 1402 | |
1403 | 1403 | /** @var bool $rekey */ |
1404 | - $rekey = ($tag & ParagonIE_Sodium_Compat::CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY) !== 0; |
|
1404 | + $rekey = ( $tag & ParagonIE_Sodium_Compat::CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY ) !== 0; |
|
1405 | 1405 | # if ((tag & crypto_secretstream_xchacha20poly1305_TAG_REKEY) != 0 || |
1406 | 1406 | # sodium_is_zero(STATE_COUNTER(state), |
1407 | 1407 | # crypto_secretstream_xchacha20poly1305_COUNTERBYTES)) { |
1408 | 1408 | # crypto_secretstream_xchacha20poly1305_rekey(state); |
1409 | 1409 | # } |
1410 | - if ($rekey || $st->needsRekey()) { |
|
1410 | + if ( $rekey || $st->needsRekey() ) { |
|
1411 | 1411 | // DO REKEY |
1412 | - self::secretstream_xchacha20poly1305_rekey($state); |
|
1412 | + self::secretstream_xchacha20poly1305_rekey( $state ); |
|
1413 | 1413 | } |
1414 | 1414 | # if (outlen_p != NULL) { |
1415 | 1415 | # *outlen_p = crypto_secretstream_xchacha20poly1305_ABYTES + mlen; |
@@ -1424,19 +1424,19 @@ discard block |
||
1424 | 1424 | * @return bool|array{0: string, 1: int} |
1425 | 1425 | * @throws SodiumException |
1426 | 1426 | */ |
1427 | - public static function secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') |
|
1427 | + public static function secretstream_xchacha20poly1305_pull( &$state, $cipher, $aad = '' ) |
|
1428 | 1428 | { |
1429 | - $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state); |
|
1429 | + $st = ParagonIE_Sodium_Core_SecretStream_State::fromString( $state ); |
|
1430 | 1430 | |
1431 | - $cipherlen = ParagonIE_Sodium_Core_Util::strlen($cipher); |
|
1431 | + $cipherlen = ParagonIE_Sodium_Core_Util::strlen( $cipher ); |
|
1432 | 1432 | # mlen = inlen - crypto_secretstream_xchacha20poly1305_ABYTES; |
1433 | 1433 | $msglen = $cipherlen - ParagonIE_Sodium_Compat::CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES; |
1434 | - $aadlen = ParagonIE_Sodium_Core_Util::strlen($aad); |
|
1434 | + $aadlen = ParagonIE_Sodium_Core_Util::strlen( $aad ); |
|
1435 | 1435 | |
1436 | 1436 | # if (mlen > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX) { |
1437 | 1437 | # sodium_misuse(); |
1438 | 1438 | # } |
1439 | - if ((($msglen + 63) >> 6) > 0xfffffffe) { |
|
1439 | + if ( ( ( $msglen + 63 ) >> 6 ) > 0xfffffffe ) { |
|
1440 | 1440 | throw new SodiumException( |
1441 | 1441 | 'message cannot be larger than SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX bytes' |
1442 | 1442 | ); |
@@ -1446,15 +1446,15 @@ discard block |
||
1446 | 1446 | # crypto_onetimeauth_poly1305_init(&poly1305_state, block); |
1447 | 1447 | # sodium_memzero(block, sizeof block); |
1448 | 1448 | $auth = new ParagonIE_Sodium_Core_Poly1305_State( |
1449 | - ParagonIE_Sodium_Core_ChaCha20::ietfStream(32, $st->getCombinedNonce(), $st->getKey()) |
|
1449 | + ParagonIE_Sodium_Core_ChaCha20::ietfStream( 32, $st->getCombinedNonce(), $st->getKey() ) |
|
1450 | 1450 | ); |
1451 | 1451 | |
1452 | 1452 | # crypto_onetimeauth_poly1305_update(&poly1305_state, ad, adlen); |
1453 | - $auth->update($aad); |
|
1453 | + $auth->update( $aad ); |
|
1454 | 1454 | |
1455 | 1455 | # crypto_onetimeauth_poly1305_update(&poly1305_state, _pad0, |
1456 | 1456 | # (0x10 - adlen) & 0xf); |
1457 | - $auth->update(str_repeat("\0", ((0x10 - $aadlen) & 0xf))); |
|
1457 | + $auth->update( str_repeat( "\0", ( ( 0x10 - $aadlen ) & 0xf ) ) ); |
|
1458 | 1458 | |
1459 | 1459 | |
1460 | 1460 | # memset(block, 0, sizeof block); |
@@ -1462,36 +1462,36 @@ discard block |
||
1462 | 1462 | # crypto_stream_chacha20_ietf_xor_ic(block, block, sizeof block, |
1463 | 1463 | # state->nonce, 1U, state->k); |
1464 | 1464 | $block = ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc( |
1465 | - $cipher[0] . str_repeat("\0", 63), |
|
1465 | + $cipher[ 0 ] . str_repeat( "\0", 63 ), |
|
1466 | 1466 | $st->getCombinedNonce(), |
1467 | 1467 | $st->getKey(), |
1468 | - ParagonIE_Sodium_Core_Util::store64_le(1) |
|
1468 | + ParagonIE_Sodium_Core_Util::store64_le( 1 ) |
|
1469 | 1469 | ); |
1470 | 1470 | # tag = block[0]; |
1471 | 1471 | # block[0] = in[0]; |
1472 | 1472 | # crypto_onetimeauth_poly1305_update(&poly1305_state, block, sizeof block); |
1473 | - $tag = ParagonIE_Sodium_Core_Util::chrToInt($block[0]); |
|
1474 | - $block[0] = $cipher[0]; |
|
1475 | - $auth->update($block); |
|
1473 | + $tag = ParagonIE_Sodium_Core_Util::chrToInt( $block[ 0 ] ); |
|
1474 | + $block[ 0 ] = $cipher[ 0 ]; |
|
1475 | + $auth->update( $block ); |
|
1476 | 1476 | |
1477 | 1477 | |
1478 | 1478 | # c = in + (sizeof tag); |
1479 | 1479 | # crypto_onetimeauth_poly1305_update(&poly1305_state, c, mlen); |
1480 | - $auth->update(ParagonIE_Sodium_Core_Util::substr($cipher, 1, $msglen)); |
|
1480 | + $auth->update( ParagonIE_Sodium_Core_Util::substr( $cipher, 1, $msglen ) ); |
|
1481 | 1481 | |
1482 | 1482 | # crypto_onetimeauth_poly1305_update |
1483 | 1483 | # (&poly1305_state, _pad0, (0x10 - (sizeof block) + mlen) & 0xf); |
1484 | - $auth->update(str_repeat("\0", ((0x10 - 64 + $msglen) & 0xf))); |
|
1484 | + $auth->update( str_repeat( "\0", ( ( 0x10 - 64 + $msglen ) & 0xf ) ) ); |
|
1485 | 1485 | |
1486 | 1486 | # STORE64_LE(slen, (uint64_t) adlen); |
1487 | 1487 | # crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen); |
1488 | - $slen = ParagonIE_Sodium_Core_Util::store64_le($aadlen); |
|
1489 | - $auth->update($slen); |
|
1488 | + $slen = ParagonIE_Sodium_Core_Util::store64_le( $aadlen ); |
|
1489 | + $auth->update( $slen ); |
|
1490 | 1490 | |
1491 | 1491 | # STORE64_LE(slen, (sizeof block) + mlen); |
1492 | 1492 | # crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen); |
1493 | - $slen = ParagonIE_Sodium_Core_Util::store64_le(64 + $msglen); |
|
1494 | - $auth->update($slen); |
|
1493 | + $slen = ParagonIE_Sodium_Core_Util::store64_le( 64 + $msglen ); |
|
1494 | + $auth->update( $slen ); |
|
1495 | 1495 | |
1496 | 1496 | # crypto_onetimeauth_poly1305_final(&poly1305_state, mac); |
1497 | 1497 | # sodium_memzero(&poly1305_state, sizeof poly1305_state); |
@@ -1503,22 +1503,22 @@ discard block |
||
1503 | 1503 | # return -1; |
1504 | 1504 | # } |
1505 | 1505 | |
1506 | - $stored = ParagonIE_Sodium_Core_Util::substr($cipher, $msglen + 1, 16); |
|
1507 | - if (!ParagonIE_Sodium_Core_Util::hashEquals($mac, $stored)) { |
|
1506 | + $stored = ParagonIE_Sodium_Core_Util::substr( $cipher, $msglen + 1, 16 ); |
|
1507 | + if ( ! ParagonIE_Sodium_Core_Util::hashEquals( $mac, $stored ) ) { |
|
1508 | 1508 | return false; |
1509 | 1509 | } |
1510 | 1510 | |
1511 | 1511 | # crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, state->nonce, 2U, state->k); |
1512 | 1512 | $out = ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc( |
1513 | - ParagonIE_Sodium_Core_Util::substr($cipher, 1, $msglen), |
|
1513 | + ParagonIE_Sodium_Core_Util::substr( $cipher, 1, $msglen ), |
|
1514 | 1514 | $st->getCombinedNonce(), |
1515 | 1515 | $st->getKey(), |
1516 | - ParagonIE_Sodium_Core_Util::store64_le(2) |
|
1516 | + ParagonIE_Sodium_Core_Util::store64_le( 2 ) |
|
1517 | 1517 | ); |
1518 | 1518 | |
1519 | 1519 | # XOR_BUF(STATE_INONCE(state), mac, |
1520 | 1520 | # crypto_secretstream_xchacha20poly1305_INONCEBYTES); |
1521 | - $st->xorNonce($mac); |
|
1521 | + $st->xorNonce( $mac ); |
|
1522 | 1522 | |
1523 | 1523 | # sodium_increment(STATE_COUNTER(state), |
1524 | 1524 | # crypto_secretstream_xchacha20poly1305_COUNTERBYTES); |
@@ -1534,12 +1534,12 @@ discard block |
||
1534 | 1534 | $state = $st->toString(); |
1535 | 1535 | |
1536 | 1536 | /** @var bool $rekey */ |
1537 | - $rekey = ($tag & ParagonIE_Sodium_Compat::CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY) !== 0; |
|
1538 | - if ($rekey || $st->needsRekey()) { |
|
1537 | + $rekey = ( $tag & ParagonIE_Sodium_Compat::CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY ) !== 0; |
|
1538 | + if ( $rekey || $st->needsRekey() ) { |
|
1539 | 1539 | // DO REKEY |
1540 | - self::secretstream_xchacha20poly1305_rekey($state); |
|
1540 | + self::secretstream_xchacha20poly1305_rekey( $state ); |
|
1541 | 1541 | } |
1542 | - return array($out, $tag); |
|
1542 | + return array( $out, $tag ); |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | 1545 | /** |
@@ -1547,9 +1547,9 @@ discard block |
||
1547 | 1547 | * @return void |
1548 | 1548 | * @throws SodiumException |
1549 | 1549 | */ |
1550 | - public static function secretstream_xchacha20poly1305_rekey(&$state) |
|
1550 | + public static function secretstream_xchacha20poly1305_rekey( &$state ) |
|
1551 | 1551 | { |
1552 | - $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state); |
|
1552 | + $st = ParagonIE_Sodium_Core_SecretStream_State::fromString( $state ); |
|
1553 | 1553 | # unsigned char new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + |
1554 | 1554 | # crypto_secretstream_xchacha20poly1305_INONCEBYTES]; |
1555 | 1555 | # size_t i; |
@@ -1562,18 +1562,18 @@ discard block |
||
1562 | 1562 | # new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] = |
1563 | 1563 | # STATE_INONCE(state)[i]; |
1564 | 1564 | # } |
1565 | - $new_key_and_inonce .= ParagonIE_Sodium_Core_Util::substR($st->getNonce(), 0, 8); |
|
1565 | + $new_key_and_inonce .= ParagonIE_Sodium_Core_Util::substR( $st->getNonce(), 0, 8 ); |
|
1566 | 1566 | |
1567 | 1567 | # crypto_stream_chacha20_ietf_xor(new_key_and_inonce, new_key_and_inonce, |
1568 | 1568 | # sizeof new_key_and_inonce, |
1569 | 1569 | # state->nonce, state->k); |
1570 | 1570 | |
1571 | - $st->rekey(ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc( |
|
1571 | + $st->rekey( ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc( |
|
1572 | 1572 | $new_key_and_inonce, |
1573 | 1573 | $st->getCombinedNonce(), |
1574 | 1574 | $st->getKey(), |
1575 | - ParagonIE_Sodium_Core_Util::store64_le(0) |
|
1576 | - )); |
|
1575 | + ParagonIE_Sodium_Core_Util::store64_le( 0 ) |
|
1576 | + ) ); |
|
1577 | 1577 | |
1578 | 1578 | # for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) { |
1579 | 1579 | # state->k[i] = new_key_and_inonce[i]; |
@@ -1599,9 +1599,9 @@ discard block |
||
1599 | 1599 | * @throws SodiumException |
1600 | 1600 | * @throws TypeError |
1601 | 1601 | */ |
1602 | - public static function sign_detached($message, $sk) |
|
1602 | + public static function sign_detached( $message, $sk ) |
|
1603 | 1603 | { |
1604 | - return ParagonIE_Sodium_Core_Ed25519::sign_detached($message, $sk); |
|
1604 | + return ParagonIE_Sodium_Core_Ed25519::sign_detached( $message, $sk ); |
|
1605 | 1605 | } |
1606 | 1606 | |
1607 | 1607 | /** |
@@ -1615,9 +1615,9 @@ discard block |
||
1615 | 1615 | * @throws SodiumException |
1616 | 1616 | * @throws TypeError |
1617 | 1617 | */ |
1618 | - public static function sign($message, $sk) |
|
1618 | + public static function sign( $message, $sk ) |
|
1619 | 1619 | { |
1620 | - return ParagonIE_Sodium_Core_Ed25519::sign($message, $sk); |
|
1620 | + return ParagonIE_Sodium_Core_Ed25519::sign( $message, $sk ); |
|
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | /** |
@@ -1631,9 +1631,9 @@ discard block |
||
1631 | 1631 | * @throws SodiumException |
1632 | 1632 | * @throws TypeError |
1633 | 1633 | */ |
1634 | - public static function sign_open($signedMessage, $pk) |
|
1634 | + public static function sign_open( $signedMessage, $pk ) |
|
1635 | 1635 | { |
1636 | - return ParagonIE_Sodium_Core_Ed25519::sign_open($signedMessage, $pk); |
|
1636 | + return ParagonIE_Sodium_Core_Ed25519::sign_open( $signedMessage, $pk ); |
|
1637 | 1637 | } |
1638 | 1638 | |
1639 | 1639 | /** |
@@ -1648,8 +1648,8 @@ discard block |
||
1648 | 1648 | * @throws SodiumException |
1649 | 1649 | * @throws TypeError |
1650 | 1650 | */ |
1651 | - public static function sign_verify_detached($signature, $message, $pk) |
|
1651 | + public static function sign_verify_detached( $signature, $message, $pk ) |
|
1652 | 1652 | { |
1653 | - return ParagonIE_Sodium_Core_Ed25519::verify_detached($signature, $message, $pk); |
|
1653 | + return ParagonIE_Sodium_Core_Ed25519::verify_detached( $signature, $message, $pk ); |
|
1654 | 1654 | } |
1655 | 1655 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('SplFixedArray')) { |
|
3 | +if ( class_exists( 'SplFixedArray' ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * SplFixedArray constructor. |
24 | 24 | * @param int $size |
25 | 25 | */ |
26 | - public function __construct($size = 0) |
|
26 | + public function __construct( $size = 0 ) |
|
27 | 27 | { |
28 | 28 | $this->size = $size; |
29 | 29 | $this->internalArray = array(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function count() |
36 | 36 | { |
37 | - return count($this->internalArray); |
|
37 | + return count( $this->internalArray ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function toArray() |
44 | 44 | { |
45 | - ksort($this->internalArray); |
|
46 | - return (array) $this->internalArray; |
|
45 | + ksort( $this->internalArray ); |
|
46 | + return (array)$this->internalArray; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,17 +52,17 @@ discard block |
||
52 | 52 | * @return SplFixedArray |
53 | 53 | * @psalm-suppress MixedAssignment |
54 | 54 | */ |
55 | - public static function fromArray(array $array, $save_indexes = true) |
|
55 | + public static function fromArray( array $array, $save_indexes = true ) |
|
56 | 56 | { |
57 | - $self = new SplFixedArray(count($array)); |
|
58 | - if($save_indexes) { |
|
59 | - foreach($array as $key => $value) { |
|
60 | - $self[(int) $key] = $value; |
|
57 | + $self = new SplFixedArray( count( $array ) ); |
|
58 | + if ( $save_indexes ) { |
|
59 | + foreach ( $array as $key => $value ) { |
|
60 | + $self[ (int)$key ] = $value; |
|
61 | 61 | } |
62 | 62 | } else { |
63 | 63 | $i = 0; |
64 | - foreach (array_values($array) as $value) { |
|
65 | - $self[$i] = $value; |
|
64 | + foreach ( array_values( $array ) as $value ) { |
|
65 | + $self[ $i ] = $value; |
|
66 | 66 | $i++; |
67 | 67 | } |
68 | 68 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param int $size |
82 | 82 | * @return bool |
83 | 83 | */ |
84 | - public function setSize($size) |
|
84 | + public function setSize( $size ) |
|
85 | 85 | { |
86 | 86 | $this->size = $size; |
87 | 87 | return true; |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | * @param string|int $index |
92 | 92 | * @return bool |
93 | 93 | */ |
94 | - public function offsetExists($index) |
|
94 | + public function offsetExists( $index ) |
|
95 | 95 | { |
96 | - return array_key_exists((int) $index, $this->internalArray); |
|
96 | + return array_key_exists( (int)$index, $this->internalArray ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @param string|int $index |
101 | 101 | * @return mixed |
102 | 102 | */ |
103 | - public function offsetGet($index) |
|
103 | + public function offsetGet( $index ) |
|
104 | 104 | { |
105 | 105 | /** @psalm-suppress MixedReturnStatement */ |
106 | - return $this->internalArray[(int) $index]; |
|
106 | + return $this->internalArray[ (int)$index ]; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param mixed $newval |
112 | 112 | * @psalm-suppress MixedAssignment |
113 | 113 | */ |
114 | - public function offsetSet($index, $newval) |
|
114 | + public function offsetSet( $index, $newval ) |
|
115 | 115 | { |
116 | - $this->internalArray[(int) $index] = $newval; |
|
116 | + $this->internalArray[ (int)$index ] = $newval; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * @param string|int $index |
121 | 121 | */ |
122 | - public function offsetUnset($index) |
|
122 | + public function offsetUnset( $index ) |
|
123 | 123 | { |
124 | - unset($this->internalArray[(int) $index]); |
|
124 | + unset( $this->internalArray[ (int)$index ] ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function rewind() |
134 | 134 | { |
135 | - reset($this->internalArray); |
|
135 | + reset( $this->internalArray ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | public function current() |
145 | 145 | { |
146 | 146 | /** @psalm-suppress MixedReturnStatement */ |
147 | - return current($this->internalArray); |
|
147 | + return current( $this->internalArray ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function key() |
155 | 155 | { |
156 | - return key($this->internalArray); |
|
156 | + return key( $this->internalArray ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function next() |
163 | 163 | { |
164 | - next($this->internalArray); |
|
164 | + next( $this->internalArray ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function valid() |
173 | 173 | { |
174 | - if (empty($this->internalArray)) { |
|
174 | + if ( empty( $this->internalArray ) ) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | - $result = next($this->internalArray) !== false; |
|
178 | - prev($this->internalArray); |
|
177 | + $result = next( $this->internalArray ) !== false; |
|
178 | + prev( $this->internalArray ); |
|
179 | 179 | return $result; |
180 | 180 | } |
181 | 181 |