@@ -7,8 +7,7 @@ |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Curve25519_Ge_Precomp |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_Curve25519_Ge_Precomp |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_Curve25519_Ge_Precomp { |
|
12 | 11 | /** |
13 | 12 | * @var ParagonIE_Sodium_Core_Curve25519_Fe |
14 | 13 | */ |
@@ -3,8 +3,7 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Class ParagonIE_Sodium_Core_Ristretto255 |
5 | 5 | */ |
6 | -class ParagonIE_Sodium_Core_Ristretto255 extends ParagonIE_Sodium_Core_Ed25519 |
|
7 | -{ |
|
6 | +class ParagonIE_Sodium_Core_Ristretto255 extends ParagonIE_Sodium_Core_Ed25519 { |
|
8 | 7 | const crypto_core_ristretto255_HASHBYTES = 64; |
9 | 8 | const HASH_SC_L = 48; |
10 | 9 | const CORE_H2C_SHA256 = 1; |
@@ -15,8 +14,7 @@ discard block |
||
15 | 14 | * @param int $b |
16 | 15 | * @return ParagonIE_Sodium_Core_Curve25519_Fe |
17 | 16 | */ |
18 | - public static function fe_cneg(ParagonIE_Sodium_Core_Curve25519_Fe $f, $b) |
|
19 | - { |
|
17 | + public static function fe_cneg(ParagonIE_Sodium_Core_Curve25519_Fe $f, $b) { |
|
20 | 18 | $negf = self::fe_neg($f); |
21 | 19 | return self::fe_cmov($f, $negf, $b); |
22 | 20 | } |
@@ -26,8 +24,7 @@ discard block |
||
26 | 24 | * @return ParagonIE_Sodium_Core_Curve25519_Fe |
27 | 25 | * @throws SodiumException |
28 | 26 | */ |
29 | - public static function fe_abs(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
30 | - { |
|
27 | + public static function fe_abs(ParagonIE_Sodium_Core_Curve25519_Fe $f) { |
|
31 | 28 | return self::fe_cneg($f, self::fe_isnegative($f)); |
32 | 29 | } |
33 | 30 | |
@@ -40,8 +37,7 @@ discard block |
||
40 | 37 | * @return int |
41 | 38 | * @throws SodiumException |
42 | 39 | */ |
43 | - public static function fe_iszero(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
44 | - { |
|
40 | + public static function fe_iszero(ParagonIE_Sodium_Core_Curve25519_Fe $f) { |
|
45 | 41 | static $zero; |
46 | 42 | if ($zero === null) { |
47 | 43 | $zero = str_repeat("\x00", 32); |
@@ -120,8 +116,7 @@ discard block |
||
120 | 116 | * @return int |
121 | 117 | * @throws SodiumException |
122 | 118 | */ |
123 | - public static function ristretto255_point_is_canonical($s) |
|
124 | - { |
|
119 | + public static function ristretto255_point_is_canonical($s) { |
|
125 | 120 | $c = (self::chrToInt($s[31]) & 0x7f) ^ 0x7f; |
126 | 121 | for ($i = 30; $i > 0; --$i) { |
127 | 122 | $c |= self::chrToInt($s[$i]) ^ 0xff; |
@@ -139,8 +134,7 @@ discard block |
||
139 | 134 | * @return array{h: ParagonIE_Sodium_Core_Curve25519_Ge_P3, res: int} |
140 | 135 | * @throws SodiumException |
141 | 136 | */ |
142 | - public static function ristretto255_frombytes($s, $skipCanonicalCheck = false) |
|
143 | - { |
|
137 | + public static function ristretto255_frombytes($s, $skipCanonicalCheck = false) { |
|
144 | 138 | if (!$skipCanonicalCheck) { |
145 | 139 | if (!self::ristretto255_point_is_canonical($s)) { |
146 | 140 | throw new SodiumException('S is not canonical'); |
@@ -193,8 +187,7 @@ discard block |
||
193 | 187 | * @return string |
194 | 188 | * @throws SodiumException |
195 | 189 | */ |
196 | - public static function ristretto255_p3_tobytes(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $h) |
|
197 | - { |
|
190 | + public static function ristretto255_p3_tobytes(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $h) { |
|
198 | 191 | $sqrtm1 = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$sqrtm1); |
199 | 192 | $invsqrtamd = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$invsqrtamd); |
200 | 193 | |
@@ -254,8 +247,7 @@ discard block |
||
254 | 247 | * |
255 | 248 | * @throws SodiumException |
256 | 249 | */ |
257 | - public static function ristretto255_elligator(ParagonIE_Sodium_Core_Curve25519_Fe $t) |
|
258 | - { |
|
250 | + public static function ristretto255_elligator(ParagonIE_Sodium_Core_Curve25519_Fe $t) { |
|
259 | 251 | $sqrtm1 = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$sqrtm1); |
260 | 252 | $onemsqd = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$onemsqd); |
261 | 253 | $d = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$d); |
@@ -326,8 +318,7 @@ discard block |
||
326 | 318 | * @return string |
327 | 319 | * @throws SodiumException |
328 | 320 | */ |
329 | - public static function ristretto255_from_hash($h) |
|
330 | - { |
|
321 | + public static function ristretto255_from_hash($h) { |
|
331 | 322 | if (self::strlen($h) !== 64) { |
332 | 323 | throw new SodiumException('Hash must be 64 bytes'); |
333 | 324 | } |
@@ -360,8 +351,7 @@ discard block |
||
360 | 351 | * @return int |
361 | 352 | * @throws SodiumException |
362 | 353 | */ |
363 | - public static function is_valid_point($p) |
|
364 | - { |
|
354 | + public static function is_valid_point($p) { |
|
365 | 355 | $result = self::ristretto255_frombytes($p); |
366 | 356 | if ($result['res'] !== 0) { |
367 | 357 | return 0; |
@@ -375,8 +365,7 @@ discard block |
||
375 | 365 | * @return string |
376 | 366 | * @throws SodiumException |
377 | 367 | */ |
378 | - public static function ristretto255_add($p, $q) |
|
379 | - { |
|
368 | + public static function ristretto255_add($p, $q) { |
|
380 | 369 | $p_res = self::ristretto255_frombytes($p); |
381 | 370 | $q_res = self::ristretto255_frombytes($q); |
382 | 371 | if ($p_res['res'] !== 0 || $q_res['res'] !== 0) { |
@@ -396,8 +385,7 @@ discard block |
||
396 | 385 | * @return string |
397 | 386 | * @throws SodiumException |
398 | 387 | */ |
399 | - public static function ristretto255_sub($p, $q) |
|
400 | - { |
|
388 | + public static function ristretto255_sub($p, $q) { |
|
401 | 389 | $p_res = self::ristretto255_frombytes($p); |
402 | 390 | $q_res = self::ristretto255_frombytes($q); |
403 | 391 | if ($p_res['res'] !== 0 || $q_res['res'] !== 0) { |
@@ -420,8 +408,7 @@ discard block |
||
420 | 408 | * @throws SodiumException |
421 | 409 | * @psalm-suppress PossiblyInvalidArgument hash API |
422 | 410 | */ |
423 | - protected static function h2c_string_to_hash_sha256($hLen, $ctx, $msg) |
|
424 | - { |
|
411 | + protected static function h2c_string_to_hash_sha256($hLen, $ctx, $msg) { |
|
425 | 412 | $h = array_fill(0, $hLen, 0); |
426 | 413 | $ctx_len = !is_null($ctx) ? self::strlen($ctx) : 0; |
427 | 414 | if ($hLen > 0xff) { |
@@ -470,8 +457,7 @@ discard block |
||
470 | 457 | * @throws SodiumException |
471 | 458 | * @psalm-suppress PossiblyInvalidArgument hash API |
472 | 459 | */ |
473 | - protected static function h2c_string_to_hash_sha512($hLen, $ctx, $msg) |
|
474 | - { |
|
460 | + protected static function h2c_string_to_hash_sha512($hLen, $ctx, $msg) { |
|
475 | 461 | $h = array_fill(0, $hLen, 0); |
476 | 462 | $ctx_len = !is_null($ctx) ? self::strlen($ctx) : 0; |
477 | 463 | if ($hLen > 0xff) { |
@@ -520,8 +506,7 @@ discard block |
||
520 | 506 | * @return string |
521 | 507 | * @throws SodiumException |
522 | 508 | */ |
523 | - public static function h2c_string_to_hash($hLen, $ctx, $msg, $hash_alg) |
|
524 | - { |
|
509 | + public static function h2c_string_to_hash($hLen, $ctx, $msg, $hash_alg) { |
|
525 | 510 | switch ($hash_alg) { |
526 | 511 | case self::CORE_H2C_SHA256: |
527 | 512 | return self::h2c_string_to_hash_sha256($hLen, $ctx, $msg); |
@@ -539,8 +524,7 @@ discard block |
||
539 | 524 | * @return string |
540 | 525 | * @throws SodiumException |
541 | 526 | */ |
542 | - protected static function _string_to_element($ctx, $msg, $hash_alg) |
|
543 | - { |
|
527 | + protected static function _string_to_element($ctx, $msg, $hash_alg) { |
|
544 | 528 | return self::ristretto255_from_hash( |
545 | 529 | self::h2c_string_to_hash(self::crypto_core_ristretto255_HASHBYTES, $ctx, $msg, $hash_alg) |
546 | 530 | ); |
@@ -551,8 +535,7 @@ discard block |
||
551 | 535 | * @throws SodiumException |
552 | 536 | * @throws Exception |
553 | 537 | */ |
554 | - public static function ristretto255_random() |
|
555 | - { |
|
538 | + public static function ristretto255_random() { |
|
556 | 539 | return self::ristretto255_from_hash( |
557 | 540 | ParagonIE_Sodium_Compat::randombytes_buf(self::crypto_core_ristretto255_HASHBYTES) |
558 | 541 | ); |
@@ -562,8 +545,7 @@ discard block |
||
562 | 545 | * @return string |
563 | 546 | * @throws SodiumException |
564 | 547 | */ |
565 | - public static function ristretto255_scalar_random() |
|
566 | - { |
|
548 | + public static function ristretto255_scalar_random() { |
|
567 | 549 | return self::scalar_random(); |
568 | 550 | } |
569 | 551 | |
@@ -572,8 +554,7 @@ discard block |
||
572 | 554 | * @return string |
573 | 555 | * @throws SodiumException |
574 | 556 | */ |
575 | - public static function ristretto255_scalar_complement($s) |
|
576 | - { |
|
557 | + public static function ristretto255_scalar_complement($s) { |
|
577 | 558 | return self::scalar_complement($s); |
578 | 559 | } |
579 | 560 | |
@@ -582,8 +563,7 @@ discard block |
||
582 | 563 | * @param string $s |
583 | 564 | * @return string |
584 | 565 | */ |
585 | - public static function ristretto255_scalar_invert($s) |
|
586 | - { |
|
566 | + public static function ristretto255_scalar_invert($s) { |
|
587 | 567 | return self::sc25519_invert($s); |
588 | 568 | } |
589 | 569 | |
@@ -592,8 +572,7 @@ discard block |
||
592 | 572 | * @return string |
593 | 573 | * @throws SodiumException |
594 | 574 | */ |
595 | - public static function ristretto255_scalar_negate($s) |
|
596 | - { |
|
575 | + public static function ristretto255_scalar_negate($s) { |
|
597 | 576 | return self::scalar_negate($s); |
598 | 577 | } |
599 | 578 | |
@@ -602,8 +581,7 @@ discard block |
||
602 | 581 | * @param string $y |
603 | 582 | * @return string |
604 | 583 | */ |
605 | - public static function ristretto255_scalar_add($x, $y) |
|
606 | - { |
|
584 | + public static function ristretto255_scalar_add($x, $y) { |
|
607 | 585 | return self::scalar_add($x, $y); |
608 | 586 | } |
609 | 587 | |
@@ -612,8 +590,7 @@ discard block |
||
612 | 590 | * @param string $y |
613 | 591 | * @return string |
614 | 592 | */ |
615 | - public static function ristretto255_scalar_sub($x, $y) |
|
616 | - { |
|
593 | + public static function ristretto255_scalar_sub($x, $y) { |
|
617 | 594 | return self::scalar_sub($x, $y); |
618 | 595 | } |
619 | 596 | |
@@ -622,8 +599,7 @@ discard block |
||
622 | 599 | * @param string $y |
623 | 600 | * @return string |
624 | 601 | */ |
625 | - public static function ristretto255_scalar_mul($x, $y) |
|
626 | - { |
|
602 | + public static function ristretto255_scalar_mul($x, $y) { |
|
627 | 603 | return self::sc25519_mul($x, $y); |
628 | 604 | } |
629 | 605 | |
@@ -634,8 +610,7 @@ discard block |
||
634 | 610 | * @return string |
635 | 611 | * @throws SodiumException |
636 | 612 | */ |
637 | - public static function ristretto255_scalar_from_string($ctx, $msg, $hash_alg) |
|
638 | - { |
|
613 | + public static function ristretto255_scalar_from_string($ctx, $msg, $hash_alg) { |
|
639 | 614 | $h = array_fill(0, 64, 0); |
640 | 615 | $h_be = self::stringToIntArray( |
641 | 616 | self::h2c_string_to_hash( |
@@ -653,8 +628,7 @@ discard block |
||
653 | 628 | * @param string $s |
654 | 629 | * @return string |
655 | 630 | */ |
656 | - public static function ristretto255_scalar_reduce($s) |
|
657 | - { |
|
631 | + public static function ristretto255_scalar_reduce($s) { |
|
658 | 632 | return self::sc_reduce($s); |
659 | 633 | } |
660 | 634 | |
@@ -664,8 +638,7 @@ discard block |
||
664 | 638 | * @return string |
665 | 639 | * @throws SodiumException |
666 | 640 | */ |
667 | - public static function scalarmult_ristretto255($n, $p) |
|
668 | - { |
|
641 | + public static function scalarmult_ristretto255($n, $p) { |
|
669 | 642 | if (self::strlen($n) !== 32) { |
670 | 643 | throw new SodiumException('Scalar must be 32 bytes, ' . self::strlen($p) . ' given.'); |
671 | 644 | } |
@@ -693,8 +666,7 @@ discard block |
||
693 | 666 | * @return string |
694 | 667 | * @throws SodiumException |
695 | 668 | */ |
696 | - public static function scalarmult_ristretto255_base($n) |
|
697 | - { |
|
669 | + public static function scalarmult_ristretto255_base($n) { |
|
698 | 670 | $t = self::stringToIntArray($n); |
699 | 671 | $t[31] &= 0x7f; |
700 | 672 | $Q = self::ge_scalarmult_base(self::intArrayToString($t)); |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_ChaCha20_Ctx |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess { |
|
12 | 11 | /** |
13 | 12 | * @var SplFixedArray internally, <int, int> |
14 | 13 | */ |
@@ -26,8 +25,7 @@ discard block |
||
26 | 25 | * @throws InvalidArgumentException |
27 | 26 | * @throws TypeError |
28 | 27 | */ |
29 | - public function __construct($key = '', $iv = '', $counter = '') |
|
30 | - { |
|
28 | + public function __construct($key = '', $iv = '', $counter = '') { |
|
31 | 29 | if (self::strlen($key) !== 32) { |
32 | 30 | throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.'); |
33 | 31 | } |
@@ -70,8 +68,7 @@ discard block |
||
70 | 68 | * @psalm-suppress MixedArrayOffset |
71 | 69 | */ |
72 | 70 | #[ReturnTypeWillChange] |
73 | - public function offsetSet($offset, $value) |
|
74 | - { |
|
71 | + public function offsetSet($offset, $value) { |
|
75 | 72 | if (!is_int($offset)) { |
76 | 73 | throw new InvalidArgumentException('Expected an integer'); |
77 | 74 | } |
@@ -88,8 +85,7 @@ discard block |
||
88 | 85 | * @return bool |
89 | 86 | */ |
90 | 87 | #[ReturnTypeWillChange] |
91 | - public function offsetExists($offset) |
|
92 | - { |
|
88 | + public function offsetExists($offset) { |
|
93 | 89 | return isset($this->container[$offset]); |
94 | 90 | } |
95 | 91 | |
@@ -101,8 +97,7 @@ discard block |
||
101 | 97 | * @psalm-suppress MixedArrayOffset |
102 | 98 | */ |
103 | 99 | #[ReturnTypeWillChange] |
104 | - public function offsetUnset($offset) |
|
105 | - { |
|
100 | + public function offsetUnset($offset) { |
|
106 | 101 | unset($this->container[$offset]); |
107 | 102 | } |
108 | 103 | |
@@ -114,8 +109,7 @@ discard block |
||
114 | 109 | * @psalm-suppress MixedArrayOffset |
115 | 110 | */ |
116 | 111 | #[ReturnTypeWillChange] |
117 | - public function offsetGet($offset) |
|
118 | - { |
|
112 | + public function offsetGet($offset) { |
|
119 | 113 | return isset($this->container[$offset]) |
120 | 114 | ? $this->container[$offset] |
121 | 115 | : null; |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_ChaCha20_IetfCtx |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_ChaCha20_IetfCtx extends ParagonIE_Sodium_Core_ChaCha20_Ctx |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_ChaCha20_IetfCtx extends ParagonIE_Sodium_Core_ChaCha20_Ctx { |
|
12 | 11 | /** |
13 | 12 | * ParagonIE_Sodium_Core_ChaCha20_IetfCtx constructor. |
14 | 13 | * |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * @throws InvalidArgumentException |
22 | 21 | * @throws TypeError |
23 | 22 | */ |
24 | - public function __construct($key = '', $iv = '', $counter = '') |
|
25 | - { |
|
23 | + public function __construct($key = '', $iv = '', $counter = '') { |
|
26 | 24 | if (self::strlen($iv) !== 12) { |
27 | 25 | throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.'); |
28 | 26 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | /** |
5 | 5 | * Class SodiumException |
6 | 6 | */ |
7 | - class SodiumException extends Exception |
|
8 | - { |
|
7 | + class SodiumException extends Exception { |
|
9 | 8 | |
10 | 9 | } |
11 | 10 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * Based on the work of Devi Mandiri in devi/salt. |
11 | 11 | */ |
12 | -abstract class ParagonIE_Sodium_Core32_BLAKE2b extends ParagonIE_Sodium_Core_Util |
|
13 | -{ |
|
12 | +abstract class ParagonIE_Sodium_Core32_BLAKE2b extends ParagonIE_Sodium_Core_Util { |
|
14 | 13 | /** |
15 | 14 | * @var SplFixedArray |
16 | 15 | */ |
@@ -49,8 +48,7 @@ discard block |
||
49 | 48 | * @throws SodiumException |
50 | 49 | * @throws TypeError |
51 | 50 | */ |
52 | - public static function new64($high, $low) |
|
53 | - { |
|
51 | + public static function new64($high, $low) { |
|
54 | 52 | return ParagonIE_Sodium_Core32_Int64::fromInts($low, $high); |
55 | 53 | } |
56 | 54 | |
@@ -65,8 +63,7 @@ discard block |
||
65 | 63 | * @throws SodiumException |
66 | 64 | * @throws TypeError |
67 | 65 | */ |
68 | - protected static function to64($num) |
|
69 | - { |
|
66 | + protected static function to64($num) { |
|
70 | 67 | list($hi, $lo) = self::numericTo64BitInteger($num); |
71 | 68 | return self::new64($hi, $lo); |
72 | 69 | } |
@@ -81,8 +78,7 @@ discard block |
||
81 | 78 | * @param ParagonIE_Sodium_Core32_Int64 $y |
82 | 79 | * @return ParagonIE_Sodium_Core32_Int64 |
83 | 80 | */ |
84 | - protected static function add64($x, $y) |
|
85 | - { |
|
81 | + protected static function add64($x, $y) { |
|
86 | 82 | return $x->addInt64($y); |
87 | 83 | } |
88 | 84 | |
@@ -94,8 +90,7 @@ discard block |
||
94 | 90 | * @param ParagonIE_Sodium_Core32_Int64 $z |
95 | 91 | * @return ParagonIE_Sodium_Core32_Int64 |
96 | 92 | */ |
97 | - public static function add364($x, $y, $z) |
|
98 | - { |
|
93 | + public static function add364($x, $y, $z) { |
|
99 | 94 | return $x->addInt64($y)->addInt64($z); |
100 | 95 | } |
101 | 96 | |
@@ -107,8 +102,7 @@ discard block |
||
107 | 102 | * @return ParagonIE_Sodium_Core32_Int64 |
108 | 103 | * @throws TypeError |
109 | 104 | */ |
110 | - public static function xor64(ParagonIE_Sodium_Core32_Int64 $x, ParagonIE_Sodium_Core32_Int64 $y) |
|
111 | - { |
|
105 | + public static function xor64(ParagonIE_Sodium_Core32_Int64 $x, ParagonIE_Sodium_Core32_Int64 $y) { |
|
112 | 106 | return $x->xorInt64($y); |
113 | 107 | } |
114 | 108 | |
@@ -121,8 +115,7 @@ discard block |
||
121 | 115 | * @throws SodiumException |
122 | 116 | * @throws TypeError |
123 | 117 | */ |
124 | - public static function rotr64(ParagonIE_Sodium_Core32_Int64 $x, $c) |
|
125 | - { |
|
118 | + public static function rotr64(ParagonIE_Sodium_Core32_Int64 $x, $c) { |
|
126 | 119 | return $x->rotateRight($c); |
127 | 120 | } |
128 | 121 | |
@@ -135,8 +128,7 @@ discard block |
||
135 | 128 | * @throws SodiumException |
136 | 129 | * @throws TypeError |
137 | 130 | */ |
138 | - public static function load64($x, $i) |
|
139 | - { |
|
131 | + public static function load64($x, $i) { |
|
140 | 132 | /** @var int $l */ |
141 | 133 | $l = (int) ($x[$i]) |
142 | 134 | | ((int) ($x[$i+1]) << 8) |
@@ -164,8 +156,7 @@ discard block |
||
164 | 156 | * @psalm-suppress MixedArrayAssignment |
165 | 157 | * @psalm-suppress MixedArrayOffset |
166 | 158 | */ |
167 | - public static function store64(SplFixedArray $x, $i, ParagonIE_Sodium_Core32_Int64 $u) |
|
168 | - { |
|
159 | + public static function store64(SplFixedArray $x, $i, ParagonIE_Sodium_Core32_Int64 $u) { |
|
169 | 160 | $v = clone $u; |
170 | 161 | $maxLength = $x->getSize() - 1; |
171 | 162 | for ($j = 0; $j < 8; ++$j) { |
@@ -187,8 +178,7 @@ discard block |
||
187 | 178 | * @throws SodiumException |
188 | 179 | * @throws TypeError |
189 | 180 | */ |
190 | - public static function pseudoConstructor() |
|
191 | - { |
|
181 | + public static function pseudoConstructor() { |
|
192 | 182 | static $called = false; |
193 | 183 | if ($called) { |
194 | 184 | return; |
@@ -221,8 +211,7 @@ discard block |
||
221 | 211 | * @throws SodiumException |
222 | 212 | * @throws TypeError |
223 | 213 | */ |
224 | - protected static function context() |
|
225 | - { |
|
214 | + protected static function context() { |
|
226 | 215 | $ctx = new SplFixedArray(6); |
227 | 216 | $ctx[0] = new SplFixedArray(8); // h |
228 | 217 | $ctx[1] = new SplFixedArray(2); // t |
@@ -260,8 +249,7 @@ discard block |
||
260 | 249 | * @psalm-suppress MixedArrayAssignment |
261 | 250 | * @psalm-suppress MixedAssignment |
262 | 251 | */ |
263 | - protected static function compress(SplFixedArray $ctx, SplFixedArray $buf) |
|
264 | - { |
|
252 | + protected static function compress(SplFixedArray $ctx, SplFixedArray $buf) { |
|
265 | 253 | $m = new SplFixedArray(16); |
266 | 254 | $v = new SplFixedArray(16); |
267 | 255 | |
@@ -318,8 +306,7 @@ discard block |
||
318 | 306 | * @psalm-suppress MixedArgument |
319 | 307 | * @psalm-suppress MixedArrayOffset |
320 | 308 | */ |
321 | - public static function G($r, $i, $a, $b, $c, $d, SplFixedArray $v, SplFixedArray $m) |
|
322 | - { |
|
309 | + public static function G($r, $i, $a, $b, $c, $d, SplFixedArray $v, SplFixedArray $m) { |
|
323 | 310 | $v[$a] = self::add364($v[$a], $v[$b], $m[self::$sigma[$r][$i << 1]]); |
324 | 311 | $v[$d] = self::rotr64(self::xor64($v[$d], $v[$a]), 32); |
325 | 312 | $v[$c] = self::add64($v[$c], $v[$d]); |
@@ -343,8 +330,7 @@ discard block |
||
343 | 330 | * @psalm-suppress MixedArrayAccess |
344 | 331 | * @psalm-suppress MixedArrayAssignment |
345 | 332 | */ |
346 | - public static function increment_counter($ctx, $inc) |
|
347 | - { |
|
333 | + public static function increment_counter($ctx, $inc) { |
|
348 | 334 | if ($inc < 0) { |
349 | 335 | throw new SodiumException('Increasing by a negative number makes no sense.'); |
350 | 336 | } |
@@ -382,8 +368,7 @@ discard block |
||
382 | 368 | * @psalm-suppress MixedMethodCall |
383 | 369 | * @psalm-suppress MixedOperand |
384 | 370 | */ |
385 | - public static function update(SplFixedArray $ctx, SplFixedArray $p, $plen) |
|
386 | - { |
|
371 | + public static function update(SplFixedArray $ctx, SplFixedArray $p, $plen) { |
|
387 | 372 | self::pseudoConstructor(); |
388 | 373 | |
389 | 374 | $offset = 0; |
@@ -446,8 +431,7 @@ discard block |
||
446 | 431 | * @psalm-suppress MixedMethodCall |
447 | 432 | * @psalm-suppress MixedOperand |
448 | 433 | */ |
449 | - public static function finish(SplFixedArray $ctx, SplFixedArray $out) |
|
450 | - { |
|
434 | + public static function finish(SplFixedArray $ctx, SplFixedArray $out) { |
|
451 | 435 | self::pseudoConstructor(); |
452 | 436 | if ($ctx[4] > 128) { |
453 | 437 | self::increment_counter($ctx, 128); |
@@ -579,8 +563,7 @@ discard block |
||
579 | 563 | * @return SplFixedArray |
580 | 564 | * @psalm-suppress MixedArgumentTypeCoercion |
581 | 565 | */ |
582 | - public static function stringToSplFixedArray($str = '') |
|
583 | - { |
|
566 | + public static function stringToSplFixedArray($str = '') { |
|
584 | 567 | $values = unpack('C*', $str); |
585 | 568 | return SplFixedArray::fromArray(array_values($values)); |
586 | 569 | } |
@@ -593,8 +576,7 @@ discard block |
||
593 | 576 | * @param SplFixedArray $a |
594 | 577 | * @return string |
595 | 578 | */ |
596 | - public static function SplFixedArrayToString(SplFixedArray $a) |
|
597 | - { |
|
579 | + public static function SplFixedArrayToString(SplFixedArray $a) { |
|
598 | 580 | /** |
599 | 581 | * @var array<int, string|int> |
600 | 582 | */ |
@@ -615,8 +597,7 @@ discard block |
||
615 | 597 | * @psalm-suppress MixedArrayAssignment |
616 | 598 | * @psalm-suppress MixedMethodCall |
617 | 599 | */ |
618 | - public static function contextToString(SplFixedArray $ctx) |
|
619 | - { |
|
600 | + public static function contextToString(SplFixedArray $ctx) { |
|
620 | 601 | $str = ''; |
621 | 602 | /** @var array<int, ParagonIE_Sodium_Core32_Int64> $ctxA */ |
622 | 603 | $ctxA = $ctx[0]->toArray(); |
@@ -682,8 +663,7 @@ discard block |
||
682 | 663 | * @psalm-suppress MixedArrayAccess |
683 | 664 | * @psalm-suppress MixedArrayAssignment |
684 | 665 | */ |
685 | - public static function stringToContext($string) |
|
686 | - { |
|
666 | + public static function stringToContext($string) { |
|
687 | 667 | $ctx = self::context(); |
688 | 668 | |
689 | 669 | # uint64_t h[8]; |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core32_Ed25519 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core32_Ed25519 extends ParagonIE_Sodium_Core32_Curve25519 |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core32_Ed25519 extends ParagonIE_Sodium_Core32_Curve25519 { |
|
12 | 11 | const KEYPAIR_BYTES = 96; |
13 | 12 | const SEED_BYTES = 32; |
14 | 13 | |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * @throws SodiumException |
21 | 20 | * @throws TypeError |
22 | 21 | */ |
23 | - public static function keypair() |
|
24 | - { |
|
22 | + public static function keypair() { |
|
25 | 23 | $seed = random_bytes(self::SEED_BYTES); |
26 | 24 | $pk = ''; |
27 | 25 | $sk = ''; |
@@ -39,8 +37,7 @@ discard block |
||
39 | 37 | * @throws SodiumException |
40 | 38 | * @throws TypeError |
41 | 39 | */ |
42 | - public static function seed_keypair(&$pk, &$sk, $seed) |
|
43 | - { |
|
40 | + public static function seed_keypair(&$pk, &$sk, $seed) { |
|
44 | 41 | if (self::strlen($seed) !== self::SEED_BYTES) { |
45 | 42 | throw new RangeException('crypto_sign keypair seed must be 32 bytes long'); |
46 | 43 | } |
@@ -58,8 +55,7 @@ discard block |
||
58 | 55 | * @return string |
59 | 56 | * @throws TypeError |
60 | 57 | */ |
61 | - public static function secretkey($keypair) |
|
62 | - { |
|
58 | + public static function secretkey($keypair) { |
|
63 | 59 | if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { |
64 | 60 | throw new RangeException('crypto_sign keypair must be 96 bytes long'); |
65 | 61 | } |
@@ -74,8 +70,7 @@ discard block |
||
74 | 70 | * @throws RangeException |
75 | 71 | * @throws TypeError |
76 | 72 | */ |
77 | - public static function publickey($keypair) |
|
78 | - { |
|
73 | + public static function publickey($keypair) { |
|
79 | 74 | if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { |
80 | 75 | throw new RangeException('crypto_sign keypair must be 96 bytes long'); |
81 | 76 | } |
@@ -90,8 +85,7 @@ discard block |
||
90 | 85 | * @throws SodiumException |
91 | 86 | * @throws TypeError |
92 | 87 | */ |
93 | - public static function publickey_from_secretkey($sk) |
|
94 | - { |
|
88 | + public static function publickey_from_secretkey($sk) { |
|
95 | 89 | /** @var string $sk */ |
96 | 90 | $sk = hash('sha512', self::substr($sk, 0, 32), true); |
97 | 91 | $sk[0] = self::intToChr( |
@@ -109,8 +103,7 @@ discard block |
||
109 | 103 | * @throws SodiumException |
110 | 104 | * @throws TypeError |
111 | 105 | */ |
112 | - public static function pk_to_curve25519($pk) |
|
113 | - { |
|
106 | + public static function pk_to_curve25519($pk) { |
|
114 | 107 | if (self::small_order($pk)) { |
115 | 108 | throw new SodiumException('Public key is on a small order'); |
116 | 109 | } |
@@ -151,8 +144,7 @@ discard block |
||
151 | 144 | * @throws SodiumException |
152 | 145 | * @throws TypeError |
153 | 146 | */ |
154 | - public static function sk_to_pk($sk) |
|
155 | - { |
|
147 | + public static function sk_to_pk($sk) { |
|
156 | 148 | return self::ge_p3_tobytes( |
157 | 149 | self::ge_scalarmult_base( |
158 | 150 | self::substr($sk, 0, 32) |
@@ -169,8 +161,7 @@ discard block |
||
169 | 161 | * @throws SodiumException |
170 | 162 | * @throws TypeError |
171 | 163 | */ |
172 | - public static function sign($message, $sk) |
|
173 | - { |
|
164 | + public static function sign($message, $sk) { |
|
174 | 165 | /** @var string $signature */ |
175 | 166 | $signature = self::sign_detached($message, $sk); |
176 | 167 | return $signature . $message; |
@@ -185,8 +176,7 @@ discard block |
||
185 | 176 | * @throws SodiumException |
186 | 177 | * @throws TypeError |
187 | 178 | */ |
188 | - public static function sign_open($message, $pk) |
|
189 | - { |
|
179 | + public static function sign_open($message, $pk) { |
|
190 | 180 | /** @var string $signature */ |
191 | 181 | $signature = self::substr($message, 0, 64); |
192 | 182 | |
@@ -209,8 +199,7 @@ discard block |
||
209 | 199 | * @throws TypeError |
210 | 200 | * @psalm-suppress PossiblyInvalidArgument |
211 | 201 | */ |
212 | - public static function sign_detached($message, $sk) |
|
213 | - { |
|
202 | + public static function sign_detached($message, $sk) { |
|
214 | 203 | # crypto_hash_sha512(az, sk, 32); |
215 | 204 | $az = hash('sha512', self::substr($sk, 0, 32), true); |
216 | 205 | |
@@ -274,8 +263,7 @@ discard block |
||
274 | 263 | * @throws SodiumException |
275 | 264 | * @throws TypeError |
276 | 265 | */ |
277 | - public static function verify_detached($sig, $message, $pk) |
|
278 | - { |
|
266 | + public static function verify_detached($sig, $message, $pk) { |
|
279 | 267 | if (self::strlen($sig) < 64) { |
280 | 268 | throw new SodiumException('Signature is too short'); |
281 | 269 | } |
@@ -341,8 +329,7 @@ discard block |
||
341 | 329 | * @throws SodiumException |
342 | 330 | * @throws TypeError |
343 | 331 | */ |
344 | - public static function check_S_lt_L($S) |
|
345 | - { |
|
332 | + public static function check_S_lt_L($S) { |
|
346 | 333 | if (self::strlen($S) < 32) { |
347 | 334 | throw new SodiumException('Signature must be 32 bytes'); |
348 | 335 | } |
@@ -377,8 +364,7 @@ discard block |
||
377 | 364 | * @throws SodiumException |
378 | 365 | * @throws TypeError |
379 | 366 | */ |
380 | - public static function small_order($R) |
|
381 | - { |
|
367 | + public static function small_order($R) { |
|
382 | 368 | static $blocklist = array( |
383 | 369 | /* 0 (order 4) */ |
384 | 370 | array( |
@@ -7,7 +7,6 @@ |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Util |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core32_Util extends ParagonIE_Sodium_Core_Util |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core32_Util extends ParagonIE_Sodium_Core_Util { |
|
12 | 11 | |
13 | 12 | } |
@@ -9,16 +9,14 @@ discard block |
||
9 | 9 | * |
10 | 10 | * Only uses 32-bit arithmetic, while the original SipHash used 64-bit integers |
11 | 11 | */ |
12 | -class ParagonIE_Sodium_Core32_SipHash extends ParagonIE_Sodium_Core32_Util |
|
13 | -{ |
|
12 | +class ParagonIE_Sodium_Core32_SipHash extends ParagonIE_Sodium_Core32_Util { |
|
14 | 13 | /** |
15 | 14 | * @internal You should not use this directly from another application |
16 | 15 | * |
17 | 16 | * @param array<int, ParagonIE_Sodium_Core32_Int64> $v |
18 | 17 | * @return array<int, ParagonIE_Sodium_Core32_Int64> |
19 | 18 | */ |
20 | - public static function sipRound(array $v) |
|
21 | - { |
|
19 | + public static function sipRound(array $v) { |
|
22 | 20 | # v0 += v1; |
23 | 21 | $v[0] = $v[0]->addInt64($v[1]); |
24 | 22 | |
@@ -73,8 +71,7 @@ discard block |
||
73 | 71 | * @throws SodiumException |
74 | 72 | * @throws TypeError |
75 | 73 | */ |
76 | - public static function sipHash24($in, $key) |
|
77 | - { |
|
74 | + public static function sipHash24($in, $key) { |
|
78 | 75 | $inlen = self::strlen($in); |
79 | 76 | |
80 | 77 | # /* "somepseudorandomlygeneratedbytes" */ |