Completed
Pull Request — develop (#1726)
by
unknown
19:16
created
vendor/paragonie/sodium_compat/src/Core32/Int32.php 3 patches
Indentation   +859 added lines, -859 removed lines patch added patch discarded remove patch
@@ -9,863 +9,863 @@
 block discarded – undo
9 9
  */
10 10
 class ParagonIE_Sodium_Core32_Int32
11 11
 {
12
-    /**
13
-     * @var array<int, int> - two 16-bit integers
14
-     *
15
-     * 0 is the higher 16 bits
16
-     * 1 is the lower 16 bits
17
-     */
18
-    public $limbs = array(0, 0);
19
-
20
-    /**
21
-     * @var int
22
-     */
23
-    public $overflow = 0;
24
-
25
-    /**
26
-     * @var bool
27
-     */
28
-    public $unsignedInt = false;
29
-
30
-    /**
31
-     * ParagonIE_Sodium_Core32_Int32 constructor.
32
-     * @param array $array
33
-     * @param bool $unsignedInt
34
-     */
35
-    public function __construct($array = array(0, 0), $unsignedInt = false)
36
-    {
37
-        $this->limbs = array(
38
-            (int) $array[0],
39
-            (int) $array[1]
40
-        );
41
-        $this->overflow = 0;
42
-        $this->unsignedInt = $unsignedInt;
43
-    }
44
-
45
-    /**
46
-     * Adds two int32 objects
47
-     *
48
-     * @param ParagonIE_Sodium_Core32_Int32 $addend
49
-     * @return ParagonIE_Sodium_Core32_Int32
50
-     */
51
-    public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend)
52
-    {
53
-        $i0 = $this->limbs[0];
54
-        $i1 = $this->limbs[1];
55
-        $j0 = $addend->limbs[0];
56
-        $j1 = $addend->limbs[1];
57
-
58
-        $r1 = $i1 + ($j1 & 0xffff);
59
-        $carry = $r1 >> 16;
60
-
61
-        $r0 = $i0 + ($j0 & 0xffff) + $carry;
62
-        $carry = $r0 >> 16;
63
-
64
-        $r0 &= 0xffff;
65
-        $r1 &= 0xffff;
66
-
67
-        $return = new ParagonIE_Sodium_Core32_Int32(
68
-            array($r0, $r1)
69
-        );
70
-        $return->overflow = $carry;
71
-        $return->unsignedInt = $this->unsignedInt;
72
-        return $return;
73
-    }
74
-
75
-    /**
76
-     * Adds a normal integer to an int32 object
77
-     *
78
-     * @param int $int
79
-     * @return ParagonIE_Sodium_Core32_Int32
80
-     * @throws SodiumException
81
-     * @throws TypeError
82
-     */
83
-    public function addInt($int)
84
-    {
85
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
86
-        /** @var int $int */
87
-        $int = (int) $int;
88
-
89
-        $int = (int) $int;
90
-
91
-        $i0 = $this->limbs[0];
92
-        $i1 = $this->limbs[1];
93
-
94
-        $r1 = $i1 + ($int & 0xffff);
95
-        $carry = $r1 >> 16;
96
-
97
-        $r0 = $i0 + (($int >> 16) & 0xffff) + $carry;
98
-        $carry = $r0 >> 16;
99
-        $r0 &= 0xffff;
100
-        $r1 &= 0xffff;
101
-        $return = new ParagonIE_Sodium_Core32_Int32(
102
-            array($r0, $r1)
103
-        );
104
-        $return->overflow = $carry;
105
-        $return->unsignedInt = $this->unsignedInt;
106
-        return $return;
107
-    }
108
-
109
-    /**
110
-     * @param int $b
111
-     * @return int
112
-     */
113
-    public function compareInt($b = 0)
114
-    {
115
-        $gt = 0;
116
-        $eq = 1;
117
-
118
-        $i = 2;
119
-        $j = 0;
120
-        while ($i > 0) {
121
-            --$i;
122
-            /** @var int $x1 */
123
-            $x1 = $this->limbs[$i];
124
-            /** @var int $x2 */
125
-            $x2 = ($b >> ($j << 4)) & 0xffff;
126
-            /** @var int $gt */
127
-            $gt |= (($x2 - $x1) >> 8) & $eq;
128
-            /** @var int $eq */
129
-            $eq &= (($x2 ^ $x1) - 1) >> 8;
130
-        }
131
-        return ($gt + $gt - $eq) + 1;
132
-    }
133
-
134
-    /**
135
-     * @param int $m
136
-     * @return ParagonIE_Sodium_Core32_Int32
137
-     */
138
-    public function mask($m = 0)
139
-    {
140
-        /** @var int $hi */
141
-        $hi = ($m >> 16) & 0xffff;
142
-        /** @var int $lo */
143
-        $lo = ($m & 0xffff);
144
-        return new ParagonIE_Sodium_Core32_Int32(
145
-            array(
146
-                (int) ($this->limbs[0] & $hi),
147
-                (int) ($this->limbs[1] & $lo)
148
-            ),
149
-            $this->unsignedInt
150
-        );
151
-    }
152
-
153
-    /**
154
-     * @param array<int, int> $a
155
-     * @param array<int, int> $b
156
-     * @param int $baseLog2
157
-     * @return array<int, int>
158
-     */
159
-    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
160
-    {
161
-        $a_l = count($a);
162
-        $b_l = count($b);
163
-        /** @var array<int, int> $r */
164
-        $r = array_fill(0, $a_l + $b_l + 1, 0);
165
-        $base = 1 << $baseLog2;
166
-        for ($i = 0; $i < $a_l; ++$i) {
167
-            $a_i = $a[$i];
168
-            for ($j = 0; $j < $a_l; ++$j) {
169
-                $b_j = $b[$j];
170
-                $product = ($a_i * $b_j) + $r[$i + $j];
171
-                $carry = ($product >> $baseLog2 & 0xffff);
172
-                $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
173
-                $r[$i + $j + 1] += $carry;
174
-            }
175
-        }
176
-        return array_slice($r, 0, 5);
177
-    }
178
-
179
-    /**
180
-     * @param int $int
181
-     * @return ParagonIE_Sodium_Core32_Int32
182
-     */
183
-    public function mulIntFast($int)
184
-    {
185
-        // Handle negative numbers
186
-        $aNeg = ($this->limbs[0] >> 15) & 1;
187
-        $bNeg = ($int >> 31) & 1;
188
-        $a = array_reverse($this->limbs);
189
-        $b = array(
190
-            $int & 0xffff,
191
-            ($int >> 16) & 0xffff
192
-        );
193
-        if ($aNeg) {
194
-            for ($i = 0; $i < 2; ++$i) {
195
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
196
-            }
197
-            ++$a[0];
198
-        }
199
-        if ($bNeg) {
200
-            for ($i = 0; $i < 2; ++$i) {
201
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
202
-            }
203
-            ++$b[0];
204
-        }
205
-        // Multiply
206
-        $res = $this->multiplyLong($a, $b);
207
-
208
-        // Re-apply negation to results
209
-        if ($aNeg !== $bNeg) {
210
-            for ($i = 0; $i < 2; ++$i) {
211
-                $res[$i] = (0xffff ^ $res[$i]) & 0xffff;
212
-            }
213
-            // Handle integer overflow
214
-            $c = 1;
215
-            for ($i = 0; $i < 2; ++$i) {
216
-                $res[$i] += $c;
217
-                $c = $res[$i] >> 16;
218
-                $res[$i] &= 0xffff;
219
-            }
220
-        }
221
-
222
-        // Return our values
223
-        $return = new ParagonIE_Sodium_Core32_Int32();
224
-        $return->limbs = array(
225
-            $res[1] & 0xffff,
226
-            $res[0] & 0xffff
227
-        );
228
-        if (count($res) > 2) {
229
-            $return->overflow = $res[2] & 0xffff;
230
-        }
231
-        $return->unsignedInt = $this->unsignedInt;
232
-        return $return;
233
-    }
234
-
235
-    /**
236
-     * @param ParagonIE_Sodium_Core32_Int32 $right
237
-     * @return ParagonIE_Sodium_Core32_Int32
238
-     */
239
-    public function mulInt32Fast(ParagonIE_Sodium_Core32_Int32 $right)
240
-    {
241
-        $aNeg = ($this->limbs[0] >> 15) & 1;
242
-        $bNeg = ($right->limbs[0] >> 15) & 1;
243
-
244
-        $a = array_reverse($this->limbs);
245
-        $b = array_reverse($right->limbs);
246
-        if ($aNeg) {
247
-            for ($i = 0; $i < 2; ++$i) {
248
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
249
-            }
250
-            ++$a[0];
251
-        }
252
-        if ($bNeg) {
253
-            for ($i = 0; $i < 2; ++$i) {
254
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
255
-            }
256
-            ++$b[0];
257
-        }
258
-        $res = $this->multiplyLong($a, $b);
259
-        if ($aNeg !== $bNeg) {
260
-            if ($aNeg !== $bNeg) {
261
-                for ($i = 0; $i < 2; ++$i) {
262
-                    $res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
263
-                }
264
-                $c = 1;
265
-                for ($i = 0; $i < 2; ++$i) {
266
-                    $res[$i] += $c;
267
-                    $c = $res[$i] >> 16;
268
-                    $res[$i] &= 0xffff;
269
-                }
270
-            }
271
-        }
272
-        $return = new ParagonIE_Sodium_Core32_Int32();
273
-        $return->limbs = array(
274
-            $res[1] & 0xffff,
275
-            $res[0] & 0xffff
276
-        );
277
-        if (count($res) > 2) {
278
-            $return->overflow = $res[2];
279
-        }
280
-        return $return;
281
-    }
282
-
283
-    /**
284
-     * @param int $int
285
-     * @param int $size
286
-     * @return ParagonIE_Sodium_Core32_Int32
287
-     * @throws SodiumException
288
-     * @throws TypeError
289
-     */
290
-    public function mulInt($int = 0, $size = 0)
291
-    {
292
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
293
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
294
-        if (ParagonIE_Sodium_Compat::$fastMult) {
295
-            return $this->mulIntFast((int) $int);
296
-        }
297
-        /** @var int $int */
298
-        $int = (int) $int;
299
-        /** @var int $size */
300
-        $size = (int) $size;
301
-
302
-        if (!$size) {
303
-            $size = 31;
304
-        }
305
-        /** @var int $size */
306
-
307
-        $a = clone $this;
308
-        $return = new ParagonIE_Sodium_Core32_Int32();
309
-        $return->unsignedInt = $this->unsignedInt;
310
-
311
-        // Initialize:
312
-        $ret0 = 0;
313
-        $ret1 = 0;
314
-        $a0 = $a->limbs[0];
315
-        $a1 = $a->limbs[1];
316
-
317
-        /** @var int $size */
318
-        /** @var int $i */
319
-        for ($i = $size; $i >= 0; --$i) {
320
-            $m = (int) (-($int & 1));
321
-            $x0 = $a0 & $m;
322
-            $x1 = $a1 & $m;
323
-
324
-            $ret1 += $x1;
325
-            $c = $ret1 >> 16;
326
-
327
-            $ret0 += $x0 + $c;
328
-
329
-            $ret0 &= 0xffff;
330
-            $ret1 &= 0xffff;
331
-
332
-            $a1 = ($a1 << 1);
333
-            $x1 = $a1 >> 16;
334
-            $a0 = ($a0 << 1) | $x1;
335
-            $a0 &= 0xffff;
336
-            $a1 &= 0xffff;
337
-            $int >>= 1;
338
-        }
339
-        $return->limbs[0] = $ret0;
340
-        $return->limbs[1] = $ret1;
341
-        return $return;
342
-    }
343
-
344
-    /**
345
-     * @param ParagonIE_Sodium_Core32_Int32 $int
346
-     * @param int $size
347
-     * @return ParagonIE_Sodium_Core32_Int32
348
-     * @throws SodiumException
349
-     * @throws TypeError
350
-     */
351
-    public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0)
352
-    {
353
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
354
-        if (ParagonIE_Sodium_Compat::$fastMult) {
355
-            return $this->mulInt32Fast($int);
356
-        }
357
-        if (!$size) {
358
-            $size = 31;
359
-        }
360
-        /** @var int $size */
361
-
362
-        $a = clone $this;
363
-        $b = clone $int;
364
-        $return = new ParagonIE_Sodium_Core32_Int32();
365
-        $return->unsignedInt = $this->unsignedInt;
366
-
367
-        // Initialize:
368
-        $ret0 = 0;
369
-        $ret1 = 0;
370
-        $a0 = $a->limbs[0];
371
-        $a1 = $a->limbs[1];
372
-        $b0 = $b->limbs[0];
373
-        $b1 = $b->limbs[1];
374
-
375
-        /** @var int $size */
376
-        /** @var int $i */
377
-        for ($i = $size; $i >= 0; --$i) {
378
-            $m = (int) (-($b1 & 1));
379
-            $x0 = $a0 & $m;
380
-            $x1 = $a1 & $m;
381
-
382
-            $ret1 += $x1;
383
-            $c = $ret1 >> 16;
384
-
385
-            $ret0 += $x0 + $c;
386
-
387
-            $ret0 &= 0xffff;
388
-            $ret1 &= 0xffff;
389
-
390
-            $a1 = ($a1 << 1);
391
-            $x1 = $a1 >> 16;
392
-            $a0 = ($a0 << 1) | $x1;
393
-            $a0 &= 0xffff;
394
-            $a1 &= 0xffff;
395
-
396
-            $x0 = ($b0 & 1) << 16;
397
-            $b0 = ($b0 >> 1);
398
-            $b1 = (($b1 | $x0) >> 1);
399
-
400
-            $b0 &= 0xffff;
401
-            $b1 &= 0xffff;
402
-
403
-        }
404
-        $return->limbs[0] = $ret0;
405
-        $return->limbs[1] = $ret1;
406
-
407
-        return $return;
408
-    }
409
-
410
-    /**
411
-     * OR this 32-bit integer with another.
412
-     *
413
-     * @param ParagonIE_Sodium_Core32_Int32 $b
414
-     * @return ParagonIE_Sodium_Core32_Int32
415
-     */
416
-    public function orInt32(ParagonIE_Sodium_Core32_Int32 $b)
417
-    {
418
-        $return = new ParagonIE_Sodium_Core32_Int32();
419
-        $return->unsignedInt = $this->unsignedInt;
420
-        $return->limbs = array(
421
-            (int) ($this->limbs[0] | $b->limbs[0]),
422
-            (int) ($this->limbs[1] | $b->limbs[1])
423
-        );
424
-        /** @var int overflow */
425
-        $return->overflow = $this->overflow | $b->overflow;
426
-        return $return;
427
-    }
428
-
429
-    /**
430
-     * @param int $b
431
-     * @return bool
432
-     */
433
-    public function isGreaterThan($b = 0)
434
-    {
435
-        return $this->compareInt($b) > 0;
436
-    }
437
-
438
-    /**
439
-     * @param int $b
440
-     * @return bool
441
-     */
442
-    public function isLessThanInt($b = 0)
443
-    {
444
-        return $this->compareInt($b) < 0;
445
-    }
446
-
447
-    /**
448
-     * @param int $c
449
-     * @return ParagonIE_Sodium_Core32_Int32
450
-     * @throws SodiumException
451
-     * @throws TypeError
452
-     * @psalm-suppress MixedArrayAccess
453
-     */
454
-    public function rotateLeft($c = 0)
455
-    {
456
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
457
-        /** @var int $c */
458
-        $c = (int) $c;
459
-
460
-        $return = new ParagonIE_Sodium_Core32_Int32();
461
-        $return->unsignedInt = $this->unsignedInt;
462
-        $c &= 31;
463
-        if ($c === 0) {
464
-            // NOP, but we want a copy.
465
-            $return->limbs = $this->limbs;
466
-        } else {
467
-            /** @var int $c */
468
-
469
-            /** @var int $idx_shift */
470
-            $idx_shift = ($c >> 4) & 1;
471
-
472
-            /** @var int $sub_shift */
473
-            $sub_shift = $c & 15;
474
-
475
-            /** @var array<int, int> $limbs */
476
-            $limbs =& $return->limbs;
477
-
478
-            /** @var array<int, int> $myLimbs */
479
-            $myLimbs =& $this->limbs;
480
-
481
-            for ($i = 1; $i >= 0; --$i) {
482
-                /** @var int $j */
483
-                $j = ($i + $idx_shift) & 1;
484
-                /** @var int $k */
485
-                $k = ($i + $idx_shift + 1) & 1;
486
-                $limbs[$i] = (int) (
487
-                    (
488
-                        ((int) ($myLimbs[$j]) << $sub_shift)
489
-                            |
490
-                        ((int) ($myLimbs[$k]) >> (16 - $sub_shift))
491
-                    ) & 0xffff
492
-                );
493
-            }
494
-        }
495
-        return $return;
496
-    }
497
-
498
-    /**
499
-     * Rotate to the right
500
-     *
501
-     * @param int $c
502
-     * @return ParagonIE_Sodium_Core32_Int32
503
-     * @throws SodiumException
504
-     * @throws TypeError
505
-     * @psalm-suppress MixedArrayAccess
506
-     */
507
-    public function rotateRight($c = 0)
508
-    {
509
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
510
-        /** @var int $c */
511
-        $c = (int) $c;
512
-
513
-        $return = new ParagonIE_Sodium_Core32_Int32();
514
-        $return->unsignedInt = $this->unsignedInt;
515
-        $c &= 31;
516
-        /** @var int $c */
517
-        if ($c === 0) {
518
-            // NOP, but we want a copy.
519
-            $return->limbs = $this->limbs;
520
-        } else {
521
-            /** @var int $c */
522
-
523
-            /** @var int $idx_shift */
524
-            $idx_shift = ($c >> 4) & 1;
525
-
526
-            /** @var int $sub_shift */
527
-            $sub_shift = $c & 15;
528
-
529
-            /** @var array<int, int> $limbs */
530
-            $limbs =& $return->limbs;
531
-
532
-            /** @var array<int, int> $myLimbs */
533
-            $myLimbs =& $this->limbs;
534
-
535
-            for ($i = 1; $i >= 0; --$i) {
536
-                /** @var int $j */
537
-                $j = ($i - $idx_shift) & 1;
538
-                /** @var int $k */
539
-                $k = ($i - $idx_shift - 1) & 1;
540
-                $limbs[$i] = (int) (
541
-                    (
542
-                        ((int) ($myLimbs[$j]) >> (int) ($sub_shift))
543
-                            |
544
-                        ((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
545
-                    ) & 0xffff
546
-                );
547
-            }
548
-        }
549
-        return $return;
550
-    }
551
-
552
-    /**
553
-     * @param bool $bool
554
-     * @return self
555
-     */
556
-    public function setUnsignedInt($bool = false)
557
-    {
558
-        $this->unsignedInt = !empty($bool);
559
-        return $this;
560
-    }
561
-
562
-    /**
563
-     * @param int $c
564
-     * @return ParagonIE_Sodium_Core32_Int32
565
-     * @throws SodiumException
566
-     * @throws TypeError
567
-     */
568
-    public function shiftLeft($c = 0)
569
-    {
570
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
571
-        /** @var int $c */
572
-        $c = (int) $c;
573
-
574
-        $return = new ParagonIE_Sodium_Core32_Int32();
575
-        $return->unsignedInt = $this->unsignedInt;
576
-        $c &= 63;
577
-        /** @var int $c */
578
-        if ($c === 0) {
579
-            $return->limbs = $this->limbs;
580
-        } elseif ($c < 0) {
581
-            /** @var int $c */
582
-            return $this->shiftRight(-$c);
583
-        } else {
584
-            /** @var int $c */
585
-            /** @var int $tmp */
586
-            $tmp = $this->limbs[1] << $c;
587
-            $return->limbs[1] = (int)($tmp & 0xffff);
588
-            /** @var int $carry */
589
-            $carry = $tmp >> 16;
590
-
591
-            /** @var int $tmp */
592
-            $tmp = ($this->limbs[0] << $c) | ($carry & 0xffff);
593
-            $return->limbs[0] = (int) ($tmp & 0xffff);
594
-        }
595
-        return $return;
596
-    }
597
-
598
-    /**
599
-     * @param int $c
600
-     * @return ParagonIE_Sodium_Core32_Int32
601
-     * @throws SodiumException
602
-     * @throws TypeError
603
-     * @psalm-suppress MixedAssignment
604
-     * @psalm-suppress MixedOperand
605
-     */
606
-    public function shiftRight($c = 0)
607
-    {
608
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
609
-        /** @var int $c */
610
-        $c = (int) $c;
611
-
612
-        $return = new ParagonIE_Sodium_Core32_Int32();
613
-        $return->unsignedInt = $this->unsignedInt;
614
-        $c &= 63;
615
-        /** @var int $c */
616
-        if ($c >= 16) {
617
-            $return->limbs = array(
618
-                (int) ($this->overflow & 0xffff),
619
-                (int) ($this->limbs[0])
620
-            );
621
-            $return->overflow = $this->overflow >> 16;
622
-            return $return->shiftRight($c & 15);
623
-        }
624
-        if ($c === 0) {
625
-            $return->limbs = $this->limbs;
626
-        } elseif ($c < 0) {
627
-            /** @var int $c */
628
-            return $this->shiftLeft(-$c);
629
-        } else {
630
-            if (!is_int($c)) {
631
-                throw new TypeError();
632
-            }
633
-            /** @var int $c */
634
-            // $return->limbs[0] = (int) (($this->limbs[0] >> $c) & 0xffff);
635
-            $carryLeft = (int) ($this->overflow & ((1 << ($c + 1)) - 1));
636
-            $return->limbs[0] = (int) ((($this->limbs[0] >> $c) | ($carryLeft << (16 - $c))) & 0xffff);
637
-            $carryRight = (int) ($this->limbs[0] & ((1 << ($c + 1)) - 1));
638
-            $return->limbs[1] = (int) ((($this->limbs[1] >> $c) | ($carryRight << (16 - $c))) & 0xffff);
639
-            $return->overflow >>= $c;
640
-        }
641
-        return $return;
642
-    }
643
-
644
-    /**
645
-     * Subtract a normal integer from an int32 object.
646
-     *
647
-     * @param int $int
648
-     * @return ParagonIE_Sodium_Core32_Int32
649
-     * @throws SodiumException
650
-     * @throws TypeError
651
-     */
652
-    public function subInt($int)
653
-    {
654
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
655
-        /** @var int $int */
656
-        $int = (int) $int;
657
-
658
-        $return = new ParagonIE_Sodium_Core32_Int32();
659
-        $return->unsignedInt = $this->unsignedInt;
660
-
661
-        /** @var int $tmp */
662
-        $tmp = $this->limbs[1] - ($int & 0xffff);
663
-        /** @var int $carry */
664
-        $carry = $tmp >> 16;
665
-        $return->limbs[1] = (int) ($tmp & 0xffff);
666
-
667
-        /** @var int $tmp */
668
-        $tmp = $this->limbs[0] - (($int >> 16) & 0xffff) + $carry;
669
-        $return->limbs[0] = (int) ($tmp & 0xffff);
670
-        return $return;
671
-    }
672
-
673
-    /**
674
-     * Subtract two int32 objects from each other
675
-     *
676
-     * @param ParagonIE_Sodium_Core32_Int32 $b
677
-     * @return ParagonIE_Sodium_Core32_Int32
678
-     */
679
-    public function subInt32(ParagonIE_Sodium_Core32_Int32 $b)
680
-    {
681
-        $return = new ParagonIE_Sodium_Core32_Int32();
682
-        $return->unsignedInt = $this->unsignedInt;
683
-
684
-        /** @var int $tmp */
685
-        $tmp = $this->limbs[1] - ($b->limbs[1] & 0xffff);
686
-        /** @var int $carry */
687
-        $carry = $tmp >> 16;
688
-        $return->limbs[1] = (int) ($tmp & 0xffff);
689
-
690
-        /** @var int $tmp */
691
-        $tmp = $this->limbs[0] - ($b->limbs[0] & 0xffff) + $carry;
692
-        $return->limbs[0] = (int) ($tmp & 0xffff);
693
-        return $return;
694
-    }
695
-
696
-    /**
697
-     * XOR this 32-bit integer with another.
698
-     *
699
-     * @param ParagonIE_Sodium_Core32_Int32 $b
700
-     * @return ParagonIE_Sodium_Core32_Int32
701
-     */
702
-    public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b)
703
-    {
704
-        $return = new ParagonIE_Sodium_Core32_Int32();
705
-        $return->unsignedInt = $this->unsignedInt;
706
-        $return->limbs = array(
707
-            (int) ($this->limbs[0] ^ $b->limbs[0]),
708
-            (int) ($this->limbs[1] ^ $b->limbs[1])
709
-        );
710
-        return $return;
711
-    }
712
-
713
-    /**
714
-     * @param int $signed
715
-     * @return self
716
-     * @throws SodiumException
717
-     * @throws TypeError
718
-     */
719
-    public static function fromInt($signed)
720
-    {
721
-        ParagonIE_Sodium_Core32_Util::declareScalarType($signed, 'int', 1);;
722
-        /** @var int $signed */
723
-        $signed = (int) $signed;
724
-
725
-        return new ParagonIE_Sodium_Core32_Int32(
726
-            array(
727
-                (int) (($signed >> 16) & 0xffff),
728
-                (int) ($signed & 0xffff)
729
-            )
730
-        );
731
-    }
732
-
733
-    /**
734
-     * @param string $string
735
-     * @return self
736
-     * @throws SodiumException
737
-     * @throws TypeError
738
-     */
739
-    public static function fromString($string)
740
-    {
741
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
742
-        $string = (string) $string;
743
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
744
-            throw new RangeException(
745
-                'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
746
-            );
747
-        }
748
-        $return = new ParagonIE_Sodium_Core32_Int32();
749
-
750
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
751
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
752
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
753
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
754
-        return $return;
755
-    }
756
-
757
-    /**
758
-     * @param string $string
759
-     * @return self
760
-     * @throws SodiumException
761
-     * @throws TypeError
762
-     */
763
-    public static function fromReverseString($string)
764
-    {
765
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
766
-        $string = (string) $string;
767
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
768
-            throw new RangeException(
769
-                'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
770
-            );
771
-        }
772
-        $return = new ParagonIE_Sodium_Core32_Int32();
773
-
774
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
775
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
776
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
777
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
778
-        return $return;
779
-    }
780
-
781
-    /**
782
-     * @return array<int, int>
783
-     */
784
-    public function toArray()
785
-    {
786
-        return array((int) ($this->limbs[0] << 16 | $this->limbs[1]));
787
-    }
788
-
789
-    /**
790
-     * @return string
791
-     * @throws TypeError
792
-     */
793
-    public function toString()
794
-    {
795
-        return
796
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
797
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
798
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
799
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff);
800
-    }
801
-
802
-    /**
803
-     * @return int
804
-     */
805
-    public function toInt()
806
-    {
807
-        return (int) (
808
-            (($this->limbs[0] & 0xffff) << 16)
809
-                |
810
-            ($this->limbs[1] & 0xffff)
811
-        );
812
-    }
813
-
814
-    /**
815
-     * @return ParagonIE_Sodium_Core32_Int32
816
-     */
817
-    public function toInt32()
818
-    {
819
-        $return = new ParagonIE_Sodium_Core32_Int32();
820
-        $return->limbs[0] = (int) ($this->limbs[0] & 0xffff);
821
-        $return->limbs[1] = (int) ($this->limbs[1] & 0xffff);
822
-        $return->unsignedInt = $this->unsignedInt;
823
-        $return->overflow = (int) ($this->overflow & 0x7fffffff);
824
-        return $return;
825
-    }
826
-
827
-    /**
828
-     * @return ParagonIE_Sodium_Core32_Int64
829
-     */
830
-    public function toInt64()
831
-    {
832
-        $return = new ParagonIE_Sodium_Core32_Int64();
833
-        $return->unsignedInt = $this->unsignedInt;
834
-        if ($this->unsignedInt) {
835
-            $return->limbs[0] += (($this->overflow >> 16) & 0xffff);
836
-            $return->limbs[1] += (($this->overflow) & 0xffff);
837
-        } else {
838
-            $neg = -(($this->limbs[0] >> 15) & 1);
839
-            $return->limbs[0] = (int)($neg & 0xffff);
840
-            $return->limbs[1] = (int)($neg & 0xffff);
841
-        }
842
-        $return->limbs[2] = (int) ($this->limbs[0] & 0xffff);
843
-        $return->limbs[3] = (int) ($this->limbs[1] & 0xffff);
844
-        return $return;
845
-    }
846
-
847
-    /**
848
-     * @return string
849
-     * @throws TypeError
850
-     */
851
-    public function toReverseString()
852
-    {
853
-        return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
854
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
855
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
856
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
857
-    }
858
-
859
-    /**
860
-     * @return string
861
-     */
862
-    public function __toString()
863
-    {
864
-        try {
865
-            return $this->toString();
866
-        } catch (TypeError $ex) {
867
-            // PHP engine can't handle exceptions from __toString()
868
-            return '';
869
-        }
870
-    }
12
+	/**
13
+	 * @var array<int, int> - two 16-bit integers
14
+	 *
15
+	 * 0 is the higher 16 bits
16
+	 * 1 is the lower 16 bits
17
+	 */
18
+	public $limbs = array(0, 0);
19
+
20
+	/**
21
+	 * @var int
22
+	 */
23
+	public $overflow = 0;
24
+
25
+	/**
26
+	 * @var bool
27
+	 */
28
+	public $unsignedInt = false;
29
+
30
+	/**
31
+	 * ParagonIE_Sodium_Core32_Int32 constructor.
32
+	 * @param array $array
33
+	 * @param bool $unsignedInt
34
+	 */
35
+	public function __construct($array = array(0, 0), $unsignedInt = false)
36
+	{
37
+		$this->limbs = array(
38
+			(int) $array[0],
39
+			(int) $array[1]
40
+		);
41
+		$this->overflow = 0;
42
+		$this->unsignedInt = $unsignedInt;
43
+	}
44
+
45
+	/**
46
+	 * Adds two int32 objects
47
+	 *
48
+	 * @param ParagonIE_Sodium_Core32_Int32 $addend
49
+	 * @return ParagonIE_Sodium_Core32_Int32
50
+	 */
51
+	public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend)
52
+	{
53
+		$i0 = $this->limbs[0];
54
+		$i1 = $this->limbs[1];
55
+		$j0 = $addend->limbs[0];
56
+		$j1 = $addend->limbs[1];
57
+
58
+		$r1 = $i1 + ($j1 & 0xffff);
59
+		$carry = $r1 >> 16;
60
+
61
+		$r0 = $i0 + ($j0 & 0xffff) + $carry;
62
+		$carry = $r0 >> 16;
63
+
64
+		$r0 &= 0xffff;
65
+		$r1 &= 0xffff;
66
+
67
+		$return = new ParagonIE_Sodium_Core32_Int32(
68
+			array($r0, $r1)
69
+		);
70
+		$return->overflow = $carry;
71
+		$return->unsignedInt = $this->unsignedInt;
72
+		return $return;
73
+	}
74
+
75
+	/**
76
+	 * Adds a normal integer to an int32 object
77
+	 *
78
+	 * @param int $int
79
+	 * @return ParagonIE_Sodium_Core32_Int32
80
+	 * @throws SodiumException
81
+	 * @throws TypeError
82
+	 */
83
+	public function addInt($int)
84
+	{
85
+		ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
86
+		/** @var int $int */
87
+		$int = (int) $int;
88
+
89
+		$int = (int) $int;
90
+
91
+		$i0 = $this->limbs[0];
92
+		$i1 = $this->limbs[1];
93
+
94
+		$r1 = $i1 + ($int & 0xffff);
95
+		$carry = $r1 >> 16;
96
+
97
+		$r0 = $i0 + (($int >> 16) & 0xffff) + $carry;
98
+		$carry = $r0 >> 16;
99
+		$r0 &= 0xffff;
100
+		$r1 &= 0xffff;
101
+		$return = new ParagonIE_Sodium_Core32_Int32(
102
+			array($r0, $r1)
103
+		);
104
+		$return->overflow = $carry;
105
+		$return->unsignedInt = $this->unsignedInt;
106
+		return $return;
107
+	}
108
+
109
+	/**
110
+	 * @param int $b
111
+	 * @return int
112
+	 */
113
+	public function compareInt($b = 0)
114
+	{
115
+		$gt = 0;
116
+		$eq = 1;
117
+
118
+		$i = 2;
119
+		$j = 0;
120
+		while ($i > 0) {
121
+			--$i;
122
+			/** @var int $x1 */
123
+			$x1 = $this->limbs[$i];
124
+			/** @var int $x2 */
125
+			$x2 = ($b >> ($j << 4)) & 0xffff;
126
+			/** @var int $gt */
127
+			$gt |= (($x2 - $x1) >> 8) & $eq;
128
+			/** @var int $eq */
129
+			$eq &= (($x2 ^ $x1) - 1) >> 8;
130
+		}
131
+		return ($gt + $gt - $eq) + 1;
132
+	}
133
+
134
+	/**
135
+	 * @param int $m
136
+	 * @return ParagonIE_Sodium_Core32_Int32
137
+	 */
138
+	public function mask($m = 0)
139
+	{
140
+		/** @var int $hi */
141
+		$hi = ($m >> 16) & 0xffff;
142
+		/** @var int $lo */
143
+		$lo = ($m & 0xffff);
144
+		return new ParagonIE_Sodium_Core32_Int32(
145
+			array(
146
+				(int) ($this->limbs[0] & $hi),
147
+				(int) ($this->limbs[1] & $lo)
148
+			),
149
+			$this->unsignedInt
150
+		);
151
+	}
152
+
153
+	/**
154
+	 * @param array<int, int> $a
155
+	 * @param array<int, int> $b
156
+	 * @param int $baseLog2
157
+	 * @return array<int, int>
158
+	 */
159
+	public function multiplyLong(array $a, array $b, $baseLog2 = 16)
160
+	{
161
+		$a_l = count($a);
162
+		$b_l = count($b);
163
+		/** @var array<int, int> $r */
164
+		$r = array_fill(0, $a_l + $b_l + 1, 0);
165
+		$base = 1 << $baseLog2;
166
+		for ($i = 0; $i < $a_l; ++$i) {
167
+			$a_i = $a[$i];
168
+			for ($j = 0; $j < $a_l; ++$j) {
169
+				$b_j = $b[$j];
170
+				$product = ($a_i * $b_j) + $r[$i + $j];
171
+				$carry = ($product >> $baseLog2 & 0xffff);
172
+				$r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
173
+				$r[$i + $j + 1] += $carry;
174
+			}
175
+		}
176
+		return array_slice($r, 0, 5);
177
+	}
178
+
179
+	/**
180
+	 * @param int $int
181
+	 * @return ParagonIE_Sodium_Core32_Int32
182
+	 */
183
+	public function mulIntFast($int)
184
+	{
185
+		// Handle negative numbers
186
+		$aNeg = ($this->limbs[0] >> 15) & 1;
187
+		$bNeg = ($int >> 31) & 1;
188
+		$a = array_reverse($this->limbs);
189
+		$b = array(
190
+			$int & 0xffff,
191
+			($int >> 16) & 0xffff
192
+		);
193
+		if ($aNeg) {
194
+			for ($i = 0; $i < 2; ++$i) {
195
+				$a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
196
+			}
197
+			++$a[0];
198
+		}
199
+		if ($bNeg) {
200
+			for ($i = 0; $i < 2; ++$i) {
201
+				$b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
202
+			}
203
+			++$b[0];
204
+		}
205
+		// Multiply
206
+		$res = $this->multiplyLong($a, $b);
207
+
208
+		// Re-apply negation to results
209
+		if ($aNeg !== $bNeg) {
210
+			for ($i = 0; $i < 2; ++$i) {
211
+				$res[$i] = (0xffff ^ $res[$i]) & 0xffff;
212
+			}
213
+			// Handle integer overflow
214
+			$c = 1;
215
+			for ($i = 0; $i < 2; ++$i) {
216
+				$res[$i] += $c;
217
+				$c = $res[$i] >> 16;
218
+				$res[$i] &= 0xffff;
219
+			}
220
+		}
221
+
222
+		// Return our values
223
+		$return = new ParagonIE_Sodium_Core32_Int32();
224
+		$return->limbs = array(
225
+			$res[1] & 0xffff,
226
+			$res[0] & 0xffff
227
+		);
228
+		if (count($res) > 2) {
229
+			$return->overflow = $res[2] & 0xffff;
230
+		}
231
+		$return->unsignedInt = $this->unsignedInt;
232
+		return $return;
233
+	}
234
+
235
+	/**
236
+	 * @param ParagonIE_Sodium_Core32_Int32 $right
237
+	 * @return ParagonIE_Sodium_Core32_Int32
238
+	 */
239
+	public function mulInt32Fast(ParagonIE_Sodium_Core32_Int32 $right)
240
+	{
241
+		$aNeg = ($this->limbs[0] >> 15) & 1;
242
+		$bNeg = ($right->limbs[0] >> 15) & 1;
243
+
244
+		$a = array_reverse($this->limbs);
245
+		$b = array_reverse($right->limbs);
246
+		if ($aNeg) {
247
+			for ($i = 0; $i < 2; ++$i) {
248
+				$a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
249
+			}
250
+			++$a[0];
251
+		}
252
+		if ($bNeg) {
253
+			for ($i = 0; $i < 2; ++$i) {
254
+				$b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
255
+			}
256
+			++$b[0];
257
+		}
258
+		$res = $this->multiplyLong($a, $b);
259
+		if ($aNeg !== $bNeg) {
260
+			if ($aNeg !== $bNeg) {
261
+				for ($i = 0; $i < 2; ++$i) {
262
+					$res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
263
+				}
264
+				$c = 1;
265
+				for ($i = 0; $i < 2; ++$i) {
266
+					$res[$i] += $c;
267
+					$c = $res[$i] >> 16;
268
+					$res[$i] &= 0xffff;
269
+				}
270
+			}
271
+		}
272
+		$return = new ParagonIE_Sodium_Core32_Int32();
273
+		$return->limbs = array(
274
+			$res[1] & 0xffff,
275
+			$res[0] & 0xffff
276
+		);
277
+		if (count($res) > 2) {
278
+			$return->overflow = $res[2];
279
+		}
280
+		return $return;
281
+	}
282
+
283
+	/**
284
+	 * @param int $int
285
+	 * @param int $size
286
+	 * @return ParagonIE_Sodium_Core32_Int32
287
+	 * @throws SodiumException
288
+	 * @throws TypeError
289
+	 */
290
+	public function mulInt($int = 0, $size = 0)
291
+	{
292
+		ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
293
+		ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
294
+		if (ParagonIE_Sodium_Compat::$fastMult) {
295
+			return $this->mulIntFast((int) $int);
296
+		}
297
+		/** @var int $int */
298
+		$int = (int) $int;
299
+		/** @var int $size */
300
+		$size = (int) $size;
301
+
302
+		if (!$size) {
303
+			$size = 31;
304
+		}
305
+		/** @var int $size */
306
+
307
+		$a = clone $this;
308
+		$return = new ParagonIE_Sodium_Core32_Int32();
309
+		$return->unsignedInt = $this->unsignedInt;
310
+
311
+		// Initialize:
312
+		$ret0 = 0;
313
+		$ret1 = 0;
314
+		$a0 = $a->limbs[0];
315
+		$a1 = $a->limbs[1];
316
+
317
+		/** @var int $size */
318
+		/** @var int $i */
319
+		for ($i = $size; $i >= 0; --$i) {
320
+			$m = (int) (-($int & 1));
321
+			$x0 = $a0 & $m;
322
+			$x1 = $a1 & $m;
323
+
324
+			$ret1 += $x1;
325
+			$c = $ret1 >> 16;
326
+
327
+			$ret0 += $x0 + $c;
328
+
329
+			$ret0 &= 0xffff;
330
+			$ret1 &= 0xffff;
331
+
332
+			$a1 = ($a1 << 1);
333
+			$x1 = $a1 >> 16;
334
+			$a0 = ($a0 << 1) | $x1;
335
+			$a0 &= 0xffff;
336
+			$a1 &= 0xffff;
337
+			$int >>= 1;
338
+		}
339
+		$return->limbs[0] = $ret0;
340
+		$return->limbs[1] = $ret1;
341
+		return $return;
342
+	}
343
+
344
+	/**
345
+	 * @param ParagonIE_Sodium_Core32_Int32 $int
346
+	 * @param int $size
347
+	 * @return ParagonIE_Sodium_Core32_Int32
348
+	 * @throws SodiumException
349
+	 * @throws TypeError
350
+	 */
351
+	public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0)
352
+	{
353
+		ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
354
+		if (ParagonIE_Sodium_Compat::$fastMult) {
355
+			return $this->mulInt32Fast($int);
356
+		}
357
+		if (!$size) {
358
+			$size = 31;
359
+		}
360
+		/** @var int $size */
361
+
362
+		$a = clone $this;
363
+		$b = clone $int;
364
+		$return = new ParagonIE_Sodium_Core32_Int32();
365
+		$return->unsignedInt = $this->unsignedInt;
366
+
367
+		// Initialize:
368
+		$ret0 = 0;
369
+		$ret1 = 0;
370
+		$a0 = $a->limbs[0];
371
+		$a1 = $a->limbs[1];
372
+		$b0 = $b->limbs[0];
373
+		$b1 = $b->limbs[1];
374
+
375
+		/** @var int $size */
376
+		/** @var int $i */
377
+		for ($i = $size; $i >= 0; --$i) {
378
+			$m = (int) (-($b1 & 1));
379
+			$x0 = $a0 & $m;
380
+			$x1 = $a1 & $m;
381
+
382
+			$ret1 += $x1;
383
+			$c = $ret1 >> 16;
384
+
385
+			$ret0 += $x0 + $c;
386
+
387
+			$ret0 &= 0xffff;
388
+			$ret1 &= 0xffff;
389
+
390
+			$a1 = ($a1 << 1);
391
+			$x1 = $a1 >> 16;
392
+			$a0 = ($a0 << 1) | $x1;
393
+			$a0 &= 0xffff;
394
+			$a1 &= 0xffff;
395
+
396
+			$x0 = ($b0 & 1) << 16;
397
+			$b0 = ($b0 >> 1);
398
+			$b1 = (($b1 | $x0) >> 1);
399
+
400
+			$b0 &= 0xffff;
401
+			$b1 &= 0xffff;
402
+
403
+		}
404
+		$return->limbs[0] = $ret0;
405
+		$return->limbs[1] = $ret1;
406
+
407
+		return $return;
408
+	}
409
+
410
+	/**
411
+	 * OR this 32-bit integer with another.
412
+	 *
413
+	 * @param ParagonIE_Sodium_Core32_Int32 $b
414
+	 * @return ParagonIE_Sodium_Core32_Int32
415
+	 */
416
+	public function orInt32(ParagonIE_Sodium_Core32_Int32 $b)
417
+	{
418
+		$return = new ParagonIE_Sodium_Core32_Int32();
419
+		$return->unsignedInt = $this->unsignedInt;
420
+		$return->limbs = array(
421
+			(int) ($this->limbs[0] | $b->limbs[0]),
422
+			(int) ($this->limbs[1] | $b->limbs[1])
423
+		);
424
+		/** @var int overflow */
425
+		$return->overflow = $this->overflow | $b->overflow;
426
+		return $return;
427
+	}
428
+
429
+	/**
430
+	 * @param int $b
431
+	 * @return bool
432
+	 */
433
+	public function isGreaterThan($b = 0)
434
+	{
435
+		return $this->compareInt($b) > 0;
436
+	}
437
+
438
+	/**
439
+	 * @param int $b
440
+	 * @return bool
441
+	 */
442
+	public function isLessThanInt($b = 0)
443
+	{
444
+		return $this->compareInt($b) < 0;
445
+	}
446
+
447
+	/**
448
+	 * @param int $c
449
+	 * @return ParagonIE_Sodium_Core32_Int32
450
+	 * @throws SodiumException
451
+	 * @throws TypeError
452
+	 * @psalm-suppress MixedArrayAccess
453
+	 */
454
+	public function rotateLeft($c = 0)
455
+	{
456
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
457
+		/** @var int $c */
458
+		$c = (int) $c;
459
+
460
+		$return = new ParagonIE_Sodium_Core32_Int32();
461
+		$return->unsignedInt = $this->unsignedInt;
462
+		$c &= 31;
463
+		if ($c === 0) {
464
+			// NOP, but we want a copy.
465
+			$return->limbs = $this->limbs;
466
+		} else {
467
+			/** @var int $c */
468
+
469
+			/** @var int $idx_shift */
470
+			$idx_shift = ($c >> 4) & 1;
471
+
472
+			/** @var int $sub_shift */
473
+			$sub_shift = $c & 15;
474
+
475
+			/** @var array<int, int> $limbs */
476
+			$limbs =& $return->limbs;
477
+
478
+			/** @var array<int, int> $myLimbs */
479
+			$myLimbs =& $this->limbs;
480
+
481
+			for ($i = 1; $i >= 0; --$i) {
482
+				/** @var int $j */
483
+				$j = ($i + $idx_shift) & 1;
484
+				/** @var int $k */
485
+				$k = ($i + $idx_shift + 1) & 1;
486
+				$limbs[$i] = (int) (
487
+					(
488
+						((int) ($myLimbs[$j]) << $sub_shift)
489
+							|
490
+						((int) ($myLimbs[$k]) >> (16 - $sub_shift))
491
+					) & 0xffff
492
+				);
493
+			}
494
+		}
495
+		return $return;
496
+	}
497
+
498
+	/**
499
+	 * Rotate to the right
500
+	 *
501
+	 * @param int $c
502
+	 * @return ParagonIE_Sodium_Core32_Int32
503
+	 * @throws SodiumException
504
+	 * @throws TypeError
505
+	 * @psalm-suppress MixedArrayAccess
506
+	 */
507
+	public function rotateRight($c = 0)
508
+	{
509
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
510
+		/** @var int $c */
511
+		$c = (int) $c;
512
+
513
+		$return = new ParagonIE_Sodium_Core32_Int32();
514
+		$return->unsignedInt = $this->unsignedInt;
515
+		$c &= 31;
516
+		/** @var int $c */
517
+		if ($c === 0) {
518
+			// NOP, but we want a copy.
519
+			$return->limbs = $this->limbs;
520
+		} else {
521
+			/** @var int $c */
522
+
523
+			/** @var int $idx_shift */
524
+			$idx_shift = ($c >> 4) & 1;
525
+
526
+			/** @var int $sub_shift */
527
+			$sub_shift = $c & 15;
528
+
529
+			/** @var array<int, int> $limbs */
530
+			$limbs =& $return->limbs;
531
+
532
+			/** @var array<int, int> $myLimbs */
533
+			$myLimbs =& $this->limbs;
534
+
535
+			for ($i = 1; $i >= 0; --$i) {
536
+				/** @var int $j */
537
+				$j = ($i - $idx_shift) & 1;
538
+				/** @var int $k */
539
+				$k = ($i - $idx_shift - 1) & 1;
540
+				$limbs[$i] = (int) (
541
+					(
542
+						((int) ($myLimbs[$j]) >> (int) ($sub_shift))
543
+							|
544
+						((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
545
+					) & 0xffff
546
+				);
547
+			}
548
+		}
549
+		return $return;
550
+	}
551
+
552
+	/**
553
+	 * @param bool $bool
554
+	 * @return self
555
+	 */
556
+	public function setUnsignedInt($bool = false)
557
+	{
558
+		$this->unsignedInt = !empty($bool);
559
+		return $this;
560
+	}
561
+
562
+	/**
563
+	 * @param int $c
564
+	 * @return ParagonIE_Sodium_Core32_Int32
565
+	 * @throws SodiumException
566
+	 * @throws TypeError
567
+	 */
568
+	public function shiftLeft($c = 0)
569
+	{
570
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
571
+		/** @var int $c */
572
+		$c = (int) $c;
573
+
574
+		$return = new ParagonIE_Sodium_Core32_Int32();
575
+		$return->unsignedInt = $this->unsignedInt;
576
+		$c &= 63;
577
+		/** @var int $c */
578
+		if ($c === 0) {
579
+			$return->limbs = $this->limbs;
580
+		} elseif ($c < 0) {
581
+			/** @var int $c */
582
+			return $this->shiftRight(-$c);
583
+		} else {
584
+			/** @var int $c */
585
+			/** @var int $tmp */
586
+			$tmp = $this->limbs[1] << $c;
587
+			$return->limbs[1] = (int)($tmp & 0xffff);
588
+			/** @var int $carry */
589
+			$carry = $tmp >> 16;
590
+
591
+			/** @var int $tmp */
592
+			$tmp = ($this->limbs[0] << $c) | ($carry & 0xffff);
593
+			$return->limbs[0] = (int) ($tmp & 0xffff);
594
+		}
595
+		return $return;
596
+	}
597
+
598
+	/**
599
+	 * @param int $c
600
+	 * @return ParagonIE_Sodium_Core32_Int32
601
+	 * @throws SodiumException
602
+	 * @throws TypeError
603
+	 * @psalm-suppress MixedAssignment
604
+	 * @psalm-suppress MixedOperand
605
+	 */
606
+	public function shiftRight($c = 0)
607
+	{
608
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
609
+		/** @var int $c */
610
+		$c = (int) $c;
611
+
612
+		$return = new ParagonIE_Sodium_Core32_Int32();
613
+		$return->unsignedInt = $this->unsignedInt;
614
+		$c &= 63;
615
+		/** @var int $c */
616
+		if ($c >= 16) {
617
+			$return->limbs = array(
618
+				(int) ($this->overflow & 0xffff),
619
+				(int) ($this->limbs[0])
620
+			);
621
+			$return->overflow = $this->overflow >> 16;
622
+			return $return->shiftRight($c & 15);
623
+		}
624
+		if ($c === 0) {
625
+			$return->limbs = $this->limbs;
626
+		} elseif ($c < 0) {
627
+			/** @var int $c */
628
+			return $this->shiftLeft(-$c);
629
+		} else {
630
+			if (!is_int($c)) {
631
+				throw new TypeError();
632
+			}
633
+			/** @var int $c */
634
+			// $return->limbs[0] = (int) (($this->limbs[0] >> $c) & 0xffff);
635
+			$carryLeft = (int) ($this->overflow & ((1 << ($c + 1)) - 1));
636
+			$return->limbs[0] = (int) ((($this->limbs[0] >> $c) | ($carryLeft << (16 - $c))) & 0xffff);
637
+			$carryRight = (int) ($this->limbs[0] & ((1 << ($c + 1)) - 1));
638
+			$return->limbs[1] = (int) ((($this->limbs[1] >> $c) | ($carryRight << (16 - $c))) & 0xffff);
639
+			$return->overflow >>= $c;
640
+		}
641
+		return $return;
642
+	}
643
+
644
+	/**
645
+	 * Subtract a normal integer from an int32 object.
646
+	 *
647
+	 * @param int $int
648
+	 * @return ParagonIE_Sodium_Core32_Int32
649
+	 * @throws SodiumException
650
+	 * @throws TypeError
651
+	 */
652
+	public function subInt($int)
653
+	{
654
+		ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
655
+		/** @var int $int */
656
+		$int = (int) $int;
657
+
658
+		$return = new ParagonIE_Sodium_Core32_Int32();
659
+		$return->unsignedInt = $this->unsignedInt;
660
+
661
+		/** @var int $tmp */
662
+		$tmp = $this->limbs[1] - ($int & 0xffff);
663
+		/** @var int $carry */
664
+		$carry = $tmp >> 16;
665
+		$return->limbs[1] = (int) ($tmp & 0xffff);
666
+
667
+		/** @var int $tmp */
668
+		$tmp = $this->limbs[0] - (($int >> 16) & 0xffff) + $carry;
669
+		$return->limbs[0] = (int) ($tmp & 0xffff);
670
+		return $return;
671
+	}
672
+
673
+	/**
674
+	 * Subtract two int32 objects from each other
675
+	 *
676
+	 * @param ParagonIE_Sodium_Core32_Int32 $b
677
+	 * @return ParagonIE_Sodium_Core32_Int32
678
+	 */
679
+	public function subInt32(ParagonIE_Sodium_Core32_Int32 $b)
680
+	{
681
+		$return = new ParagonIE_Sodium_Core32_Int32();
682
+		$return->unsignedInt = $this->unsignedInt;
683
+
684
+		/** @var int $tmp */
685
+		$tmp = $this->limbs[1] - ($b->limbs[1] & 0xffff);
686
+		/** @var int $carry */
687
+		$carry = $tmp >> 16;
688
+		$return->limbs[1] = (int) ($tmp & 0xffff);
689
+
690
+		/** @var int $tmp */
691
+		$tmp = $this->limbs[0] - ($b->limbs[0] & 0xffff) + $carry;
692
+		$return->limbs[0] = (int) ($tmp & 0xffff);
693
+		return $return;
694
+	}
695
+
696
+	/**
697
+	 * XOR this 32-bit integer with another.
698
+	 *
699
+	 * @param ParagonIE_Sodium_Core32_Int32 $b
700
+	 * @return ParagonIE_Sodium_Core32_Int32
701
+	 */
702
+	public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b)
703
+	{
704
+		$return = new ParagonIE_Sodium_Core32_Int32();
705
+		$return->unsignedInt = $this->unsignedInt;
706
+		$return->limbs = array(
707
+			(int) ($this->limbs[0] ^ $b->limbs[0]),
708
+			(int) ($this->limbs[1] ^ $b->limbs[1])
709
+		);
710
+		return $return;
711
+	}
712
+
713
+	/**
714
+	 * @param int $signed
715
+	 * @return self
716
+	 * @throws SodiumException
717
+	 * @throws TypeError
718
+	 */
719
+	public static function fromInt($signed)
720
+	{
721
+		ParagonIE_Sodium_Core32_Util::declareScalarType($signed, 'int', 1);;
722
+		/** @var int $signed */
723
+		$signed = (int) $signed;
724
+
725
+		return new ParagonIE_Sodium_Core32_Int32(
726
+			array(
727
+				(int) (($signed >> 16) & 0xffff),
728
+				(int) ($signed & 0xffff)
729
+			)
730
+		);
731
+	}
732
+
733
+	/**
734
+	 * @param string $string
735
+	 * @return self
736
+	 * @throws SodiumException
737
+	 * @throws TypeError
738
+	 */
739
+	public static function fromString($string)
740
+	{
741
+		ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
742
+		$string = (string) $string;
743
+		if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
744
+			throw new RangeException(
745
+				'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
746
+			);
747
+		}
748
+		$return = new ParagonIE_Sodium_Core32_Int32();
749
+
750
+		$return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
751
+		$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
752
+		$return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
753
+		$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
754
+		return $return;
755
+	}
756
+
757
+	/**
758
+	 * @param string $string
759
+	 * @return self
760
+	 * @throws SodiumException
761
+	 * @throws TypeError
762
+	 */
763
+	public static function fromReverseString($string)
764
+	{
765
+		ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
766
+		$string = (string) $string;
767
+		if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
768
+			throw new RangeException(
769
+				'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
770
+			);
771
+		}
772
+		$return = new ParagonIE_Sodium_Core32_Int32();
773
+
774
+		$return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
775
+		$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
776
+		$return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
777
+		$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
778
+		return $return;
779
+	}
780
+
781
+	/**
782
+	 * @return array<int, int>
783
+	 */
784
+	public function toArray()
785
+	{
786
+		return array((int) ($this->limbs[0] << 16 | $this->limbs[1]));
787
+	}
788
+
789
+	/**
790
+	 * @return string
791
+	 * @throws TypeError
792
+	 */
793
+	public function toString()
794
+	{
795
+		return
796
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
797
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
798
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
799
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff);
800
+	}
801
+
802
+	/**
803
+	 * @return int
804
+	 */
805
+	public function toInt()
806
+	{
807
+		return (int) (
808
+			(($this->limbs[0] & 0xffff) << 16)
809
+				|
810
+			($this->limbs[1] & 0xffff)
811
+		);
812
+	}
813
+
814
+	/**
815
+	 * @return ParagonIE_Sodium_Core32_Int32
816
+	 */
817
+	public function toInt32()
818
+	{
819
+		$return = new ParagonIE_Sodium_Core32_Int32();
820
+		$return->limbs[0] = (int) ($this->limbs[0] & 0xffff);
821
+		$return->limbs[1] = (int) ($this->limbs[1] & 0xffff);
822
+		$return->unsignedInt = $this->unsignedInt;
823
+		$return->overflow = (int) ($this->overflow & 0x7fffffff);
824
+		return $return;
825
+	}
826
+
827
+	/**
828
+	 * @return ParagonIE_Sodium_Core32_Int64
829
+	 */
830
+	public function toInt64()
831
+	{
832
+		$return = new ParagonIE_Sodium_Core32_Int64();
833
+		$return->unsignedInt = $this->unsignedInt;
834
+		if ($this->unsignedInt) {
835
+			$return->limbs[0] += (($this->overflow >> 16) & 0xffff);
836
+			$return->limbs[1] += (($this->overflow) & 0xffff);
837
+		} else {
838
+			$neg = -(($this->limbs[0] >> 15) & 1);
839
+			$return->limbs[0] = (int)($neg & 0xffff);
840
+			$return->limbs[1] = (int)($neg & 0xffff);
841
+		}
842
+		$return->limbs[2] = (int) ($this->limbs[0] & 0xffff);
843
+		$return->limbs[3] = (int) ($this->limbs[1] & 0xffff);
844
+		return $return;
845
+	}
846
+
847
+	/**
848
+	 * @return string
849
+	 * @throws TypeError
850
+	 */
851
+	public function toReverseString()
852
+	{
853
+		return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
854
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
855
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
856
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
857
+	}
858
+
859
+	/**
860
+	 * @return string
861
+	 */
862
+	public function __toString()
863
+	{
864
+		try {
865
+			return $this->toString();
866
+		} catch (TypeError $ex) {
867
+			// PHP engine can't handle exceptions from __toString()
868
+			return '';
869
+		}
870
+	}
871 871
 }
Please login to merge, or discard this patch.
Spacing   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
      * 0 is the higher 16 bits
16 16
      * 1 is the lower 16 bits
17 17
      */
18
-    public $limbs = array(0, 0);
18
+    public $limbs = array( 0, 0 );
19 19
 
20 20
     /**
21 21
      * @var int
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
      * @param array $array
33 33
      * @param bool $unsignedInt
34 34
      */
35
-    public function __construct($array = array(0, 0), $unsignedInt = false)
35
+    public function __construct( $array = array( 0, 0 ), $unsignedInt = false )
36 36
     {
37 37
         $this->limbs = array(
38
-            (int) $array[0],
39
-            (int) $array[1]
38
+            (int)$array[ 0 ],
39
+            (int)$array[ 1 ]
40 40
         );
41 41
         $this->overflow = 0;
42 42
         $this->unsignedInt = $unsignedInt;
@@ -48,24 +48,24 @@  discard block
 block discarded – undo
48 48
      * @param ParagonIE_Sodium_Core32_Int32 $addend
49 49
      * @return ParagonIE_Sodium_Core32_Int32
50 50
      */
51
-    public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend)
51
+    public function addInt32( ParagonIE_Sodium_Core32_Int32 $addend )
52 52
     {
53
-        $i0 = $this->limbs[0];
54
-        $i1 = $this->limbs[1];
55
-        $j0 = $addend->limbs[0];
56
-        $j1 = $addend->limbs[1];
53
+        $i0 = $this->limbs[ 0 ];
54
+        $i1 = $this->limbs[ 1 ];
55
+        $j0 = $addend->limbs[ 0 ];
56
+        $j1 = $addend->limbs[ 1 ];
57 57
 
58
-        $r1 = $i1 + ($j1 & 0xffff);
58
+        $r1 = $i1 + ( $j1 & 0xffff );
59 59
         $carry = $r1 >> 16;
60 60
 
61
-        $r0 = $i0 + ($j0 & 0xffff) + $carry;
61
+        $r0 = $i0 + ( $j0 & 0xffff ) + $carry;
62 62
         $carry = $r0 >> 16;
63 63
 
64 64
         $r0 &= 0xffff;
65 65
         $r1 &= 0xffff;
66 66
 
67 67
         $return = new ParagonIE_Sodium_Core32_Int32(
68
-            array($r0, $r1)
68
+            array( $r0, $r1 )
69 69
         );
70 70
         $return->overflow = $carry;
71 71
         $return->unsignedInt = $this->unsignedInt;
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
      * @throws SodiumException
81 81
      * @throws TypeError
82 82
      */
83
-    public function addInt($int)
83
+    public function addInt( $int )
84 84
     {
85
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
85
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
86 86
         /** @var int $int */
87
-        $int = (int) $int;
87
+        $int = (int)$int;
88 88
 
89
-        $int = (int) $int;
89
+        $int = (int)$int;
90 90
 
91
-        $i0 = $this->limbs[0];
92
-        $i1 = $this->limbs[1];
91
+        $i0 = $this->limbs[ 0 ];
92
+        $i1 = $this->limbs[ 1 ];
93 93
 
94
-        $r1 = $i1 + ($int & 0xffff);
94
+        $r1 = $i1 + ( $int & 0xffff );
95 95
         $carry = $r1 >> 16;
96 96
 
97
-        $r0 = $i0 + (($int >> 16) & 0xffff) + $carry;
97
+        $r0 = $i0 + ( ( $int >> 16 ) & 0xffff ) + $carry;
98 98
         $carry = $r0 >> 16;
99 99
         $r0 &= 0xffff;
100 100
         $r1 &= 0xffff;
101 101
         $return = new ParagonIE_Sodium_Core32_Int32(
102
-            array($r0, $r1)
102
+            array( $r0, $r1 )
103 103
         );
104 104
         $return->overflow = $carry;
105 105
         $return->unsignedInt = $this->unsignedInt;
@@ -110,41 +110,41 @@  discard block
 block discarded – undo
110 110
      * @param int $b
111 111
      * @return int
112 112
      */
113
-    public function compareInt($b = 0)
113
+    public function compareInt( $b = 0 )
114 114
     {
115 115
         $gt = 0;
116 116
         $eq = 1;
117 117
 
118 118
         $i = 2;
119 119
         $j = 0;
120
-        while ($i > 0) {
120
+        while ( $i > 0 ) {
121 121
             --$i;
122 122
             /** @var int $x1 */
123
-            $x1 = $this->limbs[$i];
123
+            $x1 = $this->limbs[ $i ];
124 124
             /** @var int $x2 */
125
-            $x2 = ($b >> ($j << 4)) & 0xffff;
125
+            $x2 = ( $b >> ( $j << 4 ) ) & 0xffff;
126 126
             /** @var int $gt */
127
-            $gt |= (($x2 - $x1) >> 8) & $eq;
127
+            $gt |= ( ( $x2 - $x1 ) >> 8 ) & $eq;
128 128
             /** @var int $eq */
129
-            $eq &= (($x2 ^ $x1) - 1) >> 8;
129
+            $eq &= ( ( $x2 ^ $x1 ) - 1 ) >> 8;
130 130
         }
131
-        return ($gt + $gt - $eq) + 1;
131
+        return ( $gt + $gt - $eq ) + 1;
132 132
     }
133 133
 
134 134
     /**
135 135
      * @param int $m
136 136
      * @return ParagonIE_Sodium_Core32_Int32
137 137
      */
138
-    public function mask($m = 0)
138
+    public function mask( $m = 0 )
139 139
     {
140 140
         /** @var int $hi */
141
-        $hi = ($m >> 16) & 0xffff;
141
+        $hi = ( $m >> 16 ) & 0xffff;
142 142
         /** @var int $lo */
143
-        $lo = ($m & 0xffff);
143
+        $lo = ( $m & 0xffff );
144 144
         return new ParagonIE_Sodium_Core32_Int32(
145 145
             array(
146
-                (int) ($this->limbs[0] & $hi),
147
-                (int) ($this->limbs[1] & $lo)
146
+                (int)( $this->limbs[ 0 ] & $hi ),
147
+                (int)( $this->limbs[ 1 ] & $lo )
148 148
             ),
149 149
             $this->unsignedInt
150 150
         );
@@ -156,77 +156,77 @@  discard block
 block discarded – undo
156 156
      * @param int $baseLog2
157 157
      * @return array<int, int>
158 158
      */
159
-    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
159
+    public function multiplyLong( array $a, array $b, $baseLog2 = 16 )
160 160
     {
161
-        $a_l = count($a);
162
-        $b_l = count($b);
161
+        $a_l = count( $a );
162
+        $b_l = count( $b );
163 163
         /** @var array<int, int> $r */
164
-        $r = array_fill(0, $a_l + $b_l + 1, 0);
164
+        $r = array_fill( 0, $a_l + $b_l + 1, 0 );
165 165
         $base = 1 << $baseLog2;
166
-        for ($i = 0; $i < $a_l; ++$i) {
167
-            $a_i = $a[$i];
168
-            for ($j = 0; $j < $a_l; ++$j) {
169
-                $b_j = $b[$j];
170
-                $product = ($a_i * $b_j) + $r[$i + $j];
171
-                $carry = ($product >> $baseLog2 & 0xffff);
172
-                $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
173
-                $r[$i + $j + 1] += $carry;
166
+        for ( $i = 0; $i < $a_l; ++$i ) {
167
+            $a_i = $a[ $i ];
168
+            for ( $j = 0; $j < $a_l; ++$j ) {
169
+                $b_j = $b[ $j ];
170
+                $product = ( $a_i * $b_j ) + $r[ $i + $j ];
171
+                $carry = ( $product >> $baseLog2 & 0xffff );
172
+                $r[ $i + $j ] = ( $product - (int)( $carry * $base ) ) & 0xffff;
173
+                $r[ $i + $j + 1 ] += $carry;
174 174
             }
175 175
         }
176
-        return array_slice($r, 0, 5);
176
+        return array_slice( $r, 0, 5 );
177 177
     }
178 178
 
179 179
     /**
180 180
      * @param int $int
181 181
      * @return ParagonIE_Sodium_Core32_Int32
182 182
      */
183
-    public function mulIntFast($int)
183
+    public function mulIntFast( $int )
184 184
     {
185 185
         // Handle negative numbers
186
-        $aNeg = ($this->limbs[0] >> 15) & 1;
187
-        $bNeg = ($int >> 31) & 1;
188
-        $a = array_reverse($this->limbs);
186
+        $aNeg = ( $this->limbs[ 0 ] >> 15 ) & 1;
187
+        $bNeg = ( $int >> 31 ) & 1;
188
+        $a = array_reverse( $this->limbs );
189 189
         $b = array(
190 190
             $int & 0xffff,
191
-            ($int >> 16) & 0xffff
191
+            ( $int >> 16 ) & 0xffff
192 192
         );
193
-        if ($aNeg) {
194
-            for ($i = 0; $i < 2; ++$i) {
195
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
193
+        if ( $aNeg ) {
194
+            for ( $i = 0; $i < 2; ++$i ) {
195
+                $a[ $i ] = ( $a[ $i ] ^ 0xffff ) & 0xffff;
196 196
             }
197
-            ++$a[0];
197
+            ++$a[ 0 ];
198 198
         }
199
-        if ($bNeg) {
200
-            for ($i = 0; $i < 2; ++$i) {
201
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
199
+        if ( $bNeg ) {
200
+            for ( $i = 0; $i < 2; ++$i ) {
201
+                $b[ $i ] = ( $b[ $i ] ^ 0xffff ) & 0xffff;
202 202
             }
203
-            ++$b[0];
203
+            ++$b[ 0 ];
204 204
         }
205 205
         // Multiply
206
-        $res = $this->multiplyLong($a, $b);
206
+        $res = $this->multiplyLong( $a, $b );
207 207
 
208 208
         // Re-apply negation to results
209
-        if ($aNeg !== $bNeg) {
210
-            for ($i = 0; $i < 2; ++$i) {
211
-                $res[$i] = (0xffff ^ $res[$i]) & 0xffff;
209
+        if ( $aNeg !== $bNeg ) {
210
+            for ( $i = 0; $i < 2; ++$i ) {
211
+                $res[ $i ] = ( 0xffff ^ $res[ $i ] ) & 0xffff;
212 212
             }
213 213
             // Handle integer overflow
214 214
             $c = 1;
215
-            for ($i = 0; $i < 2; ++$i) {
216
-                $res[$i] += $c;
217
-                $c = $res[$i] >> 16;
218
-                $res[$i] &= 0xffff;
215
+            for ( $i = 0; $i < 2; ++$i ) {
216
+                $res[ $i ] += $c;
217
+                $c = $res[ $i ] >> 16;
218
+                $res[ $i ] &= 0xffff;
219 219
             }
220 220
         }
221 221
 
222 222
         // Return our values
223 223
         $return = new ParagonIE_Sodium_Core32_Int32();
224 224
         $return->limbs = array(
225
-            $res[1] & 0xffff,
226
-            $res[0] & 0xffff
225
+            $res[ 1 ] & 0xffff,
226
+            $res[ 0 ] & 0xffff
227 227
         );
228
-        if (count($res) > 2) {
229
-            $return->overflow = $res[2] & 0xffff;
228
+        if ( count( $res ) > 2 ) {
229
+            $return->overflow = $res[ 2 ] & 0xffff;
230 230
         }
231 231
         $return->unsignedInt = $this->unsignedInt;
232 232
         return $return;
@@ -236,46 +236,46 @@  discard block
 block discarded – undo
236 236
      * @param ParagonIE_Sodium_Core32_Int32 $right
237 237
      * @return ParagonIE_Sodium_Core32_Int32
238 238
      */
239
-    public function mulInt32Fast(ParagonIE_Sodium_Core32_Int32 $right)
239
+    public function mulInt32Fast( ParagonIE_Sodium_Core32_Int32 $right )
240 240
     {
241
-        $aNeg = ($this->limbs[0] >> 15) & 1;
242
-        $bNeg = ($right->limbs[0] >> 15) & 1;
243
-
244
-        $a = array_reverse($this->limbs);
245
-        $b = array_reverse($right->limbs);
246
-        if ($aNeg) {
247
-            for ($i = 0; $i < 2; ++$i) {
248
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
241
+        $aNeg = ( $this->limbs[ 0 ] >> 15 ) & 1;
242
+        $bNeg = ( $right->limbs[ 0 ] >> 15 ) & 1;
243
+
244
+        $a = array_reverse( $this->limbs );
245
+        $b = array_reverse( $right->limbs );
246
+        if ( $aNeg ) {
247
+            for ( $i = 0; $i < 2; ++$i ) {
248
+                $a[ $i ] = ( $a[ $i ] ^ 0xffff ) & 0xffff;
249 249
             }
250
-            ++$a[0];
250
+            ++$a[ 0 ];
251 251
         }
252
-        if ($bNeg) {
253
-            for ($i = 0; $i < 2; ++$i) {
254
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
252
+        if ( $bNeg ) {
253
+            for ( $i = 0; $i < 2; ++$i ) {
254
+                $b[ $i ] = ( $b[ $i ] ^ 0xffff ) & 0xffff;
255 255
             }
256
-            ++$b[0];
256
+            ++$b[ 0 ];
257 257
         }
258
-        $res = $this->multiplyLong($a, $b);
259
-        if ($aNeg !== $bNeg) {
260
-            if ($aNeg !== $bNeg) {
261
-                for ($i = 0; $i < 2; ++$i) {
262
-                    $res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
258
+        $res = $this->multiplyLong( $a, $b );
259
+        if ( $aNeg !== $bNeg ) {
260
+            if ( $aNeg !== $bNeg ) {
261
+                for ( $i = 0; $i < 2; ++$i ) {
262
+                    $res[ $i ] = ( $res[ $i ] ^ 0xffff ) & 0xffff;
263 263
                 }
264 264
                 $c = 1;
265
-                for ($i = 0; $i < 2; ++$i) {
266
-                    $res[$i] += $c;
267
-                    $c = $res[$i] >> 16;
268
-                    $res[$i] &= 0xffff;
265
+                for ( $i = 0; $i < 2; ++$i ) {
266
+                    $res[ $i ] += $c;
267
+                    $c = $res[ $i ] >> 16;
268
+                    $res[ $i ] &= 0xffff;
269 269
                 }
270 270
             }
271 271
         }
272 272
         $return = new ParagonIE_Sodium_Core32_Int32();
273 273
         $return->limbs = array(
274
-            $res[1] & 0xffff,
275
-            $res[0] & 0xffff
274
+            $res[ 1 ] & 0xffff,
275
+            $res[ 0 ] & 0xffff
276 276
         );
277
-        if (count($res) > 2) {
278
-            $return->overflow = $res[2];
277
+        if ( count( $res ) > 2 ) {
278
+            $return->overflow = $res[ 2 ];
279 279
         }
280 280
         return $return;
281 281
     }
@@ -287,19 +287,19 @@  discard block
 block discarded – undo
287 287
      * @throws SodiumException
288 288
      * @throws TypeError
289 289
      */
290
-    public function mulInt($int = 0, $size = 0)
290
+    public function mulInt( $int = 0, $size = 0 )
291 291
     {
292
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
293
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
294
-        if (ParagonIE_Sodium_Compat::$fastMult) {
295
-            return $this->mulIntFast((int) $int);
292
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
293
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $size, 'int', 2 );
294
+        if ( ParagonIE_Sodium_Compat::$fastMult ) {
295
+            return $this->mulIntFast( (int)$int );
296 296
         }
297 297
         /** @var int $int */
298
-        $int = (int) $int;
298
+        $int = (int)$int;
299 299
         /** @var int $size */
300
-        $size = (int) $size;
300
+        $size = (int)$size;
301 301
 
302
-        if (!$size) {
302
+        if ( ! $size ) {
303 303
             $size = 31;
304 304
         }
305 305
         /** @var int $size */
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
         // Initialize:
312 312
         $ret0 = 0;
313 313
         $ret1 = 0;
314
-        $a0 = $a->limbs[0];
315
-        $a1 = $a->limbs[1];
314
+        $a0 = $a->limbs[ 0 ];
315
+        $a1 = $a->limbs[ 1 ];
316 316
 
317 317
         /** @var int $size */
318 318
         /** @var int $i */
319
-        for ($i = $size; $i >= 0; --$i) {
320
-            $m = (int) (-($int & 1));
319
+        for ( $i = $size; $i >= 0; --$i ) {
320
+            $m = (int)(-( $int & 1 ));
321 321
             $x0 = $a0 & $m;
322 322
             $x1 = $a1 & $m;
323 323
 
@@ -329,15 +329,15 @@  discard block
 block discarded – undo
329 329
             $ret0 &= 0xffff;
330 330
             $ret1 &= 0xffff;
331 331
 
332
-            $a1 = ($a1 << 1);
332
+            $a1 = ( $a1 << 1 );
333 333
             $x1 = $a1 >> 16;
334
-            $a0 = ($a0 << 1) | $x1;
334
+            $a0 = ( $a0 << 1 ) | $x1;
335 335
             $a0 &= 0xffff;
336 336
             $a1 &= 0xffff;
337 337
             $int >>= 1;
338 338
         }
339
-        $return->limbs[0] = $ret0;
340
-        $return->limbs[1] = $ret1;
339
+        $return->limbs[ 0 ] = $ret0;
340
+        $return->limbs[ 1 ] = $ret1;
341 341
         return $return;
342 342
     }
343 343
 
@@ -348,13 +348,13 @@  discard block
 block discarded – undo
348 348
      * @throws SodiumException
349 349
      * @throws TypeError
350 350
      */
351
-    public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0)
351
+    public function mulInt32( ParagonIE_Sodium_Core32_Int32 $int, $size = 0 )
352 352
     {
353
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
354
-        if (ParagonIE_Sodium_Compat::$fastMult) {
355
-            return $this->mulInt32Fast($int);
353
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $size, 'int', 2 );
354
+        if ( ParagonIE_Sodium_Compat::$fastMult ) {
355
+            return $this->mulInt32Fast( $int );
356 356
         }
357
-        if (!$size) {
357
+        if ( ! $size ) {
358 358
             $size = 31;
359 359
         }
360 360
         /** @var int $size */
@@ -367,15 +367,15 @@  discard block
 block discarded – undo
367 367
         // Initialize:
368 368
         $ret0 = 0;
369 369
         $ret1 = 0;
370
-        $a0 = $a->limbs[0];
371
-        $a1 = $a->limbs[1];
372
-        $b0 = $b->limbs[0];
373
-        $b1 = $b->limbs[1];
370
+        $a0 = $a->limbs[ 0 ];
371
+        $a1 = $a->limbs[ 1 ];
372
+        $b0 = $b->limbs[ 0 ];
373
+        $b1 = $b->limbs[ 1 ];
374 374
 
375 375
         /** @var int $size */
376 376
         /** @var int $i */
377
-        for ($i = $size; $i >= 0; --$i) {
378
-            $m = (int) (-($b1 & 1));
377
+        for ( $i = $size; $i >= 0; --$i ) {
378
+            $m = (int)(-( $b1 & 1 ));
379 379
             $x0 = $a0 & $m;
380 380
             $x1 = $a1 & $m;
381 381
 
@@ -387,22 +387,22 @@  discard block
 block discarded – undo
387 387
             $ret0 &= 0xffff;
388 388
             $ret1 &= 0xffff;
389 389
 
390
-            $a1 = ($a1 << 1);
390
+            $a1 = ( $a1 << 1 );
391 391
             $x1 = $a1 >> 16;
392
-            $a0 = ($a0 << 1) | $x1;
392
+            $a0 = ( $a0 << 1 ) | $x1;
393 393
             $a0 &= 0xffff;
394 394
             $a1 &= 0xffff;
395 395
 
396
-            $x0 = ($b0 & 1) << 16;
397
-            $b0 = ($b0 >> 1);
398
-            $b1 = (($b1 | $x0) >> 1);
396
+            $x0 = ( $b0 & 1 ) << 16;
397
+            $b0 = ( $b0 >> 1 );
398
+            $b1 = ( ( $b1 | $x0 ) >> 1 );
399 399
 
400 400
             $b0 &= 0xffff;
401 401
             $b1 &= 0xffff;
402 402
 
403 403
         }
404
-        $return->limbs[0] = $ret0;
405
-        $return->limbs[1] = $ret1;
404
+        $return->limbs[ 0 ] = $ret0;
405
+        $return->limbs[ 1 ] = $ret1;
406 406
 
407 407
         return $return;
408 408
     }
@@ -413,13 +413,13 @@  discard block
 block discarded – undo
413 413
      * @param ParagonIE_Sodium_Core32_Int32 $b
414 414
      * @return ParagonIE_Sodium_Core32_Int32
415 415
      */
416
-    public function orInt32(ParagonIE_Sodium_Core32_Int32 $b)
416
+    public function orInt32( ParagonIE_Sodium_Core32_Int32 $b )
417 417
     {
418 418
         $return = new ParagonIE_Sodium_Core32_Int32();
419 419
         $return->unsignedInt = $this->unsignedInt;
420 420
         $return->limbs = array(
421
-            (int) ($this->limbs[0] | $b->limbs[0]),
422
-            (int) ($this->limbs[1] | $b->limbs[1])
421
+            (int)( $this->limbs[ 0 ] | $b->limbs[ 0 ] ),
422
+            (int)( $this->limbs[ 1 ] | $b->limbs[ 1 ] )
423 423
         );
424 424
         /** @var int overflow */
425 425
         $return->overflow = $this->overflow | $b->overflow;
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
      * @param int $b
431 431
      * @return bool
432 432
      */
433
-    public function isGreaterThan($b = 0)
433
+    public function isGreaterThan( $b = 0 )
434 434
     {
435
-        return $this->compareInt($b) > 0;
435
+        return $this->compareInt( $b ) > 0;
436 436
     }
437 437
 
438 438
     /**
439 439
      * @param int $b
440 440
      * @return bool
441 441
      */
442
-    public function isLessThanInt($b = 0)
442
+    public function isLessThanInt( $b = 0 )
443 443
     {
444
-        return $this->compareInt($b) < 0;
444
+        return $this->compareInt( $b ) < 0;
445 445
     }
446 446
 
447 447
     /**
@@ -451,43 +451,43 @@  discard block
 block discarded – undo
451 451
      * @throws TypeError
452 452
      * @psalm-suppress MixedArrayAccess
453 453
      */
454
-    public function rotateLeft($c = 0)
454
+    public function rotateLeft( $c = 0 )
455 455
     {
456
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
456
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
457 457
         /** @var int $c */
458
-        $c = (int) $c;
458
+        $c = (int)$c;
459 459
 
460 460
         $return = new ParagonIE_Sodium_Core32_Int32();
461 461
         $return->unsignedInt = $this->unsignedInt;
462 462
         $c &= 31;
463
-        if ($c === 0) {
463
+        if ( $c === 0 ) {
464 464
             // NOP, but we want a copy.
465 465
             $return->limbs = $this->limbs;
466 466
         } else {
467 467
             /** @var int $c */
468 468
 
469 469
             /** @var int $idx_shift */
470
-            $idx_shift = ($c >> 4) & 1;
470
+            $idx_shift = ( $c >> 4 ) & 1;
471 471
 
472 472
             /** @var int $sub_shift */
473 473
             $sub_shift = $c & 15;
474 474
 
475 475
             /** @var array<int, int> $limbs */
476
-            $limbs =& $return->limbs;
476
+            $limbs = & $return->limbs;
477 477
 
478 478
             /** @var array<int, int> $myLimbs */
479
-            $myLimbs =& $this->limbs;
479
+            $myLimbs = & $this->limbs;
480 480
 
481
-            for ($i = 1; $i >= 0; --$i) {
481
+            for ( $i = 1; $i >= 0; --$i ) {
482 482
                 /** @var int $j */
483
-                $j = ($i + $idx_shift) & 1;
483
+                $j = ( $i + $idx_shift ) & 1;
484 484
                 /** @var int $k */
485
-                $k = ($i + $idx_shift + 1) & 1;
486
-                $limbs[$i] = (int) (
485
+                $k = ( $i + $idx_shift + 1 ) & 1;
486
+                $limbs[ $i ] = (int)(
487 487
                     (
488
-                        ((int) ($myLimbs[$j]) << $sub_shift)
488
+                        ( (int)( $myLimbs[ $j ] ) << $sub_shift )
489 489
                             |
490
-                        ((int) ($myLimbs[$k]) >> (16 - $sub_shift))
490
+                        ( (int)( $myLimbs[ $k ] ) >> ( 16 - $sub_shift ) )
491 491
                     ) & 0xffff
492 492
                 );
493 493
             }
@@ -504,44 +504,44 @@  discard block
 block discarded – undo
504 504
      * @throws TypeError
505 505
      * @psalm-suppress MixedArrayAccess
506 506
      */
507
-    public function rotateRight($c = 0)
507
+    public function rotateRight( $c = 0 )
508 508
     {
509
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
509
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
510 510
         /** @var int $c */
511
-        $c = (int) $c;
511
+        $c = (int)$c;
512 512
 
513 513
         $return = new ParagonIE_Sodium_Core32_Int32();
514 514
         $return->unsignedInt = $this->unsignedInt;
515 515
         $c &= 31;
516 516
         /** @var int $c */
517
-        if ($c === 0) {
517
+        if ( $c === 0 ) {
518 518
             // NOP, but we want a copy.
519 519
             $return->limbs = $this->limbs;
520 520
         } else {
521 521
             /** @var int $c */
522 522
 
523 523
             /** @var int $idx_shift */
524
-            $idx_shift = ($c >> 4) & 1;
524
+            $idx_shift = ( $c >> 4 ) & 1;
525 525
 
526 526
             /** @var int $sub_shift */
527 527
             $sub_shift = $c & 15;
528 528
 
529 529
             /** @var array<int, int> $limbs */
530
-            $limbs =& $return->limbs;
530
+            $limbs = & $return->limbs;
531 531
 
532 532
             /** @var array<int, int> $myLimbs */
533
-            $myLimbs =& $this->limbs;
533
+            $myLimbs = & $this->limbs;
534 534
 
535
-            for ($i = 1; $i >= 0; --$i) {
535
+            for ( $i = 1; $i >= 0; --$i ) {
536 536
                 /** @var int $j */
537
-                $j = ($i - $idx_shift) & 1;
537
+                $j = ( $i - $idx_shift ) & 1;
538 538
                 /** @var int $k */
539
-                $k = ($i - $idx_shift - 1) & 1;
540
-                $limbs[$i] = (int) (
539
+                $k = ( $i - $idx_shift - 1 ) & 1;
540
+                $limbs[ $i ] = (int)(
541 541
                     (
542
-                        ((int) ($myLimbs[$j]) >> (int) ($sub_shift))
542
+                        ( (int)( $myLimbs[ $j ] ) >> (int)( $sub_shift ) )
543 543
                             |
544
-                        ((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
544
+                        ( (int)( $myLimbs[ $k ] ) << ( 16 - (int)( $sub_shift ) ) )
545 545
                     ) & 0xffff
546 546
                 );
547 547
             }
@@ -553,9 +553,9 @@  discard block
 block discarded – undo
553 553
      * @param bool $bool
554 554
      * @return self
555 555
      */
556
-    public function setUnsignedInt($bool = false)
556
+    public function setUnsignedInt( $bool = false )
557 557
     {
558
-        $this->unsignedInt = !empty($bool);
558
+        $this->unsignedInt = ! empty( $bool );
559 559
         return $this;
560 560
     }
561 561
 
@@ -565,32 +565,32 @@  discard block
 block discarded – undo
565 565
      * @throws SodiumException
566 566
      * @throws TypeError
567 567
      */
568
-    public function shiftLeft($c = 0)
568
+    public function shiftLeft( $c = 0 )
569 569
     {
570
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
570
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
571 571
         /** @var int $c */
572
-        $c = (int) $c;
572
+        $c = (int)$c;
573 573
 
574 574
         $return = new ParagonIE_Sodium_Core32_Int32();
575 575
         $return->unsignedInt = $this->unsignedInt;
576 576
         $c &= 63;
577 577
         /** @var int $c */
578
-        if ($c === 0) {
578
+        if ( $c === 0 ) {
579 579
             $return->limbs = $this->limbs;
580
-        } elseif ($c < 0) {
580
+        } elseif ( $c < 0 ) {
581 581
             /** @var int $c */
582 582
             return $this->shiftRight(-$c);
583 583
         } else {
584 584
             /** @var int $c */
585 585
             /** @var int $tmp */
586
-            $tmp = $this->limbs[1] << $c;
587
-            $return->limbs[1] = (int)($tmp & 0xffff);
586
+            $tmp = $this->limbs[ 1 ] << $c;
587
+            $return->limbs[ 1 ] = (int)( $tmp & 0xffff );
588 588
             /** @var int $carry */
589 589
             $carry = $tmp >> 16;
590 590
 
591 591
             /** @var int $tmp */
592
-            $tmp = ($this->limbs[0] << $c) | ($carry & 0xffff);
593
-            $return->limbs[0] = (int) ($tmp & 0xffff);
592
+            $tmp = ( $this->limbs[ 0 ] << $c ) | ( $carry & 0xffff );
593
+            $return->limbs[ 0 ] = (int)( $tmp & 0xffff );
594 594
         }
595 595
         return $return;
596 596
     }
@@ -603,39 +603,39 @@  discard block
 block discarded – undo
603 603
      * @psalm-suppress MixedAssignment
604 604
      * @psalm-suppress MixedOperand
605 605
      */
606
-    public function shiftRight($c = 0)
606
+    public function shiftRight( $c = 0 )
607 607
     {
608
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
608
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
609 609
         /** @var int $c */
610
-        $c = (int) $c;
610
+        $c = (int)$c;
611 611
 
612 612
         $return = new ParagonIE_Sodium_Core32_Int32();
613 613
         $return->unsignedInt = $this->unsignedInt;
614 614
         $c &= 63;
615 615
         /** @var int $c */
616
-        if ($c >= 16) {
616
+        if ( $c >= 16 ) {
617 617
             $return->limbs = array(
618
-                (int) ($this->overflow & 0xffff),
619
-                (int) ($this->limbs[0])
618
+                (int)( $this->overflow & 0xffff ),
619
+                (int)( $this->limbs[ 0 ] )
620 620
             );
621 621
             $return->overflow = $this->overflow >> 16;
622
-            return $return->shiftRight($c & 15);
622
+            return $return->shiftRight( $c & 15 );
623 623
         }
624
-        if ($c === 0) {
624
+        if ( $c === 0 ) {
625 625
             $return->limbs = $this->limbs;
626
-        } elseif ($c < 0) {
626
+        } elseif ( $c < 0 ) {
627 627
             /** @var int $c */
628 628
             return $this->shiftLeft(-$c);
629 629
         } else {
630
-            if (!is_int($c)) {
630
+            if ( ! is_int( $c ) ) {
631 631
                 throw new TypeError();
632 632
             }
633 633
             /** @var int $c */
634 634
             // $return->limbs[0] = (int) (($this->limbs[0] >> $c) & 0xffff);
635
-            $carryLeft = (int) ($this->overflow & ((1 << ($c + 1)) - 1));
636
-            $return->limbs[0] = (int) ((($this->limbs[0] >> $c) | ($carryLeft << (16 - $c))) & 0xffff);
637
-            $carryRight = (int) ($this->limbs[0] & ((1 << ($c + 1)) - 1));
638
-            $return->limbs[1] = (int) ((($this->limbs[1] >> $c) | ($carryRight << (16 - $c))) & 0xffff);
635
+            $carryLeft = (int)( $this->overflow & ( ( 1 << ( $c + 1 ) ) - 1 ) );
636
+            $return->limbs[ 0 ] = (int)( ( ( $this->limbs[ 0 ] >> $c ) | ( $carryLeft << ( 16 - $c ) ) ) & 0xffff );
637
+            $carryRight = (int)( $this->limbs[ 0 ] & ( ( 1 << ( $c + 1 ) ) - 1 ) );
638
+            $return->limbs[ 1 ] = (int)( ( ( $this->limbs[ 1 ] >> $c ) | ( $carryRight << ( 16 - $c ) ) ) & 0xffff );
639 639
             $return->overflow >>= $c;
640 640
         }
641 641
         return $return;
@@ -649,24 +649,24 @@  discard block
 block discarded – undo
649 649
      * @throws SodiumException
650 650
      * @throws TypeError
651 651
      */
652
-    public function subInt($int)
652
+    public function subInt( $int )
653 653
     {
654
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
654
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
655 655
         /** @var int $int */
656
-        $int = (int) $int;
656
+        $int = (int)$int;
657 657
 
658 658
         $return = new ParagonIE_Sodium_Core32_Int32();
659 659
         $return->unsignedInt = $this->unsignedInt;
660 660
 
661 661
         /** @var int $tmp */
662
-        $tmp = $this->limbs[1] - ($int & 0xffff);
662
+        $tmp = $this->limbs[ 1 ] - ( $int & 0xffff );
663 663
         /** @var int $carry */
664 664
         $carry = $tmp >> 16;
665
-        $return->limbs[1] = (int) ($tmp & 0xffff);
665
+        $return->limbs[ 1 ] = (int)( $tmp & 0xffff );
666 666
 
667 667
         /** @var int $tmp */
668
-        $tmp = $this->limbs[0] - (($int >> 16) & 0xffff) + $carry;
669
-        $return->limbs[0] = (int) ($tmp & 0xffff);
668
+        $tmp = $this->limbs[ 0 ] - ( ( $int >> 16 ) & 0xffff ) + $carry;
669
+        $return->limbs[ 0 ] = (int)( $tmp & 0xffff );
670 670
         return $return;
671 671
     }
672 672
 
@@ -676,20 +676,20 @@  discard block
 block discarded – undo
676 676
      * @param ParagonIE_Sodium_Core32_Int32 $b
677 677
      * @return ParagonIE_Sodium_Core32_Int32
678 678
      */
679
-    public function subInt32(ParagonIE_Sodium_Core32_Int32 $b)
679
+    public function subInt32( ParagonIE_Sodium_Core32_Int32 $b )
680 680
     {
681 681
         $return = new ParagonIE_Sodium_Core32_Int32();
682 682
         $return->unsignedInt = $this->unsignedInt;
683 683
 
684 684
         /** @var int $tmp */
685
-        $tmp = $this->limbs[1] - ($b->limbs[1] & 0xffff);
685
+        $tmp = $this->limbs[ 1 ] - ( $b->limbs[ 1 ] & 0xffff );
686 686
         /** @var int $carry */
687 687
         $carry = $tmp >> 16;
688
-        $return->limbs[1] = (int) ($tmp & 0xffff);
688
+        $return->limbs[ 1 ] = (int)( $tmp & 0xffff );
689 689
 
690 690
         /** @var int $tmp */
691
-        $tmp = $this->limbs[0] - ($b->limbs[0] & 0xffff) + $carry;
692
-        $return->limbs[0] = (int) ($tmp & 0xffff);
691
+        $tmp = $this->limbs[ 0 ] - ( $b->limbs[ 0 ] & 0xffff ) + $carry;
692
+        $return->limbs[ 0 ] = (int)( $tmp & 0xffff );
693 693
         return $return;
694 694
     }
695 695
 
@@ -699,13 +699,13 @@  discard block
 block discarded – undo
699 699
      * @param ParagonIE_Sodium_Core32_Int32 $b
700 700
      * @return ParagonIE_Sodium_Core32_Int32
701 701
      */
702
-    public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b)
702
+    public function xorInt32( ParagonIE_Sodium_Core32_Int32 $b )
703 703
     {
704 704
         $return = new ParagonIE_Sodium_Core32_Int32();
705 705
         $return->unsignedInt = $this->unsignedInt;
706 706
         $return->limbs = array(
707
-            (int) ($this->limbs[0] ^ $b->limbs[0]),
708
-            (int) ($this->limbs[1] ^ $b->limbs[1])
707
+            (int)( $this->limbs[ 0 ] ^ $b->limbs[ 0 ] ),
708
+            (int)( $this->limbs[ 1 ] ^ $b->limbs[ 1 ] )
709 709
         );
710 710
         return $return;
711 711
     }
@@ -716,16 +716,16 @@  discard block
 block discarded – undo
716 716
      * @throws SodiumException
717 717
      * @throws TypeError
718 718
      */
719
-    public static function fromInt($signed)
719
+    public static function fromInt( $signed )
720 720
     {
721
-        ParagonIE_Sodium_Core32_Util::declareScalarType($signed, 'int', 1);;
721
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $signed, 'int', 1 ); ;
722 722
         /** @var int $signed */
723
-        $signed = (int) $signed;
723
+        $signed = (int)$signed;
724 724
 
725 725
         return new ParagonIE_Sodium_Core32_Int32(
726 726
             array(
727
-                (int) (($signed >> 16) & 0xffff),
728
-                (int) ($signed & 0xffff)
727
+                (int)( ( $signed >> 16 ) & 0xffff ),
728
+                (int)( $signed & 0xffff )
729 729
             )
730 730
         );
731 731
     }
@@ -736,21 +736,21 @@  discard block
 block discarded – undo
736 736
      * @throws SodiumException
737 737
      * @throws TypeError
738 738
      */
739
-    public static function fromString($string)
739
+    public static function fromString( $string )
740 740
     {
741
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
742
-        $string = (string) $string;
743
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
741
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $string, 'string', 1 );
742
+        $string = (string)$string;
743
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $string ) !== 4 ) {
744 744
             throw new RangeException(
745
-                'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
745
+                'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen( $string ) . ' given.'
746 746
             );
747 747
         }
748 748
         $return = new ParagonIE_Sodium_Core32_Int32();
749 749
 
750
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
751
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
752
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
753
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
750
+        $return->limbs[ 0 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 0 ] ) & 0xff ) << 8 );
751
+        $return->limbs[ 0 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 1 ] ) & 0xff );
752
+        $return->limbs[ 1 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 2 ] ) & 0xff ) << 8 );
753
+        $return->limbs[ 1 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 3 ] ) & 0xff );
754 754
         return $return;
755 755
     }
756 756
 
@@ -760,21 +760,21 @@  discard block
 block discarded – undo
760 760
      * @throws SodiumException
761 761
      * @throws TypeError
762 762
      */
763
-    public static function fromReverseString($string)
763
+    public static function fromReverseString( $string )
764 764
     {
765
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
766
-        $string = (string) $string;
767
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
765
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $string, 'string', 1 );
766
+        $string = (string)$string;
767
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $string ) !== 4 ) {
768 768
             throw new RangeException(
769
-                'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
769
+                'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen( $string ) . ' given.'
770 770
             );
771 771
         }
772 772
         $return = new ParagonIE_Sodium_Core32_Int32();
773 773
 
774
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
775
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
776
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
777
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
774
+        $return->limbs[ 0 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 3 ] ) & 0xff ) << 8 );
775
+        $return->limbs[ 0 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 2 ] ) & 0xff );
776
+        $return->limbs[ 1 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 1 ] ) & 0xff ) << 8 );
777
+        $return->limbs[ 1 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 0 ] ) & 0xff );
778 778
         return $return;
779 779
     }
780 780
 
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
      */
784 784
     public function toArray()
785 785
     {
786
-        return array((int) ($this->limbs[0] << 16 | $this->limbs[1]));
786
+        return array( (int)( $this->limbs[ 0 ] << 16 | $this->limbs[ 1 ] ) );
787 787
     }
788 788
 
789 789
     /**
@@ -793,10 +793,10 @@  discard block
 block discarded – undo
793 793
     public function toString()
794 794
     {
795 795
         return
796
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
797
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
798
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
799
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff);
796
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 0 ] >> 8 ) & 0xff ) .
797
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 0 ] & 0xff ) .
798
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 1 ] >> 8 ) & 0xff ) .
799
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 1 ] & 0xff );
800 800
     }
801 801
 
802 802
     /**
@@ -804,10 +804,10 @@  discard block
 block discarded – undo
804 804
      */
805 805
     public function toInt()
806 806
     {
807
-        return (int) (
808
-            (($this->limbs[0] & 0xffff) << 16)
807
+        return (int)(
808
+            ( ( $this->limbs[ 0 ] & 0xffff ) << 16 )
809 809
                 |
810
-            ($this->limbs[1] & 0xffff)
810
+            ( $this->limbs[ 1 ] & 0xffff )
811 811
         );
812 812
     }
813 813
 
@@ -817,10 +817,10 @@  discard block
 block discarded – undo
817 817
     public function toInt32()
818 818
     {
819 819
         $return = new ParagonIE_Sodium_Core32_Int32();
820
-        $return->limbs[0] = (int) ($this->limbs[0] & 0xffff);
821
-        $return->limbs[1] = (int) ($this->limbs[1] & 0xffff);
820
+        $return->limbs[ 0 ] = (int)( $this->limbs[ 0 ] & 0xffff );
821
+        $return->limbs[ 1 ] = (int)( $this->limbs[ 1 ] & 0xffff );
822 822
         $return->unsignedInt = $this->unsignedInt;
823
-        $return->overflow = (int) ($this->overflow & 0x7fffffff);
823
+        $return->overflow = (int)( $this->overflow & 0x7fffffff );
824 824
         return $return;
825 825
     }
826 826
 
@@ -831,16 +831,16 @@  discard block
 block discarded – undo
831 831
     {
832 832
         $return = new ParagonIE_Sodium_Core32_Int64();
833 833
         $return->unsignedInt = $this->unsignedInt;
834
-        if ($this->unsignedInt) {
835
-            $return->limbs[0] += (($this->overflow >> 16) & 0xffff);
836
-            $return->limbs[1] += (($this->overflow) & 0xffff);
834
+        if ( $this->unsignedInt ) {
835
+            $return->limbs[ 0 ] += ( ( $this->overflow >> 16 ) & 0xffff );
836
+            $return->limbs[ 1 ] += ( ( $this->overflow ) & 0xffff );
837 837
         } else {
838
-            $neg = -(($this->limbs[0] >> 15) & 1);
839
-            $return->limbs[0] = (int)($neg & 0xffff);
840
-            $return->limbs[1] = (int)($neg & 0xffff);
838
+            $neg = -( ( $this->limbs[ 0 ] >> 15 ) & 1 );
839
+            $return->limbs[ 0 ] = (int)( $neg & 0xffff );
840
+            $return->limbs[ 1 ] = (int)( $neg & 0xffff );
841 841
         }
842
-        $return->limbs[2] = (int) ($this->limbs[0] & 0xffff);
843
-        $return->limbs[3] = (int) ($this->limbs[1] & 0xffff);
842
+        $return->limbs[ 2 ] = (int)( $this->limbs[ 0 ] & 0xffff );
843
+        $return->limbs[ 3 ] = (int)( $this->limbs[ 1 ] & 0xffff );
844 844
         return $return;
845 845
     }
846 846
 
@@ -850,10 +850,10 @@  discard block
 block discarded – undo
850 850
      */
851 851
     public function toReverseString()
852 852
     {
853
-        return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
854
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
855
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
856
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
853
+        return ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 1 ] & 0xff ) .
854
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 1 ] >> 8 ) & 0xff ) .
855
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 0 ] & 0xff ) .
856
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 0 ] >> 8 ) & 0xff );
857 857
     }
858 858
 
859 859
     /**
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
     {
864 864
         try {
865 865
             return $this->toString();
866
-        } catch (TypeError $ex) {
866
+        } catch ( TypeError $ex ) {
867 867
             // PHP engine can't handle exceptions from __toString()
868 868
             return '';
869 869
         }
Please login to merge, or discard this patch.
Braces   +32 added lines, -64 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  * These are immutable. It always returns a new instance.
9 9
  */
10
-class ParagonIE_Sodium_Core32_Int32
11
-{
10
+class ParagonIE_Sodium_Core32_Int32 {
12 11
     /**
13 12
      * @var array<int, int> - two 16-bit integers
14 13
      *
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
      * @param array $array
33 32
      * @param bool $unsignedInt
34 33
      */
35
-    public function __construct($array = array(0, 0), $unsignedInt = false)
36
-    {
34
+    public function __construct($array = array(0, 0), $unsignedInt = false) {
37 35
         $this->limbs = array(
38 36
             (int) $array[0],
39 37
             (int) $array[1]
@@ -48,8 +46,7 @@  discard block
 block discarded – undo
48 46
      * @param ParagonIE_Sodium_Core32_Int32 $addend
49 47
      * @return ParagonIE_Sodium_Core32_Int32
50 48
      */
51
-    public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend)
52
-    {
49
+    public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend) {
53 50
         $i0 = $this->limbs[0];
54 51
         $i1 = $this->limbs[1];
55 52
         $j0 = $addend->limbs[0];
@@ -80,8 +77,7 @@  discard block
 block discarded – undo
80 77
      * @throws SodiumException
81 78
      * @throws TypeError
82 79
      */
83
-    public function addInt($int)
84
-    {
80
+    public function addInt($int) {
85 81
         ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
86 82
         /** @var int $int */
87 83
         $int = (int) $int;
@@ -110,8 +106,7 @@  discard block
 block discarded – undo
110 106
      * @param int $b
111 107
      * @return int
112 108
      */
113
-    public function compareInt($b = 0)
114
-    {
109
+    public function compareInt($b = 0) {
115 110
         $gt = 0;
116 111
         $eq = 1;
117 112
 
@@ -135,8 +130,7 @@  discard block
 block discarded – undo
135 130
      * @param int $m
136 131
      * @return ParagonIE_Sodium_Core32_Int32
137 132
      */
138
-    public function mask($m = 0)
139
-    {
133
+    public function mask($m = 0) {
140 134
         /** @var int $hi */
141 135
         $hi = ($m >> 16) & 0xffff;
142 136
         /** @var int $lo */
@@ -156,8 +150,7 @@  discard block
 block discarded – undo
156 150
      * @param int $baseLog2
157 151
      * @return array<int, int>
158 152
      */
159
-    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
160
-    {
153
+    public function multiplyLong(array $a, array $b, $baseLog2 = 16) {
161 154
         $a_l = count($a);
162 155
         $b_l = count($b);
163 156
         /** @var array<int, int> $r */
@@ -180,8 +173,7 @@  discard block
 block discarded – undo
180 173
      * @param int $int
181 174
      * @return ParagonIE_Sodium_Core32_Int32
182 175
      */
183
-    public function mulIntFast($int)
184
-    {
176
+    public function mulIntFast($int) {
185 177
         // Handle negative numbers
186 178
         $aNeg = ($this->limbs[0] >> 15) & 1;
187 179
         $bNeg = ($int >> 31) & 1;
@@ -236,8 +228,7 @@  discard block
 block discarded – undo
236 228
      * @param ParagonIE_Sodium_Core32_Int32 $right
237 229
      * @return ParagonIE_Sodium_Core32_Int32
238 230
      */
239
-    public function mulInt32Fast(ParagonIE_Sodium_Core32_Int32 $right)
240
-    {
231
+    public function mulInt32Fast(ParagonIE_Sodium_Core32_Int32 $right) {
241 232
         $aNeg = ($this->limbs[0] >> 15) & 1;
242 233
         $bNeg = ($right->limbs[0] >> 15) & 1;
243 234
 
@@ -287,8 +278,7 @@  discard block
 block discarded – undo
287 278
      * @throws SodiumException
288 279
      * @throws TypeError
289 280
      */
290
-    public function mulInt($int = 0, $size = 0)
291
-    {
281
+    public function mulInt($int = 0, $size = 0) {
292 282
         ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
293 283
         ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
294 284
         if (ParagonIE_Sodium_Compat::$fastMult) {
@@ -348,8 +338,7 @@  discard block
 block discarded – undo
348 338
      * @throws SodiumException
349 339
      * @throws TypeError
350 340
      */
351
-    public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0)
352
-    {
341
+    public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0) {
353 342
         ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
354 343
         if (ParagonIE_Sodium_Compat::$fastMult) {
355 344
             return $this->mulInt32Fast($int);
@@ -413,8 +402,7 @@  discard block
 block discarded – undo
413 402
      * @param ParagonIE_Sodium_Core32_Int32 $b
414 403
      * @return ParagonIE_Sodium_Core32_Int32
415 404
      */
416
-    public function orInt32(ParagonIE_Sodium_Core32_Int32 $b)
417
-    {
405
+    public function orInt32(ParagonIE_Sodium_Core32_Int32 $b) {
418 406
         $return = new ParagonIE_Sodium_Core32_Int32();
419 407
         $return->unsignedInt = $this->unsignedInt;
420 408
         $return->limbs = array(
@@ -430,8 +418,7 @@  discard block
 block discarded – undo
430 418
      * @param int $b
431 419
      * @return bool
432 420
      */
433
-    public function isGreaterThan($b = 0)
434
-    {
421
+    public function isGreaterThan($b = 0) {
435 422
         return $this->compareInt($b) > 0;
436 423
     }
437 424
 
@@ -439,8 +426,7 @@  discard block
 block discarded – undo
439 426
      * @param int $b
440 427
      * @return bool
441 428
      */
442
-    public function isLessThanInt($b = 0)
443
-    {
429
+    public function isLessThanInt($b = 0) {
444 430
         return $this->compareInt($b) < 0;
445 431
     }
446 432
 
@@ -451,8 +437,7 @@  discard block
 block discarded – undo
451 437
      * @throws TypeError
452 438
      * @psalm-suppress MixedArrayAccess
453 439
      */
454
-    public function rotateLeft($c = 0)
455
-    {
440
+    public function rotateLeft($c = 0) {
456 441
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
457 442
         /** @var int $c */
458 443
         $c = (int) $c;
@@ -504,8 +489,7 @@  discard block
 block discarded – undo
504 489
      * @throws TypeError
505 490
      * @psalm-suppress MixedArrayAccess
506 491
      */
507
-    public function rotateRight($c = 0)
508
-    {
492
+    public function rotateRight($c = 0) {
509 493
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
510 494
         /** @var int $c */
511 495
         $c = (int) $c;
@@ -553,8 +537,7 @@  discard block
 block discarded – undo
553 537
      * @param bool $bool
554 538
      * @return self
555 539
      */
556
-    public function setUnsignedInt($bool = false)
557
-    {
540
+    public function setUnsignedInt($bool = false) {
558 541
         $this->unsignedInt = !empty($bool);
559 542
         return $this;
560 543
     }
@@ -565,8 +548,7 @@  discard block
 block discarded – undo
565 548
      * @throws SodiumException
566 549
      * @throws TypeError
567 550
      */
568
-    public function shiftLeft($c = 0)
569
-    {
551
+    public function shiftLeft($c = 0) {
570 552
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
571 553
         /** @var int $c */
572 554
         $c = (int) $c;
@@ -603,8 +585,7 @@  discard block
 block discarded – undo
603 585
      * @psalm-suppress MixedAssignment
604 586
      * @psalm-suppress MixedOperand
605 587
      */
606
-    public function shiftRight($c = 0)
607
-    {
588
+    public function shiftRight($c = 0) {
608 589
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
609 590
         /** @var int $c */
610 591
         $c = (int) $c;
@@ -649,8 +630,7 @@  discard block
 block discarded – undo
649 630
      * @throws SodiumException
650 631
      * @throws TypeError
651 632
      */
652
-    public function subInt($int)
653
-    {
633
+    public function subInt($int) {
654 634
         ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
655 635
         /** @var int $int */
656 636
         $int = (int) $int;
@@ -676,8 +656,7 @@  discard block
 block discarded – undo
676 656
      * @param ParagonIE_Sodium_Core32_Int32 $b
677 657
      * @return ParagonIE_Sodium_Core32_Int32
678 658
      */
679
-    public function subInt32(ParagonIE_Sodium_Core32_Int32 $b)
680
-    {
659
+    public function subInt32(ParagonIE_Sodium_Core32_Int32 $b) {
681 660
         $return = new ParagonIE_Sodium_Core32_Int32();
682 661
         $return->unsignedInt = $this->unsignedInt;
683 662
 
@@ -699,8 +678,7 @@  discard block
 block discarded – undo
699 678
      * @param ParagonIE_Sodium_Core32_Int32 $b
700 679
      * @return ParagonIE_Sodium_Core32_Int32
701 680
      */
702
-    public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b)
703
-    {
681
+    public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b) {
704 682
         $return = new ParagonIE_Sodium_Core32_Int32();
705 683
         $return->unsignedInt = $this->unsignedInt;
706 684
         $return->limbs = array(
@@ -716,8 +694,7 @@  discard block
 block discarded – undo
716 694
      * @throws SodiumException
717 695
      * @throws TypeError
718 696
      */
719
-    public static function fromInt($signed)
720
-    {
697
+    public static function fromInt($signed) {
721 698
         ParagonIE_Sodium_Core32_Util::declareScalarType($signed, 'int', 1);;
722 699
         /** @var int $signed */
723 700
         $signed = (int) $signed;
@@ -736,8 +713,7 @@  discard block
 block discarded – undo
736 713
      * @throws SodiumException
737 714
      * @throws TypeError
738 715
      */
739
-    public static function fromString($string)
740
-    {
716
+    public static function fromString($string) {
741 717
         ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
742 718
         $string = (string) $string;
743 719
         if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
@@ -760,8 +736,7 @@  discard block
 block discarded – undo
760 736
      * @throws SodiumException
761 737
      * @throws TypeError
762 738
      */
763
-    public static function fromReverseString($string)
764
-    {
739
+    public static function fromReverseString($string) {
765 740
         ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
766 741
         $string = (string) $string;
767 742
         if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 4) {
@@ -781,8 +756,7 @@  discard block
 block discarded – undo
781 756
     /**
782 757
      * @return array<int, int>
783 758
      */
784
-    public function toArray()
785
-    {
759
+    public function toArray() {
786 760
         return array((int) ($this->limbs[0] << 16 | $this->limbs[1]));
787 761
     }
788 762
 
@@ -790,8 +764,7 @@  discard block
 block discarded – undo
790 764
      * @return string
791 765
      * @throws TypeError
792 766
      */
793
-    public function toString()
794
-    {
767
+    public function toString() {
795 768
         return
796 769
             ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
797 770
             ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
@@ -802,8 +775,7 @@  discard block
 block discarded – undo
802 775
     /**
803 776
      * @return int
804 777
      */
805
-    public function toInt()
806
-    {
778
+    public function toInt() {
807 779
         return (int) (
808 780
             (($this->limbs[0] & 0xffff) << 16)
809 781
                 |
@@ -814,8 +786,7 @@  discard block
 block discarded – undo
814 786
     /**
815 787
      * @return ParagonIE_Sodium_Core32_Int32
816 788
      */
817
-    public function toInt32()
818
-    {
789
+    public function toInt32() {
819 790
         $return = new ParagonIE_Sodium_Core32_Int32();
820 791
         $return->limbs[0] = (int) ($this->limbs[0] & 0xffff);
821 792
         $return->limbs[1] = (int) ($this->limbs[1] & 0xffff);
@@ -827,8 +798,7 @@  discard block
 block discarded – undo
827 798
     /**
828 799
      * @return ParagonIE_Sodium_Core32_Int64
829 800
      */
830
-    public function toInt64()
831
-    {
801
+    public function toInt64() {
832 802
         $return = new ParagonIE_Sodium_Core32_Int64();
833 803
         $return->unsignedInt = $this->unsignedInt;
834 804
         if ($this->unsignedInt) {
@@ -848,8 +818,7 @@  discard block
 block discarded – undo
848 818
      * @return string
849 819
      * @throws TypeError
850 820
      */
851
-    public function toReverseString()
852
-    {
821
+    public function toReverseString() {
853 822
         return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
854 823
             ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
855 824
             ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
@@ -859,8 +828,7 @@  discard block
 block discarded – undo
859 828
     /**
860 829
      * @return string
861 830
      */
862
-    public function __toString()
863
-    {
831
+    public function __toString() {
864 832
         try {
865 833
             return $this->toString();
866 834
         } catch (TypeError $ex) {
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/Poly1305.php 3 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (class_exists('ParagonIE_Sodium_Core32_Poly1305', false)) {
4
-    return;
4
+	return;
5 5
 }
6 6
 
7 7
 /**
@@ -9,55 +9,55 @@  discard block
 block discarded – undo
9 9
  */
10 10
 abstract class ParagonIE_Sodium_Core32_Poly1305 extends ParagonIE_Sodium_Core32_Util
11 11
 {
12
-    const BLOCK_SIZE = 16;
12
+	const BLOCK_SIZE = 16;
13 13
 
14
-    /**
15
-     * @internal You should not use this directly from another application
16
-     *
17
-     * @param string $m
18
-     * @param string $key
19
-     * @return string
20
-     * @throws SodiumException
21
-     * @throws TypeError
22
-     */
23
-    public static function onetimeauth($m, $key)
24
-    {
25
-        if (self::strlen($key) < 32) {
26
-            throw new InvalidArgumentException(
27
-                'Key must be 32 bytes long.'
28
-            );
29
-        }
30
-        $state = new ParagonIE_Sodium_Core32_Poly1305_State(
31
-            self::substr($key, 0, 32)
32
-        );
33
-        return $state
34
-            ->update($m)
35
-            ->finish();
36
-    }
14
+	/**
15
+	 * @internal You should not use this directly from another application
16
+	 *
17
+	 * @param string $m
18
+	 * @param string $key
19
+	 * @return string
20
+	 * @throws SodiumException
21
+	 * @throws TypeError
22
+	 */
23
+	public static function onetimeauth($m, $key)
24
+	{
25
+		if (self::strlen($key) < 32) {
26
+			throw new InvalidArgumentException(
27
+				'Key must be 32 bytes long.'
28
+			);
29
+		}
30
+		$state = new ParagonIE_Sodium_Core32_Poly1305_State(
31
+			self::substr($key, 0, 32)
32
+		);
33
+		return $state
34
+			->update($m)
35
+			->finish();
36
+	}
37 37
 
38
-    /**
39
-     * @internal You should not use this directly from another application
40
-     *
41
-     * @param string $mac
42
-     * @param string $m
43
-     * @param string $key
44
-     * @return bool
45
-     * @throws SodiumException
46
-     * @throws TypeError
47
-     */
48
-    public static function onetimeauth_verify($mac, $m, $key)
49
-    {
50
-        if (self::strlen($key) < 32) {
51
-            throw new InvalidArgumentException(
52
-                'Key must be 32 bytes long.'
53
-            );
54
-        }
55
-        $state = new ParagonIE_Sodium_Core32_Poly1305_State(
56
-            self::substr($key, 0, 32)
57
-        );
58
-        $calc = $state
59
-            ->update($m)
60
-            ->finish();
61
-        return self::verify_16($calc, $mac);
62
-    }
38
+	/**
39
+	 * @internal You should not use this directly from another application
40
+	 *
41
+	 * @param string $mac
42
+	 * @param string $m
43
+	 * @param string $key
44
+	 * @return bool
45
+	 * @throws SodiumException
46
+	 * @throws TypeError
47
+	 */
48
+	public static function onetimeauth_verify($mac, $m, $key)
49
+	{
50
+		if (self::strlen($key) < 32) {
51
+			throw new InvalidArgumentException(
52
+				'Key must be 32 bytes long.'
53
+			);
54
+		}
55
+		$state = new ParagonIE_Sodium_Core32_Poly1305_State(
56
+			self::substr($key, 0, 32)
57
+		);
58
+		$calc = $state
59
+			->update($m)
60
+			->finish();
61
+		return self::verify_16($calc, $mac);
62
+	}
63 63
 }
Please login to merge, or discard this 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
 
@@ -20,18 +20,18 @@  discard block
 block discarded – undo
20 20
      * @throws SodiumException
21 21
      * @throws TypeError
22 22
      */
23
-    public static function onetimeauth($m, $key)
23
+    public static function onetimeauth( $m, $key )
24 24
     {
25
-        if (self::strlen($key) < 32) {
25
+        if ( self::strlen( $key ) < 32 ) {
26 26
             throw new InvalidArgumentException(
27 27
                 'Key must be 32 bytes long.'
28 28
             );
29 29
         }
30 30
         $state = new ParagonIE_Sodium_Core32_Poly1305_State(
31
-            self::substr($key, 0, 32)
31
+            self::substr( $key, 0, 32 )
32 32
         );
33 33
         return $state
34
-            ->update($m)
34
+            ->update( $m )
35 35
             ->finish();
36 36
     }
37 37
 
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
      * @throws SodiumException
46 46
      * @throws TypeError
47 47
      */
48
-    public static function onetimeauth_verify($mac, $m, $key)
48
+    public static function onetimeauth_verify( $mac, $m, $key )
49 49
     {
50
-        if (self::strlen($key) < 32) {
50
+        if ( self::strlen( $key ) < 32 ) {
51 51
             throw new InvalidArgumentException(
52 52
                 'Key must be 32 bytes long.'
53 53
             );
54 54
         }
55 55
         $state = new ParagonIE_Sodium_Core32_Poly1305_State(
56
-            self::substr($key, 0, 32)
56
+            self::substr( $key, 0, 32 )
57 57
         );
58 58
         $calc = $state
59
-            ->update($m)
59
+            ->update( $m )
60 60
             ->finish();
61
-        return self::verify_16($calc, $mac);
61
+        return self::verify_16( $calc, $mac );
62 62
     }
63 63
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 /**
8 8
  * Class ParagonIE_Sodium_Core32_Poly1305
9 9
  */
10
-abstract class ParagonIE_Sodium_Core32_Poly1305 extends ParagonIE_Sodium_Core32_Util
11
-{
10
+abstract class ParagonIE_Sodium_Core32_Poly1305 extends ParagonIE_Sodium_Core32_Util {
12 11
     const BLOCK_SIZE = 16;
13 12
 
14 13
     /**
@@ -20,8 +19,7 @@  discard block
 block discarded – undo
20 19
      * @throws SodiumException
21 20
      * @throws TypeError
22 21
      */
23
-    public static function onetimeauth($m, $key)
24
-    {
22
+    public static function onetimeauth($m, $key) {
25 23
         if (self::strlen($key) < 32) {
26 24
             throw new InvalidArgumentException(
27 25
                 'Key must be 32 bytes long.'
@@ -45,8 +43,7 @@  discard block
 block discarded – undo
45 43
      * @throws SodiumException
46 44
      * @throws TypeError
47 45
      */
48
-    public static function onetimeauth_verify($mac, $m, $key)
49
-    {
46
+    public static function onetimeauth_verify($mac, $m, $key) {
50 47
         if (self::strlen($key) < 32) {
51 48
             throw new InvalidArgumentException(
52 49
                 'Key must be 32 bytes long.'
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/XSalsa20.php 3 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (class_exists('ParagonIE_Sodium_Core32_XSalsa20', false)) {
4
-    return;
4
+	return;
5 5
 }
6 6
 
7 7
 /**
@@ -9,49 +9,49 @@  discard block
 block discarded – undo
9 9
  */
10 10
 abstract class ParagonIE_Sodium_Core32_XSalsa20 extends ParagonIE_Sodium_Core32_HSalsa20
11 11
 {
12
-    /**
13
-     * Expand a key and nonce into an xsalsa20 keystream.
14
-     *
15
-     * @internal You should not use this directly from another application
16
-     *
17
-     * @param int $len
18
-     * @param string $nonce
19
-     * @param string $key
20
-     * @return string
21
-     * @throws SodiumException
22
-     * @throws TypeError
23
-     */
24
-    public static function xsalsa20($len, $nonce, $key)
25
-    {
26
-        $ret = self::salsa20(
27
-            $len,
28
-            self::substr($nonce, 16, 8),
29
-            self::hsalsa20($nonce, $key)
30
-        );
31
-        return $ret;
32
-    }
12
+	/**
13
+	 * Expand a key and nonce into an xsalsa20 keystream.
14
+	 *
15
+	 * @internal You should not use this directly from another application
16
+	 *
17
+	 * @param int $len
18
+	 * @param string $nonce
19
+	 * @param string $key
20
+	 * @return string
21
+	 * @throws SodiumException
22
+	 * @throws TypeError
23
+	 */
24
+	public static function xsalsa20($len, $nonce, $key)
25
+	{
26
+		$ret = self::salsa20(
27
+			$len,
28
+			self::substr($nonce, 16, 8),
29
+			self::hsalsa20($nonce, $key)
30
+		);
31
+		return $ret;
32
+	}
33 33
 
34
-    /**
35
-     * Encrypt a string with XSalsa20. Doesn't provide integrity.
36
-     *
37
-     * @internal You should not use this directly from another application
38
-     *
39
-     * @param string $message
40
-     * @param string $nonce
41
-     * @param string $key
42
-     * @return string
43
-     * @throws SodiumException
44
-     * @throws TypeError
45
-     */
46
-    public static function xsalsa20_xor($message, $nonce, $key)
47
-    {
48
-        return self::xorStrings(
49
-            $message,
50
-            self::xsalsa20(
51
-                self::strlen($message),
52
-                $nonce,
53
-                $key
54
-            )
55
-        );
56
-    }
34
+	/**
35
+	 * Encrypt a string with XSalsa20. Doesn't provide integrity.
36
+	 *
37
+	 * @internal You should not use this directly from another application
38
+	 *
39
+	 * @param string $message
40
+	 * @param string $nonce
41
+	 * @param string $key
42
+	 * @return string
43
+	 * @throws SodiumException
44
+	 * @throws TypeError
45
+	 */
46
+	public static function xsalsa20_xor($message, $nonce, $key)
47
+	{
48
+		return self::xorStrings(
49
+			$message,
50
+			self::xsalsa20(
51
+				self::strlen($message),
52
+				$nonce,
53
+				$key
54
+			)
55
+		);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 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_XSalsa20', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_XSalsa20', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
      * @throws SodiumException
22 22
      * @throws TypeError
23 23
      */
24
-    public static function xsalsa20($len, $nonce, $key)
24
+    public static function xsalsa20( $len, $nonce, $key )
25 25
     {
26 26
         $ret = self::salsa20(
27 27
             $len,
28
-            self::substr($nonce, 16, 8),
29
-            self::hsalsa20($nonce, $key)
28
+            self::substr( $nonce, 16, 8 ),
29
+            self::hsalsa20( $nonce, $key )
30 30
         );
31 31
         return $ret;
32 32
     }
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
      * @throws SodiumException
44 44
      * @throws TypeError
45 45
      */
46
-    public static function xsalsa20_xor($message, $nonce, $key)
46
+    public static function xsalsa20_xor( $message, $nonce, $key )
47 47
     {
48 48
         return self::xorStrings(
49 49
             $message,
50 50
             self::xsalsa20(
51
-                self::strlen($message),
51
+                self::strlen( $message ),
52 52
                 $nonce,
53 53
                 $key
54 54
             )
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 /**
8 8
  * Class ParagonIE_Sodium_Core32_XSalsa20
9 9
  */
10
-abstract class ParagonIE_Sodium_Core32_XSalsa20 extends ParagonIE_Sodium_Core32_HSalsa20
11
-{
10
+abstract class ParagonIE_Sodium_Core32_XSalsa20 extends ParagonIE_Sodium_Core32_HSalsa20 {
12 11
     /**
13 12
      * Expand a key and nonce into an xsalsa20 keystream.
14 13
      *
@@ -21,8 +20,7 @@  discard block
 block discarded – undo
21 20
      * @throws SodiumException
22 21
      * @throws TypeError
23 22
      */
24
-    public static function xsalsa20($len, $nonce, $key)
25
-    {
23
+    public static function xsalsa20($len, $nonce, $key) {
26 24
         $ret = self::salsa20(
27 25
             $len,
28 26
             self::substr($nonce, 16, 8),
@@ -43,8 +41,7 @@  discard block
 block discarded – undo
43 41
      * @throws SodiumException
44 42
      * @throws TypeError
45 43
      */
46
-    public static function xsalsa20_xor($message, $nonce, $key)
47
-    {
44
+    public static function xsalsa20_xor($message, $nonce, $key) {
48 45
         return self::xorStrings(
49 46
             $message,
50 47
             self::xsalsa20(
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/ChaCha20.php 3 patches
Indentation   +287 added lines, -287 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (class_exists('ParagonIE_Sodium_Core32_ChaCha20', false)) {
4
-    return;
4
+	return;
5 5
 }
6 6
 
7 7
 /**
@@ -9,83 +9,83 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class ParagonIE_Sodium_Core32_ChaCha20 extends ParagonIE_Sodium_Core32_Util
11 11
 {
12
-    /**
13
-     * The ChaCha20 quarter round function. Works on four 32-bit integers.
14
-     *
15
-     * @internal You should not use this directly from another application
16
-     *
17
-     * @param ParagonIE_Sodium_Core32_Int32 $a
18
-     * @param ParagonIE_Sodium_Core32_Int32 $b
19
-     * @param ParagonIE_Sodium_Core32_Int32 $c
20
-     * @param ParagonIE_Sodium_Core32_Int32 $d
21
-     * @return array<int, ParagonIE_Sodium_Core32_Int32>
22
-     * @throws SodiumException
23
-     * @throws TypeError
24
-     */
25
-    protected static function quarterRound(
26
-        ParagonIE_Sodium_Core32_Int32 $a,
27
-        ParagonIE_Sodium_Core32_Int32 $b,
28
-        ParagonIE_Sodium_Core32_Int32 $c,
29
-        ParagonIE_Sodium_Core32_Int32 $d
30
-    ) {
31
-        /** @var ParagonIE_Sodium_Core32_Int32 $a */
32
-        /** @var ParagonIE_Sodium_Core32_Int32 $b */
33
-        /** @var ParagonIE_Sodium_Core32_Int32 $c */
34
-        /** @var ParagonIE_Sodium_Core32_Int32 $d */
12
+	/**
13
+	 * The ChaCha20 quarter round function. Works on four 32-bit integers.
14
+	 *
15
+	 * @internal You should not use this directly from another application
16
+	 *
17
+	 * @param ParagonIE_Sodium_Core32_Int32 $a
18
+	 * @param ParagonIE_Sodium_Core32_Int32 $b
19
+	 * @param ParagonIE_Sodium_Core32_Int32 $c
20
+	 * @param ParagonIE_Sodium_Core32_Int32 $d
21
+	 * @return array<int, ParagonIE_Sodium_Core32_Int32>
22
+	 * @throws SodiumException
23
+	 * @throws TypeError
24
+	 */
25
+	protected static function quarterRound(
26
+		ParagonIE_Sodium_Core32_Int32 $a,
27
+		ParagonIE_Sodium_Core32_Int32 $b,
28
+		ParagonIE_Sodium_Core32_Int32 $c,
29
+		ParagonIE_Sodium_Core32_Int32 $d
30
+	) {
31
+		/** @var ParagonIE_Sodium_Core32_Int32 $a */
32
+		/** @var ParagonIE_Sodium_Core32_Int32 $b */
33
+		/** @var ParagonIE_Sodium_Core32_Int32 $c */
34
+		/** @var ParagonIE_Sodium_Core32_Int32 $d */
35 35
 
36
-        # a = PLUS(a,b); d = ROTATE(XOR(d,a),16);
37
-        $a = $a->addInt32($b);
38
-        $d = $d->xorInt32($a)->rotateLeft(16);
36
+		# a = PLUS(a,b); d = ROTATE(XOR(d,a),16);
37
+		$a = $a->addInt32($b);
38
+		$d = $d->xorInt32($a)->rotateLeft(16);
39 39
 
40
-        # c = PLUS(c,d); b = ROTATE(XOR(b,c),12);
41
-        $c = $c->addInt32($d);
42
-        $b = $b->xorInt32($c)->rotateLeft(12);
40
+		# c = PLUS(c,d); b = ROTATE(XOR(b,c),12);
41
+		$c = $c->addInt32($d);
42
+		$b = $b->xorInt32($c)->rotateLeft(12);
43 43
 
44
-        # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8);
45
-        $a = $a->addInt32($b);
46
-        $d = $d->xorInt32($a)->rotateLeft(8);
44
+		# a = PLUS(a,b); d = ROTATE(XOR(d,a), 8);
45
+		$a = $a->addInt32($b);
46
+		$d = $d->xorInt32($a)->rotateLeft(8);
47 47
 
48
-        # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
49
-        $c = $c->addInt32($d);
50
-        $b = $b->xorInt32($c)->rotateLeft(7);
48
+		# c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
49
+		$c = $c->addInt32($d);
50
+		$b = $b->xorInt32($c)->rotateLeft(7);
51 51
 
52
-        return array($a, $b, $c, $d);
53
-    }
52
+		return array($a, $b, $c, $d);
53
+	}
54 54
 
55
-    /**
56
-     * @internal You should not use this directly from another application
57
-     *
58
-     * @param ParagonIE_Sodium_Core32_ChaCha20_Ctx $ctx
59
-     * @param string $message
60
-     *
61
-     * @return string
62
-     * @throws SodiumException
63
-     * @throws TypeError
64
-     */
65
-    public static function encryptBytes(
66
-        ParagonIE_Sodium_Core32_ChaCha20_Ctx $ctx,
67
-        $message = ''
68
-    ) {
69
-        $bytes = self::strlen($message);
55
+	/**
56
+	 * @internal You should not use this directly from another application
57
+	 *
58
+	 * @param ParagonIE_Sodium_Core32_ChaCha20_Ctx $ctx
59
+	 * @param string $message
60
+	 *
61
+	 * @return string
62
+	 * @throws SodiumException
63
+	 * @throws TypeError
64
+	 */
65
+	public static function encryptBytes(
66
+		ParagonIE_Sodium_Core32_ChaCha20_Ctx $ctx,
67
+		$message = ''
68
+	) {
69
+		$bytes = self::strlen($message);
70 70
 
71
-        /** @var ParagonIE_Sodium_Core32_Int32 $x0 */
72
-        /** @var ParagonIE_Sodium_Core32_Int32 $x1 */
73
-        /** @var ParagonIE_Sodium_Core32_Int32 $x2 */
74
-        /** @var ParagonIE_Sodium_Core32_Int32 $x3 */
75
-        /** @var ParagonIE_Sodium_Core32_Int32 $x4 */
76
-        /** @var ParagonIE_Sodium_Core32_Int32 $x5 */
77
-        /** @var ParagonIE_Sodium_Core32_Int32 $x6 */
78
-        /** @var ParagonIE_Sodium_Core32_Int32 $x7 */
79
-        /** @var ParagonIE_Sodium_Core32_Int32 $x8 */
80
-        /** @var ParagonIE_Sodium_Core32_Int32 $x9 */
81
-        /** @var ParagonIE_Sodium_Core32_Int32 $x10 */
82
-        /** @var ParagonIE_Sodium_Core32_Int32 $x11 */
83
-        /** @var ParagonIE_Sodium_Core32_Int32 $x12 */
84
-        /** @var ParagonIE_Sodium_Core32_Int32 $x13 */
85
-        /** @var ParagonIE_Sodium_Core32_Int32 $x14 */
86
-        /** @var ParagonIE_Sodium_Core32_Int32 $x15 */
71
+		/** @var ParagonIE_Sodium_Core32_Int32 $x0 */
72
+		/** @var ParagonIE_Sodium_Core32_Int32 $x1 */
73
+		/** @var ParagonIE_Sodium_Core32_Int32 $x2 */
74
+		/** @var ParagonIE_Sodium_Core32_Int32 $x3 */
75
+		/** @var ParagonIE_Sodium_Core32_Int32 $x4 */
76
+		/** @var ParagonIE_Sodium_Core32_Int32 $x5 */
77
+		/** @var ParagonIE_Sodium_Core32_Int32 $x6 */
78
+		/** @var ParagonIE_Sodium_Core32_Int32 $x7 */
79
+		/** @var ParagonIE_Sodium_Core32_Int32 $x8 */
80
+		/** @var ParagonIE_Sodium_Core32_Int32 $x9 */
81
+		/** @var ParagonIE_Sodium_Core32_Int32 $x10 */
82
+		/** @var ParagonIE_Sodium_Core32_Int32 $x11 */
83
+		/** @var ParagonIE_Sodium_Core32_Int32 $x12 */
84
+		/** @var ParagonIE_Sodium_Core32_Int32 $x13 */
85
+		/** @var ParagonIE_Sodium_Core32_Int32 $x14 */
86
+		/** @var ParagonIE_Sodium_Core32_Int32 $x15 */
87 87
 
88
-        /*
88
+		/*
89 89
         j0 = ctx->input[0];
90 90
         j1 = ctx->input[1];
91 91
         j2 = ctx->input[2];
@@ -103,89 +103,89 @@  discard block
 block discarded – undo
103 103
         j14 = ctx->input[14];
104 104
         j15 = ctx->input[15];
105 105
         */
106
-        /** @var ParagonIE_Sodium_Core32_Int32 $j0 */
107
-        $j0  = $ctx[0];
108
-        /** @var ParagonIE_Sodium_Core32_Int32 $j1 */
109
-        $j1  = $ctx[1];
110
-        /** @var ParagonIE_Sodium_Core32_Int32 $j2 */
111
-        $j2  = $ctx[2];
112
-        /** @var ParagonIE_Sodium_Core32_Int32 $j3 */
113
-        $j3  = $ctx[3];
114
-        /** @var ParagonIE_Sodium_Core32_Int32 $j4 */
115
-        $j4  = $ctx[4];
116
-        /** @var ParagonIE_Sodium_Core32_Int32 $j5 */
117
-        $j5  = $ctx[5];
118
-        /** @var ParagonIE_Sodium_Core32_Int32 $j6 */
119
-        $j6  = $ctx[6];
120
-        /** @var ParagonIE_Sodium_Core32_Int32 $j7 */
121
-        $j7  = $ctx[7];
122
-        /** @var ParagonIE_Sodium_Core32_Int32 $j8 */
123
-        $j8  = $ctx[8];
124
-        /** @var ParagonIE_Sodium_Core32_Int32 $j9 */
125
-        $j9  = $ctx[9];
126
-        /** @var ParagonIE_Sodium_Core32_Int32 $j10 */
127
-        $j10 = $ctx[10];
128
-        /** @var ParagonIE_Sodium_Core32_Int32 $j11 */
129
-        $j11 = $ctx[11];
130
-        /** @var ParagonIE_Sodium_Core32_Int32 $j12 */
131
-        $j12 = $ctx[12];
132
-        /** @var ParagonIE_Sodium_Core32_Int32 $j13 */
133
-        $j13 = $ctx[13];
134
-        /** @var ParagonIE_Sodium_Core32_Int32 $j14 */
135
-        $j14 = $ctx[14];
136
-        /** @var ParagonIE_Sodium_Core32_Int32 $j15 */
137
-        $j15 = $ctx[15];
106
+		/** @var ParagonIE_Sodium_Core32_Int32 $j0 */
107
+		$j0  = $ctx[0];
108
+		/** @var ParagonIE_Sodium_Core32_Int32 $j1 */
109
+		$j1  = $ctx[1];
110
+		/** @var ParagonIE_Sodium_Core32_Int32 $j2 */
111
+		$j2  = $ctx[2];
112
+		/** @var ParagonIE_Sodium_Core32_Int32 $j3 */
113
+		$j3  = $ctx[3];
114
+		/** @var ParagonIE_Sodium_Core32_Int32 $j4 */
115
+		$j4  = $ctx[4];
116
+		/** @var ParagonIE_Sodium_Core32_Int32 $j5 */
117
+		$j5  = $ctx[5];
118
+		/** @var ParagonIE_Sodium_Core32_Int32 $j6 */
119
+		$j6  = $ctx[6];
120
+		/** @var ParagonIE_Sodium_Core32_Int32 $j7 */
121
+		$j7  = $ctx[7];
122
+		/** @var ParagonIE_Sodium_Core32_Int32 $j8 */
123
+		$j8  = $ctx[8];
124
+		/** @var ParagonIE_Sodium_Core32_Int32 $j9 */
125
+		$j9  = $ctx[9];
126
+		/** @var ParagonIE_Sodium_Core32_Int32 $j10 */
127
+		$j10 = $ctx[10];
128
+		/** @var ParagonIE_Sodium_Core32_Int32 $j11 */
129
+		$j11 = $ctx[11];
130
+		/** @var ParagonIE_Sodium_Core32_Int32 $j12 */
131
+		$j12 = $ctx[12];
132
+		/** @var ParagonIE_Sodium_Core32_Int32 $j13 */
133
+		$j13 = $ctx[13];
134
+		/** @var ParagonIE_Sodium_Core32_Int32 $j14 */
135
+		$j14 = $ctx[14];
136
+		/** @var ParagonIE_Sodium_Core32_Int32 $j15 */
137
+		$j15 = $ctx[15];
138 138
 
139
-        $c = '';
140
-        for (;;) {
141
-            if ($bytes < 64) {
142
-                $message .= str_repeat("\x00", 64 - $bytes);
143
-            }
139
+		$c = '';
140
+		for (;;) {
141
+			if ($bytes < 64) {
142
+				$message .= str_repeat("\x00", 64 - $bytes);
143
+			}
144 144
 
145
-            $x0 =  clone $j0;
146
-            $x1 =  clone $j1;
147
-            $x2 =  clone $j2;
148
-            $x3 =  clone $j3;
149
-            $x4 =  clone $j4;
150
-            $x5 =  clone $j5;
151
-            $x6 =  clone $j6;
152
-            $x7 =  clone $j7;
153
-            $x8 =  clone $j8;
154
-            $x9 =  clone $j9;
155
-            $x10 = clone $j10;
156
-            $x11 = clone $j11;
157
-            $x12 = clone $j12;
158
-            $x13 = clone $j13;
159
-            $x14 = clone $j14;
160
-            $x15 = clone $j15;
145
+			$x0 =  clone $j0;
146
+			$x1 =  clone $j1;
147
+			$x2 =  clone $j2;
148
+			$x3 =  clone $j3;
149
+			$x4 =  clone $j4;
150
+			$x5 =  clone $j5;
151
+			$x6 =  clone $j6;
152
+			$x7 =  clone $j7;
153
+			$x8 =  clone $j8;
154
+			$x9 =  clone $j9;
155
+			$x10 = clone $j10;
156
+			$x11 = clone $j11;
157
+			$x12 = clone $j12;
158
+			$x13 = clone $j13;
159
+			$x14 = clone $j14;
160
+			$x15 = clone $j15;
161 161
 
162
-            # for (i = 20; i > 0; i -= 2) {
163
-            for ($i = 20; $i > 0; $i -= 2) {
164
-                # QUARTERROUND( x0,  x4,  x8,  x12)
165
-                list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);
162
+			# for (i = 20; i > 0; i -= 2) {
163
+			for ($i = 20; $i > 0; $i -= 2) {
164
+				# QUARTERROUND( x0,  x4,  x8,  x12)
165
+				list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);
166 166
 
167
-                # QUARTERROUND( x1,  x5,  x9,  x13)
168
-                list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);
167
+				# QUARTERROUND( x1,  x5,  x9,  x13)
168
+				list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);
169 169
 
170
-                # QUARTERROUND( x2,  x6,  x10,  x14)
171
-                list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);
170
+				# QUARTERROUND( x2,  x6,  x10,  x14)
171
+				list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);
172 172
 
173
-                # QUARTERROUND( x3,  x7,  x11,  x15)
174
-                list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);
173
+				# QUARTERROUND( x3,  x7,  x11,  x15)
174
+				list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);
175 175
 
176
-                # QUARTERROUND( x0,  x5,  x10,  x15)
177
-                list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);
176
+				# QUARTERROUND( x0,  x5,  x10,  x15)
177
+				list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);
178 178
 
179
-                # QUARTERROUND( x1,  x6,  x11,  x12)
180
-                list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);
179
+				# QUARTERROUND( x1,  x6,  x11,  x12)
180
+				list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);
181 181
 
182
-                # QUARTERROUND( x2,  x7,  x8,  x13)
183
-                list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);
182
+				# QUARTERROUND( x2,  x7,  x8,  x13)
183
+				list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);
184 184
 
185
-                # QUARTERROUND( x3,  x4,  x9,  x14)
186
-                list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
187
-            }
188
-            /*
185
+				# QUARTERROUND( x3,  x4,  x9,  x14)
186
+				list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
187
+			}
188
+			/*
189 189
             x0 = PLUS(x0, j0);
190 190
             x1 = PLUS(x1, j1);
191 191
             x2 = PLUS(x2, j2);
@@ -203,24 +203,24 @@  discard block
 block discarded – undo
203 203
             x14 = PLUS(x14, j14);
204 204
             x15 = PLUS(x15, j15);
205 205
             */
206
-            $x0 = $x0->addInt32($j0);
207
-            $x1 = $x1->addInt32($j1);
208
-            $x2 = $x2->addInt32($j2);
209
-            $x3 = $x3->addInt32($j3);
210
-            $x4 = $x4->addInt32($j4);
211
-            $x5 = $x5->addInt32($j5);
212
-            $x6 = $x6->addInt32($j6);
213
-            $x7 = $x7->addInt32($j7);
214
-            $x8 = $x8->addInt32($j8);
215
-            $x9 = $x9->addInt32($j9);
216
-            $x10 = $x10->addInt32($j10);
217
-            $x11 = $x11->addInt32($j11);
218
-            $x12 = $x12->addInt32($j12);
219
-            $x13 = $x13->addInt32($j13);
220
-            $x14 = $x14->addInt32($j14);
221
-            $x15 = $x15->addInt32($j15);
206
+			$x0 = $x0->addInt32($j0);
207
+			$x1 = $x1->addInt32($j1);
208
+			$x2 = $x2->addInt32($j2);
209
+			$x3 = $x3->addInt32($j3);
210
+			$x4 = $x4->addInt32($j4);
211
+			$x5 = $x5->addInt32($j5);
212
+			$x6 = $x6->addInt32($j6);
213
+			$x7 = $x7->addInt32($j7);
214
+			$x8 = $x8->addInt32($j8);
215
+			$x9 = $x9->addInt32($j9);
216
+			$x10 = $x10->addInt32($j10);
217
+			$x11 = $x11->addInt32($j11);
218
+			$x12 = $x12->addInt32($j12);
219
+			$x13 = $x13->addInt32($j13);
220
+			$x14 = $x14->addInt32($j14);
221
+			$x15 = $x15->addInt32($j15);
222 222
 
223
-            /*
223
+			/*
224 224
             x0 = XOR(x0, LOAD32_LE(m + 0));
225 225
             x1 = XOR(x1, LOAD32_LE(m + 4));
226 226
             x2 = XOR(x2, LOAD32_LE(m + 8));
@@ -238,36 +238,36 @@  discard block
 block discarded – undo
238 238
             x14 = XOR(x14, LOAD32_LE(m + 56));
239 239
             x15 = XOR(x15, LOAD32_LE(m + 60));
240 240
             */
241
-            $x0  =  $x0->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  0, 4)));
242
-            $x1  =  $x1->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  4, 4)));
243
-            $x2  =  $x2->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  8, 4)));
244
-            $x3  =  $x3->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4)));
245
-            $x4  =  $x4->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 16, 4)));
246
-            $x5  =  $x5->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 20, 4)));
247
-            $x6  =  $x6->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 24, 4)));
248
-            $x7  =  $x7->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 28, 4)));
249
-            $x8  =  $x8->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 32, 4)));
250
-            $x9  =  $x9->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 36, 4)));
251
-            $x10 = $x10->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 40, 4)));
252
-            $x11 = $x11->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 44, 4)));
253
-            $x12 = $x12->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 48, 4)));
254
-            $x13 = $x13->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 52, 4)));
255
-            $x14 = $x14->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 56, 4)));
256
-            $x15 = $x15->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 60, 4)));
241
+			$x0  =  $x0->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  0, 4)));
242
+			$x1  =  $x1->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  4, 4)));
243
+			$x2  =  $x2->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  8, 4)));
244
+			$x3  =  $x3->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4)));
245
+			$x4  =  $x4->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 16, 4)));
246
+			$x5  =  $x5->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 20, 4)));
247
+			$x6  =  $x6->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 24, 4)));
248
+			$x7  =  $x7->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 28, 4)));
249
+			$x8  =  $x8->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 32, 4)));
250
+			$x9  =  $x9->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 36, 4)));
251
+			$x10 = $x10->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 40, 4)));
252
+			$x11 = $x11->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 44, 4)));
253
+			$x12 = $x12->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 48, 4)));
254
+			$x13 = $x13->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 52, 4)));
255
+			$x14 = $x14->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 56, 4)));
256
+			$x15 = $x15->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 60, 4)));
257 257
 
258
-            /*
258
+			/*
259 259
                 j12 = PLUSONE(j12);
260 260
                 if (!j12) {
261 261
                     j13 = PLUSONE(j13);
262 262
                 }
263 263
              */
264
-            /** @var ParagonIE_Sodium_Core32_Int32 $j12 */
265
-            $j12 = $j12->addInt(1);
266
-            if ($j12->limbs[0] === 0 && $j12->limbs[1] === 0) {
267
-                $j13 = $j13->addInt(1);
268
-            }
264
+			/** @var ParagonIE_Sodium_Core32_Int32 $j12 */
265
+			$j12 = $j12->addInt(1);
266
+			if ($j12->limbs[0] === 0 && $j12->limbs[1] === 0) {
267
+				$j13 = $j13->addInt(1);
268
+			}
269 269
 
270
-            /*
270
+			/*
271 271
             STORE32_LE(c + 0, x0);
272 272
             STORE32_LE(c + 4, x1);
273 273
             STORE32_LE(c + 8, x2);
@@ -286,115 +286,115 @@  discard block
 block discarded – undo
286 286
             STORE32_LE(c + 60, x15);
287 287
             */
288 288
 
289
-            $block = $x0->toReverseString() .
290
-                $x1->toReverseString() .
291
-                $x2->toReverseString() .
292
-                $x3->toReverseString() .
293
-                $x4->toReverseString() .
294
-                $x5->toReverseString() .
295
-                $x6->toReverseString() .
296
-                $x7->toReverseString() .
297
-                $x8->toReverseString() .
298
-                $x9->toReverseString() .
299
-                $x10->toReverseString() .
300
-                $x11->toReverseString() .
301
-                $x12->toReverseString() .
302
-                $x13->toReverseString() .
303
-                $x14->toReverseString() .
304
-                $x15->toReverseString();
289
+			$block = $x0->toReverseString() .
290
+				$x1->toReverseString() .
291
+				$x2->toReverseString() .
292
+				$x3->toReverseString() .
293
+				$x4->toReverseString() .
294
+				$x5->toReverseString() .
295
+				$x6->toReverseString() .
296
+				$x7->toReverseString() .
297
+				$x8->toReverseString() .
298
+				$x9->toReverseString() .
299
+				$x10->toReverseString() .
300
+				$x11->toReverseString() .
301
+				$x12->toReverseString() .
302
+				$x13->toReverseString() .
303
+				$x14->toReverseString() .
304
+				$x15->toReverseString();
305 305
 
306
-            /* Partial block */
307
-            if ($bytes < 64) {
308
-                $c .= self::substr($block, 0, $bytes);
309
-                break;
310
-            }
306
+			/* Partial block */
307
+			if ($bytes < 64) {
308
+				$c .= self::substr($block, 0, $bytes);
309
+				break;
310
+			}
311 311
 
312
-            /* Full block */
313
-            $c .= $block;
314
-            $bytes -= 64;
315
-            if ($bytes <= 0) {
316
-                break;
317
-            }
318
-            $message = self::substr($message, 64);
319
-        }
320
-        /* end for(;;) loop */
312
+			/* Full block */
313
+			$c .= $block;
314
+			$bytes -= 64;
315
+			if ($bytes <= 0) {
316
+				break;
317
+			}
318
+			$message = self::substr($message, 64);
319
+		}
320
+		/* end for(;;) loop */
321 321
 
322
-        $ctx[12] = $j12;
323
-        $ctx[13] = $j13;
324
-        return $c;
325
-    }
322
+		$ctx[12] = $j12;
323
+		$ctx[13] = $j13;
324
+		return $c;
325
+	}
326 326
 
327
-    /**
328
-     * @internal You should not use this directly from another application
329
-     *
330
-     * @param int $len
331
-     * @param string $nonce
332
-     * @param string $key
333
-     * @return string
334
-     * @throws SodiumException
335
-     * @throws TypeError
336
-     */
337
-    public static function stream($len = 64, $nonce = '', $key = '')
338
-    {
339
-        return self::encryptBytes(
340
-            new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce),
341
-            str_repeat("\x00", $len)
342
-        );
343
-    }
327
+	/**
328
+	 * @internal You should not use this directly from another application
329
+	 *
330
+	 * @param int $len
331
+	 * @param string $nonce
332
+	 * @param string $key
333
+	 * @return string
334
+	 * @throws SodiumException
335
+	 * @throws TypeError
336
+	 */
337
+	public static function stream($len = 64, $nonce = '', $key = '')
338
+	{
339
+		return self::encryptBytes(
340
+			new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce),
341
+			str_repeat("\x00", $len)
342
+		);
343
+	}
344 344
 
345
-    /**
346
-     * @internal You should not use this directly from another application
347
-     *
348
-     * @param int $len
349
-     * @param string $nonce
350
-     * @param string $key
351
-     * @return string
352
-     * @throws SodiumException
353
-     * @throws TypeError
354
-     */
355
-    public static function ietfStream($len, $nonce = '', $key = '')
356
-    {
357
-        return self::encryptBytes(
358
-            new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce),
359
-            str_repeat("\x00", $len)
360
-        );
361
-    }
345
+	/**
346
+	 * @internal You should not use this directly from another application
347
+	 *
348
+	 * @param int $len
349
+	 * @param string $nonce
350
+	 * @param string $key
351
+	 * @return string
352
+	 * @throws SodiumException
353
+	 * @throws TypeError
354
+	 */
355
+	public static function ietfStream($len, $nonce = '', $key = '')
356
+	{
357
+		return self::encryptBytes(
358
+			new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce),
359
+			str_repeat("\x00", $len)
360
+		);
361
+	}
362 362
 
363
-    /**
364
-     * @internal You should not use this directly from another application
365
-     *
366
-     * @param string $message
367
-     * @param string $nonce
368
-     * @param string $key
369
-     * @param string $ic
370
-     * @return string
371
-     * @throws SodiumException
372
-     * @throws TypeError
373
-     */
374
-    public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '')
375
-    {
376
-        return self::encryptBytes(
377
-            new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce, $ic),
378
-            $message
379
-        );
380
-    }
363
+	/**
364
+	 * @internal You should not use this directly from another application
365
+	 *
366
+	 * @param string $message
367
+	 * @param string $nonce
368
+	 * @param string $key
369
+	 * @param string $ic
370
+	 * @return string
371
+	 * @throws SodiumException
372
+	 * @throws TypeError
373
+	 */
374
+	public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '')
375
+	{
376
+		return self::encryptBytes(
377
+			new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce, $ic),
378
+			$message
379
+		);
380
+	}
381 381
 
382
-    /**
383
-     * @internal You should not use this directly from another application
384
-     *
385
-     * @param string $message
386
-     * @param string $nonce
387
-     * @param string $key
388
-     * @param string $ic
389
-     * @return string
390
-     * @throws SodiumException
391
-     * @throws TypeError
392
-     */
393
-    public static function streamXorIc($message, $nonce = '', $key = '', $ic = '')
394
-    {
395
-        return self::encryptBytes(
396
-            new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce, $ic),
397
-            $message
398
-        );
399
-    }
382
+	/**
383
+	 * @internal You should not use this directly from another application
384
+	 *
385
+	 * @param string $message
386
+	 * @param string $nonce
387
+	 * @param string $key
388
+	 * @param string $ic
389
+	 * @return string
390
+	 * @throws SodiumException
391
+	 * @throws TypeError
392
+	 */
393
+	public static function streamXorIc($message, $nonce = '', $key = '', $ic = '')
394
+	{
395
+		return self::encryptBytes(
396
+			new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce, $ic),
397
+			$message
398
+		);
399
+	}
400 400
 }
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 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_ChaCha20', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_ChaCha20', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -34,22 +34,22 @@  discard block
 block discarded – undo
34 34
         /** @var ParagonIE_Sodium_Core32_Int32 $d */
35 35
 
36 36
         # a = PLUS(a,b); d = ROTATE(XOR(d,a),16);
37
-        $a = $a->addInt32($b);
38
-        $d = $d->xorInt32($a)->rotateLeft(16);
37
+        $a = $a->addInt32( $b );
38
+        $d = $d->xorInt32( $a )->rotateLeft( 16 );
39 39
 
40 40
         # c = PLUS(c,d); b = ROTATE(XOR(b,c),12);
41
-        $c = $c->addInt32($d);
42
-        $b = $b->xorInt32($c)->rotateLeft(12);
41
+        $c = $c->addInt32( $d );
42
+        $b = $b->xorInt32( $c )->rotateLeft( 12 );
43 43
 
44 44
         # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8);
45
-        $a = $a->addInt32($b);
46
-        $d = $d->xorInt32($a)->rotateLeft(8);
45
+        $a = $a->addInt32( $b );
46
+        $d = $d->xorInt32( $a )->rotateLeft( 8 );
47 47
 
48 48
         # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
49
-        $c = $c->addInt32($d);
50
-        $b = $b->xorInt32($c)->rotateLeft(7);
49
+        $c = $c->addInt32( $d );
50
+        $b = $b->xorInt32( $c )->rotateLeft( 7 );
51 51
 
52
-        return array($a, $b, $c, $d);
52
+        return array( $a, $b, $c, $d );
53 53
     }
54 54
 
55 55
     /**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         ParagonIE_Sodium_Core32_ChaCha20_Ctx $ctx,
67 67
         $message = ''
68 68
     ) {
69
-        $bytes = self::strlen($message);
69
+        $bytes = self::strlen( $message );
70 70
 
71 71
         /** @var ParagonIE_Sodium_Core32_Int32 $x0 */
72 72
         /** @var ParagonIE_Sodium_Core32_Int32 $x1 */
@@ -104,54 +104,54 @@  discard block
 block discarded – undo
104 104
         j15 = ctx->input[15];
105 105
         */
106 106
         /** @var ParagonIE_Sodium_Core32_Int32 $j0 */
107
-        $j0  = $ctx[0];
107
+        $j0  = $ctx[ 0 ];
108 108
         /** @var ParagonIE_Sodium_Core32_Int32 $j1 */
109
-        $j1  = $ctx[1];
109
+        $j1  = $ctx[ 1 ];
110 110
         /** @var ParagonIE_Sodium_Core32_Int32 $j2 */
111
-        $j2  = $ctx[2];
111
+        $j2  = $ctx[ 2 ];
112 112
         /** @var ParagonIE_Sodium_Core32_Int32 $j3 */
113
-        $j3  = $ctx[3];
113
+        $j3  = $ctx[ 3 ];
114 114
         /** @var ParagonIE_Sodium_Core32_Int32 $j4 */
115
-        $j4  = $ctx[4];
115
+        $j4  = $ctx[ 4 ];
116 116
         /** @var ParagonIE_Sodium_Core32_Int32 $j5 */
117
-        $j5  = $ctx[5];
117
+        $j5  = $ctx[ 5 ];
118 118
         /** @var ParagonIE_Sodium_Core32_Int32 $j6 */
119
-        $j6  = $ctx[6];
119
+        $j6  = $ctx[ 6 ];
120 120
         /** @var ParagonIE_Sodium_Core32_Int32 $j7 */
121
-        $j7  = $ctx[7];
121
+        $j7  = $ctx[ 7 ];
122 122
         /** @var ParagonIE_Sodium_Core32_Int32 $j8 */
123
-        $j8  = $ctx[8];
123
+        $j8  = $ctx[ 8 ];
124 124
         /** @var ParagonIE_Sodium_Core32_Int32 $j9 */
125
-        $j9  = $ctx[9];
125
+        $j9  = $ctx[ 9 ];
126 126
         /** @var ParagonIE_Sodium_Core32_Int32 $j10 */
127
-        $j10 = $ctx[10];
127
+        $j10 = $ctx[ 10 ];
128 128
         /** @var ParagonIE_Sodium_Core32_Int32 $j11 */
129
-        $j11 = $ctx[11];
129
+        $j11 = $ctx[ 11 ];
130 130
         /** @var ParagonIE_Sodium_Core32_Int32 $j12 */
131
-        $j12 = $ctx[12];
131
+        $j12 = $ctx[ 12 ];
132 132
         /** @var ParagonIE_Sodium_Core32_Int32 $j13 */
133
-        $j13 = $ctx[13];
133
+        $j13 = $ctx[ 13 ];
134 134
         /** @var ParagonIE_Sodium_Core32_Int32 $j14 */
135
-        $j14 = $ctx[14];
135
+        $j14 = $ctx[ 14 ];
136 136
         /** @var ParagonIE_Sodium_Core32_Int32 $j15 */
137
-        $j15 = $ctx[15];
137
+        $j15 = $ctx[ 15 ];
138 138
 
139 139
         $c = '';
140
-        for (;;) {
141
-            if ($bytes < 64) {
142
-                $message .= str_repeat("\x00", 64 - $bytes);
140
+        for ( ;; ) {
141
+            if ( $bytes < 64 ) {
142
+                $message .= str_repeat( "\x00", 64 - $bytes );
143 143
             }
144 144
 
145
-            $x0 =  clone $j0;
146
-            $x1 =  clone $j1;
147
-            $x2 =  clone $j2;
148
-            $x3 =  clone $j3;
149
-            $x4 =  clone $j4;
150
-            $x5 =  clone $j5;
151
-            $x6 =  clone $j6;
152
-            $x7 =  clone $j7;
153
-            $x8 =  clone $j8;
154
-            $x9 =  clone $j9;
145
+            $x0 = clone $j0;
146
+            $x1 = clone $j1;
147
+            $x2 = clone $j2;
148
+            $x3 = clone $j3;
149
+            $x4 = clone $j4;
150
+            $x5 = clone $j5;
151
+            $x6 = clone $j6;
152
+            $x7 = clone $j7;
153
+            $x8 = clone $j8;
154
+            $x9 = clone $j9;
155 155
             $x10 = clone $j10;
156 156
             $x11 = clone $j11;
157 157
             $x12 = clone $j12;
@@ -160,30 +160,30 @@  discard block
 block discarded – undo
160 160
             $x15 = clone $j15;
161 161
 
162 162
             # for (i = 20; i > 0; i -= 2) {
163
-            for ($i = 20; $i > 0; $i -= 2) {
163
+            for ( $i = 20; $i > 0; $i -= 2 ) {
164 164
                 # QUARTERROUND( x0,  x4,  x8,  x12)
165
-                list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);
165
+                list( $x0, $x4, $x8, $x12 ) = self::quarterRound( $x0, $x4, $x8, $x12 );
166 166
 
167 167
                 # QUARTERROUND( x1,  x5,  x9,  x13)
168
-                list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);
168
+                list( $x1, $x5, $x9, $x13 ) = self::quarterRound( $x1, $x5, $x9, $x13 );
169 169
 
170 170
                 # QUARTERROUND( x2,  x6,  x10,  x14)
171
-                list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);
171
+                list( $x2, $x6, $x10, $x14 ) = self::quarterRound( $x2, $x6, $x10, $x14 );
172 172
 
173 173
                 # QUARTERROUND( x3,  x7,  x11,  x15)
174
-                list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);
174
+                list( $x3, $x7, $x11, $x15 ) = self::quarterRound( $x3, $x7, $x11, $x15 );
175 175
 
176 176
                 # QUARTERROUND( x0,  x5,  x10,  x15)
177
-                list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);
177
+                list( $x0, $x5, $x10, $x15 ) = self::quarterRound( $x0, $x5, $x10, $x15 );
178 178
 
179 179
                 # QUARTERROUND( x1,  x6,  x11,  x12)
180
-                list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);
180
+                list( $x1, $x6, $x11, $x12 ) = self::quarterRound( $x1, $x6, $x11, $x12 );
181 181
 
182 182
                 # QUARTERROUND( x2,  x7,  x8,  x13)
183
-                list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);
183
+                list( $x2, $x7, $x8, $x13 ) = self::quarterRound( $x2, $x7, $x8, $x13 );
184 184
 
185 185
                 # QUARTERROUND( x3,  x4,  x9,  x14)
186
-                list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
186
+                list( $x3, $x4, $x9, $x14 ) = self::quarterRound( $x3, $x4, $x9, $x14 );
187 187
             }
188 188
             /*
189 189
             x0 = PLUS(x0, j0);
@@ -203,22 +203,22 @@  discard block
 block discarded – undo
203 203
             x14 = PLUS(x14, j14);
204 204
             x15 = PLUS(x15, j15);
205 205
             */
206
-            $x0 = $x0->addInt32($j0);
207
-            $x1 = $x1->addInt32($j1);
208
-            $x2 = $x2->addInt32($j2);
209
-            $x3 = $x3->addInt32($j3);
210
-            $x4 = $x4->addInt32($j4);
211
-            $x5 = $x5->addInt32($j5);
212
-            $x6 = $x6->addInt32($j6);
213
-            $x7 = $x7->addInt32($j7);
214
-            $x8 = $x8->addInt32($j8);
215
-            $x9 = $x9->addInt32($j9);
216
-            $x10 = $x10->addInt32($j10);
217
-            $x11 = $x11->addInt32($j11);
218
-            $x12 = $x12->addInt32($j12);
219
-            $x13 = $x13->addInt32($j13);
220
-            $x14 = $x14->addInt32($j14);
221
-            $x15 = $x15->addInt32($j15);
206
+            $x0 = $x0->addInt32( $j0 );
207
+            $x1 = $x1->addInt32( $j1 );
208
+            $x2 = $x2->addInt32( $j2 );
209
+            $x3 = $x3->addInt32( $j3 );
210
+            $x4 = $x4->addInt32( $j4 );
211
+            $x5 = $x5->addInt32( $j5 );
212
+            $x6 = $x6->addInt32( $j6 );
213
+            $x7 = $x7->addInt32( $j7 );
214
+            $x8 = $x8->addInt32( $j8 );
215
+            $x9 = $x9->addInt32( $j9 );
216
+            $x10 = $x10->addInt32( $j10 );
217
+            $x11 = $x11->addInt32( $j11 );
218
+            $x12 = $x12->addInt32( $j12 );
219
+            $x13 = $x13->addInt32( $j13 );
220
+            $x14 = $x14->addInt32( $j14 );
221
+            $x15 = $x15->addInt32( $j15 );
222 222
 
223 223
             /*
224 224
             x0 = XOR(x0, LOAD32_LE(m + 0));
@@ -238,22 +238,22 @@  discard block
 block discarded – undo
238 238
             x14 = XOR(x14, LOAD32_LE(m + 56));
239 239
             x15 = XOR(x15, LOAD32_LE(m + 60));
240 240
             */
241
-            $x0  =  $x0->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  0, 4)));
242
-            $x1  =  $x1->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  4, 4)));
243
-            $x2  =  $x2->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message,  8, 4)));
244
-            $x3  =  $x3->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4)));
245
-            $x4  =  $x4->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 16, 4)));
246
-            $x5  =  $x5->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 20, 4)));
247
-            $x6  =  $x6->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 24, 4)));
248
-            $x7  =  $x7->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 28, 4)));
249
-            $x8  =  $x8->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 32, 4)));
250
-            $x9  =  $x9->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 36, 4)));
251
-            $x10 = $x10->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 40, 4)));
252
-            $x11 = $x11->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 44, 4)));
253
-            $x12 = $x12->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 48, 4)));
254
-            $x13 = $x13->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 52, 4)));
255
-            $x14 = $x14->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 56, 4)));
256
-            $x15 = $x15->xorInt32(ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 60, 4)));
241
+            $x0  = $x0->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 0, 4 ) ) );
242
+            $x1  = $x1->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 4, 4 ) ) );
243
+            $x2  = $x2->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 8, 4 ) ) );
244
+            $x3  = $x3->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 12, 4 ) ) );
245
+            $x4  = $x4->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 16, 4 ) ) );
246
+            $x5  = $x5->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 20, 4 ) ) );
247
+            $x6  = $x6->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 24, 4 ) ) );
248
+            $x7  = $x7->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 28, 4 ) ) );
249
+            $x8  = $x8->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 32, 4 ) ) );
250
+            $x9  = $x9->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 36, 4 ) ) );
251
+            $x10 = $x10->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 40, 4 ) ) );
252
+            $x11 = $x11->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 44, 4 ) ) );
253
+            $x12 = $x12->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 48, 4 ) ) );
254
+            $x13 = $x13->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 52, 4 ) ) );
255
+            $x14 = $x14->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 56, 4 ) ) );
256
+            $x15 = $x15->xorInt32( ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 60, 4 ) ) );
257 257
 
258 258
             /*
259 259
                 j12 = PLUSONE(j12);
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
                 }
263 263
              */
264 264
             /** @var ParagonIE_Sodium_Core32_Int32 $j12 */
265
-            $j12 = $j12->addInt(1);
266
-            if ($j12->limbs[0] === 0 && $j12->limbs[1] === 0) {
267
-                $j13 = $j13->addInt(1);
265
+            $j12 = $j12->addInt( 1 );
266
+            if ( $j12->limbs[ 0 ] === 0 && $j12->limbs[ 1 ] === 0 ) {
267
+                $j13 = $j13->addInt( 1 );
268 268
             }
269 269
 
270 270
             /*
@@ -304,23 +304,23 @@  discard block
 block discarded – undo
304 304
                 $x15->toReverseString();
305 305
 
306 306
             /* Partial block */
307
-            if ($bytes < 64) {
308
-                $c .= self::substr($block, 0, $bytes);
307
+            if ( $bytes < 64 ) {
308
+                $c .= self::substr( $block, 0, $bytes );
309 309
                 break;
310 310
             }
311 311
 
312 312
             /* Full block */
313 313
             $c .= $block;
314 314
             $bytes -= 64;
315
-            if ($bytes <= 0) {
315
+            if ( $bytes <= 0 ) {
316 316
                 break;
317 317
             }
318
-            $message = self::substr($message, 64);
318
+            $message = self::substr( $message, 64 );
319 319
         }
320 320
         /* end for(;;) loop */
321 321
 
322
-        $ctx[12] = $j12;
323
-        $ctx[13] = $j13;
322
+        $ctx[ 12 ] = $j12;
323
+        $ctx[ 13 ] = $j13;
324 324
         return $c;
325 325
     }
326 326
 
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
      * @throws SodiumException
335 335
      * @throws TypeError
336 336
      */
337
-    public static function stream($len = 64, $nonce = '', $key = '')
337
+    public static function stream( $len = 64, $nonce = '', $key = '' )
338 338
     {
339 339
         return self::encryptBytes(
340
-            new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce),
341
-            str_repeat("\x00", $len)
340
+            new ParagonIE_Sodium_Core32_ChaCha20_Ctx( $key, $nonce ),
341
+            str_repeat( "\x00", $len )
342 342
         );
343 343
     }
344 344
 
@@ -352,11 +352,11 @@  discard block
 block discarded – undo
352 352
      * @throws SodiumException
353 353
      * @throws TypeError
354 354
      */
355
-    public static function ietfStream($len, $nonce = '', $key = '')
355
+    public static function ietfStream( $len, $nonce = '', $key = '' )
356 356
     {
357 357
         return self::encryptBytes(
358
-            new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce),
359
-            str_repeat("\x00", $len)
358
+            new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx( $key, $nonce ),
359
+            str_repeat( "\x00", $len )
360 360
         );
361 361
     }
362 362
 
@@ -371,10 +371,10 @@  discard block
 block discarded – undo
371 371
      * @throws SodiumException
372 372
      * @throws TypeError
373 373
      */
374
-    public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '')
374
+    public static function ietfStreamXorIc( $message, $nonce = '', $key = '', $ic = '' )
375 375
     {
376 376
         return self::encryptBytes(
377
-            new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce, $ic),
377
+            new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx( $key, $nonce, $ic ),
378 378
             $message
379 379
         );
380 380
     }
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
      * @throws SodiumException
391 391
      * @throws TypeError
392 392
      */
393
-    public static function streamXorIc($message, $nonce = '', $key = '', $ic = '')
393
+    public static function streamXorIc( $message, $nonce = '', $key = '', $ic = '' )
394 394
     {
395 395
         return self::encryptBytes(
396
-            new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce, $ic),
396
+            new ParagonIE_Sodium_Core32_ChaCha20_Ctx( $key, $nonce, $ic ),
397 397
             $message
398 398
         );
399 399
     }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 /**
8 8
  * Class ParagonIE_Sodium_Core32_ChaCha20
9 9
  */
10
-class ParagonIE_Sodium_Core32_ChaCha20 extends ParagonIE_Sodium_Core32_Util
11
-{
10
+class ParagonIE_Sodium_Core32_ChaCha20 extends ParagonIE_Sodium_Core32_Util {
12 11
     /**
13 12
      * The ChaCha20 quarter round function. Works on four 32-bit integers.
14 13
      *
@@ -334,8 +333,7 @@  discard block
 block discarded – undo
334 333
      * @throws SodiumException
335 334
      * @throws TypeError
336 335
      */
337
-    public static function stream($len = 64, $nonce = '', $key = '')
338
-    {
336
+    public static function stream($len = 64, $nonce = '', $key = '') {
339 337
         return self::encryptBytes(
340 338
             new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce),
341 339
             str_repeat("\x00", $len)
@@ -352,8 +350,7 @@  discard block
 block discarded – undo
352 350
      * @throws SodiumException
353 351
      * @throws TypeError
354 352
      */
355
-    public static function ietfStream($len, $nonce = '', $key = '')
356
-    {
353
+    public static function ietfStream($len, $nonce = '', $key = '') {
357 354
         return self::encryptBytes(
358 355
             new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce),
359 356
             str_repeat("\x00", $len)
@@ -371,8 +368,7 @@  discard block
 block discarded – undo
371 368
      * @throws SodiumException
372 369
      * @throws TypeError
373 370
      */
374
-    public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '')
375
-    {
371
+    public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') {
376 372
         return self::encryptBytes(
377 373
             new ParagonIE_Sodium_Core32_ChaCha20_IetfCtx($key, $nonce, $ic),
378 374
             $message
@@ -390,8 +386,7 @@  discard block
 block discarded – undo
390 386
      * @throws SodiumException
391 387
      * @throws TypeError
392 388
      */
393
-    public static function streamXorIc($message, $nonce = '', $key = '', $ic = '')
394
-    {
389
+    public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') {
395 390
         return self::encryptBytes(
396 391
             new ParagonIE_Sodium_Core32_ChaCha20_Ctx($key, $nonce, $ic),
397 392
             $message
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/HChaCha20.php 3 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (class_exists('ParagonIE_Sodium_Core32_HChaCha20', false)) {
4
-    return;
4
+	return;
5 5
 }
6 6
 
7 7
 /**
@@ -9,119 +9,119 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class ParagonIE_Sodium_Core32_HChaCha20 extends ParagonIE_Sodium_Core32_ChaCha20
11 11
 {
12
-    /**
13
-     * @param string $in
14
-     * @param string $key
15
-     * @param string|null $c
16
-     * @return string
17
-     * @throws SodiumException
18
-     * @throws TypeError
19
-     */
20
-    public static function hChaCha20($in = '', $key = '', $c = null)
21
-    {
22
-        $ctx = array();
12
+	/**
13
+	 * @param string $in
14
+	 * @param string $key
15
+	 * @param string|null $c
16
+	 * @return string
17
+	 * @throws SodiumException
18
+	 * @throws TypeError
19
+	 */
20
+	public static function hChaCha20($in = '', $key = '', $c = null)
21
+	{
22
+		$ctx = array();
23 23
 
24
-        if ($c === null) {
25
-            $ctx[0] = new ParagonIE_Sodium_Core32_Int32(array(0x6170, 0x7865));
26
-            $ctx[1] = new ParagonIE_Sodium_Core32_Int32(array(0x3320, 0x646e));
27
-            $ctx[2] = new ParagonIE_Sodium_Core32_Int32(array(0x7962, 0x2d32));
28
-            $ctx[3] = new ParagonIE_Sodium_Core32_Int32(array(0x6b20, 0x6574));
29
-        } else {
30
-            $ctx[0] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 0, 4));
31
-            $ctx[1] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 4, 4));
32
-            $ctx[2] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 8, 4));
33
-            $ctx[3] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 12, 4));
34
-        }
35
-        $ctx[4]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4));
36
-        $ctx[5]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 4, 4));
37
-        $ctx[6]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 8, 4));
38
-        $ctx[7]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4));
39
-        $ctx[8]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4));
40
-        $ctx[9]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4));
41
-        $ctx[10] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4));
42
-        $ctx[11] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4));
43
-        $ctx[12] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 0, 4));
44
-        $ctx[13] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 4, 4));
45
-        $ctx[14] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 8, 4));
46
-        $ctx[15] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 12, 4));
24
+		if ($c === null) {
25
+			$ctx[0] = new ParagonIE_Sodium_Core32_Int32(array(0x6170, 0x7865));
26
+			$ctx[1] = new ParagonIE_Sodium_Core32_Int32(array(0x3320, 0x646e));
27
+			$ctx[2] = new ParagonIE_Sodium_Core32_Int32(array(0x7962, 0x2d32));
28
+			$ctx[3] = new ParagonIE_Sodium_Core32_Int32(array(0x6b20, 0x6574));
29
+		} else {
30
+			$ctx[0] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 0, 4));
31
+			$ctx[1] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 4, 4));
32
+			$ctx[2] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 8, 4));
33
+			$ctx[3] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 12, 4));
34
+		}
35
+		$ctx[4]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4));
36
+		$ctx[5]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 4, 4));
37
+		$ctx[6]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 8, 4));
38
+		$ctx[7]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4));
39
+		$ctx[8]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4));
40
+		$ctx[9]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4));
41
+		$ctx[10] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4));
42
+		$ctx[11] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4));
43
+		$ctx[12] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 0, 4));
44
+		$ctx[13] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 4, 4));
45
+		$ctx[14] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 8, 4));
46
+		$ctx[15] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 12, 4));
47 47
 
48
-        return self::hChaCha20Bytes($ctx);
49
-    }
48
+		return self::hChaCha20Bytes($ctx);
49
+	}
50 50
 
51
-    /**
52
-     * @param array $ctx
53
-     * @return string
54
-     * @throws SodiumException
55
-     * @throws TypeError
56
-     */
57
-    protected static function hChaCha20Bytes(array $ctx)
58
-    {
59
-        /** @var ParagonIE_Sodium_Core32_Int32 $x0 */
60
-        $x0  = $ctx[0];
61
-        /** @var ParagonIE_Sodium_Core32_Int32 $x1 */
62
-        $x1  = $ctx[1];
63
-        /** @var ParagonIE_Sodium_Core32_Int32 $x2 */
64
-        $x2  = $ctx[2];
65
-        /** @var ParagonIE_Sodium_Core32_Int32 $x3 */
66
-        $x3  = $ctx[3];
67
-        /** @var ParagonIE_Sodium_Core32_Int32 $x4 */
68
-        $x4  = $ctx[4];
69
-        /** @var ParagonIE_Sodium_Core32_Int32 $x5 */
70
-        $x5  = $ctx[5];
71
-        /** @var ParagonIE_Sodium_Core32_Int32 $x6 */
72
-        $x6  = $ctx[6];
73
-        /** @var ParagonIE_Sodium_Core32_Int32 $x7 */
74
-        $x7  = $ctx[7];
75
-        /** @var ParagonIE_Sodium_Core32_Int32 $x8 */
76
-        $x8  = $ctx[8];
77
-        /** @var ParagonIE_Sodium_Core32_Int32 $x9 */
78
-        $x9  = $ctx[9];
79
-        /** @var ParagonIE_Sodium_Core32_Int32 $x10 */
80
-        $x10 = $ctx[10];
81
-        /** @var ParagonIE_Sodium_Core32_Int32 $x11 */
82
-        $x11 = $ctx[11];
83
-        /** @var ParagonIE_Sodium_Core32_Int32 $x12 */
84
-        $x12 = $ctx[12];
85
-        /** @var ParagonIE_Sodium_Core32_Int32 $x13 */
86
-        $x13 = $ctx[13];
87
-        /** @var ParagonIE_Sodium_Core32_Int32 $x14 */
88
-        $x14 = $ctx[14];
89
-        /** @var ParagonIE_Sodium_Core32_Int32 $x15 */
90
-        $x15 = $ctx[15];
51
+	/**
52
+	 * @param array $ctx
53
+	 * @return string
54
+	 * @throws SodiumException
55
+	 * @throws TypeError
56
+	 */
57
+	protected static function hChaCha20Bytes(array $ctx)
58
+	{
59
+		/** @var ParagonIE_Sodium_Core32_Int32 $x0 */
60
+		$x0  = $ctx[0];
61
+		/** @var ParagonIE_Sodium_Core32_Int32 $x1 */
62
+		$x1  = $ctx[1];
63
+		/** @var ParagonIE_Sodium_Core32_Int32 $x2 */
64
+		$x2  = $ctx[2];
65
+		/** @var ParagonIE_Sodium_Core32_Int32 $x3 */
66
+		$x3  = $ctx[3];
67
+		/** @var ParagonIE_Sodium_Core32_Int32 $x4 */
68
+		$x4  = $ctx[4];
69
+		/** @var ParagonIE_Sodium_Core32_Int32 $x5 */
70
+		$x5  = $ctx[5];
71
+		/** @var ParagonIE_Sodium_Core32_Int32 $x6 */
72
+		$x6  = $ctx[6];
73
+		/** @var ParagonIE_Sodium_Core32_Int32 $x7 */
74
+		$x7  = $ctx[7];
75
+		/** @var ParagonIE_Sodium_Core32_Int32 $x8 */
76
+		$x8  = $ctx[8];
77
+		/** @var ParagonIE_Sodium_Core32_Int32 $x9 */
78
+		$x9  = $ctx[9];
79
+		/** @var ParagonIE_Sodium_Core32_Int32 $x10 */
80
+		$x10 = $ctx[10];
81
+		/** @var ParagonIE_Sodium_Core32_Int32 $x11 */
82
+		$x11 = $ctx[11];
83
+		/** @var ParagonIE_Sodium_Core32_Int32 $x12 */
84
+		$x12 = $ctx[12];
85
+		/** @var ParagonIE_Sodium_Core32_Int32 $x13 */
86
+		$x13 = $ctx[13];
87
+		/** @var ParagonIE_Sodium_Core32_Int32 $x14 */
88
+		$x14 = $ctx[14];
89
+		/** @var ParagonIE_Sodium_Core32_Int32 $x15 */
90
+		$x15 = $ctx[15];
91 91
 
92
-        for ($i = 0; $i < 10; ++$i) {
93
-            # QUARTERROUND( x0,  x4,  x8,  x12)
94
-            list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);
92
+		for ($i = 0; $i < 10; ++$i) {
93
+			# QUARTERROUND( x0,  x4,  x8,  x12)
94
+			list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);
95 95
 
96
-            # QUARTERROUND( x1,  x5,  x9,  x13)
97
-            list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);
96
+			# QUARTERROUND( x1,  x5,  x9,  x13)
97
+			list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);
98 98
 
99
-            # QUARTERROUND( x2,  x6,  x10,  x14)
100
-            list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);
99
+			# QUARTERROUND( x2,  x6,  x10,  x14)
100
+			list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);
101 101
 
102
-            # QUARTERROUND( x3,  x7,  x11,  x15)
103
-            list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);
102
+			# QUARTERROUND( x3,  x7,  x11,  x15)
103
+			list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);
104 104
 
105
-            # QUARTERROUND( x0,  x5,  x10,  x15)
106
-            list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);
105
+			# QUARTERROUND( x0,  x5,  x10,  x15)
106
+			list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);
107 107
 
108
-            # QUARTERROUND( x1,  x6,  x11,  x12)
109
-            list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);
108
+			# QUARTERROUND( x1,  x6,  x11,  x12)
109
+			list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);
110 110
 
111
-            # QUARTERROUND( x2,  x7,  x8,  x13)
112
-            list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);
111
+			# QUARTERROUND( x2,  x7,  x8,  x13)
112
+			list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);
113 113
 
114
-            # QUARTERROUND( x3,  x4,  x9,  x14)
115
-            list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
116
-        }
114
+			# QUARTERROUND( x3,  x4,  x9,  x14)
115
+			list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
116
+		}
117 117
 
118
-        return $x0->toReverseString() .
119
-            $x1->toReverseString() .
120
-            $x2->toReverseString() .
121
-            $x3->toReverseString() .
122
-            $x12->toReverseString() .
123
-            $x13->toReverseString() .
124
-            $x14->toReverseString() .
125
-            $x15->toReverseString();
126
-    }
118
+		return $x0->toReverseString() .
119
+			$x1->toReverseString() .
120
+			$x2->toReverseString() .
121
+			$x3->toReverseString() .
122
+			$x12->toReverseString() .
123
+			$x13->toReverseString() .
124
+			$x14->toReverseString() .
125
+			$x15->toReverseString();
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 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_HChaCha20', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_HChaCha20', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -17,35 +17,35 @@  discard block
 block discarded – undo
17 17
      * @throws SodiumException
18 18
      * @throws TypeError
19 19
      */
20
-    public static function hChaCha20($in = '', $key = '', $c = null)
20
+    public static function hChaCha20( $in = '', $key = '', $c = null )
21 21
     {
22 22
         $ctx = array();
23 23
 
24
-        if ($c === null) {
25
-            $ctx[0] = new ParagonIE_Sodium_Core32_Int32(array(0x6170, 0x7865));
26
-            $ctx[1] = new ParagonIE_Sodium_Core32_Int32(array(0x3320, 0x646e));
27
-            $ctx[2] = new ParagonIE_Sodium_Core32_Int32(array(0x7962, 0x2d32));
28
-            $ctx[3] = new ParagonIE_Sodium_Core32_Int32(array(0x6b20, 0x6574));
24
+        if ( $c === null ) {
25
+            $ctx[ 0 ] = new ParagonIE_Sodium_Core32_Int32( array( 0x6170, 0x7865 ) );
26
+            $ctx[ 1 ] = new ParagonIE_Sodium_Core32_Int32( array( 0x3320, 0x646e ) );
27
+            $ctx[ 2 ] = new ParagonIE_Sodium_Core32_Int32( array( 0x7962, 0x2d32 ) );
28
+            $ctx[ 3 ] = new ParagonIE_Sodium_Core32_Int32( array( 0x6b20, 0x6574 ) );
29 29
         } else {
30
-            $ctx[0] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 0, 4));
31
-            $ctx[1] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 4, 4));
32
-            $ctx[2] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 8, 4));
33
-            $ctx[3] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 12, 4));
30
+            $ctx[ 0 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 0, 4 ) );
31
+            $ctx[ 1 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 4, 4 ) );
32
+            $ctx[ 2 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 8, 4 ) );
33
+            $ctx[ 3 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 12, 4 ) );
34 34
         }
35
-        $ctx[4]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4));
36
-        $ctx[5]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 4, 4));
37
-        $ctx[6]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 8, 4));
38
-        $ctx[7]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4));
39
-        $ctx[8]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4));
40
-        $ctx[9]  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4));
41
-        $ctx[10] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4));
42
-        $ctx[11] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4));
43
-        $ctx[12] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 0, 4));
44
-        $ctx[13] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 4, 4));
45
-        $ctx[14] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 8, 4));
46
-        $ctx[15] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 12, 4));
35
+        $ctx[ 4 ]  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 0, 4 ) );
36
+        $ctx[ 5 ]  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 4, 4 ) );
37
+        $ctx[ 6 ]  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 8, 4 ) );
38
+        $ctx[ 7 ]  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 12, 4 ) );
39
+        $ctx[ 8 ]  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 16, 4 ) );
40
+        $ctx[ 9 ]  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 20, 4 ) );
41
+        $ctx[ 10 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 24, 4 ) );
42
+        $ctx[ 11 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 28, 4 ) );
43
+        $ctx[ 12 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 0, 4 ) );
44
+        $ctx[ 13 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 4, 4 ) );
45
+        $ctx[ 14 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 8, 4 ) );
46
+        $ctx[ 15 ] = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 12, 4 ) );
47 47
 
48
-        return self::hChaCha20Bytes($ctx);
48
+        return self::hChaCha20Bytes( $ctx );
49 49
     }
50 50
 
51 51
     /**
@@ -54,65 +54,65 @@  discard block
 block discarded – undo
54 54
      * @throws SodiumException
55 55
      * @throws TypeError
56 56
      */
57
-    protected static function hChaCha20Bytes(array $ctx)
57
+    protected static function hChaCha20Bytes( array $ctx )
58 58
     {
59 59
         /** @var ParagonIE_Sodium_Core32_Int32 $x0 */
60
-        $x0  = $ctx[0];
60
+        $x0  = $ctx[ 0 ];
61 61
         /** @var ParagonIE_Sodium_Core32_Int32 $x1 */
62
-        $x1  = $ctx[1];
62
+        $x1  = $ctx[ 1 ];
63 63
         /** @var ParagonIE_Sodium_Core32_Int32 $x2 */
64
-        $x2  = $ctx[2];
64
+        $x2  = $ctx[ 2 ];
65 65
         /** @var ParagonIE_Sodium_Core32_Int32 $x3 */
66
-        $x3  = $ctx[3];
66
+        $x3  = $ctx[ 3 ];
67 67
         /** @var ParagonIE_Sodium_Core32_Int32 $x4 */
68
-        $x4  = $ctx[4];
68
+        $x4  = $ctx[ 4 ];
69 69
         /** @var ParagonIE_Sodium_Core32_Int32 $x5 */
70
-        $x5  = $ctx[5];
70
+        $x5  = $ctx[ 5 ];
71 71
         /** @var ParagonIE_Sodium_Core32_Int32 $x6 */
72
-        $x6  = $ctx[6];
72
+        $x6  = $ctx[ 6 ];
73 73
         /** @var ParagonIE_Sodium_Core32_Int32 $x7 */
74
-        $x7  = $ctx[7];
74
+        $x7  = $ctx[ 7 ];
75 75
         /** @var ParagonIE_Sodium_Core32_Int32 $x8 */
76
-        $x8  = $ctx[8];
76
+        $x8  = $ctx[ 8 ];
77 77
         /** @var ParagonIE_Sodium_Core32_Int32 $x9 */
78
-        $x9  = $ctx[9];
78
+        $x9  = $ctx[ 9 ];
79 79
         /** @var ParagonIE_Sodium_Core32_Int32 $x10 */
80
-        $x10 = $ctx[10];
80
+        $x10 = $ctx[ 10 ];
81 81
         /** @var ParagonIE_Sodium_Core32_Int32 $x11 */
82
-        $x11 = $ctx[11];
82
+        $x11 = $ctx[ 11 ];
83 83
         /** @var ParagonIE_Sodium_Core32_Int32 $x12 */
84
-        $x12 = $ctx[12];
84
+        $x12 = $ctx[ 12 ];
85 85
         /** @var ParagonIE_Sodium_Core32_Int32 $x13 */
86
-        $x13 = $ctx[13];
86
+        $x13 = $ctx[ 13 ];
87 87
         /** @var ParagonIE_Sodium_Core32_Int32 $x14 */
88
-        $x14 = $ctx[14];
88
+        $x14 = $ctx[ 14 ];
89 89
         /** @var ParagonIE_Sodium_Core32_Int32 $x15 */
90
-        $x15 = $ctx[15];
90
+        $x15 = $ctx[ 15 ];
91 91
 
92
-        for ($i = 0; $i < 10; ++$i) {
92
+        for ( $i = 0; $i < 10; ++$i ) {
93 93
             # QUARTERROUND( x0,  x4,  x8,  x12)
94
-            list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);
94
+            list( $x0, $x4, $x8, $x12 ) = self::quarterRound( $x0, $x4, $x8, $x12 );
95 95
 
96 96
             # QUARTERROUND( x1,  x5,  x9,  x13)
97
-            list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);
97
+            list( $x1, $x5, $x9, $x13 ) = self::quarterRound( $x1, $x5, $x9, $x13 );
98 98
 
99 99
             # QUARTERROUND( x2,  x6,  x10,  x14)
100
-            list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);
100
+            list( $x2, $x6, $x10, $x14 ) = self::quarterRound( $x2, $x6, $x10, $x14 );
101 101
 
102 102
             # QUARTERROUND( x3,  x7,  x11,  x15)
103
-            list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);
103
+            list( $x3, $x7, $x11, $x15 ) = self::quarterRound( $x3, $x7, $x11, $x15 );
104 104
 
105 105
             # QUARTERROUND( x0,  x5,  x10,  x15)
106
-            list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);
106
+            list( $x0, $x5, $x10, $x15 ) = self::quarterRound( $x0, $x5, $x10, $x15 );
107 107
 
108 108
             # QUARTERROUND( x1,  x6,  x11,  x12)
109
-            list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);
109
+            list( $x1, $x6, $x11, $x12 ) = self::quarterRound( $x1, $x6, $x11, $x12 );
110 110
 
111 111
             # QUARTERROUND( x2,  x7,  x8,  x13)
112
-            list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);
112
+            list( $x2, $x7, $x8, $x13 ) = self::quarterRound( $x2, $x7, $x8, $x13 );
113 113
 
114 114
             # QUARTERROUND( x3,  x4,  x9,  x14)
115
-            list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
115
+            list( $x3, $x4, $x9, $x14 ) = self::quarterRound( $x3, $x4, $x9, $x14 );
116 116
         }
117 117
 
118 118
         return $x0->toReverseString() .
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 /**
8 8
  * Class ParagonIE_Sodium_Core_HChaCha20
9 9
  */
10
-class ParagonIE_Sodium_Core32_HChaCha20 extends ParagonIE_Sodium_Core32_ChaCha20
11
-{
10
+class ParagonIE_Sodium_Core32_HChaCha20 extends ParagonIE_Sodium_Core32_ChaCha20 {
12 11
     /**
13 12
      * @param string $in
14 13
      * @param string $key
@@ -17,8 +16,7 @@  discard block
 block discarded – undo
17 16
      * @throws SodiumException
18 17
      * @throws TypeError
19 18
      */
20
-    public static function hChaCha20($in = '', $key = '', $c = null)
21
-    {
19
+    public static function hChaCha20($in = '', $key = '', $c = null) {
22 20
         $ctx = array();
23 21
 
24 22
         if ($c === null) {
@@ -54,8 +52,7 @@  discard block
 block discarded – undo
54 52
      * @throws SodiumException
55 53
      * @throws TypeError
56 54
      */
57
-    protected static function hChaCha20Bytes(array $ctx)
58
-    {
55
+    protected static function hChaCha20Bytes(array $ctx) {
59 56
         /** @var ParagonIE_Sodium_Core32_Int32 $x0 */
60 57
         $x0  = $ctx[0];
61 58
         /** @var ParagonIE_Sodium_Core32_Int32 $x1 */
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/HSalsa20.php 3 patches
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (class_exists('ParagonIE_Sodium_Core32_HSalsa20', false)) {
4
-    return;
4
+	return;
5 5
 }
6 6
 
7 7
 /**
@@ -9,133 +9,133 @@  discard block
 block discarded – undo
9 9
  */
10 10
 abstract class ParagonIE_Sodium_Core32_HSalsa20 extends ParagonIE_Sodium_Core32_Salsa20
11 11
 {
12
-    /**
13
-     * Calculate an hsalsa20 hash of a single block
14
-     *
15
-     * HSalsa20 doesn't have a counter and will never be used for more than
16
-     * one block (used to derive a subkey for xsalsa20).
17
-     *
18
-     * @internal You should not use this directly from another application
19
-     *
20
-     * @param string $in
21
-     * @param string $k
22
-     * @param string|null $c
23
-     * @return string
24
-     * @throws SodiumException
25
-     * @throws TypeError
26
-     */
27
-    public static function hsalsa20($in, $k, $c = null)
28
-    {
29
-        /**
30
-         * @var ParagonIE_Sodium_Core32_Int32 $x0
31
-         * @var ParagonIE_Sodium_Core32_Int32 $x1
32
-         * @var ParagonIE_Sodium_Core32_Int32 $x2
33
-         * @var ParagonIE_Sodium_Core32_Int32 $x3
34
-         * @var ParagonIE_Sodium_Core32_Int32 $x4
35
-         * @var ParagonIE_Sodium_Core32_Int32 $x5
36
-         * @var ParagonIE_Sodium_Core32_Int32 $x6
37
-         * @var ParagonIE_Sodium_Core32_Int32 $x7
38
-         * @var ParagonIE_Sodium_Core32_Int32 $x8
39
-         * @var ParagonIE_Sodium_Core32_Int32 $x9
40
-         * @var ParagonIE_Sodium_Core32_Int32 $x10
41
-         * @var ParagonIE_Sodium_Core32_Int32 $x11
42
-         * @var ParagonIE_Sodium_Core32_Int32 $x12
43
-         * @var ParagonIE_Sodium_Core32_Int32 $x13
44
-         * @var ParagonIE_Sodium_Core32_Int32 $x14
45
-         * @var ParagonIE_Sodium_Core32_Int32 $x15
46
-         * @var ParagonIE_Sodium_Core32_Int32 $j0
47
-         * @var ParagonIE_Sodium_Core32_Int32 $j1
48
-         * @var ParagonIE_Sodium_Core32_Int32 $j2
49
-         * @var ParagonIE_Sodium_Core32_Int32 $j3
50
-         * @var ParagonIE_Sodium_Core32_Int32 $j4
51
-         * @var ParagonIE_Sodium_Core32_Int32 $j5
52
-         * @var ParagonIE_Sodium_Core32_Int32 $j6
53
-         * @var ParagonIE_Sodium_Core32_Int32 $j7
54
-         * @var ParagonIE_Sodium_Core32_Int32 $j8
55
-         * @var ParagonIE_Sodium_Core32_Int32 $j9
56
-         * @var ParagonIE_Sodium_Core32_Int32 $j10
57
-         * @var ParagonIE_Sodium_Core32_Int32 $j11
58
-         * @var ParagonIE_Sodium_Core32_Int32 $j12
59
-         * @var ParagonIE_Sodium_Core32_Int32 $j13
60
-         * @var ParagonIE_Sodium_Core32_Int32 $j14
61
-         * @var ParagonIE_Sodium_Core32_Int32 $j15
62
-         */
63
-        if (self::strlen($k) < 32) {
64
-            throw new RangeException('Key must be 32 bytes long');
65
-        }
66
-        if ($c === null) {
67
-            $x0  = new ParagonIE_Sodium_Core32_Int32(array(0x6170, 0x7865));
68
-            $x5  = new ParagonIE_Sodium_Core32_Int32(array(0x3320, 0x646e));
69
-            $x10 = new ParagonIE_Sodium_Core32_Int32(array(0x7962, 0x2d32));
70
-            $x15 = new ParagonIE_Sodium_Core32_Int32(array(0x6b20, 0x6574));
71
-        } else {
72
-            $x0  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 0, 4));
73
-            $x5  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 4, 4));
74
-            $x10 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 8, 4));
75
-            $x15 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 12, 4));
76
-        }
77
-        $x1  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 0, 4));
78
-        $x2  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 4, 4));
79
-        $x3  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 8, 4));
80
-        $x4  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 12, 4));
81
-        $x6  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 0, 4));
82
-        $x7  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 4, 4));
83
-        $x8  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 8, 4));
84
-        $x9  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 12, 4));
85
-        $x11 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 16, 4));
86
-        $x12 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 20, 4));
87
-        $x13 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 24, 4));
88
-        $x14 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 28, 4));
12
+	/**
13
+	 * Calculate an hsalsa20 hash of a single block
14
+	 *
15
+	 * HSalsa20 doesn't have a counter and will never be used for more than
16
+	 * one block (used to derive a subkey for xsalsa20).
17
+	 *
18
+	 * @internal You should not use this directly from another application
19
+	 *
20
+	 * @param string $in
21
+	 * @param string $k
22
+	 * @param string|null $c
23
+	 * @return string
24
+	 * @throws SodiumException
25
+	 * @throws TypeError
26
+	 */
27
+	public static function hsalsa20($in, $k, $c = null)
28
+	{
29
+		/**
30
+		 * @var ParagonIE_Sodium_Core32_Int32 $x0
31
+		 * @var ParagonIE_Sodium_Core32_Int32 $x1
32
+		 * @var ParagonIE_Sodium_Core32_Int32 $x2
33
+		 * @var ParagonIE_Sodium_Core32_Int32 $x3
34
+		 * @var ParagonIE_Sodium_Core32_Int32 $x4
35
+		 * @var ParagonIE_Sodium_Core32_Int32 $x5
36
+		 * @var ParagonIE_Sodium_Core32_Int32 $x6
37
+		 * @var ParagonIE_Sodium_Core32_Int32 $x7
38
+		 * @var ParagonIE_Sodium_Core32_Int32 $x8
39
+		 * @var ParagonIE_Sodium_Core32_Int32 $x9
40
+		 * @var ParagonIE_Sodium_Core32_Int32 $x10
41
+		 * @var ParagonIE_Sodium_Core32_Int32 $x11
42
+		 * @var ParagonIE_Sodium_Core32_Int32 $x12
43
+		 * @var ParagonIE_Sodium_Core32_Int32 $x13
44
+		 * @var ParagonIE_Sodium_Core32_Int32 $x14
45
+		 * @var ParagonIE_Sodium_Core32_Int32 $x15
46
+		 * @var ParagonIE_Sodium_Core32_Int32 $j0
47
+		 * @var ParagonIE_Sodium_Core32_Int32 $j1
48
+		 * @var ParagonIE_Sodium_Core32_Int32 $j2
49
+		 * @var ParagonIE_Sodium_Core32_Int32 $j3
50
+		 * @var ParagonIE_Sodium_Core32_Int32 $j4
51
+		 * @var ParagonIE_Sodium_Core32_Int32 $j5
52
+		 * @var ParagonIE_Sodium_Core32_Int32 $j6
53
+		 * @var ParagonIE_Sodium_Core32_Int32 $j7
54
+		 * @var ParagonIE_Sodium_Core32_Int32 $j8
55
+		 * @var ParagonIE_Sodium_Core32_Int32 $j9
56
+		 * @var ParagonIE_Sodium_Core32_Int32 $j10
57
+		 * @var ParagonIE_Sodium_Core32_Int32 $j11
58
+		 * @var ParagonIE_Sodium_Core32_Int32 $j12
59
+		 * @var ParagonIE_Sodium_Core32_Int32 $j13
60
+		 * @var ParagonIE_Sodium_Core32_Int32 $j14
61
+		 * @var ParagonIE_Sodium_Core32_Int32 $j15
62
+		 */
63
+		if (self::strlen($k) < 32) {
64
+			throw new RangeException('Key must be 32 bytes long');
65
+		}
66
+		if ($c === null) {
67
+			$x0  = new ParagonIE_Sodium_Core32_Int32(array(0x6170, 0x7865));
68
+			$x5  = new ParagonIE_Sodium_Core32_Int32(array(0x3320, 0x646e));
69
+			$x10 = new ParagonIE_Sodium_Core32_Int32(array(0x7962, 0x2d32));
70
+			$x15 = new ParagonIE_Sodium_Core32_Int32(array(0x6b20, 0x6574));
71
+		} else {
72
+			$x0  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 0, 4));
73
+			$x5  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 4, 4));
74
+			$x10 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 8, 4));
75
+			$x15 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 12, 4));
76
+		}
77
+		$x1  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 0, 4));
78
+		$x2  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 4, 4));
79
+		$x3  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 8, 4));
80
+		$x4  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 12, 4));
81
+		$x6  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 0, 4));
82
+		$x7  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 4, 4));
83
+		$x8  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 8, 4));
84
+		$x9  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 12, 4));
85
+		$x11 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 16, 4));
86
+		$x12 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 20, 4));
87
+		$x13 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 24, 4));
88
+		$x14 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 28, 4));
89 89
 
90
-        for ($i = self::ROUNDS; $i > 0; $i -= 2) {
91
-            $x4  = $x4->xorInt32($x0->addInt32($x12)->rotateLeft(7));
92
-            $x8  = $x8->xorInt32($x4->addInt32($x0)->rotateLeft(9));
93
-            $x12 = $x12->xorInt32($x8->addInt32($x4)->rotateLeft(13));
94
-            $x0  = $x0->xorInt32($x12->addInt32($x8)->rotateLeft(18));
90
+		for ($i = self::ROUNDS; $i > 0; $i -= 2) {
91
+			$x4  = $x4->xorInt32($x0->addInt32($x12)->rotateLeft(7));
92
+			$x8  = $x8->xorInt32($x4->addInt32($x0)->rotateLeft(9));
93
+			$x12 = $x12->xorInt32($x8->addInt32($x4)->rotateLeft(13));
94
+			$x0  = $x0->xorInt32($x12->addInt32($x8)->rotateLeft(18));
95 95
 
96
-            $x9  = $x9->xorInt32($x5->addInt32($x1)->rotateLeft(7));
97
-            $x13 = $x13->xorInt32($x9->addInt32($x5)->rotateLeft(9));
98
-            $x1  = $x1->xorInt32($x13->addInt32($x9)->rotateLeft(13));
99
-            $x5  = $x5->xorInt32($x1->addInt32($x13)->rotateLeft(18));
96
+			$x9  = $x9->xorInt32($x5->addInt32($x1)->rotateLeft(7));
97
+			$x13 = $x13->xorInt32($x9->addInt32($x5)->rotateLeft(9));
98
+			$x1  = $x1->xorInt32($x13->addInt32($x9)->rotateLeft(13));
99
+			$x5  = $x5->xorInt32($x1->addInt32($x13)->rotateLeft(18));
100 100
 
101
-            $x14 = $x14->xorInt32($x10->addInt32($x6)->rotateLeft(7));
102
-            $x2  = $x2->xorInt32($x14->addInt32($x10)->rotateLeft(9));
103
-            $x6  = $x6->xorInt32($x2->addInt32($x14)->rotateLeft(13));
104
-            $x10 = $x10->xorInt32($x6->addInt32($x2)->rotateLeft(18));
101
+			$x14 = $x14->xorInt32($x10->addInt32($x6)->rotateLeft(7));
102
+			$x2  = $x2->xorInt32($x14->addInt32($x10)->rotateLeft(9));
103
+			$x6  = $x6->xorInt32($x2->addInt32($x14)->rotateLeft(13));
104
+			$x10 = $x10->xorInt32($x6->addInt32($x2)->rotateLeft(18));
105 105
 
106
-            $x3  = $x3->xorInt32($x15->addInt32($x11)->rotateLeft(7));
107
-            $x7  = $x7->xorInt32($x3->addInt32($x15)->rotateLeft(9));
108
-            $x11 = $x11->xorInt32($x7->addInt32($x3)->rotateLeft(13));
109
-            $x15 = $x15->xorInt32($x11->addInt32($x7)->rotateLeft(18));
106
+			$x3  = $x3->xorInt32($x15->addInt32($x11)->rotateLeft(7));
107
+			$x7  = $x7->xorInt32($x3->addInt32($x15)->rotateLeft(9));
108
+			$x11 = $x11->xorInt32($x7->addInt32($x3)->rotateLeft(13));
109
+			$x15 = $x15->xorInt32($x11->addInt32($x7)->rotateLeft(18));
110 110
 
111
-            $x1  = $x1->xorInt32($x0->addInt32($x3)->rotateLeft(7));
112
-            $x2  = $x2->xorInt32($x1->addInt32($x0)->rotateLeft(9));
113
-            $x3  = $x3->xorInt32($x2->addInt32($x1)->rotateLeft(13));
114
-            $x0  = $x0->xorInt32($x3->addInt32($x2)->rotateLeft(18));
111
+			$x1  = $x1->xorInt32($x0->addInt32($x3)->rotateLeft(7));
112
+			$x2  = $x2->xorInt32($x1->addInt32($x0)->rotateLeft(9));
113
+			$x3  = $x3->xorInt32($x2->addInt32($x1)->rotateLeft(13));
114
+			$x0  = $x0->xorInt32($x3->addInt32($x2)->rotateLeft(18));
115 115
 
116
-            $x6  = $x6->xorInt32($x5->addInt32($x4)->rotateLeft(7));
117
-            $x7  = $x7->xorInt32($x6->addInt32($x5)->rotateLeft(9));
118
-            $x4  = $x4->xorInt32($x7->addInt32($x6)->rotateLeft(13));
119
-            $x5  = $x5->xorInt32($x4->addInt32($x7)->rotateLeft(18));
116
+			$x6  = $x6->xorInt32($x5->addInt32($x4)->rotateLeft(7));
117
+			$x7  = $x7->xorInt32($x6->addInt32($x5)->rotateLeft(9));
118
+			$x4  = $x4->xorInt32($x7->addInt32($x6)->rotateLeft(13));
119
+			$x5  = $x5->xorInt32($x4->addInt32($x7)->rotateLeft(18));
120 120
 
121
-            $x11 = $x11->xorInt32($x10->addInt32($x9)->rotateLeft(7));
122
-            $x8  = $x8->xorInt32($x11->addInt32($x10)->rotateLeft(9));
123
-            $x9  = $x9->xorInt32($x8->addInt32($x11)->rotateLeft(13));
124
-            $x10 = $x10->xorInt32($x9->addInt32($x8)->rotateLeft(18));
121
+			$x11 = $x11->xorInt32($x10->addInt32($x9)->rotateLeft(7));
122
+			$x8  = $x8->xorInt32($x11->addInt32($x10)->rotateLeft(9));
123
+			$x9  = $x9->xorInt32($x8->addInt32($x11)->rotateLeft(13));
124
+			$x10 = $x10->xorInt32($x9->addInt32($x8)->rotateLeft(18));
125 125
 
126
-            $x12 = $x12->xorInt32($x15->addInt32($x14)->rotateLeft(7));
127
-            $x13 = $x13->xorInt32($x12->addInt32($x15)->rotateLeft(9));
128
-            $x14 = $x14->xorInt32($x13->addInt32($x12)->rotateLeft(13));
129
-            $x15 = $x15->xorInt32($x14->addInt32($x13)->rotateLeft(18));
130
-        }
126
+			$x12 = $x12->xorInt32($x15->addInt32($x14)->rotateLeft(7));
127
+			$x13 = $x13->xorInt32($x12->addInt32($x15)->rotateLeft(9));
128
+			$x14 = $x14->xorInt32($x13->addInt32($x12)->rotateLeft(13));
129
+			$x15 = $x15->xorInt32($x14->addInt32($x13)->rotateLeft(18));
130
+		}
131 131
 
132
-        return $x0->toReverseString() .
133
-            $x5->toReverseString() .
134
-            $x10->toReverseString() .
135
-            $x15->toReverseString() .
136
-            $x6->toReverseString() .
137
-            $x7->toReverseString() .
138
-            $x8->toReverseString() .
139
-            $x9->toReverseString();
140
-    }
132
+		return $x0->toReverseString() .
133
+			$x5->toReverseString() .
134
+			$x10->toReverseString() .
135
+			$x15->toReverseString() .
136
+			$x6->toReverseString() .
137
+			$x7->toReverseString() .
138
+			$x8->toReverseString() .
139
+			$x9->toReverseString();
140
+	}
141 141
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 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_HSalsa20', false)) {
3
+if ( class_exists( 'ParagonIE_Sodium_Core32_HSalsa20', false ) ) {
4 4
     return;
5 5
 }
6 6
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * @throws SodiumException
25 25
      * @throws TypeError
26 26
      */
27
-    public static function hsalsa20($in, $k, $c = null)
27
+    public static function hsalsa20( $in, $k, $c = null )
28 28
     {
29 29
         /**
30 30
          * @var ParagonIE_Sodium_Core32_Int32 $x0
@@ -60,73 +60,73 @@  discard block
 block discarded – undo
60 60
          * @var ParagonIE_Sodium_Core32_Int32 $j14
61 61
          * @var ParagonIE_Sodium_Core32_Int32 $j15
62 62
          */
63
-        if (self::strlen($k) < 32) {
64
-            throw new RangeException('Key must be 32 bytes long');
63
+        if ( self::strlen( $k ) < 32 ) {
64
+            throw new RangeException( 'Key must be 32 bytes long' );
65 65
         }
66
-        if ($c === null) {
67
-            $x0  = new ParagonIE_Sodium_Core32_Int32(array(0x6170, 0x7865));
68
-            $x5  = new ParagonIE_Sodium_Core32_Int32(array(0x3320, 0x646e));
69
-            $x10 = new ParagonIE_Sodium_Core32_Int32(array(0x7962, 0x2d32));
70
-            $x15 = new ParagonIE_Sodium_Core32_Int32(array(0x6b20, 0x6574));
66
+        if ( $c === null ) {
67
+            $x0  = new ParagonIE_Sodium_Core32_Int32( array( 0x6170, 0x7865 ) );
68
+            $x5  = new ParagonIE_Sodium_Core32_Int32( array( 0x3320, 0x646e ) );
69
+            $x10 = new ParagonIE_Sodium_Core32_Int32( array( 0x7962, 0x2d32 ) );
70
+            $x15 = new ParagonIE_Sodium_Core32_Int32( array( 0x6b20, 0x6574 ) );
71 71
         } else {
72
-            $x0  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 0, 4));
73
-            $x5  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 4, 4));
74
-            $x10 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 8, 4));
75
-            $x15 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($c, 12, 4));
72
+            $x0  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 0, 4 ) );
73
+            $x5  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 4, 4 ) );
74
+            $x10 = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 8, 4 ) );
75
+            $x15 = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $c, 12, 4 ) );
76 76
         }
77
-        $x1  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 0, 4));
78
-        $x2  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 4, 4));
79
-        $x3  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 8, 4));
80
-        $x4  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 12, 4));
81
-        $x6  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 0, 4));
82
-        $x7  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 4, 4));
83
-        $x8  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 8, 4));
84
-        $x9  = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($in, 12, 4));
85
-        $x11 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 16, 4));
86
-        $x12 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 20, 4));
87
-        $x13 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 24, 4));
88
-        $x14 = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($k, 28, 4));
77
+        $x1  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 0, 4 ) );
78
+        $x2  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 4, 4 ) );
79
+        $x3  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 8, 4 ) );
80
+        $x4  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 12, 4 ) );
81
+        $x6  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 0, 4 ) );
82
+        $x7  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 4, 4 ) );
83
+        $x8  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 8, 4 ) );
84
+        $x9  = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $in, 12, 4 ) );
85
+        $x11 = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 16, 4 ) );
86
+        $x12 = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 20, 4 ) );
87
+        $x13 = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 24, 4 ) );
88
+        $x14 = ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $k, 28, 4 ) );
89 89
 
90
-        for ($i = self::ROUNDS; $i > 0; $i -= 2) {
91
-            $x4  = $x4->xorInt32($x0->addInt32($x12)->rotateLeft(7));
92
-            $x8  = $x8->xorInt32($x4->addInt32($x0)->rotateLeft(9));
93
-            $x12 = $x12->xorInt32($x8->addInt32($x4)->rotateLeft(13));
94
-            $x0  = $x0->xorInt32($x12->addInt32($x8)->rotateLeft(18));
90
+        for ( $i = self::ROUNDS; $i > 0; $i -= 2 ) {
91
+            $x4  = $x4->xorInt32( $x0->addInt32( $x12 )->rotateLeft( 7 ) );
92
+            $x8  = $x8->xorInt32( $x4->addInt32( $x0 )->rotateLeft( 9 ) );
93
+            $x12 = $x12->xorInt32( $x8->addInt32( $x4 )->rotateLeft( 13 ) );
94
+            $x0  = $x0->xorInt32( $x12->addInt32( $x8 )->rotateLeft( 18 ) );
95 95
 
96
-            $x9  = $x9->xorInt32($x5->addInt32($x1)->rotateLeft(7));
97
-            $x13 = $x13->xorInt32($x9->addInt32($x5)->rotateLeft(9));
98
-            $x1  = $x1->xorInt32($x13->addInt32($x9)->rotateLeft(13));
99
-            $x5  = $x5->xorInt32($x1->addInt32($x13)->rotateLeft(18));
96
+            $x9  = $x9->xorInt32( $x5->addInt32( $x1 )->rotateLeft( 7 ) );
97
+            $x13 = $x13->xorInt32( $x9->addInt32( $x5 )->rotateLeft( 9 ) );
98
+            $x1  = $x1->xorInt32( $x13->addInt32( $x9 )->rotateLeft( 13 ) );
99
+            $x5  = $x5->xorInt32( $x1->addInt32( $x13 )->rotateLeft( 18 ) );
100 100
 
101
-            $x14 = $x14->xorInt32($x10->addInt32($x6)->rotateLeft(7));
102
-            $x2  = $x2->xorInt32($x14->addInt32($x10)->rotateLeft(9));
103
-            $x6  = $x6->xorInt32($x2->addInt32($x14)->rotateLeft(13));
104
-            $x10 = $x10->xorInt32($x6->addInt32($x2)->rotateLeft(18));
101
+            $x14 = $x14->xorInt32( $x10->addInt32( $x6 )->rotateLeft( 7 ) );
102
+            $x2  = $x2->xorInt32( $x14->addInt32( $x10 )->rotateLeft( 9 ) );
103
+            $x6  = $x6->xorInt32( $x2->addInt32( $x14 )->rotateLeft( 13 ) );
104
+            $x10 = $x10->xorInt32( $x6->addInt32( $x2 )->rotateLeft( 18 ) );
105 105
 
106
-            $x3  = $x3->xorInt32($x15->addInt32($x11)->rotateLeft(7));
107
-            $x7  = $x7->xorInt32($x3->addInt32($x15)->rotateLeft(9));
108
-            $x11 = $x11->xorInt32($x7->addInt32($x3)->rotateLeft(13));
109
-            $x15 = $x15->xorInt32($x11->addInt32($x7)->rotateLeft(18));
106
+            $x3  = $x3->xorInt32( $x15->addInt32( $x11 )->rotateLeft( 7 ) );
107
+            $x7  = $x7->xorInt32( $x3->addInt32( $x15 )->rotateLeft( 9 ) );
108
+            $x11 = $x11->xorInt32( $x7->addInt32( $x3 )->rotateLeft( 13 ) );
109
+            $x15 = $x15->xorInt32( $x11->addInt32( $x7 )->rotateLeft( 18 ) );
110 110
 
111
-            $x1  = $x1->xorInt32($x0->addInt32($x3)->rotateLeft(7));
112
-            $x2  = $x2->xorInt32($x1->addInt32($x0)->rotateLeft(9));
113
-            $x3  = $x3->xorInt32($x2->addInt32($x1)->rotateLeft(13));
114
-            $x0  = $x0->xorInt32($x3->addInt32($x2)->rotateLeft(18));
111
+            $x1  = $x1->xorInt32( $x0->addInt32( $x3 )->rotateLeft( 7 ) );
112
+            $x2  = $x2->xorInt32( $x1->addInt32( $x0 )->rotateLeft( 9 ) );
113
+            $x3  = $x3->xorInt32( $x2->addInt32( $x1 )->rotateLeft( 13 ) );
114
+            $x0  = $x0->xorInt32( $x3->addInt32( $x2 )->rotateLeft( 18 ) );
115 115
 
116
-            $x6  = $x6->xorInt32($x5->addInt32($x4)->rotateLeft(7));
117
-            $x7  = $x7->xorInt32($x6->addInt32($x5)->rotateLeft(9));
118
-            $x4  = $x4->xorInt32($x7->addInt32($x6)->rotateLeft(13));
119
-            $x5  = $x5->xorInt32($x4->addInt32($x7)->rotateLeft(18));
116
+            $x6  = $x6->xorInt32( $x5->addInt32( $x4 )->rotateLeft( 7 ) );
117
+            $x7  = $x7->xorInt32( $x6->addInt32( $x5 )->rotateLeft( 9 ) );
118
+            $x4  = $x4->xorInt32( $x7->addInt32( $x6 )->rotateLeft( 13 ) );
119
+            $x5  = $x5->xorInt32( $x4->addInt32( $x7 )->rotateLeft( 18 ) );
120 120
 
121
-            $x11 = $x11->xorInt32($x10->addInt32($x9)->rotateLeft(7));
122
-            $x8  = $x8->xorInt32($x11->addInt32($x10)->rotateLeft(9));
123
-            $x9  = $x9->xorInt32($x8->addInt32($x11)->rotateLeft(13));
124
-            $x10 = $x10->xorInt32($x9->addInt32($x8)->rotateLeft(18));
121
+            $x11 = $x11->xorInt32( $x10->addInt32( $x9 )->rotateLeft( 7 ) );
122
+            $x8  = $x8->xorInt32( $x11->addInt32( $x10 )->rotateLeft( 9 ) );
123
+            $x9  = $x9->xorInt32( $x8->addInt32( $x11 )->rotateLeft( 13 ) );
124
+            $x10 = $x10->xorInt32( $x9->addInt32( $x8 )->rotateLeft( 18 ) );
125 125
 
126
-            $x12 = $x12->xorInt32($x15->addInt32($x14)->rotateLeft(7));
127
-            $x13 = $x13->xorInt32($x12->addInt32($x15)->rotateLeft(9));
128
-            $x14 = $x14->xorInt32($x13->addInt32($x12)->rotateLeft(13));
129
-            $x15 = $x15->xorInt32($x14->addInt32($x13)->rotateLeft(18));
126
+            $x12 = $x12->xorInt32( $x15->addInt32( $x14 )->rotateLeft( 7 ) );
127
+            $x13 = $x13->xorInt32( $x12->addInt32( $x15 )->rotateLeft( 9 ) );
128
+            $x14 = $x14->xorInt32( $x13->addInt32( $x12 )->rotateLeft( 13 ) );
129
+            $x15 = $x15->xorInt32( $x14->addInt32( $x13 )->rotateLeft( 18 ) );
130 130
         }
131 131
 
132 132
         return $x0->toReverseString() .
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 /**
8 8
  * Class ParagonIE_Sodium_Core32_HSalsa20
9 9
  */
10
-abstract class ParagonIE_Sodium_Core32_HSalsa20 extends ParagonIE_Sodium_Core32_Salsa20
11
-{
10
+abstract class ParagonIE_Sodium_Core32_HSalsa20 extends ParagonIE_Sodium_Core32_Salsa20 {
12 11
     /**
13 12
      * Calculate an hsalsa20 hash of a single block
14 13
      *
@@ -24,8 +23,7 @@  discard block
 block discarded – undo
24 23
      * @throws SodiumException
25 24
      * @throws TypeError
26 25
      */
27
-    public static function hsalsa20($in, $k, $c = null)
28
-    {
26
+    public static function hsalsa20($in, $k, $c = null) {
29 27
         /**
30 28
          * @var ParagonIE_Sodium_Core32_Int32 $x0
31 29
          * @var ParagonIE_Sodium_Core32_Int32 $x1
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/Poly1305/State.php 3 patches
Indentation   +440 added lines, -440 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (class_exists('ParagonIE_Sodium_Core32_Poly1305_State', false)) {
4
-    return;
4
+	return;
5 5
 }
6 6
 
7 7
 /**
@@ -9,443 +9,443 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class ParagonIE_Sodium_Core32_Poly1305_State extends ParagonIE_Sodium_Core32_Util
11 11
 {
12
-    /**
13
-     * @var array<int, int>
14
-     */
15
-    protected $buffer = array();
16
-
17
-    /**
18
-     * @var bool
19
-     */
20
-    protected $final = false;
21
-
22
-    /**
23
-     * @var array<int, ParagonIE_Sodium_Core32_Int32>
24
-     */
25
-    public $h;
26
-
27
-    /**
28
-     * @var int
29
-     */
30
-    protected $leftover = 0;
31
-
32
-    /**
33
-     * @var array<int, ParagonIE_Sodium_Core32_Int32>
34
-     */
35
-    public $r;
36
-
37
-    /**
38
-     * @var array<int, ParagonIE_Sodium_Core32_Int64>
39
-     */
40
-    public $pad;
41
-
42
-    /**
43
-     * ParagonIE_Sodium_Core32_Poly1305_State constructor.
44
-     *
45
-     * @internal You should not use this directly from another application
46
-     *
47
-     * @param string $key
48
-     * @throws InvalidArgumentException
49
-     * @throws SodiumException
50
-     * @throws TypeError
51
-     */
52
-    public function __construct($key = '')
53
-    {
54
-        if (self::strlen($key) < 32) {
55
-            throw new InvalidArgumentException(
56
-                'Poly1305 requires a 32-byte key'
57
-            );
58
-        }
59
-        /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
60
-        $this->r = array(
61
-            // st->r[0] = ...
62
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4))
63
-                ->setUnsignedInt(true)
64
-                ->mask(0x3ffffff),
65
-            // st->r[1] = ...
66
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 3, 4))
67
-                ->setUnsignedInt(true)
68
-                ->shiftRight(2)
69
-                ->mask(0x3ffff03),
70
-            // st->r[2] = ...
71
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 6, 4))
72
-                ->setUnsignedInt(true)
73
-                ->shiftRight(4)
74
-                ->mask(0x3ffc0ff),
75
-            // st->r[3] = ...
76
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 9, 4))
77
-                ->setUnsignedInt(true)
78
-                ->shiftRight(6)
79
-                ->mask(0x3f03fff),
80
-            // st->r[4] = ...
81
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4))
82
-                ->setUnsignedInt(true)
83
-                ->shiftRight(8)
84
-                ->mask(0x00fffff)
85
-        );
86
-
87
-        /* h = 0 */
88
-        $this->h = array(
89
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
90
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
91
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
92
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
93
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true)
94
-        );
95
-
96
-        /* save pad for later */
97
-        $this->pad = array(
98
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4))
99
-                ->setUnsignedInt(true)->toInt64(),
100
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4))
101
-                ->setUnsignedInt(true)->toInt64(),
102
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4))
103
-                ->setUnsignedInt(true)->toInt64(),
104
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4))
105
-                ->setUnsignedInt(true)->toInt64(),
106
-        );
107
-
108
-        $this->leftover = 0;
109
-        $this->final = false;
110
-    }
111
-
112
-    /**
113
-     * @internal You should not use this directly from another application
114
-     *
115
-     * @param string $message
116
-     * @return self
117
-     * @throws SodiumException
118
-     * @throws TypeError
119
-     */
120
-    public function update($message = '')
121
-    {
122
-        $bytes = self::strlen($message);
123
-
124
-        /* handle leftover */
125
-        if ($this->leftover) {
126
-            /** @var int $want */
127
-            $want = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - $this->leftover;
128
-            if ($want > $bytes) {
129
-                $want = $bytes;
130
-            }
131
-            for ($i = 0; $i < $want; ++$i) {
132
-                $mi = self::chrToInt($message[$i]);
133
-                $this->buffer[$this->leftover + $i] = $mi;
134
-            }
135
-            // We snip off the leftmost bytes.
136
-            $message = self::substr($message, $want);
137
-            $bytes = self::strlen($message);
138
-            $this->leftover += $want;
139
-            if ($this->leftover < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
140
-                // We still don't have enough to run $this->blocks()
141
-                return $this;
142
-            }
143
-
144
-            $this->blocks(
145
-                self::intArrayToString($this->buffer),
146
-                ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
147
-            );
148
-            $this->leftover = 0;
149
-        }
150
-
151
-        /* process full blocks */
152
-        if ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
153
-            /** @var int $want */
154
-            $want = $bytes & ~(ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1);
155
-            if ($want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
156
-                /** @var string $block */
157
-                $block = self::substr($message, 0, $want);
158
-                if (self::strlen($block) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
159
-                    $this->blocks($block, $want);
160
-                    $message = self::substr($message, $want);
161
-                    $bytes = self::strlen($message);
162
-                }
163
-            }
164
-        }
165
-
166
-        /* store leftover */
167
-        if ($bytes) {
168
-            for ($i = 0; $i < $bytes; ++$i) {
169
-                $mi = self::chrToInt($message[$i]);
170
-                $this->buffer[$this->leftover + $i] = $mi;
171
-            }
172
-            $this->leftover = (int) $this->leftover + $bytes;
173
-        }
174
-        return $this;
175
-    }
176
-
177
-    /**
178
-     * @internal You should not use this directly from another application
179
-     *
180
-     * @param string $message
181
-     * @param int $bytes
182
-     * @return self
183
-     * @throws SodiumException
184
-     * @throws TypeError
185
-     */
186
-    public function blocks($message, $bytes)
187
-    {
188
-        if (self::strlen($message) < 16) {
189
-            $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT);
190
-        }
191
-        $hibit = ParagonIE_Sodium_Core32_Int32::fromInt((int) ($this->final ? 0 : 1 << 24)); /* 1 << 128 */
192
-        $hibit->setUnsignedInt(true);
193
-        $zero = new ParagonIE_Sodium_Core32_Int64(array(0, 0, 0, 0), true);
194
-        /**
195
-         * @var ParagonIE_Sodium_Core32_Int64 $d0
196
-         * @var ParagonIE_Sodium_Core32_Int64 $d1
197
-         * @var ParagonIE_Sodium_Core32_Int64 $d2
198
-         * @var ParagonIE_Sodium_Core32_Int64 $d3
199
-         * @var ParagonIE_Sodium_Core32_Int64 $d4
200
-         * @var ParagonIE_Sodium_Core32_Int64 $r0
201
-         * @var ParagonIE_Sodium_Core32_Int64 $r1
202
-         * @var ParagonIE_Sodium_Core32_Int64 $r2
203
-         * @var ParagonIE_Sodium_Core32_Int64 $r3
204
-         * @var ParagonIE_Sodium_Core32_Int64 $r4
205
-         *
206
-         * @var ParagonIE_Sodium_Core32_Int32 $h0
207
-         * @var ParagonIE_Sodium_Core32_Int32 $h1
208
-         * @var ParagonIE_Sodium_Core32_Int32 $h2
209
-         * @var ParagonIE_Sodium_Core32_Int32 $h3
210
-         * @var ParagonIE_Sodium_Core32_Int32 $h4
211
-         */
212
-        $r0 = $this->r[0]->toInt64();
213
-        $r1 = $this->r[1]->toInt64();
214
-        $r2 = $this->r[2]->toInt64();
215
-        $r3 = $this->r[3]->toInt64();
216
-        $r4 = $this->r[4]->toInt64();
217
-
218
-        $s1 = $r1->toInt64()->mulInt(5, 3);
219
-        $s2 = $r2->toInt64()->mulInt(5, 3);
220
-        $s3 = $r3->toInt64()->mulInt(5, 3);
221
-        $s4 = $r4->toInt64()->mulInt(5, 3);
222
-
223
-        $h0 = $this->h[0];
224
-        $h1 = $this->h[1];
225
-        $h2 = $this->h[2];
226
-        $h3 = $this->h[3];
227
-        $h4 = $this->h[4];
228
-
229
-        while ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
230
-            /* h += m[i] */
231
-            $h0 = $h0->addInt32(
232
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 0, 4))
233
-                    ->mask(0x3ffffff)
234
-            )->toInt64();
235
-            $h1 = $h1->addInt32(
236
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 3, 4))
237
-                    ->shiftRight(2)
238
-                    ->mask(0x3ffffff)
239
-            )->toInt64();
240
-            $h2 = $h2->addInt32(
241
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 6, 4))
242
-                    ->shiftRight(4)
243
-                    ->mask(0x3ffffff)
244
-            )->toInt64();
245
-            $h3 = $h3->addInt32(
246
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 9, 4))
247
-                    ->shiftRight(6)
248
-                    ->mask(0x3ffffff)
249
-            )->toInt64();
250
-            $h4 = $h4->addInt32(
251
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4))
252
-                    ->shiftRight(8)
253
-                    ->orInt32($hibit)
254
-            )->toInt64();
255
-
256
-            /* h *= r */
257
-            $d0 = $zero
258
-                ->addInt64($h0->mulInt64($r0, 25))
259
-                ->addInt64($s4->mulInt64($h1, 26))
260
-                ->addInt64($s3->mulInt64($h2, 26))
261
-                ->addInt64($s2->mulInt64($h3, 26))
262
-                ->addInt64($s1->mulInt64($h4, 26));
263
-
264
-            $d1 = $zero
265
-                ->addInt64($h0->mulInt64($r1, 25))
266
-                ->addInt64($h1->mulInt64($r0, 25))
267
-                ->addInt64($s4->mulInt64($h2, 26))
268
-                ->addInt64($s3->mulInt64($h3, 26))
269
-                ->addInt64($s2->mulInt64($h4, 26));
270
-
271
-            $d2 = $zero
272
-                ->addInt64($h0->mulInt64($r2, 25))
273
-                ->addInt64($h1->mulInt64($r1, 25))
274
-                ->addInt64($h2->mulInt64($r0, 25))
275
-                ->addInt64($s4->mulInt64($h3, 26))
276
-                ->addInt64($s3->mulInt64($h4, 26));
277
-
278
-            $d3 = $zero
279
-                ->addInt64($h0->mulInt64($r3, 25))
280
-                ->addInt64($h1->mulInt64($r2, 25))
281
-                ->addInt64($h2->mulInt64($r1, 25))
282
-                ->addInt64($h3->mulInt64($r0, 25))
283
-                ->addInt64($s4->mulInt64($h4, 26));
284
-
285
-            $d4 = $zero
286
-                ->addInt64($h0->mulInt64($r4, 25))
287
-                ->addInt64($h1->mulInt64($r3, 25))
288
-                ->addInt64($h2->mulInt64($r2, 25))
289
-                ->addInt64($h3->mulInt64($r1, 25))
290
-                ->addInt64($h4->mulInt64($r0, 25));
291
-
292
-            /* (partial) h %= p */
293
-            $c = $d0->shiftRight(26);
294
-            $h0 = $d0->toInt32()->mask(0x3ffffff);
295
-            $d1 = $d1->addInt64($c);
296
-
297
-            $c = $d1->shiftRight(26);
298
-            $h1 = $d1->toInt32()->mask(0x3ffffff);
299
-            $d2 = $d2->addInt64($c);
300
-
301
-            $c = $d2->shiftRight(26);
302
-            $h2 = $d2->toInt32()->mask(0x3ffffff);
303
-            $d3 = $d3->addInt64($c);
304
-
305
-            $c = $d3->shiftRight(26);
306
-            $h3 = $d3->toInt32()->mask(0x3ffffff);
307
-            $d4 = $d4->addInt64($c);
308
-
309
-            $c = $d4->shiftRight(26);
310
-            $h4 = $d4->toInt32()->mask(0x3ffffff);
311
-            $h0 = $h0->addInt32($c->toInt32()->mulInt(5, 3));
312
-
313
-            $c = $h0->shiftRight(26);
314
-            $h0 = $h0->mask(0x3ffffff);
315
-            $h1 = $h1->addInt32($c);
316
-
317
-            // Chop off the left 32 bytes.
318
-            $message = self::substr(
319
-                $message,
320
-                ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
321
-            );
322
-            $bytes -= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE;
323
-        }
324
-
325
-        /** @var array<int, ParagonIE_Sodium_Core32_Int32> $h */
326
-        $this->h = array($h0, $h1, $h2, $h3, $h4);
327
-        return $this;
328
-    }
329
-
330
-    /**
331
-     * @internal You should not use this directly from another application
332
-     *
333
-     * @return string
334
-     * @throws SodiumException
335
-     * @throws TypeError
336
-     */
337
-    public function finish()
338
-    {
339
-        /* process the remaining block */
340
-        if ($this->leftover) {
341
-            $i = $this->leftover;
342
-            $this->buffer[$i++] = 1;
343
-            for (; $i < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE; ++$i) {
344
-                $this->buffer[$i] = 0;
345
-            }
346
-            $this->final = true;
347
-            $this->blocks(
348
-                self::substr(
349
-                    self::intArrayToString($this->buffer),
350
-                    0,
351
-                    ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
352
-                ),
353
-                $b = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
354
-            );
355
-        }
356
-
357
-        /**
358
-         * @var ParagonIE_Sodium_Core32_Int32 $f
359
-         * @var ParagonIE_Sodium_Core32_Int32 $g0
360
-         * @var ParagonIE_Sodium_Core32_Int32 $g1
361
-         * @var ParagonIE_Sodium_Core32_Int32 $g2
362
-         * @var ParagonIE_Sodium_Core32_Int32 $g3
363
-         * @var ParagonIE_Sodium_Core32_Int32 $g4
364
-         * @var ParagonIE_Sodium_Core32_Int32 $h0
365
-         * @var ParagonIE_Sodium_Core32_Int32 $h1
366
-         * @var ParagonIE_Sodium_Core32_Int32 $h2
367
-         * @var ParagonIE_Sodium_Core32_Int32 $h3
368
-         * @var ParagonIE_Sodium_Core32_Int32 $h4
369
-         */
370
-        $h0 = $this->h[0];
371
-        $h1 = $this->h[1];
372
-        $h2 = $this->h[2];
373
-        $h3 = $this->h[3];
374
-        $h4 = $this->h[4];
375
-
376
-        $c = $h1->shiftRight(26);           # $c = $h1 >> 26;
377
-        $h1 = $h1->mask(0x3ffffff);         # $h1 &= 0x3ffffff;
378
-
379
-        $h2 = $h2->addInt32($c);            # $h2 += $c;
380
-        $c = $h2->shiftRight(26);           # $c = $h2 >> 26;
381
-        $h2 = $h2->mask(0x3ffffff);         # $h2 &= 0x3ffffff;
382
-
383
-        $h3 = $h3->addInt32($c);            # $h3 += $c;
384
-        $c = $h3->shiftRight(26);           # $c = $h3 >> 26;
385
-        $h3 = $h3->mask(0x3ffffff);         # $h3 &= 0x3ffffff;
386
-
387
-        $h4 = $h4->addInt32($c);            # $h4 += $c;
388
-        $c = $h4->shiftRight(26);           # $c = $h4 >> 26;
389
-        $h4 = $h4->mask(0x3ffffff);         # $h4 &= 0x3ffffff;
390
-
391
-        $h0 = $h0->addInt32($c->mulInt(5, 3)); # $h0 += self::mul($c, 5);
392
-        $c = $h0->shiftRight(26);           # $c = $h0 >> 26;
393
-        $h0 = $h0->mask(0x3ffffff);         # $h0 &= 0x3ffffff;
394
-        $h1 = $h1->addInt32($c);            # $h1 += $c;
395
-
396
-        /* compute h + -p */
397
-        $g0 = $h0->addInt(5);
398
-        $c  = $g0->shiftRight(26);
399
-        $g0 = $g0->mask(0x3ffffff);
400
-        $g1 = $h1->addInt32($c);
401
-        $c  = $g1->shiftRight(26);
402
-        $g1 = $g1->mask(0x3ffffff);
403
-        $g2 = $h2->addInt32($c);
404
-        $c  = $g2->shiftRight(26);
405
-        $g2 = $g2->mask(0x3ffffff);
406
-        $g3 = $h3->addInt32($c);
407
-        $c  = $g3->shiftRight(26);
408
-        $g3 = $g3->mask(0x3ffffff);
409
-        $g4 = $h4->addInt32($c)->subInt(1 << 26);
410
-
411
-        # $mask = ($g4 >> 31) - 1;
412
-        /* select h if h < p, or h + -p if h >= p */
413
-        $mask = (int) (($g4->toInt() >> 31) + 1);
414
-
415
-        $g0 = $g0->mask($mask);
416
-        $g1 = $g1->mask($mask);
417
-        $g2 = $g2->mask($mask);
418
-        $g3 = $g3->mask($mask);
419
-        $g4 = $g4->mask($mask);
420
-
421
-        /** @var int $mask */
422
-        $mask = (~$mask) & 0xffffffff;
423
-
424
-        $h0 = $h0->mask($mask)->orInt32($g0);
425
-        $h1 = $h1->mask($mask)->orInt32($g1);
426
-        $h2 = $h2->mask($mask)->orInt32($g2);
427
-        $h3 = $h3->mask($mask)->orInt32($g3);
428
-        $h4 = $h4->mask($mask)->orInt32($g4);
429
-
430
-        /* h = h % (2^128) */
431
-        $h0 = $h0->orInt32($h1->shiftLeft(26));
432
-        $h1 = $h1->shiftRight(6)->orInt32($h2->shiftLeft(20));
433
-        $h2 = $h2->shiftRight(12)->orInt32($h3->shiftLeft(14));
434
-        $h3 = $h3->shiftRight(18)->orInt32($h4->shiftLeft(8));
435
-
436
-        /* mac = (h + pad) % (2^128) */
437
-        $f = $h0->toInt64()->addInt64($this->pad[0]);
438
-        $h0 = $f->toInt32();
439
-        $f = $h1->toInt64()->addInt64($this->pad[1])->addInt($h0->overflow);
440
-        $h1 = $f->toInt32();
441
-        $f = $h2->toInt64()->addInt64($this->pad[2])->addInt($h1->overflow);
442
-        $h2 = $f->toInt32();
443
-        $f = $h3->toInt64()->addInt64($this->pad[3])->addInt($h2->overflow);
444
-        $h3 = $f->toInt32();
445
-
446
-        return $h0->toReverseString() .
447
-            $h1->toReverseString() .
448
-            $h2->toReverseString() .
449
-            $h3->toReverseString();
450
-    }
12
+	/**
13
+	 * @var array<int, int>
14
+	 */
15
+	protected $buffer = array();
16
+
17
+	/**
18
+	 * @var bool
19
+	 */
20
+	protected $final = false;
21
+
22
+	/**
23
+	 * @var array<int, ParagonIE_Sodium_Core32_Int32>
24
+	 */
25
+	public $h;
26
+
27
+	/**
28
+	 * @var int
29
+	 */
30
+	protected $leftover = 0;
31
+
32
+	/**
33
+	 * @var array<int, ParagonIE_Sodium_Core32_Int32>
34
+	 */
35
+	public $r;
36
+
37
+	/**
38
+	 * @var array<int, ParagonIE_Sodium_Core32_Int64>
39
+	 */
40
+	public $pad;
41
+
42
+	/**
43
+	 * ParagonIE_Sodium_Core32_Poly1305_State constructor.
44
+	 *
45
+	 * @internal You should not use this directly from another application
46
+	 *
47
+	 * @param string $key
48
+	 * @throws InvalidArgumentException
49
+	 * @throws SodiumException
50
+	 * @throws TypeError
51
+	 */
52
+	public function __construct($key = '')
53
+	{
54
+		if (self::strlen($key) < 32) {
55
+			throw new InvalidArgumentException(
56
+				'Poly1305 requires a 32-byte key'
57
+			);
58
+		}
59
+		/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
60
+		$this->r = array(
61
+			// st->r[0] = ...
62
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4))
63
+				->setUnsignedInt(true)
64
+				->mask(0x3ffffff),
65
+			// st->r[1] = ...
66
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 3, 4))
67
+				->setUnsignedInt(true)
68
+				->shiftRight(2)
69
+				->mask(0x3ffff03),
70
+			// st->r[2] = ...
71
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 6, 4))
72
+				->setUnsignedInt(true)
73
+				->shiftRight(4)
74
+				->mask(0x3ffc0ff),
75
+			// st->r[3] = ...
76
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 9, 4))
77
+				->setUnsignedInt(true)
78
+				->shiftRight(6)
79
+				->mask(0x3f03fff),
80
+			// st->r[4] = ...
81
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4))
82
+				->setUnsignedInt(true)
83
+				->shiftRight(8)
84
+				->mask(0x00fffff)
85
+		);
86
+
87
+		/* h = 0 */
88
+		$this->h = array(
89
+			new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
90
+			new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
91
+			new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
92
+			new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
93
+			new ParagonIE_Sodium_Core32_Int32(array(0, 0), true)
94
+		);
95
+
96
+		/* save pad for later */
97
+		$this->pad = array(
98
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4))
99
+				->setUnsignedInt(true)->toInt64(),
100
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4))
101
+				->setUnsignedInt(true)->toInt64(),
102
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4))
103
+				->setUnsignedInt(true)->toInt64(),
104
+			ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4))
105
+				->setUnsignedInt(true)->toInt64(),
106
+		);
107
+
108
+		$this->leftover = 0;
109
+		$this->final = false;
110
+	}
111
+
112
+	/**
113
+	 * @internal You should not use this directly from another application
114
+	 *
115
+	 * @param string $message
116
+	 * @return self
117
+	 * @throws SodiumException
118
+	 * @throws TypeError
119
+	 */
120
+	public function update($message = '')
121
+	{
122
+		$bytes = self::strlen($message);
123
+
124
+		/* handle leftover */
125
+		if ($this->leftover) {
126
+			/** @var int $want */
127
+			$want = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - $this->leftover;
128
+			if ($want > $bytes) {
129
+				$want = $bytes;
130
+			}
131
+			for ($i = 0; $i < $want; ++$i) {
132
+				$mi = self::chrToInt($message[$i]);
133
+				$this->buffer[$this->leftover + $i] = $mi;
134
+			}
135
+			// We snip off the leftmost bytes.
136
+			$message = self::substr($message, $want);
137
+			$bytes = self::strlen($message);
138
+			$this->leftover += $want;
139
+			if ($this->leftover < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
140
+				// We still don't have enough to run $this->blocks()
141
+				return $this;
142
+			}
143
+
144
+			$this->blocks(
145
+				self::intArrayToString($this->buffer),
146
+				ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
147
+			);
148
+			$this->leftover = 0;
149
+		}
150
+
151
+		/* process full blocks */
152
+		if ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
153
+			/** @var int $want */
154
+			$want = $bytes & ~(ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1);
155
+			if ($want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
156
+				/** @var string $block */
157
+				$block = self::substr($message, 0, $want);
158
+				if (self::strlen($block) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
159
+					$this->blocks($block, $want);
160
+					$message = self::substr($message, $want);
161
+					$bytes = self::strlen($message);
162
+				}
163
+			}
164
+		}
165
+
166
+		/* store leftover */
167
+		if ($bytes) {
168
+			for ($i = 0; $i < $bytes; ++$i) {
169
+				$mi = self::chrToInt($message[$i]);
170
+				$this->buffer[$this->leftover + $i] = $mi;
171
+			}
172
+			$this->leftover = (int) $this->leftover + $bytes;
173
+		}
174
+		return $this;
175
+	}
176
+
177
+	/**
178
+	 * @internal You should not use this directly from another application
179
+	 *
180
+	 * @param string $message
181
+	 * @param int $bytes
182
+	 * @return self
183
+	 * @throws SodiumException
184
+	 * @throws TypeError
185
+	 */
186
+	public function blocks($message, $bytes)
187
+	{
188
+		if (self::strlen($message) < 16) {
189
+			$message = str_pad($message, 16, "\x00", STR_PAD_RIGHT);
190
+		}
191
+		$hibit = ParagonIE_Sodium_Core32_Int32::fromInt((int) ($this->final ? 0 : 1 << 24)); /* 1 << 128 */
192
+		$hibit->setUnsignedInt(true);
193
+		$zero = new ParagonIE_Sodium_Core32_Int64(array(0, 0, 0, 0), true);
194
+		/**
195
+		 * @var ParagonIE_Sodium_Core32_Int64 $d0
196
+		 * @var ParagonIE_Sodium_Core32_Int64 $d1
197
+		 * @var ParagonIE_Sodium_Core32_Int64 $d2
198
+		 * @var ParagonIE_Sodium_Core32_Int64 $d3
199
+		 * @var ParagonIE_Sodium_Core32_Int64 $d4
200
+		 * @var ParagonIE_Sodium_Core32_Int64 $r0
201
+		 * @var ParagonIE_Sodium_Core32_Int64 $r1
202
+		 * @var ParagonIE_Sodium_Core32_Int64 $r2
203
+		 * @var ParagonIE_Sodium_Core32_Int64 $r3
204
+		 * @var ParagonIE_Sodium_Core32_Int64 $r4
205
+		 *
206
+		 * @var ParagonIE_Sodium_Core32_Int32 $h0
207
+		 * @var ParagonIE_Sodium_Core32_Int32 $h1
208
+		 * @var ParagonIE_Sodium_Core32_Int32 $h2
209
+		 * @var ParagonIE_Sodium_Core32_Int32 $h3
210
+		 * @var ParagonIE_Sodium_Core32_Int32 $h4
211
+		 */
212
+		$r0 = $this->r[0]->toInt64();
213
+		$r1 = $this->r[1]->toInt64();
214
+		$r2 = $this->r[2]->toInt64();
215
+		$r3 = $this->r[3]->toInt64();
216
+		$r4 = $this->r[4]->toInt64();
217
+
218
+		$s1 = $r1->toInt64()->mulInt(5, 3);
219
+		$s2 = $r2->toInt64()->mulInt(5, 3);
220
+		$s3 = $r3->toInt64()->mulInt(5, 3);
221
+		$s4 = $r4->toInt64()->mulInt(5, 3);
222
+
223
+		$h0 = $this->h[0];
224
+		$h1 = $this->h[1];
225
+		$h2 = $this->h[2];
226
+		$h3 = $this->h[3];
227
+		$h4 = $this->h[4];
228
+
229
+		while ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
230
+			/* h += m[i] */
231
+			$h0 = $h0->addInt32(
232
+				ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 0, 4))
233
+					->mask(0x3ffffff)
234
+			)->toInt64();
235
+			$h1 = $h1->addInt32(
236
+				ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 3, 4))
237
+					->shiftRight(2)
238
+					->mask(0x3ffffff)
239
+			)->toInt64();
240
+			$h2 = $h2->addInt32(
241
+				ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 6, 4))
242
+					->shiftRight(4)
243
+					->mask(0x3ffffff)
244
+			)->toInt64();
245
+			$h3 = $h3->addInt32(
246
+				ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 9, 4))
247
+					->shiftRight(6)
248
+					->mask(0x3ffffff)
249
+			)->toInt64();
250
+			$h4 = $h4->addInt32(
251
+				ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4))
252
+					->shiftRight(8)
253
+					->orInt32($hibit)
254
+			)->toInt64();
255
+
256
+			/* h *= r */
257
+			$d0 = $zero
258
+				->addInt64($h0->mulInt64($r0, 25))
259
+				->addInt64($s4->mulInt64($h1, 26))
260
+				->addInt64($s3->mulInt64($h2, 26))
261
+				->addInt64($s2->mulInt64($h3, 26))
262
+				->addInt64($s1->mulInt64($h4, 26));
263
+
264
+			$d1 = $zero
265
+				->addInt64($h0->mulInt64($r1, 25))
266
+				->addInt64($h1->mulInt64($r0, 25))
267
+				->addInt64($s4->mulInt64($h2, 26))
268
+				->addInt64($s3->mulInt64($h3, 26))
269
+				->addInt64($s2->mulInt64($h4, 26));
270
+
271
+			$d2 = $zero
272
+				->addInt64($h0->mulInt64($r2, 25))
273
+				->addInt64($h1->mulInt64($r1, 25))
274
+				->addInt64($h2->mulInt64($r0, 25))
275
+				->addInt64($s4->mulInt64($h3, 26))
276
+				->addInt64($s3->mulInt64($h4, 26));
277
+
278
+			$d3 = $zero
279
+				->addInt64($h0->mulInt64($r3, 25))
280
+				->addInt64($h1->mulInt64($r2, 25))
281
+				->addInt64($h2->mulInt64($r1, 25))
282
+				->addInt64($h3->mulInt64($r0, 25))
283
+				->addInt64($s4->mulInt64($h4, 26));
284
+
285
+			$d4 = $zero
286
+				->addInt64($h0->mulInt64($r4, 25))
287
+				->addInt64($h1->mulInt64($r3, 25))
288
+				->addInt64($h2->mulInt64($r2, 25))
289
+				->addInt64($h3->mulInt64($r1, 25))
290
+				->addInt64($h4->mulInt64($r0, 25));
291
+
292
+			/* (partial) h %= p */
293
+			$c = $d0->shiftRight(26);
294
+			$h0 = $d0->toInt32()->mask(0x3ffffff);
295
+			$d1 = $d1->addInt64($c);
296
+
297
+			$c = $d1->shiftRight(26);
298
+			$h1 = $d1->toInt32()->mask(0x3ffffff);
299
+			$d2 = $d2->addInt64($c);
300
+
301
+			$c = $d2->shiftRight(26);
302
+			$h2 = $d2->toInt32()->mask(0x3ffffff);
303
+			$d3 = $d3->addInt64($c);
304
+
305
+			$c = $d3->shiftRight(26);
306
+			$h3 = $d3->toInt32()->mask(0x3ffffff);
307
+			$d4 = $d4->addInt64($c);
308
+
309
+			$c = $d4->shiftRight(26);
310
+			$h4 = $d4->toInt32()->mask(0x3ffffff);
311
+			$h0 = $h0->addInt32($c->toInt32()->mulInt(5, 3));
312
+
313
+			$c = $h0->shiftRight(26);
314
+			$h0 = $h0->mask(0x3ffffff);
315
+			$h1 = $h1->addInt32($c);
316
+
317
+			// Chop off the left 32 bytes.
318
+			$message = self::substr(
319
+				$message,
320
+				ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
321
+			);
322
+			$bytes -= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE;
323
+		}
324
+
325
+		/** @var array<int, ParagonIE_Sodium_Core32_Int32> $h */
326
+		$this->h = array($h0, $h1, $h2, $h3, $h4);
327
+		return $this;
328
+	}
329
+
330
+	/**
331
+	 * @internal You should not use this directly from another application
332
+	 *
333
+	 * @return string
334
+	 * @throws SodiumException
335
+	 * @throws TypeError
336
+	 */
337
+	public function finish()
338
+	{
339
+		/* process the remaining block */
340
+		if ($this->leftover) {
341
+			$i = $this->leftover;
342
+			$this->buffer[$i++] = 1;
343
+			for (; $i < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE; ++$i) {
344
+				$this->buffer[$i] = 0;
345
+			}
346
+			$this->final = true;
347
+			$this->blocks(
348
+				self::substr(
349
+					self::intArrayToString($this->buffer),
350
+					0,
351
+					ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
352
+				),
353
+				$b = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
354
+			);
355
+		}
356
+
357
+		/**
358
+		 * @var ParagonIE_Sodium_Core32_Int32 $f
359
+		 * @var ParagonIE_Sodium_Core32_Int32 $g0
360
+		 * @var ParagonIE_Sodium_Core32_Int32 $g1
361
+		 * @var ParagonIE_Sodium_Core32_Int32 $g2
362
+		 * @var ParagonIE_Sodium_Core32_Int32 $g3
363
+		 * @var ParagonIE_Sodium_Core32_Int32 $g4
364
+		 * @var ParagonIE_Sodium_Core32_Int32 $h0
365
+		 * @var ParagonIE_Sodium_Core32_Int32 $h1
366
+		 * @var ParagonIE_Sodium_Core32_Int32 $h2
367
+		 * @var ParagonIE_Sodium_Core32_Int32 $h3
368
+		 * @var ParagonIE_Sodium_Core32_Int32 $h4
369
+		 */
370
+		$h0 = $this->h[0];
371
+		$h1 = $this->h[1];
372
+		$h2 = $this->h[2];
373
+		$h3 = $this->h[3];
374
+		$h4 = $this->h[4];
375
+
376
+		$c = $h1->shiftRight(26);           # $c = $h1 >> 26;
377
+		$h1 = $h1->mask(0x3ffffff);         # $h1 &= 0x3ffffff;
378
+
379
+		$h2 = $h2->addInt32($c);            # $h2 += $c;
380
+		$c = $h2->shiftRight(26);           # $c = $h2 >> 26;
381
+		$h2 = $h2->mask(0x3ffffff);         # $h2 &= 0x3ffffff;
382
+
383
+		$h3 = $h3->addInt32($c);            # $h3 += $c;
384
+		$c = $h3->shiftRight(26);           # $c = $h3 >> 26;
385
+		$h3 = $h3->mask(0x3ffffff);         # $h3 &= 0x3ffffff;
386
+
387
+		$h4 = $h4->addInt32($c);            # $h4 += $c;
388
+		$c = $h4->shiftRight(26);           # $c = $h4 >> 26;
389
+		$h4 = $h4->mask(0x3ffffff);         # $h4 &= 0x3ffffff;
390
+
391
+		$h0 = $h0->addInt32($c->mulInt(5, 3)); # $h0 += self::mul($c, 5);
392
+		$c = $h0->shiftRight(26);           # $c = $h0 >> 26;
393
+		$h0 = $h0->mask(0x3ffffff);         # $h0 &= 0x3ffffff;
394
+		$h1 = $h1->addInt32($c);            # $h1 += $c;
395
+
396
+		/* compute h + -p */
397
+		$g0 = $h0->addInt(5);
398
+		$c  = $g0->shiftRight(26);
399
+		$g0 = $g0->mask(0x3ffffff);
400
+		$g1 = $h1->addInt32($c);
401
+		$c  = $g1->shiftRight(26);
402
+		$g1 = $g1->mask(0x3ffffff);
403
+		$g2 = $h2->addInt32($c);
404
+		$c  = $g2->shiftRight(26);
405
+		$g2 = $g2->mask(0x3ffffff);
406
+		$g3 = $h3->addInt32($c);
407
+		$c  = $g3->shiftRight(26);
408
+		$g3 = $g3->mask(0x3ffffff);
409
+		$g4 = $h4->addInt32($c)->subInt(1 << 26);
410
+
411
+		# $mask = ($g4 >> 31) - 1;
412
+		/* select h if h < p, or h + -p if h >= p */
413
+		$mask = (int) (($g4->toInt() >> 31) + 1);
414
+
415
+		$g0 = $g0->mask($mask);
416
+		$g1 = $g1->mask($mask);
417
+		$g2 = $g2->mask($mask);
418
+		$g3 = $g3->mask($mask);
419
+		$g4 = $g4->mask($mask);
420
+
421
+		/** @var int $mask */
422
+		$mask = (~$mask) & 0xffffffff;
423
+
424
+		$h0 = $h0->mask($mask)->orInt32($g0);
425
+		$h1 = $h1->mask($mask)->orInt32($g1);
426
+		$h2 = $h2->mask($mask)->orInt32($g2);
427
+		$h3 = $h3->mask($mask)->orInt32($g3);
428
+		$h4 = $h4->mask($mask)->orInt32($g4);
429
+
430
+		/* h = h % (2^128) */
431
+		$h0 = $h0->orInt32($h1->shiftLeft(26));
432
+		$h1 = $h1->shiftRight(6)->orInt32($h2->shiftLeft(20));
433
+		$h2 = $h2->shiftRight(12)->orInt32($h3->shiftLeft(14));
434
+		$h3 = $h3->shiftRight(18)->orInt32($h4->shiftLeft(8));
435
+
436
+		/* mac = (h + pad) % (2^128) */
437
+		$f = $h0->toInt64()->addInt64($this->pad[0]);
438
+		$h0 = $f->toInt32();
439
+		$f = $h1->toInt64()->addInt64($this->pad[1])->addInt($h0->overflow);
440
+		$h1 = $f->toInt32();
441
+		$f = $h2->toInt64()->addInt64($this->pad[2])->addInt($h1->overflow);
442
+		$h2 = $f->toInt32();
443
+		$f = $h3->toInt64()->addInt64($this->pad[3])->addInt($h2->overflow);
444
+		$h3 = $f->toInt32();
445
+
446
+		return $h0->toReverseString() .
447
+			$h1->toReverseString() .
448
+			$h2->toReverseString() .
449
+			$h3->toReverseString();
450
+	}
451 451
 }
Please login to merge, or discard this patch.
Spacing   +199 added lines, -199 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
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
      * @throws SodiumException
50 50
      * @throws TypeError
51 51
      */
52
-    public function __construct($key = '')
52
+    public function __construct( $key = '' )
53 53
     {
54
-        if (self::strlen($key) < 32) {
54
+        if ( self::strlen( $key ) < 32 ) {
55 55
             throw new InvalidArgumentException(
56 56
                 'Poly1305 requires a 32-byte key'
57 57
             );
@@ -59,50 +59,50 @@  discard block
 block discarded – undo
59 59
         /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
60 60
         $this->r = array(
61 61
             // st->r[0] = ...
62
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4))
63
-                ->setUnsignedInt(true)
64
-                ->mask(0x3ffffff),
62
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 0, 4 ) )
63
+                ->setUnsignedInt( true )
64
+                ->mask( 0x3ffffff ),
65 65
             // st->r[1] = ...
66
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 3, 4))
67
-                ->setUnsignedInt(true)
68
-                ->shiftRight(2)
69
-                ->mask(0x3ffff03),
66
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 3, 4 ) )
67
+                ->setUnsignedInt( true )
68
+                ->shiftRight( 2 )
69
+                ->mask( 0x3ffff03 ),
70 70
             // st->r[2] = ...
71
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 6, 4))
72
-                ->setUnsignedInt(true)
73
-                ->shiftRight(4)
74
-                ->mask(0x3ffc0ff),
71
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 6, 4 ) )
72
+                ->setUnsignedInt( true )
73
+                ->shiftRight( 4 )
74
+                ->mask( 0x3ffc0ff ),
75 75
             // st->r[3] = ...
76
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 9, 4))
77
-                ->setUnsignedInt(true)
78
-                ->shiftRight(6)
79
-                ->mask(0x3f03fff),
76
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 9, 4 ) )
77
+                ->setUnsignedInt( true )
78
+                ->shiftRight( 6 )
79
+                ->mask( 0x3f03fff ),
80 80
             // st->r[4] = ...
81
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4))
82
-                ->setUnsignedInt(true)
83
-                ->shiftRight(8)
84
-                ->mask(0x00fffff)
81
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 12, 4 ) )
82
+                ->setUnsignedInt( true )
83
+                ->shiftRight( 8 )
84
+                ->mask( 0x00fffff )
85 85
         );
86 86
 
87 87
         /* h = 0 */
88 88
         $this->h = array(
89
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
90
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
91
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
92
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true),
93
-            new ParagonIE_Sodium_Core32_Int32(array(0, 0), true)
89
+            new ParagonIE_Sodium_Core32_Int32( array( 0, 0 ), true ),
90
+            new ParagonIE_Sodium_Core32_Int32( array( 0, 0 ), true ),
91
+            new ParagonIE_Sodium_Core32_Int32( array( 0, 0 ), true ),
92
+            new ParagonIE_Sodium_Core32_Int32( array( 0, 0 ), true ),
93
+            new ParagonIE_Sodium_Core32_Int32( array( 0, 0 ), true )
94 94
         );
95 95
 
96 96
         /* save pad for later */
97 97
         $this->pad = array(
98
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4))
99
-                ->setUnsignedInt(true)->toInt64(),
100
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4))
101
-                ->setUnsignedInt(true)->toInt64(),
102
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4))
103
-                ->setUnsignedInt(true)->toInt64(),
104
-            ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4))
105
-                ->setUnsignedInt(true)->toInt64(),
98
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 16, 4 ) )
99
+                ->setUnsignedInt( true )->toInt64(),
100
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 20, 4 ) )
101
+                ->setUnsignedInt( true )->toInt64(),
102
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 24, 4 ) )
103
+                ->setUnsignedInt( true )->toInt64(),
104
+            ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $key, 28, 4 ) )
105
+                ->setUnsignedInt( true )->toInt64(),
106 106
         );
107 107
 
108 108
         $this->leftover = 0;
@@ -117,59 +117,59 @@  discard block
 block discarded – undo
117 117
      * @throws SodiumException
118 118
      * @throws TypeError
119 119
      */
120
-    public function update($message = '')
120
+    public function update( $message = '' )
121 121
     {
122
-        $bytes = self::strlen($message);
122
+        $bytes = self::strlen( $message );
123 123
 
124 124
         /* handle leftover */
125
-        if ($this->leftover) {
125
+        if ( $this->leftover ) {
126 126
             /** @var int $want */
127 127
             $want = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - $this->leftover;
128
-            if ($want > $bytes) {
128
+            if ( $want > $bytes ) {
129 129
                 $want = $bytes;
130 130
             }
131
-            for ($i = 0; $i < $want; ++$i) {
132
-                $mi = self::chrToInt($message[$i]);
133
-                $this->buffer[$this->leftover + $i] = $mi;
131
+            for ( $i = 0; $i < $want; ++$i ) {
132
+                $mi = self::chrToInt( $message[ $i ] );
133
+                $this->buffer[ $this->leftover + $i ] = $mi;
134 134
             }
135 135
             // We snip off the leftmost bytes.
136
-            $message = self::substr($message, $want);
137
-            $bytes = self::strlen($message);
136
+            $message = self::substr( $message, $want );
137
+            $bytes = self::strlen( $message );
138 138
             $this->leftover += $want;
139
-            if ($this->leftover < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
139
+            if ( $this->leftover < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
140 140
                 // We still don't have enough to run $this->blocks()
141 141
                 return $this;
142 142
             }
143 143
 
144 144
             $this->blocks(
145
-                self::intArrayToString($this->buffer),
145
+                self::intArrayToString( $this->buffer ),
146 146
                 ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
147 147
             );
148 148
             $this->leftover = 0;
149 149
         }
150 150
 
151 151
         /* process full blocks */
152
-        if ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
152
+        if ( $bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
153 153
             /** @var int $want */
154
-            $want = $bytes & ~(ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1);
155
-            if ($want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
154
+            $want = $bytes & ~( ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1 );
155
+            if ( $want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
156 156
                 /** @var string $block */
157
-                $block = self::substr($message, 0, $want);
158
-                if (self::strlen($block) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
159
-                    $this->blocks($block, $want);
160
-                    $message = self::substr($message, $want);
161
-                    $bytes = self::strlen($message);
157
+                $block = self::substr( $message, 0, $want );
158
+                if ( self::strlen( $block ) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
159
+                    $this->blocks( $block, $want );
160
+                    $message = self::substr( $message, $want );
161
+                    $bytes = self::strlen( $message );
162 162
                 }
163 163
             }
164 164
         }
165 165
 
166 166
         /* store leftover */
167
-        if ($bytes) {
168
-            for ($i = 0; $i < $bytes; ++$i) {
169
-                $mi = self::chrToInt($message[$i]);
170
-                $this->buffer[$this->leftover + $i] = $mi;
167
+        if ( $bytes ) {
168
+            for ( $i = 0; $i < $bytes; ++$i ) {
169
+                $mi = self::chrToInt( $message[ $i ] );
170
+                $this->buffer[ $this->leftover + $i ] = $mi;
171 171
             }
172
-            $this->leftover = (int) $this->leftover + $bytes;
172
+            $this->leftover = (int)$this->leftover + $bytes;
173 173
         }
174 174
         return $this;
175 175
     }
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
      * @throws SodiumException
184 184
      * @throws TypeError
185 185
      */
186
-    public function blocks($message, $bytes)
186
+    public function blocks( $message, $bytes )
187 187
     {
188
-        if (self::strlen($message) < 16) {
189
-            $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT);
188
+        if ( self::strlen( $message ) < 16 ) {
189
+            $message = str_pad( $message, 16, "\x00", STR_PAD_RIGHT );
190 190
         }
191
-        $hibit = ParagonIE_Sodium_Core32_Int32::fromInt((int) ($this->final ? 0 : 1 << 24)); /* 1 << 128 */
192
-        $hibit->setUnsignedInt(true);
193
-        $zero = new ParagonIE_Sodium_Core32_Int64(array(0, 0, 0, 0), true);
191
+        $hibit = ParagonIE_Sodium_Core32_Int32::fromInt( (int)( $this->final ? 0 : 1 << 24 ) ); /* 1 << 128 */
192
+        $hibit->setUnsignedInt( true );
193
+        $zero = new ParagonIE_Sodium_Core32_Int64( array( 0, 0, 0, 0 ), true );
194 194
         /**
195 195
          * @var ParagonIE_Sodium_Core32_Int64 $d0
196 196
          * @var ParagonIE_Sodium_Core32_Int64 $d1
@@ -209,110 +209,110 @@  discard block
 block discarded – undo
209 209
          * @var ParagonIE_Sodium_Core32_Int32 $h3
210 210
          * @var ParagonIE_Sodium_Core32_Int32 $h4
211 211
          */
212
-        $r0 = $this->r[0]->toInt64();
213
-        $r1 = $this->r[1]->toInt64();
214
-        $r2 = $this->r[2]->toInt64();
215
-        $r3 = $this->r[3]->toInt64();
216
-        $r4 = $this->r[4]->toInt64();
217
-
218
-        $s1 = $r1->toInt64()->mulInt(5, 3);
219
-        $s2 = $r2->toInt64()->mulInt(5, 3);
220
-        $s3 = $r3->toInt64()->mulInt(5, 3);
221
-        $s4 = $r4->toInt64()->mulInt(5, 3);
222
-
223
-        $h0 = $this->h[0];
224
-        $h1 = $this->h[1];
225
-        $h2 = $this->h[2];
226
-        $h3 = $this->h[3];
227
-        $h4 = $this->h[4];
228
-
229
-        while ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
212
+        $r0 = $this->r[ 0 ]->toInt64();
213
+        $r1 = $this->r[ 1 ]->toInt64();
214
+        $r2 = $this->r[ 2 ]->toInt64();
215
+        $r3 = $this->r[ 3 ]->toInt64();
216
+        $r4 = $this->r[ 4 ]->toInt64();
217
+
218
+        $s1 = $r1->toInt64()->mulInt( 5, 3 );
219
+        $s2 = $r2->toInt64()->mulInt( 5, 3 );
220
+        $s3 = $r3->toInt64()->mulInt( 5, 3 );
221
+        $s4 = $r4->toInt64()->mulInt( 5, 3 );
222
+
223
+        $h0 = $this->h[ 0 ];
224
+        $h1 = $this->h[ 1 ];
225
+        $h2 = $this->h[ 2 ];
226
+        $h3 = $this->h[ 3 ];
227
+        $h4 = $this->h[ 4 ];
228
+
229
+        while ( $bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE ) {
230 230
             /* h += m[i] */
231 231
             $h0 = $h0->addInt32(
232
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 0, 4))
233
-                    ->mask(0x3ffffff)
232
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 0, 4 ) )
233
+                    ->mask( 0x3ffffff )
234 234
             )->toInt64();
235 235
             $h1 = $h1->addInt32(
236
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 3, 4))
237
-                    ->shiftRight(2)
238
-                    ->mask(0x3ffffff)
236
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 3, 4 ) )
237
+                    ->shiftRight( 2 )
238
+                    ->mask( 0x3ffffff )
239 239
             )->toInt64();
240 240
             $h2 = $h2->addInt32(
241
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 6, 4))
242
-                    ->shiftRight(4)
243
-                    ->mask(0x3ffffff)
241
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 6, 4 ) )
242
+                    ->shiftRight( 4 )
243
+                    ->mask( 0x3ffffff )
244 244
             )->toInt64();
245 245
             $h3 = $h3->addInt32(
246
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 9, 4))
247
-                    ->shiftRight(6)
248
-                    ->mask(0x3ffffff)
246
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 9, 4 ) )
247
+                    ->shiftRight( 6 )
248
+                    ->mask( 0x3ffffff )
249 249
             )->toInt64();
250 250
             $h4 = $h4->addInt32(
251
-                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4))
252
-                    ->shiftRight(8)
253
-                    ->orInt32($hibit)
251
+                ParagonIE_Sodium_Core32_Int32::fromReverseString( self::substr( $message, 12, 4 ) )
252
+                    ->shiftRight( 8 )
253
+                    ->orInt32( $hibit )
254 254
             )->toInt64();
255 255
 
256 256
             /* h *= r */
257 257
             $d0 = $zero
258
-                ->addInt64($h0->mulInt64($r0, 25))
259
-                ->addInt64($s4->mulInt64($h1, 26))
260
-                ->addInt64($s3->mulInt64($h2, 26))
261
-                ->addInt64($s2->mulInt64($h3, 26))
262
-                ->addInt64($s1->mulInt64($h4, 26));
258
+                ->addInt64( $h0->mulInt64( $r0, 25 ) )
259
+                ->addInt64( $s4->mulInt64( $h1, 26 ) )
260
+                ->addInt64( $s3->mulInt64( $h2, 26 ) )
261
+                ->addInt64( $s2->mulInt64( $h3, 26 ) )
262
+                ->addInt64( $s1->mulInt64( $h4, 26 ) );
263 263
 
264 264
             $d1 = $zero
265
-                ->addInt64($h0->mulInt64($r1, 25))
266
-                ->addInt64($h1->mulInt64($r0, 25))
267
-                ->addInt64($s4->mulInt64($h2, 26))
268
-                ->addInt64($s3->mulInt64($h3, 26))
269
-                ->addInt64($s2->mulInt64($h4, 26));
265
+                ->addInt64( $h0->mulInt64( $r1, 25 ) )
266
+                ->addInt64( $h1->mulInt64( $r0, 25 ) )
267
+                ->addInt64( $s4->mulInt64( $h2, 26 ) )
268
+                ->addInt64( $s3->mulInt64( $h3, 26 ) )
269
+                ->addInt64( $s2->mulInt64( $h4, 26 ) );
270 270
 
271 271
             $d2 = $zero
272
-                ->addInt64($h0->mulInt64($r2, 25))
273
-                ->addInt64($h1->mulInt64($r1, 25))
274
-                ->addInt64($h2->mulInt64($r0, 25))
275
-                ->addInt64($s4->mulInt64($h3, 26))
276
-                ->addInt64($s3->mulInt64($h4, 26));
272
+                ->addInt64( $h0->mulInt64( $r2, 25 ) )
273
+                ->addInt64( $h1->mulInt64( $r1, 25 ) )
274
+                ->addInt64( $h2->mulInt64( $r0, 25 ) )
275
+                ->addInt64( $s4->mulInt64( $h3, 26 ) )
276
+                ->addInt64( $s3->mulInt64( $h4, 26 ) );
277 277
 
278 278
             $d3 = $zero
279
-                ->addInt64($h0->mulInt64($r3, 25))
280
-                ->addInt64($h1->mulInt64($r2, 25))
281
-                ->addInt64($h2->mulInt64($r1, 25))
282
-                ->addInt64($h3->mulInt64($r0, 25))
283
-                ->addInt64($s4->mulInt64($h4, 26));
279
+                ->addInt64( $h0->mulInt64( $r3, 25 ) )
280
+                ->addInt64( $h1->mulInt64( $r2, 25 ) )
281
+                ->addInt64( $h2->mulInt64( $r1, 25 ) )
282
+                ->addInt64( $h3->mulInt64( $r0, 25 ) )
283
+                ->addInt64( $s4->mulInt64( $h4, 26 ) );
284 284
 
285 285
             $d4 = $zero
286
-                ->addInt64($h0->mulInt64($r4, 25))
287
-                ->addInt64($h1->mulInt64($r3, 25))
288
-                ->addInt64($h2->mulInt64($r2, 25))
289
-                ->addInt64($h3->mulInt64($r1, 25))
290
-                ->addInt64($h4->mulInt64($r0, 25));
286
+                ->addInt64( $h0->mulInt64( $r4, 25 ) )
287
+                ->addInt64( $h1->mulInt64( $r3, 25 ) )
288
+                ->addInt64( $h2->mulInt64( $r2, 25 ) )
289
+                ->addInt64( $h3->mulInt64( $r1, 25 ) )
290
+                ->addInt64( $h4->mulInt64( $r0, 25 ) );
291 291
 
292 292
             /* (partial) h %= p */
293
-            $c = $d0->shiftRight(26);
294
-            $h0 = $d0->toInt32()->mask(0x3ffffff);
295
-            $d1 = $d1->addInt64($c);
293
+            $c = $d0->shiftRight( 26 );
294
+            $h0 = $d0->toInt32()->mask( 0x3ffffff );
295
+            $d1 = $d1->addInt64( $c );
296 296
 
297
-            $c = $d1->shiftRight(26);
298
-            $h1 = $d1->toInt32()->mask(0x3ffffff);
299
-            $d2 = $d2->addInt64($c);
297
+            $c = $d1->shiftRight( 26 );
298
+            $h1 = $d1->toInt32()->mask( 0x3ffffff );
299
+            $d2 = $d2->addInt64( $c );
300 300
 
301
-            $c = $d2->shiftRight(26);
302
-            $h2 = $d2->toInt32()->mask(0x3ffffff);
303
-            $d3 = $d3->addInt64($c);
301
+            $c = $d2->shiftRight( 26 );
302
+            $h2 = $d2->toInt32()->mask( 0x3ffffff );
303
+            $d3 = $d3->addInt64( $c );
304 304
 
305
-            $c = $d3->shiftRight(26);
306
-            $h3 = $d3->toInt32()->mask(0x3ffffff);
307
-            $d4 = $d4->addInt64($c);
305
+            $c = $d3->shiftRight( 26 );
306
+            $h3 = $d3->toInt32()->mask( 0x3ffffff );
307
+            $d4 = $d4->addInt64( $c );
308 308
 
309
-            $c = $d4->shiftRight(26);
310
-            $h4 = $d4->toInt32()->mask(0x3ffffff);
311
-            $h0 = $h0->addInt32($c->toInt32()->mulInt(5, 3));
309
+            $c = $d4->shiftRight( 26 );
310
+            $h4 = $d4->toInt32()->mask( 0x3ffffff );
311
+            $h0 = $h0->addInt32( $c->toInt32()->mulInt( 5, 3 ) );
312 312
 
313
-            $c = $h0->shiftRight(26);
314
-            $h0 = $h0->mask(0x3ffffff);
315
-            $h1 = $h1->addInt32($c);
313
+            $c = $h0->shiftRight( 26 );
314
+            $h0 = $h0->mask( 0x3ffffff );
315
+            $h1 = $h1->addInt32( $c );
316 316
 
317 317
             // Chop off the left 32 bytes.
318 318
             $message = self::substr(
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
         }
324 324
 
325 325
         /** @var array<int, ParagonIE_Sodium_Core32_Int32> $h */
326
-        $this->h = array($h0, $h1, $h2, $h3, $h4);
326
+        $this->h = array( $h0, $h1, $h2, $h3, $h4 );
327 327
         return $this;
328 328
     }
329 329
 
@@ -337,16 +337,16 @@  discard block
 block discarded – undo
337 337
     public function finish()
338 338
     {
339 339
         /* process the remaining block */
340
-        if ($this->leftover) {
340
+        if ( $this->leftover ) {
341 341
             $i = $this->leftover;
342
-            $this->buffer[$i++] = 1;
343
-            for (; $i < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE; ++$i) {
344
-                $this->buffer[$i] = 0;
342
+            $this->buffer[ $i++ ] = 1;
343
+            for ( ; $i < ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE; ++$i ) {
344
+                $this->buffer[ $i ] = 0;
345 345
             }
346 346
             $this->final = true;
347 347
             $this->blocks(
348 348
                 self::substr(
349
-                    self::intArrayToString($this->buffer),
349
+                    self::intArrayToString( $this->buffer ),
350 350
                     0,
351 351
                     ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE
352 352
                 ),
@@ -367,80 +367,80 @@  discard block
 block discarded – undo
367 367
          * @var ParagonIE_Sodium_Core32_Int32 $h3
368 368
          * @var ParagonIE_Sodium_Core32_Int32 $h4
369 369
          */
370
-        $h0 = $this->h[0];
371
-        $h1 = $this->h[1];
372
-        $h2 = $this->h[2];
373
-        $h3 = $this->h[3];
374
-        $h4 = $this->h[4];
370
+        $h0 = $this->h[ 0 ];
371
+        $h1 = $this->h[ 1 ];
372
+        $h2 = $this->h[ 2 ];
373
+        $h3 = $this->h[ 3 ];
374
+        $h4 = $this->h[ 4 ];
375 375
 
376
-        $c = $h1->shiftRight(26);           # $c = $h1 >> 26;
377
-        $h1 = $h1->mask(0x3ffffff);         # $h1 &= 0x3ffffff;
376
+        $c = $h1->shiftRight( 26 ); # $c = $h1 >> 26;
377
+        $h1 = $h1->mask( 0x3ffffff ); # $h1 &= 0x3ffffff;
378 378
 
379
-        $h2 = $h2->addInt32($c);            # $h2 += $c;
380
-        $c = $h2->shiftRight(26);           # $c = $h2 >> 26;
381
-        $h2 = $h2->mask(0x3ffffff);         # $h2 &= 0x3ffffff;
379
+        $h2 = $h2->addInt32( $c ); # $h2 += $c;
380
+        $c = $h2->shiftRight( 26 ); # $c = $h2 >> 26;
381
+        $h2 = $h2->mask( 0x3ffffff ); # $h2 &= 0x3ffffff;
382 382
 
383
-        $h3 = $h3->addInt32($c);            # $h3 += $c;
384
-        $c = $h3->shiftRight(26);           # $c = $h3 >> 26;
385
-        $h3 = $h3->mask(0x3ffffff);         # $h3 &= 0x3ffffff;
383
+        $h3 = $h3->addInt32( $c ); # $h3 += $c;
384
+        $c = $h3->shiftRight( 26 ); # $c = $h3 >> 26;
385
+        $h3 = $h3->mask( 0x3ffffff ); # $h3 &= 0x3ffffff;
386 386
 
387
-        $h4 = $h4->addInt32($c);            # $h4 += $c;
388
-        $c = $h4->shiftRight(26);           # $c = $h4 >> 26;
389
-        $h4 = $h4->mask(0x3ffffff);         # $h4 &= 0x3ffffff;
387
+        $h4 = $h4->addInt32( $c ); # $h4 += $c;
388
+        $c = $h4->shiftRight( 26 ); # $c = $h4 >> 26;
389
+        $h4 = $h4->mask( 0x3ffffff ); # $h4 &= 0x3ffffff;
390 390
 
391
-        $h0 = $h0->addInt32($c->mulInt(5, 3)); # $h0 += self::mul($c, 5);
392
-        $c = $h0->shiftRight(26);           # $c = $h0 >> 26;
393
-        $h0 = $h0->mask(0x3ffffff);         # $h0 &= 0x3ffffff;
394
-        $h1 = $h1->addInt32($c);            # $h1 += $c;
391
+        $h0 = $h0->addInt32( $c->mulInt( 5, 3 ) ); # $h0 += self::mul($c, 5);
392
+        $c = $h0->shiftRight( 26 ); # $c = $h0 >> 26;
393
+        $h0 = $h0->mask( 0x3ffffff ); # $h0 &= 0x3ffffff;
394
+        $h1 = $h1->addInt32( $c ); # $h1 += $c;
395 395
 
396 396
         /* compute h + -p */
397
-        $g0 = $h0->addInt(5);
398
-        $c  = $g0->shiftRight(26);
399
-        $g0 = $g0->mask(0x3ffffff);
400
-        $g1 = $h1->addInt32($c);
401
-        $c  = $g1->shiftRight(26);
402
-        $g1 = $g1->mask(0x3ffffff);
403
-        $g2 = $h2->addInt32($c);
404
-        $c  = $g2->shiftRight(26);
405
-        $g2 = $g2->mask(0x3ffffff);
406
-        $g3 = $h3->addInt32($c);
407
-        $c  = $g3->shiftRight(26);
408
-        $g3 = $g3->mask(0x3ffffff);
409
-        $g4 = $h4->addInt32($c)->subInt(1 << 26);
397
+        $g0 = $h0->addInt( 5 );
398
+        $c  = $g0->shiftRight( 26 );
399
+        $g0 = $g0->mask( 0x3ffffff );
400
+        $g1 = $h1->addInt32( $c );
401
+        $c  = $g1->shiftRight( 26 );
402
+        $g1 = $g1->mask( 0x3ffffff );
403
+        $g2 = $h2->addInt32( $c );
404
+        $c  = $g2->shiftRight( 26 );
405
+        $g2 = $g2->mask( 0x3ffffff );
406
+        $g3 = $h3->addInt32( $c );
407
+        $c  = $g3->shiftRight( 26 );
408
+        $g3 = $g3->mask( 0x3ffffff );
409
+        $g4 = $h4->addInt32( $c )->subInt( 1 << 26 );
410 410
 
411 411
         # $mask = ($g4 >> 31) - 1;
412 412
         /* select h if h < p, or h + -p if h >= p */
413
-        $mask = (int) (($g4->toInt() >> 31) + 1);
413
+        $mask = (int)( ( $g4->toInt() >> 31 ) + 1 );
414 414
 
415
-        $g0 = $g0->mask($mask);
416
-        $g1 = $g1->mask($mask);
417
-        $g2 = $g2->mask($mask);
418
-        $g3 = $g3->mask($mask);
419
-        $g4 = $g4->mask($mask);
415
+        $g0 = $g0->mask( $mask );
416
+        $g1 = $g1->mask( $mask );
417
+        $g2 = $g2->mask( $mask );
418
+        $g3 = $g3->mask( $mask );
419
+        $g4 = $g4->mask( $mask );
420 420
 
421 421
         /** @var int $mask */
422
-        $mask = (~$mask) & 0xffffffff;
422
+        $mask = ( ~$mask ) & 0xffffffff;
423 423
 
424
-        $h0 = $h0->mask($mask)->orInt32($g0);
425
-        $h1 = $h1->mask($mask)->orInt32($g1);
426
-        $h2 = $h2->mask($mask)->orInt32($g2);
427
-        $h3 = $h3->mask($mask)->orInt32($g3);
428
-        $h4 = $h4->mask($mask)->orInt32($g4);
424
+        $h0 = $h0->mask( $mask )->orInt32( $g0 );
425
+        $h1 = $h1->mask( $mask )->orInt32( $g1 );
426
+        $h2 = $h2->mask( $mask )->orInt32( $g2 );
427
+        $h3 = $h3->mask( $mask )->orInt32( $g3 );
428
+        $h4 = $h4->mask( $mask )->orInt32( $g4 );
429 429
 
430 430
         /* h = h % (2^128) */
431
-        $h0 = $h0->orInt32($h1->shiftLeft(26));
432
-        $h1 = $h1->shiftRight(6)->orInt32($h2->shiftLeft(20));
433
-        $h2 = $h2->shiftRight(12)->orInt32($h3->shiftLeft(14));
434
-        $h3 = $h3->shiftRight(18)->orInt32($h4->shiftLeft(8));
431
+        $h0 = $h0->orInt32( $h1->shiftLeft( 26 ) );
432
+        $h1 = $h1->shiftRight( 6 )->orInt32( $h2->shiftLeft( 20 ) );
433
+        $h2 = $h2->shiftRight( 12 )->orInt32( $h3->shiftLeft( 14 ) );
434
+        $h3 = $h3->shiftRight( 18 )->orInt32( $h4->shiftLeft( 8 ) );
435 435
 
436 436
         /* mac = (h + pad) % (2^128) */
437
-        $f = $h0->toInt64()->addInt64($this->pad[0]);
437
+        $f = $h0->toInt64()->addInt64( $this->pad[ 0 ] );
438 438
         $h0 = $f->toInt32();
439
-        $f = $h1->toInt64()->addInt64($this->pad[1])->addInt($h0->overflow);
439
+        $f = $h1->toInt64()->addInt64( $this->pad[ 1 ] )->addInt( $h0->overflow );
440 440
         $h1 = $f->toInt32();
441
-        $f = $h2->toInt64()->addInt64($this->pad[2])->addInt($h1->overflow);
441
+        $f = $h2->toInt64()->addInt64( $this->pad[ 2 ] )->addInt( $h1->overflow );
442 442
         $h2 = $f->toInt32();
443
-        $f = $h3->toInt64()->addInt64($this->pad[3])->addInt($h2->overflow);
443
+        $f = $h3->toInt64()->addInt64( $this->pad[ 3 ] )->addInt( $h2->overflow );
444 444
         $h3 = $f->toInt32();
445 445
 
446 446
         return $h0->toReverseString() .
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 /**
8 8
  * Class ParagonIE_Sodium_Core32_Poly1305_State
9 9
  */
10
-class ParagonIE_Sodium_Core32_Poly1305_State extends ParagonIE_Sodium_Core32_Util
11
-{
10
+class ParagonIE_Sodium_Core32_Poly1305_State extends ParagonIE_Sodium_Core32_Util {
12 11
     /**
13 12
      * @var array<int, int>
14 13
      */
@@ -49,8 +48,7 @@  discard block
 block discarded – undo
49 48
      * @throws SodiumException
50 49
      * @throws TypeError
51 50
      */
52
-    public function __construct($key = '')
53
-    {
51
+    public function __construct($key = '') {
54 52
         if (self::strlen($key) < 32) {
55 53
             throw new InvalidArgumentException(
56 54
                 'Poly1305 requires a 32-byte key'
@@ -117,8 +115,7 @@  discard block
 block discarded – undo
117 115
      * @throws SodiumException
118 116
      * @throws TypeError
119 117
      */
120
-    public function update($message = '')
121
-    {
118
+    public function update($message = '') {
122 119
         $bytes = self::strlen($message);
123 120
 
124 121
         /* handle leftover */
@@ -183,8 +180,7 @@  discard block
 block discarded – undo
183 180
      * @throws SodiumException
184 181
      * @throws TypeError
185 182
      */
186
-    public function blocks($message, $bytes)
187
-    {
183
+    public function blocks($message, $bytes) {
188 184
         if (self::strlen($message) < 16) {
189 185
             $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT);
190 186
         }
@@ -334,8 +330,7 @@  discard block
 block discarded – undo
334 330
      * @throws SodiumException
335 331
      * @throws TypeError
336 332
      */
337
-    public function finish()
338
-    {
333
+    public function finish() {
339 334
         /* process the remaining block */
340 335
         if ($this->leftover) {
341 336
             $i = $this->leftover;
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/SecretStream/State.php 3 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -5,159 +5,159 @@
 block discarded – undo
5 5
  */
6 6
 class ParagonIE_Sodium_Core32_SecretStream_State
7 7
 {
8
-    /** @var string $key */
9
-    protected $key;
10
-
11
-    /** @var int $counter */
12
-    protected $counter;
13
-
14
-    /** @var string $nonce */
15
-    protected $nonce;
16
-
17
-    /** @var string $_pad */
18
-    protected $_pad;
19
-
20
-    /**
21
-     * ParagonIE_Sodium_Core32_SecretStream_State constructor.
22
-     * @param string $key
23
-     * @param string|null $nonce
24
-     */
25
-    public function __construct($key, $nonce = null)
26
-    {
27
-        $this->key = $key;
28
-        $this->counter = 1;
29
-        if (is_null($nonce)) {
30
-            $nonce = str_repeat("\0", 12);
31
-        }
32
-        $this->nonce = str_pad($nonce, 12, "\0", STR_PAD_RIGHT);;
33
-        $this->_pad = str_repeat("\0", 4);
34
-    }
35
-
36
-    /**
37
-     * @return self
38
-     */
39
-    public function counterReset()
40
-    {
41
-        $this->counter = 1;
42
-        $this->_pad = str_repeat("\0", 4);
43
-        return $this;
44
-    }
45
-
46
-    /**
47
-     * @return string
48
-     */
49
-    public function getKey()
50
-    {
51
-        return $this->key;
52
-    }
53
-
54
-    /**
55
-     * @return string
56
-     */
57
-    public function getCounter()
58
-    {
59
-        return ParagonIE_Sodium_Core32_Util::store32_le($this->counter);
60
-    }
61
-
62
-    /**
63
-     * @return string
64
-     */
65
-    public function getNonce()
66
-    {
67
-        if (!is_string($this->nonce)) {
68
-            $this->nonce = str_repeat("\0", 12);
69
-        }
70
-        if (ParagonIE_Sodium_Core32_Util::strlen($this->nonce) !== 12) {
71
-            $this->nonce = str_pad($this->nonce, 12, "\0", STR_PAD_RIGHT);
72
-        }
73
-        return $this->nonce;
74
-    }
75
-
76
-    /**
77
-     * @return string
78
-     */
79
-    public function getCombinedNonce()
80
-    {
81
-        return $this->getCounter() .
82
-            ParagonIE_Sodium_Core32_Util::substr($this->getNonce(), 0, 8);
83
-    }
84
-
85
-    /**
86
-     * @return self
87
-     */
88
-    public function incrementCounter()
89
-    {
90
-        ++$this->counter;
91
-        return $this;
92
-    }
93
-
94
-    /**
95
-     * @return bool
96
-     */
97
-    public function needsRekey()
98
-    {
99
-        return ($this->counter & 0xffff) === 0;
100
-    }
101
-
102
-    /**
103
-     * @param string $newKeyAndNonce
104
-     * @return self
105
-     */
106
-    public function rekey($newKeyAndNonce)
107
-    {
108
-        $this->key = ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 0, 32);
109
-        $this->nonce = str_pad(
110
-            ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 32),
111
-            12,
112
-            "\0",
113
-            STR_PAD_RIGHT
114
-        );
115
-        return $this;
116
-    }
117
-
118
-    /**
119
-     * @param string $str
120
-     * @return self
121
-     */
122
-    public function xorNonce($str)
123
-    {
124
-        $this->nonce = ParagonIE_Sodium_Core32_Util::xorStrings(
125
-            $this->getNonce(),
126
-            str_pad(
127
-                ParagonIE_Sodium_Core32_Util::substr($str, 0, 8),
128
-                12,
129
-                "\0",
130
-                STR_PAD_RIGHT
131
-            )
132
-        );
133
-        return $this;
134
-    }
135
-
136
-    /**
137
-     * @param string $string
138
-     * @return self
139
-     */
140
-    public static function fromString($string)
141
-    {
142
-        $state = new ParagonIE_Sodium_Core32_SecretStream_State(
143
-            ParagonIE_Sodium_Core32_Util::substr($string, 0, 32)
144
-        );
145
-        $state->counter = ParagonIE_Sodium_Core32_Util::load_4(
146
-            ParagonIE_Sodium_Core32_Util::substr($string, 32, 4)
147
-        );
148
-        $state->nonce = ParagonIE_Sodium_Core32_Util::substr($string, 36, 12);
149
-        $state->_pad = ParagonIE_Sodium_Core32_Util::substr($string, 48, 8);
150
-        return $state;
151
-    }
152
-
153
-    /**
154
-     * @return string
155
-     */
156
-    public function toString()
157
-    {
158
-        return $this->key .
159
-            $this->getCounter() .
160
-            $this->nonce .
161
-            $this->_pad;
162
-    }
8
+	/** @var string $key */
9
+	protected $key;
10
+
11
+	/** @var int $counter */
12
+	protected $counter;
13
+
14
+	/** @var string $nonce */
15
+	protected $nonce;
16
+
17
+	/** @var string $_pad */
18
+	protected $_pad;
19
+
20
+	/**
21
+	 * ParagonIE_Sodium_Core32_SecretStream_State constructor.
22
+	 * @param string $key
23
+	 * @param string|null $nonce
24
+	 */
25
+	public function __construct($key, $nonce = null)
26
+	{
27
+		$this->key = $key;
28
+		$this->counter = 1;
29
+		if (is_null($nonce)) {
30
+			$nonce = str_repeat("\0", 12);
31
+		}
32
+		$this->nonce = str_pad($nonce, 12, "\0", STR_PAD_RIGHT);;
33
+		$this->_pad = str_repeat("\0", 4);
34
+	}
35
+
36
+	/**
37
+	 * @return self
38
+	 */
39
+	public function counterReset()
40
+	{
41
+		$this->counter = 1;
42
+		$this->_pad = str_repeat("\0", 4);
43
+		return $this;
44
+	}
45
+
46
+	/**
47
+	 * @return string
48
+	 */
49
+	public function getKey()
50
+	{
51
+		return $this->key;
52
+	}
53
+
54
+	/**
55
+	 * @return string
56
+	 */
57
+	public function getCounter()
58
+	{
59
+		return ParagonIE_Sodium_Core32_Util::store32_le($this->counter);
60
+	}
61
+
62
+	/**
63
+	 * @return string
64
+	 */
65
+	public function getNonce()
66
+	{
67
+		if (!is_string($this->nonce)) {
68
+			$this->nonce = str_repeat("\0", 12);
69
+		}
70
+		if (ParagonIE_Sodium_Core32_Util::strlen($this->nonce) !== 12) {
71
+			$this->nonce = str_pad($this->nonce, 12, "\0", STR_PAD_RIGHT);
72
+		}
73
+		return $this->nonce;
74
+	}
75
+
76
+	/**
77
+	 * @return string
78
+	 */
79
+	public function getCombinedNonce()
80
+	{
81
+		return $this->getCounter() .
82
+			ParagonIE_Sodium_Core32_Util::substr($this->getNonce(), 0, 8);
83
+	}
84
+
85
+	/**
86
+	 * @return self
87
+	 */
88
+	public function incrementCounter()
89
+	{
90
+		++$this->counter;
91
+		return $this;
92
+	}
93
+
94
+	/**
95
+	 * @return bool
96
+	 */
97
+	public function needsRekey()
98
+	{
99
+		return ($this->counter & 0xffff) === 0;
100
+	}
101
+
102
+	/**
103
+	 * @param string $newKeyAndNonce
104
+	 * @return self
105
+	 */
106
+	public function rekey($newKeyAndNonce)
107
+	{
108
+		$this->key = ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 0, 32);
109
+		$this->nonce = str_pad(
110
+			ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 32),
111
+			12,
112
+			"\0",
113
+			STR_PAD_RIGHT
114
+		);
115
+		return $this;
116
+	}
117
+
118
+	/**
119
+	 * @param string $str
120
+	 * @return self
121
+	 */
122
+	public function xorNonce($str)
123
+	{
124
+		$this->nonce = ParagonIE_Sodium_Core32_Util::xorStrings(
125
+			$this->getNonce(),
126
+			str_pad(
127
+				ParagonIE_Sodium_Core32_Util::substr($str, 0, 8),
128
+				12,
129
+				"\0",
130
+				STR_PAD_RIGHT
131
+			)
132
+		);
133
+		return $this;
134
+	}
135
+
136
+	/**
137
+	 * @param string $string
138
+	 * @return self
139
+	 */
140
+	public static function fromString($string)
141
+	{
142
+		$state = new ParagonIE_Sodium_Core32_SecretStream_State(
143
+			ParagonIE_Sodium_Core32_Util::substr($string, 0, 32)
144
+		);
145
+		$state->counter = ParagonIE_Sodium_Core32_Util::load_4(
146
+			ParagonIE_Sodium_Core32_Util::substr($string, 32, 4)
147
+		);
148
+		$state->nonce = ParagonIE_Sodium_Core32_Util::substr($string, 36, 12);
149
+		$state->_pad = ParagonIE_Sodium_Core32_Util::substr($string, 48, 8);
150
+		return $state;
151
+	}
152
+
153
+	/**
154
+	 * @return string
155
+	 */
156
+	public function toString()
157
+	{
158
+		return $this->key .
159
+			$this->getCounter() .
160
+			$this->nonce .
161
+			$this->_pad;
162
+	}
163 163
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
      * @param string $key
23 23
      * @param string|null $nonce
24 24
      */
25
-    public function __construct($key, $nonce = null)
25
+    public function __construct( $key, $nonce = null )
26 26
     {
27 27
         $this->key = $key;
28 28
         $this->counter = 1;
29
-        if (is_null($nonce)) {
30
-            $nonce = str_repeat("\0", 12);
29
+        if ( is_null( $nonce ) ) {
30
+            $nonce = str_repeat( "\0", 12 );
31 31
         }
32
-        $this->nonce = str_pad($nonce, 12, "\0", STR_PAD_RIGHT);;
33
-        $this->_pad = str_repeat("\0", 4);
32
+        $this->nonce = str_pad( $nonce, 12, "\0", STR_PAD_RIGHT ); ;
33
+        $this->_pad = str_repeat( "\0", 4 );
34 34
     }
35 35
 
36 36
     /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     public function counterReset()
40 40
     {
41 41
         $this->counter = 1;
42
-        $this->_pad = str_repeat("\0", 4);
42
+        $this->_pad = str_repeat( "\0", 4 );
43 43
         return $this;
44 44
     }
45 45
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function getCounter()
58 58
     {
59
-        return ParagonIE_Sodium_Core32_Util::store32_le($this->counter);
59
+        return ParagonIE_Sodium_Core32_Util::store32_le( $this->counter );
60 60
     }
61 61
 
62 62
     /**
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function getNonce()
66 66
     {
67
-        if (!is_string($this->nonce)) {
68
-            $this->nonce = str_repeat("\0", 12);
67
+        if ( ! is_string( $this->nonce ) ) {
68
+            $this->nonce = str_repeat( "\0", 12 );
69 69
         }
70
-        if (ParagonIE_Sodium_Core32_Util::strlen($this->nonce) !== 12) {
71
-            $this->nonce = str_pad($this->nonce, 12, "\0", STR_PAD_RIGHT);
70
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $this->nonce ) !== 12 ) {
71
+            $this->nonce = str_pad( $this->nonce, 12, "\0", STR_PAD_RIGHT );
72 72
         }
73 73
         return $this->nonce;
74 74
     }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     public function getCombinedNonce()
80 80
     {
81 81
         return $this->getCounter() .
82
-            ParagonIE_Sodium_Core32_Util::substr($this->getNonce(), 0, 8);
82
+            ParagonIE_Sodium_Core32_Util::substr( $this->getNonce(), 0, 8 );
83 83
     }
84 84
 
85 85
     /**
@@ -96,18 +96,18 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public function needsRekey()
98 98
     {
99
-        return ($this->counter & 0xffff) === 0;
99
+        return ( $this->counter & 0xffff ) === 0;
100 100
     }
101 101
 
102 102
     /**
103 103
      * @param string $newKeyAndNonce
104 104
      * @return self
105 105
      */
106
-    public function rekey($newKeyAndNonce)
106
+    public function rekey( $newKeyAndNonce )
107 107
     {
108
-        $this->key = ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 0, 32);
108
+        $this->key = ParagonIE_Sodium_Core32_Util::substr( $newKeyAndNonce, 0, 32 );
109 109
         $this->nonce = str_pad(
110
-            ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 32),
110
+            ParagonIE_Sodium_Core32_Util::substr( $newKeyAndNonce, 32 ),
111 111
             12,
112 112
             "\0",
113 113
             STR_PAD_RIGHT
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
      * @param string $str
120 120
      * @return self
121 121
      */
122
-    public function xorNonce($str)
122
+    public function xorNonce( $str )
123 123
     {
124 124
         $this->nonce = ParagonIE_Sodium_Core32_Util::xorStrings(
125 125
             $this->getNonce(),
126 126
             str_pad(
127
-                ParagonIE_Sodium_Core32_Util::substr($str, 0, 8),
127
+                ParagonIE_Sodium_Core32_Util::substr( $str, 0, 8 ),
128 128
                 12,
129 129
                 "\0",
130 130
                 STR_PAD_RIGHT
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
      * @param string $string
138 138
      * @return self
139 139
      */
140
-    public static function fromString($string)
140
+    public static function fromString( $string )
141 141
     {
142 142
         $state = new ParagonIE_Sodium_Core32_SecretStream_State(
143
-            ParagonIE_Sodium_Core32_Util::substr($string, 0, 32)
143
+            ParagonIE_Sodium_Core32_Util::substr( $string, 0, 32 )
144 144
         );
145 145
         $state->counter = ParagonIE_Sodium_Core32_Util::load_4(
146
-            ParagonIE_Sodium_Core32_Util::substr($string, 32, 4)
146
+            ParagonIE_Sodium_Core32_Util::substr( $string, 32, 4 )
147 147
         );
148
-        $state->nonce = ParagonIE_Sodium_Core32_Util::substr($string, 36, 12);
149
-        $state->_pad = ParagonIE_Sodium_Core32_Util::substr($string, 48, 8);
148
+        $state->nonce = ParagonIE_Sodium_Core32_Util::substr( $string, 36, 12 );
149
+        $state->_pad = ParagonIE_Sodium_Core32_Util::substr( $string, 48, 8 );
150 150
         return $state;
151 151
     }
152 152
 
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -3,8 +3,7 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Class ParagonIE_Sodium_Core32_SecretStream_State
5 5
  */
6
-class ParagonIE_Sodium_Core32_SecretStream_State
7
-{
6
+class ParagonIE_Sodium_Core32_SecretStream_State {
8 7
     /** @var string $key */
9 8
     protected $key;
10 9
 
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      * @param string $key
23 22
      * @param string|null $nonce
24 23
      */
25
-    public function __construct($key, $nonce = null)
26
-    {
24
+    public function __construct($key, $nonce = null) {
27 25
         $this->key = $key;
28 26
         $this->counter = 1;
29 27
         if (is_null($nonce)) {
@@ -36,8 +34,7 @@  discard block
 block discarded – undo
36 34
     /**
37 35
      * @return self
38 36
      */
39
-    public function counterReset()
40
-    {
37
+    public function counterReset() {
41 38
         $this->counter = 1;
42 39
         $this->_pad = str_repeat("\0", 4);
43 40
         return $this;
@@ -46,24 +43,21 @@  discard block
 block discarded – undo
46 43
     /**
47 44
      * @return string
48 45
      */
49
-    public function getKey()
50
-    {
46
+    public function getKey() {
51 47
         return $this->key;
52 48
     }
53 49
 
54 50
     /**
55 51
      * @return string
56 52
      */
57
-    public function getCounter()
58
-    {
53
+    public function getCounter() {
59 54
         return ParagonIE_Sodium_Core32_Util::store32_le($this->counter);
60 55
     }
61 56
 
62 57
     /**
63 58
      * @return string
64 59
      */
65
-    public function getNonce()
66
-    {
60
+    public function getNonce() {
67 61
         if (!is_string($this->nonce)) {
68 62
             $this->nonce = str_repeat("\0", 12);
69 63
         }
@@ -76,8 +70,7 @@  discard block
 block discarded – undo
76 70
     /**
77 71
      * @return string
78 72
      */
79
-    public function getCombinedNonce()
80
-    {
73
+    public function getCombinedNonce() {
81 74
         return $this->getCounter() .
82 75
             ParagonIE_Sodium_Core32_Util::substr($this->getNonce(), 0, 8);
83 76
     }
@@ -85,8 +78,7 @@  discard block
 block discarded – undo
85 78
     /**
86 79
      * @return self
87 80
      */
88
-    public function incrementCounter()
89
-    {
81
+    public function incrementCounter() {
90 82
         ++$this->counter;
91 83
         return $this;
92 84
     }
@@ -94,8 +86,7 @@  discard block
 block discarded – undo
94 86
     /**
95 87
      * @return bool
96 88
      */
97
-    public function needsRekey()
98
-    {
89
+    public function needsRekey() {
99 90
         return ($this->counter & 0xffff) === 0;
100 91
     }
101 92
 
@@ -103,8 +94,7 @@  discard block
 block discarded – undo
103 94
      * @param string $newKeyAndNonce
104 95
      * @return self
105 96
      */
106
-    public function rekey($newKeyAndNonce)
107
-    {
97
+    public function rekey($newKeyAndNonce) {
108 98
         $this->key = ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 0, 32);
109 99
         $this->nonce = str_pad(
110 100
             ParagonIE_Sodium_Core32_Util::substr($newKeyAndNonce, 32),
@@ -119,8 +109,7 @@  discard block
 block discarded – undo
119 109
      * @param string $str
120 110
      * @return self
121 111
      */
122
-    public function xorNonce($str)
123
-    {
112
+    public function xorNonce($str) {
124 113
         $this->nonce = ParagonIE_Sodium_Core32_Util::xorStrings(
125 114
             $this->getNonce(),
126 115
             str_pad(
@@ -137,8 +126,7 @@  discard block
 block discarded – undo
137 126
      * @param string $string
138 127
      * @return self
139 128
      */
140
-    public static function fromString($string)
141
-    {
129
+    public static function fromString($string) {
142 130
         $state = new ParagonIE_Sodium_Core32_SecretStream_State(
143 131
             ParagonIE_Sodium_Core32_Util::substr($string, 0, 32)
144 132
         );
@@ -153,8 +141,7 @@  discard block
 block discarded – undo
153 141
     /**
154 142
      * @return string
155 143
      */
156
-    public function toString()
157
-    {
144
+    public function toString() {
158 145
         return $this->key .
159 146
             $this->getCounter() .
160 147
             $this->nonce .
Please login to merge, or discard this patch.
vendor/paragonie/sodium_compat/src/Core32/Int64.php 3 patches
Indentation   +1046 added lines, -1046 removed lines patch added patch discarded remove patch
@@ -9,302 +9,302 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class ParagonIE_Sodium_Core32_Int64
11 11
 {
12
-    /**
13
-     * @var array<int, int> - four 16-bit integers
14
-     */
15
-    public $limbs = array(0, 0, 0, 0);
16
-
17
-    /**
18
-     * @var int
19
-     */
20
-    public $overflow = 0;
21
-
22
-    /**
23
-     * @var bool
24
-     */
25
-    public $unsignedInt = false;
26
-
27
-    /**
28
-     * ParagonIE_Sodium_Core32_Int64 constructor.
29
-     * @param array $array
30
-     * @param bool $unsignedInt
31
-     */
32
-    public function __construct($array = array(0, 0, 0, 0), $unsignedInt = false)
33
-    {
34
-        $this->limbs = array(
35
-            (int) $array[0],
36
-            (int) $array[1],
37
-            (int) $array[2],
38
-            (int) $array[3]
39
-        );
40
-        $this->overflow = 0;
41
-        $this->unsignedInt = $unsignedInt;
42
-    }
43
-
44
-    /**
45
-     * Adds two int64 objects
46
-     *
47
-     * @param ParagonIE_Sodium_Core32_Int64 $addend
48
-     * @return ParagonIE_Sodium_Core32_Int64
49
-     */
50
-    public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend)
51
-    {
52
-        $i0 = $this->limbs[0];
53
-        $i1 = $this->limbs[1];
54
-        $i2 = $this->limbs[2];
55
-        $i3 = $this->limbs[3];
56
-        $j0 = $addend->limbs[0];
57
-        $j1 = $addend->limbs[1];
58
-        $j2 = $addend->limbs[2];
59
-        $j3 = $addend->limbs[3];
60
-
61
-        $r3 = $i3 + ($j3 & 0xffff);
62
-        $carry = $r3 >> 16;
63
-
64
-        $r2 = $i2 + ($j2 & 0xffff) + $carry;
65
-        $carry = $r2 >> 16;
66
-
67
-        $r1 = $i1 + ($j1 & 0xffff) + $carry;
68
-        $carry = $r1 >> 16;
69
-
70
-        $r0 = $i0 + ($j0 & 0xffff) + $carry;
71
-        $carry = $r0 >> 16;
72
-
73
-        $r0 &= 0xffff;
74
-        $r1 &= 0xffff;
75
-        $r2 &= 0xffff;
76
-        $r3 &= 0xffff;
77
-
78
-        $return = new ParagonIE_Sodium_Core32_Int64(
79
-            array($r0, $r1, $r2, $r3)
80
-        );
81
-        $return->overflow = $carry;
82
-        $return->unsignedInt = $this->unsignedInt;
83
-        return $return;
84
-    }
85
-
86
-    /**
87
-     * Adds a normal integer to an int64 object
88
-     *
89
-     * @param int $int
90
-     * @return ParagonIE_Sodium_Core32_Int64
91
-     * @throws SodiumException
92
-     * @throws TypeError
93
-     */
94
-    public function addInt($int)
95
-    {
96
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
97
-        /** @var int $int */
98
-        $int = (int) $int;
99
-
100
-        $i0 = $this->limbs[0];
101
-        $i1 = $this->limbs[1];
102
-        $i2 = $this->limbs[2];
103
-        $i3 = $this->limbs[3];
104
-
105
-        $r3 = $i3 + ($int & 0xffff);
106
-        $carry = $r3 >> 16;
107
-
108
-        $r2 = $i2 + (($int >> 16) & 0xffff) + $carry;
109
-        $carry = $r2 >> 16;
110
-
111
-        $r1 = $i1 + $carry;
112
-        $carry = $r1 >> 16;
113
-
114
-        $r0 = $i0 + $carry;
115
-        $carry = $r0 >> 16;
116
-
117
-        $r0 &= 0xffff;
118
-        $r1 &= 0xffff;
119
-        $r2 &= 0xffff;
120
-        $r3 &= 0xffff;
121
-        $return = new ParagonIE_Sodium_Core32_Int64(
122
-            array($r0, $r1, $r2, $r3)
123
-        );
124
-        $return->overflow = $carry;
125
-        $return->unsignedInt = $this->unsignedInt;
126
-        return $return;
127
-    }
128
-
129
-    /**
130
-     * @param int $b
131
-     * @return int
132
-     */
133
-    public function compareInt($b = 0)
134
-    {
135
-        $gt = 0;
136
-        $eq = 1;
137
-
138
-        $i = 4;
139
-        $j = 0;
140
-        while ($i > 0) {
141
-            --$i;
142
-            /** @var int $x1 */
143
-            $x1 = $this->limbs[$i];
144
-            /** @var int $x2 */
145
-            $x2 = ($b >> ($j << 4)) & 0xffff;
146
-            /** int */
147
-            $gt |= (($x2 - $x1) >> 8) & $eq;
148
-            /** int */
149
-            $eq &= (($x2 ^ $x1) - 1) >> 8;
150
-        }
151
-        return ($gt + $gt - $eq) + 1;
152
-    }
153
-
154
-    /**
155
-     * @param int $b
156
-     * @return bool
157
-     */
158
-    public function isGreaterThan($b = 0)
159
-    {
160
-        return $this->compareInt($b) > 0;
161
-    }
162
-
163
-    /**
164
-     * @param int $b
165
-     * @return bool
166
-     */
167
-    public function isLessThanInt($b = 0)
168
-    {
169
-        return $this->compareInt($b) < 0;
170
-    }
171
-
172
-    /**
173
-     * @param int $hi
174
-     * @param int $lo
175
-     * @return ParagonIE_Sodium_Core32_Int64
176
-     */
177
-    public function mask64($hi = 0, $lo = 0)
178
-    {
179
-        /** @var int $a */
180
-        $a = ($hi >> 16) & 0xffff;
181
-        /** @var int $b */
182
-        $b = ($hi) & 0xffff;
183
-        /** @var int $c */
184
-        $c = ($lo >> 16) & 0xffff;
185
-        /** @var int $d */
186
-        $d = ($lo & 0xffff);
187
-        return new ParagonIE_Sodium_Core32_Int64(
188
-            array(
189
-                $this->limbs[0] & $a,
190
-                $this->limbs[1] & $b,
191
-                $this->limbs[2] & $c,
192
-                $this->limbs[3] & $d
193
-            ),
194
-            $this->unsignedInt
195
-        );
196
-    }
197
-
198
-    /**
199
-     * @param int $int
200
-     * @param int $size
201
-     * @return ParagonIE_Sodium_Core32_Int64
202
-     * @throws SodiumException
203
-     * @throws TypeError
204
-     * @psalm-suppress MixedAssignment
205
-     */
206
-    public function mulInt($int = 0, $size = 0)
207
-    {
208
-        if (ParagonIE_Sodium_Compat::$fastMult) {
209
-            return $this->mulIntFast($int);
210
-        }
211
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
212
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
213
-        /** @var int $int */
214
-        $int = (int) $int;
215
-        /** @var int $size */
216
-        $size = (int) $size;
217
-
218
-        if (!$size) {
219
-            $size = 63;
220
-        }
221
-
222
-        $a = clone $this;
223
-        $return = new ParagonIE_Sodium_Core32_Int64();
224
-        $return->unsignedInt = $this->unsignedInt;
225
-
226
-        // Initialize:
227
-        $ret0 = 0;
228
-        $ret1 = 0;
229
-        $ret2 = 0;
230
-        $ret3 = 0;
231
-        $a0 = $a->limbs[0];
232
-        $a1 = $a->limbs[1];
233
-        $a2 = $a->limbs[2];
234
-        $a3 = $a->limbs[3];
235
-
236
-        /** @var int $size */
237
-        /** @var int $i */
238
-        for ($i = $size; $i >= 0; --$i) {
239
-            $mask = -($int & 1);
240
-            $x0 = $a0 & $mask;
241
-            $x1 = $a1 & $mask;
242
-            $x2 = $a2 & $mask;
243
-            $x3 = $a3 & $mask;
244
-
245
-            $ret3 += $x3;
246
-            $c = $ret3 >> 16;
247
-
248
-            $ret2 += $x2 + $c;
249
-            $c = $ret2 >> 16;
250
-
251
-            $ret1 += $x1 + $c;
252
-            $c = $ret1 >> 16;
253
-
254
-            $ret0 += $x0 + $c;
255
-
256
-            $ret0 &= 0xffff;
257
-            $ret1 &= 0xffff;
258
-            $ret2 &= 0xffff;
259
-            $ret3 &= 0xffff;
260
-
261
-            $a3 = $a3 << 1;
262
-            $x3 = $a3 >> 16;
263
-            $a2 = ($a2 << 1) | $x3;
264
-            $x2 = $a2 >> 16;
265
-            $a1 = ($a1 << 1) | $x2;
266
-            $x1 = $a1 >> 16;
267
-            $a0 = ($a0 << 1) | $x1;
268
-            $a0 &= 0xffff;
269
-            $a1 &= 0xffff;
270
-            $a2 &= 0xffff;
271
-            $a3 &= 0xffff;
272
-
273
-            $int >>= 1;
274
-        }
275
-        $return->limbs[0] = $ret0;
276
-        $return->limbs[1] = $ret1;
277
-        $return->limbs[2] = $ret2;
278
-        $return->limbs[3] = $ret3;
279
-        return $return;
280
-    }
281
-
282
-    /**
283
-     * @param ParagonIE_Sodium_Core32_Int64 $A
284
-     * @param ParagonIE_Sodium_Core32_Int64 $B
285
-     * @return array<int, ParagonIE_Sodium_Core32_Int64>
286
-     * @throws SodiumException
287
-     * @throws TypeError
288
-     * @psalm-suppress MixedInferredReturnType
289
-     */
290
-    public static function ctSelect(
291
-        ParagonIE_Sodium_Core32_Int64 $A,
292
-        ParagonIE_Sodium_Core32_Int64 $B
293
-    ) {
294
-        $a = clone $A;
295
-        $b = clone $B;
296
-        /** @var int $aNeg */
297
-        $aNeg = ($a->limbs[0] >> 15) & 1;
298
-        /** @var int $bNeg */
299
-        $bNeg = ($b->limbs[0] >> 15) & 1;
300
-        /** @var int $m */
301
-        $m = (-($aNeg & $bNeg)) | 1;
302
-        /** @var int $swap */
303
-        $swap = $bNeg & ~$aNeg;
304
-        /** @var int $d */
305
-        $d = -$swap;
306
-
307
-        /*
12
+	/**
13
+	 * @var array<int, int> - four 16-bit integers
14
+	 */
15
+	public $limbs = array(0, 0, 0, 0);
16
+
17
+	/**
18
+	 * @var int
19
+	 */
20
+	public $overflow = 0;
21
+
22
+	/**
23
+	 * @var bool
24
+	 */
25
+	public $unsignedInt = false;
26
+
27
+	/**
28
+	 * ParagonIE_Sodium_Core32_Int64 constructor.
29
+	 * @param array $array
30
+	 * @param bool $unsignedInt
31
+	 */
32
+	public function __construct($array = array(0, 0, 0, 0), $unsignedInt = false)
33
+	{
34
+		$this->limbs = array(
35
+			(int) $array[0],
36
+			(int) $array[1],
37
+			(int) $array[2],
38
+			(int) $array[3]
39
+		);
40
+		$this->overflow = 0;
41
+		$this->unsignedInt = $unsignedInt;
42
+	}
43
+
44
+	/**
45
+	 * Adds two int64 objects
46
+	 *
47
+	 * @param ParagonIE_Sodium_Core32_Int64 $addend
48
+	 * @return ParagonIE_Sodium_Core32_Int64
49
+	 */
50
+	public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend)
51
+	{
52
+		$i0 = $this->limbs[0];
53
+		$i1 = $this->limbs[1];
54
+		$i2 = $this->limbs[2];
55
+		$i3 = $this->limbs[3];
56
+		$j0 = $addend->limbs[0];
57
+		$j1 = $addend->limbs[1];
58
+		$j2 = $addend->limbs[2];
59
+		$j3 = $addend->limbs[3];
60
+
61
+		$r3 = $i3 + ($j3 & 0xffff);
62
+		$carry = $r3 >> 16;
63
+
64
+		$r2 = $i2 + ($j2 & 0xffff) + $carry;
65
+		$carry = $r2 >> 16;
66
+
67
+		$r1 = $i1 + ($j1 & 0xffff) + $carry;
68
+		$carry = $r1 >> 16;
69
+
70
+		$r0 = $i0 + ($j0 & 0xffff) + $carry;
71
+		$carry = $r0 >> 16;
72
+
73
+		$r0 &= 0xffff;
74
+		$r1 &= 0xffff;
75
+		$r2 &= 0xffff;
76
+		$r3 &= 0xffff;
77
+
78
+		$return = new ParagonIE_Sodium_Core32_Int64(
79
+			array($r0, $r1, $r2, $r3)
80
+		);
81
+		$return->overflow = $carry;
82
+		$return->unsignedInt = $this->unsignedInt;
83
+		return $return;
84
+	}
85
+
86
+	/**
87
+	 * Adds a normal integer to an int64 object
88
+	 *
89
+	 * @param int $int
90
+	 * @return ParagonIE_Sodium_Core32_Int64
91
+	 * @throws SodiumException
92
+	 * @throws TypeError
93
+	 */
94
+	public function addInt($int)
95
+	{
96
+		ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
97
+		/** @var int $int */
98
+		$int = (int) $int;
99
+
100
+		$i0 = $this->limbs[0];
101
+		$i1 = $this->limbs[1];
102
+		$i2 = $this->limbs[2];
103
+		$i3 = $this->limbs[3];
104
+
105
+		$r3 = $i3 + ($int & 0xffff);
106
+		$carry = $r3 >> 16;
107
+
108
+		$r2 = $i2 + (($int >> 16) & 0xffff) + $carry;
109
+		$carry = $r2 >> 16;
110
+
111
+		$r1 = $i1 + $carry;
112
+		$carry = $r1 >> 16;
113
+
114
+		$r0 = $i0 + $carry;
115
+		$carry = $r0 >> 16;
116
+
117
+		$r0 &= 0xffff;
118
+		$r1 &= 0xffff;
119
+		$r2 &= 0xffff;
120
+		$r3 &= 0xffff;
121
+		$return = new ParagonIE_Sodium_Core32_Int64(
122
+			array($r0, $r1, $r2, $r3)
123
+		);
124
+		$return->overflow = $carry;
125
+		$return->unsignedInt = $this->unsignedInt;
126
+		return $return;
127
+	}
128
+
129
+	/**
130
+	 * @param int $b
131
+	 * @return int
132
+	 */
133
+	public function compareInt($b = 0)
134
+	{
135
+		$gt = 0;
136
+		$eq = 1;
137
+
138
+		$i = 4;
139
+		$j = 0;
140
+		while ($i > 0) {
141
+			--$i;
142
+			/** @var int $x1 */
143
+			$x1 = $this->limbs[$i];
144
+			/** @var int $x2 */
145
+			$x2 = ($b >> ($j << 4)) & 0xffff;
146
+			/** int */
147
+			$gt |= (($x2 - $x1) >> 8) & $eq;
148
+			/** int */
149
+			$eq &= (($x2 ^ $x1) - 1) >> 8;
150
+		}
151
+		return ($gt + $gt - $eq) + 1;
152
+	}
153
+
154
+	/**
155
+	 * @param int $b
156
+	 * @return bool
157
+	 */
158
+	public function isGreaterThan($b = 0)
159
+	{
160
+		return $this->compareInt($b) > 0;
161
+	}
162
+
163
+	/**
164
+	 * @param int $b
165
+	 * @return bool
166
+	 */
167
+	public function isLessThanInt($b = 0)
168
+	{
169
+		return $this->compareInt($b) < 0;
170
+	}
171
+
172
+	/**
173
+	 * @param int $hi
174
+	 * @param int $lo
175
+	 * @return ParagonIE_Sodium_Core32_Int64
176
+	 */
177
+	public function mask64($hi = 0, $lo = 0)
178
+	{
179
+		/** @var int $a */
180
+		$a = ($hi >> 16) & 0xffff;
181
+		/** @var int $b */
182
+		$b = ($hi) & 0xffff;
183
+		/** @var int $c */
184
+		$c = ($lo >> 16) & 0xffff;
185
+		/** @var int $d */
186
+		$d = ($lo & 0xffff);
187
+		return new ParagonIE_Sodium_Core32_Int64(
188
+			array(
189
+				$this->limbs[0] & $a,
190
+				$this->limbs[1] & $b,
191
+				$this->limbs[2] & $c,
192
+				$this->limbs[3] & $d
193
+			),
194
+			$this->unsignedInt
195
+		);
196
+	}
197
+
198
+	/**
199
+	 * @param int $int
200
+	 * @param int $size
201
+	 * @return ParagonIE_Sodium_Core32_Int64
202
+	 * @throws SodiumException
203
+	 * @throws TypeError
204
+	 * @psalm-suppress MixedAssignment
205
+	 */
206
+	public function mulInt($int = 0, $size = 0)
207
+	{
208
+		if (ParagonIE_Sodium_Compat::$fastMult) {
209
+			return $this->mulIntFast($int);
210
+		}
211
+		ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
212
+		ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
213
+		/** @var int $int */
214
+		$int = (int) $int;
215
+		/** @var int $size */
216
+		$size = (int) $size;
217
+
218
+		if (!$size) {
219
+			$size = 63;
220
+		}
221
+
222
+		$a = clone $this;
223
+		$return = new ParagonIE_Sodium_Core32_Int64();
224
+		$return->unsignedInt = $this->unsignedInt;
225
+
226
+		// Initialize:
227
+		$ret0 = 0;
228
+		$ret1 = 0;
229
+		$ret2 = 0;
230
+		$ret3 = 0;
231
+		$a0 = $a->limbs[0];
232
+		$a1 = $a->limbs[1];
233
+		$a2 = $a->limbs[2];
234
+		$a3 = $a->limbs[3];
235
+
236
+		/** @var int $size */
237
+		/** @var int $i */
238
+		for ($i = $size; $i >= 0; --$i) {
239
+			$mask = -($int & 1);
240
+			$x0 = $a0 & $mask;
241
+			$x1 = $a1 & $mask;
242
+			$x2 = $a2 & $mask;
243
+			$x3 = $a3 & $mask;
244
+
245
+			$ret3 += $x3;
246
+			$c = $ret3 >> 16;
247
+
248
+			$ret2 += $x2 + $c;
249
+			$c = $ret2 >> 16;
250
+
251
+			$ret1 += $x1 + $c;
252
+			$c = $ret1 >> 16;
253
+
254
+			$ret0 += $x0 + $c;
255
+
256
+			$ret0 &= 0xffff;
257
+			$ret1 &= 0xffff;
258
+			$ret2 &= 0xffff;
259
+			$ret3 &= 0xffff;
260
+
261
+			$a3 = $a3 << 1;
262
+			$x3 = $a3 >> 16;
263
+			$a2 = ($a2 << 1) | $x3;
264
+			$x2 = $a2 >> 16;
265
+			$a1 = ($a1 << 1) | $x2;
266
+			$x1 = $a1 >> 16;
267
+			$a0 = ($a0 << 1) | $x1;
268
+			$a0 &= 0xffff;
269
+			$a1 &= 0xffff;
270
+			$a2 &= 0xffff;
271
+			$a3 &= 0xffff;
272
+
273
+			$int >>= 1;
274
+		}
275
+		$return->limbs[0] = $ret0;
276
+		$return->limbs[1] = $ret1;
277
+		$return->limbs[2] = $ret2;
278
+		$return->limbs[3] = $ret3;
279
+		return $return;
280
+	}
281
+
282
+	/**
283
+	 * @param ParagonIE_Sodium_Core32_Int64 $A
284
+	 * @param ParagonIE_Sodium_Core32_Int64 $B
285
+	 * @return array<int, ParagonIE_Sodium_Core32_Int64>
286
+	 * @throws SodiumException
287
+	 * @throws TypeError
288
+	 * @psalm-suppress MixedInferredReturnType
289
+	 */
290
+	public static function ctSelect(
291
+		ParagonIE_Sodium_Core32_Int64 $A,
292
+		ParagonIE_Sodium_Core32_Int64 $B
293
+	) {
294
+		$a = clone $A;
295
+		$b = clone $B;
296
+		/** @var int $aNeg */
297
+		$aNeg = ($a->limbs[0] >> 15) & 1;
298
+		/** @var int $bNeg */
299
+		$bNeg = ($b->limbs[0] >> 15) & 1;
300
+		/** @var int $m */
301
+		$m = (-($aNeg & $bNeg)) | 1;
302
+		/** @var int $swap */
303
+		$swap = $bNeg & ~$aNeg;
304
+		/** @var int $d */
305
+		$d = -$swap;
306
+
307
+		/*
308 308
         if ($bNeg && !$aNeg) {
309 309
             $a = clone $int;
310 310
             $b = clone $this;
@@ -313,754 +313,754 @@  discard block
 block discarded – undo
313 313
             $b = $int->mulInt(-1);
314 314
         }
315 315
          */
316
-        $x = $a->xorInt64($b)->mask64($d, $d);
317
-        return array(
318
-            $a->xorInt64($x)->mulInt($m),
319
-            $b->xorInt64($x)->mulInt($m)
320
-        );
321
-    }
322
-
323
-    /**
324
-     * @param array<int, int> $a
325
-     * @param array<int, int> $b
326
-     * @param int $baseLog2
327
-     * @return array<int, int>
328
-     */
329
-    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
330
-    {
331
-        $a_l = count($a);
332
-        $b_l = count($b);
333
-        /** @var array<int, int> $r */
334
-        $r = array_fill(0, $a_l + $b_l + 1, 0);
335
-        $base = 1 << $baseLog2;
336
-        for ($i = 0; $i < $a_l; ++$i) {
337
-            $a_i = $a[$i];
338
-            for ($j = 0; $j < $a_l; ++$j) {
339
-                $b_j = $b[$j];
340
-                $product = ($a_i * $b_j) + $r[$i + $j];
341
-                $carry = ($product >> $baseLog2 & 0xffff);
342
-                $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
343
-                $r[$i + $j + 1] += $carry;
344
-            }
345
-        }
346
-        return array_slice($r, 0, 5);
347
-    }
348
-
349
-    /**
350
-     * @param int $int
351
-     * @return ParagonIE_Sodium_Core32_Int64
352
-     */
353
-    public function mulIntFast($int)
354
-    {
355
-        // Handle negative numbers
356
-        $aNeg = ($this->limbs[0] >> 15) & 1;
357
-        $bNeg = ($int >> 31) & 1;
358
-        $a = array_reverse($this->limbs);
359
-        $b = array(
360
-            $int & 0xffff,
361
-            ($int >> 16) & 0xffff,
362
-            -$bNeg & 0xffff,
363
-            -$bNeg & 0xffff
364
-        );
365
-        if ($aNeg) {
366
-            for ($i = 0; $i < 4; ++$i) {
367
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
368
-            }
369
-            ++$a[0];
370
-        }
371
-        if ($bNeg) {
372
-            for ($i = 0; $i < 4; ++$i) {
373
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
374
-            }
375
-            ++$b[0];
376
-        }
377
-        // Multiply
378
-        $res = $this->multiplyLong($a, $b);
379
-
380
-        // Re-apply negation to results
381
-        if ($aNeg !== $bNeg) {
382
-            for ($i = 0; $i < 4; ++$i) {
383
-                $res[$i] = (0xffff ^ $res[$i]) & 0xffff;
384
-            }
385
-            // Handle integer overflow
386
-            $c = 1;
387
-            for ($i = 0; $i < 4; ++$i) {
388
-                $res[$i] += $c;
389
-                $c = $res[$i] >> 16;
390
-                $res[$i] &= 0xffff;
391
-            }
392
-        }
393
-
394
-        // Return our values
395
-        $return = new ParagonIE_Sodium_Core32_Int64();
396
-        $return->limbs = array(
397
-            $res[3] & 0xffff,
398
-            $res[2] & 0xffff,
399
-            $res[1] & 0xffff,
400
-            $res[0] & 0xffff
401
-        );
402
-        if (count($res) > 4) {
403
-            $return->overflow = $res[4] & 0xffff;
404
-        }
405
-        $return->unsignedInt = $this->unsignedInt;
406
-        return $return;
407
-    }
408
-
409
-    /**
410
-     * @param ParagonIE_Sodium_Core32_Int64 $right
411
-     * @return ParagonIE_Sodium_Core32_Int64
412
-     */
413
-    public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right)
414
-    {
415
-        $aNeg = ($this->limbs[0] >> 15) & 1;
416
-        $bNeg = ($right->limbs[0] >> 15) & 1;
417
-
418
-        $a = array_reverse($this->limbs);
419
-        $b = array_reverse($right->limbs);
420
-        if ($aNeg) {
421
-            for ($i = 0; $i < 4; ++$i) {
422
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
423
-            }
424
-            ++$a[0];
425
-        }
426
-        if ($bNeg) {
427
-            for ($i = 0; $i < 4; ++$i) {
428
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
429
-            }
430
-            ++$b[0];
431
-        }
432
-        $res = $this->multiplyLong($a, $b);
433
-        if ($aNeg !== $bNeg) {
434
-            if ($aNeg !== $bNeg) {
435
-                for ($i = 0; $i < 4; ++$i) {
436
-                    $res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
437
-                }
438
-                $c = 1;
439
-                for ($i = 0; $i < 4; ++$i) {
440
-                    $res[$i] += $c;
441
-                    $c = $res[$i] >> 16;
442
-                    $res[$i] &= 0xffff;
443
-                }
444
-            }
445
-        }
446
-        $return = new ParagonIE_Sodium_Core32_Int64();
447
-        $return->limbs = array(
448
-            $res[3] & 0xffff,
449
-            $res[2] & 0xffff,
450
-            $res[1] & 0xffff,
451
-            $res[0] & 0xffff
452
-        );
453
-        if (count($res) > 4) {
454
-            $return->overflow = $res[4];
455
-        }
456
-        return $return;
457
-    }
458
-
459
-    /**
460
-     * @param ParagonIE_Sodium_Core32_Int64 $int
461
-     * @param int $size
462
-     * @return ParagonIE_Sodium_Core32_Int64
463
-     * @throws SodiumException
464
-     * @throws TypeError
465
-     * @psalm-suppress MixedAssignment
466
-     */
467
-    public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0)
468
-    {
469
-        if (ParagonIE_Sodium_Compat::$fastMult) {
470
-            return $this->mulInt64Fast($int);
471
-        }
472
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
473
-        if (!$size) {
474
-            $size = 63;
475
-        }
476
-        list($a, $b) = self::ctSelect($this, $int);
477
-
478
-        $return = new ParagonIE_Sodium_Core32_Int64();
479
-        $return->unsignedInt = $this->unsignedInt;
480
-
481
-        // Initialize:
482
-        $ret0 = 0;
483
-        $ret1 = 0;
484
-        $ret2 = 0;
485
-        $ret3 = 0;
486
-        $a0 = $a->limbs[0];
487
-        $a1 = $a->limbs[1];
488
-        $a2 = $a->limbs[2];
489
-        $a3 = $a->limbs[3];
490
-        $b0 = $b->limbs[0];
491
-        $b1 = $b->limbs[1];
492
-        $b2 = $b->limbs[2];
493
-        $b3 = $b->limbs[3];
494
-
495
-        /** @var int $size */
496
-        /** @var int $i */
497
-        for ($i = (int) $size; $i >= 0; --$i) {
498
-            $mask = -($b3 & 1);
499
-            $x0 = $a0 & $mask;
500
-            $x1 = $a1 & $mask;
501
-            $x2 = $a2 & $mask;
502
-            $x3 = $a3 & $mask;
503
-
504
-            $ret3 += $x3;
505
-            $c = $ret3 >> 16;
506
-
507
-            $ret2 += $x2 + $c;
508
-            $c = $ret2 >> 16;
509
-
510
-            $ret1 += $x1 + $c;
511
-            $c = $ret1 >> 16;
512
-
513
-            $ret0 += $x0 + $c;
514
-
515
-            $ret0 &= 0xffff;
516
-            $ret1 &= 0xffff;
517
-            $ret2 &= 0xffff;
518
-            $ret3 &= 0xffff;
519
-
520
-            $a3 = $a3 << 1;
521
-            $x3 = $a3 >> 16;
522
-            $a2 = ($a2 << 1) | $x3;
523
-            $x2 = $a2 >> 16;
524
-            $a1 = ($a1 << 1) | $x2;
525
-            $x1 = $a1 >> 16;
526
-            $a0 = ($a0 << 1) | $x1;
527
-            $a0 &= 0xffff;
528
-            $a1 &= 0xffff;
529
-            $a2 &= 0xffff;
530
-            $a3 &= 0xffff;
531
-
532
-            $x0 = ($b0 & 1) << 16;
533
-            $x1 = ($b1 & 1) << 16;
534
-            $x2 = ($b2 & 1) << 16;
535
-
536
-            $b0 = ($b0 >> 1);
537
-            $b1 = (($b1 | $x0) >> 1);
538
-            $b2 = (($b2 | $x1) >> 1);
539
-            $b3 = (($b3 | $x2) >> 1);
540
-
541
-            $b0 &= 0xffff;
542
-            $b1 &= 0xffff;
543
-            $b2 &= 0xffff;
544
-            $b3 &= 0xffff;
545
-
546
-        }
547
-        $return->limbs[0] = $ret0;
548
-        $return->limbs[1] = $ret1;
549
-        $return->limbs[2] = $ret2;
550
-        $return->limbs[3] = $ret3;
551
-
552
-        return $return;
553
-    }
554
-
555
-    /**
556
-     * OR this 64-bit integer with another.
557
-     *
558
-     * @param ParagonIE_Sodium_Core32_Int64 $b
559
-     * @return ParagonIE_Sodium_Core32_Int64
560
-     */
561
-    public function orInt64(ParagonIE_Sodium_Core32_Int64 $b)
562
-    {
563
-        $return = new ParagonIE_Sodium_Core32_Int64();
564
-        $return->unsignedInt = $this->unsignedInt;
565
-        $return->limbs = array(
566
-            (int) ($this->limbs[0] | $b->limbs[0]),
567
-            (int) ($this->limbs[1] | $b->limbs[1]),
568
-            (int) ($this->limbs[2] | $b->limbs[2]),
569
-            (int) ($this->limbs[3] | $b->limbs[3])
570
-        );
571
-        return $return;
572
-    }
573
-
574
-    /**
575
-     * @param int $c
576
-     * @return ParagonIE_Sodium_Core32_Int64
577
-     * @throws SodiumException
578
-     * @throws TypeError
579
-     * @psalm-suppress MixedArrayAccess
580
-     */
581
-    public function rotateLeft($c = 0)
582
-    {
583
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
584
-        /** @var int $c */
585
-        $c = (int) $c;
586
-
587
-        $return = new ParagonIE_Sodium_Core32_Int64();
588
-        $return->unsignedInt = $this->unsignedInt;
589
-        $c &= 63;
590
-        if ($c === 0) {
591
-            // NOP, but we want a copy.
592
-            $return->limbs = $this->limbs;
593
-        } else {
594
-            /** @var array<int, int> $limbs */
595
-            $limbs =& $return->limbs;
596
-
597
-            /** @var array<int, int> $myLimbs */
598
-            $myLimbs =& $this->limbs;
599
-
600
-            /** @var int $idx_shift */
601
-            $idx_shift = ($c >> 4) & 3;
602
-            /** @var int $sub_shift */
603
-            $sub_shift = $c & 15;
604
-
605
-            for ($i = 3; $i >= 0; --$i) {
606
-                /** @var int $j */
607
-                $j = ($i + $idx_shift) & 3;
608
-                /** @var int $k */
609
-                $k = ($i + $idx_shift + 1) & 3;
610
-                $limbs[$i] = (int) (
611
-                    (
612
-                        ((int) ($myLimbs[$j]) << $sub_shift)
613
-                            |
614
-                        ((int) ($myLimbs[$k]) >> (16 - $sub_shift))
615
-                    ) & 0xffff
616
-                );
617
-            }
618
-        }
619
-        return $return;
620
-    }
621
-
622
-    /**
623
-     * Rotate to the right
624
-     *
625
-     * @param int $c
626
-     * @return ParagonIE_Sodium_Core32_Int64
627
-     * @throws SodiumException
628
-     * @throws TypeError
629
-     * @psalm-suppress MixedArrayAccess
630
-     */
631
-    public function rotateRight($c = 0)
632
-    {
633
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
634
-        /** @var int $c */
635
-        $c = (int) $c;
636
-
637
-        /** @var ParagonIE_Sodium_Core32_Int64 $return */
638
-        $return = new ParagonIE_Sodium_Core32_Int64();
639
-        $return->unsignedInt = $this->unsignedInt;
640
-        $c &= 63;
641
-        /** @var int $c */
642
-        if ($c === 0) {
643
-            // NOP, but we want a copy.
644
-            $return->limbs = $this->limbs;
645
-        } else {
646
-            /** @var array<int, int> $limbs */
647
-            $limbs =& $return->limbs;
648
-
649
-            /** @var array<int, int> $myLimbs */
650
-            $myLimbs =& $this->limbs;
651
-
652
-            /** @var int $idx_shift */
653
-            $idx_shift = ($c >> 4) & 3;
654
-            /** @var int $sub_shift */
655
-            $sub_shift = $c & 15;
656
-
657
-            for ($i = 3; $i >= 0; --$i) {
658
-                /** @var int $j */
659
-                $j = ($i - $idx_shift) & 3;
660
-                /** @var int $k */
661
-                $k = ($i - $idx_shift - 1) & 3;
662
-                $limbs[$i] = (int) (
663
-                    (
664
-                        ((int) ($myLimbs[$j]) >> (int) ($sub_shift))
665
-                            |
666
-                        ((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
667
-                    ) & 0xffff
668
-                );
669
-            }
670
-        }
671
-        return $return;
672
-    }
673
-    /**
674
-     * @param int $c
675
-     * @return ParagonIE_Sodium_Core32_Int64
676
-     * @throws SodiumException
677
-     * @throws TypeError
678
-     */
679
-    public function shiftLeft($c = 0)
680
-    {
681
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
682
-        /** @var int $c */
683
-        $c = (int) $c;
684
-
685
-        $return = new ParagonIE_Sodium_Core32_Int64();
686
-        $return->unsignedInt = $this->unsignedInt;
687
-        $c &= 63;
688
-
689
-        if ($c >= 16) {
690
-            if ($c >= 48) {
691
-                $return->limbs = array(
692
-                    $this->limbs[3], 0, 0, 0
693
-                );
694
-            } elseif ($c >= 32) {
695
-                $return->limbs = array(
696
-                    $this->limbs[2], $this->limbs[3], 0, 0
697
-                );
698
-            } else {
699
-                $return->limbs = array(
700
-                    $this->limbs[1], $this->limbs[2], $this->limbs[3], 0
701
-                );
702
-            }
703
-            return $return->shiftLeft($c & 15);
704
-        }
705
-        if ($c === 0) {
706
-            $return->limbs = $this->limbs;
707
-        } elseif ($c < 0) {
708
-            /** @var int $c */
709
-            return $this->shiftRight(-$c);
710
-        } else {
711
-            if (!is_int($c)) {
712
-                throw new TypeError();
713
-            }
714
-            /** @var int $carry */
715
-            $carry = 0;
716
-            for ($i = 3; $i >= 0; --$i) {
717
-                /** @var int $tmp */
718
-                $tmp = ($this->limbs[$i] << $c) | ($carry & 0xffff);
719
-                $return->limbs[$i] = (int) ($tmp & 0xffff);
720
-                /** @var int $carry */
721
-                $carry = $tmp >> 16;
722
-            }
723
-        }
724
-        return $return;
725
-    }
726
-
727
-    /**
728
-     * @param int $c
729
-     * @return ParagonIE_Sodium_Core32_Int64
730
-     * @throws SodiumException
731
-     * @throws TypeError
732
-     */
733
-    public function shiftRight($c = 0)
734
-    {
735
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
736
-        $c = (int) $c;
737
-        /** @var int $c */
738
-        $return = new ParagonIE_Sodium_Core32_Int64();
739
-        $return->unsignedInt = $this->unsignedInt;
740
-        $c &= 63;
741
-
742
-        $negative = -(($this->limbs[0] >> 15) & 1);
743
-        if ($c >= 16) {
744
-            if ($c >= 48) {
745
-                $return->limbs = array(
746
-                    (int) ($negative & 0xffff),
747
-                    (int) ($negative & 0xffff),
748
-                    (int) ($negative & 0xffff),
749
-                    (int) $this->limbs[0]
750
-                );
751
-            } elseif ($c >= 32) {
752
-                $return->limbs = array(
753
-                    (int) ($negative & 0xffff),
754
-                    (int) ($negative & 0xffff),
755
-                    (int) $this->limbs[0],
756
-                    (int) $this->limbs[1]
757
-                );
758
-            } else {
759
-                $return->limbs = array(
760
-                    (int) ($negative & 0xffff),
761
-                    (int) $this->limbs[0],
762
-                    (int) $this->limbs[1],
763
-                    (int) $this->limbs[2]
764
-                );
765
-            }
766
-            return $return->shiftRight($c & 15);
767
-        }
768
-
769
-        if ($c === 0) {
770
-            $return->limbs = $this->limbs;
771
-        } elseif ($c < 0) {
772
-            return $this->shiftLeft(-$c);
773
-        } else {
774
-            if (!is_int($c)) {
775
-                throw new TypeError();
776
-            }
777
-            /** @var int $carryRight */
778
-            $carryRight = ($negative & 0xffff);
779
-            $mask = (int) (((1 << ($c + 1)) - 1) & 0xffff);
780
-            for ($i = 0; $i < 4; ++$i) {
781
-                $return->limbs[$i] = (int) (
782
-                    (($this->limbs[$i] >> $c) | ($carryRight << (16 - $c))) & 0xffff
783
-                );
784
-                $carryRight = (int) ($this->limbs[$i] & $mask);
785
-            }
786
-        }
787
-        return $return;
788
-    }
789
-
790
-
791
-    /**
792
-     * Subtract a normal integer from an int64 object.
793
-     *
794
-     * @param int $int
795
-     * @return ParagonIE_Sodium_Core32_Int64
796
-     * @throws SodiumException
797
-     * @throws TypeError
798
-     */
799
-    public function subInt($int)
800
-    {
801
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
802
-        $int = (int) $int;
803
-
804
-        $return = new ParagonIE_Sodium_Core32_Int64();
805
-        $return->unsignedInt = $this->unsignedInt;
806
-
807
-        /** @var int $carry */
808
-        $carry = 0;
809
-        for ($i = 3; $i >= 0; --$i) {
810
-            /** @var int $tmp */
811
-            $tmp = $this->limbs[$i] - (($int >> 16) & 0xffff) + $carry;
812
-            /** @var int $carry */
813
-            $carry = $tmp >> 16;
814
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
815
-        }
816
-        return $return;
817
-    }
818
-
819
-    /**
820
-     * The difference between two Int64 objects.
821
-     *
822
-     * @param ParagonIE_Sodium_Core32_Int64 $b
823
-     * @return ParagonIE_Sodium_Core32_Int64
824
-     */
825
-    public function subInt64(ParagonIE_Sodium_Core32_Int64 $b)
826
-    {
827
-        $return = new ParagonIE_Sodium_Core32_Int64();
828
-        $return->unsignedInt = $this->unsignedInt;
829
-        /** @var int $carry */
830
-        $carry = 0;
831
-        for ($i = 3; $i >= 0; --$i) {
832
-            /** @var int $tmp */
833
-            $tmp = $this->limbs[$i] - $b->limbs[$i] + $carry;
834
-            /** @var int $carry */
835
-            $carry = ($tmp >> 16);
836
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
837
-        }
838
-        return $return;
839
-    }
840
-
841
-    /**
842
-     * XOR this 64-bit integer with another.
843
-     *
844
-     * @param ParagonIE_Sodium_Core32_Int64 $b
845
-     * @return ParagonIE_Sodium_Core32_Int64
846
-     */
847
-    public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b)
848
-    {
849
-        $return = new ParagonIE_Sodium_Core32_Int64();
850
-        $return->unsignedInt = $this->unsignedInt;
851
-        $return->limbs = array(
852
-            (int) ($this->limbs[0] ^ $b->limbs[0]),
853
-            (int) ($this->limbs[1] ^ $b->limbs[1]),
854
-            (int) ($this->limbs[2] ^ $b->limbs[2]),
855
-            (int) ($this->limbs[3] ^ $b->limbs[3])
856
-        );
857
-        return $return;
858
-    }
859
-
860
-    /**
861
-     * @param int $low
862
-     * @param int $high
863
-     * @return self
864
-     * @throws SodiumException
865
-     * @throws TypeError
866
-     */
867
-    public static function fromInts($low, $high)
868
-    {
869
-        ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
870
-        ParagonIE_Sodium_Core32_Util::declareScalarType($high, 'int', 2);
871
-
872
-        $high = (int) $high;
873
-        $low = (int) $low;
874
-        return new ParagonIE_Sodium_Core32_Int64(
875
-            array(
876
-                (int) (($high >> 16) & 0xffff),
877
-                (int) ($high & 0xffff),
878
-                (int) (($low >> 16) & 0xffff),
879
-                (int) ($low & 0xffff)
880
-            )
881
-        );
882
-    }
883
-
884
-    /**
885
-     * @param int $low
886
-     * @return self
887
-     * @throws SodiumException
888
-     * @throws TypeError
889
-     */
890
-    public static function fromInt($low)
891
-    {
892
-        ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
893
-        $low = (int) $low;
894
-
895
-        return new ParagonIE_Sodium_Core32_Int64(
896
-            array(
897
-                0,
898
-                0,
899
-                (int) (($low >> 16) & 0xffff),
900
-                (int) ($low & 0xffff)
901
-            )
902
-        );
903
-    }
904
-
905
-    /**
906
-     * @return int
907
-     */
908
-    public function toInt()
909
-    {
910
-        return (int) (
911
-            (($this->limbs[2] & 0xffff) << 16)
912
-                |
913
-            ($this->limbs[3] & 0xffff)
914
-        );
915
-    }
916
-
917
-    /**
918
-     * @param string $string
919
-     * @return self
920
-     * @throws SodiumException
921
-     * @throws TypeError
922
-     */
923
-    public static function fromString($string)
924
-    {
925
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
926
-        $string = (string) $string;
927
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
928
-            throw new RangeException(
929
-                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
930
-            );
931
-        }
932
-        $return = new ParagonIE_Sodium_Core32_Int64();
933
-
934
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
935
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
936
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
937
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
938
-        $return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff) << 8);
939
-        $return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff);
940
-        $return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff) << 8);
941
-        $return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff);
942
-        return $return;
943
-    }
944
-
945
-    /**
946
-     * @param string $string
947
-     * @return self
948
-     * @throws SodiumException
949
-     * @throws TypeError
950
-     */
951
-    public static function fromReverseString($string)
952
-    {
953
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
954
-        $string = (string) $string;
955
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
956
-            throw new RangeException(
957
-                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
958
-            );
959
-        }
960
-        $return = new ParagonIE_Sodium_Core32_Int64();
961
-
962
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff) << 8);
963
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff);
964
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff) << 8);
965
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff);
966
-        $return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
967
-        $return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
968
-        $return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
969
-        $return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
970
-        return $return;
971
-    }
972
-
973
-    /**
974
-     * @return array<int, int>
975
-     */
976
-    public function toArray()
977
-    {
978
-        return array(
979
-            (int) ((($this->limbs[0] & 0xffff) << 16) | ($this->limbs[1] & 0xffff)),
980
-            (int) ((($this->limbs[2] & 0xffff) << 16) | ($this->limbs[3] & 0xffff))
981
-        );
982
-    }
983
-
984
-    /**
985
-     * @return ParagonIE_Sodium_Core32_Int32
986
-     */
987
-    public function toInt32()
988
-    {
989
-        $return = new ParagonIE_Sodium_Core32_Int32();
990
-        $return->limbs[0] = (int) ($this->limbs[2]);
991
-        $return->limbs[1] = (int) ($this->limbs[3]);
992
-        $return->unsignedInt = $this->unsignedInt;
993
-        $return->overflow = (int) (ParagonIE_Sodium_Core32_Util::abs($this->limbs[1], 16) & 0xffff);
994
-        return $return;
995
-    }
996
-
997
-    /**
998
-     * @return ParagonIE_Sodium_Core32_Int64
999
-     */
1000
-    public function toInt64()
1001
-    {
1002
-        $return = new ParagonIE_Sodium_Core32_Int64();
1003
-        $return->limbs[0] = (int) ($this->limbs[0]);
1004
-        $return->limbs[1] = (int) ($this->limbs[1]);
1005
-        $return->limbs[2] = (int) ($this->limbs[2]);
1006
-        $return->limbs[3] = (int) ($this->limbs[3]);
1007
-        $return->unsignedInt = $this->unsignedInt;
1008
-        $return->overflow = ParagonIE_Sodium_Core32_Util::abs($this->overflow);
1009
-        return $return;
1010
-    }
1011
-
1012
-    /**
1013
-     * @param bool $bool
1014
-     * @return self
1015
-     */
1016
-    public function setUnsignedInt($bool = false)
1017
-    {
1018
-        $this->unsignedInt = !empty($bool);
1019
-        return $this;
1020
-    }
1021
-
1022
-    /**
1023
-     * @return string
1024
-     * @throws TypeError
1025
-     */
1026
-    public function toString()
1027
-    {
1028
-        return ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
1029
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1030
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
1031
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
1032
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
1033
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
1034
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1035
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff);
1036
-    }
1037
-
1038
-    /**
1039
-     * @return string
1040
-     * @throws TypeError
1041
-     */
1042
-    public function toReverseString()
1043
-    {
1044
-        return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff) .
1045
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1046
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
1047
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
1048
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
1049
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
1050
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1051
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
1052
-    }
1053
-
1054
-    /**
1055
-     * @return string
1056
-     */
1057
-    public function __toString()
1058
-    {
1059
-        try {
1060
-            return $this->toString();
1061
-        } catch (TypeError $ex) {
1062
-            // PHP engine can't handle exceptions from __toString()
1063
-            return '';
1064
-        }
1065
-    }
316
+		$x = $a->xorInt64($b)->mask64($d, $d);
317
+		return array(
318
+			$a->xorInt64($x)->mulInt($m),
319
+			$b->xorInt64($x)->mulInt($m)
320
+		);
321
+	}
322
+
323
+	/**
324
+	 * @param array<int, int> $a
325
+	 * @param array<int, int> $b
326
+	 * @param int $baseLog2
327
+	 * @return array<int, int>
328
+	 */
329
+	public function multiplyLong(array $a, array $b, $baseLog2 = 16)
330
+	{
331
+		$a_l = count($a);
332
+		$b_l = count($b);
333
+		/** @var array<int, int> $r */
334
+		$r = array_fill(0, $a_l + $b_l + 1, 0);
335
+		$base = 1 << $baseLog2;
336
+		for ($i = 0; $i < $a_l; ++$i) {
337
+			$a_i = $a[$i];
338
+			for ($j = 0; $j < $a_l; ++$j) {
339
+				$b_j = $b[$j];
340
+				$product = ($a_i * $b_j) + $r[$i + $j];
341
+				$carry = ($product >> $baseLog2 & 0xffff);
342
+				$r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
343
+				$r[$i + $j + 1] += $carry;
344
+			}
345
+		}
346
+		return array_slice($r, 0, 5);
347
+	}
348
+
349
+	/**
350
+	 * @param int $int
351
+	 * @return ParagonIE_Sodium_Core32_Int64
352
+	 */
353
+	public function mulIntFast($int)
354
+	{
355
+		// Handle negative numbers
356
+		$aNeg = ($this->limbs[0] >> 15) & 1;
357
+		$bNeg = ($int >> 31) & 1;
358
+		$a = array_reverse($this->limbs);
359
+		$b = array(
360
+			$int & 0xffff,
361
+			($int >> 16) & 0xffff,
362
+			-$bNeg & 0xffff,
363
+			-$bNeg & 0xffff
364
+		);
365
+		if ($aNeg) {
366
+			for ($i = 0; $i < 4; ++$i) {
367
+				$a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
368
+			}
369
+			++$a[0];
370
+		}
371
+		if ($bNeg) {
372
+			for ($i = 0; $i < 4; ++$i) {
373
+				$b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
374
+			}
375
+			++$b[0];
376
+		}
377
+		// Multiply
378
+		$res = $this->multiplyLong($a, $b);
379
+
380
+		// Re-apply negation to results
381
+		if ($aNeg !== $bNeg) {
382
+			for ($i = 0; $i < 4; ++$i) {
383
+				$res[$i] = (0xffff ^ $res[$i]) & 0xffff;
384
+			}
385
+			// Handle integer overflow
386
+			$c = 1;
387
+			for ($i = 0; $i < 4; ++$i) {
388
+				$res[$i] += $c;
389
+				$c = $res[$i] >> 16;
390
+				$res[$i] &= 0xffff;
391
+			}
392
+		}
393
+
394
+		// Return our values
395
+		$return = new ParagonIE_Sodium_Core32_Int64();
396
+		$return->limbs = array(
397
+			$res[3] & 0xffff,
398
+			$res[2] & 0xffff,
399
+			$res[1] & 0xffff,
400
+			$res[0] & 0xffff
401
+		);
402
+		if (count($res) > 4) {
403
+			$return->overflow = $res[4] & 0xffff;
404
+		}
405
+		$return->unsignedInt = $this->unsignedInt;
406
+		return $return;
407
+	}
408
+
409
+	/**
410
+	 * @param ParagonIE_Sodium_Core32_Int64 $right
411
+	 * @return ParagonIE_Sodium_Core32_Int64
412
+	 */
413
+	public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right)
414
+	{
415
+		$aNeg = ($this->limbs[0] >> 15) & 1;
416
+		$bNeg = ($right->limbs[0] >> 15) & 1;
417
+
418
+		$a = array_reverse($this->limbs);
419
+		$b = array_reverse($right->limbs);
420
+		if ($aNeg) {
421
+			for ($i = 0; $i < 4; ++$i) {
422
+				$a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
423
+			}
424
+			++$a[0];
425
+		}
426
+		if ($bNeg) {
427
+			for ($i = 0; $i < 4; ++$i) {
428
+				$b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
429
+			}
430
+			++$b[0];
431
+		}
432
+		$res = $this->multiplyLong($a, $b);
433
+		if ($aNeg !== $bNeg) {
434
+			if ($aNeg !== $bNeg) {
435
+				for ($i = 0; $i < 4; ++$i) {
436
+					$res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
437
+				}
438
+				$c = 1;
439
+				for ($i = 0; $i < 4; ++$i) {
440
+					$res[$i] += $c;
441
+					$c = $res[$i] >> 16;
442
+					$res[$i] &= 0xffff;
443
+				}
444
+			}
445
+		}
446
+		$return = new ParagonIE_Sodium_Core32_Int64();
447
+		$return->limbs = array(
448
+			$res[3] & 0xffff,
449
+			$res[2] & 0xffff,
450
+			$res[1] & 0xffff,
451
+			$res[0] & 0xffff
452
+		);
453
+		if (count($res) > 4) {
454
+			$return->overflow = $res[4];
455
+		}
456
+		return $return;
457
+	}
458
+
459
+	/**
460
+	 * @param ParagonIE_Sodium_Core32_Int64 $int
461
+	 * @param int $size
462
+	 * @return ParagonIE_Sodium_Core32_Int64
463
+	 * @throws SodiumException
464
+	 * @throws TypeError
465
+	 * @psalm-suppress MixedAssignment
466
+	 */
467
+	public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0)
468
+	{
469
+		if (ParagonIE_Sodium_Compat::$fastMult) {
470
+			return $this->mulInt64Fast($int);
471
+		}
472
+		ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
473
+		if (!$size) {
474
+			$size = 63;
475
+		}
476
+		list($a, $b) = self::ctSelect($this, $int);
477
+
478
+		$return = new ParagonIE_Sodium_Core32_Int64();
479
+		$return->unsignedInt = $this->unsignedInt;
480
+
481
+		// Initialize:
482
+		$ret0 = 0;
483
+		$ret1 = 0;
484
+		$ret2 = 0;
485
+		$ret3 = 0;
486
+		$a0 = $a->limbs[0];
487
+		$a1 = $a->limbs[1];
488
+		$a2 = $a->limbs[2];
489
+		$a3 = $a->limbs[3];
490
+		$b0 = $b->limbs[0];
491
+		$b1 = $b->limbs[1];
492
+		$b2 = $b->limbs[2];
493
+		$b3 = $b->limbs[3];
494
+
495
+		/** @var int $size */
496
+		/** @var int $i */
497
+		for ($i = (int) $size; $i >= 0; --$i) {
498
+			$mask = -($b3 & 1);
499
+			$x0 = $a0 & $mask;
500
+			$x1 = $a1 & $mask;
501
+			$x2 = $a2 & $mask;
502
+			$x3 = $a3 & $mask;
503
+
504
+			$ret3 += $x3;
505
+			$c = $ret3 >> 16;
506
+
507
+			$ret2 += $x2 + $c;
508
+			$c = $ret2 >> 16;
509
+
510
+			$ret1 += $x1 + $c;
511
+			$c = $ret1 >> 16;
512
+
513
+			$ret0 += $x0 + $c;
514
+
515
+			$ret0 &= 0xffff;
516
+			$ret1 &= 0xffff;
517
+			$ret2 &= 0xffff;
518
+			$ret3 &= 0xffff;
519
+
520
+			$a3 = $a3 << 1;
521
+			$x3 = $a3 >> 16;
522
+			$a2 = ($a2 << 1) | $x3;
523
+			$x2 = $a2 >> 16;
524
+			$a1 = ($a1 << 1) | $x2;
525
+			$x1 = $a1 >> 16;
526
+			$a0 = ($a0 << 1) | $x1;
527
+			$a0 &= 0xffff;
528
+			$a1 &= 0xffff;
529
+			$a2 &= 0xffff;
530
+			$a3 &= 0xffff;
531
+
532
+			$x0 = ($b0 & 1) << 16;
533
+			$x1 = ($b1 & 1) << 16;
534
+			$x2 = ($b2 & 1) << 16;
535
+
536
+			$b0 = ($b0 >> 1);
537
+			$b1 = (($b1 | $x0) >> 1);
538
+			$b2 = (($b2 | $x1) >> 1);
539
+			$b3 = (($b3 | $x2) >> 1);
540
+
541
+			$b0 &= 0xffff;
542
+			$b1 &= 0xffff;
543
+			$b2 &= 0xffff;
544
+			$b3 &= 0xffff;
545
+
546
+		}
547
+		$return->limbs[0] = $ret0;
548
+		$return->limbs[1] = $ret1;
549
+		$return->limbs[2] = $ret2;
550
+		$return->limbs[3] = $ret3;
551
+
552
+		return $return;
553
+	}
554
+
555
+	/**
556
+	 * OR this 64-bit integer with another.
557
+	 *
558
+	 * @param ParagonIE_Sodium_Core32_Int64 $b
559
+	 * @return ParagonIE_Sodium_Core32_Int64
560
+	 */
561
+	public function orInt64(ParagonIE_Sodium_Core32_Int64 $b)
562
+	{
563
+		$return = new ParagonIE_Sodium_Core32_Int64();
564
+		$return->unsignedInt = $this->unsignedInt;
565
+		$return->limbs = array(
566
+			(int) ($this->limbs[0] | $b->limbs[0]),
567
+			(int) ($this->limbs[1] | $b->limbs[1]),
568
+			(int) ($this->limbs[2] | $b->limbs[2]),
569
+			(int) ($this->limbs[3] | $b->limbs[3])
570
+		);
571
+		return $return;
572
+	}
573
+
574
+	/**
575
+	 * @param int $c
576
+	 * @return ParagonIE_Sodium_Core32_Int64
577
+	 * @throws SodiumException
578
+	 * @throws TypeError
579
+	 * @psalm-suppress MixedArrayAccess
580
+	 */
581
+	public function rotateLeft($c = 0)
582
+	{
583
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
584
+		/** @var int $c */
585
+		$c = (int) $c;
586
+
587
+		$return = new ParagonIE_Sodium_Core32_Int64();
588
+		$return->unsignedInt = $this->unsignedInt;
589
+		$c &= 63;
590
+		if ($c === 0) {
591
+			// NOP, but we want a copy.
592
+			$return->limbs = $this->limbs;
593
+		} else {
594
+			/** @var array<int, int> $limbs */
595
+			$limbs =& $return->limbs;
596
+
597
+			/** @var array<int, int> $myLimbs */
598
+			$myLimbs =& $this->limbs;
599
+
600
+			/** @var int $idx_shift */
601
+			$idx_shift = ($c >> 4) & 3;
602
+			/** @var int $sub_shift */
603
+			$sub_shift = $c & 15;
604
+
605
+			for ($i = 3; $i >= 0; --$i) {
606
+				/** @var int $j */
607
+				$j = ($i + $idx_shift) & 3;
608
+				/** @var int $k */
609
+				$k = ($i + $idx_shift + 1) & 3;
610
+				$limbs[$i] = (int) (
611
+					(
612
+						((int) ($myLimbs[$j]) << $sub_shift)
613
+							|
614
+						((int) ($myLimbs[$k]) >> (16 - $sub_shift))
615
+					) & 0xffff
616
+				);
617
+			}
618
+		}
619
+		return $return;
620
+	}
621
+
622
+	/**
623
+	 * Rotate to the right
624
+	 *
625
+	 * @param int $c
626
+	 * @return ParagonIE_Sodium_Core32_Int64
627
+	 * @throws SodiumException
628
+	 * @throws TypeError
629
+	 * @psalm-suppress MixedArrayAccess
630
+	 */
631
+	public function rotateRight($c = 0)
632
+	{
633
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
634
+		/** @var int $c */
635
+		$c = (int) $c;
636
+
637
+		/** @var ParagonIE_Sodium_Core32_Int64 $return */
638
+		$return = new ParagonIE_Sodium_Core32_Int64();
639
+		$return->unsignedInt = $this->unsignedInt;
640
+		$c &= 63;
641
+		/** @var int $c */
642
+		if ($c === 0) {
643
+			// NOP, but we want a copy.
644
+			$return->limbs = $this->limbs;
645
+		} else {
646
+			/** @var array<int, int> $limbs */
647
+			$limbs =& $return->limbs;
648
+
649
+			/** @var array<int, int> $myLimbs */
650
+			$myLimbs =& $this->limbs;
651
+
652
+			/** @var int $idx_shift */
653
+			$idx_shift = ($c >> 4) & 3;
654
+			/** @var int $sub_shift */
655
+			$sub_shift = $c & 15;
656
+
657
+			for ($i = 3; $i >= 0; --$i) {
658
+				/** @var int $j */
659
+				$j = ($i - $idx_shift) & 3;
660
+				/** @var int $k */
661
+				$k = ($i - $idx_shift - 1) & 3;
662
+				$limbs[$i] = (int) (
663
+					(
664
+						((int) ($myLimbs[$j]) >> (int) ($sub_shift))
665
+							|
666
+						((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
667
+					) & 0xffff
668
+				);
669
+			}
670
+		}
671
+		return $return;
672
+	}
673
+	/**
674
+	 * @param int $c
675
+	 * @return ParagonIE_Sodium_Core32_Int64
676
+	 * @throws SodiumException
677
+	 * @throws TypeError
678
+	 */
679
+	public function shiftLeft($c = 0)
680
+	{
681
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
682
+		/** @var int $c */
683
+		$c = (int) $c;
684
+
685
+		$return = new ParagonIE_Sodium_Core32_Int64();
686
+		$return->unsignedInt = $this->unsignedInt;
687
+		$c &= 63;
688
+
689
+		if ($c >= 16) {
690
+			if ($c >= 48) {
691
+				$return->limbs = array(
692
+					$this->limbs[3], 0, 0, 0
693
+				);
694
+			} elseif ($c >= 32) {
695
+				$return->limbs = array(
696
+					$this->limbs[2], $this->limbs[3], 0, 0
697
+				);
698
+			} else {
699
+				$return->limbs = array(
700
+					$this->limbs[1], $this->limbs[2], $this->limbs[3], 0
701
+				);
702
+			}
703
+			return $return->shiftLeft($c & 15);
704
+		}
705
+		if ($c === 0) {
706
+			$return->limbs = $this->limbs;
707
+		} elseif ($c < 0) {
708
+			/** @var int $c */
709
+			return $this->shiftRight(-$c);
710
+		} else {
711
+			if (!is_int($c)) {
712
+				throw new TypeError();
713
+			}
714
+			/** @var int $carry */
715
+			$carry = 0;
716
+			for ($i = 3; $i >= 0; --$i) {
717
+				/** @var int $tmp */
718
+				$tmp = ($this->limbs[$i] << $c) | ($carry & 0xffff);
719
+				$return->limbs[$i] = (int) ($tmp & 0xffff);
720
+				/** @var int $carry */
721
+				$carry = $tmp >> 16;
722
+			}
723
+		}
724
+		return $return;
725
+	}
726
+
727
+	/**
728
+	 * @param int $c
729
+	 * @return ParagonIE_Sodium_Core32_Int64
730
+	 * @throws SodiumException
731
+	 * @throws TypeError
732
+	 */
733
+	public function shiftRight($c = 0)
734
+	{
735
+		ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
736
+		$c = (int) $c;
737
+		/** @var int $c */
738
+		$return = new ParagonIE_Sodium_Core32_Int64();
739
+		$return->unsignedInt = $this->unsignedInt;
740
+		$c &= 63;
741
+
742
+		$negative = -(($this->limbs[0] >> 15) & 1);
743
+		if ($c >= 16) {
744
+			if ($c >= 48) {
745
+				$return->limbs = array(
746
+					(int) ($negative & 0xffff),
747
+					(int) ($negative & 0xffff),
748
+					(int) ($negative & 0xffff),
749
+					(int) $this->limbs[0]
750
+				);
751
+			} elseif ($c >= 32) {
752
+				$return->limbs = array(
753
+					(int) ($negative & 0xffff),
754
+					(int) ($negative & 0xffff),
755
+					(int) $this->limbs[0],
756
+					(int) $this->limbs[1]
757
+				);
758
+			} else {
759
+				$return->limbs = array(
760
+					(int) ($negative & 0xffff),
761
+					(int) $this->limbs[0],
762
+					(int) $this->limbs[1],
763
+					(int) $this->limbs[2]
764
+				);
765
+			}
766
+			return $return->shiftRight($c & 15);
767
+		}
768
+
769
+		if ($c === 0) {
770
+			$return->limbs = $this->limbs;
771
+		} elseif ($c < 0) {
772
+			return $this->shiftLeft(-$c);
773
+		} else {
774
+			if (!is_int($c)) {
775
+				throw new TypeError();
776
+			}
777
+			/** @var int $carryRight */
778
+			$carryRight = ($negative & 0xffff);
779
+			$mask = (int) (((1 << ($c + 1)) - 1) & 0xffff);
780
+			for ($i = 0; $i < 4; ++$i) {
781
+				$return->limbs[$i] = (int) (
782
+					(($this->limbs[$i] >> $c) | ($carryRight << (16 - $c))) & 0xffff
783
+				);
784
+				$carryRight = (int) ($this->limbs[$i] & $mask);
785
+			}
786
+		}
787
+		return $return;
788
+	}
789
+
790
+
791
+	/**
792
+	 * Subtract a normal integer from an int64 object.
793
+	 *
794
+	 * @param int $int
795
+	 * @return ParagonIE_Sodium_Core32_Int64
796
+	 * @throws SodiumException
797
+	 * @throws TypeError
798
+	 */
799
+	public function subInt($int)
800
+	{
801
+		ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
802
+		$int = (int) $int;
803
+
804
+		$return = new ParagonIE_Sodium_Core32_Int64();
805
+		$return->unsignedInt = $this->unsignedInt;
806
+
807
+		/** @var int $carry */
808
+		$carry = 0;
809
+		for ($i = 3; $i >= 0; --$i) {
810
+			/** @var int $tmp */
811
+			$tmp = $this->limbs[$i] - (($int >> 16) & 0xffff) + $carry;
812
+			/** @var int $carry */
813
+			$carry = $tmp >> 16;
814
+			$return->limbs[$i] = (int) ($tmp & 0xffff);
815
+		}
816
+		return $return;
817
+	}
818
+
819
+	/**
820
+	 * The difference between two Int64 objects.
821
+	 *
822
+	 * @param ParagonIE_Sodium_Core32_Int64 $b
823
+	 * @return ParagonIE_Sodium_Core32_Int64
824
+	 */
825
+	public function subInt64(ParagonIE_Sodium_Core32_Int64 $b)
826
+	{
827
+		$return = new ParagonIE_Sodium_Core32_Int64();
828
+		$return->unsignedInt = $this->unsignedInt;
829
+		/** @var int $carry */
830
+		$carry = 0;
831
+		for ($i = 3; $i >= 0; --$i) {
832
+			/** @var int $tmp */
833
+			$tmp = $this->limbs[$i] - $b->limbs[$i] + $carry;
834
+			/** @var int $carry */
835
+			$carry = ($tmp >> 16);
836
+			$return->limbs[$i] = (int) ($tmp & 0xffff);
837
+		}
838
+		return $return;
839
+	}
840
+
841
+	/**
842
+	 * XOR this 64-bit integer with another.
843
+	 *
844
+	 * @param ParagonIE_Sodium_Core32_Int64 $b
845
+	 * @return ParagonIE_Sodium_Core32_Int64
846
+	 */
847
+	public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b)
848
+	{
849
+		$return = new ParagonIE_Sodium_Core32_Int64();
850
+		$return->unsignedInt = $this->unsignedInt;
851
+		$return->limbs = array(
852
+			(int) ($this->limbs[0] ^ $b->limbs[0]),
853
+			(int) ($this->limbs[1] ^ $b->limbs[1]),
854
+			(int) ($this->limbs[2] ^ $b->limbs[2]),
855
+			(int) ($this->limbs[3] ^ $b->limbs[3])
856
+		);
857
+		return $return;
858
+	}
859
+
860
+	/**
861
+	 * @param int $low
862
+	 * @param int $high
863
+	 * @return self
864
+	 * @throws SodiumException
865
+	 * @throws TypeError
866
+	 */
867
+	public static function fromInts($low, $high)
868
+	{
869
+		ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
870
+		ParagonIE_Sodium_Core32_Util::declareScalarType($high, 'int', 2);
871
+
872
+		$high = (int) $high;
873
+		$low = (int) $low;
874
+		return new ParagonIE_Sodium_Core32_Int64(
875
+			array(
876
+				(int) (($high >> 16) & 0xffff),
877
+				(int) ($high & 0xffff),
878
+				(int) (($low >> 16) & 0xffff),
879
+				(int) ($low & 0xffff)
880
+			)
881
+		);
882
+	}
883
+
884
+	/**
885
+	 * @param int $low
886
+	 * @return self
887
+	 * @throws SodiumException
888
+	 * @throws TypeError
889
+	 */
890
+	public static function fromInt($low)
891
+	{
892
+		ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
893
+		$low = (int) $low;
894
+
895
+		return new ParagonIE_Sodium_Core32_Int64(
896
+			array(
897
+				0,
898
+				0,
899
+				(int) (($low >> 16) & 0xffff),
900
+				(int) ($low & 0xffff)
901
+			)
902
+		);
903
+	}
904
+
905
+	/**
906
+	 * @return int
907
+	 */
908
+	public function toInt()
909
+	{
910
+		return (int) (
911
+			(($this->limbs[2] & 0xffff) << 16)
912
+				|
913
+			($this->limbs[3] & 0xffff)
914
+		);
915
+	}
916
+
917
+	/**
918
+	 * @param string $string
919
+	 * @return self
920
+	 * @throws SodiumException
921
+	 * @throws TypeError
922
+	 */
923
+	public static function fromString($string)
924
+	{
925
+		ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
926
+		$string = (string) $string;
927
+		if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
928
+			throw new RangeException(
929
+				'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
930
+			);
931
+		}
932
+		$return = new ParagonIE_Sodium_Core32_Int64();
933
+
934
+		$return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
935
+		$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
936
+		$return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
937
+		$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
938
+		$return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff) << 8);
939
+		$return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff);
940
+		$return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff) << 8);
941
+		$return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff);
942
+		return $return;
943
+	}
944
+
945
+	/**
946
+	 * @param string $string
947
+	 * @return self
948
+	 * @throws SodiumException
949
+	 * @throws TypeError
950
+	 */
951
+	public static function fromReverseString($string)
952
+	{
953
+		ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
954
+		$string = (string) $string;
955
+		if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
956
+			throw new RangeException(
957
+				'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
958
+			);
959
+		}
960
+		$return = new ParagonIE_Sodium_Core32_Int64();
961
+
962
+		$return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff) << 8);
963
+		$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff);
964
+		$return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff) << 8);
965
+		$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff);
966
+		$return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
967
+		$return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
968
+		$return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
969
+		$return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
970
+		return $return;
971
+	}
972
+
973
+	/**
974
+	 * @return array<int, int>
975
+	 */
976
+	public function toArray()
977
+	{
978
+		return array(
979
+			(int) ((($this->limbs[0] & 0xffff) << 16) | ($this->limbs[1] & 0xffff)),
980
+			(int) ((($this->limbs[2] & 0xffff) << 16) | ($this->limbs[3] & 0xffff))
981
+		);
982
+	}
983
+
984
+	/**
985
+	 * @return ParagonIE_Sodium_Core32_Int32
986
+	 */
987
+	public function toInt32()
988
+	{
989
+		$return = new ParagonIE_Sodium_Core32_Int32();
990
+		$return->limbs[0] = (int) ($this->limbs[2]);
991
+		$return->limbs[1] = (int) ($this->limbs[3]);
992
+		$return->unsignedInt = $this->unsignedInt;
993
+		$return->overflow = (int) (ParagonIE_Sodium_Core32_Util::abs($this->limbs[1], 16) & 0xffff);
994
+		return $return;
995
+	}
996
+
997
+	/**
998
+	 * @return ParagonIE_Sodium_Core32_Int64
999
+	 */
1000
+	public function toInt64()
1001
+	{
1002
+		$return = new ParagonIE_Sodium_Core32_Int64();
1003
+		$return->limbs[0] = (int) ($this->limbs[0]);
1004
+		$return->limbs[1] = (int) ($this->limbs[1]);
1005
+		$return->limbs[2] = (int) ($this->limbs[2]);
1006
+		$return->limbs[3] = (int) ($this->limbs[3]);
1007
+		$return->unsignedInt = $this->unsignedInt;
1008
+		$return->overflow = ParagonIE_Sodium_Core32_Util::abs($this->overflow);
1009
+		return $return;
1010
+	}
1011
+
1012
+	/**
1013
+	 * @param bool $bool
1014
+	 * @return self
1015
+	 */
1016
+	public function setUnsignedInt($bool = false)
1017
+	{
1018
+		$this->unsignedInt = !empty($bool);
1019
+		return $this;
1020
+	}
1021
+
1022
+	/**
1023
+	 * @return string
1024
+	 * @throws TypeError
1025
+	 */
1026
+	public function toString()
1027
+	{
1028
+		return ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
1029
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1030
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
1031
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
1032
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
1033
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
1034
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1035
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff);
1036
+	}
1037
+
1038
+	/**
1039
+	 * @return string
1040
+	 * @throws TypeError
1041
+	 */
1042
+	public function toReverseString()
1043
+	{
1044
+		return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff) .
1045
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1046
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
1047
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
1048
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
1049
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
1050
+			ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1051
+			ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
1052
+	}
1053
+
1054
+	/**
1055
+	 * @return string
1056
+	 */
1057
+	public function __toString()
1058
+	{
1059
+		try {
1060
+			return $this->toString();
1061
+		} catch (TypeError $ex) {
1062
+			// PHP engine can't handle exceptions from __toString()
1063
+			return '';
1064
+		}
1065
+	}
1066 1066
 }
Please login to merge, or discard this patch.
Spacing   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     /**
13 13
      * @var array<int, int> - four 16-bit integers
14 14
      */
15
-    public $limbs = array(0, 0, 0, 0);
15
+    public $limbs = array( 0, 0, 0, 0 );
16 16
 
17 17
     /**
18 18
      * @var int
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
      * @param array $array
30 30
      * @param bool $unsignedInt
31 31
      */
32
-    public function __construct($array = array(0, 0, 0, 0), $unsignedInt = false)
32
+    public function __construct( $array = array( 0, 0, 0, 0 ), $unsignedInt = false )
33 33
     {
34 34
         $this->limbs = array(
35
-            (int) $array[0],
36
-            (int) $array[1],
37
-            (int) $array[2],
38
-            (int) $array[3]
35
+            (int)$array[ 0 ],
36
+            (int)$array[ 1 ],
37
+            (int)$array[ 2 ],
38
+            (int)$array[ 3 ]
39 39
         );
40 40
         $this->overflow = 0;
41 41
         $this->unsignedInt = $unsignedInt;
@@ -47,27 +47,27 @@  discard block
 block discarded – undo
47 47
      * @param ParagonIE_Sodium_Core32_Int64 $addend
48 48
      * @return ParagonIE_Sodium_Core32_Int64
49 49
      */
50
-    public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend)
50
+    public function addInt64( ParagonIE_Sodium_Core32_Int64 $addend )
51 51
     {
52
-        $i0 = $this->limbs[0];
53
-        $i1 = $this->limbs[1];
54
-        $i2 = $this->limbs[2];
55
-        $i3 = $this->limbs[3];
56
-        $j0 = $addend->limbs[0];
57
-        $j1 = $addend->limbs[1];
58
-        $j2 = $addend->limbs[2];
59
-        $j3 = $addend->limbs[3];
60
-
61
-        $r3 = $i3 + ($j3 & 0xffff);
52
+        $i0 = $this->limbs[ 0 ];
53
+        $i1 = $this->limbs[ 1 ];
54
+        $i2 = $this->limbs[ 2 ];
55
+        $i3 = $this->limbs[ 3 ];
56
+        $j0 = $addend->limbs[ 0 ];
57
+        $j1 = $addend->limbs[ 1 ];
58
+        $j2 = $addend->limbs[ 2 ];
59
+        $j3 = $addend->limbs[ 3 ];
60
+
61
+        $r3 = $i3 + ( $j3 & 0xffff );
62 62
         $carry = $r3 >> 16;
63 63
 
64
-        $r2 = $i2 + ($j2 & 0xffff) + $carry;
64
+        $r2 = $i2 + ( $j2 & 0xffff ) + $carry;
65 65
         $carry = $r2 >> 16;
66 66
 
67
-        $r1 = $i1 + ($j1 & 0xffff) + $carry;
67
+        $r1 = $i1 + ( $j1 & 0xffff ) + $carry;
68 68
         $carry = $r1 >> 16;
69 69
 
70
-        $r0 = $i0 + ($j0 & 0xffff) + $carry;
70
+        $r0 = $i0 + ( $j0 & 0xffff ) + $carry;
71 71
         $carry = $r0 >> 16;
72 72
 
73 73
         $r0 &= 0xffff;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         $r3 &= 0xffff;
77 77
 
78 78
         $return = new ParagonIE_Sodium_Core32_Int64(
79
-            array($r0, $r1, $r2, $r3)
79
+            array( $r0, $r1, $r2, $r3 )
80 80
         );
81 81
         $return->overflow = $carry;
82 82
         $return->unsignedInt = $this->unsignedInt;
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
      * @throws SodiumException
92 92
      * @throws TypeError
93 93
      */
94
-    public function addInt($int)
94
+    public function addInt( $int )
95 95
     {
96
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
96
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
97 97
         /** @var int $int */
98
-        $int = (int) $int;
98
+        $int = (int)$int;
99 99
 
100
-        $i0 = $this->limbs[0];
101
-        $i1 = $this->limbs[1];
102
-        $i2 = $this->limbs[2];
103
-        $i3 = $this->limbs[3];
100
+        $i0 = $this->limbs[ 0 ];
101
+        $i1 = $this->limbs[ 1 ];
102
+        $i2 = $this->limbs[ 2 ];
103
+        $i3 = $this->limbs[ 3 ];
104 104
 
105
-        $r3 = $i3 + ($int & 0xffff);
105
+        $r3 = $i3 + ( $int & 0xffff );
106 106
         $carry = $r3 >> 16;
107 107
 
108
-        $r2 = $i2 + (($int >> 16) & 0xffff) + $carry;
108
+        $r2 = $i2 + ( ( $int >> 16 ) & 0xffff ) + $carry;
109 109
         $carry = $r2 >> 16;
110 110
 
111 111
         $r1 = $i1 + $carry;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         $r2 &= 0xffff;
120 120
         $r3 &= 0xffff;
121 121
         $return = new ParagonIE_Sodium_Core32_Int64(
122
-            array($r0, $r1, $r2, $r3)
122
+            array( $r0, $r1, $r2, $r3 )
123 123
         );
124 124
         $return->overflow = $carry;
125 125
         $return->unsignedInt = $this->unsignedInt;
@@ -130,43 +130,43 @@  discard block
 block discarded – undo
130 130
      * @param int $b
131 131
      * @return int
132 132
      */
133
-    public function compareInt($b = 0)
133
+    public function compareInt( $b = 0 )
134 134
     {
135 135
         $gt = 0;
136 136
         $eq = 1;
137 137
 
138 138
         $i = 4;
139 139
         $j = 0;
140
-        while ($i > 0) {
140
+        while ( $i > 0 ) {
141 141
             --$i;
142 142
             /** @var int $x1 */
143
-            $x1 = $this->limbs[$i];
143
+            $x1 = $this->limbs[ $i ];
144 144
             /** @var int $x2 */
145
-            $x2 = ($b >> ($j << 4)) & 0xffff;
145
+            $x2 = ( $b >> ( $j << 4 ) ) & 0xffff;
146 146
             /** int */
147
-            $gt |= (($x2 - $x1) >> 8) & $eq;
147
+            $gt |= ( ( $x2 - $x1 ) >> 8 ) & $eq;
148 148
             /** int */
149
-            $eq &= (($x2 ^ $x1) - 1) >> 8;
149
+            $eq &= ( ( $x2 ^ $x1 ) - 1 ) >> 8;
150 150
         }
151
-        return ($gt + $gt - $eq) + 1;
151
+        return ( $gt + $gt - $eq ) + 1;
152 152
     }
153 153
 
154 154
     /**
155 155
      * @param int $b
156 156
      * @return bool
157 157
      */
158
-    public function isGreaterThan($b = 0)
158
+    public function isGreaterThan( $b = 0 )
159 159
     {
160
-        return $this->compareInt($b) > 0;
160
+        return $this->compareInt( $b ) > 0;
161 161
     }
162 162
 
163 163
     /**
164 164
      * @param int $b
165 165
      * @return bool
166 166
      */
167
-    public function isLessThanInt($b = 0)
167
+    public function isLessThanInt( $b = 0 )
168 168
     {
169
-        return $this->compareInt($b) < 0;
169
+        return $this->compareInt( $b ) < 0;
170 170
     }
171 171
 
172 172
     /**
@@ -174,22 +174,22 @@  discard block
 block discarded – undo
174 174
      * @param int $lo
175 175
      * @return ParagonIE_Sodium_Core32_Int64
176 176
      */
177
-    public function mask64($hi = 0, $lo = 0)
177
+    public function mask64( $hi = 0, $lo = 0 )
178 178
     {
179 179
         /** @var int $a */
180
-        $a = ($hi >> 16) & 0xffff;
180
+        $a = ( $hi >> 16 ) & 0xffff;
181 181
         /** @var int $b */
182
-        $b = ($hi) & 0xffff;
182
+        $b = ( $hi ) & 0xffff;
183 183
         /** @var int $c */
184
-        $c = ($lo >> 16) & 0xffff;
184
+        $c = ( $lo >> 16 ) & 0xffff;
185 185
         /** @var int $d */
186
-        $d = ($lo & 0xffff);
186
+        $d = ( $lo & 0xffff );
187 187
         return new ParagonIE_Sodium_Core32_Int64(
188 188
             array(
189
-                $this->limbs[0] & $a,
190
-                $this->limbs[1] & $b,
191
-                $this->limbs[2] & $c,
192
-                $this->limbs[3] & $d
189
+                $this->limbs[ 0 ] & $a,
190
+                $this->limbs[ 1 ] & $b,
191
+                $this->limbs[ 2 ] & $c,
192
+                $this->limbs[ 3 ] & $d
193 193
             ),
194 194
             $this->unsignedInt
195 195
         );
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
      * @throws TypeError
204 204
      * @psalm-suppress MixedAssignment
205 205
      */
206
-    public function mulInt($int = 0, $size = 0)
206
+    public function mulInt( $int = 0, $size = 0 )
207 207
     {
208
-        if (ParagonIE_Sodium_Compat::$fastMult) {
209
-            return $this->mulIntFast($int);
208
+        if ( ParagonIE_Sodium_Compat::$fastMult ) {
209
+            return $this->mulIntFast( $int );
210 210
         }
211
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
212
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
211
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
212
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $size, 'int', 2 );
213 213
         /** @var int $int */
214
-        $int = (int) $int;
214
+        $int = (int)$int;
215 215
         /** @var int $size */
216
-        $size = (int) $size;
216
+        $size = (int)$size;
217 217
 
218
-        if (!$size) {
218
+        if ( ! $size ) {
219 219
             $size = 63;
220 220
         }
221 221
 
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
         $ret1 = 0;
229 229
         $ret2 = 0;
230 230
         $ret3 = 0;
231
-        $a0 = $a->limbs[0];
232
-        $a1 = $a->limbs[1];
233
-        $a2 = $a->limbs[2];
234
-        $a3 = $a->limbs[3];
231
+        $a0 = $a->limbs[ 0 ];
232
+        $a1 = $a->limbs[ 1 ];
233
+        $a2 = $a->limbs[ 2 ];
234
+        $a3 = $a->limbs[ 3 ];
235 235
 
236 236
         /** @var int $size */
237 237
         /** @var int $i */
238
-        for ($i = $size; $i >= 0; --$i) {
239
-            $mask = -($int & 1);
238
+        for ( $i = $size; $i >= 0; --$i ) {
239
+            $mask = -( $int & 1 );
240 240
             $x0 = $a0 & $mask;
241 241
             $x1 = $a1 & $mask;
242 242
             $x2 = $a2 & $mask;
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 
261 261
             $a3 = $a3 << 1;
262 262
             $x3 = $a3 >> 16;
263
-            $a2 = ($a2 << 1) | $x3;
263
+            $a2 = ( $a2 << 1 ) | $x3;
264 264
             $x2 = $a2 >> 16;
265
-            $a1 = ($a1 << 1) | $x2;
265
+            $a1 = ( $a1 << 1 ) | $x2;
266 266
             $x1 = $a1 >> 16;
267
-            $a0 = ($a0 << 1) | $x1;
267
+            $a0 = ( $a0 << 1 ) | $x1;
268 268
             $a0 &= 0xffff;
269 269
             $a1 &= 0xffff;
270 270
             $a2 &= 0xffff;
@@ -272,10 +272,10 @@  discard block
 block discarded – undo
272 272
 
273 273
             $int >>= 1;
274 274
         }
275
-        $return->limbs[0] = $ret0;
276
-        $return->limbs[1] = $ret1;
277
-        $return->limbs[2] = $ret2;
278
-        $return->limbs[3] = $ret3;
275
+        $return->limbs[ 0 ] = $ret0;
276
+        $return->limbs[ 1 ] = $ret1;
277
+        $return->limbs[ 2 ] = $ret2;
278
+        $return->limbs[ 3 ] = $ret3;
279 279
         return $return;
280 280
     }
281 281
 
@@ -294,11 +294,11 @@  discard block
 block discarded – undo
294 294
         $a = clone $A;
295 295
         $b = clone $B;
296 296
         /** @var int $aNeg */
297
-        $aNeg = ($a->limbs[0] >> 15) & 1;
297
+        $aNeg = ( $a->limbs[ 0 ] >> 15 ) & 1;
298 298
         /** @var int $bNeg */
299
-        $bNeg = ($b->limbs[0] >> 15) & 1;
299
+        $bNeg = ( $b->limbs[ 0 ] >> 15 ) & 1;
300 300
         /** @var int $m */
301
-        $m = (-($aNeg & $bNeg)) | 1;
301
+        $m = (-( $aNeg & $bNeg )) | 1;
302 302
         /** @var int $swap */
303 303
         $swap = $bNeg & ~$aNeg;
304 304
         /** @var int $d */
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
             $b = $int->mulInt(-1);
314 314
         }
315 315
          */
316
-        $x = $a->xorInt64($b)->mask64($d, $d);
316
+        $x = $a->xorInt64( $b )->mask64( $d, $d );
317 317
         return array(
318
-            $a->xorInt64($x)->mulInt($m),
319
-            $b->xorInt64($x)->mulInt($m)
318
+            $a->xorInt64( $x )->mulInt( $m ),
319
+            $b->xorInt64( $x )->mulInt( $m )
320 320
         );
321 321
     }
322 322
 
@@ -326,81 +326,81 @@  discard block
 block discarded – undo
326 326
      * @param int $baseLog2
327 327
      * @return array<int, int>
328 328
      */
329
-    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
329
+    public function multiplyLong( array $a, array $b, $baseLog2 = 16 )
330 330
     {
331
-        $a_l = count($a);
332
-        $b_l = count($b);
331
+        $a_l = count( $a );
332
+        $b_l = count( $b );
333 333
         /** @var array<int, int> $r */
334
-        $r = array_fill(0, $a_l + $b_l + 1, 0);
334
+        $r = array_fill( 0, $a_l + $b_l + 1, 0 );
335 335
         $base = 1 << $baseLog2;
336
-        for ($i = 0; $i < $a_l; ++$i) {
337
-            $a_i = $a[$i];
338
-            for ($j = 0; $j < $a_l; ++$j) {
339
-                $b_j = $b[$j];
340
-                $product = ($a_i * $b_j) + $r[$i + $j];
341
-                $carry = ($product >> $baseLog2 & 0xffff);
342
-                $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
343
-                $r[$i + $j + 1] += $carry;
336
+        for ( $i = 0; $i < $a_l; ++$i ) {
337
+            $a_i = $a[ $i ];
338
+            for ( $j = 0; $j < $a_l; ++$j ) {
339
+                $b_j = $b[ $j ];
340
+                $product = ( $a_i * $b_j ) + $r[ $i + $j ];
341
+                $carry = ( $product >> $baseLog2 & 0xffff );
342
+                $r[ $i + $j ] = ( $product - (int)( $carry * $base ) ) & 0xffff;
343
+                $r[ $i + $j + 1 ] += $carry;
344 344
             }
345 345
         }
346
-        return array_slice($r, 0, 5);
346
+        return array_slice( $r, 0, 5 );
347 347
     }
348 348
 
349 349
     /**
350 350
      * @param int $int
351 351
      * @return ParagonIE_Sodium_Core32_Int64
352 352
      */
353
-    public function mulIntFast($int)
353
+    public function mulIntFast( $int )
354 354
     {
355 355
         // Handle negative numbers
356
-        $aNeg = ($this->limbs[0] >> 15) & 1;
357
-        $bNeg = ($int >> 31) & 1;
358
-        $a = array_reverse($this->limbs);
356
+        $aNeg = ( $this->limbs[ 0 ] >> 15 ) & 1;
357
+        $bNeg = ( $int >> 31 ) & 1;
358
+        $a = array_reverse( $this->limbs );
359 359
         $b = array(
360 360
             $int & 0xffff,
361
-            ($int >> 16) & 0xffff,
361
+            ( $int >> 16 ) & 0xffff,
362 362
             -$bNeg & 0xffff,
363 363
             -$bNeg & 0xffff
364 364
         );
365
-        if ($aNeg) {
366
-            for ($i = 0; $i < 4; ++$i) {
367
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
365
+        if ( $aNeg ) {
366
+            for ( $i = 0; $i < 4; ++$i ) {
367
+                $a[ $i ] = ( $a[ $i ] ^ 0xffff ) & 0xffff;
368 368
             }
369
-            ++$a[0];
369
+            ++$a[ 0 ];
370 370
         }
371
-        if ($bNeg) {
372
-            for ($i = 0; $i < 4; ++$i) {
373
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
371
+        if ( $bNeg ) {
372
+            for ( $i = 0; $i < 4; ++$i ) {
373
+                $b[ $i ] = ( $b[ $i ] ^ 0xffff ) & 0xffff;
374 374
             }
375
-            ++$b[0];
375
+            ++$b[ 0 ];
376 376
         }
377 377
         // Multiply
378
-        $res = $this->multiplyLong($a, $b);
378
+        $res = $this->multiplyLong( $a, $b );
379 379
 
380 380
         // Re-apply negation to results
381
-        if ($aNeg !== $bNeg) {
382
-            for ($i = 0; $i < 4; ++$i) {
383
-                $res[$i] = (0xffff ^ $res[$i]) & 0xffff;
381
+        if ( $aNeg !== $bNeg ) {
382
+            for ( $i = 0; $i < 4; ++$i ) {
383
+                $res[ $i ] = ( 0xffff ^ $res[ $i ] ) & 0xffff;
384 384
             }
385 385
             // Handle integer overflow
386 386
             $c = 1;
387
-            for ($i = 0; $i < 4; ++$i) {
388
-                $res[$i] += $c;
389
-                $c = $res[$i] >> 16;
390
-                $res[$i] &= 0xffff;
387
+            for ( $i = 0; $i < 4; ++$i ) {
388
+                $res[ $i ] += $c;
389
+                $c = $res[ $i ] >> 16;
390
+                $res[ $i ] &= 0xffff;
391 391
             }
392 392
         }
393 393
 
394 394
         // Return our values
395 395
         $return = new ParagonIE_Sodium_Core32_Int64();
396 396
         $return->limbs = array(
397
-            $res[3] & 0xffff,
398
-            $res[2] & 0xffff,
399
-            $res[1] & 0xffff,
400
-            $res[0] & 0xffff
397
+            $res[ 3 ] & 0xffff,
398
+            $res[ 2 ] & 0xffff,
399
+            $res[ 1 ] & 0xffff,
400
+            $res[ 0 ] & 0xffff
401 401
         );
402
-        if (count($res) > 4) {
403
-            $return->overflow = $res[4] & 0xffff;
402
+        if ( count( $res ) > 4 ) {
403
+            $return->overflow = $res[ 4 ] & 0xffff;
404 404
         }
405 405
         $return->unsignedInt = $this->unsignedInt;
406 406
         return $return;
@@ -410,48 +410,48 @@  discard block
 block discarded – undo
410 410
      * @param ParagonIE_Sodium_Core32_Int64 $right
411 411
      * @return ParagonIE_Sodium_Core32_Int64
412 412
      */
413
-    public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right)
413
+    public function mulInt64Fast( ParagonIE_Sodium_Core32_Int64 $right )
414 414
     {
415
-        $aNeg = ($this->limbs[0] >> 15) & 1;
416
-        $bNeg = ($right->limbs[0] >> 15) & 1;
417
-
418
-        $a = array_reverse($this->limbs);
419
-        $b = array_reverse($right->limbs);
420
-        if ($aNeg) {
421
-            for ($i = 0; $i < 4; ++$i) {
422
-                $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
415
+        $aNeg = ( $this->limbs[ 0 ] >> 15 ) & 1;
416
+        $bNeg = ( $right->limbs[ 0 ] >> 15 ) & 1;
417
+
418
+        $a = array_reverse( $this->limbs );
419
+        $b = array_reverse( $right->limbs );
420
+        if ( $aNeg ) {
421
+            for ( $i = 0; $i < 4; ++$i ) {
422
+                $a[ $i ] = ( $a[ $i ] ^ 0xffff ) & 0xffff;
423 423
             }
424
-            ++$a[0];
424
+            ++$a[ 0 ];
425 425
         }
426
-        if ($bNeg) {
427
-            for ($i = 0; $i < 4; ++$i) {
428
-                $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
426
+        if ( $bNeg ) {
427
+            for ( $i = 0; $i < 4; ++$i ) {
428
+                $b[ $i ] = ( $b[ $i ] ^ 0xffff ) & 0xffff;
429 429
             }
430
-            ++$b[0];
430
+            ++$b[ 0 ];
431 431
         }
432
-        $res = $this->multiplyLong($a, $b);
433
-        if ($aNeg !== $bNeg) {
434
-            if ($aNeg !== $bNeg) {
435
-                for ($i = 0; $i < 4; ++$i) {
436
-                    $res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
432
+        $res = $this->multiplyLong( $a, $b );
433
+        if ( $aNeg !== $bNeg ) {
434
+            if ( $aNeg !== $bNeg ) {
435
+                for ( $i = 0; $i < 4; ++$i ) {
436
+                    $res[ $i ] = ( $res[ $i ] ^ 0xffff ) & 0xffff;
437 437
                 }
438 438
                 $c = 1;
439
-                for ($i = 0; $i < 4; ++$i) {
440
-                    $res[$i] += $c;
441
-                    $c = $res[$i] >> 16;
442
-                    $res[$i] &= 0xffff;
439
+                for ( $i = 0; $i < 4; ++$i ) {
440
+                    $res[ $i ] += $c;
441
+                    $c = $res[ $i ] >> 16;
442
+                    $res[ $i ] &= 0xffff;
443 443
                 }
444 444
             }
445 445
         }
446 446
         $return = new ParagonIE_Sodium_Core32_Int64();
447 447
         $return->limbs = array(
448
-            $res[3] & 0xffff,
449
-            $res[2] & 0xffff,
450
-            $res[1] & 0xffff,
451
-            $res[0] & 0xffff
448
+            $res[ 3 ] & 0xffff,
449
+            $res[ 2 ] & 0xffff,
450
+            $res[ 1 ] & 0xffff,
451
+            $res[ 0 ] & 0xffff
452 452
         );
453
-        if (count($res) > 4) {
454
-            $return->overflow = $res[4];
453
+        if ( count( $res ) > 4 ) {
454
+            $return->overflow = $res[ 4 ];
455 455
         }
456 456
         return $return;
457 457
     }
@@ -464,16 +464,16 @@  discard block
 block discarded – undo
464 464
      * @throws TypeError
465 465
      * @psalm-suppress MixedAssignment
466 466
      */
467
-    public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0)
467
+    public function mulInt64( ParagonIE_Sodium_Core32_Int64 $int, $size = 0 )
468 468
     {
469
-        if (ParagonIE_Sodium_Compat::$fastMult) {
470
-            return $this->mulInt64Fast($int);
469
+        if ( ParagonIE_Sodium_Compat::$fastMult ) {
470
+            return $this->mulInt64Fast( $int );
471 471
         }
472
-        ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2);
473
-        if (!$size) {
472
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $size, 'int', 2 );
473
+        if ( ! $size ) {
474 474
             $size = 63;
475 475
         }
476
-        list($a, $b) = self::ctSelect($this, $int);
476
+        list( $a, $b ) = self::ctSelect( $this, $int );
477 477
 
478 478
         $return = new ParagonIE_Sodium_Core32_Int64();
479 479
         $return->unsignedInt = $this->unsignedInt;
@@ -483,19 +483,19 @@  discard block
 block discarded – undo
483 483
         $ret1 = 0;
484 484
         $ret2 = 0;
485 485
         $ret3 = 0;
486
-        $a0 = $a->limbs[0];
487
-        $a1 = $a->limbs[1];
488
-        $a2 = $a->limbs[2];
489
-        $a3 = $a->limbs[3];
490
-        $b0 = $b->limbs[0];
491
-        $b1 = $b->limbs[1];
492
-        $b2 = $b->limbs[2];
493
-        $b3 = $b->limbs[3];
486
+        $a0 = $a->limbs[ 0 ];
487
+        $a1 = $a->limbs[ 1 ];
488
+        $a2 = $a->limbs[ 2 ];
489
+        $a3 = $a->limbs[ 3 ];
490
+        $b0 = $b->limbs[ 0 ];
491
+        $b1 = $b->limbs[ 1 ];
492
+        $b2 = $b->limbs[ 2 ];
493
+        $b3 = $b->limbs[ 3 ];
494 494
 
495 495
         /** @var int $size */
496 496
         /** @var int $i */
497
-        for ($i = (int) $size; $i >= 0; --$i) {
498
-            $mask = -($b3 & 1);
497
+        for ( $i = (int)$size; $i >= 0; --$i ) {
498
+            $mask = -( $b3 & 1 );
499 499
             $x0 = $a0 & $mask;
500 500
             $x1 = $a1 & $mask;
501 501
             $x2 = $a2 & $mask;
@@ -519,24 +519,24 @@  discard block
 block discarded – undo
519 519
 
520 520
             $a3 = $a3 << 1;
521 521
             $x3 = $a3 >> 16;
522
-            $a2 = ($a2 << 1) | $x3;
522
+            $a2 = ( $a2 << 1 ) | $x3;
523 523
             $x2 = $a2 >> 16;
524
-            $a1 = ($a1 << 1) | $x2;
524
+            $a1 = ( $a1 << 1 ) | $x2;
525 525
             $x1 = $a1 >> 16;
526
-            $a0 = ($a0 << 1) | $x1;
526
+            $a0 = ( $a0 << 1 ) | $x1;
527 527
             $a0 &= 0xffff;
528 528
             $a1 &= 0xffff;
529 529
             $a2 &= 0xffff;
530 530
             $a3 &= 0xffff;
531 531
 
532
-            $x0 = ($b0 & 1) << 16;
533
-            $x1 = ($b1 & 1) << 16;
534
-            $x2 = ($b2 & 1) << 16;
532
+            $x0 = ( $b0 & 1 ) << 16;
533
+            $x1 = ( $b1 & 1 ) << 16;
534
+            $x2 = ( $b2 & 1 ) << 16;
535 535
 
536
-            $b0 = ($b0 >> 1);
537
-            $b1 = (($b1 | $x0) >> 1);
538
-            $b2 = (($b2 | $x1) >> 1);
539
-            $b3 = (($b3 | $x2) >> 1);
536
+            $b0 = ( $b0 >> 1 );
537
+            $b1 = ( ( $b1 | $x0 ) >> 1 );
538
+            $b2 = ( ( $b2 | $x1 ) >> 1 );
539
+            $b3 = ( ( $b3 | $x2 ) >> 1 );
540 540
 
541 541
             $b0 &= 0xffff;
542 542
             $b1 &= 0xffff;
@@ -544,10 +544,10 @@  discard block
 block discarded – undo
544 544
             $b3 &= 0xffff;
545 545
 
546 546
         }
547
-        $return->limbs[0] = $ret0;
548
-        $return->limbs[1] = $ret1;
549
-        $return->limbs[2] = $ret2;
550
-        $return->limbs[3] = $ret3;
547
+        $return->limbs[ 0 ] = $ret0;
548
+        $return->limbs[ 1 ] = $ret1;
549
+        $return->limbs[ 2 ] = $ret2;
550
+        $return->limbs[ 3 ] = $ret3;
551 551
 
552 552
         return $return;
553 553
     }
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
      * @param ParagonIE_Sodium_Core32_Int64 $b
559 559
      * @return ParagonIE_Sodium_Core32_Int64
560 560
      */
561
-    public function orInt64(ParagonIE_Sodium_Core32_Int64 $b)
561
+    public function orInt64( ParagonIE_Sodium_Core32_Int64 $b )
562 562
     {
563 563
         $return = new ParagonIE_Sodium_Core32_Int64();
564 564
         $return->unsignedInt = $this->unsignedInt;
565 565
         $return->limbs = array(
566
-            (int) ($this->limbs[0] | $b->limbs[0]),
567
-            (int) ($this->limbs[1] | $b->limbs[1]),
568
-            (int) ($this->limbs[2] | $b->limbs[2]),
569
-            (int) ($this->limbs[3] | $b->limbs[3])
566
+            (int)( $this->limbs[ 0 ] | $b->limbs[ 0 ] ),
567
+            (int)( $this->limbs[ 1 ] | $b->limbs[ 1 ] ),
568
+            (int)( $this->limbs[ 2 ] | $b->limbs[ 2 ] ),
569
+            (int)( $this->limbs[ 3 ] | $b->limbs[ 3 ] )
570 570
         );
571 571
         return $return;
572 572
     }
@@ -578,40 +578,40 @@  discard block
 block discarded – undo
578 578
      * @throws TypeError
579 579
      * @psalm-suppress MixedArrayAccess
580 580
      */
581
-    public function rotateLeft($c = 0)
581
+    public function rotateLeft( $c = 0 )
582 582
     {
583
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
583
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
584 584
         /** @var int $c */
585
-        $c = (int) $c;
585
+        $c = (int)$c;
586 586
 
587 587
         $return = new ParagonIE_Sodium_Core32_Int64();
588 588
         $return->unsignedInt = $this->unsignedInt;
589 589
         $c &= 63;
590
-        if ($c === 0) {
590
+        if ( $c === 0 ) {
591 591
             // NOP, but we want a copy.
592 592
             $return->limbs = $this->limbs;
593 593
         } else {
594 594
             /** @var array<int, int> $limbs */
595
-            $limbs =& $return->limbs;
595
+            $limbs = & $return->limbs;
596 596
 
597 597
             /** @var array<int, int> $myLimbs */
598
-            $myLimbs =& $this->limbs;
598
+            $myLimbs = & $this->limbs;
599 599
 
600 600
             /** @var int $idx_shift */
601
-            $idx_shift = ($c >> 4) & 3;
601
+            $idx_shift = ( $c >> 4 ) & 3;
602 602
             /** @var int $sub_shift */
603 603
             $sub_shift = $c & 15;
604 604
 
605
-            for ($i = 3; $i >= 0; --$i) {
605
+            for ( $i = 3; $i >= 0; --$i ) {
606 606
                 /** @var int $j */
607
-                $j = ($i + $idx_shift) & 3;
607
+                $j = ( $i + $idx_shift ) & 3;
608 608
                 /** @var int $k */
609
-                $k = ($i + $idx_shift + 1) & 3;
610
-                $limbs[$i] = (int) (
609
+                $k = ( $i + $idx_shift + 1 ) & 3;
610
+                $limbs[ $i ] = (int)(
611 611
                     (
612
-                        ((int) ($myLimbs[$j]) << $sub_shift)
612
+                        ( (int)( $myLimbs[ $j ] ) << $sub_shift )
613 613
                             |
614
-                        ((int) ($myLimbs[$k]) >> (16 - $sub_shift))
614
+                        ( (int)( $myLimbs[ $k ] ) >> ( 16 - $sub_shift ) )
615 615
                     ) & 0xffff
616 616
                 );
617 617
             }
@@ -628,42 +628,42 @@  discard block
 block discarded – undo
628 628
      * @throws TypeError
629 629
      * @psalm-suppress MixedArrayAccess
630 630
      */
631
-    public function rotateRight($c = 0)
631
+    public function rotateRight( $c = 0 )
632 632
     {
633
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
633
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
634 634
         /** @var int $c */
635
-        $c = (int) $c;
635
+        $c = (int)$c;
636 636
 
637 637
         /** @var ParagonIE_Sodium_Core32_Int64 $return */
638 638
         $return = new ParagonIE_Sodium_Core32_Int64();
639 639
         $return->unsignedInt = $this->unsignedInt;
640 640
         $c &= 63;
641 641
         /** @var int $c */
642
-        if ($c === 0) {
642
+        if ( $c === 0 ) {
643 643
             // NOP, but we want a copy.
644 644
             $return->limbs = $this->limbs;
645 645
         } else {
646 646
             /** @var array<int, int> $limbs */
647
-            $limbs =& $return->limbs;
647
+            $limbs = & $return->limbs;
648 648
 
649 649
             /** @var array<int, int> $myLimbs */
650
-            $myLimbs =& $this->limbs;
650
+            $myLimbs = & $this->limbs;
651 651
 
652 652
             /** @var int $idx_shift */
653
-            $idx_shift = ($c >> 4) & 3;
653
+            $idx_shift = ( $c >> 4 ) & 3;
654 654
             /** @var int $sub_shift */
655 655
             $sub_shift = $c & 15;
656 656
 
657
-            for ($i = 3; $i >= 0; --$i) {
657
+            for ( $i = 3; $i >= 0; --$i ) {
658 658
                 /** @var int $j */
659
-                $j = ($i - $idx_shift) & 3;
659
+                $j = ( $i - $idx_shift ) & 3;
660 660
                 /** @var int $k */
661
-                $k = ($i - $idx_shift - 1) & 3;
662
-                $limbs[$i] = (int) (
661
+                $k = ( $i - $idx_shift - 1 ) & 3;
662
+                $limbs[ $i ] = (int)(
663 663
                     (
664
-                        ((int) ($myLimbs[$j]) >> (int) ($sub_shift))
664
+                        ( (int)( $myLimbs[ $j ] ) >> (int)( $sub_shift ) )
665 665
                             |
666
-                        ((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
666
+                        ( (int)( $myLimbs[ $k ] ) << ( 16 - (int)( $sub_shift ) ) )
667 667
                     ) & 0xffff
668 668
                 );
669 669
             }
@@ -676,47 +676,47 @@  discard block
 block discarded – undo
676 676
      * @throws SodiumException
677 677
      * @throws TypeError
678 678
      */
679
-    public function shiftLeft($c = 0)
679
+    public function shiftLeft( $c = 0 )
680 680
     {
681
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
681
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
682 682
         /** @var int $c */
683
-        $c = (int) $c;
683
+        $c = (int)$c;
684 684
 
685 685
         $return = new ParagonIE_Sodium_Core32_Int64();
686 686
         $return->unsignedInt = $this->unsignedInt;
687 687
         $c &= 63;
688 688
 
689
-        if ($c >= 16) {
690
-            if ($c >= 48) {
689
+        if ( $c >= 16 ) {
690
+            if ( $c >= 48 ) {
691 691
                 $return->limbs = array(
692
-                    $this->limbs[3], 0, 0, 0
692
+                    $this->limbs[ 3 ], 0, 0, 0
693 693
                 );
694
-            } elseif ($c >= 32) {
694
+            } elseif ( $c >= 32 ) {
695 695
                 $return->limbs = array(
696
-                    $this->limbs[2], $this->limbs[3], 0, 0
696
+                    $this->limbs[ 2 ], $this->limbs[ 3 ], 0, 0
697 697
                 );
698 698
             } else {
699 699
                 $return->limbs = array(
700
-                    $this->limbs[1], $this->limbs[2], $this->limbs[3], 0
700
+                    $this->limbs[ 1 ], $this->limbs[ 2 ], $this->limbs[ 3 ], 0
701 701
                 );
702 702
             }
703
-            return $return->shiftLeft($c & 15);
703
+            return $return->shiftLeft( $c & 15 );
704 704
         }
705
-        if ($c === 0) {
705
+        if ( $c === 0 ) {
706 706
             $return->limbs = $this->limbs;
707
-        } elseif ($c < 0) {
707
+        } elseif ( $c < 0 ) {
708 708
             /** @var int $c */
709 709
             return $this->shiftRight(-$c);
710 710
         } else {
711
-            if (!is_int($c)) {
711
+            if ( ! is_int( $c ) ) {
712 712
                 throw new TypeError();
713 713
             }
714 714
             /** @var int $carry */
715 715
             $carry = 0;
716
-            for ($i = 3; $i >= 0; --$i) {
716
+            for ( $i = 3; $i >= 0; --$i ) {
717 717
                 /** @var int $tmp */
718
-                $tmp = ($this->limbs[$i] << $c) | ($carry & 0xffff);
719
-                $return->limbs[$i] = (int) ($tmp & 0xffff);
718
+                $tmp = ( $this->limbs[ $i ] << $c ) | ( $carry & 0xffff );
719
+                $return->limbs[ $i ] = (int)( $tmp & 0xffff );
720 720
                 /** @var int $carry */
721 721
                 $carry = $tmp >> 16;
722 722
             }
@@ -730,58 +730,58 @@  discard block
 block discarded – undo
730 730
      * @throws SodiumException
731 731
      * @throws TypeError
732 732
      */
733
-    public function shiftRight($c = 0)
733
+    public function shiftRight( $c = 0 )
734 734
     {
735
-        ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
736
-        $c = (int) $c;
735
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $c, 'int', 1 );
736
+        $c = (int)$c;
737 737
         /** @var int $c */
738 738
         $return = new ParagonIE_Sodium_Core32_Int64();
739 739
         $return->unsignedInt = $this->unsignedInt;
740 740
         $c &= 63;
741 741
 
742
-        $negative = -(($this->limbs[0] >> 15) & 1);
743
-        if ($c >= 16) {
744
-            if ($c >= 48) {
742
+        $negative = -( ( $this->limbs[ 0 ] >> 15 ) & 1 );
743
+        if ( $c >= 16 ) {
744
+            if ( $c >= 48 ) {
745 745
                 $return->limbs = array(
746
-                    (int) ($negative & 0xffff),
747
-                    (int) ($negative & 0xffff),
748
-                    (int) ($negative & 0xffff),
749
-                    (int) $this->limbs[0]
746
+                    (int)( $negative & 0xffff ),
747
+                    (int)( $negative & 0xffff ),
748
+                    (int)( $negative & 0xffff ),
749
+                    (int)$this->limbs[ 0 ]
750 750
                 );
751
-            } elseif ($c >= 32) {
751
+            } elseif ( $c >= 32 ) {
752 752
                 $return->limbs = array(
753
-                    (int) ($negative & 0xffff),
754
-                    (int) ($negative & 0xffff),
755
-                    (int) $this->limbs[0],
756
-                    (int) $this->limbs[1]
753
+                    (int)( $negative & 0xffff ),
754
+                    (int)( $negative & 0xffff ),
755
+                    (int)$this->limbs[ 0 ],
756
+                    (int)$this->limbs[ 1 ]
757 757
                 );
758 758
             } else {
759 759
                 $return->limbs = array(
760
-                    (int) ($negative & 0xffff),
761
-                    (int) $this->limbs[0],
762
-                    (int) $this->limbs[1],
763
-                    (int) $this->limbs[2]
760
+                    (int)( $negative & 0xffff ),
761
+                    (int)$this->limbs[ 0 ],
762
+                    (int)$this->limbs[ 1 ],
763
+                    (int)$this->limbs[ 2 ]
764 764
                 );
765 765
             }
766
-            return $return->shiftRight($c & 15);
766
+            return $return->shiftRight( $c & 15 );
767 767
         }
768 768
 
769
-        if ($c === 0) {
769
+        if ( $c === 0 ) {
770 770
             $return->limbs = $this->limbs;
771
-        } elseif ($c < 0) {
771
+        } elseif ( $c < 0 ) {
772 772
             return $this->shiftLeft(-$c);
773 773
         } else {
774
-            if (!is_int($c)) {
774
+            if ( ! is_int( $c ) ) {
775 775
                 throw new TypeError();
776 776
             }
777 777
             /** @var int $carryRight */
778
-            $carryRight = ($negative & 0xffff);
779
-            $mask = (int) (((1 << ($c + 1)) - 1) & 0xffff);
780
-            for ($i = 0; $i < 4; ++$i) {
781
-                $return->limbs[$i] = (int) (
782
-                    (($this->limbs[$i] >> $c) | ($carryRight << (16 - $c))) & 0xffff
778
+            $carryRight = ( $negative & 0xffff );
779
+            $mask = (int)( ( ( 1 << ( $c + 1 ) ) - 1 ) & 0xffff );
780
+            for ( $i = 0; $i < 4; ++$i ) {
781
+                $return->limbs[ $i ] = (int)(
782
+                    ( ( $this->limbs[ $i ] >> $c ) | ( $carryRight << ( 16 - $c ) ) ) & 0xffff
783 783
                 );
784
-                $carryRight = (int) ($this->limbs[$i] & $mask);
784
+                $carryRight = (int)( $this->limbs[ $i ] & $mask );
785 785
             }
786 786
         }
787 787
         return $return;
@@ -796,22 +796,22 @@  discard block
 block discarded – undo
796 796
      * @throws SodiumException
797 797
      * @throws TypeError
798 798
      */
799
-    public function subInt($int)
799
+    public function subInt( $int )
800 800
     {
801
-        ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
802
-        $int = (int) $int;
801
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $int, 'int', 1 );
802
+        $int = (int)$int;
803 803
 
804 804
         $return = new ParagonIE_Sodium_Core32_Int64();
805 805
         $return->unsignedInt = $this->unsignedInt;
806 806
 
807 807
         /** @var int $carry */
808 808
         $carry = 0;
809
-        for ($i = 3; $i >= 0; --$i) {
809
+        for ( $i = 3; $i >= 0; --$i ) {
810 810
             /** @var int $tmp */
811
-            $tmp = $this->limbs[$i] - (($int >> 16) & 0xffff) + $carry;
811
+            $tmp = $this->limbs[ $i ] - ( ( $int >> 16 ) & 0xffff ) + $carry;
812 812
             /** @var int $carry */
813 813
             $carry = $tmp >> 16;
814
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
814
+            $return->limbs[ $i ] = (int)( $tmp & 0xffff );
815 815
         }
816 816
         return $return;
817 817
     }
@@ -822,18 +822,18 @@  discard block
 block discarded – undo
822 822
      * @param ParagonIE_Sodium_Core32_Int64 $b
823 823
      * @return ParagonIE_Sodium_Core32_Int64
824 824
      */
825
-    public function subInt64(ParagonIE_Sodium_Core32_Int64 $b)
825
+    public function subInt64( ParagonIE_Sodium_Core32_Int64 $b )
826 826
     {
827 827
         $return = new ParagonIE_Sodium_Core32_Int64();
828 828
         $return->unsignedInt = $this->unsignedInt;
829 829
         /** @var int $carry */
830 830
         $carry = 0;
831
-        for ($i = 3; $i >= 0; --$i) {
831
+        for ( $i = 3; $i >= 0; --$i ) {
832 832
             /** @var int $tmp */
833
-            $tmp = $this->limbs[$i] - $b->limbs[$i] + $carry;
833
+            $tmp = $this->limbs[ $i ] - $b->limbs[ $i ] + $carry;
834 834
             /** @var int $carry */
835
-            $carry = ($tmp >> 16);
836
-            $return->limbs[$i] = (int) ($tmp & 0xffff);
835
+            $carry = ( $tmp >> 16 );
836
+            $return->limbs[ $i ] = (int)( $tmp & 0xffff );
837 837
         }
838 838
         return $return;
839 839
     }
@@ -844,15 +844,15 @@  discard block
 block discarded – undo
844 844
      * @param ParagonIE_Sodium_Core32_Int64 $b
845 845
      * @return ParagonIE_Sodium_Core32_Int64
846 846
      */
847
-    public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b)
847
+    public function xorInt64( ParagonIE_Sodium_Core32_Int64 $b )
848 848
     {
849 849
         $return = new ParagonIE_Sodium_Core32_Int64();
850 850
         $return->unsignedInt = $this->unsignedInt;
851 851
         $return->limbs = array(
852
-            (int) ($this->limbs[0] ^ $b->limbs[0]),
853
-            (int) ($this->limbs[1] ^ $b->limbs[1]),
854
-            (int) ($this->limbs[2] ^ $b->limbs[2]),
855
-            (int) ($this->limbs[3] ^ $b->limbs[3])
852
+            (int)( $this->limbs[ 0 ] ^ $b->limbs[ 0 ] ),
853
+            (int)( $this->limbs[ 1 ] ^ $b->limbs[ 1 ] ),
854
+            (int)( $this->limbs[ 2 ] ^ $b->limbs[ 2 ] ),
855
+            (int)( $this->limbs[ 3 ] ^ $b->limbs[ 3 ] )
856 856
         );
857 857
         return $return;
858 858
     }
@@ -864,19 +864,19 @@  discard block
 block discarded – undo
864 864
      * @throws SodiumException
865 865
      * @throws TypeError
866 866
      */
867
-    public static function fromInts($low, $high)
867
+    public static function fromInts( $low, $high )
868 868
     {
869
-        ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
870
-        ParagonIE_Sodium_Core32_Util::declareScalarType($high, 'int', 2);
869
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $low, 'int', 1 );
870
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $high, 'int', 2 );
871 871
 
872
-        $high = (int) $high;
873
-        $low = (int) $low;
872
+        $high = (int)$high;
873
+        $low = (int)$low;
874 874
         return new ParagonIE_Sodium_Core32_Int64(
875 875
             array(
876
-                (int) (($high >> 16) & 0xffff),
877
-                (int) ($high & 0xffff),
878
-                (int) (($low >> 16) & 0xffff),
879
-                (int) ($low & 0xffff)
876
+                (int)( ( $high >> 16 ) & 0xffff ),
877
+                (int)( $high & 0xffff ),
878
+                (int)( ( $low >> 16 ) & 0xffff ),
879
+                (int)( $low & 0xffff )
880 880
             )
881 881
         );
882 882
     }
@@ -887,17 +887,17 @@  discard block
 block discarded – undo
887 887
      * @throws SodiumException
888 888
      * @throws TypeError
889 889
      */
890
-    public static function fromInt($low)
890
+    public static function fromInt( $low )
891 891
     {
892
-        ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
893
-        $low = (int) $low;
892
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $low, 'int', 1 );
893
+        $low = (int)$low;
894 894
 
895 895
         return new ParagonIE_Sodium_Core32_Int64(
896 896
             array(
897 897
                 0,
898 898
                 0,
899
-                (int) (($low >> 16) & 0xffff),
900
-                (int) ($low & 0xffff)
899
+                (int)( ( $low >> 16 ) & 0xffff ),
900
+                (int)( $low & 0xffff )
901 901
             )
902 902
         );
903 903
     }
@@ -907,10 +907,10 @@  discard block
 block discarded – undo
907 907
      */
908 908
     public function toInt()
909 909
     {
910
-        return (int) (
911
-            (($this->limbs[2] & 0xffff) << 16)
910
+        return (int)(
911
+            ( ( $this->limbs[ 2 ] & 0xffff ) << 16 )
912 912
                 |
913
-            ($this->limbs[3] & 0xffff)
913
+            ( $this->limbs[ 3 ] & 0xffff )
914 914
         );
915 915
     }
916 916
 
@@ -920,25 +920,25 @@  discard block
 block discarded – undo
920 920
      * @throws SodiumException
921 921
      * @throws TypeError
922 922
      */
923
-    public static function fromString($string)
923
+    public static function fromString( $string )
924 924
     {
925
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
926
-        $string = (string) $string;
927
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
925
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $string, 'string', 1 );
926
+        $string = (string)$string;
927
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $string ) !== 8 ) {
928 928
             throw new RangeException(
929
-                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
929
+                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen( $string ) . ' given.'
930 930
             );
931 931
         }
932 932
         $return = new ParagonIE_Sodium_Core32_Int64();
933 933
 
934
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
935
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
936
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
937
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
938
-        $return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff) << 8);
939
-        $return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff);
940
-        $return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff) << 8);
941
-        $return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff);
934
+        $return->limbs[ 0 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 0 ] ) & 0xff ) << 8 );
935
+        $return->limbs[ 0 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 1 ] ) & 0xff );
936
+        $return->limbs[ 1 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 2 ] ) & 0xff ) << 8 );
937
+        $return->limbs[ 1 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 3 ] ) & 0xff );
938
+        $return->limbs[ 2 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 4 ] ) & 0xff ) << 8 );
939
+        $return->limbs[ 2 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 5 ] ) & 0xff );
940
+        $return->limbs[ 3 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 6 ] ) & 0xff ) << 8 );
941
+        $return->limbs[ 3 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 7 ] ) & 0xff );
942 942
         return $return;
943 943
     }
944 944
 
@@ -948,25 +948,25 @@  discard block
 block discarded – undo
948 948
      * @throws SodiumException
949 949
      * @throws TypeError
950 950
      */
951
-    public static function fromReverseString($string)
951
+    public static function fromReverseString( $string )
952 952
     {
953
-        ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
954
-        $string = (string) $string;
955
-        if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
953
+        ParagonIE_Sodium_Core32_Util::declareScalarType( $string, 'string', 1 );
954
+        $string = (string)$string;
955
+        if ( ParagonIE_Sodium_Core32_Util::strlen( $string ) !== 8 ) {
956 956
             throw new RangeException(
957
-                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
957
+                'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen( $string ) . ' given.'
958 958
             );
959 959
         }
960 960
         $return = new ParagonIE_Sodium_Core32_Int64();
961 961
 
962
-        $return->limbs[0]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff) << 8);
963
-        $return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff);
964
-        $return->limbs[1]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff) << 8);
965
-        $return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff);
966
-        $return->limbs[2]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
967
-        $return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
968
-        $return->limbs[3]  = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
969
-        $return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
962
+        $return->limbs[ 0 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 7 ] ) & 0xff ) << 8 );
963
+        $return->limbs[ 0 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 6 ] ) & 0xff );
964
+        $return->limbs[ 1 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 5 ] ) & 0xff ) << 8 );
965
+        $return->limbs[ 1 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 4 ] ) & 0xff );
966
+        $return->limbs[ 2 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 3 ] ) & 0xff ) << 8 );
967
+        $return->limbs[ 2 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 2 ] ) & 0xff );
968
+        $return->limbs[ 3 ]  = (int)( ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 1 ] ) & 0xff ) << 8 );
969
+        $return->limbs[ 3 ] |= ( ParagonIE_Sodium_Core32_Util::chrToInt( $string[ 0 ] ) & 0xff );
970 970
         return $return;
971 971
     }
972 972
 
@@ -976,8 +976,8 @@  discard block
 block discarded – undo
976 976
     public function toArray()
977 977
     {
978 978
         return array(
979
-            (int) ((($this->limbs[0] & 0xffff) << 16) | ($this->limbs[1] & 0xffff)),
980
-            (int) ((($this->limbs[2] & 0xffff) << 16) | ($this->limbs[3] & 0xffff))
979
+            (int)( ( ( $this->limbs[ 0 ] & 0xffff ) << 16 ) | ( $this->limbs[ 1 ] & 0xffff ) ),
980
+            (int)( ( ( $this->limbs[ 2 ] & 0xffff ) << 16 ) | ( $this->limbs[ 3 ] & 0xffff ) )
981 981
         );
982 982
     }
983 983
 
@@ -987,10 +987,10 @@  discard block
 block discarded – undo
987 987
     public function toInt32()
988 988
     {
989 989
         $return = new ParagonIE_Sodium_Core32_Int32();
990
-        $return->limbs[0] = (int) ($this->limbs[2]);
991
-        $return->limbs[1] = (int) ($this->limbs[3]);
990
+        $return->limbs[ 0 ] = (int)( $this->limbs[ 2 ] );
991
+        $return->limbs[ 1 ] = (int)( $this->limbs[ 3 ] );
992 992
         $return->unsignedInt = $this->unsignedInt;
993
-        $return->overflow = (int) (ParagonIE_Sodium_Core32_Util::abs($this->limbs[1], 16) & 0xffff);
993
+        $return->overflow = (int)( ParagonIE_Sodium_Core32_Util::abs( $this->limbs[ 1 ], 16 ) & 0xffff );
994 994
         return $return;
995 995
     }
996 996
 
@@ -1000,12 +1000,12 @@  discard block
 block discarded – undo
1000 1000
     public function toInt64()
1001 1001
     {
1002 1002
         $return = new ParagonIE_Sodium_Core32_Int64();
1003
-        $return->limbs[0] = (int) ($this->limbs[0]);
1004
-        $return->limbs[1] = (int) ($this->limbs[1]);
1005
-        $return->limbs[2] = (int) ($this->limbs[2]);
1006
-        $return->limbs[3] = (int) ($this->limbs[3]);
1003
+        $return->limbs[ 0 ] = (int)( $this->limbs[ 0 ] );
1004
+        $return->limbs[ 1 ] = (int)( $this->limbs[ 1 ] );
1005
+        $return->limbs[ 2 ] = (int)( $this->limbs[ 2 ] );
1006
+        $return->limbs[ 3 ] = (int)( $this->limbs[ 3 ] );
1007 1007
         $return->unsignedInt = $this->unsignedInt;
1008
-        $return->overflow = ParagonIE_Sodium_Core32_Util::abs($this->overflow);
1008
+        $return->overflow = ParagonIE_Sodium_Core32_Util::abs( $this->overflow );
1009 1009
         return $return;
1010 1010
     }
1011 1011
 
@@ -1013,9 +1013,9 @@  discard block
 block discarded – undo
1013 1013
      * @param bool $bool
1014 1014
      * @return self
1015 1015
      */
1016
-    public function setUnsignedInt($bool = false)
1016
+    public function setUnsignedInt( $bool = false )
1017 1017
     {
1018
-        $this->unsignedInt = !empty($bool);
1018
+        $this->unsignedInt = ! empty( $bool );
1019 1019
         return $this;
1020 1020
     }
1021 1021
 
@@ -1025,14 +1025,14 @@  discard block
 block discarded – undo
1025 1025
      */
1026 1026
     public function toString()
1027 1027
     {
1028
-        return ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
1029
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1030
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
1031
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
1032
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
1033
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
1034
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1035
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff);
1028
+        return ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 0 ] >> 8 ) & 0xff ) .
1029
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 0 ] & 0xff ) .
1030
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 1 ] >> 8 ) & 0xff ) .
1031
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 1 ] & 0xff ) .
1032
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 2 ] >> 8 ) & 0xff ) .
1033
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 2 ] & 0xff ) .
1034
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 3 ] >> 8 ) & 0xff ) .
1035
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 3 ] & 0xff );
1036 1036
     }
1037 1037
 
1038 1038
     /**
@@ -1041,14 +1041,14 @@  discard block
 block discarded – undo
1041 1041
      */
1042 1042
     public function toReverseString()
1043 1043
     {
1044
-        return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff) .
1045
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1046
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
1047
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[2] >> 8) & 0xff) .
1048
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
1049
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
1050
-            ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1051
-            ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
1044
+        return ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 3 ] & 0xff ) .
1045
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 3 ] >> 8 ) & 0xff ) .
1046
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 2 ] & 0xff ) .
1047
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 2 ] >> 8 ) & 0xff ) .
1048
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 1 ] & 0xff ) .
1049
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 1 ] >> 8 ) & 0xff ) .
1050
+            ParagonIE_Sodium_Core32_Util::intToChr( $this->limbs[ 0 ] & 0xff ) .
1051
+            ParagonIE_Sodium_Core32_Util::intToChr( ( $this->limbs[ 0 ] >> 8 ) & 0xff );
1052 1052
     }
1053 1053
 
1054 1054
     /**
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
     {
1059 1059
         try {
1060 1060
             return $this->toString();
1061
-        } catch (TypeError $ex) {
1061
+        } catch ( TypeError $ex ) {
1062 1062
             // PHP engine can't handle exceptions from __toString()
1063 1063
             return '';
1064 1064
         }
Please login to merge, or discard this patch.
Braces   +33 added lines, -66 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  * These are immutable. It always returns a new instance.
9 9
  */
10
-class ParagonIE_Sodium_Core32_Int64
11
-{
10
+class ParagonIE_Sodium_Core32_Int64 {
12 11
     /**
13 12
      * @var array<int, int> - four 16-bit integers
14 13
      */
@@ -29,8 +28,7 @@  discard block
 block discarded – undo
29 28
      * @param array $array
30 29
      * @param bool $unsignedInt
31 30
      */
32
-    public function __construct($array = array(0, 0, 0, 0), $unsignedInt = false)
33
-    {
31
+    public function __construct($array = array(0, 0, 0, 0), $unsignedInt = false) {
34 32
         $this->limbs = array(
35 33
             (int) $array[0],
36 34
             (int) $array[1],
@@ -47,8 +45,7 @@  discard block
 block discarded – undo
47 45
      * @param ParagonIE_Sodium_Core32_Int64 $addend
48 46
      * @return ParagonIE_Sodium_Core32_Int64
49 47
      */
50
-    public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend)
51
-    {
48
+    public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend) {
52 49
         $i0 = $this->limbs[0];
53 50
         $i1 = $this->limbs[1];
54 51
         $i2 = $this->limbs[2];
@@ -91,8 +88,7 @@  discard block
 block discarded – undo
91 88
      * @throws SodiumException
92 89
      * @throws TypeError
93 90
      */
94
-    public function addInt($int)
95
-    {
91
+    public function addInt($int) {
96 92
         ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
97 93
         /** @var int $int */
98 94
         $int = (int) $int;
@@ -130,8 +126,7 @@  discard block
 block discarded – undo
130 126
      * @param int $b
131 127
      * @return int
132 128
      */
133
-    public function compareInt($b = 0)
134
-    {
129
+    public function compareInt($b = 0) {
135 130
         $gt = 0;
136 131
         $eq = 1;
137 132
 
@@ -155,8 +150,7 @@  discard block
 block discarded – undo
155 150
      * @param int $b
156 151
      * @return bool
157 152
      */
158
-    public function isGreaterThan($b = 0)
159
-    {
153
+    public function isGreaterThan($b = 0) {
160 154
         return $this->compareInt($b) > 0;
161 155
     }
162 156
 
@@ -164,8 +158,7 @@  discard block
 block discarded – undo
164 158
      * @param int $b
165 159
      * @return bool
166 160
      */
167
-    public function isLessThanInt($b = 0)
168
-    {
161
+    public function isLessThanInt($b = 0) {
169 162
         return $this->compareInt($b) < 0;
170 163
     }
171 164
 
@@ -174,8 +167,7 @@  discard block
 block discarded – undo
174 167
      * @param int $lo
175 168
      * @return ParagonIE_Sodium_Core32_Int64
176 169
      */
177
-    public function mask64($hi = 0, $lo = 0)
178
-    {
170
+    public function mask64($hi = 0, $lo = 0) {
179 171
         /** @var int $a */
180 172
         $a = ($hi >> 16) & 0xffff;
181 173
         /** @var int $b */
@@ -203,8 +195,7 @@  discard block
 block discarded – undo
203 195
      * @throws TypeError
204 196
      * @psalm-suppress MixedAssignment
205 197
      */
206
-    public function mulInt($int = 0, $size = 0)
207
-    {
198
+    public function mulInt($int = 0, $size = 0) {
208 199
         if (ParagonIE_Sodium_Compat::$fastMult) {
209 200
             return $this->mulIntFast($int);
210 201
         }
@@ -326,8 +317,7 @@  discard block
 block discarded – undo
326 317
      * @param int $baseLog2
327 318
      * @return array<int, int>
328 319
      */
329
-    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
330
-    {
320
+    public function multiplyLong(array $a, array $b, $baseLog2 = 16) {
331 321
         $a_l = count($a);
332 322
         $b_l = count($b);
333 323
         /** @var array<int, int> $r */
@@ -350,8 +340,7 @@  discard block
 block discarded – undo
350 340
      * @param int $int
351 341
      * @return ParagonIE_Sodium_Core32_Int64
352 342
      */
353
-    public function mulIntFast($int)
354
-    {
343
+    public function mulIntFast($int) {
355 344
         // Handle negative numbers
356 345
         $aNeg = ($this->limbs[0] >> 15) & 1;
357 346
         $bNeg = ($int >> 31) & 1;
@@ -410,8 +399,7 @@  discard block
 block discarded – undo
410 399
      * @param ParagonIE_Sodium_Core32_Int64 $right
411 400
      * @return ParagonIE_Sodium_Core32_Int64
412 401
      */
413
-    public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right)
414
-    {
402
+    public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right) {
415 403
         $aNeg = ($this->limbs[0] >> 15) & 1;
416 404
         $bNeg = ($right->limbs[0] >> 15) & 1;
417 405
 
@@ -464,8 +452,7 @@  discard block
 block discarded – undo
464 452
      * @throws TypeError
465 453
      * @psalm-suppress MixedAssignment
466 454
      */
467
-    public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0)
468
-    {
455
+    public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0) {
469 456
         if (ParagonIE_Sodium_Compat::$fastMult) {
470 457
             return $this->mulInt64Fast($int);
471 458
         }
@@ -558,8 +545,7 @@  discard block
 block discarded – undo
558 545
      * @param ParagonIE_Sodium_Core32_Int64 $b
559 546
      * @return ParagonIE_Sodium_Core32_Int64
560 547
      */
561
-    public function orInt64(ParagonIE_Sodium_Core32_Int64 $b)
562
-    {
548
+    public function orInt64(ParagonIE_Sodium_Core32_Int64 $b) {
563 549
         $return = new ParagonIE_Sodium_Core32_Int64();
564 550
         $return->unsignedInt = $this->unsignedInt;
565 551
         $return->limbs = array(
@@ -578,8 +564,7 @@  discard block
 block discarded – undo
578 564
      * @throws TypeError
579 565
      * @psalm-suppress MixedArrayAccess
580 566
      */
581
-    public function rotateLeft($c = 0)
582
-    {
567
+    public function rotateLeft($c = 0) {
583 568
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
584 569
         /** @var int $c */
585 570
         $c = (int) $c;
@@ -628,8 +613,7 @@  discard block
 block discarded – undo
628 613
      * @throws TypeError
629 614
      * @psalm-suppress MixedArrayAccess
630 615
      */
631
-    public function rotateRight($c = 0)
632
-    {
616
+    public function rotateRight($c = 0) {
633 617
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
634 618
         /** @var int $c */
635 619
         $c = (int) $c;
@@ -676,8 +660,7 @@  discard block
 block discarded – undo
676 660
      * @throws SodiumException
677 661
      * @throws TypeError
678 662
      */
679
-    public function shiftLeft($c = 0)
680
-    {
663
+    public function shiftLeft($c = 0) {
681 664
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
682 665
         /** @var int $c */
683 666
         $c = (int) $c;
@@ -730,8 +713,7 @@  discard block
 block discarded – undo
730 713
      * @throws SodiumException
731 714
      * @throws TypeError
732 715
      */
733
-    public function shiftRight($c = 0)
734
-    {
716
+    public function shiftRight($c = 0) {
735 717
         ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
736 718
         $c = (int) $c;
737 719
         /** @var int $c */
@@ -796,8 +778,7 @@  discard block
 block discarded – undo
796 778
      * @throws SodiumException
797 779
      * @throws TypeError
798 780
      */
799
-    public function subInt($int)
800
-    {
781
+    public function subInt($int) {
801 782
         ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
802 783
         $int = (int) $int;
803 784
 
@@ -822,8 +803,7 @@  discard block
 block discarded – undo
822 803
      * @param ParagonIE_Sodium_Core32_Int64 $b
823 804
      * @return ParagonIE_Sodium_Core32_Int64
824 805
      */
825
-    public function subInt64(ParagonIE_Sodium_Core32_Int64 $b)
826
-    {
806
+    public function subInt64(ParagonIE_Sodium_Core32_Int64 $b) {
827 807
         $return = new ParagonIE_Sodium_Core32_Int64();
828 808
         $return->unsignedInt = $this->unsignedInt;
829 809
         /** @var int $carry */
@@ -844,8 +824,7 @@  discard block
 block discarded – undo
844 824
      * @param ParagonIE_Sodium_Core32_Int64 $b
845 825
      * @return ParagonIE_Sodium_Core32_Int64
846 826
      */
847
-    public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b)
848
-    {
827
+    public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b) {
849 828
         $return = new ParagonIE_Sodium_Core32_Int64();
850 829
         $return->unsignedInt = $this->unsignedInt;
851 830
         $return->limbs = array(
@@ -864,8 +843,7 @@  discard block
 block discarded – undo
864 843
      * @throws SodiumException
865 844
      * @throws TypeError
866 845
      */
867
-    public static function fromInts($low, $high)
868
-    {
846
+    public static function fromInts($low, $high) {
869 847
         ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
870 848
         ParagonIE_Sodium_Core32_Util::declareScalarType($high, 'int', 2);
871 849
 
@@ -887,8 +865,7 @@  discard block
 block discarded – undo
887 865
      * @throws SodiumException
888 866
      * @throws TypeError
889 867
      */
890
-    public static function fromInt($low)
891
-    {
868
+    public static function fromInt($low) {
892 869
         ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
893 870
         $low = (int) $low;
894 871
 
@@ -905,8 +882,7 @@  discard block
 block discarded – undo
905 882
     /**
906 883
      * @return int
907 884
      */
908
-    public function toInt()
909
-    {
885
+    public function toInt() {
910 886
         return (int) (
911 887
             (($this->limbs[2] & 0xffff) << 16)
912 888
                 |
@@ -920,8 +896,7 @@  discard block
 block discarded – undo
920 896
      * @throws SodiumException
921 897
      * @throws TypeError
922 898
      */
923
-    public static function fromString($string)
924
-    {
899
+    public static function fromString($string) {
925 900
         ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
926 901
         $string = (string) $string;
927 902
         if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
@@ -948,8 +923,7 @@  discard block
 block discarded – undo
948 923
      * @throws SodiumException
949 924
      * @throws TypeError
950 925
      */
951
-    public static function fromReverseString($string)
952
-    {
926
+    public static function fromReverseString($string) {
953 927
         ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
954 928
         $string = (string) $string;
955 929
         if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
@@ -973,8 +947,7 @@  discard block
 block discarded – undo
973 947
     /**
974 948
      * @return array<int, int>
975 949
      */
976
-    public function toArray()
977
-    {
950
+    public function toArray() {
978 951
         return array(
979 952
             (int) ((($this->limbs[0] & 0xffff) << 16) | ($this->limbs[1] & 0xffff)),
980 953
             (int) ((($this->limbs[2] & 0xffff) << 16) | ($this->limbs[3] & 0xffff))
@@ -984,8 +957,7 @@  discard block
 block discarded – undo
984 957
     /**
985 958
      * @return ParagonIE_Sodium_Core32_Int32
986 959
      */
987
-    public function toInt32()
988
-    {
960
+    public function toInt32() {
989 961
         $return = new ParagonIE_Sodium_Core32_Int32();
990 962
         $return->limbs[0] = (int) ($this->limbs[2]);
991 963
         $return->limbs[1] = (int) ($this->limbs[3]);
@@ -997,8 +969,7 @@  discard block
 block discarded – undo
997 969
     /**
998 970
      * @return ParagonIE_Sodium_Core32_Int64
999 971
      */
1000
-    public function toInt64()
1001
-    {
972
+    public function toInt64() {
1002 973
         $return = new ParagonIE_Sodium_Core32_Int64();
1003 974
         $return->limbs[0] = (int) ($this->limbs[0]);
1004 975
         $return->limbs[1] = (int) ($this->limbs[1]);
@@ -1013,8 +984,7 @@  discard block
 block discarded – undo
1013 984
      * @param bool $bool
1014 985
      * @return self
1015 986
      */
1016
-    public function setUnsignedInt($bool = false)
1017
-    {
987
+    public function setUnsignedInt($bool = false) {
1018 988
         $this->unsignedInt = !empty($bool);
1019 989
         return $this;
1020 990
     }
@@ -1023,8 +993,7 @@  discard block
 block discarded – undo
1023 993
      * @return string
1024 994
      * @throws TypeError
1025 995
      */
1026
-    public function toString()
1027
-    {
996
+    public function toString() {
1028 997
         return ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
1029 998
             ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
1030 999
             ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
@@ -1039,8 +1008,7 @@  discard block
 block discarded – undo
1039 1008
      * @return string
1040 1009
      * @throws TypeError
1041 1010
      */
1042
-    public function toReverseString()
1043
-    {
1011
+    public function toReverseString() {
1044 1012
         return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[3] & 0xff) .
1045 1013
             ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[3] >> 8) & 0xff) .
1046 1014
             ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[2] & 0xff) .
@@ -1054,8 +1022,7 @@  discard block
 block discarded – undo
1054 1022
     /**
1055 1023
      * @return string
1056 1024
      */
1057
-    public function __toString()
1058
-    {
1025
+    public function __toString() {
1059 1026
         try {
1060 1027
             return $this->toString();
1061 1028
         } catch (TypeError $ex) {
Please login to merge, or discard this patch.