@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises. |
7 | 7 | * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) |
8 | 8 | */ |
9 | -class ParagonIE_Sodium_Core_Base64_Original |
|
10 | -{ |
|
9 | +class ParagonIE_Sodium_Core_Base64_Original { |
|
11 | 10 | // COPY ParagonIE_Sodium_Core_Base64_Common STARTING HERE |
12 | 11 | /** |
13 | 12 | * Encode into Base64 |
@@ -18,8 +17,7 @@ discard block |
||
18 | 17 | * @return string |
19 | 18 | * @throws TypeError |
20 | 19 | */ |
21 | - public static function encode($src) |
|
22 | - { |
|
20 | + public static function encode($src) { |
|
23 | 21 | return self::doEncode($src, true); |
24 | 22 | } |
25 | 23 | |
@@ -32,8 +30,7 @@ discard block |
||
32 | 30 | * @return string |
33 | 31 | * @throws TypeError |
34 | 32 | */ |
35 | - public static function encodeUnpadded($src) |
|
36 | - { |
|
33 | + public static function encodeUnpadded($src) { |
|
37 | 34 | return self::doEncode($src, false); |
38 | 35 | } |
39 | 36 | |
@@ -43,8 +40,7 @@ discard block |
||
43 | 40 | * @return string |
44 | 41 | * @throws TypeError |
45 | 42 | */ |
46 | - protected static function doEncode($src, $pad = true) |
|
47 | - { |
|
43 | + protected static function doEncode($src, $pad = true) { |
|
48 | 44 | $dest = ''; |
49 | 45 | $srcLen = ParagonIE_Sodium_Core_Util::strlen($src); |
50 | 46 | // Main loop (no padding): |
@@ -99,8 +95,7 @@ discard block |
||
99 | 95 | * @throws TypeError |
100 | 96 | * @psalm-suppress RedundantCondition |
101 | 97 | */ |
102 | - public static function decode($src, $strictPadding = false) |
|
103 | - { |
|
98 | + public static function decode($src, $strictPadding = false) { |
|
104 | 99 | // Remove padding |
105 | 100 | $srcLen = ParagonIE_Sodium_Core_Util::strlen($src); |
106 | 101 | if ($srcLen === 0) { |
@@ -198,8 +193,7 @@ discard block |
||
198 | 193 | * @param int $src |
199 | 194 | * @return int |
200 | 195 | */ |
201 | - protected static function decode6Bits($src) |
|
202 | - { |
|
196 | + protected static function decode6Bits($src) { |
|
203 | 197 | $ret = -1; |
204 | 198 | |
205 | 199 | // if ($src > 0x40 && $src < 0x5b) $ret += $src - 0x41 + 1; // -64 |
@@ -227,8 +221,7 @@ discard block |
||
227 | 221 | * @param int $src |
228 | 222 | * @return string |
229 | 223 | */ |
230 | - protected static function encode6Bits($src) |
|
231 | - { |
|
224 | + protected static function encode6Bits($src) { |
|
232 | 225 | $diff = 0x41; |
233 | 226 | |
234 | 227 | // if ($src > 25) $diff += 0x61 - 0x41 - 26; // 6 |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises. |
7 | 7 | * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) |
8 | 8 | */ |
9 | -class ParagonIE_Sodium_Core_Base64_UrlSafe |
|
10 | -{ |
|
9 | +class ParagonIE_Sodium_Core_Base64_UrlSafe { |
|
11 | 10 | // COPY ParagonIE_Sodium_Core_Base64_Common STARTING HERE |
12 | 11 | /** |
13 | 12 | * Encode into Base64 |
@@ -18,8 +17,7 @@ discard block |
||
18 | 17 | * @return string |
19 | 18 | * @throws TypeError |
20 | 19 | */ |
21 | - public static function encode($src) |
|
22 | - { |
|
20 | + public static function encode($src) { |
|
23 | 21 | return self::doEncode($src, true); |
24 | 22 | } |
25 | 23 | |
@@ -32,8 +30,7 @@ discard block |
||
32 | 30 | * @return string |
33 | 31 | * @throws TypeError |
34 | 32 | */ |
35 | - public static function encodeUnpadded($src) |
|
36 | - { |
|
33 | + public static function encodeUnpadded($src) { |
|
37 | 34 | return self::doEncode($src, false); |
38 | 35 | } |
39 | 36 | |
@@ -43,8 +40,7 @@ discard block |
||
43 | 40 | * @return string |
44 | 41 | * @throws TypeError |
45 | 42 | */ |
46 | - protected static function doEncode($src, $pad = true) |
|
47 | - { |
|
43 | + protected static function doEncode($src, $pad = true) { |
|
48 | 44 | $dest = ''; |
49 | 45 | $srcLen = ParagonIE_Sodium_Core_Util::strlen($src); |
50 | 46 | // Main loop (no padding): |
@@ -99,8 +95,7 @@ discard block |
||
99 | 95 | * @throws TypeError |
100 | 96 | * @psalm-suppress RedundantCondition |
101 | 97 | */ |
102 | - public static function decode($src, $strictPadding = false) |
|
103 | - { |
|
98 | + public static function decode($src, $strictPadding = false) { |
|
104 | 99 | // Remove padding |
105 | 100 | $srcLen = ParagonIE_Sodium_Core_Util::strlen($src); |
106 | 101 | if ($srcLen === 0) { |
@@ -197,8 +192,7 @@ discard block |
||
197 | 192 | * @param int $src |
198 | 193 | * @return int |
199 | 194 | */ |
200 | - protected static function decode6Bits($src) |
|
201 | - { |
|
195 | + protected static function decode6Bits($src) { |
|
202 | 196 | $ret = -1; |
203 | 197 | |
204 | 198 | // if ($src > 0x40 && $src < 0x5b) $ret += $src - 0x41 + 1; // -64 |
@@ -226,8 +220,7 @@ discard block |
||
226 | 220 | * @param int $src |
227 | 221 | * @return string |
228 | 222 | */ |
229 | - protected static function encode6Bits($src) |
|
230 | - { |
|
223 | + protected static function encode6Bits($src) { |
|
231 | 224 | $diff = 0x41; |
232 | 225 | |
233 | 226 | // if ($src > 25) $diff += 0x61 - 0x41 - 26; // 6 |
@@ -3,8 +3,7 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Class ParagonIE_Sodium_Core_SecretStream_State |
5 | 5 | */ |
6 | -class ParagonIE_Sodium_Core_SecretStream_State |
|
7 | -{ |
|
6 | +class ParagonIE_Sodium_Core_SecretStream_State { |
|
8 | 7 | /** @var string $key */ |
9 | 8 | protected $key; |
10 | 9 | |
@@ -22,8 +21,7 @@ discard block |
||
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 |
||
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 |
||
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_Core_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 |
||
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_Core_Util::substr($this->getNonce(), 0, 8); |
83 | 76 | } |
@@ -85,8 +78,7 @@ discard block |
||
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 |
||
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 |
||
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_Core_Util::substr($newKeyAndNonce, 0, 32); |
109 | 99 | $this->nonce = str_pad( |
110 | 100 | ParagonIE_Sodium_Core_Util::substr($newKeyAndNonce, 32), |
@@ -119,8 +109,7 @@ discard block |
||
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_Core_Util::xorStrings( |
125 | 114 | $this->getNonce(), |
126 | 115 | str_pad( |
@@ -137,8 +126,7 @@ discard block |
||
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_Core_SecretStream_State( |
143 | 131 | ParagonIE_Sodium_Core_Util::substr($string, 0, 32) |
144 | 132 | ); |
@@ -153,8 +141,7 @@ discard block |
||
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 . |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Salsa20 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_Salsa20 extends ParagonIE_Sodium_Core_Util |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_Salsa20 extends ParagonIE_Sodium_Core_Util { |
|
12 | 11 | const ROUNDS = 20; |
13 | 12 | |
14 | 13 | /** |
@@ -22,8 +21,7 @@ discard block |
||
22 | 21 | * @return string |
23 | 22 | * @throws TypeError |
24 | 23 | */ |
25 | - public static function core_salsa20($in, $k, $c = null) |
|
26 | - { |
|
24 | + public static function core_salsa20($in, $k, $c = null) { |
|
27 | 25 | if (self::strlen($k) < 32) { |
28 | 26 | throw new RangeException('Key must be 32 bytes long'); |
29 | 27 | } |
@@ -138,8 +136,7 @@ discard block |
||
138 | 136 | * @throws SodiumException |
139 | 137 | * @throws TypeError |
140 | 138 | */ |
141 | - public static function salsa20($len, $nonce, $key) |
|
142 | - { |
|
139 | + public static function salsa20($len, $nonce, $key) { |
|
143 | 140 | if (self::strlen($key) !== 32) { |
144 | 141 | throw new RangeException('Key must be 32 bytes long'); |
145 | 142 | } |
@@ -183,8 +180,7 @@ discard block |
||
183 | 180 | * @throws SodiumException |
184 | 181 | * @throws TypeError |
185 | 182 | */ |
186 | - public static function salsa20_xor_ic($m, $n, $ic, $k) |
|
187 | - { |
|
183 | + public static function salsa20_xor_ic($m, $n, $ic, $k) { |
|
188 | 184 | $mlen = self::strlen($m); |
189 | 185 | if ($mlen < 1) { |
190 | 186 | return ''; |
@@ -240,8 +236,7 @@ discard block |
||
240 | 236 | * @throws SodiumException |
241 | 237 | * @throws TypeError |
242 | 238 | */ |
243 | - public static function salsa20_xor($message, $nonce, $key) |
|
244 | - { |
|
239 | + public static function salsa20_xor($message, $nonce, $key) { |
|
245 | 240 | return self::xorStrings( |
246 | 241 | $message, |
247 | 242 | self::salsa20( |
@@ -259,8 +254,7 @@ discard block |
||
259 | 254 | * @param int $c |
260 | 255 | * @return int |
261 | 256 | */ |
262 | - public static function rotate($u, $c) |
|
263 | - { |
|
257 | + public static function rotate($u, $c) { |
|
264 | 258 | $u &= 0xffffffff; |
265 | 259 | $c %= 32; |
266 | 260 | return (int) (0xffffffff & ( |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * This represents a Field Element |
11 | 11 | */ |
12 | -class ParagonIE_Sodium_Core_Curve25519_Fe implements ArrayAccess |
|
13 | -{ |
|
12 | +class ParagonIE_Sodium_Core_Curve25519_Fe implements ArrayAccess { |
|
14 | 13 | /** |
15 | 14 | * @var array<int, int> |
16 | 15 | */ |
@@ -28,8 +27,7 @@ discard block |
||
28 | 27 | * @param bool $save_indexes |
29 | 28 | * @return self |
30 | 29 | */ |
31 | - public static function fromArray($array, $save_indexes = null) |
|
32 | - { |
|
30 | + public static function fromArray($array, $save_indexes = null) { |
|
33 | 31 | $count = count($array); |
34 | 32 | if ($save_indexes) { |
35 | 33 | $keys = array_keys($array); |
@@ -61,8 +59,7 @@ discard block |
||
61 | 59 | * @psalm-suppress MixedArrayOffset |
62 | 60 | */ |
63 | 61 | #[ReturnTypeWillChange] |
64 | - public function offsetSet($offset, $value) |
|
65 | - { |
|
62 | + public function offsetSet($offset, $value) { |
|
66 | 63 | if (!is_int($value)) { |
67 | 64 | throw new InvalidArgumentException('Expected an integer'); |
68 | 65 | } |
@@ -81,8 +78,7 @@ discard block |
||
81 | 78 | * @psalm-suppress MixedArrayOffset |
82 | 79 | */ |
83 | 80 | #[ReturnTypeWillChange] |
84 | - public function offsetExists($offset) |
|
85 | - { |
|
81 | + public function offsetExists($offset) { |
|
86 | 82 | return isset($this->container[$offset]); |
87 | 83 | } |
88 | 84 | |
@@ -94,8 +90,7 @@ discard block |
||
94 | 90 | * @psalm-suppress MixedArrayOffset |
95 | 91 | */ |
96 | 92 | #[ReturnTypeWillChange] |
97 | - public function offsetUnset($offset) |
|
98 | - { |
|
93 | + public function offsetUnset($offset) { |
|
99 | 94 | unset($this->container[$offset]); |
100 | 95 | } |
101 | 96 | |
@@ -107,8 +102,7 @@ discard block |
||
107 | 102 | * @psalm-suppress MixedArrayOffset |
108 | 103 | */ |
109 | 104 | #[ReturnTypeWillChange] |
110 | - public function offsetGet($offset) |
|
111 | - { |
|
105 | + public function offsetGet($offset) { |
|
112 | 106 | if (!isset($this->container[$offset])) { |
113 | 107 | $this->container[$offset] = 0; |
114 | 108 | } |
@@ -120,8 +114,7 @@ discard block |
||
120 | 114 | * |
121 | 115 | * @return array |
122 | 116 | */ |
123 | - public function __debugInfo() |
|
124 | - { |
|
117 | + public function __debugInfo() { |
|
125 | 118 | return array(implode(', ', $this->container)); |
126 | 119 | } |
127 | 120 | } |
@@ -9,8 +9,7 @@ |
||
9 | 9 | * |
10 | 10 | * This just contains the constants in the ref10/base.h file |
11 | 11 | */ |
12 | -class ParagonIE_Sodium_Core_Curve25519_H extends ParagonIE_Sodium_Core_Util |
|
13 | -{ |
|
12 | +class ParagonIE_Sodium_Core_Curve25519_H extends ParagonIE_Sodium_Core_Util { |
|
14 | 13 | /** |
15 | 14 | * See: libsodium's crypto_core/curve25519/ref10/base.h |
16 | 15 | * |
@@ -7,8 +7,7 @@ |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Curve25519_Ge_P3 |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_Curve25519_Ge_P3 |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_Curve25519_Ge_P3 { |
|
12 | 11 | /** |
13 | 12 | * @var ParagonIE_Sodium_Core_Curve25519_Fe |
14 | 13 | */ |
@@ -7,8 +7,7 @@ |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Curve25519_Ge_P2 |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_Curve25519_Ge_P2 |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_Curve25519_Ge_P2 { |
|
12 | 11 | /** |
13 | 12 | * @var ParagonIE_Sodium_Core_Curve25519_Fe |
14 | 13 | */ |
@@ -6,8 +6,7 @@ |
||
6 | 6 | /** |
7 | 7 | * Class ParagonIE_Sodium_Core_Curve25519_Ge_P1p1 |
8 | 8 | */ |
9 | -class ParagonIE_Sodium_Core_Curve25519_Ge_P1p1 |
|
10 | -{ |
|
9 | +class ParagonIE_Sodium_Core_Curve25519_Ge_P1p1 { |
|
11 | 10 | /** |
12 | 11 | * @var ParagonIE_Sodium_Core_Curve25519_Fe |
13 | 12 | */ |