Completed
Push — develop ( f0d100...266ee2 )
by J.D.
04:14
created
src/library/sodium_compat/src/Crypto32.php 1 patch
Spacing   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_Crypto32', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Crypto32', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
         $key = ''
75 75
     ) {
76 76
         /** @var int $len - Length of message (ciphertext + MAC) */
77
-        $len = ParagonIE_Sodium_Core32_Util::strlen($message);
77
+        $len = ParagonIE_Sodium_Core32_Util::strlen( $message );
78 78
 
79 79
         /** @var int  $clen - Length of ciphertext */
80 80
         $clen = $len - self::aead_chacha20poly1305_ABYTES;
81 81
 
82 82
         /** @var int $adlen - Length of associated data */
83
-        $adlen = ParagonIE_Sodium_Core32_Util::strlen($ad);
83
+        $adlen = ParagonIE_Sodium_Core32_Util::strlen( $ad );
84 84
 
85 85
         /** @var string $mac - Message authentication code */
86 86
         $mac = ParagonIE_Sodium_Core32_Util::substr(
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         );
91 91
 
92 92
         /** @var string $ciphertext - The encrypted message (sans MAC) */
93
-        $ciphertext = ParagonIE_Sodium_Core32_Util::substr($message, 0, $clen);
93
+        $ciphertext = ParagonIE_Sodium_Core32_Util::substr( $message, 0, $clen );
94 94
 
95 95
         /** @var string The first block of the chacha20 keystream, used as a poly1305 key */
96 96
         $block0 = ParagonIE_Sodium_Core32_ChaCha20::stream(
@@ -100,21 +100,21 @@  discard block
 block discarded – undo
100 100
         );
101 101
 
102 102
         /* Recalculate the Poly1305 authentication tag (MAC): */
103
-        $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0);
103
+        $state = new ParagonIE_Sodium_Core32_Poly1305_State( $block0 );
104 104
         try {
105
-            ParagonIE_Sodium_Compat::memzero($block0);
106
-        } catch (Error $ex) {
105
+            ParagonIE_Sodium_Compat::memzero( $block0 );
106
+        } catch ( Error $ex ) {
107 107
             $block0 = null;
108 108
         }
109
-        $state->update($ad);
110
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($adlen));
111
-        $state->update($ciphertext);
112
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($clen));
109
+        $state->update( $ad );
110
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $adlen ) );
111
+        $state->update( $ciphertext );
112
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $clen ) );
113 113
         $computed_mac = $state->finish();
114 114
 
115 115
         /* Compare the given MAC with the recalculated MAC: */
116
-        if (!ParagonIE_Sodium_Core32_Util::verify_16($computed_mac, $mac)) {
117
-            throw new Error('Invalid MAC');
116
+        if ( ! ParagonIE_Sodium_Core32_Util::verify_16( $computed_mac, $mac ) ) {
117
+            throw new Error( 'Invalid MAC' );
118 118
         }
119 119
 
120 120
         // Here, we know that the MAC is valid, so we decrypt and return the plaintext
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
             $ciphertext,
123 123
             $nonce,
124 124
             $key,
125
-            ParagonIE_Sodium_Core32_Util::store64_le(1)
125
+            ParagonIE_Sodium_Core32_Util::store64_le( 1 )
126 126
         );
127 127
     }
128 128
 
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
         $key = ''
145 145
     ) {
146 146
         /** @var int $len - Length of the plaintext message */
147
-        $len = ParagonIE_Sodium_Core32_Util::strlen($message);
147
+        $len = ParagonIE_Sodium_Core32_Util::strlen( $message );
148 148
 
149 149
         /** @var int $adlen - Length of the associated data */
150
-        $adlen = ParagonIE_Sodium_Core32_Util::strlen($ad);
150
+        $adlen = ParagonIE_Sodium_Core32_Util::strlen( $ad );
151 151
 
152 152
         /** @var string The first block of the chacha20 keystream, used as a poly1305 key */
153 153
         $block0 = ParagonIE_Sodium_Core32_ChaCha20::stream(
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
             $nonce,
156 156
             $key
157 157
         );
158
-        $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0);
158
+        $state = new ParagonIE_Sodium_Core32_Poly1305_State( $block0 );
159 159
         try {
160
-            ParagonIE_Sodium_Compat::memzero($block0);
161
-        } catch (Error $ex) {
160
+            ParagonIE_Sodium_Compat::memzero( $block0 );
161
+        } catch ( Error $ex ) {
162 162
             $block0 = null;
163 163
         }
164 164
 
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
             $message,
168 168
             $nonce,
169 169
             $key,
170
-            ParagonIE_Sodium_Core32_Util::store64_le(1)
170
+            ParagonIE_Sodium_Core32_Util::store64_le( 1 )
171 171
         );
172 172
 
173
-        $state->update($ad);
174
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($adlen));
175
-        $state->update($ciphertext);
176
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($len));
173
+        $state->update( $ad );
174
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $adlen ) );
175
+        $state->update( $ciphertext );
176
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $len ) );
177 177
         return $ciphertext . $state->finish();
178 178
     }
179 179
 
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
         $key = ''
197 197
     ) {
198 198
         /** @var int $adlen - Length of associated data */
199
-        $adlen = ParagonIE_Sodium_Core32_Util::strlen($ad);
199
+        $adlen = ParagonIE_Sodium_Core32_Util::strlen( $ad );
200 200
 
201 201
         /** @var int $len - Length of message (ciphertext + MAC) */
202
-        $len = ParagonIE_Sodium_Core32_Util::strlen($message);
202
+        $len = ParagonIE_Sodium_Core32_Util::strlen( $message );
203 203
 
204 204
         /** @var int  $clen - Length of ciphertext */
205 205
         $clen = $len - self::aead_chacha20poly1305_IETF_ABYTES;
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
         );
227 227
 
228 228
         /* Recalculate the Poly1305 authentication tag (MAC): */
229
-        $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0);
229
+        $state = new ParagonIE_Sodium_Core32_Poly1305_State( $block0 );
230 230
         try {
231
-            ParagonIE_Sodium_Compat::memzero($block0);
232
-        } catch (Error $ex) {
231
+            ParagonIE_Sodium_Compat::memzero( $block0 );
232
+        } catch ( Error $ex ) {
233 233
             $block0 = null;
234 234
         }
235
-        $state->update($ad);
236
-        $state->update(str_repeat("\x00", ((0x10 - $adlen) & 0xf)));
237
-        $state->update($ciphertext);
238
-        $state->update(str_repeat("\x00", (0x10 - $clen) & 0xf));
239
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($adlen));
240
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($clen));
235
+        $state->update( $ad );
236
+        $state->update( str_repeat( "\x00", ( ( 0x10 - $adlen ) & 0xf ) ) );
237
+        $state->update( $ciphertext );
238
+        $state->update( str_repeat( "\x00", ( 0x10 - $clen ) & 0xf ) );
239
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $adlen ) );
240
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $clen ) );
241 241
         $computed_mac = $state->finish();
242 242
 
243 243
         /* Compare the given MAC with the recalculated MAC: */
244
-        if (!ParagonIE_Sodium_Core32_Util::verify_16($computed_mac, $mac)) {
245
-            throw new Error('Invalid MAC');
244
+        if ( ! ParagonIE_Sodium_Core32_Util::verify_16( $computed_mac, $mac ) ) {
245
+            throw new Error( 'Invalid MAC' );
246 246
         }
247 247
 
248 248
         // Here, we know that the MAC is valid, so we decrypt and return the plaintext
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
             $ciphertext,
251 251
             $nonce,
252 252
             $key,
253
-            ParagonIE_Sodium_Core32_Util::store64_le(1)
253
+            ParagonIE_Sodium_Core32_Util::store64_le( 1 )
254 254
         );
255 255
     }
256 256
 
@@ -272,10 +272,10 @@  discard block
 block discarded – undo
272 272
         $key = ''
273 273
     ) {
274 274
         /** @var int $len - Length of the plaintext message */
275
-        $len = ParagonIE_Sodium_Core32_Util::strlen($message);
275
+        $len = ParagonIE_Sodium_Core32_Util::strlen( $message );
276 276
 
277 277
         /** @var int $adlen - Length of the associated data */
278
-        $adlen = ParagonIE_Sodium_Core32_Util::strlen($ad);
278
+        $adlen = ParagonIE_Sodium_Core32_Util::strlen( $ad );
279 279
 
280 280
         /** @var string The first block of the chacha20 keystream, used as a poly1305 key */
281 281
         $block0 = ParagonIE_Sodium_Core32_ChaCha20::ietfStream(
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
             $nonce,
284 284
             $key
285 285
         );
286
-        $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0);
286
+        $state = new ParagonIE_Sodium_Core32_Poly1305_State( $block0 );
287 287
         try {
288
-            ParagonIE_Sodium_Compat::memzero($block0);
289
-        } catch (Error $ex) {
288
+            ParagonIE_Sodium_Compat::memzero( $block0 );
289
+        } catch ( Error $ex ) {
290 290
             $block0 = null;
291 291
         }
292 292
 
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
             $message,
296 296
             $nonce,
297 297
             $key,
298
-            ParagonIE_Sodium_Core32_Util::store64_le(1)
298
+            ParagonIE_Sodium_Core32_Util::store64_le( 1 )
299 299
         );
300 300
 
301
-        $state->update($ad);
302
-        $state->update(str_repeat("\x00", ((0x10 - $adlen) & 0xf)));
303
-        $state->update($ciphertext);
304
-        $state->update(str_repeat("\x00", ((0x10 - $len) & 0xf)));
305
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($adlen));
306
-        $state->update(ParagonIE_Sodium_Core32_Util::store64_le($len));
301
+        $state->update( $ad );
302
+        $state->update( str_repeat( "\x00", ( ( 0x10 - $adlen ) & 0xf ) ) );
303
+        $state->update( $ciphertext );
304
+        $state->update( str_repeat( "\x00", ( ( 0x10 - $len ) & 0xf ) ) );
305
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $adlen ) );
306
+        $state->update( ParagonIE_Sodium_Core32_Util::store64_le( $len ) );
307 307
         return $ciphertext . $state->finish();
308 308
     }
309 309
 
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
         $key = ''
327 327
     ) {
328 328
         $subkey = ParagonIE_Sodium_Core32_HChaCha20::hChaCha20(
329
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 0, 16),
329
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 0, 16 ),
330 330
             $key
331 331
         );
332 332
         $nonceLast = "\x00\x00\x00\x00" .
333
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8);
333
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 );
334 334
 
335
-        return self::aead_chacha20poly1305_ietf_decrypt($message, $ad, $nonceLast, $subkey);
335
+        return self::aead_chacha20poly1305_ietf_decrypt( $message, $ad, $nonceLast, $subkey );
336 336
     }
337 337
 
338 338
     /**
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
         $key = ''
354 354
     ) {
355 355
         $subkey = ParagonIE_Sodium_Core32_HChaCha20::hChaCha20(
356
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 0, 16),
356
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 0, 16 ),
357 357
             $key
358 358
         );
359 359
         $nonceLast = "\x00\x00\x00\x00" .
360
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8);
360
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 );
361 361
 
362
-        return self::aead_chacha20poly1305_ietf_encrypt($message, $ad, $nonceLast, $subkey);
362
+        return self::aead_chacha20poly1305_ietf_encrypt( $message, $ad, $nonceLast, $subkey );
363 363
     }
364 364
 
365 365
     /**
@@ -371,10 +371,10 @@  discard block
 block discarded – undo
371 371
      * @param string $key
372 372
      * @return string
373 373
      */
374
-    public static function auth($message, $key)
374
+    public static function auth( $message, $key )
375 375
     {
376 376
         return ParagonIE_Sodium_Core32_Util::substr(
377
-            hash_hmac('sha512', $message, $key, true),
377
+            hash_hmac( 'sha512', $message, $key, true ),
378 378
             0,
379 379
             32
380 380
         );
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
      * @param string $key
391 391
      * @return bool
392 392
      */
393
-    public static function auth_verify($mac, $message, $key)
393
+    public static function auth_verify( $mac, $message, $key )
394 394
     {
395 395
         return ParagonIE_Sodium_Core32_Util::hashEquals(
396 396
             $mac,
397
-            self::auth($message, $key)
397
+            self::auth( $message, $key )
398 398
         );
399 399
     }
400 400
 
@@ -408,14 +408,14 @@  discard block
 block discarded – undo
408 408
      * @param string $keypair
409 409
      * @return string
410 410
      */
411
-    public static function box($plaintext, $nonce, $keypair)
411
+    public static function box( $plaintext, $nonce, $keypair )
412 412
     {
413 413
         $c = self::secretbox(
414 414
             $plaintext,
415 415
             $nonce,
416 416
             self::box_beforenm(
417
-                self::box_secretkey($keypair),
418
-                self::box_publickey($keypair)
417
+                self::box_secretkey( $keypair ),
418
+                self::box_publickey( $keypair )
419 419
             )
420 420
         );
421 421
         return $c;
@@ -430,16 +430,16 @@  discard block
 block discarded – undo
430 430
      * @param string $publicKey
431 431
      * @return string
432 432
      */
433
-    public static function box_seal($message, $publicKey)
433
+    public static function box_seal( $message, $publicKey )
434 434
     {
435 435
         /** @var string $ephemeralKeypair */
436 436
         $ephemeralKeypair = self::box_keypair();
437 437
 
438 438
         /** @var string $ephemeralSK */
439
-        $ephemeralSK = self::box_secretkey($ephemeralKeypair);
439
+        $ephemeralSK = self::box_secretkey( $ephemeralKeypair );
440 440
 
441 441
         /** @var string $ephemeralPK */
442
-        $ephemeralPK = self::box_publickey($ephemeralKeypair);
442
+        $ephemeralPK = self::box_publickey( $ephemeralKeypair );
443 443
 
444 444
         /** @var string $nonce */
445 445
         $nonce = self::generichash(
@@ -449,15 +449,15 @@  discard block
 block discarded – undo
449 449
         );
450 450
 
451 451
         /** @var string $keypair - The combined keypair used in crypto_box() */
452
-        $keypair = self::box_keypair_from_secretkey_and_publickey($ephemeralSK, $publicKey);
452
+        $keypair = self::box_keypair_from_secretkey_and_publickey( $ephemeralSK, $publicKey );
453 453
 
454 454
         /** @var string $ciphertext Ciphertext + MAC from crypto_box */
455
-        $ciphertext = self::box($message, $nonce, $keypair);
455
+        $ciphertext = self::box( $message, $nonce, $keypair );
456 456
         try {
457
-            ParagonIE_Sodium_Compat::memzero($ephemeralKeypair);
458
-            ParagonIE_Sodium_Compat::memzero($ephemeralSK);
459
-            ParagonIE_Sodium_Compat::memzero($nonce);
460
-        } catch (Error $ex) {
457
+            ParagonIE_Sodium_Compat::memzero( $ephemeralKeypair );
458
+            ParagonIE_Sodium_Compat::memzero( $ephemeralSK );
459
+            ParagonIE_Sodium_Compat::memzero( $nonce );
460
+        } catch ( Error $ex ) {
461 461
             $ephemeralKeypair = null;
462 462
             $ephemeralSK = null;
463 463
             $nonce = null;
@@ -474,19 +474,19 @@  discard block
 block discarded – undo
474 474
      * @param string $keypair
475 475
      * @return string
476 476
      */
477
-    public static function box_seal_open($message, $keypair)
477
+    public static function box_seal_open( $message, $keypair )
478 478
     {
479 479
         /** @var string $ephemeralPK */
480
-        $ephemeralPK = ParagonIE_Sodium_Core32_Util::substr($message, 0, 32);
480
+        $ephemeralPK = ParagonIE_Sodium_Core32_Util::substr( $message, 0, 32 );
481 481
 
482 482
         /** @var string $ciphertext (ciphertext + MAC) */
483
-        $ciphertext = ParagonIE_Sodium_Core32_Util::substr($message, 32);
483
+        $ciphertext = ParagonIE_Sodium_Core32_Util::substr( $message, 32 );
484 484
 
485 485
         /** @var string $secretKey */
486
-        $secretKey = self::box_secretkey($keypair);
486
+        $secretKey = self::box_secretkey( $keypair );
487 487
 
488 488
         /** @var string $publicKey */
489
-        $publicKey = self::box_publickey($keypair);
489
+        $publicKey = self::box_publickey( $keypair );
490 490
 
491 491
         /** @var string $nonce */
492 492
         $nonce = self::generichash(
@@ -496,15 +496,15 @@  discard block
 block discarded – undo
496 496
         );
497 497
 
498 498
         /** @var string $keypair */
499
-        $keypair = self::box_keypair_from_secretkey_and_publickey($secretKey, $ephemeralPK);
499
+        $keypair = self::box_keypair_from_secretkey_and_publickey( $secretKey, $ephemeralPK );
500 500
 
501 501
         /** @var string $m */
502
-        $m = self::box_open($ciphertext, $nonce, $keypair);
502
+        $m = self::box_open( $ciphertext, $nonce, $keypair );
503 503
         try {
504
-            ParagonIE_Sodium_Compat::memzero($secretKey);
505
-            ParagonIE_Sodium_Compat::memzero($ephemeralPK);
506
-            ParagonIE_Sodium_Compat::memzero($nonce);
507
-        } catch (Error $ex) {
504
+            ParagonIE_Sodium_Compat::memzero( $secretKey );
505
+            ParagonIE_Sodium_Compat::memzero( $ephemeralPK );
506
+            ParagonIE_Sodium_Compat::memzero( $nonce );
507
+        } catch ( Error $ex ) {
508 508
             $secretKey = null;
509 509
             $ephemeralPK = null;
510 510
             $nonce = null;
@@ -521,11 +521,11 @@  discard block
 block discarded – undo
521 521
      * @param string $pk
522 522
      * @return string
523 523
      */
524
-    public static function box_beforenm($sk, $pk)
524
+    public static function box_beforenm( $sk, $pk )
525 525
     {
526 526
         return ParagonIE_Sodium_Core32_HSalsa20::hsalsa20(
527
-            str_repeat("\x00", 16),
528
-            self::scalarmult($sk, $pk)
527
+            str_repeat( "\x00", 16 ),
528
+            self::scalarmult( $sk, $pk )
529 529
         );
530 530
     }
531 531
 
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
      */
537 537
     public static function box_keypair()
538 538
     {
539
-        $sKey = random_bytes(32);
540
-        $pKey = self::scalarmult_base($sKey);
539
+        $sKey = random_bytes( 32 );
540
+        $pKey = self::scalarmult_base( $sKey );
541 541
         return $sKey . $pKey;
542 542
     }
543 543
 
@@ -548,10 +548,10 @@  discard block
 block discarded – undo
548 548
      * @param string $pKey
549 549
      * @return string
550 550
      */
551
-    public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey)
551
+    public static function box_keypair_from_secretkey_and_publickey( $sKey, $pKey )
552 552
     {
553
-        return ParagonIE_Sodium_Core32_Util::substr($sKey, 0, 32) .
554
-            ParagonIE_Sodium_Core32_Util::substr($pKey, 0, 32);
553
+        return ParagonIE_Sodium_Core32_Util::substr( $sKey, 0, 32 ) .
554
+            ParagonIE_Sodium_Core32_Util::substr( $pKey, 0, 32 );
555 555
     }
556 556
 
557 557
     /**
@@ -561,12 +561,12 @@  discard block
 block discarded – undo
561 561
      * @return string
562 562
      * @throws RangeException
563 563
      */
564
-    public static function box_secretkey($keypair)
564
+    public static function box_secretkey( $keypair )
565 565
     {
566
-        if (ParagonIE_Sodium_Core32_Util::strlen($keypair) !== 64) {
567
-            throw new RangeException('Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.');
566
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $keypair ) !== 64 ) {
567
+            throw new RangeException( 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' );
568 568
         }
569
-        return ParagonIE_Sodium_Core32_Util::substr($keypair, 0, 32);
569
+        return ParagonIE_Sodium_Core32_Util::substr( $keypair, 0, 32 );
570 570
     }
571 571
 
572 572
     /**
@@ -576,12 +576,12 @@  discard block
 block discarded – undo
576 576
      * @return string
577 577
      * @throws RangeException
578 578
      */
579
-    public static function box_publickey($keypair)
579
+    public static function box_publickey( $keypair )
580 580
     {
581
-        if (ParagonIE_Sodium_Core32_Util::strlen($keypair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) {
582
-            throw new RangeException('Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.');
581
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $keypair ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES ) {
582
+            throw new RangeException( 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' );
583 583
         }
584
-        return ParagonIE_Sodium_Core32_Util::substr($keypair, 32, 32);
584
+        return ParagonIE_Sodium_Core32_Util::substr( $keypair, 32, 32 );
585 585
     }
586 586
 
587 587
     /**
@@ -591,12 +591,12 @@  discard block
 block discarded – undo
591 591
      * @return string
592 592
      * @throws RangeException
593 593
      */
594
-    public static function box_publickey_from_secretkey($sKey)
594
+    public static function box_publickey_from_secretkey( $sKey )
595 595
     {
596
-        if (ParagonIE_Sodium_Core32_Util::strlen($sKey) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES) {
597
-            throw new RangeException('Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES bytes long.');
596
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $sKey ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES ) {
597
+            throw new RangeException( 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES bytes long.' );
598 598
         }
599
-        return self::scalarmult_base($sKey);
599
+        return self::scalarmult_base( $sKey );
600 600
     }
601 601
 
602 602
     /**
@@ -610,14 +610,14 @@  discard block
 block discarded – undo
610 610
      * @param string $keypair
611 611
      * @return string
612 612
      */
613
-    public static function box_open($ciphertext, $nonce, $keypair)
613
+    public static function box_open( $ciphertext, $nonce, $keypair )
614 614
     {
615 615
         return self::secretbox_open(
616 616
             $ciphertext,
617 617
             $nonce,
618 618
             self::box_beforenm(
619
-                self::box_secretkey($keypair),
620
-                self::box_publickey($keypair)
619
+                self::box_secretkey( $keypair ),
620
+                self::box_publickey( $keypair )
621 621
             )
622 622
         );
623 623
     }
@@ -633,34 +633,34 @@  discard block
 block discarded – undo
633 633
      * @return string
634 634
      * @throws RangeException
635 635
      */
636
-    public static function generichash($message, $key = '', $outlen = 32)
636
+    public static function generichash( $message, $key = '', $outlen = 32 )
637 637
     {
638 638
         // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized
639 639
         ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor();
640 640
 
641 641
         $k = null;
642
-        if (!empty($key)) {
642
+        if ( ! empty( $key ) ) {
643 643
             /** @var SplFixedArray $k */
644
-            $k = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($key);
645
-            if ($k->count() > ParagonIE_Sodium_Core32_BLAKE2b::KEYBYTES) {
646
-                throw new RangeException('Invalid key size');
644
+            $k = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray( $key );
645
+            if ( $k->count() > ParagonIE_Sodium_Core32_BLAKE2b::KEYBYTES ) {
646
+                throw new RangeException( 'Invalid key size' );
647 647
             }
648 648
         }
649 649
 
650 650
         /** @var SplFixedArray $in */
651
-        $in = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($message);
651
+        $in = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray( $message );
652 652
 
653 653
         /** @var SplFixedArray $ctx */
654
-        $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init($k, $outlen);
655
-        ParagonIE_Sodium_Core32_BLAKE2b::update($ctx, $in, $in->count());
654
+        $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init( $k, $outlen );
655
+        ParagonIE_Sodium_Core32_BLAKE2b::update( $ctx, $in, $in->count() );
656 656
 
657 657
         /** @var SplFixedArray $out */
658
-        $out = new SplFixedArray($outlen);
659
-        $out = ParagonIE_Sodium_Core32_BLAKE2b::finish($ctx, $out);
658
+        $out = new SplFixedArray( $outlen );
659
+        $out = ParagonIE_Sodium_Core32_BLAKE2b::finish( $ctx, $out );
660 660
 
661 661
         /** @var array<int, int> */
662 662
         $outArray = $out->toArray();
663
-        return ParagonIE_Sodium_Core32_Util::intArrayToString($outArray);
663
+        return ParagonIE_Sodium_Core32_Util::intArrayToString( $outArray );
664 664
     }
665 665
 
666 666
     /**
@@ -673,22 +673,22 @@  discard block
 block discarded – undo
673 673
      * @return string
674 674
      * @throws TypeError
675 675
      */
676
-    public static function generichash_final($ctx, $outlen = 32)
676
+    public static function generichash_final( $ctx, $outlen = 32 )
677 677
     {
678
-        if (!is_string($ctx)) {
679
-            throw new TypeError('Context must be a string');
678
+        if ( ! is_string( $ctx ) ) {
679
+            throw new TypeError( 'Context must be a string' );
680 680
         }
681
-        $out = new SplFixedArray($outlen);
681
+        $out = new SplFixedArray( $outlen );
682 682
 
683 683
         /** @var SplFixedArray $context */
684
-        $context = ParagonIE_Sodium_Core32_BLAKE2b::stringToContext($ctx);
684
+        $context = ParagonIE_Sodium_Core32_BLAKE2b::stringToContext( $ctx );
685 685
 
686 686
         /** @var SplFixedArray $out */
687
-        $out = ParagonIE_Sodium_Core32_BLAKE2b::finish($context, $out);
687
+        $out = ParagonIE_Sodium_Core32_BLAKE2b::finish( $context, $out );
688 688
 
689 689
         /** @var array<int, int> */
690 690
         $outArray = $out->toArray();
691
-        return ParagonIE_Sodium_Core32_Util::intArrayToString($outArray);
691
+        return ParagonIE_Sodium_Core32_Util::intArrayToString( $outArray );
692 692
     }
693 693
 
694 694
     /**
@@ -701,23 +701,23 @@  discard block
 block discarded – undo
701 701
      * @return string
702 702
      * @throws RangeException
703 703
      */
704
-    public static function generichash_init($key = '', $outputLength = 32)
704
+    public static function generichash_init( $key = '', $outputLength = 32 )
705 705
     {
706 706
         // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized
707 707
         ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor();
708 708
 
709 709
         $k = null;
710
-        if (!empty($key)) {
711
-            $k = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($key);
712
-            if ($k->count() > ParagonIE_Sodium_Core32_BLAKE2b::KEYBYTES) {
713
-                throw new RangeException('Invalid key size');
710
+        if ( ! empty( $key ) ) {
711
+            $k = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray( $key );
712
+            if ( $k->count() > ParagonIE_Sodium_Core32_BLAKE2b::KEYBYTES ) {
713
+                throw new RangeException( 'Invalid key size' );
714 714
             }
715 715
         }
716 716
 
717 717
         /** @var SplFixedArray $ctx */
718
-        $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init($k, $outputLength);
718
+        $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init( $k, $outputLength );
719 719
 
720
-        return ParagonIE_Sodium_Core32_BLAKE2b::contextToString($ctx);
720
+        return ParagonIE_Sodium_Core32_BLAKE2b::contextToString( $ctx );
721 721
     }
722 722
 
723 723
     /**
@@ -729,20 +729,20 @@  discard block
 block discarded – undo
729 729
      * @param string $message
730 730
      * @return string
731 731
      */
732
-    public static function generichash_update($ctx, $message)
732
+    public static function generichash_update( $ctx, $message )
733 733
     {
734 734
         // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized
735 735
         ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor();
736 736
 
737 737
         /** @var SplFixedArray $context */
738
-        $context = ParagonIE_Sodium_Core32_BLAKE2b::stringToContext($ctx);
738
+        $context = ParagonIE_Sodium_Core32_BLAKE2b::stringToContext( $ctx );
739 739
 
740 740
         /** @var SplFixedArray $in */
741
-        $in = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($message);
741
+        $in = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray( $message );
742 742
 
743
-        ParagonIE_Sodium_Core32_BLAKE2b::update($context, $in, $in->count());
743
+        ParagonIE_Sodium_Core32_BLAKE2b::update( $context, $in, $in->count() );
744 744
 
745
-        return ParagonIE_Sodium_Core32_BLAKE2b::contextToString($context);
745
+        return ParagonIE_Sodium_Core32_BLAKE2b::contextToString( $context );
746 746
     }
747 747
 
748 748
     /**
@@ -756,10 +756,10 @@  discard block
 block discarded – undo
756 756
      * @param string $server_pk
757 757
      * @return string
758 758
      */
759
-    public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk)
759
+    public static function keyExchange( $my_sk, $their_pk, $client_pk, $server_pk )
760 760
     {
761 761
         return self::generichash(
762
-            self::scalarmult($my_sk, $their_pk) .
762
+            self::scalarmult( $my_sk, $their_pk ) .
763 763
             $client_pk .
764 764
             $server_pk
765 765
         );
@@ -776,10 +776,10 @@  discard block
 block discarded – undo
776 776
      *
777 777
      * @throws Error
778 778
      */
779
-    public static function scalarmult($sKey, $pKey)
779
+    public static function scalarmult( $sKey, $pKey )
780 780
     {
781
-        $q = ParagonIE_Sodium_Core32_X25519::crypto_scalarmult_curve25519_ref10($sKey, $pKey);
782
-        self::scalarmult_throw_if_zero($q);
781
+        $q = ParagonIE_Sodium_Core32_X25519::crypto_scalarmult_curve25519_ref10( $sKey, $pKey );
782
+        self::scalarmult_throw_if_zero( $q );
783 783
         return $q;
784 784
     }
785 785
 
@@ -792,10 +792,10 @@  discard block
 block discarded – undo
792 792
      *
793 793
      * @throws Error
794 794
      */
795
-    public static function scalarmult_base($secret)
795
+    public static function scalarmult_base( $secret )
796 796
     {
797
-        $q = ParagonIE_Sodium_Core32_X25519::crypto_scalarmult_curve25519_ref10_base($secret);
798
-        self::scalarmult_throw_if_zero($q);
797
+        $q = ParagonIE_Sodium_Core32_X25519::crypto_scalarmult_curve25519_ref10_base( $secret );
798
+        self::scalarmult_throw_if_zero( $q );
799 799
         return $q;
800 800
     }
801 801
 
@@ -806,16 +806,16 @@  discard block
 block discarded – undo
806 806
      * @return void
807 807
      * @throws Error
808 808
      */
809
-    protected static function scalarmult_throw_if_zero($q)
809
+    protected static function scalarmult_throw_if_zero( $q )
810 810
     {
811 811
         $d = 0;
812
-        for ($i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i) {
813
-            $d |= ParagonIE_Sodium_Core32_Util::chrToInt($q[$i]);
812
+        for ( $i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i ) {
813
+            $d |= ParagonIE_Sodium_Core32_Util::chrToInt( $q[$i] );
814 814
         }
815 815
 
816 816
         /* branch-free variant of === 0 */
817
-        if (-(1 & (($d - 1) >> 8))) {
818
-            throw new Error('Zero public key is not allowed');
817
+        if (-( 1 & ( ( $d - 1 ) >> 8 ) )) {
818
+            throw new Error( 'Zero public key is not allowed' );
819 819
         }
820 820
     }
821 821
 
@@ -829,26 +829,26 @@  discard block
 block discarded – undo
829 829
      * @param string $key
830 830
      * @return string
831 831
      */
832
-    public static function secretbox($plaintext, $nonce, $key)
832
+    public static function secretbox( $plaintext, $nonce, $key )
833 833
     {
834 834
         /** @var string $subkey */
835
-        $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key);
835
+        $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20( $nonce, $key );
836 836
 
837 837
         /** @var string $block0 */
838
-        $block0 = str_repeat("\x00", 32);
838
+        $block0 = str_repeat( "\x00", 32 );
839 839
 
840 840
         /** @var int $mlen - Length of the plaintext message */
841
-        $mlen = ParagonIE_Sodium_Core32_Util::strlen($plaintext);
841
+        $mlen = ParagonIE_Sodium_Core32_Util::strlen( $plaintext );
842 842
         $mlen0 = $mlen;
843
-        if ($mlen0 > 64 - self::secretbox_xsalsa20poly1305_ZEROBYTES) {
843
+        if ( $mlen0 > 64 - self::secretbox_xsalsa20poly1305_ZEROBYTES ) {
844 844
             $mlen0 = 64 - self::secretbox_xsalsa20poly1305_ZEROBYTES;
845 845
         }
846
-        $block0 .= ParagonIE_Sodium_Core32_Util::substr($plaintext, 0, $mlen0);
846
+        $block0 .= ParagonIE_Sodium_Core32_Util::substr( $plaintext, 0, $mlen0 );
847 847
 
848 848
         /** @var string $block0 */
849 849
         $block0 = ParagonIE_Sodium_Core32_Salsa20::salsa20_xor(
850 850
             $block0,
851
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
851
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 ),
852 852
             $subkey
853 853
         );
854 854
 
@@ -857,13 +857,13 @@  discard block
 block discarded – undo
857 857
             $block0,
858 858
             self::secretbox_xsalsa20poly1305_ZEROBYTES
859 859
         );
860
-        if ($mlen > $mlen0) {
860
+        if ( $mlen > $mlen0 ) {
861 861
             $c .= ParagonIE_Sodium_Core32_Salsa20::salsa20_xor_ic(
862 862
                 ParagonIE_Sodium_Core32_Util::substr(
863 863
                     $plaintext,
864 864
                     self::secretbox_xsalsa20poly1305_ZEROBYTES
865 865
                 ),
866
-                ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
866
+                ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 ),
867 867
                 1,
868 868
                 $subkey
869 869
             );
@@ -876,18 +876,18 @@  discard block
 block discarded – undo
876 876
             )
877 877
         );
878 878
         try {
879
-            ParagonIE_Sodium_Compat::memzero($block0);
880
-            ParagonIE_Sodium_Compat::memzero($subkey);
881
-        } catch (Error $ex) {
879
+            ParagonIE_Sodium_Compat::memzero( $block0 );
880
+            ParagonIE_Sodium_Compat::memzero( $subkey );
881
+        } catch ( Error $ex ) {
882 882
             $block0 = null;
883 883
             $subkey = null;
884 884
         }
885 885
 
886
-        $state->update($c);
886
+        $state->update( $c );
887 887
 
888 888
         /** @var string $c - MAC || ciphertext */
889 889
         $c = $state->finish() . $c;
890
-        unset($state);
890
+        unset( $state );
891 891
 
892 892
         return $c;
893 893
     }
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
      * @return string
904 904
      * @throws Error
905 905
      */
906
-    public static function secretbox_open($ciphertext, $nonce, $key)
906
+    public static function secretbox_open( $ciphertext, $nonce, $key )
907 907
     {
908 908
         /** @var string $mac */
909 909
         $mac = ParagonIE_Sodium_Core32_Util::substr(
@@ -919,44 +919,44 @@  discard block
 block discarded – undo
919 919
         );
920 920
 
921 921
         /** @var int $clen */
922
-        $clen = ParagonIE_Sodium_Core32_Util::strlen($c);
922
+        $clen = ParagonIE_Sodium_Core32_Util::strlen( $c );
923 923
 
924 924
         /** @var string $subkey */
925
-        $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key);
925
+        $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20( $nonce, $key );
926 926
 
927 927
         /** @var string $block0 */
928 928
         $block0 = ParagonIE_Sodium_Core32_Salsa20::salsa20(
929 929
             64,
930
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
930
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 ),
931 931
             $subkey
932 932
         );
933 933
         $verified = ParagonIE_Sodium_Core32_Poly1305::onetimeauth_verify(
934 934
             $mac,
935 935
             $c,
936
-            ParagonIE_Sodium_Core32_Util::substr($block0, 0, 32)
936
+            ParagonIE_Sodium_Core32_Util::substr( $block0, 0, 32 )
937 937
         );
938
-        if (!$verified) {
938
+        if ( ! $verified ) {
939 939
             try {
940
-                ParagonIE_Sodium_Compat::memzero($subkey);
941
-            } catch (Error $ex) {
940
+                ParagonIE_Sodium_Compat::memzero( $subkey );
941
+            } catch ( Error $ex ) {
942 942
                 $subkey = null;
943 943
             }
944
-            throw new Error('Invalid MAC');
944
+            throw new Error( 'Invalid MAC' );
945 945
         }
946 946
 
947 947
         /** @var string $m - Decrypted message */
948 948
         $m = ParagonIE_Sodium_Core32_Util::xorStrings(
949
-            ParagonIE_Sodium_Core32_Util::substr($block0, self::secretbox_xsalsa20poly1305_ZEROBYTES),
950
-            ParagonIE_Sodium_Core32_Util::substr($c, 0, self::secretbox_xsalsa20poly1305_ZEROBYTES)
949
+            ParagonIE_Sodium_Core32_Util::substr( $block0, self::secretbox_xsalsa20poly1305_ZEROBYTES ),
950
+            ParagonIE_Sodium_Core32_Util::substr( $c, 0, self::secretbox_xsalsa20poly1305_ZEROBYTES )
951 951
         );
952
-        if ($clen > self::secretbox_xsalsa20poly1305_ZEROBYTES) {
952
+        if ( $clen > self::secretbox_xsalsa20poly1305_ZEROBYTES ) {
953 953
             // We had more than 1 block, so let's continue to decrypt the rest.
954 954
             $m .= ParagonIE_Sodium_Core32_Salsa20::salsa20_xor_ic(
955 955
                 ParagonIE_Sodium_Core32_Util::substr(
956 956
                     $c,
957 957
                     self::secretbox_xsalsa20poly1305_ZEROBYTES
958 958
                 ),
959
-                ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
959
+                ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 ),
960 960
                 1,
961 961
                 $subkey
962 962
             );
@@ -974,25 +974,25 @@  discard block
 block discarded – undo
974 974
      * @param string $key
975 975
      * @return string
976 976
      */
977
-    public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key)
977
+    public static function secretbox_xchacha20poly1305( $plaintext, $nonce, $key )
978 978
     {
979 979
         /** @var string $subkey */
980 980
         $subkey = ParagonIE_Sodium_Core32_HChaCha20::hChaCha20(
981
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 0, 16),
981
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 0, 16 ),
982 982
             $key
983 983
         );
984
-        $nonceLast = ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8);
984
+        $nonceLast = ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 );
985 985
 
986 986
         /** @var string $block0 */
987
-        $block0 = str_repeat("\x00", 32);
987
+        $block0 = str_repeat( "\x00", 32 );
988 988
 
989 989
         /** @var int $mlen - Length of the plaintext message */
990
-        $mlen = ParagonIE_Sodium_Core32_Util::strlen($plaintext);
990
+        $mlen = ParagonIE_Sodium_Core32_Util::strlen( $plaintext );
991 991
         $mlen0 = $mlen;
992
-        if ($mlen0 > 64 - self::secretbox_xchacha20poly1305_ZEROBYTES) {
992
+        if ( $mlen0 > 64 - self::secretbox_xchacha20poly1305_ZEROBYTES ) {
993 993
             $mlen0 = 64 - self::secretbox_xchacha20poly1305_ZEROBYTES;
994 994
         }
995
-        $block0 .= ParagonIE_Sodium_Core32_Util::substr($plaintext, 0, $mlen0);
995
+        $block0 .= ParagonIE_Sodium_Core32_Util::substr( $plaintext, 0, $mlen0 );
996 996
 
997 997
         /** @var string $block0 */
998 998
         $block0 = ParagonIE_Sodium_Core32_ChaCha20::streamXorIc(
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
             $block0,
1007 1007
             self::secretbox_xchacha20poly1305_ZEROBYTES
1008 1008
         );
1009
-        if ($mlen > $mlen0) {
1009
+        if ( $mlen > $mlen0 ) {
1010 1010
             $c .= ParagonIE_Sodium_Core32_ChaCha20::streamXorIc(
1011 1011
                 ParagonIE_Sodium_Core32_Util::substr(
1012 1012
                     $plaintext,
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
                 ),
1015 1015
                 $nonceLast,
1016 1016
                 $subkey,
1017
-                ParagonIE_Sodium_Core32_Util::store64_le(1)
1017
+                ParagonIE_Sodium_Core32_Util::store64_le( 1 )
1018 1018
             );
1019 1019
         }
1020 1020
         $state = new ParagonIE_Sodium_Core32_Poly1305_State(
@@ -1025,18 +1025,18 @@  discard block
 block discarded – undo
1025 1025
             )
1026 1026
         );
1027 1027
         try {
1028
-            ParagonIE_Sodium_Compat::memzero($block0);
1029
-            ParagonIE_Sodium_Compat::memzero($subkey);
1030
-        } catch (Error $ex) {
1028
+            ParagonIE_Sodium_Compat::memzero( $block0 );
1029
+            ParagonIE_Sodium_Compat::memzero( $subkey );
1030
+        } catch ( Error $ex ) {
1031 1031
             $block0 = null;
1032 1032
             $subkey = null;
1033 1033
         }
1034 1034
 
1035
-        $state->update($c);
1035
+        $state->update( $c );
1036 1036
 
1037 1037
         /** @var string $c - MAC || ciphertext */
1038 1038
         $c = $state->finish() . $c;
1039
-        unset($state);
1039
+        unset( $state );
1040 1040
 
1041 1041
         return $c;
1042 1042
     }
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
      * @return string
1053 1053
      * @throws Error
1054 1054
      */
1055
-    public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key)
1055
+    public static function secretbox_xchacha20poly1305_open( $ciphertext, $nonce, $key )
1056 1056
     {
1057 1057
         /** @var string $mac */
1058 1058
         $mac = ParagonIE_Sodium_Core32_Util::substr(
@@ -1068,48 +1068,48 @@  discard block
 block discarded – undo
1068 1068
         );
1069 1069
 
1070 1070
         /** @var int $clen */
1071
-        $clen = ParagonIE_Sodium_Core32_Util::strlen($c);
1071
+        $clen = ParagonIE_Sodium_Core32_Util::strlen( $c );
1072 1072
 
1073 1073
         /** @var string $subkey */
1074
-        $subkey = ParagonIE_Sodium_Core32_HChaCha20::hchacha20($nonce, $key);
1074
+        $subkey = ParagonIE_Sodium_Core32_HChaCha20::hchacha20( $nonce, $key );
1075 1075
 
1076 1076
         /** @var string $block0 */
1077 1077
         $block0 = ParagonIE_Sodium_Core32_ChaCha20::stream(
1078 1078
             64,
1079
-            ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
1079
+            ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 ),
1080 1080
             $subkey
1081 1081
         );
1082 1082
         $verified = ParagonIE_Sodium_Core32_Poly1305::onetimeauth_verify(
1083 1083
             $mac,
1084 1084
             $c,
1085
-            ParagonIE_Sodium_Core32_Util::substr($block0, 0, 32)
1085
+            ParagonIE_Sodium_Core32_Util::substr( $block0, 0, 32 )
1086 1086
         );
1087 1087
 
1088
-        if (!$verified) {
1088
+        if ( ! $verified ) {
1089 1089
             try {
1090
-                ParagonIE_Sodium_Compat::memzero($subkey);
1091
-            } catch (Error $ex) {
1090
+                ParagonIE_Sodium_Compat::memzero( $subkey );
1091
+            } catch ( Error $ex ) {
1092 1092
                 $subkey = null;
1093 1093
             }
1094
-            throw new Error('Invalid MAC');
1094
+            throw new Error( 'Invalid MAC' );
1095 1095
         }
1096 1096
 
1097 1097
         /** @var string $m - Decrypted message */
1098 1098
         $m = ParagonIE_Sodium_Core32_Util::xorStrings(
1099
-            ParagonIE_Sodium_Core32_Util::substr($block0, self::secretbox_xchacha20poly1305_ZEROBYTES),
1100
-            ParagonIE_Sodium_Core32_Util::substr($c, 0, self::secretbox_xchacha20poly1305_ZEROBYTES)
1099
+            ParagonIE_Sodium_Core32_Util::substr( $block0, self::secretbox_xchacha20poly1305_ZEROBYTES ),
1100
+            ParagonIE_Sodium_Core32_Util::substr( $c, 0, self::secretbox_xchacha20poly1305_ZEROBYTES )
1101 1101
         );
1102 1102
 
1103
-        if ($clen > self::secretbox_xchacha20poly1305_ZEROBYTES) {
1103
+        if ( $clen > self::secretbox_xchacha20poly1305_ZEROBYTES ) {
1104 1104
             // We had more than 1 block, so let's continue to decrypt the rest.
1105 1105
             $m .= ParagonIE_Sodium_Core32_ChaCha20::streamXorIc(
1106 1106
                 ParagonIE_Sodium_Core32_Util::substr(
1107 1107
                     $c,
1108 1108
                     self::secretbox_xchacha20poly1305_ZEROBYTES
1109 1109
                 ),
1110
-                ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
1110
+                ParagonIE_Sodium_Core32_Util::substr( $nonce, 16, 8 ),
1111 1111
                 $subkey,
1112
-                ParagonIE_Sodium_Core32_Util::store64_le(1)
1112
+                ParagonIE_Sodium_Core32_Util::store64_le( 1 )
1113 1113
             );
1114 1114
         }
1115 1115
         return $m;
@@ -1124,9 +1124,9 @@  discard block
 block discarded – undo
1124 1124
      * @param string $sk
1125 1125
      * @return string
1126 1126
      */
1127
-    public static function sign_detached($message, $sk)
1127
+    public static function sign_detached( $message, $sk )
1128 1128
     {
1129
-        return ParagonIE_Sodium_Core32_Ed25519::sign_detached($message, $sk);
1129
+        return ParagonIE_Sodium_Core32_Ed25519::sign_detached( $message, $sk );
1130 1130
     }
1131 1131
 
1132 1132
     /**
@@ -1138,9 +1138,9 @@  discard block
 block discarded – undo
1138 1138
      * @param string $sk
1139 1139
      * @return string
1140 1140
      */
1141
-    public static function sign($message, $sk)
1141
+    public static function sign( $message, $sk )
1142 1142
     {
1143
-        return ParagonIE_Sodium_Core32_Ed25519::sign($message, $sk);
1143
+        return ParagonIE_Sodium_Core32_Ed25519::sign( $message, $sk );
1144 1144
     }
1145 1145
 
1146 1146
     /**
@@ -1152,9 +1152,9 @@  discard block
 block discarded – undo
1152 1152
      * @param string $pk
1153 1153
      * @return string
1154 1154
      */
1155
-    public static function sign_open($signedMessage, $pk)
1155
+    public static function sign_open( $signedMessage, $pk )
1156 1156
     {
1157
-        return ParagonIE_Sodium_Core32_Ed25519::sign_open($signedMessage, $pk);
1157
+        return ParagonIE_Sodium_Core32_Ed25519::sign_open( $signedMessage, $pk );
1158 1158
     }
1159 1159
 
1160 1160
     /**
@@ -1167,8 +1167,8 @@  discard block
 block discarded – undo
1167 1167
      * @param string $pk
1168 1168
      * @return bool
1169 1169
      */
1170
-    public static function sign_verify_detached($signature, $message, $pk)
1170
+    public static function sign_verify_detached( $signature, $message, $pk )
1171 1171
     {
1172
-        return ParagonIE_Sodium_Core32_Ed25519::verify_detached($signature, $message, $pk);
1172
+        return ParagonIE_Sodium_Core32_Ed25519::verify_detached( $signature, $message, $pk );
1173 1173
     }
1174 1174
 }
Please login to merge, or discard this patch.
src/library/sodium_compat/src/File.php 1 patch
Spacing   +377 added lines, -377 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_File', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_File', false ) ) {
4 4
     return;
5 5
 }
6 6
 /**
@@ -25,52 +25,52 @@  discard block
 block discarded – undo
25 25
      * @throws Error
26 26
      * @throws TypeError
27 27
      */
28
-    public static function box($inputFile, $outputFile, $nonce, $keyPair)
28
+    public static function box( $inputFile, $outputFile, $nonce, $keyPair )
29 29
     {
30 30
         /* Type checks: */
31
-        if (!is_string($inputFile)) {
32
-            throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.');
31
+        if ( ! is_string( $inputFile ) ) {
32
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $inputFile ) . ' given.' );
33 33
         }
34
-        if (!is_string($outputFile)) {
35
-            throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
34
+        if ( ! is_string( $outputFile ) ) {
35
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $outputFile ) . ' given.' );
36 36
         }
37
-        if (!is_string($nonce)) {
38
-            throw new TypeError('Argument 3 must be a string, ' . gettype($nonce) . ' given.');
37
+        if ( ! is_string( $nonce ) ) {
38
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $nonce ) . ' given.' );
39 39
         }
40 40
 
41 41
         /* Input validation: */
42
-        if (!is_string($keyPair)) {
43
-            throw new TypeError('Argument 4 must be a string, ' . gettype($keyPair) . ' given.');
42
+        if ( ! is_string( $keyPair ) ) {
43
+            throw new TypeError( 'Argument 4 must be a string, ' . gettype( $keyPair ) . ' given.' );
44 44
         }
45
-        if (self::strlen($nonce) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES) {
46
-            throw new TypeError('Argument 3 must be CRYPTO_BOX_NONCEBYTES bytes');
45
+        if ( self::strlen( $nonce ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES ) {
46
+            throw new TypeError( 'Argument 3 must be CRYPTO_BOX_NONCEBYTES bytes' );
47 47
         }
48
-        if (self::strlen($keyPair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) {
49
-            throw new TypeError('Argument 4 must be CRYPTO_BOX_KEYPAIRBYTES bytes');
48
+        if ( self::strlen( $keyPair ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES ) {
49
+            throw new TypeError( 'Argument 4 must be CRYPTO_BOX_KEYPAIRBYTES bytes' );
50 50
         }
51 51
 
52 52
         /** @var int $size */
53
-        $size = filesize($inputFile);
54
-        if (!is_int($size)) {
55
-            throw new Error('Could not obtain the file size');
53
+        $size = filesize( $inputFile );
54
+        if ( ! is_int( $size ) ) {
55
+            throw new Error( 'Could not obtain the file size' );
56 56
         }
57 57
 
58 58
         /** @var resource $ifp */
59
-        $ifp = fopen($inputFile, 'rb');
60
-        if (!is_resource($ifp)) {
61
-            throw new Error('Could not open input file for reading');
59
+        $ifp = fopen( $inputFile, 'rb' );
60
+        if ( ! is_resource( $ifp ) ) {
61
+            throw new Error( 'Could not open input file for reading' );
62 62
         }
63 63
 
64 64
         /** @var resource $ofp */
65
-        $ofp = fopen($outputFile, 'wb');
66
-        if (!is_resource($ofp)) {
67
-            fclose($ifp);
68
-            throw new Error('Could not open output file for writing');
65
+        $ofp = fopen( $outputFile, 'wb' );
66
+        if ( ! is_resource( $ofp ) ) {
67
+            fclose( $ifp );
68
+            throw new Error( 'Could not open output file for writing' );
69 69
         }
70 70
 
71
-        $res = self::box_encrypt($ifp, $ofp, $size, $nonce, $keyPair);
72
-        fclose($ifp);
73
-        fclose($ofp);
71
+        $res = self::box_encrypt( $ifp, $ofp, $size, $nonce, $keyPair );
72
+        fclose( $ifp );
73
+        fclose( $ofp );
74 74
         return $res;
75 75
     }
76 76
 
@@ -91,57 +91,57 @@  discard block
 block discarded – undo
91 91
      * @throws Error
92 92
      * @throws TypeError
93 93
      */
94
-    public static function box_open($inputFile, $outputFile, $nonce, $keypair)
94
+    public static function box_open( $inputFile, $outputFile, $nonce, $keypair )
95 95
     {
96 96
         /* Type checks: */
97
-        if (!is_string($inputFile)) {
98
-            throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.');
97
+        if ( ! is_string( $inputFile ) ) {
98
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $inputFile ) . ' given.' );
99 99
         }
100
-        if (!is_string($outputFile)) {
101
-            throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
100
+        if ( ! is_string( $outputFile ) ) {
101
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $outputFile ) . ' given.' );
102 102
         }
103
-        if (!is_string($nonce)) {
104
-            throw new TypeError('Argument 3 must be a string, ' . gettype($nonce) . ' given.');
103
+        if ( ! is_string( $nonce ) ) {
104
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $nonce ) . ' given.' );
105 105
         }
106
-        if (!is_string($keypair)) {
107
-            throw new TypeError('Argument 4 must be a string, ' . gettype($keypair) . ' given.');
106
+        if ( ! is_string( $keypair ) ) {
107
+            throw new TypeError( 'Argument 4 must be a string, ' . gettype( $keypair ) . ' given.' );
108 108
         }
109 109
 
110 110
         /* Input validation: */
111
-        if (self::strlen($nonce) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES) {
112
-            throw new TypeError('Argument 4 must be CRYPTO_BOX_NONCEBYTES bytes');
111
+        if ( self::strlen( $nonce ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES ) {
112
+            throw new TypeError( 'Argument 4 must be CRYPTO_BOX_NONCEBYTES bytes' );
113 113
         }
114
-        if (self::strlen($keypair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) {
115
-            throw new TypeError('Argument 4 must be CRYPTO_BOX_KEYPAIRBYTES bytes');
114
+        if ( self::strlen( $keypair ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES ) {
115
+            throw new TypeError( 'Argument 4 must be CRYPTO_BOX_KEYPAIRBYTES bytes' );
116 116
         }
117 117
 
118 118
         /** @var int $size */
119
-        $size = filesize($inputFile);
120
-        if (!is_int($size)) {
121
-            throw new Error('Could not obtain the file size');
119
+        $size = filesize( $inputFile );
120
+        if ( ! is_int( $size ) ) {
121
+            throw new Error( 'Could not obtain the file size' );
122 122
         }
123 123
 
124 124
         /** @var resource $ifp */
125
-        $ifp = fopen($inputFile, 'rb');
126
-        if (!is_resource($ifp)) {
127
-            throw new Error('Could not open input file for reading');
125
+        $ifp = fopen( $inputFile, 'rb' );
126
+        if ( ! is_resource( $ifp ) ) {
127
+            throw new Error( 'Could not open input file for reading' );
128 128
         }
129 129
 
130 130
         /** @var resource $ofp */
131
-        $ofp = fopen($outputFile, 'wb');
132
-        if (!is_resource($ofp)) {
133
-            fclose($ifp);
134
-            throw new Error('Could not open output file for writing');
131
+        $ofp = fopen( $outputFile, 'wb' );
132
+        if ( ! is_resource( $ofp ) ) {
133
+            fclose( $ifp );
134
+            throw new Error( 'Could not open output file for writing' );
135 135
         }
136 136
 
137
-        $res = self::box_decrypt($ifp, $ofp, $size, $nonce, $keypair);
138
-        fclose($ifp);
139
-        fclose($ofp);
137
+        $res = self::box_decrypt( $ifp, $ofp, $size, $nonce, $keypair );
138
+        fclose( $ifp );
139
+        fclose( $ofp );
140 140
         try {
141
-            ParagonIE_Sodium_Compat::memzero($nonce);
142
-            ParagonIE_Sodium_Compat::memzero($ephKeypair);
143
-        } catch (Error $ex) {
144
-            unset($ephKeypair);
141
+            ParagonIE_Sodium_Compat::memzero( $nonce );
142
+            ParagonIE_Sodium_Compat::memzero( $ephKeypair );
143
+        } catch ( Error $ex ) {
144
+            unset( $ephKeypair );
145 145
         }
146 146
         return $res;
147 147
     }
@@ -159,41 +159,41 @@  discard block
 block discarded – undo
159 159
      * @throws Error
160 160
      * @throws TypeError
161 161
      */
162
-    public static function box_seal($inputFile, $outputFile, $publicKey)
162
+    public static function box_seal( $inputFile, $outputFile, $publicKey )
163 163
     {
164 164
         /* Type checks: */
165
-        if (!is_string($inputFile)) {
166
-            throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.');
165
+        if ( ! is_string( $inputFile ) ) {
166
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $inputFile ) . ' given.' );
167 167
         }
168
-        if (!is_string($outputFile)) {
169
-            throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
168
+        if ( ! is_string( $outputFile ) ) {
169
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $outputFile ) . ' given.' );
170 170
         }
171
-        if (!is_string($publicKey)) {
172
-            throw new TypeError('Argument 3 must be a string, ' . gettype($publicKey) . ' given.');
171
+        if ( ! is_string( $publicKey ) ) {
172
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $publicKey ) . ' given.' );
173 173
         }
174 174
 
175 175
         /* Input validation: */
176
-        if (self::strlen($publicKey) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) {
177
-            throw new TypeError('Argument 3 must be CRYPTO_BOX_PUBLICKEYBYTES bytes');
176
+        if ( self::strlen( $publicKey ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES ) {
177
+            throw new TypeError( 'Argument 3 must be CRYPTO_BOX_PUBLICKEYBYTES bytes' );
178 178
         }
179 179
 
180 180
         /** @var int $size */
181
-        $size = filesize($inputFile);
182
-        if (!is_int($size)) {
183
-            throw new Error('Could not obtain the file size');
181
+        $size = filesize( $inputFile );
182
+        if ( ! is_int( $size ) ) {
183
+            throw new Error( 'Could not obtain the file size' );
184 184
         }
185 185
 
186 186
         /** @var resource $ifp */
187
-        $ifp = fopen($inputFile, 'rb');
188
-        if (!is_resource($ifp)) {
189
-            throw new Error('Could not open input file for reading');
187
+        $ifp = fopen( $inputFile, 'rb' );
188
+        if ( ! is_resource( $ifp ) ) {
189
+            throw new Error( 'Could not open input file for reading' );
190 190
         }
191 191
 
192 192
         /** @var resource $ofp */
193
-        $ofp = fopen($outputFile, 'wb');
194
-        if (!is_resource($ofp)) {
195
-            fclose($ifp);
196
-            throw new Error('Could not open output file for writing');
193
+        $ofp = fopen( $outputFile, 'wb' );
194
+        if ( ! is_resource( $ofp ) ) {
195
+            fclose( $ifp );
196
+            throw new Error( 'Could not open output file for writing' );
197 197
         }
198 198
 
199 199
         /** @var string $ephKeypair */
@@ -201,12 +201,12 @@  discard block
 block discarded – undo
201 201
 
202 202
         /** @var string $msgKeypair */
203 203
         $msgKeypair = ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey(
204
-            ParagonIE_Sodium_Compat::crypto_box_secretkey($ephKeypair),
204
+            ParagonIE_Sodium_Compat::crypto_box_secretkey( $ephKeypair ),
205 205
             $publicKey
206 206
         );
207 207
 
208 208
         /** @var string $ephemeralPK */
209
-        $ephemeralPK = ParagonIE_Sodium_Compat::crypto_box_publickey($ephKeypair);
209
+        $ephemeralPK = ParagonIE_Sodium_Compat::crypto_box_publickey( $ephKeypair );
210 210
 
211 211
         /** @var string $nonce */
212 212
         $nonce = ParagonIE_Sodium_Compat::crypto_generichash(
@@ -221,27 +221,27 @@  discard block
 block discarded – undo
221 221
             $ephemeralPK,
222 222
             ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES
223 223
         );
224
-        if (!is_int($firstWrite)) {
225
-            fclose($ifp);
226
-            fclose($ofp);
227
-            ParagonIE_Sodium_Compat::memzero($ephKeypair);
228
-            throw new Error('Could not write to output file');
229
-        }
230
-        if ($firstWrite !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) {
231
-            ParagonIE_Sodium_Compat::memzero($ephKeypair);
232
-            fclose($ifp);
233
-            fclose($ofp);
234
-            throw new Error('Error writing public key to output file');
235
-        }
236
-
237
-        $res = self::box_encrypt($ifp, $ofp, $size, $nonce, $msgKeypair);
238
-        fclose($ifp);
239
-        fclose($ofp);
224
+        if ( ! is_int( $firstWrite ) ) {
225
+            fclose( $ifp );
226
+            fclose( $ofp );
227
+            ParagonIE_Sodium_Compat::memzero( $ephKeypair );
228
+            throw new Error( 'Could not write to output file' );
229
+        }
230
+        if ( $firstWrite !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES ) {
231
+            ParagonIE_Sodium_Compat::memzero( $ephKeypair );
232
+            fclose( $ifp );
233
+            fclose( $ofp );
234
+            throw new Error( 'Error writing public key to output file' );
235
+        }
236
+
237
+        $res = self::box_encrypt( $ifp, $ofp, $size, $nonce, $msgKeypair );
238
+        fclose( $ifp );
239
+        fclose( $ofp );
240 240
         try {
241
-            ParagonIE_Sodium_Compat::memzero($nonce);
242
-            ParagonIE_Sodium_Compat::memzero($ephKeypair);
243
-        } catch (Error $ex) {
244
-            unset($ephKeypair);
241
+            ParagonIE_Sodium_Compat::memzero( $nonce );
242
+            ParagonIE_Sodium_Compat::memzero( $ephKeypair );
243
+        } catch ( Error $ex ) {
244
+            unset( $ephKeypair );
245 245
         }
246 246
         return $res;
247 247
     }
@@ -262,53 +262,53 @@  discard block
 block discarded – undo
262 262
      * @throws Error
263 263
      * @throws TypeError
264 264
      */
265
-    public static function box_seal_open($inputFile, $outputFile, $ecdhKeypair)
265
+    public static function box_seal_open( $inputFile, $outputFile, $ecdhKeypair )
266 266
     {
267 267
         /* Type checks: */
268
-        if (!is_string($inputFile)) {
269
-            throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.');
268
+        if ( ! is_string( $inputFile ) ) {
269
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $inputFile ) . ' given.' );
270 270
         }
271
-        if (!is_string($outputFile)) {
272
-            throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
271
+        if ( ! is_string( $outputFile ) ) {
272
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $outputFile ) . ' given.' );
273 273
         }
274
-        if (!is_string($ecdhKeypair)) {
275
-            throw new TypeError('Argument 3 must be a string, ' . gettype($ecdhKeypair) . ' given.');
274
+        if ( ! is_string( $ecdhKeypair ) ) {
275
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $ecdhKeypair ) . ' given.' );
276 276
         }
277 277
 
278 278
         /* Input validation: */
279
-        if (self::strlen($ecdhKeypair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) {
280
-            throw new TypeError('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES bytes');
279
+        if ( self::strlen( $ecdhKeypair ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES ) {
280
+            throw new TypeError( 'Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES bytes' );
281 281
         }
282 282
 
283
-        $publicKey = ParagonIE_Sodium_Compat::crypto_box_publickey($ecdhKeypair);
283
+        $publicKey = ParagonIE_Sodium_Compat::crypto_box_publickey( $ecdhKeypair );
284 284
 
285 285
         /** @var int $size */
286
-        $size = filesize($inputFile);
287
-        if (!is_int($size)) {
288
-            throw new Error('Could not obtain the file size');
286
+        $size = filesize( $inputFile );
287
+        if ( ! is_int( $size ) ) {
288
+            throw new Error( 'Could not obtain the file size' );
289 289
         }
290 290
 
291 291
         /** @var resource $ifp */
292
-        $ifp = fopen($inputFile, 'rb');
293
-        if (!is_resource($ifp)) {
294
-            throw new Error('Could not open input file for reading');
292
+        $ifp = fopen( $inputFile, 'rb' );
293
+        if ( ! is_resource( $ifp ) ) {
294
+            throw new Error( 'Could not open input file for reading' );
295 295
         }
296 296
 
297 297
         /** @var resource $ofp */
298
-        $ofp = fopen($outputFile, 'wb');
299
-        if (!is_resource($ofp)) {
300
-            fclose($ifp);
301
-            throw new Error('Could not open output file for writing');
298
+        $ofp = fopen( $outputFile, 'wb' );
299
+        if ( ! is_resource( $ofp ) ) {
300
+            fclose( $ifp );
301
+            throw new Error( 'Could not open output file for writing' );
302 302
         }
303 303
 
304
-        $ephemeralPK = fread($ifp, ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES);
305
-        if (!is_string($ephemeralPK)) {
306
-            throw new Error('Could not read input file');
304
+        $ephemeralPK = fread( $ifp, ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES );
305
+        if ( ! is_string( $ephemeralPK ) ) {
306
+            throw new Error( 'Could not read input file' );
307 307
         }
308
-        if (self::strlen($ephemeralPK) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) {
309
-            fclose($ifp);
310
-            fclose($ofp);
311
-            throw new Error('Could not read public key from sealed file');
308
+        if ( self::strlen( $ephemeralPK ) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES ) {
309
+            fclose( $ifp );
310
+            fclose( $ofp );
311
+            throw new Error( 'Could not read public key from sealed file' );
312 312
         }
313 313
 
314 314
         $nonce = ParagonIE_Sodium_Compat::crypto_generichash(
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
             24
318 318
         );
319 319
         $msgKeypair = ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey(
320
-            ParagonIE_Sodium_Compat::crypto_box_secretkey($ecdhKeypair),
320
+            ParagonIE_Sodium_Compat::crypto_box_secretkey( $ecdhKeypair ),
321 321
             $ephemeralPK
322 322
         );
323 323
 
324
-        $res = self::box_decrypt($ifp, $ofp, $size, $nonce, $msgKeypair);
325
-        fclose($ifp);
326
-        fclose($ofp);
324
+        $res = self::box_decrypt( $ifp, $ofp, $size, $nonce, $msgKeypair );
325
+        fclose( $ifp );
326
+        fclose( $ofp );
327 327
         try {
328
-            ParagonIE_Sodium_Compat::memzero($nonce);
329
-            ParagonIE_Sodium_Compat::memzero($ephKeypair);
330
-        } catch (Error $ex) {
331
-            unset($ephKeypair);
328
+            ParagonIE_Sodium_Compat::memzero( $nonce );
329
+            ParagonIE_Sodium_Compat::memzero( $ephKeypair );
330
+        } catch ( Error $ex ) {
331
+            unset( $ephKeypair );
332 332
         }
333 333
         return $res;
334 334
     }
@@ -345,68 +345,68 @@  discard block
 block discarded – undo
345 345
      * @throws TypeError
346 346
      * @psalm-suppress FailedTypeResolution
347 347
      */
348
-    public static function generichash($filePath, $key = '', $outputLength = 32)
348
+    public static function generichash( $filePath, $key = '', $outputLength = 32 )
349 349
     {
350 350
         /* Type checks: */
351
-        if (!is_string($filePath)) {
352
-            throw new TypeError('Argument 1 must be a string, ' . gettype($filePath) . ' given.');
351
+        if ( ! is_string( $filePath ) ) {
352
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $filePath ) . ' given.' );
353 353
         }
354
-        if (!is_string($key)) {
355
-            if (is_null($key)) {
354
+        if ( ! is_string( $key ) ) {
355
+            if ( is_null( $key ) ) {
356 356
                 $key = '';
357 357
             } else {
358
-                throw new TypeError('Argument 2 must be a string, ' . gettype($key) . ' given.');
358
+                throw new TypeError( 'Argument 2 must be a string, ' . gettype( $key ) . ' given.' );
359 359
             }
360 360
         }
361
-        if (!is_int($outputLength)) {
362
-            if (!is_numeric($outputLength)) {
363
-                throw new TypeError('Argument 3 must be an integer, ' . gettype($outputLength) . ' given.');
361
+        if ( ! is_int( $outputLength ) ) {
362
+            if ( ! is_numeric( $outputLength ) ) {
363
+                throw new TypeError( 'Argument 3 must be an integer, ' . gettype( $outputLength ) . ' given.' );
364 364
             }
365 365
             $outputLength = (int) $outputLength;
366 366
         }
367 367
 
368 368
         /* Input validation: */
369
-        if (!empty($key)) {
370
-            if (self::strlen($key) < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MIN) {
371
-                throw new TypeError('Argument 2 must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes');
369
+        if ( ! empty( $key ) ) {
370
+            if ( self::strlen( $key ) < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MIN ) {
371
+                throw new TypeError( 'Argument 2 must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes' );
372 372
             }
373
-            if (self::strlen($key) > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MAX) {
374
-                throw new TypeError('Argument 2 must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes');
373
+            if ( self::strlen( $key ) > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MAX ) {
374
+                throw new TypeError( 'Argument 2 must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes' );
375 375
             }
376 376
         }
377
-        if ($outputLength < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MIN) {
378
-            throw new Error('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MIN');
377
+        if ( $outputLength < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MIN ) {
378
+            throw new Error( 'Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MIN' );
379 379
         }
380
-        if ($outputLength > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MAX) {
381
-            throw new Error('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MAX');
380
+        if ( $outputLength > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MAX ) {
381
+            throw new Error( 'Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MAX' );
382 382
         }
383 383
 
384 384
         /** @var int $size */
385
-        $size = filesize($filePath);
386
-        if (!is_int($size)) {
387
-            throw new Error('Could not obtain the file size');
385
+        $size = filesize( $filePath );
386
+        if ( ! is_int( $size ) ) {
387
+            throw new Error( 'Could not obtain the file size' );
388 388
         }
389 389
 
390 390
         /** @var resource $fp */
391
-        $fp = fopen($filePath, 'rb');
392
-        if (!is_resource($fp)) {
393
-            throw new Error('Could not open input file for reading');
391
+        $fp = fopen( $filePath, 'rb' );
392
+        if ( ! is_resource( $fp ) ) {
393
+            throw new Error( 'Could not open input file for reading' );
394 394
         }
395
-        $ctx = ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outputLength);
396
-        while ($size > 0) {
395
+        $ctx = ParagonIE_Sodium_Compat::crypto_generichash_init( $key, $outputLength );
396
+        while ( $size > 0 ) {
397 397
             $blockSize = $size > 64
398 398
                 ? 64
399 399
                 : $size;
400
-            $read = fread($fp, $blockSize);
401
-            if (!is_string($read)) {
402
-                throw new Error('Could not read input file');
400
+            $read = fread( $fp, $blockSize );
401
+            if ( ! is_string( $read ) ) {
402
+                throw new Error( 'Could not read input file' );
403 403
             }
404
-            ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $read);
404
+            ParagonIE_Sodium_Compat::crypto_generichash_update( $ctx, $read );
405 405
             $size -= $blockSize;
406 406
         }
407 407
 
408
-        fclose($fp);
409
-        return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength);
408
+        fclose( $fp );
409
+        return ParagonIE_Sodium_Compat::crypto_generichash_final( $ctx, $outputLength );
410 410
     }
411 411
 
412 412
     /**
@@ -423,52 +423,52 @@  discard block
 block discarded – undo
423 423
      * @throws Error
424 424
      * @throws TypeError
425 425
      */
426
-    public static function secretbox($inputFile, $outputFile, $nonce, $key)
426
+    public static function secretbox( $inputFile, $outputFile, $nonce, $key )
427 427
     {
428 428
         /* Type checks: */
429
-        if (!is_string($inputFile)) {
430
-            throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given..');
429
+        if ( ! is_string( $inputFile ) ) {
430
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $inputFile ) . ' given..' );
431 431
         }
432
-        if (!is_string($outputFile)) {
433
-            throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
432
+        if ( ! is_string( $outputFile ) ) {
433
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $outputFile ) . ' given.' );
434 434
         }
435
-        if (!is_string($nonce)) {
436
-            throw new TypeError('Argument 3 must be a string, ' . gettype($nonce) . ' given.');
435
+        if ( ! is_string( $nonce ) ) {
436
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $nonce ) . ' given.' );
437 437
         }
438 438
 
439 439
         /* Input validation: */
440
-        if (self::strlen($nonce) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_NONCEBYTES) {
441
-            throw new TypeError('Argument 3 must be CRYPTO_SECRETBOX_NONCEBYTES bytes');
440
+        if ( self::strlen( $nonce ) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_NONCEBYTES ) {
441
+            throw new TypeError( 'Argument 3 must be CRYPTO_SECRETBOX_NONCEBYTES bytes' );
442 442
         }
443
-        if (!is_string($key)) {
444
-            throw new TypeError('Argument 4 must be a string, ' . gettype($key) . ' given.');
443
+        if ( ! is_string( $key ) ) {
444
+            throw new TypeError( 'Argument 4 must be a string, ' . gettype( $key ) . ' given.' );
445 445
         }
446
-        if (self::strlen($key) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_KEYBYTES) {
447
-            throw new TypeError('Argument 4 must be CRYPTO_SECRETBOX_KEYBYTES bytes');
446
+        if ( self::strlen( $key ) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_KEYBYTES ) {
447
+            throw new TypeError( 'Argument 4 must be CRYPTO_SECRETBOX_KEYBYTES bytes' );
448 448
         }
449 449
 
450 450
         /** @var int $size */
451
-        $size = filesize($inputFile);
452
-        if (!is_int($size)) {
453
-            throw new Error('Could not obtain the file size');
451
+        $size = filesize( $inputFile );
452
+        if ( ! is_int( $size ) ) {
453
+            throw new Error( 'Could not obtain the file size' );
454 454
         }
455 455
 
456 456
         /** @var resource $ifp */
457
-        $ifp = fopen($inputFile, 'rb');
458
-        if (!is_resource($ifp)) {
459
-            throw new Error('Could not open input file for reading');
457
+        $ifp = fopen( $inputFile, 'rb' );
458
+        if ( ! is_resource( $ifp ) ) {
459
+            throw new Error( 'Could not open input file for reading' );
460 460
         }
461 461
 
462 462
         /** @var resource $ofp */
463
-        $ofp = fopen($outputFile, 'wb');
464
-        if (!is_resource($ofp)) {
465
-            fclose($ifp);
466
-            throw new Error('Could not open output file for writing');
463
+        $ofp = fopen( $outputFile, 'wb' );
464
+        if ( ! is_resource( $ofp ) ) {
465
+            fclose( $ifp );
466
+            throw new Error( 'Could not open output file for writing' );
467 467
         }
468 468
 
469
-        $res = self::secretbox_encrypt($ifp, $ofp, $size, $nonce, $key);
470
-        fclose($ifp);
471
-        fclose($ofp);
469
+        $res = self::secretbox_encrypt( $ifp, $ofp, $size, $nonce, $key );
470
+        fclose( $ifp );
471
+        fclose( $ofp );
472 472
         return $res;
473 473
     }
474 474
     /**
@@ -488,56 +488,56 @@  discard block
 block discarded – undo
488 488
      * @throws Error
489 489
      * @throws TypeError
490 490
      */
491
-    public static function secretbox_open($inputFile, $outputFile, $nonce, $key)
491
+    public static function secretbox_open( $inputFile, $outputFile, $nonce, $key )
492 492
     {
493 493
         /* Type checks: */
494
-        if (!is_string($inputFile)) {
495
-            throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.');
494
+        if ( ! is_string( $inputFile ) ) {
495
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $inputFile ) . ' given.' );
496 496
         }
497
-        if (!is_string($outputFile)) {
498
-            throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
497
+        if ( ! is_string( $outputFile ) ) {
498
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $outputFile ) . ' given.' );
499 499
         }
500
-        if (!is_string($nonce)) {
501
-            throw new TypeError('Argument 3 must be a string, ' . gettype($nonce) . ' given.');
500
+        if ( ! is_string( $nonce ) ) {
501
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $nonce ) . ' given.' );
502 502
         }
503
-        if (!is_string($key)) {
504
-            throw new TypeError('Argument 4 must be a string, ' . gettype($key) . ' given.');
503
+        if ( ! is_string( $key ) ) {
504
+            throw new TypeError( 'Argument 4 must be a string, ' . gettype( $key ) . ' given.' );
505 505
         }
506 506
 
507 507
         /* Input validation: */
508
-        if (self::strlen($nonce) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_NONCEBYTES) {
509
-            throw new TypeError('Argument 4 must be CRYPTO_SECRETBOX_NONCEBYTES bytes');
508
+        if ( self::strlen( $nonce ) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_NONCEBYTES ) {
509
+            throw new TypeError( 'Argument 4 must be CRYPTO_SECRETBOX_NONCEBYTES bytes' );
510 510
         }
511
-        if (self::strlen($key) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_KEYBYTES) {
512
-            throw new TypeError('Argument 4 must be CRYPTO_SECRETBOXBOX_KEYBYTES bytes');
511
+        if ( self::strlen( $key ) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_KEYBYTES ) {
512
+            throw new TypeError( 'Argument 4 must be CRYPTO_SECRETBOXBOX_KEYBYTES bytes' );
513 513
         }
514 514
 
515 515
         /** @var int $size */
516
-        $size = filesize($inputFile);
517
-        if (!is_int($size)) {
518
-            throw new Error('Could not obtain the file size');
516
+        $size = filesize( $inputFile );
517
+        if ( ! is_int( $size ) ) {
518
+            throw new Error( 'Could not obtain the file size' );
519 519
         }
520 520
 
521 521
         /** @var resource $ifp */
522
-        $ifp = fopen($inputFile, 'rb');
523
-        if (!is_resource($ifp)) {
524
-            throw new Error('Could not open input file for reading');
522
+        $ifp = fopen( $inputFile, 'rb' );
523
+        if ( ! is_resource( $ifp ) ) {
524
+            throw new Error( 'Could not open input file for reading' );
525 525
         }
526 526
 
527 527
         /** @var resource $ofp */
528
-        $ofp = fopen($outputFile, 'wb');
529
-        if (!is_resource($ofp)) {
530
-            fclose($ifp);
531
-            throw new Error('Could not open output file for writing');
528
+        $ofp = fopen( $outputFile, 'wb' );
529
+        if ( ! is_resource( $ofp ) ) {
530
+            fclose( $ifp );
531
+            throw new Error( 'Could not open output file for writing' );
532 532
         }
533 533
 
534
-        $res = self::secretbox_decrypt($ifp, $ofp, $size, $nonce, $key);
535
-        fclose($ifp);
536
-        fclose($ofp);
534
+        $res = self::secretbox_decrypt( $ifp, $ofp, $size, $nonce, $key );
535
+        fclose( $ifp );
536
+        fclose( $ofp );
537 537
         try {
538
-            ParagonIE_Sodium_Compat::memzero($key);
539
-        } catch (Error $ex) {
540
-            unset($key);
538
+            ParagonIE_Sodium_Compat::memzero( $key );
539
+        } catch ( Error $ex ) {
540
+            unset( $key );
541 541
         }
542 542
         return $res;
543 543
     }
@@ -554,82 +554,82 @@  discard block
 block discarded – undo
554 554
      * @throws Error
555 555
      * @throws TypeError
556 556
      */
557
-    public static function sign($filePath, $secretKey)
557
+    public static function sign( $filePath, $secretKey )
558 558
     {
559 559
         /* Type checks: */
560
-        if (!is_string($filePath)) {
561
-            throw new TypeError('Argument 1 must be a string, ' . gettype($filePath) . ' given.');
560
+        if ( ! is_string( $filePath ) ) {
561
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $filePath ) . ' given.' );
562 562
         }
563
-        if (!is_string($secretKey)) {
564
-            throw new TypeError('Argument 2 must be a string, ' . gettype($secretKey) . ' given.');
563
+        if ( ! is_string( $secretKey ) ) {
564
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $secretKey ) . ' given.' );
565 565
         }
566 566
 
567 567
         /* Input validation: */
568
-        if (self::strlen($secretKey) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_SECRETKEYBYTES) {
569
-            throw new TypeError('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES bytes');
568
+        if ( self::strlen( $secretKey ) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_SECRETKEYBYTES ) {
569
+            throw new TypeError( 'Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES bytes' );
570 570
         }
571 571
 
572 572
         /** @var int $size */
573
-        $size = filesize($filePath);
574
-        if (!is_int($size)) {
575
-            throw new Error('Could not obtain the file size');
573
+        $size = filesize( $filePath );
574
+        if ( ! is_int( $size ) ) {
575
+            throw new Error( 'Could not obtain the file size' );
576 576
         }
577 577
 
578 578
         /** @var resource $fp */
579
-        $fp = fopen($filePath, 'rb');
580
-        if (!is_resource($fp)) {
581
-            throw new Error('Could not open input file for reading');
579
+        $fp = fopen( $filePath, 'rb' );
580
+        if ( ! is_resource( $fp ) ) {
581
+            throw new Error( 'Could not open input file for reading' );
582 582
         }
583 583
 
584 584
         /** @var string $az */
585
-        $az = hash('sha512', self::substr($secretKey, 0, 32), true);
585
+        $az = hash( 'sha512', self::substr( $secretKey, 0, 32 ), true );
586 586
 
587
-        $az[0] = self::intToChr(self::chrToInt($az[0]) & 248);
588
-        $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64);
587
+        $az[0] = self::intToChr( self::chrToInt( $az[0] ) & 248 );
588
+        $az[31] = self::intToChr( ( self::chrToInt( $az[31] ) & 63 ) | 64 );
589 589
 
590 590
         /** @var resource $hs */
591
-        $hs = hash_init('sha512');
592
-        hash_update($hs, self::substr($az, 32, 32));
593
-        $hs = self::updateHashWithFile($hs, $fp, $size);
591
+        $hs = hash_init( 'sha512' );
592
+        hash_update( $hs, self::substr( $az, 32, 32 ) );
593
+        $hs = self::updateHashWithFile( $hs, $fp, $size );
594 594
 
595 595
         /** @var string $nonceHash */
596
-        $nonceHash = hash_final($hs, true);
596
+        $nonceHash = hash_final( $hs, true );
597 597
 
598 598
         /** @var string $pk */
599
-        $pk = self::substr($secretKey, 32, 32);
599
+        $pk = self::substr( $secretKey, 32, 32 );
600 600
 
601 601
         /** @var string $nonce */
602
-        $nonce = ParagonIE_Sodium_Core_Ed25519::sc_reduce($nonceHash) . self::substr($nonceHash, 32);
602
+        $nonce = ParagonIE_Sodium_Core_Ed25519::sc_reduce( $nonceHash ) . self::substr( $nonceHash, 32 );
603 603
 
604 604
         /** @var string $sig */
605 605
         $sig = ParagonIE_Sodium_Core_Ed25519::ge_p3_tobytes(
606
-            ParagonIE_Sodium_Core_Ed25519::ge_scalarmult_base($nonce)
606
+            ParagonIE_Sodium_Core_Ed25519::ge_scalarmult_base( $nonce )
607 607
         );
608 608
 
609 609
         /** @var resource $hs */
610
-        $hs = hash_init('sha512');
611
-        hash_update($hs, self::substr($sig, 0, 32));
612
-        hash_update($hs, self::substr($pk, 0, 32));
613
-        $hs = self::updateHashWithFile($hs, $fp, $size);
610
+        $hs = hash_init( 'sha512' );
611
+        hash_update( $hs, self::substr( $sig, 0, 32 ) );
612
+        hash_update( $hs, self::substr( $pk, 0, 32 ) );
613
+        $hs = self::updateHashWithFile( $hs, $fp, $size );
614 614
 
615 615
         /** @var string $hramHash */
616
-        $hramHash = hash_final($hs, true);
616
+        $hramHash = hash_final( $hs, true );
617 617
 
618 618
         /** @var string $hram */
619
-        $hram = ParagonIE_Sodium_Core_Ed25519::sc_reduce($hramHash);
619
+        $hram = ParagonIE_Sodium_Core_Ed25519::sc_reduce( $hramHash );
620 620
 
621 621
         /** @var string $sigAfter */
622
-        $sigAfter = ParagonIE_Sodium_Core_Ed25519::sc_muladd($hram, $az, $nonce);
622
+        $sigAfter = ParagonIE_Sodium_Core_Ed25519::sc_muladd( $hram, $az, $nonce );
623 623
 
624 624
         /** @var string $sig */
625
-        $sig = self::substr($sig, 0, 32) . self::substr($sigAfter, 0, 32);
625
+        $sig = self::substr( $sig, 0, 32 ) . self::substr( $sigAfter, 0, 32 );
626 626
 
627 627
         try {
628
-            ParagonIE_Sodium_Compat::memzero($az);
629
-        } catch (Error $ex) {
628
+            ParagonIE_Sodium_Compat::memzero( $az );
629
+        } catch ( Error $ex ) {
630 630
             $az = null;
631 631
         }
632
-        fclose($fp);
632
+        fclose( $fp );
633 633
         return $sig;
634 634
     }
635 635
 
@@ -646,58 +646,58 @@  discard block
 block discarded – undo
646 646
      * @throws Error
647 647
      * @throws Exception
648 648
      */
649
-    public static function verify($sig, $filePath, $publicKey)
649
+    public static function verify( $sig, $filePath, $publicKey )
650 650
     {
651 651
         /* Type checks: */
652
-        if (!is_string($sig)) {
653
-            throw new TypeError('Argument 1 must be a string, ' . gettype($sig) . ' given.');
652
+        if ( ! is_string( $sig ) ) {
653
+            throw new TypeError( 'Argument 1 must be a string, ' . gettype( $sig ) . ' given.' );
654 654
         }
655
-        if (!is_string($filePath)) {
656
-            throw new TypeError('Argument 2 must be a string, ' . gettype($filePath) . ' given.');
655
+        if ( ! is_string( $filePath ) ) {
656
+            throw new TypeError( 'Argument 2 must be a string, ' . gettype( $filePath ) . ' given.' );
657 657
         }
658
-        if (!is_string($publicKey)) {
659
-            throw new TypeError('Argument 3 must be a string, ' . gettype($publicKey) . ' given.');
658
+        if ( ! is_string( $publicKey ) ) {
659
+            throw new TypeError( 'Argument 3 must be a string, ' . gettype( $publicKey ) . ' given.' );
660 660
         }
661 661
 
662 662
         /* Input validation: */
663
-        if (self::strlen($sig) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_BYTES) {
664
-            throw new TypeError('Argument 1 must be CRYPTO_SIGN_BYTES bytes');
663
+        if ( self::strlen( $sig ) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_BYTES ) {
664
+            throw new TypeError( 'Argument 1 must be CRYPTO_SIGN_BYTES bytes' );
665 665
         }
666
-        if (self::strlen($publicKey) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_PUBLICKEYBYTES) {
667
-            throw new TypeError('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES bytes');
666
+        if ( self::strlen( $publicKey ) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_PUBLICKEYBYTES ) {
667
+            throw new TypeError( 'Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES bytes' );
668 668
         }
669
-        if (self::strlen($sig) < 64) {
670
-            throw new Exception('Signature is too short');
669
+        if ( self::strlen( $sig ) < 64 ) {
670
+            throw new Exception( 'Signature is too short' );
671 671
         }
672 672
 
673 673
         /* Security checks */
674
-        if (ParagonIE_Sodium_Core_Ed25519::check_S_lt_L(self::substr($sig, 32, 32))) {
675
-            throw new Exception('S < L - Invalid signature');
674
+        if ( ParagonIE_Sodium_Core_Ed25519::check_S_lt_L( self::substr( $sig, 32, 32 ) ) ) {
675
+            throw new Exception( 'S < L - Invalid signature' );
676 676
         }
677
-        if (ParagonIE_Sodium_Core_Ed25519::small_order($sig)) {
678
-            throw new Exception('Signature is on too small of an order');
677
+        if ( ParagonIE_Sodium_Core_Ed25519::small_order( $sig ) ) {
678
+            throw new Exception( 'Signature is on too small of an order' );
679 679
         }
680
-        if ((self::chrToInt($sig[63]) & 224) !== 0) {
681
-            throw new Exception('Invalid signature');
680
+        if ( ( self::chrToInt( $sig[63] ) & 224 ) !== 0 ) {
681
+            throw new Exception( 'Invalid signature' );
682 682
         }
683 683
         $d = 0;
684
-        for ($i = 0; $i < 32; ++$i) {
685
-            $d |= self::chrToInt($publicKey[$i]);
684
+        for ( $i = 0; $i < 32; ++$i ) {
685
+            $d |= self::chrToInt( $publicKey[$i] );
686 686
         }
687
-        if ($d === 0) {
688
-            throw new Exception('All zero public key');
687
+        if ( $d === 0 ) {
688
+            throw new Exception( 'All zero public key' );
689 689
         }
690 690
 
691 691
         /** @var int $size */
692
-        $size = filesize($filePath);
693
-        if (!is_int($size)) {
694
-            throw new Error('Could not obtain the file size');
692
+        $size = filesize( $filePath );
693
+        if ( ! is_int( $size ) ) {
694
+            throw new Error( 'Could not obtain the file size' );
695 695
         }
696 696
 
697 697
         /** @var resource $fp */
698
-        $fp = fopen($filePath, 'rb');
699
-        if (!is_resource($fp)) {
700
-            throw new Error('Could not open input file for reading');
698
+        $fp = fopen( $filePath, 'rb' );
699
+        if ( ! is_resource( $fp ) ) {
700
+            throw new Error( 'Could not open input file for reading' );
701 701
         }
702 702
 
703 703
         /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */
@@ -707,35 +707,35 @@  discard block
 block discarded – undo
707 707
         ParagonIE_Sodium_Compat::$fastMult = true;
708 708
 
709 709
         /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A */
710
-        $A = ParagonIE_Sodium_Core_Ed25519::ge_frombytes_negate_vartime($publicKey);
710
+        $A = ParagonIE_Sodium_Core_Ed25519::ge_frombytes_negate_vartime( $publicKey );
711 711
 
712 712
         /** @var resource $hs */
713
-        $hs = hash_init('sha512');
714
-        hash_update($hs, self::substr($sig, 0, 32));
715
-        hash_update($hs, self::substr($publicKey, 0, 32));
716
-        $hs = self::updateHashWithFile($hs, $fp, $size);
713
+        $hs = hash_init( 'sha512' );
714
+        hash_update( $hs, self::substr( $sig, 0, 32 ) );
715
+        hash_update( $hs, self::substr( $publicKey, 0, 32 ) );
716
+        $hs = self::updateHashWithFile( $hs, $fp, $size );
717 717
         /** @var string $hDigest */
718
-        $hDigest = hash_final($hs, true);
718
+        $hDigest = hash_final( $hs, true );
719 719
 
720 720
         /** @var string $h */
721
-        $h = ParagonIE_Sodium_Core_Ed25519::sc_reduce($hDigest) . self::substr($hDigest, 32);
721
+        $h = ParagonIE_Sodium_Core_Ed25519::sc_reduce( $hDigest ) . self::substr( $hDigest, 32 );
722 722
 
723 723
         /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P2 $R */
724 724
         $R = ParagonIE_Sodium_Core_Ed25519::ge_double_scalarmult_vartime(
725 725
             $h,
726 726
             $A,
727
-            self::substr($sig, 32)
727
+            self::substr( $sig, 32 )
728 728
         );
729 729
 
730 730
         /** @var string $rcheck */
731
-        $rcheck = ParagonIE_Sodium_Core_Ed25519::ge_tobytes($R);
731
+        $rcheck = ParagonIE_Sodium_Core_Ed25519::ge_tobytes( $R );
732 732
 
733 733
         // Close the file handle
734
-        fclose($fp);
734
+        fclose( $fp );
735 735
 
736 736
         // Reset ParagonIE_Sodium_Compat::$fastMult to what it was before.
737 737
         ParagonIE_Sodium_Compat::$fastMult = $orig;
738
-        return self::verify_32($rcheck, self::substr($sig, 0, 32));
738
+        return self::verify_32( $rcheck, self::substr( $sig, 0, 32 ) );
739 739
     }
740 740
 
741 741
     /**
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
      * @param string   $boxKeypair
747 747
      * @return bool
748 748
      */
749
-    protected static function box_encrypt($ifp, $ofp, $mlen, $nonce, $boxKeypair)
749
+    protected static function box_encrypt( $ifp, $ofp, $mlen, $nonce, $boxKeypair )
750 750
     {
751 751
         return self::secretbox_encrypt(
752 752
             $ifp,
@@ -754,8 +754,8 @@  discard block
 block discarded – undo
754 754
             $mlen,
755 755
             $nonce,
756 756
             ParagonIE_Sodium_Crypto::box_beforenm(
757
-                ParagonIE_Sodium_Crypto::box_secretkey($boxKeypair),
758
-                ParagonIE_Sodium_Crypto::box_publickey($boxKeypair)
757
+                ParagonIE_Sodium_Crypto::box_secretkey( $boxKeypair ),
758
+                ParagonIE_Sodium_Crypto::box_publickey( $boxKeypair )
759 759
             )
760 760
         );
761 761
     }
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
      * @param string   $boxKeypair
770 770
      * @return bool
771 771
      */
772
-    protected static function box_decrypt($ifp, $ofp, $mlen, $nonce, $boxKeypair)
772
+    protected static function box_decrypt( $ifp, $ofp, $mlen, $nonce, $boxKeypair )
773 773
     {
774 774
         return self::secretbox_decrypt(
775 775
             $ifp,
@@ -777,8 +777,8 @@  discard block
 block discarded – undo
777 777
             $mlen,
778 778
             $nonce,
779 779
             ParagonIE_Sodium_Crypto::box_beforenm(
780
-                ParagonIE_Sodium_Crypto::box_secretkey($boxKeypair),
781
-                ParagonIE_Sodium_Crypto::box_publickey($boxKeypair)
780
+                ParagonIE_Sodium_Crypto::box_secretkey( $boxKeypair ),
781
+                ParagonIE_Sodium_Crypto::box_publickey( $boxKeypair )
782 782
             )
783 783
         );
784 784
     }
@@ -794,29 +794,29 @@  discard block
 block discarded – undo
794 794
      * @return bool
795 795
      * @throws Error
796 796
      */
797
-    protected static function secretbox_encrypt($ifp, $ofp, $mlen, $nonce, $key)
797
+    protected static function secretbox_encrypt( $ifp, $ofp, $mlen, $nonce, $key )
798 798
     {
799
-        $plaintext = fread($ifp, 32);
800
-        if (!is_string($plaintext)) {
801
-            throw new Error('Could not read input file');
799
+        $plaintext = fread( $ifp, 32 );
800
+        if ( ! is_string( $plaintext ) ) {
801
+            throw new Error( 'Could not read input file' );
802 802
         }
803
-        $first32 = ftell($ifp);
803
+        $first32 = ftell( $ifp );
804 804
 
805 805
         /** @var string $subkey */
806
-        $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20($nonce, $key);
806
+        $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20( $nonce, $key );
807 807
 
808 808
         /** @var string $realNonce */
809
-        $realNonce = ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8);
809
+        $realNonce = ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 );
810 810
 
811 811
         /** @var string $block0 */
812
-        $block0 = str_repeat("\x00", 32);
812
+        $block0 = str_repeat( "\x00", 32 );
813 813
 
814 814
         /** @var int $mlen - Length of the plaintext message */
815 815
         $mlen0 = $mlen;
816
-        if ($mlen0 > 64 - ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES) {
816
+        if ( $mlen0 > 64 - ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES ) {
817 817
             $mlen0 = 64 - ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES;
818 818
         }
819
-        $block0 .= ParagonIE_Sodium_Core_Util::substr($plaintext, 0, $mlen0);
819
+        $block0 .= ParagonIE_Sodium_Core_Util::substr( $plaintext, 0, $mlen0 );
820 820
 
821 821
         /** @var string $block0 */
822 822
         $block0 = ParagonIE_Sodium_Core_Salsa20::salsa20_xor(
@@ -834,16 +834,16 @@  discard block
 block discarded – undo
834 834
         );
835 835
 
836 836
         // Pre-write 16 blank bytes for the Poly1305 tag
837
-        $start = ftell($ofp);
838
-        fwrite($ofp, str_repeat("\x00", 16));
837
+        $start = ftell( $ofp );
838
+        fwrite( $ofp, str_repeat( "\x00", 16 ) );
839 839
 
840 840
         /** @var string $c */
841 841
         $cBlock = ParagonIE_Sodium_Core_Util::substr(
842 842
             $block0,
843 843
             ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES
844 844
         );
845
-        $state->update($cBlock);
846
-        fwrite($ofp, $cBlock);
845
+        $state->update( $cBlock );
846
+        fwrite( $ofp, $cBlock );
847 847
         $mlen -= 32;
848 848
 
849 849
         /** @var int $iter */
@@ -856,15 +856,15 @@  discard block
 block discarded – undo
856 856
          * Set the cursor to the end of the first half-block. All future bytes will
857 857
          * generated from salsa20_xor_ic, starting from 1 (second block).
858 858
          */
859
-        fseek($ifp, $first32, SEEK_SET);
859
+        fseek( $ifp, $first32, SEEK_SET );
860 860
 
861
-        while ($mlen > 0) {
861
+        while ( $mlen > 0 ) {
862 862
             $blockSize = $mlen > self::BUFFER_SIZE
863 863
                 ? self::BUFFER_SIZE
864 864
                 : $mlen;
865
-            $plaintext = fread($ifp, $blockSize);
866
-            if (!is_string($plaintext)) {
867
-                throw new Error('Could not read input file');
865
+            $plaintext = fread( $ifp, $blockSize );
866
+            if ( ! is_string( $plaintext ) ) {
867
+                throw new Error( 'Could not read input file' );
868 868
             }
869 869
             $cBlock = ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic(
870 870
                 $plaintext,
@@ -872,29 +872,29 @@  discard block
 block discarded – undo
872 872
                 $iter,
873 873
                 $subkey
874 874
             );
875
-            fwrite($ofp, $cBlock, $blockSize);
876
-            $state->update($cBlock);
875
+            fwrite( $ofp, $cBlock, $blockSize );
876
+            $state->update( $cBlock );
877 877
 
878 878
             $mlen -= $blockSize;
879 879
             $iter += $incr;
880 880
         }
881 881
         try {
882
-            ParagonIE_Sodium_Compat::memzero($block0);
883
-            ParagonIE_Sodium_Compat::memzero($subkey);
884
-        } catch (Error $ex) {
882
+            ParagonIE_Sodium_Compat::memzero( $block0 );
883
+            ParagonIE_Sodium_Compat::memzero( $subkey );
884
+        } catch ( Error $ex ) {
885 885
             $block0 = null;
886 886
             $subkey = null;
887 887
         }
888
-        $end = ftell($ofp);
888
+        $end = ftell( $ofp );
889 889
 
890 890
         /*
891 891
          * Write the Poly1305 authentication tag that provides integrity
892 892
          * over the ciphertext (encrypt-then-MAC)
893 893
          */
894
-        fseek($ofp, $start, SEEK_SET);
895
-        fwrite($ofp, $state->finish(), ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_MACBYTES);
896
-        fseek($ofp, $end, SEEK_SET);
897
-        unset($state);
894
+        fseek( $ofp, $start, SEEK_SET );
895
+        fwrite( $ofp, $state->finish(), ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_MACBYTES );
896
+        fseek( $ofp, $end, SEEK_SET );
897
+        unset( $state );
898 898
 
899 899
         return true;
900 900
     }
@@ -911,46 +911,46 @@  discard block
 block discarded – undo
911 911
      * @throws Error
912 912
      * @throws Exception
913 913
      */
914
-    protected static function secretbox_decrypt($ifp, $ofp, $mlen, $nonce, $key)
914
+    protected static function secretbox_decrypt( $ifp, $ofp, $mlen, $nonce, $key )
915 915
     {
916
-        $tag = fread($ifp, 16);
917
-        if (!is_string($tag)) {
918
-            throw new Error('Could not read input file');
916
+        $tag = fread( $ifp, 16 );
917
+        if ( ! is_string( $tag ) ) {
918
+            throw new Error( 'Could not read input file' );
919 919
         }
920 920
 
921 921
         /** @var string $subkey */
922
-        $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20($nonce, $key);
922
+        $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20( $nonce, $key );
923 923
 
924 924
         /** @var string $realNonce */
925
-        $realNonce = ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8);
925
+        $realNonce = ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 );
926 926
 
927 927
         /** @var string $block0 */
928 928
         $block0 = ParagonIE_Sodium_Core_Salsa20::salsa20(
929 929
             64,
930
-            ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8),
930
+            ParagonIE_Sodium_Core_Util::substr( $nonce, 16, 8 ),
931 931
             $subkey
932 932
         );
933 933
 
934 934
         /* Verify the Poly1305 MAC -before- attempting to decrypt! */
935
-        $state = new ParagonIE_Sodium_Core_Poly1305_State(self::substr($block0, 0, 32));
936
-        if (!self::onetimeauth_verify($state, $ifp, $tag, $mlen)) {
937
-            throw new Exception('Invalid MAC');
935
+        $state = new ParagonIE_Sodium_Core_Poly1305_State( self::substr( $block0, 0, 32 ) );
936
+        if ( ! self::onetimeauth_verify( $state, $ifp, $tag, $mlen ) ) {
937
+            throw new Exception( 'Invalid MAC' );
938 938
         }
939 939
 
940 940
         /*
941 941
          * Set the cursor to the end of the first half-block. All future bytes will
942 942
          * generated from salsa20_xor_ic, starting from 1 (second block).
943 943
          */
944
-        $first32 = fread($ifp, 32);
945
-        if (!is_string($first32)) {
946
-            throw new Error('Could not read input file');
944
+        $first32 = fread( $ifp, 32 );
945
+        if ( ! is_string( $first32 ) ) {
946
+            throw new Error( 'Could not read input file' );
947 947
         }
948
-        $first32len = self::strlen($first32);
948
+        $first32len = self::strlen( $first32 );
949 949
         fwrite(
950 950
             $ofp,
951 951
             self::xorStrings(
952
-                self::substr($block0, 32, $first32len),
953
-                self::substr($first32, 0, $first32len)
952
+                self::substr( $block0, 32, $first32len ),
953
+                self::substr( $first32, 0, $first32len )
954 954
             )
955 955
         );
956 956
         $mlen -= 32;
@@ -962,13 +962,13 @@  discard block
 block discarded – undo
962 962
         $incr = self::BUFFER_SIZE >> 6;
963 963
 
964 964
         /* Decrypts ciphertext, writes to output file. */
965
-        while ($mlen > 0) {
965
+        while ( $mlen > 0 ) {
966 966
             $blockSize = $mlen > self::BUFFER_SIZE
967 967
                 ? self::BUFFER_SIZE
968 968
                 : $mlen;
969
-            $ciphertext = fread($ifp, $blockSize);
970
-            if (!is_string($ciphertext)) {
971
-                throw new Error('Could not read input file');
969
+            $ciphertext = fread( $ifp, $blockSize );
970
+            if ( ! is_string( $ciphertext ) ) {
971
+                throw new Error( 'Could not read input file' );
972 972
             }
973 973
             $pBlock = ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic(
974 974
                 $ciphertext,
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
                 $iter,
977 977
                 $subkey
978 978
             );
979
-            fwrite($ofp, $pBlock, $blockSize);
979
+            fwrite( $ofp, $pBlock, $blockSize );
980 980
             $mlen -= $blockSize;
981 981
             $iter += $incr;
982 982
         }
@@ -991,10 +991,10 @@  discard block
 block discarded – undo
991 991
      * @return bool
992 992
      * @throws Error
993 993
      */
994
-    protected static function onetimeauth_verify(ParagonIE_Sodium_Core_Poly1305_State $state, $ifp, $tag = '', $mlen = 0)
994
+    protected static function onetimeauth_verify( ParagonIE_Sodium_Core_Poly1305_State $state, $ifp, $tag = '', $mlen = 0 )
995 995
     {
996 996
         /** @var int $pos */
997
-        $pos = ftell($ifp);
997
+        $pos = ftell( $ifp );
998 998
 
999 999
         /** @var int $iter */
1000 1000
         $iter = 1;
@@ -1002,21 +1002,21 @@  discard block
 block discarded – undo
1002 1002
         /** @var int $incr */
1003 1003
         $incr = self::BUFFER_SIZE >> 6;
1004 1004
 
1005
-        while ($mlen > 0) {
1005
+        while ( $mlen > 0 ) {
1006 1006
             $blockSize = $mlen > self::BUFFER_SIZE
1007 1007
                 ? self::BUFFER_SIZE
1008 1008
                 : $mlen;
1009
-            $ciphertext = fread($ifp, $blockSize);
1010
-            if (!is_string($ciphertext)) {
1011
-                throw new Error('Could not read input file');
1009
+            $ciphertext = fread( $ifp, $blockSize );
1010
+            if ( ! is_string( $ciphertext ) ) {
1011
+                throw new Error( 'Could not read input file' );
1012 1012
             }
1013
-            $state->update($ciphertext);
1013
+            $state->update( $ciphertext );
1014 1014
             $mlen -= $blockSize;
1015 1015
             $iter += $incr;
1016 1016
         }
1017
-        $res = ParagonIE_Sodium_Core_Util::verify_16($tag, $state->finish());
1017
+        $res = ParagonIE_Sodium_Core_Util::verify_16( $tag, $state->finish() );
1018 1018
 
1019
-        fseek($ifp, $pos, SEEK_SET);
1019
+        fseek( $ifp, $pos, SEEK_SET );
1020 1020
         return $res;
1021 1021
     }
1022 1022
 
@@ -1034,47 +1034,47 @@  discard block
 block discarded – undo
1034 1034
      *                 PHP 7.2 changes from a resource to an object,
1035 1035
      *                 which causes Psalm to complain about an error.
1036 1036
      */
1037
-    public static function updateHashWithFile($hash, $fp, $size = 0)
1037
+    public static function updateHashWithFile( $hash, $fp, $size = 0 )
1038 1038
     {
1039 1039
         /* Type checks: */
1040
-        if (PHP_VERSION_ID < 70200) {
1041
-            if (!is_resource($hash)) {
1042
-                throw new TypeError('Argument 1 must be a resource, ' . gettype($hash) . ' given.');
1040
+        if ( PHP_VERSION_ID < 70200 ) {
1041
+            if ( ! is_resource( $hash ) ) {
1042
+                throw new TypeError( 'Argument 1 must be a resource, ' . gettype( $hash ) . ' given.' );
1043 1043
             }
1044 1044
 
1045 1045
         } else {
1046
-            if (!is_object($hash)) {
1047
-                throw new TypeError('Argument 1 must be an object (PHP 7.2+), ' . gettype($hash) . ' given.');
1046
+            if ( ! is_object( $hash ) ) {
1047
+                throw new TypeError( 'Argument 1 must be an object (PHP 7.2+), ' . gettype( $hash ) . ' given.' );
1048 1048
             }
1049 1049
         }
1050
-        if (!is_resource($fp)) {
1051
-            throw new TypeError('Argument 2 must be a resource, ' . gettype($fp) . ' given.');
1050
+        if ( ! is_resource( $fp ) ) {
1051
+            throw new TypeError( 'Argument 2 must be a resource, ' . gettype( $fp ) . ' given.' );
1052 1052
         }
1053
-        if (!is_int($size)) {
1054
-            throw new TypeError('Argument 3 must be an integer, ' . gettype($size) . ' given.');
1053
+        if ( ! is_int( $size ) ) {
1054
+            throw new TypeError( 'Argument 3 must be an integer, ' . gettype( $size ) . ' given.' );
1055 1055
         }
1056 1056
 
1057 1057
         /** @var int $originalPosition */
1058
-        $originalPosition = ftell($fp);
1058
+        $originalPosition = ftell( $fp );
1059 1059
 
1060 1060
         // Move file pointer to beginning of file
1061
-        fseek($fp, 0, SEEK_SET);
1062
-        for ($i = 0; $i < $size; $i += self::BUFFER_SIZE) {
1061
+        fseek( $fp, 0, SEEK_SET );
1062
+        for ( $i = 0; $i < $size; $i += self::BUFFER_SIZE ) {
1063 1063
             /** @var string $message */
1064 1064
             $message = fread(
1065 1065
                 $fp,
1066
-                ($size - $i) > self::BUFFER_SIZE
1066
+                ( $size - $i ) > self::BUFFER_SIZE
1067 1067
                     ? $size - $i
1068 1068
                     : self::BUFFER_SIZE
1069 1069
             );
1070
-            if (!is_string($message)) {
1071
-                throw new Error('Unexpected error reading from file.');
1070
+            if ( ! is_string( $message ) ) {
1071
+                throw new Error( 'Unexpected error reading from file.' );
1072 1072
             }
1073 1073
             /** @psalm-suppress InvalidArgument */
1074
-            hash_update($hash, $message);
1074
+            hash_update( $hash, $message );
1075 1075
         }
1076 1076
         // Reset file pointer's position
1077
-        fseek($fp, $originalPosition, SEEK_SET);
1077
+        fseek( $fp, $originalPosition, SEEK_SET );
1078 1078
         return $hash;
1079 1079
     }
1080 1080
 }
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Util.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_Core32_Util', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_Util', false ) ) {
4 4
     return;
5 5
 }
6 6
 
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Poly1305.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_Core32_Poly1305', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_Poly1305', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
      * @param string $key
19 19
      * @return string
20 20
      */
21
-    public static function onetimeauth($m, $key)
21
+    public static function onetimeauth( $m, $key )
22 22
     {
23
-        if (self::strlen($key) < 32) {
23
+        if ( self::strlen( $key ) < 32 ) {
24 24
             throw new InvalidArgumentException(
25 25
                 'Key must be 32 bytes long.'
26 26
             );
27 27
         }
28 28
         $state = new ParagonIE_Sodium_Core32_Poly1305_State(
29
-            self::substr($key, 0, 32)
29
+            self::substr( $key, 0, 32 )
30 30
         );
31 31
         return $state
32
-            ->update($m)
32
+            ->update( $m )
33 33
             ->finish();
34 34
     }
35 35
 
@@ -41,19 +41,19 @@  discard block
 block discarded – undo
41 41
      * @param string $key
42 42
      * @return bool
43 43
      */
44
-    public static function onetimeauth_verify($mac, $m, $key)
44
+    public static function onetimeauth_verify( $mac, $m, $key )
45 45
     {
46
-        if (self::strlen($key) < 32) {
46
+        if ( self::strlen( $key ) < 32 ) {
47 47
             throw new InvalidArgumentException(
48 48
                 'Key must be 32 bytes long.'
49 49
             );
50 50
         }
51 51
         $state = new ParagonIE_Sodium_Core32_Poly1305_State(
52
-            self::substr($key, 0, 32)
52
+            self::substr( $key, 0, 32 )
53 53
         );
54 54
         $calc = $state
55
-            ->update($m)
55
+            ->update( $m )
56 56
             ->finish();
57
-        return self::verify_16($calc, $mac);
57
+        return self::verify_16( $calc, $mac );
58 58
     }
59 59
 }
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Int64.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * ParagonIE_Sodium_Core32_Int64 constructor.
24 24
      * @param array $array
25 25
      */
26
-    public function __construct($array = array(0, 0, 0, 0))
26
+    public function __construct( $array = array( 0, 0, 0, 0 ) )
27 27
     {
28 28
         $this->limbs = array(
29 29
             (int) $array[0],
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
      * @param ParagonIE_Sodium_Core32_Int64 $addend
41 41
      * @return ParagonIE_Sodium_Core32_Int64
42 42
      */
43
-    public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend)
43
+    public function addInt64( ParagonIE_Sodium_Core32_Int64 $addend )
44 44
     {
45 45
         $return = new ParagonIE_Sodium_Core32_Int64();
46 46
         $carry = 0;
47
-        for ($i = 3; $i >= 0; --$i) {
47
+        for ( $i = 3; $i >= 0; --$i ) {
48 48
             $tmp = $this->limbs[$i] + $addend->limbs[$i] + $carry;
49 49
             $carry = $tmp >> 16;
50
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
50
+            $return->limbs[$i] = (int) ( $tmp & 0xffff );
51 51
         }
52 52
         $return->overflow = $carry;
53 53
         return $return;
@@ -59,22 +59,22 @@  discard block
 block discarded – undo
59 59
      * @param int $int
60 60
      * @return ParagonIE_Sodium_Core32_Int64
61 61
      */
62
-    public function addInt($int)
62
+    public function addInt( $int )
63 63
     {
64
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
64
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
65 65
 
66 66
         $return = new ParagonIE_Sodium_Core32_Int64();
67 67
         $carry = 0;
68
-        for ($i = 3; $i >= 0; --$i) {
69
-            $step = (3 - $i) << 4; // 0, 16, 32, 48
70
-            if ($i < 2) {
68
+        for ( $i = 3; $i >= 0; --$i ) {
69
+            $step = ( 3 - $i ) << 4; // 0, 16, 32, 48
70
+            if ( $i < 2 ) {
71 71
                 $toAdd = 0;
72 72
             } else {
73
-                $toAdd = (($int >> $step) & 0xffff);
73
+                $toAdd = ( ( $int >> $step ) & 0xffff );
74 74
             }
75 75
             $tmp = $this->limbs[$i] + $toAdd + $carry;
76 76
             $carry = $tmp >> 16;
77
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
77
+            $return->limbs[$i] = (int) ( $tmp & 0xffff );
78 78
         }
79 79
         $return->overflow = $carry;
80 80
         return $return;
@@ -84,39 +84,39 @@  discard block
 block discarded – undo
84 84
      * @param int $b
85 85
      * @return int
86 86
      */
87
-    public function compareInt($b = 0)
87
+    public function compareInt( $b = 0 )
88 88
     {
89 89
         $gt = 0;
90 90
         $eq = 1;
91 91
 
92 92
         $i = 4;
93 93
         $j = 0;
94
-        while ($i > 0) {
94
+        while ( $i > 0 ) {
95 95
             --$i;
96 96
             $x1 = $this->limbs[$i];
97
-            $x2 = ($b >> ($j << 4)) & 0xffff;
98
-            $gt |= (($x2 - $x1) >> 8) & $eq;
99
-            $eq &= (($x2 ^ $x1) - 1) >> 8;
97
+            $x2 = ( $b >> ( $j << 4 ) ) & 0xffff;
98
+            $gt |= ( ( $x2 - $x1 ) >> 8 ) & $eq;
99
+            $eq &= ( ( $x2 ^ $x1 ) - 1 ) >> 8;
100 100
         }
101
-        return ($gt + $gt - $eq) + 1;
101
+        return ( $gt + $gt - $eq ) + 1;
102 102
     }
103 103
 
104 104
     /**
105 105
      * @param int $b
106 106
      * @return bool
107 107
      */
108
-    public function isGreaterThan($b = 0)
108
+    public function isGreaterThan( $b = 0 )
109 109
     {
110
-        return $this->compareInt($b) > 0;
110
+        return $this->compareInt( $b ) > 0;
111 111
     }
112 112
 
113 113
     /**
114 114
      * @param int $b
115 115
      * @return bool
116 116
      */
117
-    public function isLessThanInt($b = 0)
117
+    public function isLessThanInt( $b = 0 )
118 118
     {
119
-        return $this->compareInt($b) < 0;
119
+        return $this->compareInt( $b ) < 0;
120 120
     }
121 121
 
122 122
 
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
      * @param int $lo
126 126
      * @return ParagonIE_Sodium_Core32_Int64
127 127
      */
128
-    public function mask64($hi = 0, $lo = 0)
128
+    public function mask64( $hi = 0, $lo = 0 )
129 129
     {
130
-        $a = ($hi >> 16) & 0xffff;
131
-        $b = ($hi) & 0xffff;
132
-        $c = ($lo >> 16) & 0xffff;
133
-        $d = ($lo & 0xffff);
130
+        $a = ( $hi >> 16 ) & 0xffff;
131
+        $b = ( $hi ) & 0xffff;
132
+        $c = ( $lo >> 16 ) & 0xffff;
133
+        $d = ( $lo & 0xffff );
134 134
         return new ParagonIE_Sodium_Core32_Int64(
135 135
             array(
136 136
                 $this->limbs[0] & $a,
@@ -146,25 +146,25 @@  discard block
 block discarded – undo
146 146
      * @param int $size
147 147
      * @return ParagonIE_Sodium_Core32_Int64
148 148
      */
149
-    public function mulInt($int = 0, $size = 0)
149
+    public function mulInt( $int = 0, $size = 0 )
150 150
     {
151
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
152
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
153
-        if (!$size) {
151
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
152
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $size, 'int', 2 );
153
+        if ( ! $size ) {
154 154
             $size = 63;
155 155
         }
156 156
 
157 157
         $a = clone $this;
158 158
         $return = new ParagonIE_Sodium_Core32_Int64();
159 159
 
160
-        for ($i = $size; $i >= 0; --$i) {
160
+        for ( $i = $size; $i >= 0; --$i ) {
161 161
             $return = $return->addInt64(
162 162
                 $a->mask64(
163
-                    (int) (-($int & 1)),
164
-                    (int) (-($int & 1))
163
+                    (int) (-( $int & 1 )),
164
+                    (int) (-( $int & 1 ))
165 165
                 )
166 166
             );
167
-            $a = $a->shiftLeft(1);
167
+            $a = $a->shiftLeft( 1 );
168 168
             $int >>= 1;
169 169
         }
170 170
         return $return;
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
      * @param int $size
176 176
      * @return ParagonIE_Sodium_Core32_Int64
177 177
      */
178
-    public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0)
178
+    public function mulInt64( ParagonIE_Sodium_Core32_Int64 $int, $size = 0 )
179 179
     {
180
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
181
-        if (!$size) {
180
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $size, 'int', 2 );
181
+        if ( ! $size ) {
182 182
             $size = 63;
183 183
         }
184 184
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         $b = clone $int;
187 187
         $return = new ParagonIE_Sodium_Core32_Int64();
188 188
 
189
-        for ($i = $size; $i >= 0; --$i) {
189
+        for ( $i = $size; $i >= 0; --$i ) {
190 190
             /*
191 191
             $c += (int) ($a & -($b & 1));
192 192
             $a <<= 1;
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
              */
195 195
             $return = $return->addInt64(
196 196
                 $a->mask64(
197
-                    (int) (-($b->limbs[3] & 1)),
198
-                    (int) (-($b->limbs[3] & 1))
197
+                    (int) (-( $b->limbs[3] & 1 )),
198
+                    (int) (-( $b->limbs[3] & 1 ))
199 199
                 )
200 200
             );
201
-            $a = $a->shiftLeft(1);
202
-            $b = $b->shiftRight(1);
201
+            $a = $a->shiftLeft( 1 );
202
+            $b = $b->shiftRight( 1 );
203 203
         }
204 204
         return $return;
205 205
     }
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
      * @param ParagonIE_Sodium_Core32_Int64 $b
211 211
      * @return ParagonIE_Sodium_Core32_Int64
212 212
      */
213
-    public function orInt64(ParagonIE_Sodium_Core32_Int64 $b)
213
+    public function orInt64( ParagonIE_Sodium_Core32_Int64 $b )
214 214
     {
215 215
         $return = new ParagonIE_Sodium_Core32_Int64();
216 216
         $return->limbs = array(
217
-            (int) ($this->limbs[0] | $b->limbs[0]),
218
-            (int) ($this->limbs[1] | $b->limbs[1]),
219
-            (int) ($this->limbs[2] | $b->limbs[2]),
220
-            (int) ($this->limbs[3] | $b->limbs[3])
217
+            (int) ( $this->limbs[0] | $b->limbs[0] ),
218
+            (int) ( $this->limbs[1] | $b->limbs[1] ),
219
+            (int) ( $this->limbs[2] | $b->limbs[2] ),
220
+            (int) ( $this->limbs[3] | $b->limbs[3] )
221 221
         );
222 222
         return $return;
223 223
     }
@@ -226,27 +226,27 @@  discard block
 block discarded – undo
226 226
      * @param int $c
227 227
      * @return ParagonIE_Sodium_Core32_Int64
228 228
      */
229
-    public function rotateLeft($c = 0)
229
+    public function rotateLeft( $c = 0 )
230 230
     {
231
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
231
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
232 232
 
233 233
         $return = new ParagonIE_Sodium_Core32_Int64();
234 234
         $c &= 63;
235
-        if ($c === 0) {
235
+        if ( $c === 0 ) {
236 236
             // NOP, but we want a copy.
237 237
             $return->limbs = $this->limbs;
238 238
         } else {
239
-            $idx_shift = ($c >> 4) & 3;
239
+            $idx_shift = ( $c >> 4 ) & 3;
240 240
             $sub_shift = $c & 15;
241 241
 
242
-            for ($i = 3; $i >= 0; --$i) {
243
-                $j = ($i + $idx_shift) & 3;
244
-                $k = ($i + $idx_shift + 1) & 3;
242
+            for ( $i = 3; $i >= 0; --$i ) {
243
+                $j = ( $i + $idx_shift ) & 3;
244
+                $k = ( $i + $idx_shift + 1 ) & 3;
245 245
                 $return->limbs[$i] = (int) (
246 246
                     (
247
-                        ($this->limbs[$j] << $sub_shift)
247
+                        ( $this->limbs[$j] << $sub_shift )
248 248
                             |
249
-                        ($this->limbs[$k] >> (16 - $sub_shift))
249
+                        ( $this->limbs[$k] >> ( 16 - $sub_shift ) )
250 250
                     ) & 0xffff
251 251
                 );
252 252
             }
@@ -260,27 +260,27 @@  discard block
 block discarded – undo
260 260
      * @param int $c
261 261
      * @return ParagonIE_Sodium_Core32_Int64
262 262
      */
263
-    public function rotateRight($c = 0)
263
+    public function rotateRight( $c = 0 )
264 264
     {
265
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
265
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
266 266
 
267 267
         $return = new ParagonIE_Sodium_Core32_Int64();
268 268
         $c &= 63;
269
-        if ($c === 0) {
269
+        if ( $c === 0 ) {
270 270
             // NOP, but we want a copy.
271 271
             $return->limbs = $this->limbs;
272 272
         } else {
273
-            $idx_shift = ($c >> 4) & 3;
273
+            $idx_shift = ( $c >> 4 ) & 3;
274 274
             $sub_shift = $c & 15;
275 275
 
276
-            for ($i = 3; $i >= 0; --$i) {
277
-                $j = ($i - $idx_shift) & 3;
278
-                $k = ($i - $idx_shift - 1) & 3;
276
+            for ( $i = 3; $i >= 0; --$i ) {
277
+                $j = ( $i - $idx_shift ) & 3;
278
+                $k = ( $i - $idx_shift - 1 ) & 3;
279 279
                 $return->limbs[$i] = (int) (
280 280
                     (
281
-                        ($this->limbs[$j] >> ($sub_shift))
281
+                        ( $this->limbs[$j] >> ( $sub_shift ) )
282 282
                             |
283
-                        ($this->limbs[$k] << (16 - $sub_shift))
283
+                        ( $this->limbs[$k] << ( 16 - $sub_shift ) )
284 284
                     ) & 0xffff
285 285
                 );
286 286
             }
@@ -292,18 +292,18 @@  discard block
 block discarded – undo
292 292
      * @return ParagonIE_Sodium_Core32_Int64
293 293
      * @throws TypeError
294 294
      */
295
-    public function shiftLeft($c = 0)
295
+    public function shiftLeft( $c = 0 )
296 296
     {
297
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
297
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
298 298
         $return = new ParagonIE_Sodium_Core32_Int64();
299 299
         $c &= 63;
300 300
 
301
-        if ($c >= 16) {
302
-            if ($c >= 48) {
301
+        if ( $c >= 16 ) {
302
+            if ( $c >= 48 ) {
303 303
                 $return->limbs = array(
304 304
                     $this->limbs[3], 0, 0, 0
305 305
                 );
306
-            } elseif ($c >= 32) {
306
+            } elseif ( $c >= 32 ) {
307 307
                 $return->limbs = array(
308 308
                     $this->limbs[2], $this->limbs[3], 0, 0
309 309
                 );
@@ -312,20 +312,20 @@  discard block
 block discarded – undo
312 312
                     $this->limbs[1], $this->limbs[2], $this->limbs[3], 0
313 313
                 );
314 314
             }
315
-            return $return->shiftLeft($c & 15);
315
+            return $return->shiftLeft( $c & 15 );
316 316
         }
317
-        if ($c === 0) {
317
+        if ( $c === 0 ) {
318 318
             $return->limbs = $this->limbs;
319
-        } elseif ($c < 0) {
319
+        } elseif ( $c < 0 ) {
320 320
             return $this->shiftRight(-$c);
321 321
         } else {
322
-            if (is_null($c)) {
322
+            if ( is_null( $c ) ) {
323 323
                 throw new TypeError();
324 324
             }
325 325
             $carry = 0;
326
-            for ($i = 3; $i >= 0; --$i) {
327
-                $tmp = ($this->limbs[$i] << $c) | ($carry & 0xffff);
328
-                $return->limbs[$i] = (int) ($tmp & 0xffff);
326
+            for ( $i = 3; $i >= 0; --$i ) {
327
+                $tmp = ( $this->limbs[$i] << $c ) | ( $carry & 0xffff );
328
+                $return->limbs[$i] = (int) ( $tmp & 0xffff );
329 329
                 $carry = $tmp >> 16;
330 330
             }
331 331
         }
@@ -337,54 +337,54 @@  discard block
 block discarded – undo
337 337
      * @return ParagonIE_Sodium_Core32_Int64
338 338
      * @throws TypeError
339 339
      */
340
-    public function shiftRight($c = 0)
340
+    public function shiftRight( $c = 0 )
341 341
     {
342
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
342
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
343 343
         $return = new ParagonIE_Sodium_Core32_Int64();
344 344
         $c &= 63;
345 345
 
346
-        $negative = -(($this->limbs[0] >> 15) & 1);
347
-        if ($c >= 16) {
348
-            if ($c >= 48) {
346
+        $negative = -( ( $this->limbs[0] >> 15 ) & 1 );
347
+        if ( $c >= 16 ) {
348
+            if ( $c >= 48 ) {
349 349
                 $return->limbs = array(
350
-                    (int) ($negative & 0xffff),
351
-                    (int) ($negative & 0xffff),
352
-                    (int) ($negative & 0xffff),
350
+                    (int) ( $negative & 0xffff ),
351
+                    (int) ( $negative & 0xffff ),
352
+                    (int) ( $negative & 0xffff ),
353 353
                     (int) $this->limbs[0]
354 354
                 );
355
-            } elseif ($c >= 32) {
355
+            } elseif ( $c >= 32 ) {
356 356
                 $return->limbs = array(
357
-                    (int) ($negative & 0xffff),
358
-                    (int) ($negative & 0xffff),
357
+                    (int) ( $negative & 0xffff ),
358
+                    (int) ( $negative & 0xffff ),
359 359
                     (int) $this->limbs[0],
360 360
                     (int) $this->limbs[1]
361 361
                 );
362 362
             } else {
363 363
                 $return->limbs = array(
364
-                    (int) ($negative & 0xffff),
364
+                    (int) ( $negative & 0xffff ),
365 365
                     (int) $this->limbs[0],
366 366
                     (int) $this->limbs[1],
367 367
                     (int) $this->limbs[2]
368 368
                 );
369 369
             }
370
-            return $return->shiftRight($c & 15);
370
+            return $return->shiftRight( $c & 15 );
371 371
         }
372 372
 
373
-        if ($c === 0) {
373
+        if ( $c === 0 ) {
374 374
             $return->limbs = $this->limbs;
375
-        } elseif ($c < 0) {
375
+        } elseif ( $c < 0 ) {
376 376
             return $this->shiftLeft(-$c);
377 377
         } else {
378
-            if (is_null($c)) {
378
+            if ( is_null( $c ) ) {
379 379
                 throw new TypeError();
380 380
             }
381
-            $carryRight = ($negative & 0xffff);
382
-            $mask = (int) (((1 << ($c + 1)) - 1) & 0xffff);
383
-            for ($i = 0; $i < 4; ++$i) {
381
+            $carryRight = ( $negative & 0xffff );
382
+            $mask = (int) ( ( ( 1 << ( $c + 1 ) ) - 1 ) & 0xffff );
383
+            for ( $i = 0; $i < 4; ++$i ) {
384 384
                 $return->limbs[$i] = (int) (
385
-                    (($this->limbs[$i] >> $c) | ($carryRight << (16 - $c))) & 0xffff
385
+                    ( ( $this->limbs[$i] >> $c ) | ( $carryRight << ( 16 - $c ) ) ) & 0xffff
386 386
                 );
387
-                $carryRight = (int) ($this->limbs[$i] & $mask);
387
+                $carryRight = (int) ( $this->limbs[$i] & $mask );
388 388
             }
389 389
         }
390 390
         return $return;
@@ -397,17 +397,17 @@  discard block
 block discarded – undo
397 397
      * @param int $int
398 398
      * @return ParagonIE_Sodium_Core32_Int64
399 399
      */
400
-    public function subInt($int)
400
+    public function subInt( $int )
401 401
     {
402
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
402
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
403 403
 
404 404
         $return = new ParagonIE_Sodium_Core32_Int64();
405 405
 
406 406
         $carry = 0;
407
-        for ($i = 3; $i >= 0; --$i) {
408
-            $tmp = $this->limbs[$i] - (($int >> 16) & 0xffff) + $carry;
407
+        for ( $i = 3; $i >= 0; --$i ) {
408
+            $tmp = $this->limbs[$i] - ( ( $int >> 16 ) & 0xffff ) + $carry;
409 409
             $carry = $tmp >> 16;
410
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
410
+            $return->limbs[$i] = (int) ( $tmp & 0xffff );
411 411
         }
412 412
         return $return;
413 413
     }
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
      * @param ParagonIE_Sodium_Core32_Int64 $b
419 419
      * @return ParagonIE_Sodium_Core32_Int64
420 420
      */
421
-    public function subInt64(ParagonIE_Sodium_Core32_Int64 $b)
421
+    public function subInt64( ParagonIE_Sodium_Core32_Int64 $b )
422 422
     {
423 423
         $return = new ParagonIE_Sodium_Core32_Int64();
424 424
         $carry = 0;
425
-        for ($i = 3; $i >= 0; --$i) {
425
+        for ( $i = 3; $i >= 0; --$i ) {
426 426
             $tmp = $this->limbs[$i] - $b->limbs[$i] + $carry;
427
-            $carry = ($tmp >> 16);
428
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
427
+            $carry = ( $tmp >> 16 );
428
+            $return->limbs[$i] = (int) ( $tmp & 0xffff );
429 429
 
430 430
         }
431 431
         return $return;
@@ -437,14 +437,14 @@  discard block
 block discarded – undo
437 437
      * @param ParagonIE_Sodium_Core32_Int64 $b
438 438
      * @return ParagonIE_Sodium_Core32_Int64
439 439
      */
440
-    public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b)
440
+    public function xorInt64( ParagonIE_Sodium_Core32_Int64 $b )
441 441
     {
442 442
         $return = new ParagonIE_Sodium_Core32_Int64();
443 443
         $return->limbs = array(
444
-            (int) ($this->limbs[0] ^ $b->limbs[0]),
445
-            (int) ($this->limbs[1] ^ $b->limbs[1]),
446
-            (int) ($this->limbs[2] ^ $b->limbs[2]),
447
-            (int) ($this->limbs[3] ^ $b->limbs[3])
444
+            (int) ( $this->limbs[0] ^ $b->limbs[0] ),
445
+            (int) ( $this->limbs[1] ^ $b->limbs[1] ),
446
+            (int) ( $this->limbs[2] ^ $b->limbs[2] ),
447
+            (int) ( $this->limbs[3] ^ $b->limbs[3] )
448 448
         );
449 449
         return $return;
450 450
     }
@@ -454,17 +454,17 @@  discard block
 block discarded – undo
454 454
      * @param int $high
455 455
      * @return self
456 456
      */
457
-    public static function fromInts($low, $high)
457
+    public static function fromInts( $low, $high )
458 458
     {
459
-        ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
460
-        ParagonIE_Sodium_Core32_Util::declareScalarType($high, 'int', 2);
459
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $low, 'int', 1 );
460
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $high, 'int', 2 );
461 461
 
462 462
         return new ParagonIE_Sodium_Core32_Int64(
463 463
             array(
464
-                (int) (($high >> 16) & 0xffff),
465
-                (int) ($high & 0xffff),
466
-                (int) (($low >> 16) & 0xffff),
467
-                (int) ($low & 0xffff)
464
+                (int) ( ( $high >> 16 ) & 0xffff ),
465
+                (int) ( $high & 0xffff ),
466
+                (int) ( ( $low >> 16 ) & 0xffff ),
467
+                (int) ( $low & 0xffff )
468 468
             )
469 469
         );
470 470
     }
@@ -473,25 +473,25 @@  discard block
 block discarded – undo
473 473
      * @param string $string
474 474
      * @return self
475 475
      */
476
-    public static function fromString($string)
476
+    public static function fromString( $string )
477 477
     {
478
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
478
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $string, 'string', 1 );
479 479
         $string = (string) $string;
480
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
480
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $string ) !== 8 ) {
481 481
             throw new RangeException(
482
-                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
482
+                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen( $string ) . ' given.'
483 483
             );
484 484
         }
485 485
         $return = new ParagonIE_Sodium_Core32_Int64();
486 486
 
487
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
488
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
489
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
490
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
491
-        $return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff) << 8);
492
-        $return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff);
493
-        $return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff) << 8);
494
-        $return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff);
487
+        $return->limbs[0]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[0] ) & 0xff ) << 8 );
488
+        $return->limbs[0] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[1] ) & 0xff );
489
+        $return->limbs[1]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[2] ) & 0xff ) << 8 );
490
+        $return->limbs[1] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[3] ) & 0xff );
491
+        $return->limbs[2]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[4] ) & 0xff ) << 8 );
492
+        $return->limbs[2] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[5] ) & 0xff );
493
+        $return->limbs[3]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[6] ) & 0xff ) << 8 );
494
+        $return->limbs[3] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[7] ) & 0xff );
495 495
         return $return;
496 496
     }
497 497
 
@@ -499,25 +499,25 @@  discard block
 block discarded – undo
499 499
      * @param string $string
500 500
      * @return self
501 501
      */
502
-    public static function fromReverseString($string)
502
+    public static function fromReverseString( $string )
503 503
     {
504
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
504
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $string, 'string', 1 );
505 505
         $string = (string) $string;
506
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
506
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $string ) !== 8 ) {
507 507
             throw new RangeException(
508
-                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
508
+                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen( $string ) . ' given.'
509 509
             );
510 510
         }
511 511
         $return = new ParagonIE_Sodium_Core32_Int64();
512 512
 
513
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff) << 8);
514
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff);
515
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff) << 8);
516
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff);
517
-        $return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
518
-        $return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
519
-        $return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
520
-        $return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
513
+        $return->limbs[0]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[7] ) & 0xff ) << 8 );
514
+        $return->limbs[0] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[6] ) & 0xff );
515
+        $return->limbs[1]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[5] ) & 0xff ) << 8 );
516
+        $return->limbs[1] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[4] ) & 0xff );
517
+        $return->limbs[2]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[3] ) & 0xff ) << 8 );
518
+        $return->limbs[2] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[2] ) & 0xff );
519
+        $return->limbs[3]  = (int) ( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[1] ) & 0xff ) << 8 );
520
+        $return->limbs[3] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[0] ) & 0xff );
521 521
         return $return;
522 522
     }
523 523
 
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
     public function toArray()
528 528
     {
529 529
         return array(
530
-            (int) ((($this->limbs[0] & 0xffff) << 16) | ($this->limbs[1] & 0xffff)),
531
-            (int) ((($this->limbs[2] & 0xffff) << 16) | ($this->limbs[3] & 0xffff))
530
+            (int) ( ( ( $this->limbs[0] & 0xffff ) << 16 ) | ( $this->limbs[1] & 0xffff ) ),
531
+            (int) ( ( ( $this->limbs[2] & 0xffff ) << 16 ) | ( $this->limbs[3] & 0xffff ) )
532 532
         );
533 533
     }
534 534
 
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
     public function toInt32()
539 539
     {
540 540
         $return = new ParagonIE_Sodium_Core32_Int32();
541
-        $return->limbs[0] = (int) ($this->limbs[2]);
542
-        $return->limbs[1] = (int) ($this->limbs[3]);
541
+        $return->limbs[0] = (int) ( $this->limbs[2] );
542
+        $return->limbs[1] = (int) ( $this->limbs[3] );
543 543
         return $return;
544 544
     }
545 545
 
@@ -549,10 +549,10 @@  discard block
 block discarded – undo
549 549
     public function toInt64()
550 550
     {
551 551
         $return = new ParagonIE_Sodium_Core32_Int64();
552
-        $return->limbs[0] = (int) ($this->limbs[0]);
553
-        $return->limbs[1] = (int) ($this->limbs[1]);
554
-        $return->limbs[2] = (int) ($this->limbs[2]);
555
-        $return->limbs[3] = (int) ($this->limbs[3]);
552
+        $return->limbs[0] = (int) ( $this->limbs[0] );
553
+        $return->limbs[1] = (int) ( $this->limbs[1] );
554
+        $return->limbs[2] = (int) ( $this->limbs[2] );
555
+        $return->limbs[3] = (int) ( $this->limbs[3] );
556 556
         return $return;
557 557
     }
558 558
 
@@ -561,14 +561,14 @@  discard block
 block discarded – undo
561 561
      */
562 562
     public function toString()
563 563
     {
564
-        return ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
565
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
566
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
567
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
568
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
569
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
570
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
571
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff);
564
+        return ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[0] >> 8 ) & 0xff ) .
565
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[0] & 0xff ) .
566
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[1] >> 8 ) & 0xff ) .
567
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[1] & 0xff ) .
568
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[2] >> 8 ) & 0xff ) .
569
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[2] & 0xff ) .
570
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[3] >> 8 ) & 0xff ) .
571
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[3] & 0xff );
572 572
     }
573 573
 
574 574
     /**
@@ -576,14 +576,14 @@  discard block
 block discarded – undo
576 576
      */
577 577
     public function toReverseString()
578 578
     {
579
-        return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff) .
580
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
581
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
582
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
583
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
584
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
585
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
586
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
579
+        return ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[3] & 0xff ) .
580
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[3] >> 8 ) & 0xff ) .
581
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[2] & 0xff ) .
582
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[2] >> 8 ) & 0xff ) .
583
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[1] & 0xff ) .
584
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[1] >> 8 ) & 0xff ) .
585
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[0] & 0xff ) .
586
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[0] >> 8 ) & 0xff );
587 587
     }
588 588
 
589 589
     /**
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Ed25519.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_Core32_Ed25519', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_Ed25519', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public static function keypair()
21 21
     {
22
-        $seed = random_bytes(self::SEED_BYTES);
22
+        $seed = random_bytes( self::SEED_BYTES );
23 23
         $pk = '';
24 24
         $sk = '';
25
-        self::seed_keypair($pk, $sk, $seed);
25
+        self::seed_keypair( $pk, $sk, $seed );
26 26
         return $sk . $pk;
27 27
     }
28 28
 
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
      * @param string $seed
35 35
      * @return string
36 36
      */
37
-    public static function seed_keypair(&$pk, &$sk, $seed)
37
+    public static function seed_keypair( &$pk, &$sk, $seed )
38 38
     {
39
-        if (self::strlen($seed) !== self::SEED_BYTES) {
40
-            throw new RangeException('crypto_sign keypair seed must be 32 bytes long');
39
+        if ( self::strlen( $seed ) !== self::SEED_BYTES ) {
40
+            throw new RangeException( 'crypto_sign keypair seed must be 32 bytes long' );
41 41
         }
42 42
 
43 43
         /** @var string $pk */
44
-        $pk = self::publickey_from_secretkey($seed);
44
+        $pk = self::publickey_from_secretkey( $seed );
45 45
         $sk = $seed . $pk;
46 46
         return $sk;
47 47
     }
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
      * @param string $keypair
53 53
      * @return string
54 54
      */
55
-    public static function secretkey($keypair)
55
+    public static function secretkey( $keypair )
56 56
     {
57
-        if (self::strlen($keypair) !== self::KEYPAIR_BYTES) {
58
-            throw new RangeException('crypto_sign keypair must be 96 bytes long');
57
+        if ( self::strlen( $keypair ) !== self::KEYPAIR_BYTES ) {
58
+            throw new RangeException( 'crypto_sign keypair must be 96 bytes long' );
59 59
         }
60
-        return self::substr($keypair, 0, 64);
60
+        return self::substr( $keypair, 0, 64 );
61 61
     }
62 62
 
63 63
     /**
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
      * @param string $keypair
67 67
      * @return string
68 68
      */
69
-    public static function publickey($keypair)
69
+    public static function publickey( $keypair )
70 70
     {
71
-        if (self::strlen($keypair) !== self::KEYPAIR_BYTES) {
72
-            throw new RangeException('crypto_sign keypair must be 96 bytes long');
71
+        if ( self::strlen( $keypair ) !== self::KEYPAIR_BYTES ) {
72
+            throw new RangeException( 'crypto_sign keypair must be 96 bytes long' );
73 73
         }
74
-        return self::substr($keypair, 64, 32);
74
+        return self::substr( $keypair, 64, 32 );
75 75
     }
76 76
 
77 77
     /**
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
      * @param string $sk
81 81
      * @return string
82 82
      */
83
-    public static function publickey_from_secretkey($sk)
83
+    public static function publickey_from_secretkey( $sk )
84 84
     {
85 85
         /** @var string $sk */
86
-        $sk = hash('sha512', self::substr($sk, 0, 32), true);
86
+        $sk = hash( 'sha512', self::substr( $sk, 0, 32 ), true );
87 87
         $sk[0] = self::intToChr(
88
-            self::chrToInt($sk[0]) & 248
88
+            self::chrToInt( $sk[0] ) & 248
89 89
         );
90 90
         $sk[31] = self::intToChr(
91
-            (self::chrToInt($sk[31]) & 63) | 64
91
+            ( self::chrToInt( $sk[31] ) & 63 ) | 64
92 92
         );
93
-        return self::sk_to_pk($sk);
93
+        return self::sk_to_pk( $sk );
94 94
     }
95 95
 
96 96
     /**
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
      * @param string $sk
100 100
      * @return string
101 101
      */
102
-    public static function sk_to_pk($sk)
102
+    public static function sk_to_pk( $sk )
103 103
     {
104 104
         return self::ge_p3_tobytes(
105 105
             self::ge_scalarmult_base(
106
-                self::substr($sk, 0, 32)
106
+                self::substr( $sk, 0, 32 )
107 107
             )
108 108
         );
109 109
     }
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
      * @param string $sk
116 116
      * @return string
117 117
      */
118
-    public static function sign($message, $sk)
118
+    public static function sign( $message, $sk )
119 119
     {
120 120
         /** @var string $signature */
121
-        $signature = self::sign_detached($message, $sk);
121
+        $signature = self::sign_detached( $message, $sk );
122 122
         return $signature . $message;
123 123
     }
124 124
 
@@ -130,18 +130,18 @@  discard block
 block discarded – undo
130 130
      * @return string         Message (without signature)
131 131
      * @throws Exception
132 132
      */
133
-    public static function sign_open($message, $pk)
133
+    public static function sign_open( $message, $pk )
134 134
     {
135 135
         /** @var string $signature */
136
-        $signature = self::substr($message, 0, 64);
136
+        $signature = self::substr( $message, 0, 64 );
137 137
 
138 138
         /** @var string $message */
139
-        $message = self::substr($message, 64);
139
+        $message = self::substr( $message, 64 );
140 140
 
141
-        if (self::verify_detached($signature, $message, $pk)) {
141
+        if ( self::verify_detached( $signature, $message, $pk ) ) {
142 142
             return $message;
143 143
         }
144
-        throw new Exception('Invalid signature');
144
+        throw new Exception( 'Invalid signature' );
145 145
     }
146 146
 
147 147
     /**
@@ -151,56 +151,56 @@  discard block
 block discarded – undo
151 151
      * @param string $sk
152 152
      * @return string
153 153
      */
154
-    public static function sign_detached($message, $sk)
154
+    public static function sign_detached( $message, $sk )
155 155
     {
156 156
         # crypto_hash_sha512(az, sk, 32);
157
-        $az =  hash('sha512', self::substr($sk, 0, 32), true);
157
+        $az = hash( 'sha512', self::substr( $sk, 0, 32 ), true );
158 158
 
159 159
         # az[0] &= 248;
160 160
         # az[31] &= 63;
161 161
         # az[31] |= 64;
162
-        $az[0] = self::intToChr(self::chrToInt($az[0]) & 248);
163
-        $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64);
162
+        $az[0] = self::intToChr( self::chrToInt( $az[0] ) & 248 );
163
+        $az[31] = self::intToChr( ( self::chrToInt( $az[31] ) & 63 ) | 64 );
164 164
 
165 165
         # crypto_hash_sha512_init(&hs);
166 166
         # crypto_hash_sha512_update(&hs, az + 32, 32);
167 167
         # crypto_hash_sha512_update(&hs, m, mlen);
168 168
         # crypto_hash_sha512_final(&hs, nonce);
169
-        $hs = hash_init('sha512');
170
-        hash_update($hs, self::substr($az, 32, 32));
171
-        hash_update($hs, $message);
172
-        $nonceHash = hash_final($hs, true);
169
+        $hs = hash_init( 'sha512' );
170
+        hash_update( $hs, self::substr( $az, 32, 32 ) );
171
+        hash_update( $hs, $message );
172
+        $nonceHash = hash_final( $hs, true );
173 173
 
174 174
         # memmove(sig + 32, sk + 32, 32);
175
-        $pk = self::substr($sk, 32, 32);
175
+        $pk = self::substr( $sk, 32, 32 );
176 176
 
177 177
         # sc_reduce(nonce);
178 178
         # ge_scalarmult_base(&R, nonce);
179 179
         # ge_p3_tobytes(sig, &R);
180
-        $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32);
180
+        $nonce = self::sc_reduce( $nonceHash ) . self::substr( $nonceHash, 32 );
181 181
         $sig = self::ge_p3_tobytes(
182
-            self::ge_scalarmult_base($nonce)
182
+            self::ge_scalarmult_base( $nonce )
183 183
         );
184 184
 
185 185
         # crypto_hash_sha512_init(&hs);
186 186
         # crypto_hash_sha512_update(&hs, sig, 64);
187 187
         # crypto_hash_sha512_update(&hs, m, mlen);
188 188
         # crypto_hash_sha512_final(&hs, hram);
189
-        $hs = hash_init('sha512');
190
-        hash_update($hs, self::substr($sig, 0, 32));
191
-        hash_update($hs, self::substr($pk, 0, 32));
192
-        hash_update($hs, $message);
193
-        $hramHash = hash_final($hs, true);
189
+        $hs = hash_init( 'sha512' );
190
+        hash_update( $hs, self::substr( $sig, 0, 32 ) );
191
+        hash_update( $hs, self::substr( $pk, 0, 32 ) );
192
+        hash_update( $hs, $message );
193
+        $hramHash = hash_final( $hs, true );
194 194
 
195 195
         # sc_reduce(hram);
196 196
         # sc_muladd(sig + 32, hram, az, nonce);
197
-        $hram = self::sc_reduce($hramHash);
198
-        $sigAfter = self::sc_muladd($hram, $az, $nonce);
199
-        $sig = self::substr($sig, 0, 32) . self::substr($sigAfter, 0, 32);
197
+        $hram = self::sc_reduce( $hramHash );
198
+        $sigAfter = self::sc_muladd( $hram, $az, $nonce );
199
+        $sig = self::substr( $sig, 0, 32 ) . self::substr( $sigAfter, 0, 32 );
200 200
 
201 201
         try {
202
-            ParagonIE_Sodium_Compat::memzero($az);
203
-        } catch (Error $ex) {
202
+            ParagonIE_Sodium_Compat::memzero( $az );
203
+        } catch ( Error $ex ) {
204 204
             $az = null;
205 205
         }
206 206
         return $sig;
@@ -215,26 +215,26 @@  discard block
 block discarded – undo
215 215
      * @return bool
216 216
      * @throws Exception
217 217
      */
218
-    public static function verify_detached($sig, $message, $pk)
218
+    public static function verify_detached( $sig, $message, $pk )
219 219
     {
220
-        if (self::strlen($sig) < 64) {
221
-            throw new Exception('Signature is too short');
220
+        if ( self::strlen( $sig ) < 64 ) {
221
+            throw new Exception( 'Signature is too short' );
222 222
         }
223
-        if (self::check_S_lt_L(self::substr($sig, 32, 32))) {
224
-            throw new Exception('S < L - Invalid signature');
223
+        if ( self::check_S_lt_L( self::substr( $sig, 32, 32 ) ) ) {
224
+            throw new Exception( 'S < L - Invalid signature' );
225 225
         }
226
-        if (self::small_order($sig)) {
227
-            throw new Exception('Signature is on too small of an order');
226
+        if ( self::small_order( $sig ) ) {
227
+            throw new Exception( 'Signature is on too small of an order' );
228 228
         }
229
-        if ((self::chrToInt($sig[63]) & 224) !== 0) {
230
-            throw new Exception('Invalid signature');
229
+        if ( ( self::chrToInt( $sig[63] ) & 224 ) !== 0 ) {
230
+            throw new Exception( 'Invalid signature' );
231 231
         }
232 232
         $d = 0;
233
-        for ($i = 0; $i < 32; ++$i) {
234
-            $d |= self::chrToInt($pk[$i]);
233
+        for ( $i = 0; $i < 32; ++$i ) {
234
+            $d |= self::chrToInt( $pk[$i] );
235 235
         }
236
-        if ($d === 0) {
237
-            throw new Exception('All zero public key');
236
+        if ( $d === 0 ) {
237
+            throw new Exception( 'All zero public key' );
238 238
         }
239 239
 
240 240
         /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */
@@ -244,34 +244,34 @@  discard block
 block discarded – undo
244 244
         ParagonIE_Sodium_Compat::$fastMult = true;
245 245
 
246 246
         /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $A */
247
-        $A = self::ge_frombytes_negate_vartime($pk);
247
+        $A = self::ge_frombytes_negate_vartime( $pk );
248 248
 
249 249
         /** @var string $hDigest */
250 250
         $hDigest = hash(
251 251
             'sha512',
252
-            self::substr($sig, 0, 32) .
253
-            self::substr($pk, 0, 32) .
252
+            self::substr( $sig, 0, 32 ) .
253
+            self::substr( $pk, 0, 32 ) .
254 254
             $message,
255 255
             true
256 256
         );
257 257
 
258 258
         /** @var string $h */
259
-        $h = self::sc_reduce($hDigest) . self::substr($hDigest, 32);
259
+        $h = self::sc_reduce( $hDigest ) . self::substr( $hDigest, 32 );
260 260
 
261 261
         /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $R */
262 262
         $R = self::ge_double_scalarmult_vartime(
263 263
             $h,
264 264
             $A,
265
-            self::substr($sig, 32)
265
+            self::substr( $sig, 32 )
266 266
         );
267 267
 
268 268
         /** @var string $rcheck */
269
-        $rcheck = self::ge_tobytes($R);
269
+        $rcheck = self::ge_tobytes( $R );
270 270
 
271 271
         // Reset ParagonIE_Sodium_Compat::$fastMult to what it was before.
272 272
         ParagonIE_Sodium_Compat::$fastMult = $orig;
273 273
 
274
-        return self::verify_32($rcheck, self::substr($sig, 0, 32));
274
+        return self::verify_32( $rcheck, self::substr( $sig, 0, 32 ) );
275 275
     }
276 276
 
277 277
     /**
@@ -281,10 +281,10 @@  discard block
 block discarded – undo
281 281
      * @return bool
282 282
      * @throws Exception
283 283
      */
284
-    public static function check_S_lt_L($S)
284
+    public static function check_S_lt_L( $S )
285 285
     {
286
-        if (self::strlen($S) < 32) {
287
-            throw new Exception('Signature must be 32 bytes');
286
+        if ( self::strlen( $S ) < 32 ) {
287
+            throw new Exception( 'Signature must be 32 bytes' );
288 288
         }
289 289
         static $L = array(
290 290
             0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
 
299 299
         do {
300 300
             --$i;
301
-            $x = self::chrToInt($S[$i]);
301
+            $x = self::chrToInt( $S[$i] );
302 302
             $c |= (
303
-                (($x - $L[$i]) >> 8) & $n
303
+                ( ( $x - $L[$i] ) >> 8 ) & $n
304 304
             );
305 305
             $n &= (
306
-                (($x ^ $L[$i]) - 1) >> 8
306
+                ( ( $x ^ $L[$i] ) - 1 ) >> 8
307 307
             );
308
-        } while ($i !== 0);
308
+        } while ( $i !== 0 );
309 309
 
310 310
         return $c === 0;
311 311
     }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      * @param string $R
315 315
      * @return bool
316 316
      */
317
-    public static function small_order($R)
317
+    public static function small_order( $R )
318 318
     {
319 319
         static $blacklist = array(
320 320
             /* 0 (order 4) */
@@ -402,14 +402,14 @@  discard block
 block discarded – undo
402 402
                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
403 403
             )
404 404
         );
405
-        $countBlacklist = count($blacklist);
405
+        $countBlacklist = count( $blacklist );
406 406
 
407
-        for ($i = 0; $i < $countBlacklist; ++$i) {
407
+        for ( $i = 0; $i < $countBlacklist; ++$i ) {
408 408
             $c = 0;
409
-            for ($j = 0; $j < 32; ++$j) {
410
-                $c |= self::chrToInt($R[$j]) ^ $blacklist[$i][$j];
409
+            for ( $j = 0; $j < 32; ++$j ) {
410
+                $c |= self::chrToInt( $R[$j] ) ^ $blacklist[$i][$j];
411 411
             }
412
-            if ($c === 0) {
412
+            if ( $c === 0 ) {
413 413
                 return true;
414 414
             }
415 415
         }
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Poly1305/State.php 1 patch
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_Core32_Poly1305_State', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_Poly1305_State', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      * @param string $key
48 48
      * @throws InvalidArgumentException
49 49
      */
50
-    public function __construct($key = '')
50
+    public function __construct( $key = '' )
51 51
     {
52
-        if (self::strlen($key) < 32) {
52
+        if ( self::strlen( $key ) < 32 ) {
53 53
             throw new InvalidArgumentException(
54 54
                 'Poly1305 requires a 32-byte key'
55 55
             );
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
         /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
58 58
         $this->r = array(
59 59
             // st->r[0] = ...
60
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4))
61
-                ->mask(0x3ffffff),
60
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 0, 4 ) )
61
+                ->mask( 0x3ffffff ),
62 62
             // st->r[1] = ...
63
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 3, 4))
64
-                ->shiftRight(2)
65
-                ->mask(0x3ffff03),
63
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 3, 4 ) )
64
+                ->shiftRight( 2 )
65
+                ->mask( 0x3ffff03 ),
66 66
             // st->r[2] = ...
67
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 6, 4))
68
-                ->shiftRight(4)
69
-                ->mask(0x3ffc0ff),
67
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 6, 4 ) )
68
+                ->shiftRight( 4 )
69
+                ->mask( 0x3ffc0ff ),
70 70
             // st->r[3] = ...
71
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 9, 4))
72
-                ->shiftRight(6)
73
-                ->mask(0x3f03fff),
71
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 9, 4 ) )
72
+                ->shiftRight( 6 )
73
+                ->mask( 0x3f03fff ),
74 74
             // st->r[4] = ...
75
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4))
76
-                ->shiftRight(8)
77
-                ->mask(0x00fffff)
75
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 12, 4 ) )
76
+                ->shiftRight( 8 )
77
+                ->mask( 0x00fffff )
78 78
         );
79 79
 
80 80
         /* h = 0 */
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
 
89 89
         /* save pad for later */
90 90
         $this->pad = array(
91
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4))->toInt64(),
92
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4))->toInt64(),
93
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4))->toInt64(),
94
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4))->toInt64(),
91
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 16, 4 ) )->toInt64(),
92
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 20, 4 ) )->toInt64(),
93
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 24, 4 ) )->toInt64(),
94
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 28, 4 ) )->toInt64(),
95 95
         );
96 96
 
97 97
         $this->leftover = 0;
@@ -104,53 +104,53 @@  discard block
 block discarded – undo
104 104
      * @param string $message
105 105
      * @return self
106 106
      */
107
-    public function update($message = '')
107
+    public function update( $message = '' )
108 108
     {
109
-        $bytes = self::strlen($message);
109
+        $bytes = self::strlen( $message );
110 110
 
111 111
         /* handle leftover */
112
-        if ($this->leftover) {
112
+        if ( $this->leftover ) {
113 113
             $want = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - $this->leftover;
114
-            if ($want > $bytes) {
114
+            if ( $want > $bytes ) {
115 115
                 $want = $bytes;
116 116
             }
117
-            for ($i = 0; $i < $want; ++$i) {
118
-                $mi = self::chrToInt($message[$i]);
117
+            for ( $i = 0; $i < $want; ++$i ) {
118
+                $mi = self::chrToInt( $message[$i] );
119 119
                 $this->buffer[$this->leftover + $i] = $mi;
120 120
             }
121 121
             // We snip off the leftmost bytes.
122
-            $message = self::substr($message, $want);
123
-            $bytes = self::strlen($message);
122
+            $message = self::substr( $message, $want );
123
+            $bytes = self::strlen( $message );
124 124
             $this->leftover += $want;
125
-            if ($this->leftover < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
125
+            if ( $this->leftover < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
126 126
                 // We still don't have enough to run $this->blocks()
127 127
                 return $this;
128 128
             }
129 129
 
130 130
             $this->blocks(
131
-                static::intArrayToString($this->buffer),
131
+                static::intArrayToString( $this->buffer ),
132 132
                 ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
133 133
             );
134 134
             $this->leftover = 0;
135 135
         }
136 136
 
137 137
         /* process full blocks */
138
-        if ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
139
-            $want = $bytes & ~(ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1);
140
-            if ($want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
141
-                $block = self::substr($message, 0, $want);
142
-                if (self::strlen($block) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
143
-                    $this->blocks($block, $want);
144
-                    $message = self::substr($message, $want);
145
-                    $bytes = self::strlen($message);
138
+        if ( $bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
139
+            $want = $bytes & ~( ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1 );
140
+            if ( $want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
141
+                $block = self::substr( $message, 0, $want );
142
+                if ( self::strlen( $block ) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
143
+                    $this->blocks( $block, $want );
144
+                    $message = self::substr( $message, $want );
145
+                    $bytes = self::strlen( $message );
146 146
                 }
147 147
             }
148 148
         }
149 149
 
150 150
         /* store leftover */
151
-        if ($bytes) {
152
-            for ($i = 0; $i < $bytes; ++$i) {
153
-                $mi = self::chrToInt($message[$i]);
151
+        if ( $bytes ) {
152
+            for ( $i = 0; $i < $bytes; ++$i ) {
153
+                $mi = self::chrToInt( $message[$i] );
154 154
                 $this->buffer[$this->leftover + $i] = $mi;
155 155
             }
156 156
             $this->leftover = (int) $this->leftover + $bytes;
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
      * @param int $bytes
166 166
      * @return self
167 167
      */
168
-    public function blocks($message, $bytes)
168
+    public function blocks( $message, $bytes )
169 169
     {
170
-        if (self::strlen($message) < 16) {
171
-            $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT);
170
+        if ( self::strlen( $message ) < 16 ) {
171
+            $message = str_pad( $message, 16, "\x00", STR_PAD_RIGHT );
172 172
         }
173
-        $hibit = ParagonIE_Sodium_Core32_Int32::fromInt($this->final ? 0 : 1 << 24); /* 1 << 128 */
173
+        $hibit = ParagonIE_Sodium_Core32_Int32::fromInt( $this->final ? 0 : 1 << 24 ); /* 1 << 128 */
174 174
         $zero = new ParagonIE_Sodium_Core32_Int64();
175 175
         /**
176 176
          * @var ParagonIE_Sodium_Core32_Int64 $d0
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
         $r3 = $this->r[3]->toInt64();
197 197
         $r4 = $this->r[4]->toInt64();
198 198
 
199
-        $s1 = $r1->toInt64()->mulInt(5);
200
-        $s2 = $r2->toInt64()->mulInt(5);
201
-        $s3 = $r3->toInt64()->mulInt(5);
202
-        $s4 = $r4->toInt64()->mulInt(5);
199
+        $s1 = $r1->toInt64()->mulInt( 5 );
200
+        $s2 = $r2->toInt64()->mulInt( 5 );
201
+        $s3 = $r3->toInt64()->mulInt( 5 );
202
+        $s4 = $r4->toInt64()->mulInt( 5 );
203 203
 
204 204
         $h0 = $this->h[0];
205 205
         $h1 = $this->h[1];
@@ -207,93 +207,93 @@  discard block
 block discarded – undo
207 207
         $h3 = $this->h[3];
208 208
         $h4 = $this->h[4];
209 209
 
210
-        while ($bytes >= ParagonIE_Sodium_Core_Poly1305::BLOCK_SIZE) {
210
+        while ( $bytes >= ParagonIE_Sodium_Core_Poly1305::BLOCK_SIZE ) {
211 211
             /* h += m[i] */
212 212
             $h0 = $h0->addInt32(
213
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 0, 4))
214
-                    ->mask(0x3ffffff)
213
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 0, 4 ) )
214
+                    ->mask( 0x3ffffff )
215 215
             );
216 216
             $h1 = $h1->addInt32(
217
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 3, 4))
218
-                    ->shiftRight(2)
219
-                    ->mask(0x3ffffff)
217
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 3, 4 ) )
218
+                    ->shiftRight( 2 )
219
+                    ->mask( 0x3ffffff )
220 220
             );
221 221
             $h2 = $h2->addInt32(
222
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 6, 4))
223
-                    ->shiftRight(4)
224
-                    ->mask(0x3ffffff)
222
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 6, 4 ) )
223
+                    ->shiftRight( 4 )
224
+                    ->mask( 0x3ffffff )
225 225
             );
226 226
             $h3 = $h3->addInt32(
227
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 9, 4))
228
-                    ->shiftRight(6)
229
-                    ->mask(0x3ffffff)
227
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 9, 4 ) )
228
+                    ->shiftRight( 6 )
229
+                    ->mask( 0x3ffffff )
230 230
             );
231 231
             $h4 = $h4->addInt32(
232
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4))
233
-                    ->shiftRight(8)
234
-                    ->orInt32($hibit)
232
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 12, 4 ) )
233
+                    ->shiftRight( 8 )
234
+                    ->orInt32( $hibit )
235 235
             );
236 236
 
237 237
             /* h *= r */
238 238
             $d0 = $zero
239
-                ->addInt64($h0->toInt64()->mulInt64($r0))
240
-                ->addInt64($h1->toInt64()->mulInt64($s4))
241
-                ->addInt64($h2->toInt64()->mulInt64($s3))
242
-                ->addInt64($h3->toInt64()->mulInt64($s2))
243
-                ->addInt64($h4->toInt64()->mulInt64($s1));
239
+                ->addInt64( $h0->toInt64()->mulInt64( $r0 ) )
240
+                ->addInt64( $h1->toInt64()->mulInt64( $s4 ) )
241
+                ->addInt64( $h2->toInt64()->mulInt64( $s3 ) )
242
+                ->addInt64( $h3->toInt64()->mulInt64( $s2 ) )
243
+                ->addInt64( $h4->toInt64()->mulInt64( $s1 ) );
244 244
 
245 245
             $d1 = $zero
246
-                ->addInt64($h0->toInt64()->mulInt64($r1))
247
-                ->addInt64($h1->toInt64()->mulInt64($r0))
248
-                ->addInt64($h2->toInt64()->mulInt64($s4))
249
-                ->addInt64($h3->toInt64()->mulInt64($s3))
250
-                ->addInt64($h4->toInt64()->mulInt64($s2));
246
+                ->addInt64( $h0->toInt64()->mulInt64( $r1 ) )
247
+                ->addInt64( $h1->toInt64()->mulInt64( $r0 ) )
248
+                ->addInt64( $h2->toInt64()->mulInt64( $s4 ) )
249
+                ->addInt64( $h3->toInt64()->mulInt64( $s3 ) )
250
+                ->addInt64( $h4->toInt64()->mulInt64( $s2 ) );
251 251
 
252 252
             $d2 = $zero
253
-                ->addInt64($h0->toInt64()->mulInt64($r2))
254
-                ->addInt64($h1->toInt64()->mulInt64($r1))
255
-                ->addInt64($h2->toInt64()->mulInt64($r0))
256
-                ->addInt64($h3->toInt64()->mulInt64($s4))
257
-                ->addInt64($h4->toInt64()->mulInt64($s3));
253
+                ->addInt64( $h0->toInt64()->mulInt64( $r2 ) )
254
+                ->addInt64( $h1->toInt64()->mulInt64( $r1 ) )
255
+                ->addInt64( $h2->toInt64()->mulInt64( $r0 ) )
256
+                ->addInt64( $h3->toInt64()->mulInt64( $s4 ) )
257
+                ->addInt64( $h4->toInt64()->mulInt64( $s3 ) );
258 258
 
259 259
             $d3 = $zero
260
-                ->addInt64($h0->toInt64()->mulInt64($r3))
261
-                ->addInt64($h1->toInt64()->mulInt64($r2))
262
-                ->addInt64($h2->toInt64()->mulInt64($r1))
263
-                ->addInt64($h3->toInt64()->mulInt64($r0))
264
-                ->addInt64($h4->toInt64()->mulInt64($s4));
260
+                ->addInt64( $h0->toInt64()->mulInt64( $r3 ) )
261
+                ->addInt64( $h1->toInt64()->mulInt64( $r2 ) )
262
+                ->addInt64( $h2->toInt64()->mulInt64( $r1 ) )
263
+                ->addInt64( $h3->toInt64()->mulInt64( $r0 ) )
264
+                ->addInt64( $h4->toInt64()->mulInt64( $s4 ) );
265 265
 
266 266
             $d4 = $zero
267
-                ->addInt64($h0->toInt64()->mulInt64($r4))
268
-                ->addInt64($h1->toInt64()->mulInt64($r3))
269
-                ->addInt64($h2->toInt64()->mulInt64($r2))
270
-                ->addInt64($h3->toInt64()->mulInt64($r1))
271
-                ->addInt64($h4->toInt64()->mulInt64($r0));
267
+                ->addInt64( $h0->toInt64()->mulInt64( $r4 ) )
268
+                ->addInt64( $h1->toInt64()->mulInt64( $r3 ) )
269
+                ->addInt64( $h2->toInt64()->mulInt64( $r2 ) )
270
+                ->addInt64( $h3->toInt64()->mulInt64( $r1 ) )
271
+                ->addInt64( $h4->toInt64()->mulInt64( $r0 ) );
272 272
 
273 273
             /* (partial) h %= p */
274
-            $c = $d0->shiftRight(26);
275
-            $h0 = $d0->toInt32()->mask(0x3ffffff);
276
-            $d1 = $d1->addInt64($c);
274
+            $c = $d0->shiftRight( 26 );
275
+            $h0 = $d0->toInt32()->mask( 0x3ffffff );
276
+            $d1 = $d1->addInt64( $c );
277 277
 
278
-            $c = $d1->shiftRight(26);
279
-            $h1 = $d1->toInt32()->mask(0x3ffffff);
280
-            $d2 = $d2->addInt64($c);
278
+            $c = $d1->shiftRight( 26 );
279
+            $h1 = $d1->toInt32()->mask( 0x3ffffff );
280
+            $d2 = $d2->addInt64( $c );
281 281
 
282
-            $c = $d2->shiftRight(26);
283
-            $h2 = $d2->toInt32()->mask(0x3ffffff);
284
-            $d3 = $d3->addInt64($c);
282
+            $c = $d2->shiftRight( 26 );
283
+            $h2 = $d2->toInt32()->mask( 0x3ffffff );
284
+            $d3 = $d3->addInt64( $c );
285 285
 
286
-            $c = $d3->shiftRight(26);
287
-            $h3 = $d3->toInt32()->mask(0x3ffffff);
288
-            $d4 = $d4->addInt64($c);
286
+            $c = $d3->shiftRight( 26 );
287
+            $h3 = $d3->toInt32()->mask( 0x3ffffff );
288
+            $d4 = $d4->addInt64( $c );
289 289
 
290
-            $c = $d4->shiftRight(26);
291
-            $h4 = $d4->toInt32()->mask(0x3ffffff);
292
-            $h0 = $h0->addInt32($c->toInt32()->mulInt(5));
290
+            $c = $d4->shiftRight( 26 );
291
+            $h4 = $d4->toInt32()->mask( 0x3ffffff );
292
+            $h0 = $h0->addInt32( $c->toInt32()->mulInt( 5 ) );
293 293
 
294
-            $c = $h0->shiftRight(26);
295
-            $h0 = $h0->mask(0x3ffffff);
296
-            $h1 = $h1->addInt32($c);
294
+            $c = $h0->shiftRight( 26 );
295
+            $h0 = $h0->mask( 0x3ffffff );
296
+            $h1 = $h1->addInt32( $c );
297 297
 
298 298
             // Chop off the left 32 bytes.
299 299
             $message = self::substr(
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         }
305 305
 
306 306
         /** @var array<int, ParagonIE_Sodium_Core32_Int32> $h */
307
-        $this->h = array($h0, $h1, $h2, $h3, $h4);
307
+        $this->h = array( $h0, $h1, $h2, $h3, $h4 );
308 308
         return $this;
309 309
     }
310 310
 
@@ -316,16 +316,16 @@  discard block
 block discarded – undo
316 316
     public function finish()
317 317
     {
318 318
         /* process the remaining block */
319
-        if ($this->leftover) {
319
+        if ( $this->leftover ) {
320 320
             $i = $this->leftover;
321 321
             $this->buffer[$i++] = 1;
322
-            for (; $i < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE; ++$i) {
322
+            for ( ; $i < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE; ++$i ) {
323 323
                 $this->buffer[$i] = 0;
324 324
             }
325 325
             $this->final = true;
326 326
             $this->blocks(
327 327
                 self::substr(
328
-                    static::intArrayToString($this->buffer),
328
+                    static::intArrayToString( $this->buffer ),
329 329
                     0,
330 330
                     ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
331 331
                 ),
@@ -352,73 +352,73 @@  discard block
 block discarded – undo
352 352
         $h3 = $this->h[3];
353 353
         $h4 = $this->h[4];
354 354
 
355
-        $c = $h1->shiftRight(26);           # $c = $h1 >> 26;
356
-        $h1 = $h1->mask(0x3ffffff);         # $h1 &= 0x3ffffff;
355
+        $c = $h1->shiftRight( 26 ); # $c = $h1 >> 26;
356
+        $h1 = $h1->mask( 0x3ffffff ); # $h1 &= 0x3ffffff;
357 357
 
358
-        $h2 = $h2->addInt32($c);            # $h2 += $c;
359
-        $c = $h2->shiftRight(26);           # $c = $h2 >> 26;
360
-        $h2 = $h2->mask(0x3ffffff);         # $h2 &= 0x3ffffff;
358
+        $h2 = $h2->addInt32( $c ); # $h2 += $c;
359
+        $c = $h2->shiftRight( 26 ); # $c = $h2 >> 26;
360
+        $h2 = $h2->mask( 0x3ffffff ); # $h2 &= 0x3ffffff;
361 361
 
362
-        $h3 = $h3->addInt32($c);            # $h3 += $c;
363
-        $c = $h3->shiftRight(26);           # $c = $h3 >> 26;
364
-        $h3 = $h3->mask(0x3ffffff);         # $h3 &= 0x3ffffff;
362
+        $h3 = $h3->addInt32( $c ); # $h3 += $c;
363
+        $c = $h3->shiftRight( 26 ); # $c = $h3 >> 26;
364
+        $h3 = $h3->mask( 0x3ffffff ); # $h3 &= 0x3ffffff;
365 365
 
366
-        $h4 = $h4->addInt32($c);            # $h4 += $c;
367
-        $c = $h4->shiftRight(26);           # $c = $h4 >> 26;
368
-        $h4 = $h4->mask(0x3ffffff);         # $h4 &= 0x3ffffff;
366
+        $h4 = $h4->addInt32( $c ); # $h4 += $c;
367
+        $c = $h4->shiftRight( 26 ); # $c = $h4 >> 26;
368
+        $h4 = $h4->mask( 0x3ffffff ); # $h4 &= 0x3ffffff;
369 369
 
370
-        $h0 = $h0->addInt32($c->mulInt(5)); # $h0 += self::mul($c, 5);
371
-        $c = $h0->shiftRight(26);           # $c = $h0 >> 26;
372
-        $h0 = $h0->mask(0x3ffffff);         # $h0 &= 0x3ffffff;
373
-        $h1 = $h1->addInt32($c);            # $h1 += $c;
370
+        $h0 = $h0->addInt32( $c->mulInt( 5 ) ); # $h0 += self::mul($c, 5);
371
+        $c = $h0->shiftRight( 26 ); # $c = $h0 >> 26;
372
+        $h0 = $h0->mask( 0x3ffffff ); # $h0 &= 0x3ffffff;
373
+        $h1 = $h1->addInt32( $c ); # $h1 += $c;
374 374
 
375 375
         /* compute h + -p */
376
-        $g0 = $h0->addInt(5);
377
-        $c  = $g0->shiftRight(26);
378
-        $g0 = $g0->mask(0x3ffffff);
379
-        $g1 = $h1->addInt32($c);
380
-        $c  = $g1->shiftRight(26);
381
-        $g1 = $g1->mask(0x3ffffff);
382
-        $g2 = $h2->addInt32($c);
383
-        $c  = $g2->shiftRight(26);
384
-        $g2 = $g2->mask(0x3ffffff);
385
-        $g3 = $h3->addInt32($c);
386
-        $c  = $g3->shiftRight(26);
387
-        $g3 = $g3->mask(0x3ffffff);
388
-        $g4 = $h4->addInt32($c)->subInt(1 << 26);
376
+        $g0 = $h0->addInt( 5 );
377
+        $c  = $g0->shiftRight( 26 );
378
+        $g0 = $g0->mask( 0x3ffffff );
379
+        $g1 = $h1->addInt32( $c );
380
+        $c  = $g1->shiftRight( 26 );
381
+        $g1 = $g1->mask( 0x3ffffff );
382
+        $g2 = $h2->addInt32( $c );
383
+        $c  = $g2->shiftRight( 26 );
384
+        $g2 = $g2->mask( 0x3ffffff );
385
+        $g3 = $h3->addInt32( $c );
386
+        $c  = $g3->shiftRight( 26 );
387
+        $g3 = $g3->mask( 0x3ffffff );
388
+        $g4 = $h4->addInt32( $c )->subInt( 1 << 26 );
389 389
 
390 390
         # $mask = ($g4 >> 31) - 1;
391 391
         /* select h if h < p, or h + -p if h >= p */
392
-        $mask = (int) (($g4->toInt() >> 31) + 1);
392
+        $mask = (int) ( ( $g4->toInt() >> 31 ) + 1 );
393 393
 
394
-        $g0 = $g0->mask($mask);
395
-        $g1 = $g1->mask($mask);
396
-        $g2 = $g2->mask($mask);
397
-        $g3 = $g3->mask($mask);
398
-        $g4 = $g4->mask($mask);
394
+        $g0 = $g0->mask( $mask );
395
+        $g1 = $g1->mask( $mask );
396
+        $g2 = $g2->mask( $mask );
397
+        $g3 = $g3->mask( $mask );
398
+        $g4 = $g4->mask( $mask );
399 399
 
400
-        $mask = (~$mask) & 0xffffffff;
400
+        $mask = ( ~$mask ) & 0xffffffff;
401 401
 
402
-        $h0 = $h0->mask($mask)->orInt32($g0);
403
-        $h1 = $h1->mask($mask)->orInt32($g1);
404
-        $h2 = $h2->mask($mask)->orInt32($g2);
405
-        $h3 = $h3->mask($mask)->orInt32($g3);
406
-        $h4 = $h4->mask($mask)->orInt32($g4);
402
+        $h0 = $h0->mask( $mask )->orInt32( $g0 );
403
+        $h1 = $h1->mask( $mask )->orInt32( $g1 );
404
+        $h2 = $h2->mask( $mask )->orInt32( $g2 );
405
+        $h3 = $h3->mask( $mask )->orInt32( $g3 );
406
+        $h4 = $h4->mask( $mask )->orInt32( $g4 );
407 407
 
408 408
         /* h = h % (2^128) */
409
-        $h0 = $h0->orInt32($h1->shiftLeft(26));
410
-        $h1 = $h1->shiftRight(6)->orInt32($h2->shiftLeft(20));
411
-        $h2 = $h2->shiftRight(12)->orInt32($h3->shiftLeft(14));
412
-        $h3 = $h3->shiftRight(18)->orInt32($h4->shiftLeft(8));
409
+        $h0 = $h0->orInt32( $h1->shiftLeft( 26 ) );
410
+        $h1 = $h1->shiftRight( 6 )->orInt32( $h2->shiftLeft( 20 ) );
411
+        $h2 = $h2->shiftRight( 12 )->orInt32( $h3->shiftLeft( 14 ) );
412
+        $h3 = $h3->shiftRight( 18 )->orInt32( $h4->shiftLeft( 8 ) );
413 413
 
414 414
         /* mac = (h + pad) % (2^128) */
415
-        $f = $h0->toInt64()->addInt64($this->pad[0]);
415
+        $f = $h0->toInt64()->addInt64( $this->pad[0] );
416 416
         $h0 = $f->toInt32();
417
-        $f = $h1->toInt64()->addInt64($this->pad[1])->addInt($h0->overflow);
417
+        $f = $h1->toInt64()->addInt64( $this->pad[1] )->addInt( $h0->overflow );
418 418
         $h1 = $f->toInt32();
419
-        $f = $h2->toInt64()->addInt64($this->pad[2])->addInt($h1->overflow);
419
+        $f = $h2->toInt64()->addInt64( $this->pad[2] )->addInt( $h1->overflow );
420 420
         $h2 = $f->toInt32();
421
-        $f = $h3->toInt64()->addInt64($this->pad[3])->addInt($h2->overflow);
421
+        $f = $h3->toInt64()->addInt64( $this->pad[3] )->addInt( $h2->overflow );
422 422
         $h3 = $f->toInt32();
423 423
 
424 424
         return $h0->toReverseString() .
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Curve25519/Ge/P3.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (class_exists('ParagonIE_Sodium_Core32_Curve25519_Ge_P3', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_Curve25519_Ge_P3', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
         ParagonIE_Sodium_Core32_Curve25519_Fe $z = null,
46 46
         ParagonIE_Sodium_Core32_Curve25519_Fe $t = null
47 47
     ) {
48
-        if ($x === null) {
48
+        if ( $x === null ) {
49 49
             $x = new ParagonIE_Sodium_Core32_Curve25519_Fe();
50 50
         }
51 51
         $this->X = $x;
52
-        if ($y === null) {
52
+        if ( $y === null ) {
53 53
             $y = new ParagonIE_Sodium_Core32_Curve25519_Fe();
54 54
         }
55 55
         $this->Y = $y;
56
-        if ($z === null) {
56
+        if ( $z === null ) {
57 57
             $z = new ParagonIE_Sodium_Core32_Curve25519_Fe();
58 58
         }
59 59
         $this->Z = $z;
60
-        if ($t === null) {
60
+        if ( $t === null ) {
61 61
             $t = new ParagonIE_Sodium_Core32_Curve25519_Fe();
62 62
         }
63 63
         $this->T = $t;
Please login to merge, or discard this patch.
src/library/sodium_compat/src/Core32/Curve25519/Ge/Cached.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 
4
-if (class_exists('ParagonIE_Sodium_Core32_Curve25519_Ge_Cached', false)) {
4
+if ( class_exists( 'ParagonIE_Sodium_Core32_Curve25519_Ge_Cached', false ) ) {
5 5
     return;
6 6
 }
7 7
 /**
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
         ParagonIE_Sodium_Core32_Curve25519_Fe $Z = null,
46 46
         ParagonIE_Sodium_Core32_Curve25519_Fe $T2d = null
47 47
     ) {
48
-        if ($YplusX === null) {
48
+        if ( $YplusX === null ) {
49 49
             $YplusX = new ParagonIE_Sodium_Core32_Curve25519_Fe();
50 50
         }
51 51
         $this->YplusX = $YplusX;
52
-        if ($YminusX === null) {
52
+        if ( $YminusX === null ) {
53 53
             $YminusX = new ParagonIE_Sodium_Core32_Curve25519_Fe();
54 54
         }
55 55
         $this->YminusX = $YminusX;
56
-        if ($Z === null) {
56
+        if ( $Z === null ) {
57 57
             $Z = new ParagonIE_Sodium_Core32_Curve25519_Fe();
58 58
         }
59 59
         $this->Z = $Z;
60
-        if ($T2d === null) {
60
+        if ( $T2d === null ) {
61 61
             $T2d = new ParagonIE_Sodium_Core32_Curve25519_Fe();
62 62
         }
63 63
         $this->T2d = $T2d;
Please login to merge, or discard this patch.