@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_Ed25519', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_Ed25519', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function keypair() |
25 | 25 | { |
26 | - $seed = random_bytes(self::SEED_BYTES); |
|
26 | + $seed = random_bytes( self::SEED_BYTES ); |
|
27 | 27 | $pk = ''; |
28 | 28 | $sk = ''; |
29 | - self::seed_keypair($pk, $sk, $seed); |
|
29 | + self::seed_keypair( $pk, $sk, $seed ); |
|
30 | 30 | return $sk . $pk; |
31 | 31 | } |
32 | 32 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | * @throws SodiumException |
41 | 41 | * @throws TypeError |
42 | 42 | */ |
43 | - public static function seed_keypair(&$pk, &$sk, $seed) |
|
43 | + public static function seed_keypair( &$pk, &$sk, $seed ) |
|
44 | 44 | { |
45 | - if (self::strlen($seed) !== self::SEED_BYTES) { |
|
46 | - throw new RangeException('crypto_sign keypair seed must be 32 bytes long'); |
|
45 | + if ( self::strlen( $seed ) !== self::SEED_BYTES ) { |
|
46 | + throw new RangeException( 'crypto_sign keypair seed must be 32 bytes long' ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** @var string $pk */ |
50 | - $pk = self::publickey_from_secretkey($seed); |
|
50 | + $pk = self::publickey_from_secretkey( $seed ); |
|
51 | 51 | $sk = $seed . $pk; |
52 | 52 | return $sk; |
53 | 53 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @return string |
60 | 60 | * @throws TypeError |
61 | 61 | */ |
62 | - public static function secretkey($keypair) |
|
62 | + public static function secretkey( $keypair ) |
|
63 | 63 | { |
64 | - if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { |
|
65 | - throw new RangeException('crypto_sign keypair must be 96 bytes long'); |
|
64 | + if ( self::strlen( $keypair ) !== self::KEYPAIR_BYTES ) { |
|
65 | + throw new RangeException( 'crypto_sign keypair must be 96 bytes long' ); |
|
66 | 66 | } |
67 | - return self::substr($keypair, 0, 64); |
|
67 | + return self::substr( $keypair, 0, 64 ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * @return string |
75 | 75 | * @throws TypeError |
76 | 76 | */ |
77 | - public static function publickey($keypair) |
|
77 | + public static function publickey( $keypair ) |
|
78 | 78 | { |
79 | - if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { |
|
80 | - throw new RangeException('crypto_sign keypair must be 96 bytes long'); |
|
79 | + if ( self::strlen( $keypair ) !== self::KEYPAIR_BYTES ) { |
|
80 | + throw new RangeException( 'crypto_sign keypair must be 96 bytes long' ); |
|
81 | 81 | } |
82 | - return self::substr($keypair, 64, 32); |
|
82 | + return self::substr( $keypair, 64, 32 ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,17 +90,17 @@ discard block |
||
90 | 90 | * @throws SodiumException |
91 | 91 | * @throws TypeError |
92 | 92 | */ |
93 | - public static function publickey_from_secretkey($sk) |
|
93 | + public static function publickey_from_secretkey( $sk ) |
|
94 | 94 | { |
95 | 95 | /** @var string $sk */ |
96 | - $sk = hash('sha512', self::substr($sk, 0, 32), true); |
|
97 | - $sk[0] = self::intToChr( |
|
98 | - self::chrToInt($sk[0]) & 248 |
|
96 | + $sk = hash( 'sha512', self::substr( $sk, 0, 32 ), true ); |
|
97 | + $sk[ 0 ] = self::intToChr( |
|
98 | + self::chrToInt( $sk[ 0 ] ) & 248 |
|
99 | 99 | ); |
100 | - $sk[31] = self::intToChr( |
|
101 | - (self::chrToInt($sk[31]) & 63) | 64 |
|
100 | + $sk[ 31 ] = self::intToChr( |
|
101 | + ( self::chrToInt( $sk[ 31 ] ) & 63 ) | 64 |
|
102 | 102 | ); |
103 | - return self::sk_to_pk($sk); |
|
103 | + return self::sk_to_pk( $sk ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | * @throws SodiumException |
110 | 110 | * @throws TypeError |
111 | 111 | */ |
112 | - public static function pk_to_curve25519($pk) |
|
112 | + public static function pk_to_curve25519( $pk ) |
|
113 | 113 | { |
114 | - if (self::small_order($pk)) { |
|
115 | - throw new SodiumException('Public key is on a small order'); |
|
114 | + if ( self::small_order( $pk ) ) { |
|
115 | + throw new SodiumException( 'Public key is on a small order' ); |
|
116 | 116 | } |
117 | - $A = self::ge_frombytes_negate_vartime(self::substr($pk, 0, 32)); |
|
118 | - $p1 = self::ge_mul_l($A); |
|
119 | - if (!self::fe_isnonzero($p1->X)) { |
|
120 | - throw new SodiumException('Unexpected zero result'); |
|
117 | + $A = self::ge_frombytes_negate_vartime( self::substr( $pk, 0, 32 ) ); |
|
118 | + $p1 = self::ge_mul_l( $A ); |
|
119 | + if ( ! self::fe_isnonzero( $p1->X ) ) { |
|
120 | + throw new SodiumException( 'Unexpected zero result' ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | # fe_1(one_minus_y); |
@@ -134,12 +134,12 @@ discard block |
||
134 | 134 | # fe_add(x, x, A.Y); |
135 | 135 | # fe_mul(x, x, one_minus_y); |
136 | 136 | $x = self::fe_mul( |
137 | - self::fe_add(self::fe_1(), $A->Y), |
|
137 | + self::fe_add( self::fe_1(), $A->Y ), |
|
138 | 138 | $one_minux_y |
139 | 139 | ); |
140 | 140 | |
141 | 141 | # fe_tobytes(curve25519_pk, x); |
142 | - return self::fe_tobytes($x); |
|
142 | + return self::fe_tobytes( $x ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | * @throws SodiumException |
151 | 151 | * @throws TypeError |
152 | 152 | */ |
153 | - public static function sk_to_pk($sk) |
|
153 | + public static function sk_to_pk( $sk ) |
|
154 | 154 | { |
155 | 155 | return self::ge_p3_tobytes( |
156 | 156 | self::ge_scalarmult_base( |
157 | - self::substr($sk, 0, 32) |
|
157 | + self::substr( $sk, 0, 32 ) |
|
158 | 158 | ) |
159 | 159 | ); |
160 | 160 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * @throws SodiumException |
169 | 169 | * @throws TypeError |
170 | 170 | */ |
171 | - public static function sign($message, $sk) |
|
171 | + public static function sign( $message, $sk ) |
|
172 | 172 | { |
173 | 173 | /** @var string $signature */ |
174 | - $signature = self::sign_detached($message, $sk); |
|
174 | + $signature = self::sign_detached( $message, $sk ); |
|
175 | 175 | return $signature . $message; |
176 | 176 | } |
177 | 177 | |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | * @throws SodiumException |
185 | 185 | * @throws TypeError |
186 | 186 | */ |
187 | - public static function sign_open($message, $pk) |
|
187 | + public static function sign_open( $message, $pk ) |
|
188 | 188 | { |
189 | 189 | /** @var string $signature */ |
190 | - $signature = self::substr($message, 0, 64); |
|
190 | + $signature = self::substr( $message, 0, 64 ); |
|
191 | 191 | |
192 | 192 | /** @var string $message */ |
193 | - $message = self::substr($message, 64); |
|
193 | + $message = self::substr( $message, 64 ); |
|
194 | 194 | |
195 | - if (self::verify_detached($signature, $message, $pk)) { |
|
195 | + if ( self::verify_detached( $signature, $message, $pk ) ) { |
|
196 | 196 | return $message; |
197 | 197 | } |
198 | - throw new SodiumException('Invalid signature'); |
|
198 | + throw new SodiumException( 'Invalid signature' ); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -207,56 +207,56 @@ discard block |
||
207 | 207 | * @throws SodiumException |
208 | 208 | * @throws TypeError |
209 | 209 | */ |
210 | - public static function sign_detached($message, $sk) |
|
210 | + public static function sign_detached( $message, $sk ) |
|
211 | 211 | { |
212 | 212 | # crypto_hash_sha512(az, sk, 32); |
213 | - $az = hash('sha512', self::substr($sk, 0, 32), true); |
|
213 | + $az = hash( 'sha512', self::substr( $sk, 0, 32 ), true ); |
|
214 | 214 | |
215 | 215 | # az[0] &= 248; |
216 | 216 | # az[31] &= 63; |
217 | 217 | # az[31] |= 64; |
218 | - $az[0] = self::intToChr(self::chrToInt($az[0]) & 248); |
|
219 | - $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64); |
|
218 | + $az[ 0 ] = self::intToChr( self::chrToInt( $az[ 0 ] ) & 248 ); |
|
219 | + $az[ 31 ] = self::intToChr( ( self::chrToInt( $az[ 31 ] ) & 63 ) | 64 ); |
|
220 | 220 | |
221 | 221 | # crypto_hash_sha512_init(&hs); |
222 | 222 | # crypto_hash_sha512_update(&hs, az + 32, 32); |
223 | 223 | # crypto_hash_sha512_update(&hs, m, mlen); |
224 | 224 | # crypto_hash_sha512_final(&hs, nonce); |
225 | - $hs = hash_init('sha512'); |
|
226 | - hash_update($hs, self::substr($az, 32, 32)); |
|
227 | - hash_update($hs, $message); |
|
228 | - $nonceHash = hash_final($hs, true); |
|
225 | + $hs = hash_init( 'sha512' ); |
|
226 | + hash_update( $hs, self::substr( $az, 32, 32 ) ); |
|
227 | + hash_update( $hs, $message ); |
|
228 | + $nonceHash = hash_final( $hs, true ); |
|
229 | 229 | |
230 | 230 | # memmove(sig + 32, sk + 32, 32); |
231 | - $pk = self::substr($sk, 32, 32); |
|
231 | + $pk = self::substr( $sk, 32, 32 ); |
|
232 | 232 | |
233 | 233 | # sc_reduce(nonce); |
234 | 234 | # ge_scalarmult_base(&R, nonce); |
235 | 235 | # ge_p3_tobytes(sig, &R); |
236 | - $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32); |
|
236 | + $nonce = self::sc_reduce( $nonceHash ) . self::substr( $nonceHash, 32 ); |
|
237 | 237 | $sig = self::ge_p3_tobytes( |
238 | - self::ge_scalarmult_base($nonce) |
|
238 | + self::ge_scalarmult_base( $nonce ) |
|
239 | 239 | ); |
240 | 240 | |
241 | 241 | # crypto_hash_sha512_init(&hs); |
242 | 242 | # crypto_hash_sha512_update(&hs, sig, 64); |
243 | 243 | # crypto_hash_sha512_update(&hs, m, mlen); |
244 | 244 | # crypto_hash_sha512_final(&hs, hram); |
245 | - $hs = hash_init('sha512'); |
|
246 | - hash_update($hs, self::substr($sig, 0, 32)); |
|
247 | - hash_update($hs, self::substr($pk, 0, 32)); |
|
248 | - hash_update($hs, $message); |
|
249 | - $hramHash = hash_final($hs, true); |
|
245 | + $hs = hash_init( 'sha512' ); |
|
246 | + hash_update( $hs, self::substr( $sig, 0, 32 ) ); |
|
247 | + hash_update( $hs, self::substr( $pk, 0, 32 ) ); |
|
248 | + hash_update( $hs, $message ); |
|
249 | + $hramHash = hash_final( $hs, true ); |
|
250 | 250 | |
251 | 251 | # sc_reduce(hram); |
252 | 252 | # sc_muladd(sig + 32, hram, az, nonce); |
253 | - $hram = self::sc_reduce($hramHash); |
|
254 | - $sigAfter = self::sc_muladd($hram, $az, $nonce); |
|
255 | - $sig = self::substr($sig, 0, 32) . self::substr($sigAfter, 0, 32); |
|
253 | + $hram = self::sc_reduce( $hramHash ); |
|
254 | + $sigAfter = self::sc_muladd( $hram, $az, $nonce ); |
|
255 | + $sig = self::substr( $sig, 0, 32 ) . self::substr( $sigAfter, 0, 32 ); |
|
256 | 256 | |
257 | 257 | try { |
258 | - ParagonIE_Sodium_Compat::memzero($az); |
|
259 | - } catch (SodiumException $ex) { |
|
258 | + ParagonIE_Sodium_Compat::memzero( $az ); |
|
259 | + } catch ( SodiumException $ex ) { |
|
260 | 260 | $az = null; |
261 | 261 | } |
262 | 262 | return $sig; |
@@ -272,26 +272,26 @@ discard block |
||
272 | 272 | * @throws SodiumException |
273 | 273 | * @throws TypeError |
274 | 274 | */ |
275 | - public static function verify_detached($sig, $message, $pk) |
|
275 | + public static function verify_detached( $sig, $message, $pk ) |
|
276 | 276 | { |
277 | - if (self::strlen($sig) < 64) { |
|
278 | - throw new SodiumException('Signature is too short'); |
|
277 | + if ( self::strlen( $sig ) < 64 ) { |
|
278 | + throw new SodiumException( 'Signature is too short' ); |
|
279 | 279 | } |
280 | - if ((self::chrToInt($sig[63]) & 240) && self::check_S_lt_L(self::substr($sig, 32, 32))) { |
|
281 | - throw new SodiumException('S < L - Invalid signature'); |
|
280 | + if ( ( self::chrToInt( $sig[ 63 ] ) & 240 ) && self::check_S_lt_L( self::substr( $sig, 32, 32 ) ) ) { |
|
281 | + throw new SodiumException( 'S < L - Invalid signature' ); |
|
282 | 282 | } |
283 | - if (self::small_order($sig)) { |
|
284 | - throw new SodiumException('Signature is on too small of an order'); |
|
283 | + if ( self::small_order( $sig ) ) { |
|
284 | + throw new SodiumException( 'Signature is on too small of an order' ); |
|
285 | 285 | } |
286 | - if ((self::chrToInt($sig[63]) & 224) !== 0) { |
|
287 | - throw new SodiumException('Invalid signature'); |
|
286 | + if ( ( self::chrToInt( $sig[ 63 ] ) & 224 ) !== 0 ) { |
|
287 | + throw new SodiumException( 'Invalid signature' ); |
|
288 | 288 | } |
289 | 289 | $d = 0; |
290 | - for ($i = 0; $i < 32; ++$i) { |
|
291 | - $d |= self::chrToInt($pk[$i]); |
|
290 | + for ( $i = 0; $i < 32; ++$i ) { |
|
291 | + $d |= self::chrToInt( $pk[ $i ] ); |
|
292 | 292 | } |
293 | - if ($d === 0) { |
|
294 | - throw new SodiumException('All zero public key'); |
|
293 | + if ( $d === 0 ) { |
|
294 | + throw new SodiumException( 'All zero public key' ); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */ |
@@ -301,34 +301,34 @@ discard block |
||
301 | 301 | ParagonIE_Sodium_Compat::$fastMult = true; |
302 | 302 | |
303 | 303 | /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A */ |
304 | - $A = self::ge_frombytes_negate_vartime($pk); |
|
304 | + $A = self::ge_frombytes_negate_vartime( $pk ); |
|
305 | 305 | |
306 | 306 | /** @var string $hDigest */ |
307 | 307 | $hDigest = hash( |
308 | 308 | 'sha512', |
309 | - self::substr($sig, 0, 32) . |
|
310 | - self::substr($pk, 0, 32) . |
|
309 | + self::substr( $sig, 0, 32 ) . |
|
310 | + self::substr( $pk, 0, 32 ) . |
|
311 | 311 | $message, |
312 | 312 | true |
313 | 313 | ); |
314 | 314 | |
315 | 315 | /** @var string $h */ |
316 | - $h = self::sc_reduce($hDigest) . self::substr($hDigest, 32); |
|
316 | + $h = self::sc_reduce( $hDigest ) . self::substr( $hDigest, 32 ); |
|
317 | 317 | |
318 | 318 | /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P2 $R */ |
319 | 319 | $R = self::ge_double_scalarmult_vartime( |
320 | 320 | $h, |
321 | 321 | $A, |
322 | - self::substr($sig, 32) |
|
322 | + self::substr( $sig, 32 ) |
|
323 | 323 | ); |
324 | 324 | |
325 | 325 | /** @var string $rcheck */ |
326 | - $rcheck = self::ge_tobytes($R); |
|
326 | + $rcheck = self::ge_tobytes( $R ); |
|
327 | 327 | |
328 | 328 | // Reset ParagonIE_Sodium_Compat::$fastMult to what it was before. |
329 | 329 | ParagonIE_Sodium_Compat::$fastMult = $orig; |
330 | 330 | |
331 | - return self::verify_32($rcheck, self::substr($sig, 0, 32)); |
|
331 | + return self::verify_32( $rcheck, self::substr( $sig, 0, 32 ) ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -339,10 +339,10 @@ discard block |
||
339 | 339 | * @throws SodiumException |
340 | 340 | * @throws TypeError |
341 | 341 | */ |
342 | - public static function check_S_lt_L($S) |
|
342 | + public static function check_S_lt_L( $S ) |
|
343 | 343 | { |
344 | - if (self::strlen($S) < 32) { |
|
345 | - throw new SodiumException('Signature must be 32 bytes'); |
|
344 | + if ( self::strlen( $S ) < 32 ) { |
|
345 | + throw new SodiumException( 'Signature must be 32 bytes' ); |
|
346 | 346 | } |
347 | 347 | $L = array( |
348 | 348 | 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, |
@@ -357,14 +357,14 @@ discard block |
||
357 | 357 | /** @var array<int, int> $L */ |
358 | 358 | do { |
359 | 359 | --$i; |
360 | - $x = self::chrToInt($S[$i]); |
|
360 | + $x = self::chrToInt( $S[ $i ] ); |
|
361 | 361 | $c |= ( |
362 | - (($x - $L[$i]) >> 8) & $n |
|
362 | + ( ( $x - $L[ $i ] ) >> 8 ) & $n |
|
363 | 363 | ); |
364 | 364 | $n &= ( |
365 | - (($x ^ $L[$i]) - 1) >> 8 |
|
365 | + ( ( $x ^ $L[ $i ] ) - 1 ) >> 8 |
|
366 | 366 | ); |
367 | - } while ($i !== 0); |
|
367 | + } while ( $i !== 0 ); |
|
368 | 368 | |
369 | 369 | return $c === 0; |
370 | 370 | } |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @throws SodiumException |
376 | 376 | * @throws TypeError |
377 | 377 | */ |
378 | - public static function small_order($R) |
|
378 | + public static function small_order( $R ) |
|
379 | 379 | { |
380 | 380 | /** @var array<int, array<int, int>> $blocklist */ |
381 | 381 | $blocklist = array( |
@@ -465,14 +465,14 @@ discard block |
||
465 | 465 | ) |
466 | 466 | ); |
467 | 467 | /** @var int $countBlocklist */ |
468 | - $countBlocklist = count($blocklist); |
|
468 | + $countBlocklist = count( $blocklist ); |
|
469 | 469 | |
470 | - for ($i = 0; $i < $countBlocklist; ++$i) { |
|
470 | + for ( $i = 0; $i < $countBlocklist; ++$i ) { |
|
471 | 471 | $c = 0; |
472 | - for ($j = 0; $j < 32; ++$j) { |
|
473 | - $c |= self::chrToInt($R[$j]) ^ (int) $blocklist[$i][$j]; |
|
472 | + for ( $j = 0; $j < 32; ++$j ) { |
|
473 | + $c |= self::chrToInt( $R[ $j ] ) ^ (int)$blocklist[ $i ][ $j ]; |
|
474 | 474 | } |
475 | - if ($c === 0) { |
|
475 | + if ( $c === 0 ) { |
|
476 | 476 | return true; |
477 | 477 | } |
478 | 478 | } |
@@ -484,13 +484,13 @@ discard block |
||
484 | 484 | * @return string |
485 | 485 | * @throws SodiumException |
486 | 486 | */ |
487 | - public static function scalar_complement($s) |
|
487 | + public static function scalar_complement( $s ) |
|
488 | 488 | { |
489 | - $t_ = self::L . str_repeat("\x00", 32); |
|
490 | - sodium_increment($t_); |
|
491 | - $s_ = $s . str_repeat("\x00", 32); |
|
492 | - ParagonIE_Sodium_Compat::sub($t_, $s_); |
|
493 | - return self::sc_reduce($t_); |
|
489 | + $t_ = self::L . str_repeat( "\x00", 32 ); |
|
490 | + sodium_increment( $t_ ); |
|
491 | + $s_ = $s . str_repeat( "\x00", 32 ); |
|
492 | + ParagonIE_Sodium_Compat::sub( $t_, $s_ ); |
|
493 | + return self::sc_reduce( $t_ ); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -500,12 +500,12 @@ discard block |
||
500 | 500 | public static function scalar_random() |
501 | 501 | { |
502 | 502 | do { |
503 | - $r = ParagonIE_Sodium_Compat::randombytes_buf(self::SCALAR_BYTES); |
|
504 | - $r[self::SCALAR_BYTES - 1] = self::intToChr( |
|
505 | - self::chrToInt($r[self::SCALAR_BYTES - 1]) & 0x1f |
|
503 | + $r = ParagonIE_Sodium_Compat::randombytes_buf( self::SCALAR_BYTES ); |
|
504 | + $r[ self::SCALAR_BYTES - 1 ] = self::intToChr( |
|
505 | + self::chrToInt( $r[ self::SCALAR_BYTES - 1 ] ) & 0x1f |
|
506 | 506 | ); |
507 | 507 | } while ( |
508 | - !self::check_S_lt_L($r) || ParagonIE_Sodium_Compat::is_zero($r) |
|
508 | + ! self::check_S_lt_L( $r ) || ParagonIE_Sodium_Compat::is_zero( $r ) |
|
509 | 509 | ); |
510 | 510 | return $r; |
511 | 511 | } |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | * @return string |
516 | 516 | * @throws SodiumException |
517 | 517 | */ |
518 | - public static function scalar_negate($s) |
|
518 | + public static function scalar_negate( $s ) |
|
519 | 519 | { |
520 | - $t_ = self::L . str_repeat("\x00", 32) ; |
|
521 | - $s_ = $s . str_repeat("\x00", 32) ; |
|
522 | - ParagonIE_Sodium_Compat::sub($t_, $s_); |
|
523 | - return self::sc_reduce($t_); |
|
520 | + $t_ = self::L . str_repeat( "\x00", 32 ); |
|
521 | + $s_ = $s . str_repeat( "\x00", 32 ); |
|
522 | + ParagonIE_Sodium_Compat::sub( $t_, $s_ ); |
|
523 | + return self::sc_reduce( $t_ ); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | * @return string |
530 | 530 | * @throws SodiumException |
531 | 531 | */ |
532 | - public static function scalar_add($a, $b) |
|
532 | + public static function scalar_add( $a, $b ) |
|
533 | 533 | { |
534 | - $a_ = $a . str_repeat("\x00", 32); |
|
535 | - $b_ = $b . str_repeat("\x00", 32); |
|
536 | - ParagonIE_Sodium_Compat::add($a_, $b_); |
|
537 | - return self::sc_reduce($a_); |
|
534 | + $a_ = $a . str_repeat( "\x00", 32 ); |
|
535 | + $b_ = $b . str_repeat( "\x00", 32 ); |
|
536 | + ParagonIE_Sodium_Compat::add( $a_, $b_ ); |
|
537 | + return self::sc_reduce( $a_ ); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -543,9 +543,9 @@ discard block |
||
543 | 543 | * @return string |
544 | 544 | * @throws SodiumException |
545 | 545 | */ |
546 | - public static function scalar_sub($x, $y) |
|
546 | + public static function scalar_sub( $x, $y ) |
|
547 | 547 | { |
548 | - $yn = self::scalar_negate($y); |
|
549 | - return self::scalar_add($x, $yn); |
|
548 | + $yn = self::scalar_negate( $y ); |
|
549 | + return self::scalar_add( $x, $yn ); |
|
550 | 550 | } |
551 | 551 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_Util', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_Util', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -14,22 +14,22 @@ discard block |
||
14 | 14 | * @param int $size (16, 32, 64) |
15 | 15 | * @return int |
16 | 16 | */ |
17 | - public static function abs($integer, $size = 0) |
|
17 | + public static function abs( $integer, $size = 0 ) |
|
18 | 18 | { |
19 | 19 | /** @var int $realSize */ |
20 | - $realSize = (PHP_INT_SIZE << 3) - 1; |
|
21 | - if ($size) { |
|
20 | + $realSize = ( PHP_INT_SIZE << 3 ) - 1; |
|
21 | + if ( $size ) { |
|
22 | 22 | --$size; |
23 | 23 | } else { |
24 | 24 | /** @var int $size */ |
25 | 25 | $size = $realSize; |
26 | 26 | } |
27 | 27 | |
28 | - $negative = -(($integer >> $size) & 1); |
|
29 | - return (int) ( |
|
30 | - ($integer ^ $negative) |
|
28 | + $negative = -( ( $integer >> $size ) & 1 ); |
|
29 | + return (int)( |
|
30 | + ( $integer ^ $negative ) |
|
31 | 31 | + |
32 | - (($negative >> $realSize) & 1) |
|
32 | + ( ( $negative >> $realSize ) & 1 ) |
|
33 | 33 | ); |
34 | 34 | } |
35 | 35 | |
@@ -43,26 +43,26 @@ discard block |
||
43 | 43 | * @return string |
44 | 44 | * @throws TypeError |
45 | 45 | */ |
46 | - public static function bin2hex($binaryString) |
|
46 | + public static function bin2hex( $binaryString ) |
|
47 | 47 | { |
48 | 48 | /* Type checks: */ |
49 | - if (!is_string($binaryString)) { |
|
50 | - throw new TypeError('Argument 1 must be a string, ' . gettype($binaryString) . ' given.'); |
|
49 | + if ( ! is_string( $binaryString ) ) { |
|
50 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $binaryString ) . ' given.' ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | $hex = ''; |
54 | - $len = self::strlen($binaryString); |
|
55 | - for ($i = 0; $i < $len; ++$i) { |
|
54 | + $len = self::strlen( $binaryString ); |
|
55 | + for ( $i = 0; $i < $len; ++$i ) { |
|
56 | 56 | /** @var array<int, int> $chunk */ |
57 | - $chunk = unpack('C', $binaryString[$i]); |
|
57 | + $chunk = unpack( 'C', $binaryString[ $i ] ); |
|
58 | 58 | /** @var int $c */ |
59 | - $c = $chunk[1] & 0xf; |
|
59 | + $c = $chunk[ 1 ] & 0xf; |
|
60 | 60 | /** @var int $b */ |
61 | - $b = $chunk[1] >> 4; |
|
61 | + $b = $chunk[ 1 ] >> 4; |
|
62 | 62 | $hex .= pack( |
63 | 63 | 'CC', |
64 | - (87 + $b + ((($b - 10) >> 8) & ~38)), |
|
65 | - (87 + $c + ((($c - 10) >> 8) & ~38)) |
|
64 | + ( 87 + $b + ( ( ( $b - 10 ) >> 8 ) & ~38 ) ), |
|
65 | + ( 87 + $c + ( ( ( $c - 10 ) >> 8 ) & ~38 ) ) |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | return $hex; |
@@ -78,25 +78,25 @@ discard block |
||
78 | 78 | * @return string |
79 | 79 | * @throws TypeError |
80 | 80 | */ |
81 | - public static function bin2hexUpper($bin_string) |
|
81 | + public static function bin2hexUpper( $bin_string ) |
|
82 | 82 | { |
83 | 83 | $hex = ''; |
84 | - $len = self::strlen($bin_string); |
|
85 | - for ($i = 0; $i < $len; ++$i) { |
|
84 | + $len = self::strlen( $bin_string ); |
|
85 | + for ( $i = 0; $i < $len; ++$i ) { |
|
86 | 86 | /** @var array<int, int> $chunk */ |
87 | - $chunk = unpack('C', $bin_string[$i]); |
|
87 | + $chunk = unpack( 'C', $bin_string[ $i ] ); |
|
88 | 88 | /** |
89 | 89 | * Lower 16 bits |
90 | 90 | * |
91 | 91 | * @var int $c |
92 | 92 | */ |
93 | - $c = $chunk[1] & 0xf; |
|
93 | + $c = $chunk[ 1 ] & 0xf; |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Upper 16 bits |
97 | 97 | * @var int $b |
98 | 98 | */ |
99 | - $b = $chunk[1] >> 4; |
|
99 | + $b = $chunk[ 1 ] >> 4; |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Use pack() and binary operators to turn the two integers |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | */ |
107 | 107 | $hex .= pack( |
108 | 108 | 'CC', |
109 | - (55 + $b + ((($b - 10) >> 8) & ~6)), |
|
110 | - (55 + $c + ((($c - 10) >> 8) & ~6)) |
|
109 | + ( 55 + $b + ( ( ( $b - 10 ) >> 8 ) & ~6 ) ), |
|
110 | + ( 55 + $c + ( ( ( $c - 10 ) >> 8 ) & ~6 ) ) |
|
111 | 111 | ); |
112 | 112 | } |
113 | 113 | return $hex; |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @throws SodiumException |
124 | 124 | * @throws TypeError |
125 | 125 | */ |
126 | - public static function chrToInt($chr) |
|
126 | + public static function chrToInt( $chr ) |
|
127 | 127 | { |
128 | 128 | /* Type checks: */ |
129 | - if (!is_string($chr)) { |
|
130 | - throw new TypeError('Argument 1 must be a string, ' . gettype($chr) . ' given.'); |
|
129 | + if ( ! is_string( $chr ) ) { |
|
130 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $chr ) . ' given.' ); |
|
131 | 131 | } |
132 | - if (self::strlen($chr) !== 1) { |
|
133 | - throw new SodiumException('chrToInt() expects a string that is exactly 1 character long'); |
|
132 | + if ( self::strlen( $chr ) !== 1 ) { |
|
133 | + throw new SodiumException( 'chrToInt() expects a string that is exactly 1 character long' ); |
|
134 | 134 | } |
135 | 135 | /** @var array<int, int> $chunk */ |
136 | - $chunk = unpack('C', $chr); |
|
137 | - return (int) ($chunk[1]); |
|
136 | + $chunk = unpack( 'C', $chr ); |
|
137 | + return (int)( $chunk[ 1 ] ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -149,25 +149,25 @@ discard block |
||
149 | 149 | * @throws SodiumException |
150 | 150 | * @throws TypeError |
151 | 151 | */ |
152 | - public static function compare($left, $right, $len = null) |
|
152 | + public static function compare( $left, $right, $len = null ) |
|
153 | 153 | { |
154 | - $leftLen = self::strlen($left); |
|
155 | - $rightLen = self::strlen($right); |
|
156 | - if ($len === null) { |
|
157 | - $len = max($leftLen, $rightLen); |
|
158 | - $left = str_pad($left, $len, "\x00", STR_PAD_RIGHT); |
|
159 | - $right = str_pad($right, $len, "\x00", STR_PAD_RIGHT); |
|
154 | + $leftLen = self::strlen( $left ); |
|
155 | + $rightLen = self::strlen( $right ); |
|
156 | + if ( $len === null ) { |
|
157 | + $len = max( $leftLen, $rightLen ); |
|
158 | + $left = str_pad( $left, $len, "\x00", STR_PAD_RIGHT ); |
|
159 | + $right = str_pad( $right, $len, "\x00", STR_PAD_RIGHT ); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | $gt = 0; |
163 | 163 | $eq = 1; |
164 | 164 | $i = $len; |
165 | - while ($i !== 0) { |
|
165 | + while ( $i !== 0 ) { |
|
166 | 166 | --$i; |
167 | - $gt |= ((self::chrToInt($right[$i]) - self::chrToInt($left[$i])) >> 8) & $eq; |
|
168 | - $eq &= ((self::chrToInt($right[$i]) ^ self::chrToInt($left[$i])) - 1) >> 8; |
|
167 | + $gt |= ( ( self::chrToInt( $right[ $i ] ) - self::chrToInt( $left[ $i ] ) ) >> 8 ) & $eq; |
|
168 | + $eq &= ( ( self::chrToInt( $right[ $i ] ) ^ self::chrToInt( $left[ $i ] ) ) - 1 ) >> 8; |
|
169 | 169 | } |
170 | - return ($gt + $gt + $eq) - 1; |
|
170 | + return ( $gt + $gt + $eq ) - 1; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -180,71 +180,71 @@ discard block |
||
180 | 180 | * @throws SodiumException |
181 | 181 | * @return void |
182 | 182 | */ |
183 | - public static function declareScalarType(&$mixedVar = null, $type = 'void', $argumentIndex = 0) |
|
183 | + public static function declareScalarType( &$mixedVar = null, $type = 'void', $argumentIndex = 0 ) |
|
184 | 184 | { |
185 | - if (func_num_args() === 0) { |
|
185 | + if ( func_num_args() === 0 ) { |
|
186 | 186 | /* Tautology, by default */ |
187 | 187 | return; |
188 | 188 | } |
189 | - if (func_num_args() === 1) { |
|
190 | - throw new TypeError('Declared void, but passed a variable'); |
|
189 | + if ( func_num_args() === 1 ) { |
|
190 | + throw new TypeError( 'Declared void, but passed a variable' ); |
|
191 | 191 | } |
192 | - $realType = strtolower(gettype($mixedVar)); |
|
193 | - $type = strtolower($type); |
|
194 | - switch ($type) { |
|
192 | + $realType = strtolower( gettype( $mixedVar ) ); |
|
193 | + $type = strtolower( $type ); |
|
194 | + switch ( $type ) { |
|
195 | 195 | case 'null': |
196 | - if ($mixedVar !== null) { |
|
197 | - throw new TypeError('Argument ' . $argumentIndex . ' must be null, ' . $realType . ' given.'); |
|
196 | + if ( $mixedVar !== null ) { |
|
197 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be null, ' . $realType . ' given.' ); |
|
198 | 198 | } |
199 | 199 | break; |
200 | 200 | case 'integer': |
201 | 201 | case 'int': |
202 | - $allow = array('int', 'integer'); |
|
203 | - if (!in_array($type, $allow)) { |
|
204 | - throw new TypeError('Argument ' . $argumentIndex . ' must be an integer, ' . $realType . ' given.'); |
|
202 | + $allow = array( 'int', 'integer' ); |
|
203 | + if ( ! in_array( $type, $allow ) ) { |
|
204 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be an integer, ' . $realType . ' given.' ); |
|
205 | 205 | } |
206 | - $mixedVar = (int) $mixedVar; |
|
206 | + $mixedVar = (int)$mixedVar; |
|
207 | 207 | break; |
208 | 208 | case 'boolean': |
209 | 209 | case 'bool': |
210 | - $allow = array('bool', 'boolean'); |
|
211 | - if (!in_array($type, $allow)) { |
|
212 | - throw new TypeError('Argument ' . $argumentIndex . ' must be a boolean, ' . $realType . ' given.'); |
|
210 | + $allow = array( 'bool', 'boolean' ); |
|
211 | + if ( ! in_array( $type, $allow ) ) { |
|
212 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be a boolean, ' . $realType . ' given.' ); |
|
213 | 213 | } |
214 | - $mixedVar = (bool) $mixedVar; |
|
214 | + $mixedVar = (bool)$mixedVar; |
|
215 | 215 | break; |
216 | 216 | case 'string': |
217 | - if (!is_string($mixedVar)) { |
|
218 | - throw new TypeError('Argument ' . $argumentIndex . ' must be a string, ' . $realType . ' given.'); |
|
217 | + if ( ! is_string( $mixedVar ) ) { |
|
218 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be a string, ' . $realType . ' given.' ); |
|
219 | 219 | } |
220 | - $mixedVar = (string) $mixedVar; |
|
220 | + $mixedVar = (string)$mixedVar; |
|
221 | 221 | break; |
222 | 222 | case 'decimal': |
223 | 223 | case 'double': |
224 | 224 | case 'float': |
225 | - $allow = array('decimal', 'double', 'float'); |
|
226 | - if (!in_array($type, $allow)) { |
|
227 | - throw new TypeError('Argument ' . $argumentIndex . ' must be a float, ' . $realType . ' given.'); |
|
225 | + $allow = array( 'decimal', 'double', 'float' ); |
|
226 | + if ( ! in_array( $type, $allow ) ) { |
|
227 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be a float, ' . $realType . ' given.' ); |
|
228 | 228 | } |
229 | - $mixedVar = (float) $mixedVar; |
|
229 | + $mixedVar = (float)$mixedVar; |
|
230 | 230 | break; |
231 | 231 | case 'object': |
232 | - if (!is_object($mixedVar)) { |
|
233 | - throw new TypeError('Argument ' . $argumentIndex . ' must be an object, ' . $realType . ' given.'); |
|
232 | + if ( ! is_object( $mixedVar ) ) { |
|
233 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be an object, ' . $realType . ' given.' ); |
|
234 | 234 | } |
235 | 235 | break; |
236 | 236 | case 'array': |
237 | - if (!is_array($mixedVar)) { |
|
238 | - if (is_object($mixedVar)) { |
|
239 | - if ($mixedVar instanceof ArrayAccess) { |
|
237 | + if ( ! is_array( $mixedVar ) ) { |
|
238 | + if ( is_object( $mixedVar ) ) { |
|
239 | + if ( $mixedVar instanceof ArrayAccess ) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | } |
243 | - throw new TypeError('Argument ' . $argumentIndex . ' must be an array, ' . $realType . ' given.'); |
|
243 | + throw new TypeError( 'Argument ' . $argumentIndex . ' must be an array, ' . $realType . ' given.' ); |
|
244 | 244 | } |
245 | 245 | break; |
246 | 246 | default: |
247 | - throw new SodiumException('Unknown type (' . $realType .') does not match expect type (' . $type . ')'); |
|
247 | + throw new SodiumException( 'Unknown type (' . $realType . ') does not match expect type (' . $type . ')' ); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -257,30 +257,30 @@ discard block |
||
257 | 257 | * @throws SodiumException |
258 | 258 | * @throws TypeError |
259 | 259 | */ |
260 | - public static function hashEquals($left, $right) |
|
260 | + public static function hashEquals( $left, $right ) |
|
261 | 261 | { |
262 | 262 | /* Type checks: */ |
263 | - if (!is_string($left)) { |
|
264 | - throw new TypeError('Argument 1 must be a string, ' . gettype($left) . ' given.'); |
|
263 | + if ( ! is_string( $left ) ) { |
|
264 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $left ) . ' given.' ); |
|
265 | 265 | } |
266 | - if (!is_string($right)) { |
|
267 | - throw new TypeError('Argument 2 must be a string, ' . gettype($right) . ' given.'); |
|
266 | + if ( ! is_string( $right ) ) { |
|
267 | + throw new TypeError( 'Argument 2 must be a string, ' . gettype( $right ) . ' given.' ); |
|
268 | 268 | } |
269 | 269 | |
270 | - if (is_callable('hash_equals')) { |
|
271 | - return hash_equals($left, $right); |
|
270 | + if ( is_callable( 'hash_equals' ) ) { |
|
271 | + return hash_equals( $left, $right ); |
|
272 | 272 | } |
273 | 273 | $d = 0; |
274 | 274 | /** @var int $len */ |
275 | - $len = self::strlen($left); |
|
276 | - if ($len !== self::strlen($right)) { |
|
275 | + $len = self::strlen( $left ); |
|
276 | + if ( $len !== self::strlen( $right ) ) { |
|
277 | 277 | return false; |
278 | 278 | } |
279 | - for ($i = 0; $i < $len; ++$i) { |
|
280 | - $d |= self::chrToInt($left[$i]) ^ self::chrToInt($right[$i]); |
|
279 | + for ( $i = 0; $i < $len; ++$i ) { |
|
280 | + $d |= self::chrToInt( $left[ $i ] ) ^ self::chrToInt( $right[ $i ] ); |
|
281 | 281 | } |
282 | 282 | |
283 | - if ($d !== 0) { |
|
283 | + if ( $d !== 0 ) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | return $left === $right; |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | * @throws SodiumException |
296 | 296 | * @psalm-suppress PossiblyInvalidArgument |
297 | 297 | */ |
298 | - protected static function hash_update(&$hs, $data) |
|
298 | + protected static function hash_update( &$hs, $data ) |
|
299 | 299 | { |
300 | - if (!hash_update($hs, $data)) { |
|
301 | - throw new SodiumException('hash_update() failed'); |
|
300 | + if ( ! hash_update( $hs, $data ) ) { |
|
301 | + throw new SodiumException( 'hash_update() failed' ); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | * @throws RangeException |
315 | 315 | * @throws TypeError |
316 | 316 | */ |
317 | - public static function hex2bin($hexString, $strictPadding = false) |
|
317 | + public static function hex2bin( $hexString, $strictPadding = false ) |
|
318 | 318 | { |
319 | 319 | /* Type checks: */ |
320 | - if (!is_string($hexString)) { |
|
321 | - throw new TypeError('Argument 1 must be a string, ' . gettype($hexString) . ' given.'); |
|
320 | + if ( ! is_string( $hexString ) ) { |
|
321 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $hexString ) . ' given.' ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** @var int $hex_pos */ |
@@ -328,11 +328,11 @@ discard block |
||
328 | 328 | /** @var int $c_acc */ |
329 | 329 | $c_acc = 0; |
330 | 330 | /** @var int $hex_len */ |
331 | - $hex_len = self::strlen($hexString); |
|
331 | + $hex_len = self::strlen( $hexString ); |
|
332 | 332 | /** @var int $state */ |
333 | 333 | $state = 0; |
334 | - if (($hex_len & 1) !== 0) { |
|
335 | - if ($strictPadding) { |
|
334 | + if ( ( $hex_len & 1 ) !== 0 ) { |
|
335 | + if ( $strictPadding ) { |
|
336 | 336 | throw new RangeException( |
337 | 337 | 'Expected an even number of hexadecimal characters' |
338 | 338 | ); |
@@ -342,30 +342,30 @@ discard block |
||
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - $chunk = unpack('C*', $hexString); |
|
346 | - while ($hex_pos < $hex_len) { |
|
345 | + $chunk = unpack( 'C*', $hexString ); |
|
346 | + while ( $hex_pos < $hex_len ) { |
|
347 | 347 | ++$hex_pos; |
348 | 348 | /** @var int $c */ |
349 | - $c = $chunk[$hex_pos]; |
|
349 | + $c = $chunk[ $hex_pos ]; |
|
350 | 350 | /** @var int $c_num */ |
351 | 351 | $c_num = $c ^ 48; |
352 | 352 | /** @var int $c_num0 */ |
353 | - $c_num0 = ($c_num - 10) >> 8; |
|
353 | + $c_num0 = ( $c_num - 10 ) >> 8; |
|
354 | 354 | /** @var int $c_alpha */ |
355 | - $c_alpha = ($c & ~32) - 55; |
|
355 | + $c_alpha = ( $c & ~32 ) - 55; |
|
356 | 356 | /** @var int $c_alpha0 */ |
357 | - $c_alpha0 = (($c_alpha - 10) ^ ($c_alpha - 16)) >> 8; |
|
358 | - if (($c_num0 | $c_alpha0) === 0) { |
|
357 | + $c_alpha0 = ( ( $c_alpha - 10 ) ^ ( $c_alpha - 16 ) ) >> 8; |
|
358 | + if ( ( $c_num0 | $c_alpha0 ) === 0 ) { |
|
359 | 359 | throw new RangeException( |
360 | 360 | 'hex2bin() only expects hexadecimal characters' |
361 | 361 | ); |
362 | 362 | } |
363 | 363 | /** @var int $c_val */ |
364 | - $c_val = ($c_num0 & $c_num) | ($c_alpha & $c_alpha0); |
|
365 | - if ($state === 0) { |
|
364 | + $c_val = ( $c_num0 & $c_num ) | ( $c_alpha & $c_alpha0 ); |
|
365 | + if ( $state === 0 ) { |
|
366 | 366 | $c_acc = $c_val * 16; |
367 | 367 | } else { |
368 | - $bin .= pack('C', $c_acc | $c_val); |
|
368 | + $bin .= pack( 'C', $c_acc | $c_val ); |
|
369 | 369 | } |
370 | 370 | $state ^= 1; |
371 | 371 | } |
@@ -380,15 +380,15 @@ discard block |
||
380 | 380 | * @param array<int, int> $ints |
381 | 381 | * @return string |
382 | 382 | */ |
383 | - public static function intArrayToString(array $ints) |
|
383 | + public static function intArrayToString( array $ints ) |
|
384 | 384 | { |
385 | 385 | /** @var array<int, int> $args */ |
386 | 386 | $args = $ints; |
387 | - foreach ($args as $i => $v) { |
|
388 | - $args[$i] = (int) ($v & 0xff); |
|
387 | + foreach ( $args as $i => $v ) { |
|
388 | + $args[ $i ] = (int)( $v & 0xff ); |
|
389 | 389 | } |
390 | - array_unshift($args, str_repeat('C', count($ints))); |
|
391 | - return (string) (call_user_func_array('pack', $args)); |
|
390 | + array_unshift( $args, str_repeat( 'C', count( $ints ) ) ); |
|
391 | + return (string)( call_user_func_array( 'pack', $args ) ); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | * @return string |
401 | 401 | * @throws TypeError |
402 | 402 | */ |
403 | - public static function intToChr($int) |
|
403 | + public static function intToChr( $int ) |
|
404 | 404 | { |
405 | - return pack('C', $int); |
|
405 | + return pack( 'C', $int ); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -415,22 +415,22 @@ discard block |
||
415 | 415 | * @throws RangeException |
416 | 416 | * @throws TypeError |
417 | 417 | */ |
418 | - public static function load_3($string) |
|
418 | + public static function load_3( $string ) |
|
419 | 419 | { |
420 | 420 | /* Type checks: */ |
421 | - if (!is_string($string)) { |
|
422 | - throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.'); |
|
421 | + if ( ! is_string( $string ) ) { |
|
422 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $string ) . ' given.' ); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /* Input validation: */ |
426 | - if (self::strlen($string) < 3) { |
|
426 | + if ( self::strlen( $string ) < 3 ) { |
|
427 | 427 | throw new RangeException( |
428 | - 'String must be 3 bytes or more; ' . self::strlen($string) . ' given.' |
|
428 | + 'String must be 3 bytes or more; ' . self::strlen( $string ) . ' given.' |
|
429 | 429 | ); |
430 | 430 | } |
431 | 431 | /** @var array<int, int> $unpacked */ |
432 | - $unpacked = unpack('V', $string . "\0"); |
|
433 | - return (int) ($unpacked[1] & 0xffffff); |
|
432 | + $unpacked = unpack( 'V', $string . "\0" ); |
|
433 | + return (int)( $unpacked[ 1 ] & 0xffffff ); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -443,22 +443,22 @@ discard block |
||
443 | 443 | * @throws RangeException |
444 | 444 | * @throws TypeError |
445 | 445 | */ |
446 | - public static function load_4($string) |
|
446 | + public static function load_4( $string ) |
|
447 | 447 | { |
448 | 448 | /* Type checks: */ |
449 | - if (!is_string($string)) { |
|
450 | - throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.'); |
|
449 | + if ( ! is_string( $string ) ) { |
|
450 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $string ) . ' given.' ); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /* Input validation: */ |
454 | - if (self::strlen($string) < 4) { |
|
454 | + if ( self::strlen( $string ) < 4 ) { |
|
455 | 455 | throw new RangeException( |
456 | - 'String must be 4 bytes or more; ' . self::strlen($string) . ' given.' |
|
456 | + 'String must be 4 bytes or more; ' . self::strlen( $string ) . ' given.' |
|
457 | 457 | ); |
458 | 458 | } |
459 | 459 | /** @var array<int, int> $unpacked */ |
460 | - $unpacked = unpack('V', $string); |
|
461 | - return (int) ($unpacked[1] & 0xffffffff); |
|
460 | + $unpacked = unpack( 'V', $string ); |
|
461 | + return (int)( $unpacked[ 1 ] & 0xffffffff ); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -472,35 +472,35 @@ discard block |
||
472 | 472 | * @throws SodiumException |
473 | 473 | * @throws TypeError |
474 | 474 | */ |
475 | - public static function load64_le($string) |
|
475 | + public static function load64_le( $string ) |
|
476 | 476 | { |
477 | 477 | /* Type checks: */ |
478 | - if (!is_string($string)) { |
|
479 | - throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.'); |
|
478 | + if ( ! is_string( $string ) ) { |
|
479 | + throw new TypeError( 'Argument 1 must be a string, ' . gettype( $string ) . ' given.' ); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /* Input validation: */ |
483 | - if (self::strlen($string) < 4) { |
|
483 | + if ( self::strlen( $string ) < 4 ) { |
|
484 | 484 | throw new RangeException( |
485 | - 'String must be 4 bytes or more; ' . self::strlen($string) . ' given.' |
|
485 | + 'String must be 4 bytes or more; ' . self::strlen( $string ) . ' given.' |
|
486 | 486 | ); |
487 | 487 | } |
488 | - if (PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8) { |
|
488 | + if ( PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8 ) { |
|
489 | 489 | /** @var array<int, int> $unpacked */ |
490 | - $unpacked = unpack('P', $string); |
|
491 | - return (int) $unpacked[1]; |
|
490 | + $unpacked = unpack( 'P', $string ); |
|
491 | + return (int)$unpacked[ 1 ]; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** @var int $result */ |
495 | - $result = (self::chrToInt($string[0]) & 0xff); |
|
496 | - $result |= (self::chrToInt($string[1]) & 0xff) << 8; |
|
497 | - $result |= (self::chrToInt($string[2]) & 0xff) << 16; |
|
498 | - $result |= (self::chrToInt($string[3]) & 0xff) << 24; |
|
499 | - $result |= (self::chrToInt($string[4]) & 0xff) << 32; |
|
500 | - $result |= (self::chrToInt($string[5]) & 0xff) << 40; |
|
501 | - $result |= (self::chrToInt($string[6]) & 0xff) << 48; |
|
502 | - $result |= (self::chrToInt($string[7]) & 0xff) << 56; |
|
503 | - return (int) $result; |
|
495 | + $result = ( self::chrToInt( $string[ 0 ] ) & 0xff ); |
|
496 | + $result |= ( self::chrToInt( $string[ 1 ] ) & 0xff ) << 8; |
|
497 | + $result |= ( self::chrToInt( $string[ 2 ] ) & 0xff ) << 16; |
|
498 | + $result |= ( self::chrToInt( $string[ 3 ] ) & 0xff ) << 24; |
|
499 | + $result |= ( self::chrToInt( $string[ 4 ] ) & 0xff ) << 32; |
|
500 | + $result |= ( self::chrToInt( $string[ 5 ] ) & 0xff ) << 40; |
|
501 | + $result |= ( self::chrToInt( $string[ 6 ] ) & 0xff ) << 48; |
|
502 | + $result |= ( self::chrToInt( $string[ 7 ] ) & 0xff ) << 56; |
|
503 | + return (int)$result; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -512,9 +512,9 @@ discard block |
||
512 | 512 | * @throws SodiumException |
513 | 513 | * @throws TypeError |
514 | 514 | */ |
515 | - public static function memcmp($left, $right) |
|
515 | + public static function memcmp( $left, $right ) |
|
516 | 516 | { |
517 | - if (self::hashEquals($left, $right)) { |
|
517 | + if ( self::hashEquals( $left, $right ) ) { |
|
518 | 518 | return 0; |
519 | 519 | } |
520 | 520 | return -1; |
@@ -537,19 +537,19 @@ discard block |
||
537 | 537 | * constant operands) |
538 | 538 | * @return int |
539 | 539 | */ |
540 | - public static function mul($a, $b, $size = 0) |
|
540 | + public static function mul( $a, $b, $size = 0 ) |
|
541 | 541 | { |
542 | - if (ParagonIE_Sodium_Compat::$fastMult) { |
|
543 | - return (int) ($a * $b); |
|
542 | + if ( ParagonIE_Sodium_Compat::$fastMult ) { |
|
543 | + return (int)( $a * $b ); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | static $defaultSize = null; |
547 | 547 | /** @var int $defaultSize */ |
548 | - if (!$defaultSize) { |
|
548 | + if ( ! $defaultSize ) { |
|
549 | 549 | /** @var int $defaultSize */ |
550 | - $defaultSize = (PHP_INT_SIZE << 3) - 1; |
|
550 | + $defaultSize = ( PHP_INT_SIZE << 3 ) - 1; |
|
551 | 551 | } |
552 | - if ($size < 1) { |
|
552 | + if ( $size < 1 ) { |
|
553 | 553 | /** @var int $size */ |
554 | 554 | $size = $defaultSize; |
555 | 555 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * |
566 | 566 | * @var int |
567 | 567 | */ |
568 | - $mask = -(($b >> ((int) $defaultSize)) & 1); |
|
568 | + $mask = -( ( $b >> ( (int)$defaultSize ) ) & 1 ); |
|
569 | 569 | |
570 | 570 | /** |
571 | 571 | * Ensure $b is a positive integer, without creating |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * |
574 | 574 | * @var int $b |
575 | 575 | */ |
576 | - $b = ($b & ~$mask) | ($mask & -$b); |
|
576 | + $b = ( $b & ~$mask ) | ( $mask & -$b ); |
|
577 | 577 | |
578 | 578 | /** |
579 | 579 | * Unless $size is provided: |
@@ -581,12 +581,12 @@ discard block |
||
581 | 581 | * This loop always runs 32 times when PHP_INT_SIZE is 4. |
582 | 582 | * This loop always runs 64 times when PHP_INT_SIZE is 8. |
583 | 583 | */ |
584 | - for ($i = $size; $i >= 0; --$i) { |
|
585 | - $c += (int) ($a & -($b & 1)); |
|
584 | + for ( $i = $size; $i >= 0; --$i ) { |
|
585 | + $c += (int)( $a & -( $b & 1 ) ); |
|
586 | 586 | $a <<= 1; |
587 | 587 | $b >>= 1; |
588 | 588 | } |
589 | - $c = (int) @($c & -1); |
|
589 | + $c = (int)@( $c & -1 ); |
|
590 | 590 | |
591 | 591 | /** |
592 | 592 | * If $b was negative, we then apply the same value to $c here. |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | * |
598 | 598 | * The end result is what we'd expect from integer multiplication. |
599 | 599 | */ |
600 | - return (int) (($c & ~$mask) | ($mask & -$c)); |
|
600 | + return (int)( ( $c & ~$mask ) | ( $mask & -$c ) ); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -609,22 +609,22 @@ discard block |
||
609 | 609 | * @param int|float $num |
610 | 610 | * @return array<int, int> |
611 | 611 | */ |
612 | - public static function numericTo64BitInteger($num) |
|
612 | + public static function numericTo64BitInteger( $num ) |
|
613 | 613 | { |
614 | 614 | $high = 0; |
615 | 615 | /** @var int $low */ |
616 | 616 | $low = $num & 0xffffffff; |
617 | 617 | |
618 | - if ((+(abs($num))) >= 1) { |
|
619 | - if ($num > 0) { |
|
618 | + if ( (+( abs( $num ) )) >= 1 ) { |
|
619 | + if ( $num > 0 ) { |
|
620 | 620 | /** @var int $high */ |
621 | - $high = min((+(floor($num/4294967296))), 4294967295); |
|
621 | + $high = min( (+( floor( $num / 4294967296 ) )), 4294967295 ); |
|
622 | 622 | } else { |
623 | 623 | /** @var int $high */ |
624 | - $high = ~~((+(ceil(($num - (+((~~($num)))))/4294967296)))); |
|
624 | + $high = ~~( (+( ceil( ( $num - (+( ( ~~( $num ) ) )) ) / 4294967296 ) )) ); |
|
625 | 625 | } |
626 | 626 | } |
627 | - return array((int) $high, (int) $low); |
|
627 | + return array( (int)$high, (int)$low ); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -636,19 +636,19 @@ discard block |
||
636 | 636 | * @return string |
637 | 637 | * @throws TypeError |
638 | 638 | */ |
639 | - public static function store_3($int) |
|
639 | + public static function store_3( $int ) |
|
640 | 640 | { |
641 | 641 | /* Type checks: */ |
642 | - if (!is_int($int)) { |
|
643 | - if (is_numeric($int)) { |
|
644 | - $int = (int) $int; |
|
642 | + if ( ! is_int( $int ) ) { |
|
643 | + if ( is_numeric( $int ) ) { |
|
644 | + $int = (int)$int; |
|
645 | 645 | } else { |
646 | - throw new TypeError('Argument 1 must be an integer, ' . gettype($int) . ' given.'); |
|
646 | + throw new TypeError( 'Argument 1 must be an integer, ' . gettype( $int ) . ' given.' ); |
|
647 | 647 | } |
648 | 648 | } |
649 | 649 | /** @var string $packed */ |
650 | - $packed = pack('N', $int); |
|
651 | - return self::substr($packed, 1, 3); |
|
650 | + $packed = pack( 'N', $int ); |
|
651 | + return self::substr( $packed, 1, 3 ); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -660,19 +660,19 @@ discard block |
||
660 | 660 | * @return string |
661 | 661 | * @throws TypeError |
662 | 662 | */ |
663 | - public static function store32_le($int) |
|
663 | + public static function store32_le( $int ) |
|
664 | 664 | { |
665 | 665 | /* Type checks: */ |
666 | - if (!is_int($int)) { |
|
667 | - if (is_numeric($int)) { |
|
668 | - $int = (int) $int; |
|
666 | + if ( ! is_int( $int ) ) { |
|
667 | + if ( is_numeric( $int ) ) { |
|
668 | + $int = (int)$int; |
|
669 | 669 | } else { |
670 | - throw new TypeError('Argument 1 must be an integer, ' . gettype($int) . ' given.'); |
|
670 | + throw new TypeError( 'Argument 1 must be an integer, ' . gettype( $int ) . ' given.' ); |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
674 | 674 | /** @var string $packed */ |
675 | - $packed = pack('V', $int); |
|
675 | + $packed = pack( 'V', $int ); |
|
676 | 676 | return $packed; |
677 | 677 | } |
678 | 678 | |
@@ -685,19 +685,19 @@ discard block |
||
685 | 685 | * @return string |
686 | 686 | * @throws TypeError |
687 | 687 | */ |
688 | - public static function store_4($int) |
|
688 | + public static function store_4( $int ) |
|
689 | 689 | { |
690 | 690 | /* Type checks: */ |
691 | - if (!is_int($int)) { |
|
692 | - if (is_numeric($int)) { |
|
693 | - $int = (int) $int; |
|
691 | + if ( ! is_int( $int ) ) { |
|
692 | + if ( is_numeric( $int ) ) { |
|
693 | + $int = (int)$int; |
|
694 | 694 | } else { |
695 | - throw new TypeError('Argument 1 must be an integer, ' . gettype($int) . ' given.'); |
|
695 | + throw new TypeError( 'Argument 1 must be an integer, ' . gettype( $int ) . ' given.' ); |
|
696 | 696 | } |
697 | 697 | } |
698 | 698 | |
699 | 699 | /** @var string $packed */ |
700 | - $packed = pack('N', $int); |
|
700 | + $packed = pack( 'N', $int ); |
|
701 | 701 | return $packed; |
702 | 702 | } |
703 | 703 | |
@@ -710,46 +710,46 @@ discard block |
||
710 | 710 | * @return string |
711 | 711 | * @throws TypeError |
712 | 712 | */ |
713 | - public static function store64_le($int) |
|
713 | + public static function store64_le( $int ) |
|
714 | 714 | { |
715 | 715 | /* Type checks: */ |
716 | - if (!is_int($int)) { |
|
717 | - if (is_numeric($int)) { |
|
718 | - $int = (int) $int; |
|
716 | + if ( ! is_int( $int ) ) { |
|
717 | + if ( is_numeric( $int ) ) { |
|
718 | + $int = (int)$int; |
|
719 | 719 | } else { |
720 | - throw new TypeError('Argument 1 must be an integer, ' . gettype($int) . ' given.'); |
|
720 | + throw new TypeError( 'Argument 1 must be an integer, ' . gettype( $int ) . ' given.' ); |
|
721 | 721 | } |
722 | 722 | } |
723 | 723 | |
724 | - if (PHP_INT_SIZE === 8) { |
|
725 | - if (PHP_VERSION_ID >= 50603) { |
|
724 | + if ( PHP_INT_SIZE === 8 ) { |
|
725 | + if ( PHP_VERSION_ID >= 50603 ) { |
|
726 | 726 | /** @var string $packed */ |
727 | - $packed = pack('P', $int); |
|
727 | + $packed = pack( 'P', $int ); |
|
728 | 728 | return $packed; |
729 | 729 | } |
730 | - return self::intToChr($int & 0xff) . |
|
731 | - self::intToChr(($int >> 8) & 0xff) . |
|
732 | - self::intToChr(($int >> 16) & 0xff) . |
|
733 | - self::intToChr(($int >> 24) & 0xff) . |
|
734 | - self::intToChr(($int >> 32) & 0xff) . |
|
735 | - self::intToChr(($int >> 40) & 0xff) . |
|
736 | - self::intToChr(($int >> 48) & 0xff) . |
|
737 | - self::intToChr(($int >> 56) & 0xff); |
|
738 | - } |
|
739 | - if ($int > PHP_INT_MAX) { |
|
740 | - list($hiB, $int) = self::numericTo64BitInteger($int); |
|
730 | + return self::intToChr( $int & 0xff ) . |
|
731 | + self::intToChr( ( $int >> 8 ) & 0xff ) . |
|
732 | + self::intToChr( ( $int >> 16 ) & 0xff ) . |
|
733 | + self::intToChr( ( $int >> 24 ) & 0xff ) . |
|
734 | + self::intToChr( ( $int >> 32 ) & 0xff ) . |
|
735 | + self::intToChr( ( $int >> 40 ) & 0xff ) . |
|
736 | + self::intToChr( ( $int >> 48 ) & 0xff ) . |
|
737 | + self::intToChr( ( $int >> 56 ) & 0xff ); |
|
738 | + } |
|
739 | + if ( $int > PHP_INT_MAX ) { |
|
740 | + list( $hiB, $int ) = self::numericTo64BitInteger( $int ); |
|
741 | 741 | } else { |
742 | 742 | $hiB = 0; |
743 | 743 | } |
744 | 744 | return |
745 | - self::intToChr(($int ) & 0xff) . |
|
746 | - self::intToChr(($int >> 8) & 0xff) . |
|
747 | - self::intToChr(($int >> 16) & 0xff) . |
|
748 | - self::intToChr(($int >> 24) & 0xff) . |
|
749 | - self::intToChr($hiB & 0xff) . |
|
750 | - self::intToChr(($hiB >> 8) & 0xff) . |
|
751 | - self::intToChr(($hiB >> 16) & 0xff) . |
|
752 | - self::intToChr(($hiB >> 24) & 0xff); |
|
745 | + self::intToChr( ( $int ) & 0xff ) . |
|
746 | + self::intToChr( ( $int >> 8 ) & 0xff ) . |
|
747 | + self::intToChr( ( $int >> 16 ) & 0xff ) . |
|
748 | + self::intToChr( ( $int >> 24 ) & 0xff ) . |
|
749 | + self::intToChr( $hiB & 0xff ) . |
|
750 | + self::intToChr( ( $hiB >> 8 ) & 0xff ) . |
|
751 | + self::intToChr( ( $hiB >> 16 ) & 0xff ) . |
|
752 | + self::intToChr( ( $hiB >> 24 ) & 0xff ); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
@@ -763,17 +763,17 @@ discard block |
||
763 | 763 | * @return int |
764 | 764 | * @throws TypeError |
765 | 765 | */ |
766 | - public static function strlen($str) |
|
766 | + public static function strlen( $str ) |
|
767 | 767 | { |
768 | 768 | /* Type checks: */ |
769 | - if (!is_string($str)) { |
|
770 | - throw new TypeError('String expected'); |
|
769 | + if ( ! is_string( $str ) ) { |
|
770 | + throw new TypeError( 'String expected' ); |
|
771 | 771 | } |
772 | 772 | |
773 | - return (int) ( |
|
773 | + return (int)( |
|
774 | 774 | self::isMbStringOverride() |
775 | - ? mb_strlen($str, '8bit') |
|
776 | - : strlen($str) |
|
775 | + ? mb_strlen( $str, '8bit' ) |
|
776 | + : strlen( $str ) |
|
777 | 777 | ); |
778 | 778 | } |
779 | 779 | |
@@ -786,16 +786,16 @@ discard block |
||
786 | 786 | * @return array<int, int> |
787 | 787 | * @throws TypeError |
788 | 788 | */ |
789 | - public static function stringToIntArray($string) |
|
789 | + public static function stringToIntArray( $string ) |
|
790 | 790 | { |
791 | - if (!is_string($string)) { |
|
792 | - throw new TypeError('String expected'); |
|
791 | + if ( ! is_string( $string ) ) { |
|
792 | + throw new TypeError( 'String expected' ); |
|
793 | 793 | } |
794 | 794 | /** |
795 | 795 | * @var array<int, int> |
796 | 796 | */ |
797 | 797 | $values = array_values( |
798 | - unpack('C*', $string) |
|
798 | + unpack( 'C*', $string ) |
|
799 | 799 | ); |
800 | 800 | return $values; |
801 | 801 | } |
@@ -813,28 +813,28 @@ discard block |
||
813 | 813 | * @return string |
814 | 814 | * @throws TypeError |
815 | 815 | */ |
816 | - public static function substr($str, $start = 0, $length = null) |
|
816 | + public static function substr( $str, $start = 0, $length = null ) |
|
817 | 817 | { |
818 | 818 | /* Type checks: */ |
819 | - if (!is_string($str)) { |
|
820 | - throw new TypeError('String expected'); |
|
819 | + if ( ! is_string( $str ) ) { |
|
820 | + throw new TypeError( 'String expected' ); |
|
821 | 821 | } |
822 | 822 | |
823 | - if ($length === 0) { |
|
823 | + if ( $length === 0 ) { |
|
824 | 824 | return ''; |
825 | 825 | } |
826 | 826 | |
827 | - if (self::isMbStringOverride()) { |
|
828 | - if (PHP_VERSION_ID < 50400 && $length === null) { |
|
829 | - $length = self::strlen($str); |
|
827 | + if ( self::isMbStringOverride() ) { |
|
828 | + if ( PHP_VERSION_ID < 50400 && $length === null ) { |
|
829 | + $length = self::strlen( $str ); |
|
830 | 830 | } |
831 | - $sub = (string) mb_substr($str, $start, $length, '8bit'); |
|
832 | - } elseif ($length === null) { |
|
833 | - $sub = (string) substr($str, $start); |
|
831 | + $sub = (string)mb_substr( $str, $start, $length, '8bit' ); |
|
832 | + } elseif ( $length === null ) { |
|
833 | + $sub = (string)substr( $str, $start ); |
|
834 | 834 | } else { |
835 | - $sub = (string) substr($str, $start, $length); |
|
835 | + $sub = (string)substr( $str, $start, $length ); |
|
836 | 836 | } |
837 | - if ($sub !== '') { |
|
837 | + if ( $sub !== '' ) { |
|
838 | 838 | return $sub; |
839 | 839 | } |
840 | 840 | return ''; |
@@ -851,18 +851,18 @@ discard block |
||
851 | 851 | * @throws SodiumException |
852 | 852 | * @throws TypeError |
853 | 853 | */ |
854 | - public static function verify_16($a, $b) |
|
854 | + public static function verify_16( $a, $b ) |
|
855 | 855 | { |
856 | 856 | /* Type checks: */ |
857 | - if (!is_string($a)) { |
|
858 | - throw new TypeError('String expected'); |
|
857 | + if ( ! is_string( $a ) ) { |
|
858 | + throw new TypeError( 'String expected' ); |
|
859 | 859 | } |
860 | - if (!is_string($b)) { |
|
861 | - throw new TypeError('String expected'); |
|
860 | + if ( ! is_string( $b ) ) { |
|
861 | + throw new TypeError( 'String expected' ); |
|
862 | 862 | } |
863 | 863 | return self::hashEquals( |
864 | - self::substr($a, 0, 16), |
|
865 | - self::substr($b, 0, 16) |
|
864 | + self::substr( $a, 0, 16 ), |
|
865 | + self::substr( $b, 0, 16 ) |
|
866 | 866 | ); |
867 | 867 | } |
868 | 868 | |
@@ -877,18 +877,18 @@ discard block |
||
877 | 877 | * @throws SodiumException |
878 | 878 | * @throws TypeError |
879 | 879 | */ |
880 | - public static function verify_32($a, $b) |
|
880 | + public static function verify_32( $a, $b ) |
|
881 | 881 | { |
882 | 882 | /* Type checks: */ |
883 | - if (!is_string($a)) { |
|
884 | - throw new TypeError('String expected'); |
|
883 | + if ( ! is_string( $a ) ) { |
|
884 | + throw new TypeError( 'String expected' ); |
|
885 | 885 | } |
886 | - if (!is_string($b)) { |
|
887 | - throw new TypeError('String expected'); |
|
886 | + if ( ! is_string( $b ) ) { |
|
887 | + throw new TypeError( 'String expected' ); |
|
888 | 888 | } |
889 | 889 | return self::hashEquals( |
890 | - self::substr($a, 0, 32), |
|
891 | - self::substr($b, 0, 32) |
|
890 | + self::substr( $a, 0, 32 ), |
|
891 | + self::substr( $b, 0, 32 ) |
|
892 | 892 | ); |
893 | 893 | } |
894 | 894 | |
@@ -902,17 +902,17 @@ discard block |
||
902 | 902 | * @return string |
903 | 903 | * @throws TypeError |
904 | 904 | */ |
905 | - public static function xorStrings($a, $b) |
|
905 | + public static function xorStrings( $a, $b ) |
|
906 | 906 | { |
907 | 907 | /* Type checks: */ |
908 | - if (!is_string($a)) { |
|
909 | - throw new TypeError('Argument 1 must be a string'); |
|
908 | + if ( ! is_string( $a ) ) { |
|
909 | + throw new TypeError( 'Argument 1 must be a string' ); |
|
910 | 910 | } |
911 | - if (!is_string($b)) { |
|
912 | - throw new TypeError('Argument 2 must be a string'); |
|
911 | + if ( ! is_string( $b ) ) { |
|
912 | + throw new TypeError( 'Argument 2 must be a string' ); |
|
913 | 913 | } |
914 | 914 | |
915 | - return (string) ($a ^ $b); |
|
915 | + return (string)( $a ^ $b ); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -929,15 +929,15 @@ discard block |
||
929 | 929 | { |
930 | 930 | static $mbstring = null; |
931 | 931 | |
932 | - if ($mbstring === null) { |
|
933 | - if (!defined('MB_OVERLOAD_STRING')) { |
|
932 | + if ( $mbstring === null ) { |
|
933 | + if ( ! defined( 'MB_OVERLOAD_STRING' ) ) { |
|
934 | 934 | $mbstring = false; |
935 | 935 | return $mbstring; |
936 | 936 | } |
937 | - $mbstring = extension_loaded('mbstring') |
|
938 | - && defined('MB_OVERLOAD_STRING') |
|
937 | + $mbstring = extension_loaded( 'mbstring' ) |
|
938 | + && defined( 'MB_OVERLOAD_STRING' ) |
|
939 | 939 | && |
940 | - ((int) (ini_get('mbstring.func_overload')) & 2); |
|
940 | + ( (int)( ini_get( 'mbstring.func_overload' ) ) & 2 ); |
|
941 | 941 | // MB_OVERLOAD_STRING === 2 |
942 | 942 | } |
943 | 943 | /** @var bool $mbstring */ |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_SipHash', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_SipHash', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -18,65 +18,65 @@ discard block |
||
18 | 18 | * @return int[] |
19 | 19 | * |
20 | 20 | */ |
21 | - public static function sipRound(array $v) |
|
21 | + public static function sipRound( array $v ) |
|
22 | 22 | { |
23 | 23 | # v0 += v1; |
24 | - list($v[0], $v[1]) = self::add( |
|
25 | - array($v[0], $v[1]), |
|
26 | - array($v[2], $v[3]) |
|
24 | + list( $v[ 0 ], $v[ 1 ] ) = self::add( |
|
25 | + array( $v[ 0 ], $v[ 1 ] ), |
|
26 | + array( $v[ 2 ], $v[ 3 ] ) |
|
27 | 27 | ); |
28 | 28 | |
29 | 29 | # v1=ROTL(v1,13); |
30 | - list($v[2], $v[3]) = self::rotl_64((int) $v[2], (int) $v[3], 13); |
|
30 | + list( $v[ 2 ], $v[ 3 ] ) = self::rotl_64( (int)$v[ 2 ], (int)$v[ 3 ], 13 ); |
|
31 | 31 | |
32 | 32 | # v1 ^= v0; |
33 | - $v[2] = (int) $v[2] ^ (int) $v[0]; |
|
34 | - $v[3] = (int) $v[3] ^ (int) $v[1]; |
|
33 | + $v[ 2 ] = (int)$v[ 2 ] ^ (int)$v[ 0 ]; |
|
34 | + $v[ 3 ] = (int)$v[ 3 ] ^ (int)$v[ 1 ]; |
|
35 | 35 | |
36 | 36 | # v0=ROTL(v0,32); |
37 | - list($v[0], $v[1]) = self::rotl_64((int) $v[0], (int) $v[1], 32); |
|
37 | + list( $v[ 0 ], $v[ 1 ] ) = self::rotl_64( (int)$v[ 0 ], (int)$v[ 1 ], 32 ); |
|
38 | 38 | |
39 | 39 | # v2 += v3; |
40 | - list($v[4], $v[5]) = self::add( |
|
41 | - array((int) $v[4], (int) $v[5]), |
|
42 | - array((int) $v[6], (int) $v[7]) |
|
40 | + list( $v[ 4 ], $v[ 5 ] ) = self::add( |
|
41 | + array( (int)$v[ 4 ], (int)$v[ 5 ] ), |
|
42 | + array( (int)$v[ 6 ], (int)$v[ 7 ] ) |
|
43 | 43 | ); |
44 | 44 | |
45 | 45 | # v3=ROTL(v3,16); |
46 | - list($v[6], $v[7]) = self::rotl_64((int) $v[6], (int) $v[7], 16); |
|
46 | + list( $v[ 6 ], $v[ 7 ] ) = self::rotl_64( (int)$v[ 6 ], (int)$v[ 7 ], 16 ); |
|
47 | 47 | |
48 | 48 | # v3 ^= v2; |
49 | - $v[6] = (int) $v[6] ^ (int) $v[4]; |
|
50 | - $v[7] = (int) $v[7] ^ (int) $v[5]; |
|
49 | + $v[ 6 ] = (int)$v[ 6 ] ^ (int)$v[ 4 ]; |
|
50 | + $v[ 7 ] = (int)$v[ 7 ] ^ (int)$v[ 5 ]; |
|
51 | 51 | |
52 | 52 | # v0 += v3; |
53 | - list($v[0], $v[1]) = self::add( |
|
54 | - array((int) $v[0], (int) $v[1]), |
|
55 | - array((int) $v[6], (int) $v[7]) |
|
53 | + list( $v[ 0 ], $v[ 1 ] ) = self::add( |
|
54 | + array( (int)$v[ 0 ], (int)$v[ 1 ] ), |
|
55 | + array( (int)$v[ 6 ], (int)$v[ 7 ] ) |
|
56 | 56 | ); |
57 | 57 | |
58 | 58 | # v3=ROTL(v3,21); |
59 | - list($v[6], $v[7]) = self::rotl_64((int) $v[6], (int) $v[7], 21); |
|
59 | + list( $v[ 6 ], $v[ 7 ] ) = self::rotl_64( (int)$v[ 6 ], (int)$v[ 7 ], 21 ); |
|
60 | 60 | |
61 | 61 | # v3 ^= v0; |
62 | - $v[6] = (int) $v[6] ^ (int) $v[0]; |
|
63 | - $v[7] = (int) $v[7] ^ (int) $v[1]; |
|
62 | + $v[ 6 ] = (int)$v[ 6 ] ^ (int)$v[ 0 ]; |
|
63 | + $v[ 7 ] = (int)$v[ 7 ] ^ (int)$v[ 1 ]; |
|
64 | 64 | |
65 | 65 | # v2 += v1; |
66 | - list($v[4], $v[5]) = self::add( |
|
67 | - array((int) $v[4], (int) $v[5]), |
|
68 | - array((int) $v[2], (int) $v[3]) |
|
66 | + list( $v[ 4 ], $v[ 5 ] ) = self::add( |
|
67 | + array( (int)$v[ 4 ], (int)$v[ 5 ] ), |
|
68 | + array( (int)$v[ 2 ], (int)$v[ 3 ] ) |
|
69 | 69 | ); |
70 | 70 | |
71 | 71 | # v1=ROTL(v1,17); |
72 | - list($v[2], $v[3]) = self::rotl_64((int) $v[2], (int) $v[3], 17); |
|
72 | + list( $v[ 2 ], $v[ 3 ] ) = self::rotl_64( (int)$v[ 2 ], (int)$v[ 3 ], 17 ); |
|
73 | 73 | |
74 | 74 | # v1 ^= v2;; |
75 | - $v[2] = (int) $v[2] ^ (int) $v[4]; |
|
76 | - $v[3] = (int) $v[3] ^ (int) $v[5]; |
|
75 | + $v[ 2 ] = (int)$v[ 2 ] ^ (int)$v[ 4 ]; |
|
76 | + $v[ 3 ] = (int)$v[ 3 ] ^ (int)$v[ 5 ]; |
|
77 | 77 | |
78 | 78 | # v2=ROTL(v2,32) |
79 | - list($v[4], $v[5]) = self::rotl_64((int) $v[4], (int) $v[5], 32); |
|
79 | + list( $v[ 4 ], $v[ 5 ] ) = self::rotl_64( (int)$v[ 4 ], (int)$v[ 5 ], 32 ); |
|
80 | 80 | |
81 | 81 | return $v; |
82 | 82 | } |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * @param int[] $b |
91 | 91 | * @return array<int, mixed> |
92 | 92 | */ |
93 | - public static function add(array $a, array $b) |
|
93 | + public static function add( array $a, array $b ) |
|
94 | 94 | { |
95 | 95 | /** @var int $x1 */ |
96 | - $x1 = $a[1] + $b[1]; |
|
96 | + $x1 = $a[ 1 ] + $b[ 1 ]; |
|
97 | 97 | /** @var int $c */ |
98 | 98 | $c = $x1 >> 32; // Carry if ($a + $b) > 0xffffffff |
99 | 99 | /** @var int $x0 */ |
100 | - $x0 = $a[0] + $b[0] + $c; |
|
100 | + $x0 = $a[ 0 ] + $b[ 0 ] + $c; |
|
101 | 101 | return array( |
102 | 102 | $x0 & 0xffffffff, |
103 | 103 | $x1 & 0xffffffff |
@@ -112,33 +112,33 @@ discard block |
||
112 | 112 | * @param int $c |
113 | 113 | * @return array<int, mixed> |
114 | 114 | */ |
115 | - public static function rotl_64($int0, $int1, $c) |
|
115 | + public static function rotl_64( $int0, $int1, $c ) |
|
116 | 116 | { |
117 | 117 | $int0 &= 0xffffffff; |
118 | 118 | $int1 &= 0xffffffff; |
119 | 119 | $c &= 63; |
120 | - if ($c === 32) { |
|
121 | - return array($int1, $int0); |
|
120 | + if ( $c === 32 ) { |
|
121 | + return array( $int1, $int0 ); |
|
122 | 122 | } |
123 | - if ($c > 31) { |
|
123 | + if ( $c > 31 ) { |
|
124 | 124 | $tmp = $int1; |
125 | 125 | $int1 = $int0; |
126 | 126 | $int0 = $tmp; |
127 | 127 | $c &= 31; |
128 | 128 | } |
129 | - if ($c === 0) { |
|
130 | - return array($int0, $int1); |
|
129 | + if ( $c === 0 ) { |
|
130 | + return array( $int0, $int1 ); |
|
131 | 131 | } |
132 | 132 | return array( |
133 | 133 | 0xffffffff & ( |
134 | - ($int0 << $c) |
|
134 | + ( $int0 << $c ) |
|
135 | 135 | | |
136 | - ($int1 >> (32 - $c)) |
|
136 | + ( $int1 >> ( 32 - $c ) ) |
|
137 | 137 | ), |
138 | 138 | 0xffffffff & ( |
139 | - ($int1 << $c) |
|
139 | + ( $int1 << $c ) |
|
140 | 140 | | |
141 | - ($int0 >> (32 - $c)) |
|
141 | + ( $int0 >> ( 32 - $c ) ) |
|
142 | 142 | ), |
143 | 143 | ); |
144 | 144 | } |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * @throws SodiumException |
161 | 161 | * @throws TypeError |
162 | 162 | */ |
163 | - public static function sipHash24($in, $key) |
|
163 | + public static function sipHash24( $in, $key ) |
|
164 | 164 | { |
165 | - $inlen = self::strlen($in); |
|
165 | + $inlen = self::strlen( $in ); |
|
166 | 166 | |
167 | 167 | # /* "somepseudorandomlygeneratedbytes" */ |
168 | 168 | # u64 v0 = 0x736f6d6570736575ULL; |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | # u64 k0 = LOAD64_LE( k ); |
188 | 188 | # u64 k1 = LOAD64_LE( k + 8 ); |
189 | 189 | $k = array( |
190 | - self::load_4(self::substr($key, 4, 4)), |
|
191 | - self::load_4(self::substr($key, 0, 4)), |
|
192 | - self::load_4(self::substr($key, 12, 4)), |
|
193 | - self::load_4(self::substr($key, 8, 4)) |
|
190 | + self::load_4( self::substr( $key, 4, 4 ) ), |
|
191 | + self::load_4( self::substr( $key, 0, 4 ) ), |
|
192 | + self::load_4( self::substr( $key, 12, 4 ) ), |
|
193 | + self::load_4( self::substr( $key, 8, 4 ) ) |
|
194 | 194 | ); |
195 | 195 | // k0 => $k[0], $k[1] |
196 | 196 | // k1 => $k[2], $k[3] |
@@ -203,41 +203,41 @@ discard block |
||
203 | 203 | // See docblock for why the 0th index gets the higher bits. |
204 | 204 | |
205 | 205 | # v3 ^= k1; |
206 | - $v[6] ^= $k[2]; |
|
207 | - $v[7] ^= $k[3]; |
|
206 | + $v[ 6 ] ^= $k[ 2 ]; |
|
207 | + $v[ 7 ] ^= $k[ 3 ]; |
|
208 | 208 | # v2 ^= k0; |
209 | - $v[4] ^= $k[0]; |
|
210 | - $v[5] ^= $k[1]; |
|
209 | + $v[ 4 ] ^= $k[ 0 ]; |
|
210 | + $v[ 5 ] ^= $k[ 1 ]; |
|
211 | 211 | # v1 ^= k1; |
212 | - $v[2] ^= $k[2]; |
|
213 | - $v[3] ^= $k[3]; |
|
212 | + $v[ 2 ] ^= $k[ 2 ]; |
|
213 | + $v[ 3 ] ^= $k[ 3 ]; |
|
214 | 214 | # v0 ^= k0; |
215 | - $v[0] ^= $k[0]; |
|
216 | - $v[1] ^= $k[1]; |
|
215 | + $v[ 0 ] ^= $k[ 0 ]; |
|
216 | + $v[ 1 ] ^= $k[ 1 ]; |
|
217 | 217 | |
218 | 218 | $left = $inlen; |
219 | 219 | # for ( ; in != end; in += 8 ) |
220 | - while ($left >= 8) { |
|
220 | + while ( $left >= 8 ) { |
|
221 | 221 | # m = LOAD64_LE( in ); |
222 | 222 | $m = array( |
223 | - self::load_4(self::substr($in, 4, 4)), |
|
224 | - self::load_4(self::substr($in, 0, 4)) |
|
223 | + self::load_4( self::substr( $in, 4, 4 ) ), |
|
224 | + self::load_4( self::substr( $in, 0, 4 ) ) |
|
225 | 225 | ); |
226 | 226 | |
227 | 227 | # v3 ^= m; |
228 | - $v[6] ^= $m[0]; |
|
229 | - $v[7] ^= $m[1]; |
|
228 | + $v[ 6 ] ^= $m[ 0 ]; |
|
229 | + $v[ 7 ] ^= $m[ 1 ]; |
|
230 | 230 | |
231 | 231 | # SIPROUND; |
232 | 232 | # SIPROUND; |
233 | - $v = self::sipRound($v); |
|
234 | - $v = self::sipRound($v); |
|
233 | + $v = self::sipRound( $v ); |
|
234 | + $v = self::sipRound( $v ); |
|
235 | 235 | |
236 | 236 | # v0 ^= m; |
237 | - $v[0] ^= $m[0]; |
|
238 | - $v[1] ^= $m[1]; |
|
237 | + $v[ 0 ] ^= $m[ 0 ]; |
|
238 | + $v[ 1 ] ^= $m[ 1 ]; |
|
239 | 239 | |
240 | - $in = self::substr($in, 8); |
|
240 | + $in = self::substr( $in, 8 ); |
|
241 | 241 | $left -= 8; |
242 | 242 | } |
243 | 243 | |
@@ -252,55 +252,55 @@ discard block |
||
252 | 252 | # case 1: b |= ( ( u64 )in[ 0] ); break; |
253 | 253 | # case 0: break; |
254 | 254 | # } |
255 | - switch ($left) { |
|
255 | + switch ( $left ) { |
|
256 | 256 | case 7: |
257 | - $b[0] |= self::chrToInt($in[6]) << 16; |
|
257 | + $b[ 0 ] |= self::chrToInt( $in[ 6 ] ) << 16; |
|
258 | 258 | case 6: |
259 | - $b[0] |= self::chrToInt($in[5]) << 8; |
|
259 | + $b[ 0 ] |= self::chrToInt( $in[ 5 ] ) << 8; |
|
260 | 260 | case 5: |
261 | - $b[0] |= self::chrToInt($in[4]); |
|
261 | + $b[ 0 ] |= self::chrToInt( $in[ 4 ] ); |
|
262 | 262 | case 4: |
263 | - $b[1] |= self::chrToInt($in[3]) << 24; |
|
263 | + $b[ 1 ] |= self::chrToInt( $in[ 3 ] ) << 24; |
|
264 | 264 | case 3: |
265 | - $b[1] |= self::chrToInt($in[2]) << 16; |
|
265 | + $b[ 1 ] |= self::chrToInt( $in[ 2 ] ) << 16; |
|
266 | 266 | case 2: |
267 | - $b[1] |= self::chrToInt($in[1]) << 8; |
|
267 | + $b[ 1 ] |= self::chrToInt( $in[ 1 ] ) << 8; |
|
268 | 268 | case 1: |
269 | - $b[1] |= self::chrToInt($in[0]); |
|
269 | + $b[ 1 ] |= self::chrToInt( $in[ 0 ] ); |
|
270 | 270 | case 0: |
271 | 271 | break; |
272 | 272 | } |
273 | 273 | // See docblock for why the 0th index gets the higher bits. |
274 | 274 | |
275 | 275 | # v3 ^= b; |
276 | - $v[6] ^= $b[0]; |
|
277 | - $v[7] ^= $b[1]; |
|
276 | + $v[ 6 ] ^= $b[ 0 ]; |
|
277 | + $v[ 7 ] ^= $b[ 1 ]; |
|
278 | 278 | |
279 | 279 | # SIPROUND; |
280 | 280 | # SIPROUND; |
281 | - $v = self::sipRound($v); |
|
282 | - $v = self::sipRound($v); |
|
281 | + $v = self::sipRound( $v ); |
|
282 | + $v = self::sipRound( $v ); |
|
283 | 283 | |
284 | 284 | # v0 ^= b; |
285 | - $v[0] ^= $b[0]; |
|
286 | - $v[1] ^= $b[1]; |
|
285 | + $v[ 0 ] ^= $b[ 0 ]; |
|
286 | + $v[ 1 ] ^= $b[ 1 ]; |
|
287 | 287 | |
288 | 288 | // Flip the lower 8 bits of v2 which is ($v[4], $v[5]) in our implementation |
289 | 289 | # v2 ^= 0xff; |
290 | - $v[5] ^= 0xff; |
|
290 | + $v[ 5 ] ^= 0xff; |
|
291 | 291 | |
292 | 292 | # SIPROUND; |
293 | 293 | # SIPROUND; |
294 | 294 | # SIPROUND; |
295 | 295 | # SIPROUND; |
296 | - $v = self::sipRound($v); |
|
297 | - $v = self::sipRound($v); |
|
298 | - $v = self::sipRound($v); |
|
299 | - $v = self::sipRound($v); |
|
296 | + $v = self::sipRound( $v ); |
|
297 | + $v = self::sipRound( $v ); |
|
298 | + $v = self::sipRound( $v ); |
|
299 | + $v = self::sipRound( $v ); |
|
300 | 300 | |
301 | 301 | # b = v0 ^ v1 ^ v2 ^ v3; |
302 | 302 | # STORE64_LE( out, b ); |
303 | - return self::store32_le($v[1] ^ $v[3] ^ $v[5] ^ $v[7]) . |
|
304 | - self::store32_le($v[0] ^ $v[2] ^ $v[4] ^ $v[6]); |
|
303 | + return self::store32_le( $v[ 1 ] ^ $v[ 3 ] ^ $v[ 5 ] ^ $v[ 7 ] ) . |
|
304 | + self::store32_le( $v[ 0 ] ^ $v[ 2 ] ^ $v[ 4 ] ^ $v[ 6 ] ); |
|
305 | 305 | } |
306 | 306 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_XChaCha20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_XChaCha20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -19,20 +19,20 @@ discard block |
||
19 | 19 | * @throws SodiumException |
20 | 20 | * @throws TypeError |
21 | 21 | */ |
22 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
22 | + public static function stream( $len = 64, $nonce = '', $key = '' ) |
|
23 | 23 | { |
24 | - if (self::strlen($nonce) !== 24) { |
|
25 | - throw new SodiumException('Nonce must be 24 bytes long'); |
|
24 | + if ( self::strlen( $nonce ) !== 24 ) { |
|
25 | + throw new SodiumException( 'Nonce must be 24 bytes long' ); |
|
26 | 26 | } |
27 | 27 | return self::encryptBytes( |
28 | 28 | new ParagonIE_Sodium_Core_ChaCha20_Ctx( |
29 | 29 | self::hChaCha20( |
30 | - self::substr($nonce, 0, 16), |
|
30 | + self::substr( $nonce, 0, 16 ), |
|
31 | 31 | $key |
32 | 32 | ), |
33 | - self::substr($nonce, 16, 8) |
|
33 | + self::substr( $nonce, 16, 8 ) |
|
34 | 34 | ), |
35 | - str_repeat("\x00", $len) |
|
35 | + str_repeat( "\x00", $len ) |
|
36 | 36 | ); |
37 | 37 | } |
38 | 38 | |
@@ -46,20 +46,20 @@ discard block |
||
46 | 46 | * @throws SodiumException |
47 | 47 | * @throws TypeError |
48 | 48 | */ |
49 | - public static function ietfStream($len = 64, $nonce = '', $key = '') |
|
49 | + public static function ietfStream( $len = 64, $nonce = '', $key = '' ) |
|
50 | 50 | { |
51 | - if (self::strlen($nonce) !== 24) { |
|
52 | - throw new SodiumException('Nonce must be 24 bytes long'); |
|
51 | + if ( self::strlen( $nonce ) !== 24 ) { |
|
52 | + throw new SodiumException( 'Nonce must be 24 bytes long' ); |
|
53 | 53 | } |
54 | 54 | return self::encryptBytes( |
55 | 55 | new ParagonIE_Sodium_Core_ChaCha20_IetfCtx( |
56 | 56 | self::hChaCha20( |
57 | - self::substr($nonce, 0, 16), |
|
57 | + self::substr( $nonce, 0, 16 ), |
|
58 | 58 | $key |
59 | 59 | ), |
60 | - "\x00\x00\x00\x00" . self::substr($nonce, 16, 8) |
|
60 | + "\x00\x00\x00\x00" . self::substr( $nonce, 16, 8 ) |
|
61 | 61 | ), |
62 | - str_repeat("\x00", $len) |
|
62 | + str_repeat( "\x00", $len ) |
|
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | * @throws SodiumException |
75 | 75 | * @throws TypeError |
76 | 76 | */ |
77 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
77 | + public static function streamXorIc( $message, $nonce = '', $key = '', $ic = '' ) |
|
78 | 78 | { |
79 | - if (self::strlen($nonce) !== 24) { |
|
80 | - throw new SodiumException('Nonce must be 24 bytes long'); |
|
79 | + if ( self::strlen( $nonce ) !== 24 ) { |
|
80 | + throw new SodiumException( 'Nonce must be 24 bytes long' ); |
|
81 | 81 | } |
82 | 82 | return self::encryptBytes( |
83 | 83 | new ParagonIE_Sodium_Core_ChaCha20_Ctx( |
84 | - self::hChaCha20(self::substr($nonce, 0, 16), $key), |
|
85 | - self::substr($nonce, 16, 8), |
|
84 | + self::hChaCha20( self::substr( $nonce, 0, 16 ), $key ), |
|
85 | + self::substr( $nonce, 16, 8 ), |
|
86 | 86 | $ic |
87 | 87 | ), |
88 | 88 | $message |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * @throws SodiumException |
101 | 101 | * @throws TypeError |
102 | 102 | */ |
103 | - public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
103 | + public static function ietfStreamXorIc( $message, $nonce = '', $key = '', $ic = '' ) |
|
104 | 104 | { |
105 | - if (self::strlen($nonce) !== 24) { |
|
106 | - throw new SodiumException('Nonce must be 24 bytes long'); |
|
105 | + if ( self::strlen( $nonce ) !== 24 ) { |
|
106 | + throw new SodiumException( 'Nonce must be 24 bytes long' ); |
|
107 | 107 | } |
108 | 108 | return self::encryptBytes( |
109 | 109 | new ParagonIE_Sodium_Core_ChaCha20_IetfCtx( |
110 | - self::hChaCha20(self::substr($nonce, 0, 16), $key), |
|
111 | - "\x00\x00\x00\x00" . self::substr($nonce, 16, 8), |
|
110 | + self::hChaCha20( self::substr( $nonce, 0, 16 ), $key ), |
|
111 | + "\x00\x00\x00\x00" . self::substr( $nonce, 16, 8 ), |
|
112 | 112 | $ic |
113 | 113 | ), |
114 | 114 | $message |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_X25519', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_X25519', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -25,57 +25,57 @@ discard block |
||
25 | 25 | ParagonIE_Sodium_Core_Curve25519_Fe $g, |
26 | 26 | $b = 0 |
27 | 27 | ) { |
28 | - $f0 = (int) $f[0]; |
|
29 | - $f1 = (int) $f[1]; |
|
30 | - $f2 = (int) $f[2]; |
|
31 | - $f3 = (int) $f[3]; |
|
32 | - $f4 = (int) $f[4]; |
|
33 | - $f5 = (int) $f[5]; |
|
34 | - $f6 = (int) $f[6]; |
|
35 | - $f7 = (int) $f[7]; |
|
36 | - $f8 = (int) $f[8]; |
|
37 | - $f9 = (int) $f[9]; |
|
38 | - $g0 = (int) $g[0]; |
|
39 | - $g1 = (int) $g[1]; |
|
40 | - $g2 = (int) $g[2]; |
|
41 | - $g3 = (int) $g[3]; |
|
42 | - $g4 = (int) $g[4]; |
|
43 | - $g5 = (int) $g[5]; |
|
44 | - $g6 = (int) $g[6]; |
|
45 | - $g7 = (int) $g[7]; |
|
46 | - $g8 = (int) $g[8]; |
|
47 | - $g9 = (int) $g[9]; |
|
28 | + $f0 = (int)$f[ 0 ]; |
|
29 | + $f1 = (int)$f[ 1 ]; |
|
30 | + $f2 = (int)$f[ 2 ]; |
|
31 | + $f3 = (int)$f[ 3 ]; |
|
32 | + $f4 = (int)$f[ 4 ]; |
|
33 | + $f5 = (int)$f[ 5 ]; |
|
34 | + $f6 = (int)$f[ 6 ]; |
|
35 | + $f7 = (int)$f[ 7 ]; |
|
36 | + $f8 = (int)$f[ 8 ]; |
|
37 | + $f9 = (int)$f[ 9 ]; |
|
38 | + $g0 = (int)$g[ 0 ]; |
|
39 | + $g1 = (int)$g[ 1 ]; |
|
40 | + $g2 = (int)$g[ 2 ]; |
|
41 | + $g3 = (int)$g[ 3 ]; |
|
42 | + $g4 = (int)$g[ 4 ]; |
|
43 | + $g5 = (int)$g[ 5 ]; |
|
44 | + $g6 = (int)$g[ 6 ]; |
|
45 | + $g7 = (int)$g[ 7 ]; |
|
46 | + $g8 = (int)$g[ 8 ]; |
|
47 | + $g9 = (int)$g[ 9 ]; |
|
48 | 48 | $b = -$b; |
49 | - $x0 = ($f0 ^ $g0) & $b; |
|
50 | - $x1 = ($f1 ^ $g1) & $b; |
|
51 | - $x2 = ($f2 ^ $g2) & $b; |
|
52 | - $x3 = ($f3 ^ $g3) & $b; |
|
53 | - $x4 = ($f4 ^ $g4) & $b; |
|
54 | - $x5 = ($f5 ^ $g5) & $b; |
|
55 | - $x6 = ($f6 ^ $g6) & $b; |
|
56 | - $x7 = ($f7 ^ $g7) & $b; |
|
57 | - $x8 = ($f8 ^ $g8) & $b; |
|
58 | - $x9 = ($f9 ^ $g9) & $b; |
|
59 | - $f[0] = $f0 ^ $x0; |
|
60 | - $f[1] = $f1 ^ $x1; |
|
61 | - $f[2] = $f2 ^ $x2; |
|
62 | - $f[3] = $f3 ^ $x3; |
|
63 | - $f[4] = $f4 ^ $x4; |
|
64 | - $f[5] = $f5 ^ $x5; |
|
65 | - $f[6] = $f6 ^ $x6; |
|
66 | - $f[7] = $f7 ^ $x7; |
|
67 | - $f[8] = $f8 ^ $x8; |
|
68 | - $f[9] = $f9 ^ $x9; |
|
69 | - $g[0] = $g0 ^ $x0; |
|
70 | - $g[1] = $g1 ^ $x1; |
|
71 | - $g[2] = $g2 ^ $x2; |
|
72 | - $g[3] = $g3 ^ $x3; |
|
73 | - $g[4] = $g4 ^ $x4; |
|
74 | - $g[5] = $g5 ^ $x5; |
|
75 | - $g[6] = $g6 ^ $x6; |
|
76 | - $g[7] = $g7 ^ $x7; |
|
77 | - $g[8] = $g8 ^ $x8; |
|
78 | - $g[9] = $g9 ^ $x9; |
|
49 | + $x0 = ( $f0 ^ $g0 ) & $b; |
|
50 | + $x1 = ( $f1 ^ $g1 ) & $b; |
|
51 | + $x2 = ( $f2 ^ $g2 ) & $b; |
|
52 | + $x3 = ( $f3 ^ $g3 ) & $b; |
|
53 | + $x4 = ( $f4 ^ $g4 ) & $b; |
|
54 | + $x5 = ( $f5 ^ $g5 ) & $b; |
|
55 | + $x6 = ( $f6 ^ $g6 ) & $b; |
|
56 | + $x7 = ( $f7 ^ $g7 ) & $b; |
|
57 | + $x8 = ( $f8 ^ $g8 ) & $b; |
|
58 | + $x9 = ( $f9 ^ $g9 ) & $b; |
|
59 | + $f[ 0 ] = $f0 ^ $x0; |
|
60 | + $f[ 1 ] = $f1 ^ $x1; |
|
61 | + $f[ 2 ] = $f2 ^ $x2; |
|
62 | + $f[ 3 ] = $f3 ^ $x3; |
|
63 | + $f[ 4 ] = $f4 ^ $x4; |
|
64 | + $f[ 5 ] = $f5 ^ $x5; |
|
65 | + $f[ 6 ] = $f6 ^ $x6; |
|
66 | + $f[ 7 ] = $f7 ^ $x7; |
|
67 | + $f[ 8 ] = $f8 ^ $x8; |
|
68 | + $f[ 9 ] = $f9 ^ $x9; |
|
69 | + $g[ 0 ] = $g0 ^ $x0; |
|
70 | + $g[ 1 ] = $g1 ^ $x1; |
|
71 | + $g[ 2 ] = $g2 ^ $x2; |
|
72 | + $g[ 3 ] = $g3 ^ $x3; |
|
73 | + $g[ 4 ] = $g4 ^ $x4; |
|
74 | + $g[ 5 ] = $g5 ^ $x5; |
|
75 | + $g[ 6 ] = $g6 ^ $x6; |
|
76 | + $g[ 7 ] = $g7 ^ $x7; |
|
77 | + $g[ 8 ] = $g8 ^ $x8; |
|
78 | + $g[ 9 ] = $g9 ^ $x9; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,67 +84,67 @@ discard block |
||
84 | 84 | * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
85 | 85 | * @return ParagonIE_Sodium_Core_Curve25519_Fe |
86 | 86 | */ |
87 | - public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
87 | + public static function fe_mul121666( ParagonIE_Sodium_Core_Curve25519_Fe $f ) |
|
88 | 88 | { |
89 | 89 | $h = array( |
90 | - self::mul((int) $f[0], 121666, 17), |
|
91 | - self::mul((int) $f[1], 121666, 17), |
|
92 | - self::mul((int) $f[2], 121666, 17), |
|
93 | - self::mul((int) $f[3], 121666, 17), |
|
94 | - self::mul((int) $f[4], 121666, 17), |
|
95 | - self::mul((int) $f[5], 121666, 17), |
|
96 | - self::mul((int) $f[6], 121666, 17), |
|
97 | - self::mul((int) $f[7], 121666, 17), |
|
98 | - self::mul((int) $f[8], 121666, 17), |
|
99 | - self::mul((int) $f[9], 121666, 17) |
|
90 | + self::mul( (int)$f[ 0 ], 121666, 17 ), |
|
91 | + self::mul( (int)$f[ 1 ], 121666, 17 ), |
|
92 | + self::mul( (int)$f[ 2 ], 121666, 17 ), |
|
93 | + self::mul( (int)$f[ 3 ], 121666, 17 ), |
|
94 | + self::mul( (int)$f[ 4 ], 121666, 17 ), |
|
95 | + self::mul( (int)$f[ 5 ], 121666, 17 ), |
|
96 | + self::mul( (int)$f[ 6 ], 121666, 17 ), |
|
97 | + self::mul( (int)$f[ 7 ], 121666, 17 ), |
|
98 | + self::mul( (int)$f[ 8 ], 121666, 17 ), |
|
99 | + self::mul( (int)$f[ 9 ], 121666, 17 ) |
|
100 | 100 | ); |
101 | 101 | |
102 | 102 | /** @var int $carry9 */ |
103 | - $carry9 = ($h[9] + (1 << 24)) >> 25; |
|
104 | - $h[0] += self::mul($carry9, 19, 5); |
|
105 | - $h[9] -= $carry9 << 25; |
|
103 | + $carry9 = ( $h[ 9 ] + ( 1 << 24 ) ) >> 25; |
|
104 | + $h[ 0 ] += self::mul( $carry9, 19, 5 ); |
|
105 | + $h[ 9 ] -= $carry9 << 25; |
|
106 | 106 | /** @var int $carry1 */ |
107 | - $carry1 = ($h[1] + (1 << 24)) >> 25; |
|
108 | - $h[2] += $carry1; |
|
109 | - $h[1] -= $carry1 << 25; |
|
107 | + $carry1 = ( $h[ 1 ] + ( 1 << 24 ) ) >> 25; |
|
108 | + $h[ 2 ] += $carry1; |
|
109 | + $h[ 1 ] -= $carry1 << 25; |
|
110 | 110 | /** @var int $carry3 */ |
111 | - $carry3 = ($h[3] + (1 << 24)) >> 25; |
|
112 | - $h[4] += $carry3; |
|
113 | - $h[3] -= $carry3 << 25; |
|
111 | + $carry3 = ( $h[ 3 ] + ( 1 << 24 ) ) >> 25; |
|
112 | + $h[ 4 ] += $carry3; |
|
113 | + $h[ 3 ] -= $carry3 << 25; |
|
114 | 114 | /** @var int $carry5 */ |
115 | - $carry5 = ($h[5] + (1 << 24)) >> 25; |
|
116 | - $h[6] += $carry5; |
|
117 | - $h[5] -= $carry5 << 25; |
|
115 | + $carry5 = ( $h[ 5 ] + ( 1 << 24 ) ) >> 25; |
|
116 | + $h[ 6 ] += $carry5; |
|
117 | + $h[ 5 ] -= $carry5 << 25; |
|
118 | 118 | /** @var int $carry7 */ |
119 | - $carry7 = ($h[7] + (1 << 24)) >> 25; |
|
120 | - $h[8] += $carry7; |
|
121 | - $h[7] -= $carry7 << 25; |
|
119 | + $carry7 = ( $h[ 7 ] + ( 1 << 24 ) ) >> 25; |
|
120 | + $h[ 8 ] += $carry7; |
|
121 | + $h[ 7 ] -= $carry7 << 25; |
|
122 | 122 | |
123 | 123 | /** @var int $carry0 */ |
124 | - $carry0 = ($h[0] + (1 << 25)) >> 26; |
|
125 | - $h[1] += $carry0; |
|
126 | - $h[0] -= $carry0 << 26; |
|
124 | + $carry0 = ( $h[ 0 ] + ( 1 << 25 ) ) >> 26; |
|
125 | + $h[ 1 ] += $carry0; |
|
126 | + $h[ 0 ] -= $carry0 << 26; |
|
127 | 127 | /** @var int $carry2 */ |
128 | - $carry2 = ($h[2] + (1 << 25)) >> 26; |
|
129 | - $h[3] += $carry2; |
|
130 | - $h[2] -= $carry2 << 26; |
|
128 | + $carry2 = ( $h[ 2 ] + ( 1 << 25 ) ) >> 26; |
|
129 | + $h[ 3 ] += $carry2; |
|
130 | + $h[ 2 ] -= $carry2 << 26; |
|
131 | 131 | /** @var int $carry4 */ |
132 | - $carry4 = ($h[4] + (1 << 25)) >> 26; |
|
133 | - $h[5] += $carry4; |
|
134 | - $h[4] -= $carry4 << 26; |
|
132 | + $carry4 = ( $h[ 4 ] + ( 1 << 25 ) ) >> 26; |
|
133 | + $h[ 5 ] += $carry4; |
|
134 | + $h[ 4 ] -= $carry4 << 26; |
|
135 | 135 | /** @var int $carry6 */ |
136 | - $carry6 = ($h[6] + (1 << 25)) >> 26; |
|
137 | - $h[7] += $carry6; |
|
138 | - $h[6] -= $carry6 << 26; |
|
136 | + $carry6 = ( $h[ 6 ] + ( 1 << 25 ) ) >> 26; |
|
137 | + $h[ 7 ] += $carry6; |
|
138 | + $h[ 6 ] -= $carry6 << 26; |
|
139 | 139 | /** @var int $carry8 */ |
140 | - $carry8 = ($h[8] + (1 << 25)) >> 26; |
|
141 | - $h[9] += $carry8; |
|
142 | - $h[8] -= $carry8 << 26; |
|
140 | + $carry8 = ( $h[ 8 ] + ( 1 << 25 ) ) >> 26; |
|
141 | + $h[ 9 ] += $carry8; |
|
142 | + $h[ 8 ] -= $carry8 << 26; |
|
143 | 143 | |
144 | - foreach ($h as $i => $value) { |
|
145 | - $h[$i] = (int) $value; |
|
144 | + foreach ( $h as $i => $value ) { |
|
145 | + $h[ $i ] = (int)$value; |
|
146 | 146 | } |
147 | - return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); |
|
147 | + return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( $h ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -158,27 +158,27 @@ discard block |
||
158 | 158 | * @throws SodiumException |
159 | 159 | * @throws TypeError |
160 | 160 | */ |
161 | - public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
161 | + public static function crypto_scalarmult_curve25519_ref10( $n, $p ) |
|
162 | 162 | { |
163 | 163 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
164 | 164 | $e = '' . $n; |
165 | 165 | # e[0] &= 248; |
166 | - $e[0] = self::intToChr( |
|
167 | - self::chrToInt($e[0]) & 248 |
|
166 | + $e[ 0 ] = self::intToChr( |
|
167 | + self::chrToInt( $e[ 0 ] ) & 248 |
|
168 | 168 | ); |
169 | 169 | # e[31] &= 127; |
170 | 170 | # e[31] |= 64; |
171 | - $e[31] = self::intToChr( |
|
172 | - (self::chrToInt($e[31]) & 127) | 64 |
|
171 | + $e[ 31 ] = self::intToChr( |
|
172 | + ( self::chrToInt( $e[ 31 ] ) & 127 ) | 64 |
|
173 | 173 | ); |
174 | 174 | # fe_frombytes(x1,p); |
175 | - $x1 = self::fe_frombytes($p); |
|
175 | + $x1 = self::fe_frombytes( $p ); |
|
176 | 176 | # fe_1(x2); |
177 | 177 | $x2 = self::fe_1(); |
178 | 178 | # fe_0(z2); |
179 | 179 | $z2 = self::fe_0(); |
180 | 180 | # fe_copy(x3,x1); |
181 | - $x3 = self::fe_copy($x1); |
|
181 | + $x3 = self::fe_copy( $x1 ); |
|
182 | 182 | # fe_1(z3); |
183 | 183 | $z3 = self::fe_1(); |
184 | 184 | |
@@ -187,89 +187,89 @@ discard block |
||
187 | 187 | $swap = 0; |
188 | 188 | |
189 | 189 | # for (pos = 254;pos >= 0;--pos) { |
190 | - for ($pos = 254; $pos >= 0; --$pos) { |
|
190 | + for ( $pos = 254; $pos >= 0; --$pos ) { |
|
191 | 191 | # b = e[pos / 8] >> (pos & 7); |
192 | 192 | /** @var int $b */ |
193 | 193 | $b = self::chrToInt( |
194 | - $e[(int) floor($pos / 8)] |
|
195 | - ) >> ($pos & 7); |
|
194 | + $e[ (int)floor( $pos / 8 ) ] |
|
195 | + ) >> ( $pos & 7 ); |
|
196 | 196 | # b &= 1; |
197 | 197 | $b &= 1; |
198 | 198 | # swap ^= b; |
199 | 199 | $swap ^= $b; |
200 | 200 | # fe_cswap(x2,x3,swap); |
201 | - self::fe_cswap($x2, $x3, $swap); |
|
201 | + self::fe_cswap( $x2, $x3, $swap ); |
|
202 | 202 | # fe_cswap(z2,z3,swap); |
203 | - self::fe_cswap($z2, $z3, $swap); |
|
203 | + self::fe_cswap( $z2, $z3, $swap ); |
|
204 | 204 | # swap = b; |
205 | 205 | $swap = $b; |
206 | 206 | # fe_sub(tmp0,x3,z3); |
207 | - $tmp0 = self::fe_sub($x3, $z3); |
|
207 | + $tmp0 = self::fe_sub( $x3, $z3 ); |
|
208 | 208 | # fe_sub(tmp1,x2,z2); |
209 | - $tmp1 = self::fe_sub($x2, $z2); |
|
209 | + $tmp1 = self::fe_sub( $x2, $z2 ); |
|
210 | 210 | |
211 | 211 | # fe_add(x2,x2,z2); |
212 | - $x2 = self::fe_add($x2, $z2); |
|
212 | + $x2 = self::fe_add( $x2, $z2 ); |
|
213 | 213 | |
214 | 214 | # fe_add(z2,x3,z3); |
215 | - $z2 = self::fe_add($x3, $z3); |
|
215 | + $z2 = self::fe_add( $x3, $z3 ); |
|
216 | 216 | |
217 | 217 | # fe_mul(z3,tmp0,x2); |
218 | - $z3 = self::fe_mul($tmp0, $x2); |
|
218 | + $z3 = self::fe_mul( $tmp0, $x2 ); |
|
219 | 219 | |
220 | 220 | # fe_mul(z2,z2,tmp1); |
221 | - $z2 = self::fe_mul($z2, $tmp1); |
|
221 | + $z2 = self::fe_mul( $z2, $tmp1 ); |
|
222 | 222 | |
223 | 223 | # fe_sq(tmp0,tmp1); |
224 | - $tmp0 = self::fe_sq($tmp1); |
|
224 | + $tmp0 = self::fe_sq( $tmp1 ); |
|
225 | 225 | |
226 | 226 | # fe_sq(tmp1,x2); |
227 | - $tmp1 = self::fe_sq($x2); |
|
227 | + $tmp1 = self::fe_sq( $x2 ); |
|
228 | 228 | |
229 | 229 | # fe_add(x3,z3,z2); |
230 | - $x3 = self::fe_add($z3, $z2); |
|
230 | + $x3 = self::fe_add( $z3, $z2 ); |
|
231 | 231 | |
232 | 232 | # fe_sub(z2,z3,z2); |
233 | - $z2 = self::fe_sub($z3, $z2); |
|
233 | + $z2 = self::fe_sub( $z3, $z2 ); |
|
234 | 234 | |
235 | 235 | # fe_mul(x2,tmp1,tmp0); |
236 | - $x2 = self::fe_mul($tmp1, $tmp0); |
|
236 | + $x2 = self::fe_mul( $tmp1, $tmp0 ); |
|
237 | 237 | |
238 | 238 | # fe_sub(tmp1,tmp1,tmp0); |
239 | - $tmp1 = self::fe_sub($tmp1, $tmp0); |
|
239 | + $tmp1 = self::fe_sub( $tmp1, $tmp0 ); |
|
240 | 240 | |
241 | 241 | # fe_sq(z2,z2); |
242 | - $z2 = self::fe_sq($z2); |
|
242 | + $z2 = self::fe_sq( $z2 ); |
|
243 | 243 | |
244 | 244 | # fe_mul121666(z3,tmp1); |
245 | - $z3 = self::fe_mul121666($tmp1); |
|
245 | + $z3 = self::fe_mul121666( $tmp1 ); |
|
246 | 246 | |
247 | 247 | # fe_sq(x3,x3); |
248 | - $x3 = self::fe_sq($x3); |
|
248 | + $x3 = self::fe_sq( $x3 ); |
|
249 | 249 | |
250 | 250 | # fe_add(tmp0,tmp0,z3); |
251 | - $tmp0 = self::fe_add($tmp0, $z3); |
|
251 | + $tmp0 = self::fe_add( $tmp0, $z3 ); |
|
252 | 252 | |
253 | 253 | # fe_mul(z3,x1,z2); |
254 | - $z3 = self::fe_mul($x1, $z2); |
|
254 | + $z3 = self::fe_mul( $x1, $z2 ); |
|
255 | 255 | |
256 | 256 | # fe_mul(z2,tmp1,tmp0); |
257 | - $z2 = self::fe_mul($tmp1, $tmp0); |
|
257 | + $z2 = self::fe_mul( $tmp1, $tmp0 ); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | # fe_cswap(x2,x3,swap); |
261 | - self::fe_cswap($x2, $x3, $swap); |
|
261 | + self::fe_cswap( $x2, $x3, $swap ); |
|
262 | 262 | |
263 | 263 | # fe_cswap(z2,z3,swap); |
264 | - self::fe_cswap($z2, $z3, $swap); |
|
264 | + self::fe_cswap( $z2, $z3, $swap ); |
|
265 | 265 | |
266 | 266 | # fe_invert(z2,z2); |
267 | - $z2 = self::fe_invert($z2); |
|
267 | + $z2 = self::fe_invert( $z2 ); |
|
268 | 268 | |
269 | 269 | # fe_mul(x2,x2,z2); |
270 | - $x2 = self::fe_mul($x2, $z2); |
|
270 | + $x2 = self::fe_mul( $x2, $z2 ); |
|
271 | 271 | # fe_tobytes(q,x2); |
272 | - return self::fe_tobytes($x2); |
|
272 | + return self::fe_tobytes( $x2 ); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY, |
284 | 284 | ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ |
285 | 285 | ) { |
286 | - $tempX = self::fe_add($edwardsZ, $edwardsY); |
|
287 | - $tempZ = self::fe_sub($edwardsZ, $edwardsY); |
|
288 | - $tempZ = self::fe_invert($tempZ); |
|
289 | - return self::fe_mul($tempX, $tempZ); |
|
286 | + $tempX = self::fe_add( $edwardsZ, $edwardsY ); |
|
287 | + $tempZ = self::fe_sub( $edwardsZ, $edwardsY ); |
|
288 | + $tempZ = self::fe_invert( $tempZ ); |
|
289 | + return self::fe_mul( $tempX, $tempZ ); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -297,31 +297,31 @@ discard block |
||
297 | 297 | * @throws SodiumException |
298 | 298 | * @throws TypeError |
299 | 299 | */ |
300 | - public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
300 | + public static function crypto_scalarmult_curve25519_ref10_base( $n ) |
|
301 | 301 | { |
302 | 302 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
303 | 303 | $e = '' . $n; |
304 | 304 | |
305 | 305 | # e[0] &= 248; |
306 | - $e[0] = self::intToChr( |
|
307 | - self::chrToInt($e[0]) & 248 |
|
306 | + $e[ 0 ] = self::intToChr( |
|
307 | + self::chrToInt( $e[ 0 ] ) & 248 |
|
308 | 308 | ); |
309 | 309 | |
310 | 310 | # e[31] &= 127; |
311 | 311 | # e[31] |= 64; |
312 | - $e[31] = self::intToChr( |
|
313 | - (self::chrToInt($e[31]) & 127) | 64 |
|
312 | + $e[ 31 ] = self::intToChr( |
|
313 | + ( self::chrToInt( $e[ 31 ] ) & 127 ) | 64 |
|
314 | 314 | ); |
315 | 315 | |
316 | - $A = self::ge_scalarmult_base($e); |
|
316 | + $A = self::ge_scalarmult_base( $e ); |
|
317 | 317 | if ( |
318 | - !($A->Y instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
318 | + ! ( $A->Y instanceof ParagonIE_Sodium_Core_Curve25519_Fe ) |
|
319 | 319 | || |
320 | - !($A->Z instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
320 | + ! ( $A->Z instanceof ParagonIE_Sodium_Core_Curve25519_Fe ) |
|
321 | 321 | ) { |
322 | - throw new TypeError('Null points encountered'); |
|
322 | + throw new TypeError( 'Null points encountered' ); |
|
323 | 323 | } |
324 | - $pk = self::edwards_to_montgomery($A->Y, $A->Z); |
|
325 | - return self::fe_tobytes($pk); |
|
324 | + $pk = self::edwards_to_montgomery( $A->Y, $A->Z ); |
|
325 | + return self::fe_tobytes( $pk ); |
|
326 | 326 | } |
327 | 327 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_Poly1305', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_Poly1305', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -20,18 +20,18 @@ discard block |
||
20 | 20 | * @throws SodiumException |
21 | 21 | * @throws TypeError |
22 | 22 | */ |
23 | - public static function onetimeauth($m, $key) |
|
23 | + public static function onetimeauth( $m, $key ) |
|
24 | 24 | { |
25 | - if (self::strlen($key) < 32) { |
|
25 | + if ( self::strlen( $key ) < 32 ) { |
|
26 | 26 | throw new InvalidArgumentException( |
27 | 27 | 'Key must be 32 bytes long.' |
28 | 28 | ); |
29 | 29 | } |
30 | 30 | $state = new ParagonIE_Sodium_Core_Poly1305_State( |
31 | - self::substr($key, 0, 32) |
|
31 | + self::substr( $key, 0, 32 ) |
|
32 | 32 | ); |
33 | 33 | return $state |
34 | - ->update($m) |
|
34 | + ->update( $m ) |
|
35 | 35 | ->finish(); |
36 | 36 | } |
37 | 37 | |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | * @throws SodiumException |
46 | 46 | * @throws TypeError |
47 | 47 | */ |
48 | - public static function onetimeauth_verify($mac, $m, $key) |
|
48 | + public static function onetimeauth_verify( $mac, $m, $key ) |
|
49 | 49 | { |
50 | - if (self::strlen($key) < 32) { |
|
50 | + if ( self::strlen( $key ) < 32 ) { |
|
51 | 51 | throw new InvalidArgumentException( |
52 | 52 | 'Key must be 32 bytes long.' |
53 | 53 | ); |
54 | 54 | } |
55 | 55 | $state = new ParagonIE_Sodium_Core_Poly1305_State( |
56 | - self::substr($key, 0, 32) |
|
56 | + self::substr( $key, 0, 32 ) |
|
57 | 57 | ); |
58 | 58 | $calc = $state |
59 | - ->update($m) |
|
59 | + ->update( $m ) |
|
60 | 60 | ->finish(); |
61 | - return self::verify_16($calc, $mac); |
|
61 | + return self::verify_16( $calc, $mac ); |
|
62 | 62 | } |
63 | 63 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_XSalsa20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_XSalsa20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | * @throws SodiumException |
22 | 22 | * @throws TypeError |
23 | 23 | */ |
24 | - public static function xsalsa20($len, $nonce, $key) |
|
24 | + public static function xsalsa20( $len, $nonce, $key ) |
|
25 | 25 | { |
26 | 26 | $ret = self::salsa20( |
27 | 27 | $len, |
28 | - self::substr($nonce, 16, 8), |
|
29 | - self::hsalsa20($nonce, $key) |
|
28 | + self::substr( $nonce, 16, 8 ), |
|
29 | + self::hsalsa20( $nonce, $key ) |
|
30 | 30 | ); |
31 | 31 | return $ret; |
32 | 32 | } |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | * @throws SodiumException |
44 | 44 | * @throws TypeError |
45 | 45 | */ |
46 | - public static function xsalsa20_xor($message, $nonce, $key) |
|
46 | + public static function xsalsa20_xor( $message, $nonce, $key ) |
|
47 | 47 | { |
48 | 48 | return self::xorStrings( |
49 | 49 | $message, |
50 | 50 | self::xsalsa20( |
51 | - self::strlen($message), |
|
51 | + self::strlen( $message ), |
|
52 | 52 | $nonce, |
53 | 53 | $key |
54 | 54 | ) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_ChaCha20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_ChaCha20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | * @param int $n |
19 | 19 | * @return int |
20 | 20 | */ |
21 | - public static function rotate($v, $n) |
|
21 | + public static function rotate( $v, $n ) |
|
22 | 22 | { |
23 | 23 | $v &= 0xffffffff; |
24 | 24 | $n &= 31; |
25 | - return (int) ( |
|
25 | + return (int)( |
|
26 | 26 | 0xffffffff & ( |
27 | - ($v << $n) |
|
27 | + ( $v << $n ) |
|
28 | 28 | | |
29 | - ($v >> (32 - $n)) |
|
29 | + ( $v >> ( 32 - $n ) ) |
|
30 | 30 | ) |
31 | 31 | ); |
32 | 32 | } |
@@ -42,28 +42,28 @@ discard block |
||
42 | 42 | * @param int $d |
43 | 43 | * @return array<int, int> |
44 | 44 | */ |
45 | - protected static function quarterRound($a, $b, $c, $d) |
|
45 | + protected static function quarterRound( $a, $b, $c, $d ) |
|
46 | 46 | { |
47 | 47 | # a = PLUS(a,b); d = ROTATE(XOR(d,a),16); |
48 | 48 | /** @var int $a */ |
49 | - $a = ($a + $b) & 0xffffffff; |
|
50 | - $d = self::rotate($d ^ $a, 16); |
|
49 | + $a = ( $a + $b ) & 0xffffffff; |
|
50 | + $d = self::rotate( $d ^ $a, 16 ); |
|
51 | 51 | |
52 | 52 | # c = PLUS(c,d); b = ROTATE(XOR(b,c),12); |
53 | 53 | /** @var int $c */ |
54 | - $c = ($c + $d) & 0xffffffff; |
|
55 | - $b = self::rotate($b ^ $c, 12); |
|
54 | + $c = ( $c + $d ) & 0xffffffff; |
|
55 | + $b = self::rotate( $b ^ $c, 12 ); |
|
56 | 56 | |
57 | 57 | # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); |
58 | 58 | /** @var int $a */ |
59 | - $a = ($a + $b) & 0xffffffff; |
|
60 | - $d = self::rotate($d ^ $a, 8); |
|
59 | + $a = ( $a + $b ) & 0xffffffff; |
|
60 | + $d = self::rotate( $d ^ $a, 8 ); |
|
61 | 61 | |
62 | 62 | # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); |
63 | 63 | /** @var int $c */ |
64 | - $c = ($c + $d) & 0xffffffff; |
|
65 | - $b = self::rotate($b ^ $c, 7); |
|
66 | - return array((int) $a, (int) $b, (int) $c, (int) $d); |
|
64 | + $c = ( $c + $d ) & 0xffffffff; |
|
65 | + $b = self::rotate( $b ^ $c, 7 ); |
|
66 | + return array( (int)$a, (int)$b, (int)$c, (int)$d ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx, |
81 | 81 | $message = '' |
82 | 82 | ) { |
83 | - $bytes = self::strlen($message); |
|
83 | + $bytes = self::strlen( $message ); |
|
84 | 84 | |
85 | 85 | /* |
86 | 86 | j0 = ctx->input[0]; |
@@ -100,71 +100,71 @@ discard block |
||
100 | 100 | j14 = ctx->input[14]; |
101 | 101 | j15 = ctx->input[15]; |
102 | 102 | */ |
103 | - $j0 = (int) $ctx[0]; |
|
104 | - $j1 = (int) $ctx[1]; |
|
105 | - $j2 = (int) $ctx[2]; |
|
106 | - $j3 = (int) $ctx[3]; |
|
107 | - $j4 = (int) $ctx[4]; |
|
108 | - $j5 = (int) $ctx[5]; |
|
109 | - $j6 = (int) $ctx[6]; |
|
110 | - $j7 = (int) $ctx[7]; |
|
111 | - $j8 = (int) $ctx[8]; |
|
112 | - $j9 = (int) $ctx[9]; |
|
113 | - $j10 = (int) $ctx[10]; |
|
114 | - $j11 = (int) $ctx[11]; |
|
115 | - $j12 = (int) $ctx[12]; |
|
116 | - $j13 = (int) $ctx[13]; |
|
117 | - $j14 = (int) $ctx[14]; |
|
118 | - $j15 = (int) $ctx[15]; |
|
103 | + $j0 = (int)$ctx[ 0 ]; |
|
104 | + $j1 = (int)$ctx[ 1 ]; |
|
105 | + $j2 = (int)$ctx[ 2 ]; |
|
106 | + $j3 = (int)$ctx[ 3 ]; |
|
107 | + $j4 = (int)$ctx[ 4 ]; |
|
108 | + $j5 = (int)$ctx[ 5 ]; |
|
109 | + $j6 = (int)$ctx[ 6 ]; |
|
110 | + $j7 = (int)$ctx[ 7 ]; |
|
111 | + $j8 = (int)$ctx[ 8 ]; |
|
112 | + $j9 = (int)$ctx[ 9 ]; |
|
113 | + $j10 = (int)$ctx[ 10 ]; |
|
114 | + $j11 = (int)$ctx[ 11 ]; |
|
115 | + $j12 = (int)$ctx[ 12 ]; |
|
116 | + $j13 = (int)$ctx[ 13 ]; |
|
117 | + $j14 = (int)$ctx[ 14 ]; |
|
118 | + $j15 = (int)$ctx[ 15 ]; |
|
119 | 119 | |
120 | 120 | $c = ''; |
121 | - for (;;) { |
|
122 | - if ($bytes < 64) { |
|
123 | - $message .= str_repeat("\x00", 64 - $bytes); |
|
121 | + for ( ;; ) { |
|
122 | + if ( $bytes < 64 ) { |
|
123 | + $message .= str_repeat( "\x00", 64 - $bytes ); |
|
124 | 124 | } |
125 | 125 | |
126 | - $x0 = (int) $j0; |
|
127 | - $x1 = (int) $j1; |
|
128 | - $x2 = (int) $j2; |
|
129 | - $x3 = (int) $j3; |
|
130 | - $x4 = (int) $j4; |
|
131 | - $x5 = (int) $j5; |
|
132 | - $x6 = (int) $j6; |
|
133 | - $x7 = (int) $j7; |
|
134 | - $x8 = (int) $j8; |
|
135 | - $x9 = (int) $j9; |
|
136 | - $x10 = (int) $j10; |
|
137 | - $x11 = (int) $j11; |
|
138 | - $x12 = (int) $j12; |
|
139 | - $x13 = (int) $j13; |
|
140 | - $x14 = (int) $j14; |
|
141 | - $x15 = (int) $j15; |
|
126 | + $x0 = (int)$j0; |
|
127 | + $x1 = (int)$j1; |
|
128 | + $x2 = (int)$j2; |
|
129 | + $x3 = (int)$j3; |
|
130 | + $x4 = (int)$j4; |
|
131 | + $x5 = (int)$j5; |
|
132 | + $x6 = (int)$j6; |
|
133 | + $x7 = (int)$j7; |
|
134 | + $x8 = (int)$j8; |
|
135 | + $x9 = (int)$j9; |
|
136 | + $x10 = (int)$j10; |
|
137 | + $x11 = (int)$j11; |
|
138 | + $x12 = (int)$j12; |
|
139 | + $x13 = (int)$j13; |
|
140 | + $x14 = (int)$j14; |
|
141 | + $x15 = (int)$j15; |
|
142 | 142 | |
143 | 143 | # for (i = 20; i > 0; i -= 2) { |
144 | - for ($i = 20; $i > 0; $i -= 2) { |
|
144 | + for ( $i = 20; $i > 0; $i -= 2 ) { |
|
145 | 145 | # QUARTERROUND( x0, x4, x8, x12) |
146 | - list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
146 | + list( $x0, $x4, $x8, $x12 ) = self::quarterRound( $x0, $x4, $x8, $x12 ); |
|
147 | 147 | |
148 | 148 | # QUARTERROUND( x1, x5, x9, x13) |
149 | - list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
149 | + list( $x1, $x5, $x9, $x13 ) = self::quarterRound( $x1, $x5, $x9, $x13 ); |
|
150 | 150 | |
151 | 151 | # QUARTERROUND( x2, x6, x10, x14) |
152 | - list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
152 | + list( $x2, $x6, $x10, $x14 ) = self::quarterRound( $x2, $x6, $x10, $x14 ); |
|
153 | 153 | |
154 | 154 | # QUARTERROUND( x3, x7, x11, x15) |
155 | - list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
155 | + list( $x3, $x7, $x11, $x15 ) = self::quarterRound( $x3, $x7, $x11, $x15 ); |
|
156 | 156 | |
157 | 157 | # QUARTERROUND( x0, x5, x10, x15) |
158 | - list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
158 | + list( $x0, $x5, $x10, $x15 ) = self::quarterRound( $x0, $x5, $x10, $x15 ); |
|
159 | 159 | |
160 | 160 | # QUARTERROUND( x1, x6, x11, x12) |
161 | - list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
161 | + list( $x1, $x6, $x11, $x12 ) = self::quarterRound( $x1, $x6, $x11, $x12 ); |
|
162 | 162 | |
163 | 163 | # QUARTERROUND( x2, x7, x8, x13) |
164 | - list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
164 | + list( $x2, $x7, $x8, $x13 ) = self::quarterRound( $x2, $x7, $x8, $x13 ); |
|
165 | 165 | |
166 | 166 | # QUARTERROUND( x3, x4, x9, x14) |
167 | - list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
167 | + list( $x3, $x4, $x9, $x14 ) = self::quarterRound( $x3, $x4, $x9, $x14 ); |
|
168 | 168 | } |
169 | 169 | /* |
170 | 170 | x0 = PLUS(x0, j0); |
@@ -185,37 +185,37 @@ discard block |
||
185 | 185 | x15 = PLUS(x15, j15); |
186 | 186 | */ |
187 | 187 | /** @var int $x0 */ |
188 | - $x0 = ($x0 & 0xffffffff) + $j0; |
|
188 | + $x0 = ( $x0 & 0xffffffff ) + $j0; |
|
189 | 189 | /** @var int $x1 */ |
190 | - $x1 = ($x1 & 0xffffffff) + $j1; |
|
190 | + $x1 = ( $x1 & 0xffffffff ) + $j1; |
|
191 | 191 | /** @var int $x2 */ |
192 | - $x2 = ($x2 & 0xffffffff) + $j2; |
|
192 | + $x2 = ( $x2 & 0xffffffff ) + $j2; |
|
193 | 193 | /** @var int $x3 */ |
194 | - $x3 = ($x3 & 0xffffffff) + $j3; |
|
194 | + $x3 = ( $x3 & 0xffffffff ) + $j3; |
|
195 | 195 | /** @var int $x4 */ |
196 | - $x4 = ($x4 & 0xffffffff) + $j4; |
|
196 | + $x4 = ( $x4 & 0xffffffff ) + $j4; |
|
197 | 197 | /** @var int $x5 */ |
198 | - $x5 = ($x5 & 0xffffffff) + $j5; |
|
198 | + $x5 = ( $x5 & 0xffffffff ) + $j5; |
|
199 | 199 | /** @var int $x6 */ |
200 | - $x6 = ($x6 & 0xffffffff) + $j6; |
|
200 | + $x6 = ( $x6 & 0xffffffff ) + $j6; |
|
201 | 201 | /** @var int $x7 */ |
202 | - $x7 = ($x7 & 0xffffffff) + $j7; |
|
202 | + $x7 = ( $x7 & 0xffffffff ) + $j7; |
|
203 | 203 | /** @var int $x8 */ |
204 | - $x8 = ($x8 & 0xffffffff) + $j8; |
|
204 | + $x8 = ( $x8 & 0xffffffff ) + $j8; |
|
205 | 205 | /** @var int $x9 */ |
206 | - $x9 = ($x9 & 0xffffffff) + $j9; |
|
206 | + $x9 = ( $x9 & 0xffffffff ) + $j9; |
|
207 | 207 | /** @var int $x10 */ |
208 | - $x10 = ($x10 & 0xffffffff) + $j10; |
|
208 | + $x10 = ( $x10 & 0xffffffff ) + $j10; |
|
209 | 209 | /** @var int $x11 */ |
210 | - $x11 = ($x11 & 0xffffffff) + $j11; |
|
210 | + $x11 = ( $x11 & 0xffffffff ) + $j11; |
|
211 | 211 | /** @var int $x12 */ |
212 | - $x12 = ($x12 & 0xffffffff) + $j12; |
|
212 | + $x12 = ( $x12 & 0xffffffff ) + $j12; |
|
213 | 213 | /** @var int $x13 */ |
214 | - $x13 = ($x13 & 0xffffffff) + $j13; |
|
214 | + $x13 = ( $x13 & 0xffffffff ) + $j13; |
|
215 | 215 | /** @var int $x14 */ |
216 | - $x14 = ($x14 & 0xffffffff) + $j14; |
|
216 | + $x14 = ( $x14 & 0xffffffff ) + $j14; |
|
217 | 217 | /** @var int $x15 */ |
218 | - $x15 = ($x15 & 0xffffffff) + $j15; |
|
218 | + $x15 = ( $x15 & 0xffffffff ) + $j15; |
|
219 | 219 | |
220 | 220 | /* |
221 | 221 | x0 = XOR(x0, LOAD32_LE(m + 0)); |
@@ -235,22 +235,22 @@ discard block |
||
235 | 235 | x14 = XOR(x14, LOAD32_LE(m + 56)); |
236 | 236 | x15 = XOR(x15, LOAD32_LE(m + 60)); |
237 | 237 | */ |
238 | - $x0 ^= self::load_4(self::substr($message, 0, 4)); |
|
239 | - $x1 ^= self::load_4(self::substr($message, 4, 4)); |
|
240 | - $x2 ^= self::load_4(self::substr($message, 8, 4)); |
|
241 | - $x3 ^= self::load_4(self::substr($message, 12, 4)); |
|
242 | - $x4 ^= self::load_4(self::substr($message, 16, 4)); |
|
243 | - $x5 ^= self::load_4(self::substr($message, 20, 4)); |
|
244 | - $x6 ^= self::load_4(self::substr($message, 24, 4)); |
|
245 | - $x7 ^= self::load_4(self::substr($message, 28, 4)); |
|
246 | - $x8 ^= self::load_4(self::substr($message, 32, 4)); |
|
247 | - $x9 ^= self::load_4(self::substr($message, 36, 4)); |
|
248 | - $x10 ^= self::load_4(self::substr($message, 40, 4)); |
|
249 | - $x11 ^= self::load_4(self::substr($message, 44, 4)); |
|
250 | - $x12 ^= self::load_4(self::substr($message, 48, 4)); |
|
251 | - $x13 ^= self::load_4(self::substr($message, 52, 4)); |
|
252 | - $x14 ^= self::load_4(self::substr($message, 56, 4)); |
|
253 | - $x15 ^= self::load_4(self::substr($message, 60, 4)); |
|
238 | + $x0 ^= self::load_4( self::substr( $message, 0, 4 ) ); |
|
239 | + $x1 ^= self::load_4( self::substr( $message, 4, 4 ) ); |
|
240 | + $x2 ^= self::load_4( self::substr( $message, 8, 4 ) ); |
|
241 | + $x3 ^= self::load_4( self::substr( $message, 12, 4 ) ); |
|
242 | + $x4 ^= self::load_4( self::substr( $message, 16, 4 ) ); |
|
243 | + $x5 ^= self::load_4( self::substr( $message, 20, 4 ) ); |
|
244 | + $x6 ^= self::load_4( self::substr( $message, 24, 4 ) ); |
|
245 | + $x7 ^= self::load_4( self::substr( $message, 28, 4 ) ); |
|
246 | + $x8 ^= self::load_4( self::substr( $message, 32, 4 ) ); |
|
247 | + $x9 ^= self::load_4( self::substr( $message, 36, 4 ) ); |
|
248 | + $x10 ^= self::load_4( self::substr( $message, 40, 4 ) ); |
|
249 | + $x11 ^= self::load_4( self::substr( $message, 44, 4 ) ); |
|
250 | + $x12 ^= self::load_4( self::substr( $message, 48, 4 ) ); |
|
251 | + $x13 ^= self::load_4( self::substr( $message, 52, 4 ) ); |
|
252 | + $x14 ^= self::load_4( self::substr( $message, 56, 4 ) ); |
|
253 | + $x15 ^= self::load_4( self::substr( $message, 60, 4 ) ); |
|
254 | 254 | |
255 | 255 | /* |
256 | 256 | j12 = PLUSONE(j12); |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | } |
260 | 260 | */ |
261 | 261 | ++$j12; |
262 | - if ($j12 & 0xf0000000) { |
|
263 | - throw new SodiumException('Overflow'); |
|
262 | + if ( $j12 & 0xf0000000 ) { |
|
263 | + throw new SodiumException( 'Overflow' ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /* |
@@ -281,41 +281,41 @@ discard block |
||
281 | 281 | STORE32_LE(c + 56, x14); |
282 | 282 | STORE32_LE(c + 60, x15); |
283 | 283 | */ |
284 | - $block = self::store32_le((int) ($x0 & 0xffffffff)) . |
|
285 | - self::store32_le((int) ($x1 & 0xffffffff)) . |
|
286 | - self::store32_le((int) ($x2 & 0xffffffff)) . |
|
287 | - self::store32_le((int) ($x3 & 0xffffffff)) . |
|
288 | - self::store32_le((int) ($x4 & 0xffffffff)) . |
|
289 | - self::store32_le((int) ($x5 & 0xffffffff)) . |
|
290 | - self::store32_le((int) ($x6 & 0xffffffff)) . |
|
291 | - self::store32_le((int) ($x7 & 0xffffffff)) . |
|
292 | - self::store32_le((int) ($x8 & 0xffffffff)) . |
|
293 | - self::store32_le((int) ($x9 & 0xffffffff)) . |
|
294 | - self::store32_le((int) ($x10 & 0xffffffff)) . |
|
295 | - self::store32_le((int) ($x11 & 0xffffffff)) . |
|
296 | - self::store32_le((int) ($x12 & 0xffffffff)) . |
|
297 | - self::store32_le((int) ($x13 & 0xffffffff)) . |
|
298 | - self::store32_le((int) ($x14 & 0xffffffff)) . |
|
299 | - self::store32_le((int) ($x15 & 0xffffffff)); |
|
284 | + $block = self::store32_le( (int)( $x0 & 0xffffffff ) ) . |
|
285 | + self::store32_le( (int)( $x1 & 0xffffffff ) ) . |
|
286 | + self::store32_le( (int)( $x2 & 0xffffffff ) ) . |
|
287 | + self::store32_le( (int)( $x3 & 0xffffffff ) ) . |
|
288 | + self::store32_le( (int)( $x4 & 0xffffffff ) ) . |
|
289 | + self::store32_le( (int)( $x5 & 0xffffffff ) ) . |
|
290 | + self::store32_le( (int)( $x6 & 0xffffffff ) ) . |
|
291 | + self::store32_le( (int)( $x7 & 0xffffffff ) ) . |
|
292 | + self::store32_le( (int)( $x8 & 0xffffffff ) ) . |
|
293 | + self::store32_le( (int)( $x9 & 0xffffffff ) ) . |
|
294 | + self::store32_le( (int)( $x10 & 0xffffffff ) ) . |
|
295 | + self::store32_le( (int)( $x11 & 0xffffffff ) ) . |
|
296 | + self::store32_le( (int)( $x12 & 0xffffffff ) ) . |
|
297 | + self::store32_le( (int)( $x13 & 0xffffffff ) ) . |
|
298 | + self::store32_le( (int)( $x14 & 0xffffffff ) ) . |
|
299 | + self::store32_le( (int)( $x15 & 0xffffffff ) ); |
|
300 | 300 | |
301 | 301 | /* Partial block */ |
302 | - if ($bytes < 64) { |
|
303 | - $c .= self::substr($block, 0, $bytes); |
|
302 | + if ( $bytes < 64 ) { |
|
303 | + $c .= self::substr( $block, 0, $bytes ); |
|
304 | 304 | break; |
305 | 305 | } |
306 | 306 | |
307 | 307 | /* Full block */ |
308 | 308 | $c .= $block; |
309 | 309 | $bytes -= 64; |
310 | - if ($bytes <= 0) { |
|
310 | + if ( $bytes <= 0 ) { |
|
311 | 311 | break; |
312 | 312 | } |
313 | - $message = self::substr($message, 64); |
|
313 | + $message = self::substr( $message, 64 ); |
|
314 | 314 | } |
315 | 315 | /* end for(;;) loop */ |
316 | 316 | |
317 | - $ctx[12] = $j12; |
|
318 | - $ctx[13] = $j13; |
|
317 | + $ctx[ 12 ] = $j12; |
|
318 | + $ctx[ 13 ] = $j13; |
|
319 | 319 | return $c; |
320 | 320 | } |
321 | 321 | |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | * @throws SodiumException |
330 | 330 | * @throws TypeError |
331 | 331 | */ |
332 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
332 | + public static function stream( $len = 64, $nonce = '', $key = '' ) |
|
333 | 333 | { |
334 | 334 | return self::encryptBytes( |
335 | - new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce), |
|
336 | - str_repeat("\x00", $len) |
|
335 | + new ParagonIE_Sodium_Core_ChaCha20_Ctx( $key, $nonce ), |
|
336 | + str_repeat( "\x00", $len ) |
|
337 | 337 | ); |
338 | 338 | } |
339 | 339 | |
@@ -347,11 +347,11 @@ discard block |
||
347 | 347 | * @throws SodiumException |
348 | 348 | * @throws TypeError |
349 | 349 | */ |
350 | - public static function ietfStream($len, $nonce = '', $key = '') |
|
350 | + public static function ietfStream( $len, $nonce = '', $key = '' ) |
|
351 | 351 | { |
352 | 352 | return self::encryptBytes( |
353 | - new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce), |
|
354 | - str_repeat("\x00", $len) |
|
353 | + new ParagonIE_Sodium_Core_ChaCha20_IetfCtx( $key, $nonce ), |
|
354 | + str_repeat( "\x00", $len ) |
|
355 | 355 | ); |
356 | 356 | } |
357 | 357 | |
@@ -366,10 +366,10 @@ discard block |
||
366 | 366 | * @throws SodiumException |
367 | 367 | * @throws TypeError |
368 | 368 | */ |
369 | - public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
369 | + public static function ietfStreamXorIc( $message, $nonce = '', $key = '', $ic = '' ) |
|
370 | 370 | { |
371 | 371 | return self::encryptBytes( |
372 | - new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce, $ic), |
|
372 | + new ParagonIE_Sodium_Core_ChaCha20_IetfCtx( $key, $nonce, $ic ), |
|
373 | 373 | $message |
374 | 374 | ); |
375 | 375 | } |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | * @throws SodiumException |
386 | 386 | * @throws TypeError |
387 | 387 | */ |
388 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
388 | + public static function streamXorIc( $message, $nonce = '', $key = '', $ic = '' ) |
|
389 | 389 | { |
390 | 390 | return self::encryptBytes( |
391 | - new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce, $ic), |
|
391 | + new ParagonIE_Sodium_Core_ChaCha20_Ctx( $key, $nonce, $ic ), |
|
392 | 392 | $message |
393 | 393 | ); |
394 | 394 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_HChaCha20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_HChaCha20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -16,34 +16,34 @@ discard block |
||
16 | 16 | * @return string |
17 | 17 | * @throws TypeError |
18 | 18 | */ |
19 | - public static function hChaCha20($in = '', $key = '', $c = null) |
|
19 | + public static function hChaCha20( $in = '', $key = '', $c = null ) |
|
20 | 20 | { |
21 | 21 | $ctx = array(); |
22 | 22 | |
23 | - if ($c === null) { |
|
24 | - $ctx[0] = 0x61707865; |
|
25 | - $ctx[1] = 0x3320646e; |
|
26 | - $ctx[2] = 0x79622d32; |
|
27 | - $ctx[3] = 0x6b206574; |
|
23 | + if ( $c === null ) { |
|
24 | + $ctx[ 0 ] = 0x61707865; |
|
25 | + $ctx[ 1 ] = 0x3320646e; |
|
26 | + $ctx[ 2 ] = 0x79622d32; |
|
27 | + $ctx[ 3 ] = 0x6b206574; |
|
28 | 28 | } else { |
29 | - $ctx[0] = self::load_4(self::substr($c, 0, 4)); |
|
30 | - $ctx[1] = self::load_4(self::substr($c, 4, 4)); |
|
31 | - $ctx[2] = self::load_4(self::substr($c, 8, 4)); |
|
32 | - $ctx[3] = self::load_4(self::substr($c, 12, 4)); |
|
29 | + $ctx[ 0 ] = self::load_4( self::substr( $c, 0, 4 ) ); |
|
30 | + $ctx[ 1 ] = self::load_4( self::substr( $c, 4, 4 ) ); |
|
31 | + $ctx[ 2 ] = self::load_4( self::substr( $c, 8, 4 ) ); |
|
32 | + $ctx[ 3 ] = self::load_4( self::substr( $c, 12, 4 ) ); |
|
33 | 33 | } |
34 | - $ctx[4] = self::load_4(self::substr($key, 0, 4)); |
|
35 | - $ctx[5] = self::load_4(self::substr($key, 4, 4)); |
|
36 | - $ctx[6] = self::load_4(self::substr($key, 8, 4)); |
|
37 | - $ctx[7] = self::load_4(self::substr($key, 12, 4)); |
|
38 | - $ctx[8] = self::load_4(self::substr($key, 16, 4)); |
|
39 | - $ctx[9] = self::load_4(self::substr($key, 20, 4)); |
|
40 | - $ctx[10] = self::load_4(self::substr($key, 24, 4)); |
|
41 | - $ctx[11] = self::load_4(self::substr($key, 28, 4)); |
|
42 | - $ctx[12] = self::load_4(self::substr($in, 0, 4)); |
|
43 | - $ctx[13] = self::load_4(self::substr($in, 4, 4)); |
|
44 | - $ctx[14] = self::load_4(self::substr($in, 8, 4)); |
|
45 | - $ctx[15] = self::load_4(self::substr($in, 12, 4)); |
|
46 | - return self::hChaCha20Bytes($ctx); |
|
34 | + $ctx[ 4 ] = self::load_4( self::substr( $key, 0, 4 ) ); |
|
35 | + $ctx[ 5 ] = self::load_4( self::substr( $key, 4, 4 ) ); |
|
36 | + $ctx[ 6 ] = self::load_4( self::substr( $key, 8, 4 ) ); |
|
37 | + $ctx[ 7 ] = self::load_4( self::substr( $key, 12, 4 ) ); |
|
38 | + $ctx[ 8 ] = self::load_4( self::substr( $key, 16, 4 ) ); |
|
39 | + $ctx[ 9 ] = self::load_4( self::substr( $key, 20, 4 ) ); |
|
40 | + $ctx[ 10 ] = self::load_4( self::substr( $key, 24, 4 ) ); |
|
41 | + $ctx[ 11 ] = self::load_4( self::substr( $key, 28, 4 ) ); |
|
42 | + $ctx[ 12 ] = self::load_4( self::substr( $in, 0, 4 ) ); |
|
43 | + $ctx[ 13 ] = self::load_4( self::substr( $in, 4, 4 ) ); |
|
44 | + $ctx[ 14 ] = self::load_4( self::substr( $in, 8, 4 ) ); |
|
45 | + $ctx[ 15 ] = self::load_4( self::substr( $in, 12, 4 ) ); |
|
46 | + return self::hChaCha20Bytes( $ctx ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,58 +51,58 @@ discard block |
||
51 | 51 | * @return string |
52 | 52 | * @throws TypeError |
53 | 53 | */ |
54 | - protected static function hChaCha20Bytes(array $ctx) |
|
54 | + protected static function hChaCha20Bytes( array $ctx ) |
|
55 | 55 | { |
56 | - $x0 = (int) $ctx[0]; |
|
57 | - $x1 = (int) $ctx[1]; |
|
58 | - $x2 = (int) $ctx[2]; |
|
59 | - $x3 = (int) $ctx[3]; |
|
60 | - $x4 = (int) $ctx[4]; |
|
61 | - $x5 = (int) $ctx[5]; |
|
62 | - $x6 = (int) $ctx[6]; |
|
63 | - $x7 = (int) $ctx[7]; |
|
64 | - $x8 = (int) $ctx[8]; |
|
65 | - $x9 = (int) $ctx[9]; |
|
66 | - $x10 = (int) $ctx[10]; |
|
67 | - $x11 = (int) $ctx[11]; |
|
68 | - $x12 = (int) $ctx[12]; |
|
69 | - $x13 = (int) $ctx[13]; |
|
70 | - $x14 = (int) $ctx[14]; |
|
71 | - $x15 = (int) $ctx[15]; |
|
56 | + $x0 = (int)$ctx[ 0 ]; |
|
57 | + $x1 = (int)$ctx[ 1 ]; |
|
58 | + $x2 = (int)$ctx[ 2 ]; |
|
59 | + $x3 = (int)$ctx[ 3 ]; |
|
60 | + $x4 = (int)$ctx[ 4 ]; |
|
61 | + $x5 = (int)$ctx[ 5 ]; |
|
62 | + $x6 = (int)$ctx[ 6 ]; |
|
63 | + $x7 = (int)$ctx[ 7 ]; |
|
64 | + $x8 = (int)$ctx[ 8 ]; |
|
65 | + $x9 = (int)$ctx[ 9 ]; |
|
66 | + $x10 = (int)$ctx[ 10 ]; |
|
67 | + $x11 = (int)$ctx[ 11 ]; |
|
68 | + $x12 = (int)$ctx[ 12 ]; |
|
69 | + $x13 = (int)$ctx[ 13 ]; |
|
70 | + $x14 = (int)$ctx[ 14 ]; |
|
71 | + $x15 = (int)$ctx[ 15 ]; |
|
72 | 72 | |
73 | - for ($i = 0; $i < 10; ++$i) { |
|
73 | + for ( $i = 0; $i < 10; ++$i ) { |
|
74 | 74 | # QUARTERROUND( x0, x4, x8, x12) |
75 | - list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
75 | + list( $x0, $x4, $x8, $x12 ) = self::quarterRound( $x0, $x4, $x8, $x12 ); |
|
76 | 76 | |
77 | 77 | # QUARTERROUND( x1, x5, x9, x13) |
78 | - list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
78 | + list( $x1, $x5, $x9, $x13 ) = self::quarterRound( $x1, $x5, $x9, $x13 ); |
|
79 | 79 | |
80 | 80 | # QUARTERROUND( x2, x6, x10, x14) |
81 | - list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
81 | + list( $x2, $x6, $x10, $x14 ) = self::quarterRound( $x2, $x6, $x10, $x14 ); |
|
82 | 82 | |
83 | 83 | # QUARTERROUND( x3, x7, x11, x15) |
84 | - list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
84 | + list( $x3, $x7, $x11, $x15 ) = self::quarterRound( $x3, $x7, $x11, $x15 ); |
|
85 | 85 | |
86 | 86 | # QUARTERROUND( x0, x5, x10, x15) |
87 | - list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
87 | + list( $x0, $x5, $x10, $x15 ) = self::quarterRound( $x0, $x5, $x10, $x15 ); |
|
88 | 88 | |
89 | 89 | # QUARTERROUND( x1, x6, x11, x12) |
90 | - list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
90 | + list( $x1, $x6, $x11, $x12 ) = self::quarterRound( $x1, $x6, $x11, $x12 ); |
|
91 | 91 | |
92 | 92 | # QUARTERROUND( x2, x7, x8, x13) |
93 | - list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
93 | + list( $x2, $x7, $x8, $x13 ) = self::quarterRound( $x2, $x7, $x8, $x13 ); |
|
94 | 94 | |
95 | 95 | # QUARTERROUND( x3, x4, x9, x14) |
96 | - list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
96 | + list( $x3, $x4, $x9, $x14 ) = self::quarterRound( $x3, $x4, $x9, $x14 ); |
|
97 | 97 | } |
98 | 98 | |
99 | - return self::store32_le((int) ($x0 & 0xffffffff)) . |
|
100 | - self::store32_le((int) ($x1 & 0xffffffff)) . |
|
101 | - self::store32_le((int) ($x2 & 0xffffffff)) . |
|
102 | - self::store32_le((int) ($x3 & 0xffffffff)) . |
|
103 | - self::store32_le((int) ($x12 & 0xffffffff)) . |
|
104 | - self::store32_le((int) ($x13 & 0xffffffff)) . |
|
105 | - self::store32_le((int) ($x14 & 0xffffffff)) . |
|
106 | - self::store32_le((int) ($x15 & 0xffffffff)); |
|
99 | + return self::store32_le( (int)( $x0 & 0xffffffff ) ) . |
|
100 | + self::store32_le( (int)( $x1 & 0xffffffff ) ) . |
|
101 | + self::store32_le( (int)( $x2 & 0xffffffff ) ) . |
|
102 | + self::store32_le( (int)( $x3 & 0xffffffff ) ) . |
|
103 | + self::store32_le( (int)( $x12 & 0xffffffff ) ) . |
|
104 | + self::store32_le( (int)( $x13 & 0xffffffff ) ) . |
|
105 | + self::store32_le( (int)( $x14 & 0xffffffff ) ) . |
|
106 | + self::store32_le( (int)( $x15 & 0xffffffff ) ); |
|
107 | 107 | } |
108 | 108 | } |