@@ -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" */ |
@@ -7,8 +7,7 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * Class ParagonIE_Sodium_Core32_XChaCha20 |
| 9 | 9 | */ |
| 10 | -class ParagonIE_Sodium_Core32_XChaCha20 extends ParagonIE_Sodium_Core32_HChaCha20 |
|
| 11 | -{ |
|
| 10 | +class ParagonIE_Sodium_Core32_XChaCha20 extends ParagonIE_Sodium_Core32_HChaCha20 { |
|
| 12 | 11 | /** |
| 13 | 12 | * @internal You should not use this directly from another application |
| 14 | 13 | * |
@@ -19,8 +18,7 @@ discard block |
||
| 19 | 18 | * @throws SodiumException |
| 20 | 19 | * @throws TypeError |
| 21 | 20 | */ |
| 22 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
| 23 | - { |
|
| 21 | + public static function stream($len = 64, $nonce = '', $key = '') { |
|
| 24 | 22 | if (self::strlen($nonce) !== 24) { |
| 25 | 23 | throw new SodiumException('Nonce must be 24 bytes long'); |
| 26 | 24 | } |
@@ -47,8 +45,7 @@ discard block |
||
| 47 | 45 | * @throws SodiumException |
| 48 | 46 | * @throws TypeError |
| 49 | 47 | */ |
| 50 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
| 51 | - { |
|
| 48 | + public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { |
|
| 52 | 49 | if (self::strlen($nonce) !== 24) { |
| 53 | 50 | throw new SodiumException('Nonce must be 24 bytes long'); |
| 54 | 51 | } |
@@ -7,8 +7,7 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * Class ParagonIE_Sodium_Core32_X25519 |
| 9 | 9 | */ |
| 10 | -abstract class ParagonIE_Sodium_Core32_X25519 extends ParagonIE_Sodium_Core32_Curve25519 |
|
| 11 | -{ |
|
| 10 | +abstract class ParagonIE_Sodium_Core32_X25519 extends ParagonIE_Sodium_Core32_Curve25519 { |
|
| 12 | 11 | /** |
| 13 | 12 | * Alters the objects passed to this method in place. |
| 14 | 13 | * |
@@ -100,8 +99,7 @@ discard block |
||
| 100 | 99 | * @psalm-suppress MixedAssignment |
| 101 | 100 | * @psalm-suppress MixedMethodCall |
| 102 | 101 | */ |
| 103 | - public static function fe_mul121666(ParagonIE_Sodium_Core32_Curve25519_Fe $f) |
|
| 104 | - { |
|
| 102 | + public static function fe_mul121666(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { |
|
| 105 | 103 | /** @var array<int, ParagonIE_Sodium_Core32_Int64> $h */ |
| 106 | 104 | $h = array(); |
| 107 | 105 | for ($i = 0; $i < 10; ++$i) { |
@@ -167,8 +165,7 @@ discard block |
||
| 167 | 165 | * @throws SodiumException |
| 168 | 166 | * @throws TypeError |
| 169 | 167 | */ |
| 170 | - public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
| 171 | - { |
|
| 168 | + public static function crypto_scalarmult_curve25519_ref10($n, $p) { |
|
| 172 | 169 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
| 173 | 170 | $e = '' . $n; |
| 174 | 171 | # e[0] &= 248; |
@@ -315,8 +312,7 @@ discard block |
||
| 315 | 312 | * @throws SodiumException |
| 316 | 313 | * @throws TypeError |
| 317 | 314 | */ |
| 318 | - public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
| 319 | - { |
|
| 315 | + public static function crypto_scalarmult_curve25519_ref10_base($n) { |
|
| 320 | 316 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
| 321 | 317 | $e = '' . $n; |
| 322 | 318 | |
@@ -7,8 +7,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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) { |