@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_Salsa20', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,257 +9,257 @@ discard block |
||
9 | 9 | */ |
10 | 10 | abstract class ParagonIE_Sodium_Core_Salsa20 extends ParagonIE_Sodium_Core_Util |
11 | 11 | { |
12 | - const ROUNDS = 20; |
|
12 | + const ROUNDS = 20; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Calculate an salsa20 hash of a single block |
|
16 | - * |
|
17 | - * @internal You should not use this directly from another application |
|
18 | - * |
|
19 | - * @param string $in |
|
20 | - * @param string $k |
|
21 | - * @param string|null $c |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public static function core_salsa20($in, $k, $c = null) |
|
25 | - { |
|
26 | - if (self::strlen($k) < 32) { |
|
27 | - throw new RangeException('Key must be 32 bytes long'); |
|
28 | - } |
|
29 | - if ($c === null) { |
|
30 | - $j0 = $x0 = 0x61707865; |
|
31 | - $j5 = $x5 = 0x3320646e; |
|
32 | - $j10 = $x10 = 0x79622d32; |
|
33 | - $j15 = $x15 = 0x6b206574; |
|
34 | - } else { |
|
35 | - $j0 = $x0 = self::load_4(self::substr($c, 0, 4)); |
|
36 | - $j5 = $x5 = self::load_4(self::substr($c, 4, 4)); |
|
37 | - $j10 = $x10 = self::load_4(self::substr($c, 8, 4)); |
|
38 | - $j15 = $x15 = self::load_4(self::substr($c, 12, 4)); |
|
39 | - } |
|
40 | - $j1 = $x1 = self::load_4(self::substr($k, 0, 4)); |
|
41 | - $j2 = $x2 = self::load_4(self::substr($k, 4, 4)); |
|
42 | - $j3 = $x3 = self::load_4(self::substr($k, 8, 4)); |
|
43 | - $j4 = $x4 = self::load_4(self::substr($k, 12, 4)); |
|
44 | - $j6 = $x6 = self::load_4(self::substr($in, 0, 4)); |
|
45 | - $j7 = $x7 = self::load_4(self::substr($in, 4, 4)); |
|
46 | - $j8 = $x8 = self::load_4(self::substr($in, 8, 4)); |
|
47 | - $j9 = $x9 = self::load_4(self::substr($in, 12, 4)); |
|
48 | - $j11 = $x11 = self::load_4(self::substr($k, 16, 4)); |
|
49 | - $j12 = $x12 = self::load_4(self::substr($k, 20, 4)); |
|
50 | - $j13 = $x13 = self::load_4(self::substr($k, 24, 4)); |
|
51 | - $j14 = $x14 = self::load_4(self::substr($k, 28, 4)); |
|
14 | + /** |
|
15 | + * Calculate an salsa20 hash of a single block |
|
16 | + * |
|
17 | + * @internal You should not use this directly from another application |
|
18 | + * |
|
19 | + * @param string $in |
|
20 | + * @param string $k |
|
21 | + * @param string|null $c |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public static function core_salsa20($in, $k, $c = null) |
|
25 | + { |
|
26 | + if (self::strlen($k) < 32) { |
|
27 | + throw new RangeException('Key must be 32 bytes long'); |
|
28 | + } |
|
29 | + if ($c === null) { |
|
30 | + $j0 = $x0 = 0x61707865; |
|
31 | + $j5 = $x5 = 0x3320646e; |
|
32 | + $j10 = $x10 = 0x79622d32; |
|
33 | + $j15 = $x15 = 0x6b206574; |
|
34 | + } else { |
|
35 | + $j0 = $x0 = self::load_4(self::substr($c, 0, 4)); |
|
36 | + $j5 = $x5 = self::load_4(self::substr($c, 4, 4)); |
|
37 | + $j10 = $x10 = self::load_4(self::substr($c, 8, 4)); |
|
38 | + $j15 = $x15 = self::load_4(self::substr($c, 12, 4)); |
|
39 | + } |
|
40 | + $j1 = $x1 = self::load_4(self::substr($k, 0, 4)); |
|
41 | + $j2 = $x2 = self::load_4(self::substr($k, 4, 4)); |
|
42 | + $j3 = $x3 = self::load_4(self::substr($k, 8, 4)); |
|
43 | + $j4 = $x4 = self::load_4(self::substr($k, 12, 4)); |
|
44 | + $j6 = $x6 = self::load_4(self::substr($in, 0, 4)); |
|
45 | + $j7 = $x7 = self::load_4(self::substr($in, 4, 4)); |
|
46 | + $j8 = $x8 = self::load_4(self::substr($in, 8, 4)); |
|
47 | + $j9 = $x9 = self::load_4(self::substr($in, 12, 4)); |
|
48 | + $j11 = $x11 = self::load_4(self::substr($k, 16, 4)); |
|
49 | + $j12 = $x12 = self::load_4(self::substr($k, 20, 4)); |
|
50 | + $j13 = $x13 = self::load_4(self::substr($k, 24, 4)); |
|
51 | + $j14 = $x14 = self::load_4(self::substr($k, 28, 4)); |
|
52 | 52 | |
53 | - for ($i = self::ROUNDS; $i > 0; $i -= 2) { |
|
54 | - $x4 ^= self::rotate($x0 + $x12, 7); |
|
55 | - $x8 ^= self::rotate($x4 + $x0, 9); |
|
56 | - $x12 ^= self::rotate($x8 + $x4, 13); |
|
57 | - $x0 ^= self::rotate($x12 + $x8, 18); |
|
53 | + for ($i = self::ROUNDS; $i > 0; $i -= 2) { |
|
54 | + $x4 ^= self::rotate($x0 + $x12, 7); |
|
55 | + $x8 ^= self::rotate($x4 + $x0, 9); |
|
56 | + $x12 ^= self::rotate($x8 + $x4, 13); |
|
57 | + $x0 ^= self::rotate($x12 + $x8, 18); |
|
58 | 58 | |
59 | - $x9 ^= self::rotate($x5 + $x1, 7); |
|
60 | - $x13 ^= self::rotate($x9 + $x5, 9); |
|
61 | - $x1 ^= self::rotate($x13 + $x9, 13); |
|
62 | - $x5 ^= self::rotate($x1 + $x13, 18); |
|
59 | + $x9 ^= self::rotate($x5 + $x1, 7); |
|
60 | + $x13 ^= self::rotate($x9 + $x5, 9); |
|
61 | + $x1 ^= self::rotate($x13 + $x9, 13); |
|
62 | + $x5 ^= self::rotate($x1 + $x13, 18); |
|
63 | 63 | |
64 | - $x14 ^= self::rotate($x10 + $x6, 7); |
|
65 | - $x2 ^= self::rotate($x14 + $x10, 9); |
|
66 | - $x6 ^= self::rotate($x2 + $x14, 13); |
|
67 | - $x10 ^= self::rotate($x6 + $x2, 18); |
|
64 | + $x14 ^= self::rotate($x10 + $x6, 7); |
|
65 | + $x2 ^= self::rotate($x14 + $x10, 9); |
|
66 | + $x6 ^= self::rotate($x2 + $x14, 13); |
|
67 | + $x10 ^= self::rotate($x6 + $x2, 18); |
|
68 | 68 | |
69 | - $x3 ^= self::rotate($x15 + $x11, 7); |
|
70 | - $x7 ^= self::rotate($x3 + $x15, 9); |
|
71 | - $x11 ^= self::rotate($x7 + $x3, 13); |
|
72 | - $x15 ^= self::rotate($x11 + $x7, 18); |
|
69 | + $x3 ^= self::rotate($x15 + $x11, 7); |
|
70 | + $x7 ^= self::rotate($x3 + $x15, 9); |
|
71 | + $x11 ^= self::rotate($x7 + $x3, 13); |
|
72 | + $x15 ^= self::rotate($x11 + $x7, 18); |
|
73 | 73 | |
74 | - $x1 ^= self::rotate($x0 + $x3, 7); |
|
75 | - $x2 ^= self::rotate($x1 + $x0, 9); |
|
76 | - $x3 ^= self::rotate($x2 + $x1, 13); |
|
77 | - $x0 ^= self::rotate($x3 + $x2, 18); |
|
74 | + $x1 ^= self::rotate($x0 + $x3, 7); |
|
75 | + $x2 ^= self::rotate($x1 + $x0, 9); |
|
76 | + $x3 ^= self::rotate($x2 + $x1, 13); |
|
77 | + $x0 ^= self::rotate($x3 + $x2, 18); |
|
78 | 78 | |
79 | - $x6 ^= self::rotate($x5 + $x4, 7); |
|
80 | - $x7 ^= self::rotate($x6 + $x5, 9); |
|
81 | - $x4 ^= self::rotate($x7 + $x6, 13); |
|
82 | - $x5 ^= self::rotate($x4 + $x7, 18); |
|
79 | + $x6 ^= self::rotate($x5 + $x4, 7); |
|
80 | + $x7 ^= self::rotate($x6 + $x5, 9); |
|
81 | + $x4 ^= self::rotate($x7 + $x6, 13); |
|
82 | + $x5 ^= self::rotate($x4 + $x7, 18); |
|
83 | 83 | |
84 | - $x11 ^= self::rotate($x10 + $x9, 7); |
|
85 | - $x8 ^= self::rotate($x11 + $x10, 9); |
|
86 | - $x9 ^= self::rotate($x8 + $x11, 13); |
|
87 | - $x10 ^= self::rotate($x9 + $x8, 18); |
|
84 | + $x11 ^= self::rotate($x10 + $x9, 7); |
|
85 | + $x8 ^= self::rotate($x11 + $x10, 9); |
|
86 | + $x9 ^= self::rotate($x8 + $x11, 13); |
|
87 | + $x10 ^= self::rotate($x9 + $x8, 18); |
|
88 | 88 | |
89 | - $x12 ^= self::rotate($x15 + $x14, 7); |
|
90 | - $x13 ^= self::rotate($x12 + $x15, 9); |
|
91 | - $x14 ^= self::rotate($x13 + $x12, 13); |
|
92 | - $x15 ^= self::rotate($x14 + $x13, 18); |
|
93 | - } |
|
89 | + $x12 ^= self::rotate($x15 + $x14, 7); |
|
90 | + $x13 ^= self::rotate($x12 + $x15, 9); |
|
91 | + $x14 ^= self::rotate($x13 + $x12, 13); |
|
92 | + $x15 ^= self::rotate($x14 + $x13, 18); |
|
93 | + } |
|
94 | 94 | |
95 | - $x0 += $j0; |
|
96 | - $x1 += $j1; |
|
97 | - $x2 += $j2; |
|
98 | - $x3 += $j3; |
|
99 | - $x4 += $j4; |
|
100 | - $x5 += $j5; |
|
101 | - $x6 += $j6; |
|
102 | - $x7 += $j7; |
|
103 | - $x8 += $j8; |
|
104 | - $x9 += $j9; |
|
105 | - $x10 += $j10; |
|
106 | - $x11 += $j11; |
|
107 | - $x12 += $j12; |
|
108 | - $x13 += $j13; |
|
109 | - $x14 += $j14; |
|
110 | - $x15 += $j15; |
|
95 | + $x0 += $j0; |
|
96 | + $x1 += $j1; |
|
97 | + $x2 += $j2; |
|
98 | + $x3 += $j3; |
|
99 | + $x4 += $j4; |
|
100 | + $x5 += $j5; |
|
101 | + $x6 += $j6; |
|
102 | + $x7 += $j7; |
|
103 | + $x8 += $j8; |
|
104 | + $x9 += $j9; |
|
105 | + $x10 += $j10; |
|
106 | + $x11 += $j11; |
|
107 | + $x12 += $j12; |
|
108 | + $x13 += $j13; |
|
109 | + $x14 += $j14; |
|
110 | + $x15 += $j15; |
|
111 | 111 | |
112 | - return self::store32_le($x0) . |
|
113 | - self::store32_le($x1) . |
|
114 | - self::store32_le($x2) . |
|
115 | - self::store32_le($x3) . |
|
116 | - self::store32_le($x4) . |
|
117 | - self::store32_le($x5) . |
|
118 | - self::store32_le($x6) . |
|
119 | - self::store32_le($x7) . |
|
120 | - self::store32_le($x8) . |
|
121 | - self::store32_le($x9) . |
|
122 | - self::store32_le($x10) . |
|
123 | - self::store32_le($x11) . |
|
124 | - self::store32_le($x12) . |
|
125 | - self::store32_le($x13) . |
|
126 | - self::store32_le($x14) . |
|
127 | - self::store32_le($x15); |
|
128 | - } |
|
112 | + return self::store32_le($x0) . |
|
113 | + self::store32_le($x1) . |
|
114 | + self::store32_le($x2) . |
|
115 | + self::store32_le($x3) . |
|
116 | + self::store32_le($x4) . |
|
117 | + self::store32_le($x5) . |
|
118 | + self::store32_le($x6) . |
|
119 | + self::store32_le($x7) . |
|
120 | + self::store32_le($x8) . |
|
121 | + self::store32_le($x9) . |
|
122 | + self::store32_le($x10) . |
|
123 | + self::store32_le($x11) . |
|
124 | + self::store32_le($x12) . |
|
125 | + self::store32_le($x13) . |
|
126 | + self::store32_le($x14) . |
|
127 | + self::store32_le($x15); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @internal You should not use this directly from another application |
|
132 | - * |
|
133 | - * @param int $len |
|
134 | - * @param string $nonce |
|
135 | - * @param string $key |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public static function salsa20($len, $nonce, $key) |
|
139 | - { |
|
140 | - if (self::strlen($key) !== 32) { |
|
141 | - throw new RangeException('Key must be 32 bytes long'); |
|
142 | - } |
|
143 | - $kcopy = '' . $key; |
|
144 | - $in = self::substr($nonce, 0, 8) . str_repeat("\0", 8); |
|
145 | - $c = ''; |
|
146 | - while ($len >= 64) { |
|
147 | - $c .= self::core_salsa20($in, $kcopy, null); |
|
148 | - $u = 1; |
|
149 | - // Internal counter. |
|
150 | - for ($i = 8; $i < 16; ++$i) { |
|
151 | - $u += self::chrToInt($in[$i]); |
|
152 | - $in[$i] = self::intToChr($u & 0xff); |
|
153 | - $u >>= 8; |
|
154 | - } |
|
155 | - $len -= 64; |
|
156 | - } |
|
157 | - if ($len > 0) { |
|
158 | - $c .= self::substr( |
|
159 | - self::core_salsa20($in, $kcopy, null), |
|
160 | - 0, |
|
161 | - $len |
|
162 | - ); |
|
163 | - } |
|
164 | - try { |
|
165 | - ParagonIE_Sodium_Compat::memzero($kcopy); |
|
166 | - } catch (Error $ex) { |
|
167 | - $kcopy = null; |
|
168 | - } |
|
169 | - return $c; |
|
170 | - } |
|
130 | + /** |
|
131 | + * @internal You should not use this directly from another application |
|
132 | + * |
|
133 | + * @param int $len |
|
134 | + * @param string $nonce |
|
135 | + * @param string $key |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public static function salsa20($len, $nonce, $key) |
|
139 | + { |
|
140 | + if (self::strlen($key) !== 32) { |
|
141 | + throw new RangeException('Key must be 32 bytes long'); |
|
142 | + } |
|
143 | + $kcopy = '' . $key; |
|
144 | + $in = self::substr($nonce, 0, 8) . str_repeat("\0", 8); |
|
145 | + $c = ''; |
|
146 | + while ($len >= 64) { |
|
147 | + $c .= self::core_salsa20($in, $kcopy, null); |
|
148 | + $u = 1; |
|
149 | + // Internal counter. |
|
150 | + for ($i = 8; $i < 16; ++$i) { |
|
151 | + $u += self::chrToInt($in[$i]); |
|
152 | + $in[$i] = self::intToChr($u & 0xff); |
|
153 | + $u >>= 8; |
|
154 | + } |
|
155 | + $len -= 64; |
|
156 | + } |
|
157 | + if ($len > 0) { |
|
158 | + $c .= self::substr( |
|
159 | + self::core_salsa20($in, $kcopy, null), |
|
160 | + 0, |
|
161 | + $len |
|
162 | + ); |
|
163 | + } |
|
164 | + try { |
|
165 | + ParagonIE_Sodium_Compat::memzero($kcopy); |
|
166 | + } catch (Error $ex) { |
|
167 | + $kcopy = null; |
|
168 | + } |
|
169 | + return $c; |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * @internal You should not use this directly from another application |
|
174 | - * |
|
175 | - * @param string $m |
|
176 | - * @param string $n |
|
177 | - * @param int $ic |
|
178 | - * @param string $k |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public static function salsa20_xor_ic($m, $n, $ic, $k) |
|
182 | - { |
|
183 | - $mlen = self::strlen($m); |
|
184 | - if ($mlen < 1) { |
|
185 | - return ''; |
|
186 | - } |
|
187 | - $kcopy = self::substr($k, 0, 32); |
|
188 | - $in = self::substr($n, 0, 8); |
|
189 | - // Initialize the counter |
|
190 | - $in .= ParagonIE_Sodium_Core_Util::store64_le($ic); |
|
172 | + /** |
|
173 | + * @internal You should not use this directly from another application |
|
174 | + * |
|
175 | + * @param string $m |
|
176 | + * @param string $n |
|
177 | + * @param int $ic |
|
178 | + * @param string $k |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public static function salsa20_xor_ic($m, $n, $ic, $k) |
|
182 | + { |
|
183 | + $mlen = self::strlen($m); |
|
184 | + if ($mlen < 1) { |
|
185 | + return ''; |
|
186 | + } |
|
187 | + $kcopy = self::substr($k, 0, 32); |
|
188 | + $in = self::substr($n, 0, 8); |
|
189 | + // Initialize the counter |
|
190 | + $in .= ParagonIE_Sodium_Core_Util::store64_le($ic); |
|
191 | 191 | |
192 | - $c = ''; |
|
193 | - while ($mlen >= 64) { |
|
194 | - $block = self::core_salsa20($in, $kcopy, null); |
|
195 | - $c .= self::xorStrings( |
|
196 | - self::substr($m, 0, 64), |
|
197 | - self::substr($block, 0, 64) |
|
198 | - ); |
|
199 | - $u = 1; |
|
200 | - for ($i = 8; $i < 16; ++$i) { |
|
201 | - $u += self::chrToInt($in[$i]); |
|
202 | - $in[$i] = self::intToChr($u & 0xff); |
|
203 | - $u >>= 8; |
|
204 | - } |
|
192 | + $c = ''; |
|
193 | + while ($mlen >= 64) { |
|
194 | + $block = self::core_salsa20($in, $kcopy, null); |
|
195 | + $c .= self::xorStrings( |
|
196 | + self::substr($m, 0, 64), |
|
197 | + self::substr($block, 0, 64) |
|
198 | + ); |
|
199 | + $u = 1; |
|
200 | + for ($i = 8; $i < 16; ++$i) { |
|
201 | + $u += self::chrToInt($in[$i]); |
|
202 | + $in[$i] = self::intToChr($u & 0xff); |
|
203 | + $u >>= 8; |
|
204 | + } |
|
205 | 205 | |
206 | - $mlen -= 64; |
|
207 | - $m = self::substr($m, 64); |
|
208 | - } |
|
206 | + $mlen -= 64; |
|
207 | + $m = self::substr($m, 64); |
|
208 | + } |
|
209 | 209 | |
210 | - if ($mlen) { |
|
211 | - $block = self::core_salsa20($in, $kcopy, null); |
|
212 | - $c .= self::xorStrings( |
|
213 | - self::substr($m, 0, $mlen), |
|
214 | - self::substr($block, 0, $mlen) |
|
215 | - ); |
|
216 | - } |
|
217 | - try { |
|
218 | - ParagonIE_Sodium_Compat::memzero($block); |
|
219 | - ParagonIE_Sodium_Compat::memzero($kcopy); |
|
220 | - } catch (Error $ex) { |
|
221 | - $block = null; |
|
222 | - $kcopy = null; |
|
223 | - } |
|
210 | + if ($mlen) { |
|
211 | + $block = self::core_salsa20($in, $kcopy, null); |
|
212 | + $c .= self::xorStrings( |
|
213 | + self::substr($m, 0, $mlen), |
|
214 | + self::substr($block, 0, $mlen) |
|
215 | + ); |
|
216 | + } |
|
217 | + try { |
|
218 | + ParagonIE_Sodium_Compat::memzero($block); |
|
219 | + ParagonIE_Sodium_Compat::memzero($kcopy); |
|
220 | + } catch (Error $ex) { |
|
221 | + $block = null; |
|
222 | + $kcopy = null; |
|
223 | + } |
|
224 | 224 | |
225 | - return $c; |
|
226 | - } |
|
225 | + return $c; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * @internal You should not use this directly from another application |
|
230 | - * |
|
231 | - * @param string $message |
|
232 | - * @param string $nonce |
|
233 | - * @param string $key |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public static function salsa20_xor($message, $nonce, $key) |
|
237 | - { |
|
238 | - return self::xorStrings( |
|
239 | - $message, |
|
240 | - self::salsa20( |
|
241 | - self::strlen($message), |
|
242 | - $nonce, |
|
243 | - $key |
|
244 | - ) |
|
245 | - ); |
|
246 | - } |
|
228 | + /** |
|
229 | + * @internal You should not use this directly from another application |
|
230 | + * |
|
231 | + * @param string $message |
|
232 | + * @param string $nonce |
|
233 | + * @param string $key |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public static function salsa20_xor($message, $nonce, $key) |
|
237 | + { |
|
238 | + return self::xorStrings( |
|
239 | + $message, |
|
240 | + self::salsa20( |
|
241 | + self::strlen($message), |
|
242 | + $nonce, |
|
243 | + $key |
|
244 | + ) |
|
245 | + ); |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @internal You should not use this directly from another application |
|
250 | - * |
|
251 | - * @param int $u |
|
252 | - * @param int $c |
|
253 | - * @return int |
|
254 | - */ |
|
255 | - public static function rotate($u, $c) |
|
256 | - { |
|
257 | - $u &= 0xffffffff; |
|
258 | - $c %= 32; |
|
259 | - return 0xffffffff & ( |
|
260 | - ($u << $c) |
|
261 | - | |
|
262 | - ($u >> (32 - $c)) |
|
263 | - ); |
|
264 | - } |
|
248 | + /** |
|
249 | + * @internal You should not use this directly from another application |
|
250 | + * |
|
251 | + * @param int $u |
|
252 | + * @param int $c |
|
253 | + * @return int |
|
254 | + */ |
|
255 | + public static function rotate($u, $c) |
|
256 | + { |
|
257 | + $u &= 0xffffffff; |
|
258 | + $c %= 32; |
|
259 | + return 0xffffffff & ( |
|
260 | + ($u << $c) |
|
261 | + | |
|
262 | + ($u >> (32 - $c)) |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_Salsa20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_Salsa20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -21,75 +21,75 @@ discard block |
||
21 | 21 | * @param string|null $c |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - public static function core_salsa20($in, $k, $c = null) |
|
24 | + public static function core_salsa20( $in, $k, $c = null ) |
|
25 | 25 | { |
26 | - if (self::strlen($k) < 32) { |
|
27 | - throw new RangeException('Key must be 32 bytes long'); |
|
26 | + if ( self::strlen( $k ) < 32 ) { |
|
27 | + throw new RangeException( 'Key must be 32 bytes long' ); |
|
28 | 28 | } |
29 | - if ($c === null) { |
|
29 | + if ( $c === null ) { |
|
30 | 30 | $j0 = $x0 = 0x61707865; |
31 | 31 | $j5 = $x5 = 0x3320646e; |
32 | 32 | $j10 = $x10 = 0x79622d32; |
33 | 33 | $j15 = $x15 = 0x6b206574; |
34 | 34 | } else { |
35 | - $j0 = $x0 = self::load_4(self::substr($c, 0, 4)); |
|
36 | - $j5 = $x5 = self::load_4(self::substr($c, 4, 4)); |
|
37 | - $j10 = $x10 = self::load_4(self::substr($c, 8, 4)); |
|
38 | - $j15 = $x15 = self::load_4(self::substr($c, 12, 4)); |
|
35 | + $j0 = $x0 = self::load_4( self::substr( $c, 0, 4 ) ); |
|
36 | + $j5 = $x5 = self::load_4( self::substr( $c, 4, 4 ) ); |
|
37 | + $j10 = $x10 = self::load_4( self::substr( $c, 8, 4 ) ); |
|
38 | + $j15 = $x15 = self::load_4( self::substr( $c, 12, 4 ) ); |
|
39 | 39 | } |
40 | - $j1 = $x1 = self::load_4(self::substr($k, 0, 4)); |
|
41 | - $j2 = $x2 = self::load_4(self::substr($k, 4, 4)); |
|
42 | - $j3 = $x3 = self::load_4(self::substr($k, 8, 4)); |
|
43 | - $j4 = $x4 = self::load_4(self::substr($k, 12, 4)); |
|
44 | - $j6 = $x6 = self::load_4(self::substr($in, 0, 4)); |
|
45 | - $j7 = $x7 = self::load_4(self::substr($in, 4, 4)); |
|
46 | - $j8 = $x8 = self::load_4(self::substr($in, 8, 4)); |
|
47 | - $j9 = $x9 = self::load_4(self::substr($in, 12, 4)); |
|
48 | - $j11 = $x11 = self::load_4(self::substr($k, 16, 4)); |
|
49 | - $j12 = $x12 = self::load_4(self::substr($k, 20, 4)); |
|
50 | - $j13 = $x13 = self::load_4(self::substr($k, 24, 4)); |
|
51 | - $j14 = $x14 = self::load_4(self::substr($k, 28, 4)); |
|
40 | + $j1 = $x1 = self::load_4( self::substr( $k, 0, 4 ) ); |
|
41 | + $j2 = $x2 = self::load_4( self::substr( $k, 4, 4 ) ); |
|
42 | + $j3 = $x3 = self::load_4( self::substr( $k, 8, 4 ) ); |
|
43 | + $j4 = $x4 = self::load_4( self::substr( $k, 12, 4 ) ); |
|
44 | + $j6 = $x6 = self::load_4( self::substr( $in, 0, 4 ) ); |
|
45 | + $j7 = $x7 = self::load_4( self::substr( $in, 4, 4 ) ); |
|
46 | + $j8 = $x8 = self::load_4( self::substr( $in, 8, 4 ) ); |
|
47 | + $j9 = $x9 = self::load_4( self::substr( $in, 12, 4 ) ); |
|
48 | + $j11 = $x11 = self::load_4( self::substr( $k, 16, 4 ) ); |
|
49 | + $j12 = $x12 = self::load_4( self::substr( $k, 20, 4 ) ); |
|
50 | + $j13 = $x13 = self::load_4( self::substr( $k, 24, 4 ) ); |
|
51 | + $j14 = $x14 = self::load_4( self::substr( $k, 28, 4 ) ); |
|
52 | 52 | |
53 | - for ($i = self::ROUNDS; $i > 0; $i -= 2) { |
|
54 | - $x4 ^= self::rotate($x0 + $x12, 7); |
|
55 | - $x8 ^= self::rotate($x4 + $x0, 9); |
|
56 | - $x12 ^= self::rotate($x8 + $x4, 13); |
|
57 | - $x0 ^= self::rotate($x12 + $x8, 18); |
|
53 | + for ( $i = self::ROUNDS; $i > 0; $i -= 2 ) { |
|
54 | + $x4 ^= self::rotate( $x0 + $x12, 7 ); |
|
55 | + $x8 ^= self::rotate( $x4 + $x0, 9 ); |
|
56 | + $x12 ^= self::rotate( $x8 + $x4, 13 ); |
|
57 | + $x0 ^= self::rotate( $x12 + $x8, 18 ); |
|
58 | 58 | |
59 | - $x9 ^= self::rotate($x5 + $x1, 7); |
|
60 | - $x13 ^= self::rotate($x9 + $x5, 9); |
|
61 | - $x1 ^= self::rotate($x13 + $x9, 13); |
|
62 | - $x5 ^= self::rotate($x1 + $x13, 18); |
|
59 | + $x9 ^= self::rotate( $x5 + $x1, 7 ); |
|
60 | + $x13 ^= self::rotate( $x9 + $x5, 9 ); |
|
61 | + $x1 ^= self::rotate( $x13 + $x9, 13 ); |
|
62 | + $x5 ^= self::rotate( $x1 + $x13, 18 ); |
|
63 | 63 | |
64 | - $x14 ^= self::rotate($x10 + $x6, 7); |
|
65 | - $x2 ^= self::rotate($x14 + $x10, 9); |
|
66 | - $x6 ^= self::rotate($x2 + $x14, 13); |
|
67 | - $x10 ^= self::rotate($x6 + $x2, 18); |
|
64 | + $x14 ^= self::rotate( $x10 + $x6, 7 ); |
|
65 | + $x2 ^= self::rotate( $x14 + $x10, 9 ); |
|
66 | + $x6 ^= self::rotate( $x2 + $x14, 13 ); |
|
67 | + $x10 ^= self::rotate( $x6 + $x2, 18 ); |
|
68 | 68 | |
69 | - $x3 ^= self::rotate($x15 + $x11, 7); |
|
70 | - $x7 ^= self::rotate($x3 + $x15, 9); |
|
71 | - $x11 ^= self::rotate($x7 + $x3, 13); |
|
72 | - $x15 ^= self::rotate($x11 + $x7, 18); |
|
69 | + $x3 ^= self::rotate( $x15 + $x11, 7 ); |
|
70 | + $x7 ^= self::rotate( $x3 + $x15, 9 ); |
|
71 | + $x11 ^= self::rotate( $x7 + $x3, 13 ); |
|
72 | + $x15 ^= self::rotate( $x11 + $x7, 18 ); |
|
73 | 73 | |
74 | - $x1 ^= self::rotate($x0 + $x3, 7); |
|
75 | - $x2 ^= self::rotate($x1 + $x0, 9); |
|
76 | - $x3 ^= self::rotate($x2 + $x1, 13); |
|
77 | - $x0 ^= self::rotate($x3 + $x2, 18); |
|
74 | + $x1 ^= self::rotate( $x0 + $x3, 7 ); |
|
75 | + $x2 ^= self::rotate( $x1 + $x0, 9 ); |
|
76 | + $x3 ^= self::rotate( $x2 + $x1, 13 ); |
|
77 | + $x0 ^= self::rotate( $x3 + $x2, 18 ); |
|
78 | 78 | |
79 | - $x6 ^= self::rotate($x5 + $x4, 7); |
|
80 | - $x7 ^= self::rotate($x6 + $x5, 9); |
|
81 | - $x4 ^= self::rotate($x7 + $x6, 13); |
|
82 | - $x5 ^= self::rotate($x4 + $x7, 18); |
|
79 | + $x6 ^= self::rotate( $x5 + $x4, 7 ); |
|
80 | + $x7 ^= self::rotate( $x6 + $x5, 9 ); |
|
81 | + $x4 ^= self::rotate( $x7 + $x6, 13 ); |
|
82 | + $x5 ^= self::rotate( $x4 + $x7, 18 ); |
|
83 | 83 | |
84 | - $x11 ^= self::rotate($x10 + $x9, 7); |
|
85 | - $x8 ^= self::rotate($x11 + $x10, 9); |
|
86 | - $x9 ^= self::rotate($x8 + $x11, 13); |
|
87 | - $x10 ^= self::rotate($x9 + $x8, 18); |
|
84 | + $x11 ^= self::rotate( $x10 + $x9, 7 ); |
|
85 | + $x8 ^= self::rotate( $x11 + $x10, 9 ); |
|
86 | + $x9 ^= self::rotate( $x8 + $x11, 13 ); |
|
87 | + $x10 ^= self::rotate( $x9 + $x8, 18 ); |
|
88 | 88 | |
89 | - $x12 ^= self::rotate($x15 + $x14, 7); |
|
90 | - $x13 ^= self::rotate($x12 + $x15, 9); |
|
91 | - $x14 ^= self::rotate($x13 + $x12, 13); |
|
92 | - $x15 ^= self::rotate($x14 + $x13, 18); |
|
89 | + $x12 ^= self::rotate( $x15 + $x14, 7 ); |
|
90 | + $x13 ^= self::rotate( $x12 + $x15, 9 ); |
|
91 | + $x14 ^= self::rotate( $x13 + $x12, 13 ); |
|
92 | + $x15 ^= self::rotate( $x14 + $x13, 18 ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $x0 += $j0; |
@@ -109,22 +109,22 @@ discard block |
||
109 | 109 | $x14 += $j14; |
110 | 110 | $x15 += $j15; |
111 | 111 | |
112 | - return self::store32_le($x0) . |
|
113 | - self::store32_le($x1) . |
|
114 | - self::store32_le($x2) . |
|
115 | - self::store32_le($x3) . |
|
116 | - self::store32_le($x4) . |
|
117 | - self::store32_le($x5) . |
|
118 | - self::store32_le($x6) . |
|
119 | - self::store32_le($x7) . |
|
120 | - self::store32_le($x8) . |
|
121 | - self::store32_le($x9) . |
|
122 | - self::store32_le($x10) . |
|
123 | - self::store32_le($x11) . |
|
124 | - self::store32_le($x12) . |
|
125 | - self::store32_le($x13) . |
|
126 | - self::store32_le($x14) . |
|
127 | - self::store32_le($x15); |
|
112 | + return self::store32_le( $x0 ) . |
|
113 | + self::store32_le( $x1 ) . |
|
114 | + self::store32_le( $x2 ) . |
|
115 | + self::store32_le( $x3 ) . |
|
116 | + self::store32_le( $x4 ) . |
|
117 | + self::store32_le( $x5 ) . |
|
118 | + self::store32_le( $x6 ) . |
|
119 | + self::store32_le( $x7 ) . |
|
120 | + self::store32_le( $x8 ) . |
|
121 | + self::store32_le( $x9 ) . |
|
122 | + self::store32_le( $x10 ) . |
|
123 | + self::store32_le( $x11 ) . |
|
124 | + self::store32_le( $x12 ) . |
|
125 | + self::store32_le( $x13 ) . |
|
126 | + self::store32_le( $x14 ) . |
|
127 | + self::store32_le( $x15 ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -135,35 +135,35 @@ discard block |
||
135 | 135 | * @param string $key |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public static function salsa20($len, $nonce, $key) |
|
138 | + public static function salsa20( $len, $nonce, $key ) |
|
139 | 139 | { |
140 | - if (self::strlen($key) !== 32) { |
|
141 | - throw new RangeException('Key must be 32 bytes long'); |
|
140 | + if ( self::strlen( $key ) !== 32 ) { |
|
141 | + throw new RangeException( 'Key must be 32 bytes long' ); |
|
142 | 142 | } |
143 | 143 | $kcopy = '' . $key; |
144 | - $in = self::substr($nonce, 0, 8) . str_repeat("\0", 8); |
|
144 | + $in = self::substr( $nonce, 0, 8 ) . str_repeat( "\0", 8 ); |
|
145 | 145 | $c = ''; |
146 | - while ($len >= 64) { |
|
147 | - $c .= self::core_salsa20($in, $kcopy, null); |
|
146 | + while ( $len >= 64 ) { |
|
147 | + $c .= self::core_salsa20( $in, $kcopy, null ); |
|
148 | 148 | $u = 1; |
149 | 149 | // Internal counter. |
150 | - for ($i = 8; $i < 16; ++$i) { |
|
151 | - $u += self::chrToInt($in[$i]); |
|
152 | - $in[$i] = self::intToChr($u & 0xff); |
|
150 | + for ( $i = 8; $i < 16; ++$i ) { |
|
151 | + $u += self::chrToInt( $in[$i] ); |
|
152 | + $in[$i] = self::intToChr( $u & 0xff ); |
|
153 | 153 | $u >>= 8; |
154 | 154 | } |
155 | 155 | $len -= 64; |
156 | 156 | } |
157 | - if ($len > 0) { |
|
157 | + if ( $len > 0 ) { |
|
158 | 158 | $c .= self::substr( |
159 | - self::core_salsa20($in, $kcopy, null), |
|
159 | + self::core_salsa20( $in, $kcopy, null ), |
|
160 | 160 | 0, |
161 | 161 | $len |
162 | 162 | ); |
163 | 163 | } |
164 | 164 | try { |
165 | - ParagonIE_Sodium_Compat::memzero($kcopy); |
|
166 | - } catch (Error $ex) { |
|
165 | + ParagonIE_Sodium_Compat::memzero( $kcopy ); |
|
166 | + } catch ( Error $ex ) { |
|
167 | 167 | $kcopy = null; |
168 | 168 | } |
169 | 169 | return $c; |
@@ -178,46 +178,46 @@ discard block |
||
178 | 178 | * @param string $k |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public static function salsa20_xor_ic($m, $n, $ic, $k) |
|
181 | + public static function salsa20_xor_ic( $m, $n, $ic, $k ) |
|
182 | 182 | { |
183 | - $mlen = self::strlen($m); |
|
184 | - if ($mlen < 1) { |
|
183 | + $mlen = self::strlen( $m ); |
|
184 | + if ( $mlen < 1 ) { |
|
185 | 185 | return ''; |
186 | 186 | } |
187 | - $kcopy = self::substr($k, 0, 32); |
|
188 | - $in = self::substr($n, 0, 8); |
|
187 | + $kcopy = self::substr( $k, 0, 32 ); |
|
188 | + $in = self::substr( $n, 0, 8 ); |
|
189 | 189 | // Initialize the counter |
190 | - $in .= ParagonIE_Sodium_Core_Util::store64_le($ic); |
|
190 | + $in .= ParagonIE_Sodium_Core_Util::store64_le( $ic ); |
|
191 | 191 | |
192 | 192 | $c = ''; |
193 | - while ($mlen >= 64) { |
|
194 | - $block = self::core_salsa20($in, $kcopy, null); |
|
193 | + while ( $mlen >= 64 ) { |
|
194 | + $block = self::core_salsa20( $in, $kcopy, null ); |
|
195 | 195 | $c .= self::xorStrings( |
196 | - self::substr($m, 0, 64), |
|
197 | - self::substr($block, 0, 64) |
|
196 | + self::substr( $m, 0, 64 ), |
|
197 | + self::substr( $block, 0, 64 ) |
|
198 | 198 | ); |
199 | 199 | $u = 1; |
200 | - for ($i = 8; $i < 16; ++$i) { |
|
201 | - $u += self::chrToInt($in[$i]); |
|
202 | - $in[$i] = self::intToChr($u & 0xff); |
|
200 | + for ( $i = 8; $i < 16; ++$i ) { |
|
201 | + $u += self::chrToInt( $in[$i] ); |
|
202 | + $in[$i] = self::intToChr( $u & 0xff ); |
|
203 | 203 | $u >>= 8; |
204 | 204 | } |
205 | 205 | |
206 | 206 | $mlen -= 64; |
207 | - $m = self::substr($m, 64); |
|
207 | + $m = self::substr( $m, 64 ); |
|
208 | 208 | } |
209 | 209 | |
210 | - if ($mlen) { |
|
211 | - $block = self::core_salsa20($in, $kcopy, null); |
|
210 | + if ( $mlen ) { |
|
211 | + $block = self::core_salsa20( $in, $kcopy, null ); |
|
212 | 212 | $c .= self::xorStrings( |
213 | - self::substr($m, 0, $mlen), |
|
214 | - self::substr($block, 0, $mlen) |
|
213 | + self::substr( $m, 0, $mlen ), |
|
214 | + self::substr( $block, 0, $mlen ) |
|
215 | 215 | ); |
216 | 216 | } |
217 | 217 | try { |
218 | - ParagonIE_Sodium_Compat::memzero($block); |
|
219 | - ParagonIE_Sodium_Compat::memzero($kcopy); |
|
220 | - } catch (Error $ex) { |
|
218 | + ParagonIE_Sodium_Compat::memzero( $block ); |
|
219 | + ParagonIE_Sodium_Compat::memzero( $kcopy ); |
|
220 | + } catch ( Error $ex ) { |
|
221 | 221 | $block = null; |
222 | 222 | $kcopy = null; |
223 | 223 | } |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | * @param string $key |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - public static function salsa20_xor($message, $nonce, $key) |
|
236 | + public static function salsa20_xor( $message, $nonce, $key ) |
|
237 | 237 | { |
238 | 238 | return self::xorStrings( |
239 | 239 | $message, |
240 | 240 | self::salsa20( |
241 | - self::strlen($message), |
|
241 | + self::strlen( $message ), |
|
242 | 242 | $nonce, |
243 | 243 | $key |
244 | 244 | ) |
@@ -252,14 +252,14 @@ discard block |
||
252 | 252 | * @param int $c |
253 | 253 | * @return int |
254 | 254 | */ |
255 | - public static function rotate($u, $c) |
|
255 | + public static function rotate( $u, $c ) |
|
256 | 256 | { |
257 | 257 | $u &= 0xffffffff; |
258 | 258 | $c %= 32; |
259 | 259 | return 0xffffffff & ( |
260 | - ($u << $c) |
|
260 | + ( $u << $c ) |
|
261 | 261 | | |
262 | - ($u >> (32 - $c)) |
|
262 | + ( $u >> ( 32 - $c ) ) |
|
263 | 263 | ); |
264 | 264 | } |
265 | 265 | } |
@@ -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 | /** |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * @param string|null $c |
22 | 21 | * @return string |
23 | 22 | */ |
24 | - public static function core_salsa20($in, $k, $c = null) |
|
25 | - { |
|
23 | + public static function core_salsa20($in, $k, $c = null) { |
|
26 | 24 | if (self::strlen($k) < 32) { |
27 | 25 | throw new RangeException('Key must be 32 bytes long'); |
28 | 26 | } |
@@ -135,8 +133,7 @@ discard block |
||
135 | 133 | * @param string $key |
136 | 134 | * @return string |
137 | 135 | */ |
138 | - public static function salsa20($len, $nonce, $key) |
|
139 | - { |
|
136 | + public static function salsa20($len, $nonce, $key) { |
|
140 | 137 | if (self::strlen($key) !== 32) { |
141 | 138 | throw new RangeException('Key must be 32 bytes long'); |
142 | 139 | } |
@@ -178,8 +175,7 @@ discard block |
||
178 | 175 | * @param string $k |
179 | 176 | * @return string |
180 | 177 | */ |
181 | - public static function salsa20_xor_ic($m, $n, $ic, $k) |
|
182 | - { |
|
178 | + public static function salsa20_xor_ic($m, $n, $ic, $k) { |
|
183 | 179 | $mlen = self::strlen($m); |
184 | 180 | if ($mlen < 1) { |
185 | 181 | return ''; |
@@ -233,8 +229,7 @@ discard block |
||
233 | 229 | * @param string $key |
234 | 230 | * @return string |
235 | 231 | */ |
236 | - public static function salsa20_xor($message, $nonce, $key) |
|
237 | - { |
|
232 | + public static function salsa20_xor($message, $nonce, $key) { |
|
238 | 233 | return self::xorStrings( |
239 | 234 | $message, |
240 | 235 | self::salsa20( |
@@ -252,8 +247,7 @@ discard block |
||
252 | 247 | * @param int $c |
253 | 248 | * @return int |
254 | 249 | */ |
255 | - public static function rotate($u, $c) |
|
256 | - { |
|
250 | + public static function rotate($u, $c) { |
|
257 | 251 | $u &= 0xffffffff; |
258 | 252 | $c %= 32; |
259 | 253 | return 0xffffffff & ( |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_XSalsa20', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,45 +9,45 @@ discard block |
||
9 | 9 | */ |
10 | 10 | abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_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 | - */ |
|
22 | - public static function xsalsa20($len, $nonce, $key) |
|
23 | - { |
|
24 | - $ret = self::salsa20( |
|
25 | - $len, |
|
26 | - self::substr($nonce, 16, 8), |
|
27 | - self::hsalsa20($nonce, $key) |
|
28 | - ); |
|
29 | - return $ret; |
|
30 | - } |
|
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 | + */ |
|
22 | + public static function xsalsa20($len, $nonce, $key) |
|
23 | + { |
|
24 | + $ret = self::salsa20( |
|
25 | + $len, |
|
26 | + self::substr($nonce, 16, 8), |
|
27 | + self::hsalsa20($nonce, $key) |
|
28 | + ); |
|
29 | + return $ret; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Encrypt a string with XSalsa20. Doesn't provide integrity. |
|
34 | - * |
|
35 | - * @internal You should not use this directly from another application |
|
36 | - * |
|
37 | - * @param string $message |
|
38 | - * @param string $nonce |
|
39 | - * @param string $key |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public static function xsalsa20_xor($message, $nonce, $key) |
|
43 | - { |
|
44 | - return self::xorStrings( |
|
45 | - $message, |
|
46 | - self::xsalsa20( |
|
47 | - self::strlen($message), |
|
48 | - $nonce, |
|
49 | - $key |
|
50 | - ) |
|
51 | - ); |
|
52 | - } |
|
32 | + /** |
|
33 | + * Encrypt a string with XSalsa20. Doesn't provide integrity. |
|
34 | + * |
|
35 | + * @internal You should not use this directly from another application |
|
36 | + * |
|
37 | + * @param string $message |
|
38 | + * @param string $nonce |
|
39 | + * @param string $key |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public static function xsalsa20_xor($message, $nonce, $key) |
|
43 | + { |
|
44 | + return self::xorStrings( |
|
45 | + $message, |
|
46 | + self::xsalsa20( |
|
47 | + self::strlen($message), |
|
48 | + $nonce, |
|
49 | + $key |
|
50 | + ) |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_XSalsa20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_XSalsa20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * @param string $key |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public static function xsalsa20($len, $nonce, $key) |
|
22 | + public static function xsalsa20( $len, $nonce, $key ) |
|
23 | 23 | { |
24 | 24 | $ret = self::salsa20( |
25 | 25 | $len, |
26 | - self::substr($nonce, 16, 8), |
|
27 | - self::hsalsa20($nonce, $key) |
|
26 | + self::substr( $nonce, 16, 8 ), |
|
27 | + self::hsalsa20( $nonce, $key ) |
|
28 | 28 | ); |
29 | 29 | return $ret; |
30 | 30 | } |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | * @param string $key |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - public static function xsalsa20_xor($message, $nonce, $key) |
|
42 | + public static function xsalsa20_xor( $message, $nonce, $key ) |
|
43 | 43 | { |
44 | 44 | return self::xorStrings( |
45 | 45 | $message, |
46 | 46 | self::xsalsa20( |
47 | - self::strlen($message), |
|
47 | + self::strlen( $message ), |
|
48 | 48 | $nonce, |
49 | 49 | $key |
50 | 50 | ) |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_XSalsa20 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_HSalsa20 |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_HSalsa20 { |
|
12 | 11 | /** |
13 | 12 | * Expand a key and nonce into an xsalsa20 keystream. |
14 | 13 | * |
@@ -19,8 +18,7 @@ discard block |
||
19 | 18 | * @param string $key |
20 | 19 | * @return string |
21 | 20 | */ |
22 | - public static function xsalsa20($len, $nonce, $key) |
|
23 | - { |
|
21 | + public static function xsalsa20($len, $nonce, $key) { |
|
24 | 22 | $ret = self::salsa20( |
25 | 23 | $len, |
26 | 24 | self::substr($nonce, 16, 8), |
@@ -39,8 +37,7 @@ discard block |
||
39 | 37 | * @param string $key |
40 | 38 | * @return string |
41 | 39 | */ |
42 | - public static function xsalsa20_xor($message, $nonce, $key) |
|
43 | - { |
|
40 | + public static function xsalsa20_xor($message, $nonce, $key) { |
|
44 | 41 | return self::xorStrings( |
45 | 42 | $message, |
46 | 43 | self::xsalsa20( |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_ChaCha20', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,73 +9,73 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class ParagonIE_Sodium_Core_ChaCha20 extends ParagonIE_Sodium_Core_Util |
11 | 11 | { |
12 | - /** |
|
13 | - * Bitwise left rotation |
|
14 | - * |
|
15 | - * @internal You should not use this directly from another application |
|
16 | - * |
|
17 | - * @param int $v |
|
18 | - * @param int $n |
|
19 | - * @return int |
|
20 | - */ |
|
21 | - public static function rotate($v, $n) |
|
22 | - { |
|
23 | - $v &= 0xffffffff; |
|
24 | - $n &= 31; |
|
25 | - return 0xffffffff & ( |
|
26 | - ($v << $n) |
|
27 | - | |
|
28 | - ($v >> (32 - $n)) |
|
29 | - ); |
|
30 | - } |
|
12 | + /** |
|
13 | + * Bitwise left rotation |
|
14 | + * |
|
15 | + * @internal You should not use this directly from another application |
|
16 | + * |
|
17 | + * @param int $v |
|
18 | + * @param int $n |
|
19 | + * @return int |
|
20 | + */ |
|
21 | + public static function rotate($v, $n) |
|
22 | + { |
|
23 | + $v &= 0xffffffff; |
|
24 | + $n &= 31; |
|
25 | + return 0xffffffff & ( |
|
26 | + ($v << $n) |
|
27 | + | |
|
28 | + ($v >> (32 - $n)) |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * The ChaCha20 quarter round function. Works on four 32-bit integers. |
|
34 | - * |
|
35 | - * @internal You should not use this directly from another application |
|
36 | - * |
|
37 | - * @param int $a |
|
38 | - * @param int $b |
|
39 | - * @param int $c |
|
40 | - * @param int $d |
|
41 | - * @return array<int, int> |
|
42 | - */ |
|
43 | - protected static function quarterRound($a, $b, $c, $d) |
|
44 | - { |
|
45 | - # a = PLUS(a,b); d = ROTATE(XOR(d,a),16); |
|
46 | - $a = ($a + $b) & 0xffffffff; |
|
47 | - $d = self::rotate($d ^ $a, 16); |
|
32 | + /** |
|
33 | + * The ChaCha20 quarter round function. Works on four 32-bit integers. |
|
34 | + * |
|
35 | + * @internal You should not use this directly from another application |
|
36 | + * |
|
37 | + * @param int $a |
|
38 | + * @param int $b |
|
39 | + * @param int $c |
|
40 | + * @param int $d |
|
41 | + * @return array<int, int> |
|
42 | + */ |
|
43 | + protected static function quarterRound($a, $b, $c, $d) |
|
44 | + { |
|
45 | + # a = PLUS(a,b); d = ROTATE(XOR(d,a),16); |
|
46 | + $a = ($a + $b) & 0xffffffff; |
|
47 | + $d = self::rotate($d ^ $a, 16); |
|
48 | 48 | |
49 | - # c = PLUS(c,d); b = ROTATE(XOR(b,c),12); |
|
50 | - $c = ($c + $d) & 0xffffffff; |
|
51 | - $b = self::rotate($b ^ $c, 12); |
|
49 | + # c = PLUS(c,d); b = ROTATE(XOR(b,c),12); |
|
50 | + $c = ($c + $d) & 0xffffffff; |
|
51 | + $b = self::rotate($b ^ $c, 12); |
|
52 | 52 | |
53 | - # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); |
|
54 | - $a = ($a + $b) & 0xffffffff; |
|
55 | - $d = self::rotate($d ^ $a, 8); |
|
53 | + # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); |
|
54 | + $a = ($a + $b) & 0xffffffff; |
|
55 | + $d = self::rotate($d ^ $a, 8); |
|
56 | 56 | |
57 | - # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); |
|
58 | - $c = ($c + $d) & 0xffffffff; |
|
59 | - $b = self::rotate($b ^ $c, 7); |
|
60 | - return array((int) $a, (int) $b, (int) $c, (int) $d); |
|
61 | - } |
|
57 | + # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); |
|
58 | + $c = ($c + $d) & 0xffffffff; |
|
59 | + $b = self::rotate($b ^ $c, 7); |
|
60 | + return array((int) $a, (int) $b, (int) $c, (int) $d); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @internal You should not use this directly from another application |
|
65 | - * |
|
66 | - * @param ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx |
|
67 | - * @param string $message |
|
68 | - * |
|
69 | - * @return string |
|
70 | - * @throws Exception |
|
71 | - */ |
|
72 | - public static function encryptBytes( |
|
73 | - ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx, |
|
74 | - $message = '' |
|
75 | - ) { |
|
76 | - $bytes = self::strlen($message); |
|
63 | + /** |
|
64 | + * @internal You should not use this directly from another application |
|
65 | + * |
|
66 | + * @param ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx |
|
67 | + * @param string $message |
|
68 | + * |
|
69 | + * @return string |
|
70 | + * @throws Exception |
|
71 | + */ |
|
72 | + public static function encryptBytes( |
|
73 | + ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx, |
|
74 | + $message = '' |
|
75 | + ) { |
|
76 | + $bytes = self::strlen($message); |
|
77 | 77 | |
78 | - /* |
|
78 | + /* |
|
79 | 79 | j0 = ctx->input[0]; |
80 | 80 | j1 = ctx->input[1]; |
81 | 81 | j2 = ctx->input[2]; |
@@ -93,73 +93,73 @@ discard block |
||
93 | 93 | j14 = ctx->input[14]; |
94 | 94 | j15 = ctx->input[15]; |
95 | 95 | */ |
96 | - $j0 = (int) $ctx[0]; |
|
97 | - $j1 = (int) $ctx[1]; |
|
98 | - $j2 = (int) $ctx[2]; |
|
99 | - $j3 = (int) $ctx[3]; |
|
100 | - $j4 = (int) $ctx[4]; |
|
101 | - $j5 = (int) $ctx[5]; |
|
102 | - $j6 = (int) $ctx[6]; |
|
103 | - $j7 = (int) $ctx[7]; |
|
104 | - $j8 = (int) $ctx[8]; |
|
105 | - $j9 = (int) $ctx[9]; |
|
106 | - $j10 = (int) $ctx[10]; |
|
107 | - $j11 = (int) $ctx[11]; |
|
108 | - $j12 = (int) $ctx[12]; |
|
109 | - $j13 = (int) $ctx[13]; |
|
110 | - $j14 = (int) $ctx[14]; |
|
111 | - $j15 = (int) $ctx[15]; |
|
96 | + $j0 = (int) $ctx[0]; |
|
97 | + $j1 = (int) $ctx[1]; |
|
98 | + $j2 = (int) $ctx[2]; |
|
99 | + $j3 = (int) $ctx[3]; |
|
100 | + $j4 = (int) $ctx[4]; |
|
101 | + $j5 = (int) $ctx[5]; |
|
102 | + $j6 = (int) $ctx[6]; |
|
103 | + $j7 = (int) $ctx[7]; |
|
104 | + $j8 = (int) $ctx[8]; |
|
105 | + $j9 = (int) $ctx[9]; |
|
106 | + $j10 = (int) $ctx[10]; |
|
107 | + $j11 = (int) $ctx[11]; |
|
108 | + $j12 = (int) $ctx[12]; |
|
109 | + $j13 = (int) $ctx[13]; |
|
110 | + $j14 = (int) $ctx[14]; |
|
111 | + $j15 = (int) $ctx[15]; |
|
112 | 112 | |
113 | - $c = ''; |
|
114 | - for (;;) { |
|
115 | - if ($bytes < 64) { |
|
116 | - $message .= str_repeat("\x00", 64 - $bytes); |
|
117 | - } |
|
113 | + $c = ''; |
|
114 | + for (;;) { |
|
115 | + if ($bytes < 64) { |
|
116 | + $message .= str_repeat("\x00", 64 - $bytes); |
|
117 | + } |
|
118 | 118 | |
119 | - $x0 = (int) $j0; |
|
120 | - $x1 = (int) $j1; |
|
121 | - $x2 = (int) $j2; |
|
122 | - $x3 = (int) $j3; |
|
123 | - $x4 = (int) $j4; |
|
124 | - $x5 = (int) $j5; |
|
125 | - $x6 = (int) $j6; |
|
126 | - $x7 = (int) $j7; |
|
127 | - $x8 = (int) $j8; |
|
128 | - $x9 = (int) $j9; |
|
129 | - $x10 = (int) $j10; |
|
130 | - $x11 = (int) $j11; |
|
131 | - $x12 = (int) $j12; |
|
132 | - $x13 = (int) $j13; |
|
133 | - $x14 = (int) $j14; |
|
134 | - $x15 = (int) $j15; |
|
119 | + $x0 = (int) $j0; |
|
120 | + $x1 = (int) $j1; |
|
121 | + $x2 = (int) $j2; |
|
122 | + $x3 = (int) $j3; |
|
123 | + $x4 = (int) $j4; |
|
124 | + $x5 = (int) $j5; |
|
125 | + $x6 = (int) $j6; |
|
126 | + $x7 = (int) $j7; |
|
127 | + $x8 = (int) $j8; |
|
128 | + $x9 = (int) $j9; |
|
129 | + $x10 = (int) $j10; |
|
130 | + $x11 = (int) $j11; |
|
131 | + $x12 = (int) $j12; |
|
132 | + $x13 = (int) $j13; |
|
133 | + $x14 = (int) $j14; |
|
134 | + $x15 = (int) $j15; |
|
135 | 135 | |
136 | - # for (i = 20; i > 0; i -= 2) { |
|
137 | - for ($i = 20; $i > 0; $i -= 2) { |
|
138 | - # QUARTERROUND( x0, x4, x8, x12) |
|
139 | - list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
136 | + # for (i = 20; i > 0; i -= 2) { |
|
137 | + for ($i = 20; $i > 0; $i -= 2) { |
|
138 | + # QUARTERROUND( x0, x4, x8, x12) |
|
139 | + list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
140 | 140 | |
141 | - # QUARTERROUND( x1, x5, x9, x13) |
|
142 | - list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
141 | + # QUARTERROUND( x1, x5, x9, x13) |
|
142 | + list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
143 | 143 | |
144 | - # QUARTERROUND( x2, x6, x10, x14) |
|
145 | - list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
144 | + # QUARTERROUND( x2, x6, x10, x14) |
|
145 | + list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
146 | 146 | |
147 | - # QUARTERROUND( x3, x7, x11, x15) |
|
148 | - list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
147 | + # QUARTERROUND( x3, x7, x11, x15) |
|
148 | + list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
149 | 149 | |
150 | - # QUARTERROUND( x0, x5, x10, x15) |
|
151 | - list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
150 | + # QUARTERROUND( x0, x5, x10, x15) |
|
151 | + list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
152 | 152 | |
153 | - # QUARTERROUND( x1, x6, x11, x12) |
|
154 | - list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
153 | + # QUARTERROUND( x1, x6, x11, x12) |
|
154 | + list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
155 | 155 | |
156 | - # QUARTERROUND( x2, x7, x8, x13) |
|
157 | - list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
156 | + # QUARTERROUND( x2, x7, x8, x13) |
|
157 | + list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
158 | 158 | |
159 | - # QUARTERROUND( x3, x4, x9, x14) |
|
160 | - list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
161 | - } |
|
162 | - /* |
|
159 | + # QUARTERROUND( x3, x4, x9, x14) |
|
160 | + list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
161 | + } |
|
162 | + /* |
|
163 | 163 | x0 = PLUS(x0, j0); |
164 | 164 | x1 = PLUS(x1, j1); |
165 | 165 | x2 = PLUS(x2, j2); |
@@ -177,24 +177,24 @@ discard block |
||
177 | 177 | x14 = PLUS(x14, j14); |
178 | 178 | x15 = PLUS(x15, j15); |
179 | 179 | */ |
180 | - $x0 = ($x0 & 0xffffffff) + $j0; |
|
181 | - $x1 = ($x1 & 0xffffffff) + $j1; |
|
182 | - $x2 = ($x2 & 0xffffffff) + $j2; |
|
183 | - $x3 = ($x3 & 0xffffffff) + $j3; |
|
184 | - $x4 = ($x4 & 0xffffffff) + $j4; |
|
185 | - $x5 = ($x5 & 0xffffffff) + $j5; |
|
186 | - $x6 = ($x6 & 0xffffffff) + $j6; |
|
187 | - $x7 = ($x7 & 0xffffffff) + $j7; |
|
188 | - $x8 = ($x8 & 0xffffffff) + $j8; |
|
189 | - $x9 = ($x9 & 0xffffffff) + $j9; |
|
190 | - $x10 = ($x10 & 0xffffffff) + $j10; |
|
191 | - $x11 = ($x11 & 0xffffffff) + $j11; |
|
192 | - $x12 = ($x12 & 0xffffffff) + $j12; |
|
193 | - $x13 = ($x13 & 0xffffffff) + $j13; |
|
194 | - $x14 = ($x14 & 0xffffffff) + $j14; |
|
195 | - $x15 = ($x15 & 0xffffffff) + $j15; |
|
180 | + $x0 = ($x0 & 0xffffffff) + $j0; |
|
181 | + $x1 = ($x1 & 0xffffffff) + $j1; |
|
182 | + $x2 = ($x2 & 0xffffffff) + $j2; |
|
183 | + $x3 = ($x3 & 0xffffffff) + $j3; |
|
184 | + $x4 = ($x4 & 0xffffffff) + $j4; |
|
185 | + $x5 = ($x5 & 0xffffffff) + $j5; |
|
186 | + $x6 = ($x6 & 0xffffffff) + $j6; |
|
187 | + $x7 = ($x7 & 0xffffffff) + $j7; |
|
188 | + $x8 = ($x8 & 0xffffffff) + $j8; |
|
189 | + $x9 = ($x9 & 0xffffffff) + $j9; |
|
190 | + $x10 = ($x10 & 0xffffffff) + $j10; |
|
191 | + $x11 = ($x11 & 0xffffffff) + $j11; |
|
192 | + $x12 = ($x12 & 0xffffffff) + $j12; |
|
193 | + $x13 = ($x13 & 0xffffffff) + $j13; |
|
194 | + $x14 = ($x14 & 0xffffffff) + $j14; |
|
195 | + $x15 = ($x15 & 0xffffffff) + $j15; |
|
196 | 196 | |
197 | - /* |
|
197 | + /* |
|
198 | 198 | x0 = XOR(x0, LOAD32_LE(m + 0)); |
199 | 199 | x1 = XOR(x1, LOAD32_LE(m + 4)); |
200 | 200 | x2 = XOR(x2, LOAD32_LE(m + 8)); |
@@ -212,35 +212,35 @@ discard block |
||
212 | 212 | x14 = XOR(x14, LOAD32_LE(m + 56)); |
213 | 213 | x15 = XOR(x15, LOAD32_LE(m + 60)); |
214 | 214 | */ |
215 | - $x0 ^= self::load_4(self::substr($message, 0, 4)); |
|
216 | - $x1 ^= self::load_4(self::substr($message, 4, 4)); |
|
217 | - $x2 ^= self::load_4(self::substr($message, 8, 4)); |
|
218 | - $x3 ^= self::load_4(self::substr($message, 12, 4)); |
|
219 | - $x4 ^= self::load_4(self::substr($message, 16, 4)); |
|
220 | - $x5 ^= self::load_4(self::substr($message, 20, 4)); |
|
221 | - $x6 ^= self::load_4(self::substr($message, 24, 4)); |
|
222 | - $x7 ^= self::load_4(self::substr($message, 28, 4)); |
|
223 | - $x8 ^= self::load_4(self::substr($message, 32, 4)); |
|
224 | - $x9 ^= self::load_4(self::substr($message, 36, 4)); |
|
225 | - $x10 ^= self::load_4(self::substr($message, 40, 4)); |
|
226 | - $x11 ^= self::load_4(self::substr($message, 44, 4)); |
|
227 | - $x12 ^= self::load_4(self::substr($message, 48, 4)); |
|
228 | - $x13 ^= self::load_4(self::substr($message, 52, 4)); |
|
229 | - $x14 ^= self::load_4(self::substr($message, 56, 4)); |
|
230 | - $x15 ^= self::load_4(self::substr($message, 60, 4)); |
|
215 | + $x0 ^= self::load_4(self::substr($message, 0, 4)); |
|
216 | + $x1 ^= self::load_4(self::substr($message, 4, 4)); |
|
217 | + $x2 ^= self::load_4(self::substr($message, 8, 4)); |
|
218 | + $x3 ^= self::load_4(self::substr($message, 12, 4)); |
|
219 | + $x4 ^= self::load_4(self::substr($message, 16, 4)); |
|
220 | + $x5 ^= self::load_4(self::substr($message, 20, 4)); |
|
221 | + $x6 ^= self::load_4(self::substr($message, 24, 4)); |
|
222 | + $x7 ^= self::load_4(self::substr($message, 28, 4)); |
|
223 | + $x8 ^= self::load_4(self::substr($message, 32, 4)); |
|
224 | + $x9 ^= self::load_4(self::substr($message, 36, 4)); |
|
225 | + $x10 ^= self::load_4(self::substr($message, 40, 4)); |
|
226 | + $x11 ^= self::load_4(self::substr($message, 44, 4)); |
|
227 | + $x12 ^= self::load_4(self::substr($message, 48, 4)); |
|
228 | + $x13 ^= self::load_4(self::substr($message, 52, 4)); |
|
229 | + $x14 ^= self::load_4(self::substr($message, 56, 4)); |
|
230 | + $x15 ^= self::load_4(self::substr($message, 60, 4)); |
|
231 | 231 | |
232 | - /* |
|
232 | + /* |
|
233 | 233 | j12 = PLUSONE(j12); |
234 | 234 | if (!j12) { |
235 | 235 | j13 = PLUSONE(j13); |
236 | 236 | } |
237 | 237 | */ |
238 | - ++$j12; |
|
239 | - if ($j12 & 0xf0000000) { |
|
240 | - throw new Exception('Overflow'); |
|
241 | - } |
|
238 | + ++$j12; |
|
239 | + if ($j12 & 0xf0000000) { |
|
240 | + throw new Exception('Overflow'); |
|
241 | + } |
|
242 | 242 | |
243 | - /* |
|
243 | + /* |
|
244 | 244 | STORE32_LE(c + 0, x0); |
245 | 245 | STORE32_LE(c + 4, x1); |
246 | 246 | STORE32_LE(c + 8, x2); |
@@ -258,107 +258,107 @@ discard block |
||
258 | 258 | STORE32_LE(c + 56, x14); |
259 | 259 | STORE32_LE(c + 60, x15); |
260 | 260 | */ |
261 | - $block = self::store32_le((int) ($x0 & 0xffffffff)) . |
|
262 | - self::store32_le((int) ($x1 & 0xffffffff)) . |
|
263 | - self::store32_le((int) ($x2 & 0xffffffff)) . |
|
264 | - self::store32_le((int) ($x3 & 0xffffffff)) . |
|
265 | - self::store32_le((int) ($x4 & 0xffffffff)) . |
|
266 | - self::store32_le((int) ($x5 & 0xffffffff)) . |
|
267 | - self::store32_le((int) ($x6 & 0xffffffff)) . |
|
268 | - self::store32_le((int) ($x7 & 0xffffffff)) . |
|
269 | - self::store32_le((int) ($x8 & 0xffffffff)) . |
|
270 | - self::store32_le((int) ($x9 & 0xffffffff)) . |
|
271 | - self::store32_le((int) ($x10 & 0xffffffff)) . |
|
272 | - self::store32_le((int) ($x11 & 0xffffffff)) . |
|
273 | - self::store32_le((int) ($x12 & 0xffffffff)) . |
|
274 | - self::store32_le((int) ($x13 & 0xffffffff)) . |
|
275 | - self::store32_le((int) ($x14 & 0xffffffff)) . |
|
276 | - self::store32_le((int) ($x15 & 0xffffffff)); |
|
261 | + $block = self::store32_le((int) ($x0 & 0xffffffff)) . |
|
262 | + self::store32_le((int) ($x1 & 0xffffffff)) . |
|
263 | + self::store32_le((int) ($x2 & 0xffffffff)) . |
|
264 | + self::store32_le((int) ($x3 & 0xffffffff)) . |
|
265 | + self::store32_le((int) ($x4 & 0xffffffff)) . |
|
266 | + self::store32_le((int) ($x5 & 0xffffffff)) . |
|
267 | + self::store32_le((int) ($x6 & 0xffffffff)) . |
|
268 | + self::store32_le((int) ($x7 & 0xffffffff)) . |
|
269 | + self::store32_le((int) ($x8 & 0xffffffff)) . |
|
270 | + self::store32_le((int) ($x9 & 0xffffffff)) . |
|
271 | + self::store32_le((int) ($x10 & 0xffffffff)) . |
|
272 | + self::store32_le((int) ($x11 & 0xffffffff)) . |
|
273 | + self::store32_le((int) ($x12 & 0xffffffff)) . |
|
274 | + self::store32_le((int) ($x13 & 0xffffffff)) . |
|
275 | + self::store32_le((int) ($x14 & 0xffffffff)) . |
|
276 | + self::store32_le((int) ($x15 & 0xffffffff)); |
|
277 | 277 | |
278 | - /* Partial block */ |
|
279 | - if ($bytes < 64) { |
|
280 | - $c .= self::substr($block, 0, $bytes); |
|
281 | - break; |
|
282 | - } |
|
278 | + /* Partial block */ |
|
279 | + if ($bytes < 64) { |
|
280 | + $c .= self::substr($block, 0, $bytes); |
|
281 | + break; |
|
282 | + } |
|
283 | 283 | |
284 | - /* Full block */ |
|
285 | - $c .= $block; |
|
286 | - $bytes -= 64; |
|
287 | - if ($bytes <= 0) { |
|
288 | - break; |
|
289 | - } |
|
290 | - $message = self::substr($message, 64); |
|
291 | - } |
|
292 | - /* end for(;;) loop */ |
|
284 | + /* Full block */ |
|
285 | + $c .= $block; |
|
286 | + $bytes -= 64; |
|
287 | + if ($bytes <= 0) { |
|
288 | + break; |
|
289 | + } |
|
290 | + $message = self::substr($message, 64); |
|
291 | + } |
|
292 | + /* end for(;;) loop */ |
|
293 | 293 | |
294 | - $ctx[12] = $j12; |
|
295 | - $ctx[13] = $j13; |
|
296 | - return $c; |
|
297 | - } |
|
294 | + $ctx[12] = $j12; |
|
295 | + $ctx[13] = $j13; |
|
296 | + return $c; |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * @internal You should not use this directly from another application |
|
301 | - * |
|
302 | - * @param int $len |
|
303 | - * @param string $nonce |
|
304 | - * @param string $key |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
308 | - { |
|
309 | - return self::encryptBytes( |
|
310 | - new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce), |
|
311 | - str_repeat("\x00", $len) |
|
312 | - ); |
|
313 | - } |
|
299 | + /** |
|
300 | + * @internal You should not use this directly from another application |
|
301 | + * |
|
302 | + * @param int $len |
|
303 | + * @param string $nonce |
|
304 | + * @param string $key |
|
305 | + * @return string |
|
306 | + */ |
|
307 | + public static function stream($len = 64, $nonce = '', $key = '') |
|
308 | + { |
|
309 | + return self::encryptBytes( |
|
310 | + new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce), |
|
311 | + str_repeat("\x00", $len) |
|
312 | + ); |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * @internal You should not use this directly from another application |
|
317 | - * |
|
318 | - * @param int $len |
|
319 | - * @param string $nonce |
|
320 | - * @param string $key |
|
321 | - * @return string |
|
322 | - */ |
|
323 | - public static function ietfStream($len, $nonce = '', $key = '') |
|
324 | - { |
|
325 | - return self::encryptBytes( |
|
326 | - new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce), |
|
327 | - str_repeat("\x00", $len) |
|
328 | - ); |
|
329 | - } |
|
315 | + /** |
|
316 | + * @internal You should not use this directly from another application |
|
317 | + * |
|
318 | + * @param int $len |
|
319 | + * @param string $nonce |
|
320 | + * @param string $key |
|
321 | + * @return string |
|
322 | + */ |
|
323 | + public static function ietfStream($len, $nonce = '', $key = '') |
|
324 | + { |
|
325 | + return self::encryptBytes( |
|
326 | + new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce), |
|
327 | + str_repeat("\x00", $len) |
|
328 | + ); |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * @internal You should not use this directly from another application |
|
333 | - * |
|
334 | - * @param string $message |
|
335 | - * @param string $nonce |
|
336 | - * @param string $key |
|
337 | - * @param string $ic |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
341 | - { |
|
342 | - return self::encryptBytes( |
|
343 | - new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce, $ic), |
|
344 | - $message |
|
345 | - ); |
|
346 | - } |
|
331 | + /** |
|
332 | + * @internal You should not use this directly from another application |
|
333 | + * |
|
334 | + * @param string $message |
|
335 | + * @param string $nonce |
|
336 | + * @param string $key |
|
337 | + * @param string $ic |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
341 | + { |
|
342 | + return self::encryptBytes( |
|
343 | + new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce, $ic), |
|
344 | + $message |
|
345 | + ); |
|
346 | + } |
|
347 | 347 | |
348 | - /** |
|
349 | - * @internal You should not use this directly from another application |
|
350 | - * |
|
351 | - * @param string $message |
|
352 | - * @param string $nonce |
|
353 | - * @param string $key |
|
354 | - * @param string $ic |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
358 | - { |
|
359 | - return self::encryptBytes( |
|
360 | - new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce, $ic), |
|
361 | - $message |
|
362 | - ); |
|
363 | - } |
|
348 | + /** |
|
349 | + * @internal You should not use this directly from another application |
|
350 | + * |
|
351 | + * @param string $message |
|
352 | + * @param string $nonce |
|
353 | + * @param string $key |
|
354 | + * @param string $ic |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
358 | + { |
|
359 | + return self::encryptBytes( |
|
360 | + new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce, $ic), |
|
361 | + $message |
|
362 | + ); |
|
363 | + } |
|
364 | 364 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_ChaCha20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_ChaCha20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | * @param int $n |
19 | 19 | * @return int |
20 | 20 | */ |
21 | - public static function rotate($v, $n) |
|
21 | + public static function rotate( $v, $n ) |
|
22 | 22 | { |
23 | 23 | $v &= 0xffffffff; |
24 | 24 | $n &= 31; |
25 | 25 | return 0xffffffff & ( |
26 | - ($v << $n) |
|
26 | + ( $v << $n ) |
|
27 | 27 | | |
28 | - ($v >> (32 - $n)) |
|
28 | + ( $v >> ( 32 - $n ) ) |
|
29 | 29 | ); |
30 | 30 | } |
31 | 31 | |
@@ -40,24 +40,24 @@ discard block |
||
40 | 40 | * @param int $d |
41 | 41 | * @return array<int, int> |
42 | 42 | */ |
43 | - protected static function quarterRound($a, $b, $c, $d) |
|
43 | + protected static function quarterRound( $a, $b, $c, $d ) |
|
44 | 44 | { |
45 | 45 | # a = PLUS(a,b); d = ROTATE(XOR(d,a),16); |
46 | - $a = ($a + $b) & 0xffffffff; |
|
47 | - $d = self::rotate($d ^ $a, 16); |
|
46 | + $a = ( $a + $b ) & 0xffffffff; |
|
47 | + $d = self::rotate( $d ^ $a, 16 ); |
|
48 | 48 | |
49 | 49 | # c = PLUS(c,d); b = ROTATE(XOR(b,c),12); |
50 | - $c = ($c + $d) & 0xffffffff; |
|
51 | - $b = self::rotate($b ^ $c, 12); |
|
50 | + $c = ( $c + $d ) & 0xffffffff; |
|
51 | + $b = self::rotate( $b ^ $c, 12 ); |
|
52 | 52 | |
53 | 53 | # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); |
54 | - $a = ($a + $b) & 0xffffffff; |
|
55 | - $d = self::rotate($d ^ $a, 8); |
|
54 | + $a = ( $a + $b ) & 0xffffffff; |
|
55 | + $d = self::rotate( $d ^ $a, 8 ); |
|
56 | 56 | |
57 | 57 | # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); |
58 | - $c = ($c + $d) & 0xffffffff; |
|
59 | - $b = self::rotate($b ^ $c, 7); |
|
60 | - return array((int) $a, (int) $b, (int) $c, (int) $d); |
|
58 | + $c = ( $c + $d ) & 0xffffffff; |
|
59 | + $b = self::rotate( $b ^ $c, 7 ); |
|
60 | + return array( (int) $a, (int) $b, (int) $c, (int) $d ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx, |
74 | 74 | $message = '' |
75 | 75 | ) { |
76 | - $bytes = self::strlen($message); |
|
76 | + $bytes = self::strlen( $message ); |
|
77 | 77 | |
78 | 78 | /* |
79 | 79 | j0 = ctx->input[0]; |
@@ -111,21 +111,21 @@ discard block |
||
111 | 111 | $j15 = (int) $ctx[15]; |
112 | 112 | |
113 | 113 | $c = ''; |
114 | - for (;;) { |
|
115 | - if ($bytes < 64) { |
|
116 | - $message .= str_repeat("\x00", 64 - $bytes); |
|
114 | + for ( ;; ) { |
|
115 | + if ( $bytes < 64 ) { |
|
116 | + $message .= str_repeat( "\x00", 64 - $bytes ); |
|
117 | 117 | } |
118 | 118 | |
119 | - $x0 = (int) $j0; |
|
120 | - $x1 = (int) $j1; |
|
121 | - $x2 = (int) $j2; |
|
122 | - $x3 = (int) $j3; |
|
123 | - $x4 = (int) $j4; |
|
124 | - $x5 = (int) $j5; |
|
125 | - $x6 = (int) $j6; |
|
126 | - $x7 = (int) $j7; |
|
127 | - $x8 = (int) $j8; |
|
128 | - $x9 = (int) $j9; |
|
119 | + $x0 = (int) $j0; |
|
120 | + $x1 = (int) $j1; |
|
121 | + $x2 = (int) $j2; |
|
122 | + $x3 = (int) $j3; |
|
123 | + $x4 = (int) $j4; |
|
124 | + $x5 = (int) $j5; |
|
125 | + $x6 = (int) $j6; |
|
126 | + $x7 = (int) $j7; |
|
127 | + $x8 = (int) $j8; |
|
128 | + $x9 = (int) $j9; |
|
129 | 129 | $x10 = (int) $j10; |
130 | 130 | $x11 = (int) $j11; |
131 | 131 | $x12 = (int) $j12; |
@@ -134,30 +134,30 @@ discard block |
||
134 | 134 | $x15 = (int) $j15; |
135 | 135 | |
136 | 136 | # for (i = 20; i > 0; i -= 2) { |
137 | - for ($i = 20; $i > 0; $i -= 2) { |
|
137 | + for ( $i = 20; $i > 0; $i -= 2 ) { |
|
138 | 138 | # QUARTERROUND( x0, x4, x8, x12) |
139 | - list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
139 | + list( $x0, $x4, $x8, $x12 ) = self::quarterRound( $x0, $x4, $x8, $x12 ); |
|
140 | 140 | |
141 | 141 | # QUARTERROUND( x1, x5, x9, x13) |
142 | - list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
142 | + list( $x1, $x5, $x9, $x13 ) = self::quarterRound( $x1, $x5, $x9, $x13 ); |
|
143 | 143 | |
144 | 144 | # QUARTERROUND( x2, x6, x10, x14) |
145 | - list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
145 | + list( $x2, $x6, $x10, $x14 ) = self::quarterRound( $x2, $x6, $x10, $x14 ); |
|
146 | 146 | |
147 | 147 | # QUARTERROUND( x3, x7, x11, x15) |
148 | - list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
148 | + list( $x3, $x7, $x11, $x15 ) = self::quarterRound( $x3, $x7, $x11, $x15 ); |
|
149 | 149 | |
150 | 150 | # QUARTERROUND( x0, x5, x10, x15) |
151 | - list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
151 | + list( $x0, $x5, $x10, $x15 ) = self::quarterRound( $x0, $x5, $x10, $x15 ); |
|
152 | 152 | |
153 | 153 | # QUARTERROUND( x1, x6, x11, x12) |
154 | - list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
154 | + list( $x1, $x6, $x11, $x12 ) = self::quarterRound( $x1, $x6, $x11, $x12 ); |
|
155 | 155 | |
156 | 156 | # QUARTERROUND( x2, x7, x8, x13) |
157 | - list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
157 | + list( $x2, $x7, $x8, $x13 ) = self::quarterRound( $x2, $x7, $x8, $x13 ); |
|
158 | 158 | |
159 | 159 | # QUARTERROUND( x3, x4, x9, x14) |
160 | - list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
160 | + list( $x3, $x4, $x9, $x14 ) = self::quarterRound( $x3, $x4, $x9, $x14 ); |
|
161 | 161 | } |
162 | 162 | /* |
163 | 163 | x0 = PLUS(x0, j0); |
@@ -177,22 +177,22 @@ discard block |
||
177 | 177 | x14 = PLUS(x14, j14); |
178 | 178 | x15 = PLUS(x15, j15); |
179 | 179 | */ |
180 | - $x0 = ($x0 & 0xffffffff) + $j0; |
|
181 | - $x1 = ($x1 & 0xffffffff) + $j1; |
|
182 | - $x2 = ($x2 & 0xffffffff) + $j2; |
|
183 | - $x3 = ($x3 & 0xffffffff) + $j3; |
|
184 | - $x4 = ($x4 & 0xffffffff) + $j4; |
|
185 | - $x5 = ($x5 & 0xffffffff) + $j5; |
|
186 | - $x6 = ($x6 & 0xffffffff) + $j6; |
|
187 | - $x7 = ($x7 & 0xffffffff) + $j7; |
|
188 | - $x8 = ($x8 & 0xffffffff) + $j8; |
|
189 | - $x9 = ($x9 & 0xffffffff) + $j9; |
|
190 | - $x10 = ($x10 & 0xffffffff) + $j10; |
|
191 | - $x11 = ($x11 & 0xffffffff) + $j11; |
|
192 | - $x12 = ($x12 & 0xffffffff) + $j12; |
|
193 | - $x13 = ($x13 & 0xffffffff) + $j13; |
|
194 | - $x14 = ($x14 & 0xffffffff) + $j14; |
|
195 | - $x15 = ($x15 & 0xffffffff) + $j15; |
|
180 | + $x0 = ( $x0 & 0xffffffff ) + $j0; |
|
181 | + $x1 = ( $x1 & 0xffffffff ) + $j1; |
|
182 | + $x2 = ( $x2 & 0xffffffff ) + $j2; |
|
183 | + $x3 = ( $x3 & 0xffffffff ) + $j3; |
|
184 | + $x4 = ( $x4 & 0xffffffff ) + $j4; |
|
185 | + $x5 = ( $x5 & 0xffffffff ) + $j5; |
|
186 | + $x6 = ( $x6 & 0xffffffff ) + $j6; |
|
187 | + $x7 = ( $x7 & 0xffffffff ) + $j7; |
|
188 | + $x8 = ( $x8 & 0xffffffff ) + $j8; |
|
189 | + $x9 = ( $x9 & 0xffffffff ) + $j9; |
|
190 | + $x10 = ( $x10 & 0xffffffff ) + $j10; |
|
191 | + $x11 = ( $x11 & 0xffffffff ) + $j11; |
|
192 | + $x12 = ( $x12 & 0xffffffff ) + $j12; |
|
193 | + $x13 = ( $x13 & 0xffffffff ) + $j13; |
|
194 | + $x14 = ( $x14 & 0xffffffff ) + $j14; |
|
195 | + $x15 = ( $x15 & 0xffffffff ) + $j15; |
|
196 | 196 | |
197 | 197 | /* |
198 | 198 | x0 = XOR(x0, LOAD32_LE(m + 0)); |
@@ -212,22 +212,22 @@ discard block |
||
212 | 212 | x14 = XOR(x14, LOAD32_LE(m + 56)); |
213 | 213 | x15 = XOR(x15, LOAD32_LE(m + 60)); |
214 | 214 | */ |
215 | - $x0 ^= self::load_4(self::substr($message, 0, 4)); |
|
216 | - $x1 ^= self::load_4(self::substr($message, 4, 4)); |
|
217 | - $x2 ^= self::load_4(self::substr($message, 8, 4)); |
|
218 | - $x3 ^= self::load_4(self::substr($message, 12, 4)); |
|
219 | - $x4 ^= self::load_4(self::substr($message, 16, 4)); |
|
220 | - $x5 ^= self::load_4(self::substr($message, 20, 4)); |
|
221 | - $x6 ^= self::load_4(self::substr($message, 24, 4)); |
|
222 | - $x7 ^= self::load_4(self::substr($message, 28, 4)); |
|
223 | - $x8 ^= self::load_4(self::substr($message, 32, 4)); |
|
224 | - $x9 ^= self::load_4(self::substr($message, 36, 4)); |
|
225 | - $x10 ^= self::load_4(self::substr($message, 40, 4)); |
|
226 | - $x11 ^= self::load_4(self::substr($message, 44, 4)); |
|
227 | - $x12 ^= self::load_4(self::substr($message, 48, 4)); |
|
228 | - $x13 ^= self::load_4(self::substr($message, 52, 4)); |
|
229 | - $x14 ^= self::load_4(self::substr($message, 56, 4)); |
|
230 | - $x15 ^= self::load_4(self::substr($message, 60, 4)); |
|
215 | + $x0 ^= self::load_4( self::substr( $message, 0, 4 ) ); |
|
216 | + $x1 ^= self::load_4( self::substr( $message, 4, 4 ) ); |
|
217 | + $x2 ^= self::load_4( self::substr( $message, 8, 4 ) ); |
|
218 | + $x3 ^= self::load_4( self::substr( $message, 12, 4 ) ); |
|
219 | + $x4 ^= self::load_4( self::substr( $message, 16, 4 ) ); |
|
220 | + $x5 ^= self::load_4( self::substr( $message, 20, 4 ) ); |
|
221 | + $x6 ^= self::load_4( self::substr( $message, 24, 4 ) ); |
|
222 | + $x7 ^= self::load_4( self::substr( $message, 28, 4 ) ); |
|
223 | + $x8 ^= self::load_4( self::substr( $message, 32, 4 ) ); |
|
224 | + $x9 ^= self::load_4( self::substr( $message, 36, 4 ) ); |
|
225 | + $x10 ^= self::load_4( self::substr( $message, 40, 4 ) ); |
|
226 | + $x11 ^= self::load_4( self::substr( $message, 44, 4 ) ); |
|
227 | + $x12 ^= self::load_4( self::substr( $message, 48, 4 ) ); |
|
228 | + $x13 ^= self::load_4( self::substr( $message, 52, 4 ) ); |
|
229 | + $x14 ^= self::load_4( self::substr( $message, 56, 4 ) ); |
|
230 | + $x15 ^= self::load_4( self::substr( $message, 60, 4 ) ); |
|
231 | 231 | |
232 | 232 | /* |
233 | 233 | j12 = PLUSONE(j12); |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | } |
237 | 237 | */ |
238 | 238 | ++$j12; |
239 | - if ($j12 & 0xf0000000) { |
|
240 | - throw new Exception('Overflow'); |
|
239 | + if ( $j12 & 0xf0000000 ) { |
|
240 | + throw new Exception( 'Overflow' ); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /* |
@@ -258,36 +258,36 @@ discard block |
||
258 | 258 | STORE32_LE(c + 56, x14); |
259 | 259 | STORE32_LE(c + 60, x15); |
260 | 260 | */ |
261 | - $block = self::store32_le((int) ($x0 & 0xffffffff)) . |
|
262 | - self::store32_le((int) ($x1 & 0xffffffff)) . |
|
263 | - self::store32_le((int) ($x2 & 0xffffffff)) . |
|
264 | - self::store32_le((int) ($x3 & 0xffffffff)) . |
|
265 | - self::store32_le((int) ($x4 & 0xffffffff)) . |
|
266 | - self::store32_le((int) ($x5 & 0xffffffff)) . |
|
267 | - self::store32_le((int) ($x6 & 0xffffffff)) . |
|
268 | - self::store32_le((int) ($x7 & 0xffffffff)) . |
|
269 | - self::store32_le((int) ($x8 & 0xffffffff)) . |
|
270 | - self::store32_le((int) ($x9 & 0xffffffff)) . |
|
271 | - self::store32_le((int) ($x10 & 0xffffffff)) . |
|
272 | - self::store32_le((int) ($x11 & 0xffffffff)) . |
|
273 | - self::store32_le((int) ($x12 & 0xffffffff)) . |
|
274 | - self::store32_le((int) ($x13 & 0xffffffff)) . |
|
275 | - self::store32_le((int) ($x14 & 0xffffffff)) . |
|
276 | - self::store32_le((int) ($x15 & 0xffffffff)); |
|
261 | + $block = self::store32_le( (int) ( $x0 & 0xffffffff ) ) . |
|
262 | + self::store32_le( (int) ( $x1 & 0xffffffff ) ) . |
|
263 | + self::store32_le( (int) ( $x2 & 0xffffffff ) ) . |
|
264 | + self::store32_le( (int) ( $x3 & 0xffffffff ) ) . |
|
265 | + self::store32_le( (int) ( $x4 & 0xffffffff ) ) . |
|
266 | + self::store32_le( (int) ( $x5 & 0xffffffff ) ) . |
|
267 | + self::store32_le( (int) ( $x6 & 0xffffffff ) ) . |
|
268 | + self::store32_le( (int) ( $x7 & 0xffffffff ) ) . |
|
269 | + self::store32_le( (int) ( $x8 & 0xffffffff ) ) . |
|
270 | + self::store32_le( (int) ( $x9 & 0xffffffff ) ) . |
|
271 | + self::store32_le( (int) ( $x10 & 0xffffffff ) ) . |
|
272 | + self::store32_le( (int) ( $x11 & 0xffffffff ) ) . |
|
273 | + self::store32_le( (int) ( $x12 & 0xffffffff ) ) . |
|
274 | + self::store32_le( (int) ( $x13 & 0xffffffff ) ) . |
|
275 | + self::store32_le( (int) ( $x14 & 0xffffffff ) ) . |
|
276 | + self::store32_le( (int) ( $x15 & 0xffffffff ) ); |
|
277 | 277 | |
278 | 278 | /* Partial block */ |
279 | - if ($bytes < 64) { |
|
280 | - $c .= self::substr($block, 0, $bytes); |
|
279 | + if ( $bytes < 64 ) { |
|
280 | + $c .= self::substr( $block, 0, $bytes ); |
|
281 | 281 | break; |
282 | 282 | } |
283 | 283 | |
284 | 284 | /* Full block */ |
285 | 285 | $c .= $block; |
286 | 286 | $bytes -= 64; |
287 | - if ($bytes <= 0) { |
|
287 | + if ( $bytes <= 0 ) { |
|
288 | 288 | break; |
289 | 289 | } |
290 | - $message = self::substr($message, 64); |
|
290 | + $message = self::substr( $message, 64 ); |
|
291 | 291 | } |
292 | 292 | /* end for(;;) loop */ |
293 | 293 | |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | * @param string $key |
305 | 305 | * @return string |
306 | 306 | */ |
307 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
307 | + public static function stream( $len = 64, $nonce = '', $key = '' ) |
|
308 | 308 | { |
309 | 309 | return self::encryptBytes( |
310 | - new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce), |
|
311 | - str_repeat("\x00", $len) |
|
310 | + new ParagonIE_Sodium_Core_ChaCha20_Ctx( $key, $nonce ), |
|
311 | + str_repeat( "\x00", $len ) |
|
312 | 312 | ); |
313 | 313 | } |
314 | 314 | |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | * @param string $key |
321 | 321 | * @return string |
322 | 322 | */ |
323 | - public static function ietfStream($len, $nonce = '', $key = '') |
|
323 | + public static function ietfStream( $len, $nonce = '', $key = '' ) |
|
324 | 324 | { |
325 | 325 | return self::encryptBytes( |
326 | - new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce), |
|
327 | - str_repeat("\x00", $len) |
|
326 | + new ParagonIE_Sodium_Core_ChaCha20_IetfCtx( $key, $nonce ), |
|
327 | + str_repeat( "\x00", $len ) |
|
328 | 328 | ); |
329 | 329 | } |
330 | 330 | |
@@ -337,10 +337,10 @@ discard block |
||
337 | 337 | * @param string $ic |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
340 | + public static function ietfStreamXorIc( $message, $nonce = '', $key = '', $ic = '' ) |
|
341 | 341 | { |
342 | 342 | return self::encryptBytes( |
343 | - new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce, $ic), |
|
343 | + new ParagonIE_Sodium_Core_ChaCha20_IetfCtx( $key, $nonce, $ic ), |
|
344 | 344 | $message |
345 | 345 | ); |
346 | 346 | } |
@@ -354,10 +354,10 @@ discard block |
||
354 | 354 | * @param string $ic |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
357 | + public static function streamXorIc( $message, $nonce = '', $key = '', $ic = '' ) |
|
358 | 358 | { |
359 | 359 | return self::encryptBytes( |
360 | - new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce, $ic), |
|
360 | + new ParagonIE_Sodium_Core_ChaCha20_Ctx( $key, $nonce, $ic ), |
|
361 | 361 | $message |
362 | 362 | ); |
363 | 363 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_ChaCha20 |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_ChaCha20 extends ParagonIE_Sodium_Core_Util |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_ChaCha20 extends ParagonIE_Sodium_Core_Util { |
|
12 | 11 | /** |
13 | 12 | * Bitwise left rotation |
14 | 13 | * |
@@ -18,8 +17,7 @@ discard block |
||
18 | 17 | * @param int $n |
19 | 18 | * @return int |
20 | 19 | */ |
21 | - public static function rotate($v, $n) |
|
22 | - { |
|
20 | + public static function rotate($v, $n) { |
|
23 | 21 | $v &= 0xffffffff; |
24 | 22 | $n &= 31; |
25 | 23 | return 0xffffffff & ( |
@@ -40,8 +38,7 @@ discard block |
||
40 | 38 | * @param int $d |
41 | 39 | * @return array<int, int> |
42 | 40 | */ |
43 | - protected static function quarterRound($a, $b, $c, $d) |
|
44 | - { |
|
41 | + protected static function quarterRound($a, $b, $c, $d) { |
|
45 | 42 | # a = PLUS(a,b); d = ROTATE(XOR(d,a),16); |
46 | 43 | $a = ($a + $b) & 0xffffffff; |
47 | 44 | $d = self::rotate($d ^ $a, 16); |
@@ -304,8 +301,7 @@ discard block |
||
304 | 301 | * @param string $key |
305 | 302 | * @return string |
306 | 303 | */ |
307 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
308 | - { |
|
304 | + public static function stream($len = 64, $nonce = '', $key = '') { |
|
309 | 305 | return self::encryptBytes( |
310 | 306 | new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce), |
311 | 307 | str_repeat("\x00", $len) |
@@ -320,8 +316,7 @@ discard block |
||
320 | 316 | * @param string $key |
321 | 317 | * @return string |
322 | 318 | */ |
323 | - public static function ietfStream($len, $nonce = '', $key = '') |
|
324 | - { |
|
319 | + public static function ietfStream($len, $nonce = '', $key = '') { |
|
325 | 320 | return self::encryptBytes( |
326 | 321 | new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce), |
327 | 322 | str_repeat("\x00", $len) |
@@ -337,8 +332,7 @@ discard block |
||
337 | 332 | * @param string $ic |
338 | 333 | * @return string |
339 | 334 | */ |
340 | - public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
341 | - { |
|
335 | + public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') { |
|
342 | 336 | return self::encryptBytes( |
343 | 337 | new ParagonIE_Sodium_Core_ChaCha20_IetfCtx($key, $nonce, $ic), |
344 | 338 | $message |
@@ -354,8 +348,7 @@ discard block |
||
354 | 348 | * @param string $ic |
355 | 349 | * @return string |
356 | 350 | */ |
357 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
358 | - { |
|
351 | + public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { |
|
359 | 352 | return self::encryptBytes( |
360 | 353 | new ParagonIE_Sodium_Core_ChaCha20_Ctx($key, $nonce, $ic), |
361 | 354 | $message |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_X25519', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,303 +9,303 @@ discard block |
||
9 | 9 | */ |
10 | 10 | abstract class ParagonIE_Sodium_Core_X25519 extends ParagonIE_Sodium_Core_Curve25519 |
11 | 11 | { |
12 | - /** |
|
13 | - * Alters the objects passed to this method in place. |
|
14 | - * |
|
15 | - * @internal You should not use this directly from another application |
|
16 | - * |
|
17 | - * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
|
18 | - * @param ParagonIE_Sodium_Core_Curve25519_Fe $g |
|
19 | - * @param int $b |
|
20 | - * @return void |
|
21 | - */ |
|
22 | - public static function fe_cswap( |
|
23 | - ParagonIE_Sodium_Core_Curve25519_Fe $f, |
|
24 | - ParagonIE_Sodium_Core_Curve25519_Fe $g, |
|
25 | - $b = 0 |
|
26 | - ) { |
|
27 | - $f0 = (int) $f[0]; |
|
28 | - $f1 = (int) $f[1]; |
|
29 | - $f2 = (int) $f[2]; |
|
30 | - $f3 = (int) $f[3]; |
|
31 | - $f4 = (int) $f[4]; |
|
32 | - $f5 = (int) $f[5]; |
|
33 | - $f6 = (int) $f[6]; |
|
34 | - $f7 = (int) $f[7]; |
|
35 | - $f8 = (int) $f[8]; |
|
36 | - $f9 = (int) $f[9]; |
|
37 | - $g0 = (int) $g[0]; |
|
38 | - $g1 = (int) $g[1]; |
|
39 | - $g2 = (int) $g[2]; |
|
40 | - $g3 = (int) $g[3]; |
|
41 | - $g4 = (int) $g[4]; |
|
42 | - $g5 = (int) $g[5]; |
|
43 | - $g6 = (int) $g[6]; |
|
44 | - $g7 = (int) $g[7]; |
|
45 | - $g8 = (int) $g[8]; |
|
46 | - $g9 = (int) $g[9]; |
|
47 | - $b = -$b; |
|
48 | - $x0 = ($f0 ^ $g0) & $b; |
|
49 | - $x1 = ($f1 ^ $g1) & $b; |
|
50 | - $x2 = ($f2 ^ $g2) & $b; |
|
51 | - $x3 = ($f3 ^ $g3) & $b; |
|
52 | - $x4 = ($f4 ^ $g4) & $b; |
|
53 | - $x5 = ($f5 ^ $g5) & $b; |
|
54 | - $x6 = ($f6 ^ $g6) & $b; |
|
55 | - $x7 = ($f7 ^ $g7) & $b; |
|
56 | - $x8 = ($f8 ^ $g8) & $b; |
|
57 | - $x9 = ($f9 ^ $g9) & $b; |
|
58 | - $f[0] = $f0 ^ $x0; |
|
59 | - $f[1] = $f1 ^ $x1; |
|
60 | - $f[2] = $f2 ^ $x2; |
|
61 | - $f[3] = $f3 ^ $x3; |
|
62 | - $f[4] = $f4 ^ $x4; |
|
63 | - $f[5] = $f5 ^ $x5; |
|
64 | - $f[6] = $f6 ^ $x6; |
|
65 | - $f[7] = $f7 ^ $x7; |
|
66 | - $f[8] = $f8 ^ $x8; |
|
67 | - $f[9] = $f9 ^ $x9; |
|
68 | - $g[0] = $g0 ^ $x0; |
|
69 | - $g[1] = $g1 ^ $x1; |
|
70 | - $g[2] = $g2 ^ $x2; |
|
71 | - $g[3] = $g3 ^ $x3; |
|
72 | - $g[4] = $g4 ^ $x4; |
|
73 | - $g[5] = $g5 ^ $x5; |
|
74 | - $g[6] = $g6 ^ $x6; |
|
75 | - $g[7] = $g7 ^ $x7; |
|
76 | - $g[8] = $g8 ^ $x8; |
|
77 | - $g[9] = $g9 ^ $x9; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @internal You should not use this directly from another application |
|
82 | - * |
|
83 | - * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
|
84 | - * @return ParagonIE_Sodium_Core_Curve25519_Fe |
|
85 | - */ |
|
86 | - public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
87 | - { |
|
88 | - $h = array( |
|
89 | - self::mul($f[0], 121666, 17), |
|
90 | - self::mul($f[1], 121666, 17), |
|
91 | - self::mul($f[2], 121666, 17), |
|
92 | - self::mul($f[3], 121666, 17), |
|
93 | - self::mul($f[4], 121666, 17), |
|
94 | - self::mul($f[5], 121666, 17), |
|
95 | - self::mul($f[6], 121666, 17), |
|
96 | - self::mul($f[7], 121666, 17), |
|
97 | - self::mul($f[8], 121666, 17), |
|
98 | - self::mul($f[9], 121666, 17) |
|
99 | - ); |
|
100 | - |
|
101 | - $carry9 = ($h[9] + (1 << 24)) >> 25; |
|
102 | - $h[0] += self::mul($carry9, 19, 5); |
|
103 | - $h[9] -= $carry9 << 25; |
|
104 | - $carry1 = ($h[1] + (1 << 24)) >> 25; |
|
105 | - $h[2] += $carry1; |
|
106 | - $h[1] -= $carry1 << 25; |
|
107 | - $carry3 = ($h[3] + (1 << 24)) >> 25; |
|
108 | - $h[4] += $carry3; |
|
109 | - $h[3] -= $carry3 << 25; |
|
110 | - $carry5 = ($h[5] + (1 << 24)) >> 25; |
|
111 | - $h[6] += $carry5; |
|
112 | - $h[5] -= $carry5 << 25; |
|
113 | - $carry7 = ($h[7] + (1 << 24)) >> 25; |
|
114 | - $h[8] += $carry7; |
|
115 | - $h[7] -= $carry7 << 25; |
|
116 | - |
|
117 | - $carry0 = ($h[0] + (1 << 25)) >> 26; |
|
118 | - $h[1] += $carry0; |
|
119 | - $h[0] -= $carry0 << 26; |
|
120 | - $carry2 = ($h[2] + (1 << 25)) >> 26; |
|
121 | - $h[3] += $carry2; |
|
122 | - $h[2] -= $carry2 << 26; |
|
123 | - $carry4 = ($h[4] + (1 << 25)) >> 26; |
|
124 | - $h[5] += $carry4; |
|
125 | - $h[4] -= $carry4 << 26; |
|
126 | - $carry6 = ($h[6] + (1 << 25)) >> 26; |
|
127 | - $h[7] += $carry6; |
|
128 | - $h[6] -= $carry6 << 26; |
|
129 | - $carry8 = ($h[8] + (1 << 25)) >> 26; |
|
130 | - $h[9] += $carry8; |
|
131 | - $h[8] -= $carry8 << 26; |
|
132 | - |
|
133 | - foreach ($h as $i => $value) { |
|
134 | - $h[$i] = (int) $value; |
|
135 | - } |
|
136 | - return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @internal You should not use this directly from another application |
|
141 | - * |
|
142 | - * Inline comments preceded by # are from libsodium's ref10 code. |
|
143 | - * |
|
144 | - * @param string $n |
|
145 | - * @param string $p |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
149 | - { |
|
150 | - # for (i = 0;i < 32;++i) e[i] = n[i]; |
|
151 | - $e = '' . $n; |
|
152 | - # e[0] &= 248; |
|
153 | - $e[0] = self::intToChr( |
|
154 | - self::chrToInt($e[0]) & 248 |
|
155 | - ); |
|
156 | - # e[31] &= 127; |
|
157 | - # e[31] |= 64; |
|
158 | - $e[31] = self::intToChr( |
|
159 | - (self::chrToInt($e[31]) & 127) | 64 |
|
160 | - ); |
|
161 | - # fe_frombytes(x1,p); |
|
162 | - $x1 = self::fe_frombytes($p); |
|
163 | - # fe_1(x2); |
|
164 | - $x2 = self::fe_1(); |
|
165 | - # fe_0(z2); |
|
166 | - $z2 = self::fe_0(); |
|
167 | - # fe_copy(x3,x1); |
|
168 | - $x3 = self::fe_copy($x1); |
|
169 | - # fe_1(z3); |
|
170 | - $z3 = self::fe_1(); |
|
171 | - |
|
172 | - # swap = 0; |
|
173 | - $swap = 0; |
|
174 | - |
|
175 | - # for (pos = 254;pos >= 0;--pos) { |
|
176 | - for ($pos = 254; $pos >= 0; --$pos) { |
|
177 | - # b = e[pos / 8] >> (pos & 7); |
|
178 | - $b = self::chrToInt( |
|
179 | - $e[(int) floor($pos / 8)] |
|
180 | - ) >> ($pos & 7); |
|
181 | - # b &= 1; |
|
182 | - $b &= 1; |
|
183 | - # swap ^= b; |
|
184 | - $swap ^= $b; |
|
185 | - # fe_cswap(x2,x3,swap); |
|
186 | - self::fe_cswap($x2, $x3, $swap); |
|
187 | - # fe_cswap(z2,z3,swap); |
|
188 | - self::fe_cswap($z2, $z3, $swap); |
|
189 | - # swap = b; |
|
190 | - $swap = $b; |
|
191 | - # fe_sub(tmp0,x3,z3); |
|
192 | - $tmp0 = self::fe_sub($x3, $z3); |
|
193 | - # fe_sub(tmp1,x2,z2); |
|
194 | - $tmp1 = self::fe_sub($x2, $z2); |
|
195 | - |
|
196 | - # fe_add(x2,x2,z2); |
|
197 | - $x2 = self::fe_add($x2, $z2); |
|
198 | - |
|
199 | - # fe_add(z2,x3,z3); |
|
200 | - $z2 = self::fe_add($x3, $z3); |
|
201 | - |
|
202 | - # fe_mul(z3,tmp0,x2); |
|
203 | - $z3 = self::fe_mul($tmp0, $x2); |
|
204 | - |
|
205 | - # fe_mul(z2,z2,tmp1); |
|
206 | - $z2 = self::fe_mul($z2, $tmp1); |
|
207 | - |
|
208 | - # fe_sq(tmp0,tmp1); |
|
209 | - $tmp0 = self::fe_sq($tmp1); |
|
210 | - |
|
211 | - # fe_sq(tmp1,x2); |
|
212 | - $tmp1 = self::fe_sq($x2); |
|
213 | - |
|
214 | - # fe_add(x3,z3,z2); |
|
215 | - $x3 = self::fe_add($z3, $z2); |
|
216 | - |
|
217 | - # fe_sub(z2,z3,z2); |
|
218 | - $z2 = self::fe_sub($z3, $z2); |
|
219 | - |
|
220 | - # fe_mul(x2,tmp1,tmp0); |
|
221 | - $x2 = self::fe_mul($tmp1, $tmp0); |
|
222 | - |
|
223 | - # fe_sub(tmp1,tmp1,tmp0); |
|
224 | - $tmp1 = self::fe_sub($tmp1, $tmp0); |
|
225 | - |
|
226 | - # fe_sq(z2,z2); |
|
227 | - $z2 = self::fe_sq($z2); |
|
228 | - |
|
229 | - # fe_mul121666(z3,tmp1); |
|
230 | - $z3 = self::fe_mul121666($tmp1); |
|
231 | - |
|
232 | - # fe_sq(x3,x3); |
|
233 | - $x3 = self::fe_sq($x3); |
|
234 | - |
|
235 | - # fe_add(tmp0,tmp0,z3); |
|
236 | - $tmp0 = self::fe_add($tmp0, $z3); |
|
237 | - |
|
238 | - # fe_mul(z3,x1,z2); |
|
239 | - $z3 = self::fe_mul($x1, $z2); |
|
240 | - |
|
241 | - # fe_mul(z2,tmp1,tmp0); |
|
242 | - $z2 = self::fe_mul($tmp1, $tmp0); |
|
243 | - } |
|
244 | - |
|
245 | - # fe_cswap(x2,x3,swap); |
|
246 | - self::fe_cswap($x2, $x3, $swap); |
|
247 | - |
|
248 | - # fe_cswap(z2,z3,swap); |
|
249 | - self::fe_cswap($z2, $z3, $swap); |
|
250 | - |
|
251 | - # fe_invert(z2,z2); |
|
252 | - $z2 = self::fe_invert($z2); |
|
253 | - |
|
254 | - # fe_mul(x2,x2,z2); |
|
255 | - $x2 = self::fe_mul($x2, $z2); |
|
256 | - # fe_tobytes(q,x2); |
|
257 | - return self::fe_tobytes($x2); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @internal You should not use this directly from another application |
|
262 | - * |
|
263 | - * @param ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY |
|
264 | - * @param ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ |
|
265 | - * @return ParagonIE_Sodium_Core_Curve25519_Fe |
|
266 | - */ |
|
267 | - public static function edwards_to_montgomery( |
|
268 | - ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY, |
|
269 | - ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ |
|
270 | - ) { |
|
271 | - $tempX = self::fe_add($edwardsZ, $edwardsY); |
|
272 | - $tempZ = self::fe_sub($edwardsZ, $edwardsY); |
|
273 | - $tempZ = self::fe_invert($tempZ); |
|
274 | - return self::fe_mul($tempX, $tempZ); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * @internal You should not use this directly from another application |
|
279 | - * |
|
280 | - * @param string $n |
|
281 | - * @return string |
|
282 | - * @throws TypeError |
|
283 | - */ |
|
284 | - public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
285 | - { |
|
286 | - # for (i = 0;i < 32;++i) e[i] = n[i]; |
|
287 | - $e = '' . $n; |
|
288 | - |
|
289 | - # e[0] &= 248; |
|
290 | - $e[0] = self::intToChr( |
|
291 | - self::chrToInt($e[0]) & 248 |
|
292 | - ); |
|
293 | - |
|
294 | - # e[31] &= 127; |
|
295 | - # e[31] |= 64; |
|
296 | - $e[31] = self::intToChr( |
|
297 | - (self::chrToInt($e[31]) & 127) | 64 |
|
298 | - ); |
|
299 | - |
|
300 | - $A = self::ge_scalarmult_base($e); |
|
301 | - if ( |
|
302 | - !($A->Y instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
303 | - || |
|
304 | - !($A->Z instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
305 | - ) { |
|
306 | - throw new TypeError('Null points encountered'); |
|
307 | - } |
|
308 | - $pk = self::edwards_to_montgomery($A->Y, $A->Z); |
|
309 | - return self::fe_tobytes($pk); |
|
310 | - } |
|
12 | + /** |
|
13 | + * Alters the objects passed to this method in place. |
|
14 | + * |
|
15 | + * @internal You should not use this directly from another application |
|
16 | + * |
|
17 | + * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
|
18 | + * @param ParagonIE_Sodium_Core_Curve25519_Fe $g |
|
19 | + * @param int $b |
|
20 | + * @return void |
|
21 | + */ |
|
22 | + public static function fe_cswap( |
|
23 | + ParagonIE_Sodium_Core_Curve25519_Fe $f, |
|
24 | + ParagonIE_Sodium_Core_Curve25519_Fe $g, |
|
25 | + $b = 0 |
|
26 | + ) { |
|
27 | + $f0 = (int) $f[0]; |
|
28 | + $f1 = (int) $f[1]; |
|
29 | + $f2 = (int) $f[2]; |
|
30 | + $f3 = (int) $f[3]; |
|
31 | + $f4 = (int) $f[4]; |
|
32 | + $f5 = (int) $f[5]; |
|
33 | + $f6 = (int) $f[6]; |
|
34 | + $f7 = (int) $f[7]; |
|
35 | + $f8 = (int) $f[8]; |
|
36 | + $f9 = (int) $f[9]; |
|
37 | + $g0 = (int) $g[0]; |
|
38 | + $g1 = (int) $g[1]; |
|
39 | + $g2 = (int) $g[2]; |
|
40 | + $g3 = (int) $g[3]; |
|
41 | + $g4 = (int) $g[4]; |
|
42 | + $g5 = (int) $g[5]; |
|
43 | + $g6 = (int) $g[6]; |
|
44 | + $g7 = (int) $g[7]; |
|
45 | + $g8 = (int) $g[8]; |
|
46 | + $g9 = (int) $g[9]; |
|
47 | + $b = -$b; |
|
48 | + $x0 = ($f0 ^ $g0) & $b; |
|
49 | + $x1 = ($f1 ^ $g1) & $b; |
|
50 | + $x2 = ($f2 ^ $g2) & $b; |
|
51 | + $x3 = ($f3 ^ $g3) & $b; |
|
52 | + $x4 = ($f4 ^ $g4) & $b; |
|
53 | + $x5 = ($f5 ^ $g5) & $b; |
|
54 | + $x6 = ($f6 ^ $g6) & $b; |
|
55 | + $x7 = ($f7 ^ $g7) & $b; |
|
56 | + $x8 = ($f8 ^ $g8) & $b; |
|
57 | + $x9 = ($f9 ^ $g9) & $b; |
|
58 | + $f[0] = $f0 ^ $x0; |
|
59 | + $f[1] = $f1 ^ $x1; |
|
60 | + $f[2] = $f2 ^ $x2; |
|
61 | + $f[3] = $f3 ^ $x3; |
|
62 | + $f[4] = $f4 ^ $x4; |
|
63 | + $f[5] = $f5 ^ $x5; |
|
64 | + $f[6] = $f6 ^ $x6; |
|
65 | + $f[7] = $f7 ^ $x7; |
|
66 | + $f[8] = $f8 ^ $x8; |
|
67 | + $f[9] = $f9 ^ $x9; |
|
68 | + $g[0] = $g0 ^ $x0; |
|
69 | + $g[1] = $g1 ^ $x1; |
|
70 | + $g[2] = $g2 ^ $x2; |
|
71 | + $g[3] = $g3 ^ $x3; |
|
72 | + $g[4] = $g4 ^ $x4; |
|
73 | + $g[5] = $g5 ^ $x5; |
|
74 | + $g[6] = $g6 ^ $x6; |
|
75 | + $g[7] = $g7 ^ $x7; |
|
76 | + $g[8] = $g8 ^ $x8; |
|
77 | + $g[9] = $g9 ^ $x9; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @internal You should not use this directly from another application |
|
82 | + * |
|
83 | + * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
|
84 | + * @return ParagonIE_Sodium_Core_Curve25519_Fe |
|
85 | + */ |
|
86 | + public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
87 | + { |
|
88 | + $h = array( |
|
89 | + self::mul($f[0], 121666, 17), |
|
90 | + self::mul($f[1], 121666, 17), |
|
91 | + self::mul($f[2], 121666, 17), |
|
92 | + self::mul($f[3], 121666, 17), |
|
93 | + self::mul($f[4], 121666, 17), |
|
94 | + self::mul($f[5], 121666, 17), |
|
95 | + self::mul($f[6], 121666, 17), |
|
96 | + self::mul($f[7], 121666, 17), |
|
97 | + self::mul($f[8], 121666, 17), |
|
98 | + self::mul($f[9], 121666, 17) |
|
99 | + ); |
|
100 | + |
|
101 | + $carry9 = ($h[9] + (1 << 24)) >> 25; |
|
102 | + $h[0] += self::mul($carry9, 19, 5); |
|
103 | + $h[9] -= $carry9 << 25; |
|
104 | + $carry1 = ($h[1] + (1 << 24)) >> 25; |
|
105 | + $h[2] += $carry1; |
|
106 | + $h[1] -= $carry1 << 25; |
|
107 | + $carry3 = ($h[3] + (1 << 24)) >> 25; |
|
108 | + $h[4] += $carry3; |
|
109 | + $h[3] -= $carry3 << 25; |
|
110 | + $carry5 = ($h[5] + (1 << 24)) >> 25; |
|
111 | + $h[6] += $carry5; |
|
112 | + $h[5] -= $carry5 << 25; |
|
113 | + $carry7 = ($h[7] + (1 << 24)) >> 25; |
|
114 | + $h[8] += $carry7; |
|
115 | + $h[7] -= $carry7 << 25; |
|
116 | + |
|
117 | + $carry0 = ($h[0] + (1 << 25)) >> 26; |
|
118 | + $h[1] += $carry0; |
|
119 | + $h[0] -= $carry0 << 26; |
|
120 | + $carry2 = ($h[2] + (1 << 25)) >> 26; |
|
121 | + $h[3] += $carry2; |
|
122 | + $h[2] -= $carry2 << 26; |
|
123 | + $carry4 = ($h[4] + (1 << 25)) >> 26; |
|
124 | + $h[5] += $carry4; |
|
125 | + $h[4] -= $carry4 << 26; |
|
126 | + $carry6 = ($h[6] + (1 << 25)) >> 26; |
|
127 | + $h[7] += $carry6; |
|
128 | + $h[6] -= $carry6 << 26; |
|
129 | + $carry8 = ($h[8] + (1 << 25)) >> 26; |
|
130 | + $h[9] += $carry8; |
|
131 | + $h[8] -= $carry8 << 26; |
|
132 | + |
|
133 | + foreach ($h as $i => $value) { |
|
134 | + $h[$i] = (int) $value; |
|
135 | + } |
|
136 | + return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @internal You should not use this directly from another application |
|
141 | + * |
|
142 | + * Inline comments preceded by # are from libsodium's ref10 code. |
|
143 | + * |
|
144 | + * @param string $n |
|
145 | + * @param string $p |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
149 | + { |
|
150 | + # for (i = 0;i < 32;++i) e[i] = n[i]; |
|
151 | + $e = '' . $n; |
|
152 | + # e[0] &= 248; |
|
153 | + $e[0] = self::intToChr( |
|
154 | + self::chrToInt($e[0]) & 248 |
|
155 | + ); |
|
156 | + # e[31] &= 127; |
|
157 | + # e[31] |= 64; |
|
158 | + $e[31] = self::intToChr( |
|
159 | + (self::chrToInt($e[31]) & 127) | 64 |
|
160 | + ); |
|
161 | + # fe_frombytes(x1,p); |
|
162 | + $x1 = self::fe_frombytes($p); |
|
163 | + # fe_1(x2); |
|
164 | + $x2 = self::fe_1(); |
|
165 | + # fe_0(z2); |
|
166 | + $z2 = self::fe_0(); |
|
167 | + # fe_copy(x3,x1); |
|
168 | + $x3 = self::fe_copy($x1); |
|
169 | + # fe_1(z3); |
|
170 | + $z3 = self::fe_1(); |
|
171 | + |
|
172 | + # swap = 0; |
|
173 | + $swap = 0; |
|
174 | + |
|
175 | + # for (pos = 254;pos >= 0;--pos) { |
|
176 | + for ($pos = 254; $pos >= 0; --$pos) { |
|
177 | + # b = e[pos / 8] >> (pos & 7); |
|
178 | + $b = self::chrToInt( |
|
179 | + $e[(int) floor($pos / 8)] |
|
180 | + ) >> ($pos & 7); |
|
181 | + # b &= 1; |
|
182 | + $b &= 1; |
|
183 | + # swap ^= b; |
|
184 | + $swap ^= $b; |
|
185 | + # fe_cswap(x2,x3,swap); |
|
186 | + self::fe_cswap($x2, $x3, $swap); |
|
187 | + # fe_cswap(z2,z3,swap); |
|
188 | + self::fe_cswap($z2, $z3, $swap); |
|
189 | + # swap = b; |
|
190 | + $swap = $b; |
|
191 | + # fe_sub(tmp0,x3,z3); |
|
192 | + $tmp0 = self::fe_sub($x3, $z3); |
|
193 | + # fe_sub(tmp1,x2,z2); |
|
194 | + $tmp1 = self::fe_sub($x2, $z2); |
|
195 | + |
|
196 | + # fe_add(x2,x2,z2); |
|
197 | + $x2 = self::fe_add($x2, $z2); |
|
198 | + |
|
199 | + # fe_add(z2,x3,z3); |
|
200 | + $z2 = self::fe_add($x3, $z3); |
|
201 | + |
|
202 | + # fe_mul(z3,tmp0,x2); |
|
203 | + $z3 = self::fe_mul($tmp0, $x2); |
|
204 | + |
|
205 | + # fe_mul(z2,z2,tmp1); |
|
206 | + $z2 = self::fe_mul($z2, $tmp1); |
|
207 | + |
|
208 | + # fe_sq(tmp0,tmp1); |
|
209 | + $tmp0 = self::fe_sq($tmp1); |
|
210 | + |
|
211 | + # fe_sq(tmp1,x2); |
|
212 | + $tmp1 = self::fe_sq($x2); |
|
213 | + |
|
214 | + # fe_add(x3,z3,z2); |
|
215 | + $x3 = self::fe_add($z3, $z2); |
|
216 | + |
|
217 | + # fe_sub(z2,z3,z2); |
|
218 | + $z2 = self::fe_sub($z3, $z2); |
|
219 | + |
|
220 | + # fe_mul(x2,tmp1,tmp0); |
|
221 | + $x2 = self::fe_mul($tmp1, $tmp0); |
|
222 | + |
|
223 | + # fe_sub(tmp1,tmp1,tmp0); |
|
224 | + $tmp1 = self::fe_sub($tmp1, $tmp0); |
|
225 | + |
|
226 | + # fe_sq(z2,z2); |
|
227 | + $z2 = self::fe_sq($z2); |
|
228 | + |
|
229 | + # fe_mul121666(z3,tmp1); |
|
230 | + $z3 = self::fe_mul121666($tmp1); |
|
231 | + |
|
232 | + # fe_sq(x3,x3); |
|
233 | + $x3 = self::fe_sq($x3); |
|
234 | + |
|
235 | + # fe_add(tmp0,tmp0,z3); |
|
236 | + $tmp0 = self::fe_add($tmp0, $z3); |
|
237 | + |
|
238 | + # fe_mul(z3,x1,z2); |
|
239 | + $z3 = self::fe_mul($x1, $z2); |
|
240 | + |
|
241 | + # fe_mul(z2,tmp1,tmp0); |
|
242 | + $z2 = self::fe_mul($tmp1, $tmp0); |
|
243 | + } |
|
244 | + |
|
245 | + # fe_cswap(x2,x3,swap); |
|
246 | + self::fe_cswap($x2, $x3, $swap); |
|
247 | + |
|
248 | + # fe_cswap(z2,z3,swap); |
|
249 | + self::fe_cswap($z2, $z3, $swap); |
|
250 | + |
|
251 | + # fe_invert(z2,z2); |
|
252 | + $z2 = self::fe_invert($z2); |
|
253 | + |
|
254 | + # fe_mul(x2,x2,z2); |
|
255 | + $x2 = self::fe_mul($x2, $z2); |
|
256 | + # fe_tobytes(q,x2); |
|
257 | + return self::fe_tobytes($x2); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @internal You should not use this directly from another application |
|
262 | + * |
|
263 | + * @param ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY |
|
264 | + * @param ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ |
|
265 | + * @return ParagonIE_Sodium_Core_Curve25519_Fe |
|
266 | + */ |
|
267 | + public static function edwards_to_montgomery( |
|
268 | + ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY, |
|
269 | + ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ |
|
270 | + ) { |
|
271 | + $tempX = self::fe_add($edwardsZ, $edwardsY); |
|
272 | + $tempZ = self::fe_sub($edwardsZ, $edwardsY); |
|
273 | + $tempZ = self::fe_invert($tempZ); |
|
274 | + return self::fe_mul($tempX, $tempZ); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * @internal You should not use this directly from another application |
|
279 | + * |
|
280 | + * @param string $n |
|
281 | + * @return string |
|
282 | + * @throws TypeError |
|
283 | + */ |
|
284 | + public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
285 | + { |
|
286 | + # for (i = 0;i < 32;++i) e[i] = n[i]; |
|
287 | + $e = '' . $n; |
|
288 | + |
|
289 | + # e[0] &= 248; |
|
290 | + $e[0] = self::intToChr( |
|
291 | + self::chrToInt($e[0]) & 248 |
|
292 | + ); |
|
293 | + |
|
294 | + # e[31] &= 127; |
|
295 | + # e[31] |= 64; |
|
296 | + $e[31] = self::intToChr( |
|
297 | + (self::chrToInt($e[31]) & 127) | 64 |
|
298 | + ); |
|
299 | + |
|
300 | + $A = self::ge_scalarmult_base($e); |
|
301 | + if ( |
|
302 | + !($A->Y instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
303 | + || |
|
304 | + !($A->Z instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
305 | + ) { |
|
306 | + throw new TypeError('Null points encountered'); |
|
307 | + } |
|
308 | + $pk = self::edwards_to_montgomery($A->Y, $A->Z); |
|
309 | + return self::fe_tobytes($pk); |
|
310 | + } |
|
311 | 311 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_X25519', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_X25519', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | $g8 = (int) $g[8]; |
46 | 46 | $g9 = (int) $g[9]; |
47 | 47 | $b = -$b; |
48 | - $x0 = ($f0 ^ $g0) & $b; |
|
49 | - $x1 = ($f1 ^ $g1) & $b; |
|
50 | - $x2 = ($f2 ^ $g2) & $b; |
|
51 | - $x3 = ($f3 ^ $g3) & $b; |
|
52 | - $x4 = ($f4 ^ $g4) & $b; |
|
53 | - $x5 = ($f5 ^ $g5) & $b; |
|
54 | - $x6 = ($f6 ^ $g6) & $b; |
|
55 | - $x7 = ($f7 ^ $g7) & $b; |
|
56 | - $x8 = ($f8 ^ $g8) & $b; |
|
57 | - $x9 = ($f9 ^ $g9) & $b; |
|
48 | + $x0 = ( $f0 ^ $g0 ) & $b; |
|
49 | + $x1 = ( $f1 ^ $g1 ) & $b; |
|
50 | + $x2 = ( $f2 ^ $g2 ) & $b; |
|
51 | + $x3 = ( $f3 ^ $g3 ) & $b; |
|
52 | + $x4 = ( $f4 ^ $g4 ) & $b; |
|
53 | + $x5 = ( $f5 ^ $g5 ) & $b; |
|
54 | + $x6 = ( $f6 ^ $g6 ) & $b; |
|
55 | + $x7 = ( $f7 ^ $g7 ) & $b; |
|
56 | + $x8 = ( $f8 ^ $g8 ) & $b; |
|
57 | + $x9 = ( $f9 ^ $g9 ) & $b; |
|
58 | 58 | $f[0] = $f0 ^ $x0; |
59 | 59 | $f[1] = $f1 ^ $x1; |
60 | 60 | $f[2] = $f2 ^ $x2; |
@@ -83,57 +83,57 @@ discard block |
||
83 | 83 | * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
84 | 84 | * @return ParagonIE_Sodium_Core_Curve25519_Fe |
85 | 85 | */ |
86 | - public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
86 | + public static function fe_mul121666( ParagonIE_Sodium_Core_Curve25519_Fe $f ) |
|
87 | 87 | { |
88 | 88 | $h = array( |
89 | - self::mul($f[0], 121666, 17), |
|
90 | - self::mul($f[1], 121666, 17), |
|
91 | - self::mul($f[2], 121666, 17), |
|
92 | - self::mul($f[3], 121666, 17), |
|
93 | - self::mul($f[4], 121666, 17), |
|
94 | - self::mul($f[5], 121666, 17), |
|
95 | - self::mul($f[6], 121666, 17), |
|
96 | - self::mul($f[7], 121666, 17), |
|
97 | - self::mul($f[8], 121666, 17), |
|
98 | - self::mul($f[9], 121666, 17) |
|
89 | + self::mul( $f[0], 121666, 17 ), |
|
90 | + self::mul( $f[1], 121666, 17 ), |
|
91 | + self::mul( $f[2], 121666, 17 ), |
|
92 | + self::mul( $f[3], 121666, 17 ), |
|
93 | + self::mul( $f[4], 121666, 17 ), |
|
94 | + self::mul( $f[5], 121666, 17 ), |
|
95 | + self::mul( $f[6], 121666, 17 ), |
|
96 | + self::mul( $f[7], 121666, 17 ), |
|
97 | + self::mul( $f[8], 121666, 17 ), |
|
98 | + self::mul( $f[9], 121666, 17 ) |
|
99 | 99 | ); |
100 | 100 | |
101 | - $carry9 = ($h[9] + (1 << 24)) >> 25; |
|
102 | - $h[0] += self::mul($carry9, 19, 5); |
|
101 | + $carry9 = ( $h[9] + ( 1 << 24 ) ) >> 25; |
|
102 | + $h[0] += self::mul( $carry9, 19, 5 ); |
|
103 | 103 | $h[9] -= $carry9 << 25; |
104 | - $carry1 = ($h[1] + (1 << 24)) >> 25; |
|
104 | + $carry1 = ( $h[1] + ( 1 << 24 ) ) >> 25; |
|
105 | 105 | $h[2] += $carry1; |
106 | 106 | $h[1] -= $carry1 << 25; |
107 | - $carry3 = ($h[3] + (1 << 24)) >> 25; |
|
107 | + $carry3 = ( $h[3] + ( 1 << 24 ) ) >> 25; |
|
108 | 108 | $h[4] += $carry3; |
109 | 109 | $h[3] -= $carry3 << 25; |
110 | - $carry5 = ($h[5] + (1 << 24)) >> 25; |
|
110 | + $carry5 = ( $h[5] + ( 1 << 24 ) ) >> 25; |
|
111 | 111 | $h[6] += $carry5; |
112 | 112 | $h[5] -= $carry5 << 25; |
113 | - $carry7 = ($h[7] + (1 << 24)) >> 25; |
|
113 | + $carry7 = ( $h[7] + ( 1 << 24 ) ) >> 25; |
|
114 | 114 | $h[8] += $carry7; |
115 | 115 | $h[7] -= $carry7 << 25; |
116 | 116 | |
117 | - $carry0 = ($h[0] + (1 << 25)) >> 26; |
|
117 | + $carry0 = ( $h[0] + ( 1 << 25 ) ) >> 26; |
|
118 | 118 | $h[1] += $carry0; |
119 | 119 | $h[0] -= $carry0 << 26; |
120 | - $carry2 = ($h[2] + (1 << 25)) >> 26; |
|
120 | + $carry2 = ( $h[2] + ( 1 << 25 ) ) >> 26; |
|
121 | 121 | $h[3] += $carry2; |
122 | 122 | $h[2] -= $carry2 << 26; |
123 | - $carry4 = ($h[4] + (1 << 25)) >> 26; |
|
123 | + $carry4 = ( $h[4] + ( 1 << 25 ) ) >> 26; |
|
124 | 124 | $h[5] += $carry4; |
125 | 125 | $h[4] -= $carry4 << 26; |
126 | - $carry6 = ($h[6] + (1 << 25)) >> 26; |
|
126 | + $carry6 = ( $h[6] + ( 1 << 25 ) ) >> 26; |
|
127 | 127 | $h[7] += $carry6; |
128 | 128 | $h[6] -= $carry6 << 26; |
129 | - $carry8 = ($h[8] + (1 << 25)) >> 26; |
|
129 | + $carry8 = ( $h[8] + ( 1 << 25 ) ) >> 26; |
|
130 | 130 | $h[9] += $carry8; |
131 | 131 | $h[8] -= $carry8 << 26; |
132 | 132 | |
133 | - foreach ($h as $i => $value) { |
|
133 | + foreach ( $h as $i => $value ) { |
|
134 | 134 | $h[$i] = (int) $value; |
135 | 135 | } |
136 | - return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); |
|
136 | + return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( $h ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -145,27 +145,27 @@ discard block |
||
145 | 145 | * @param string $p |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
148 | + public static function crypto_scalarmult_curve25519_ref10( $n, $p ) |
|
149 | 149 | { |
150 | 150 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
151 | 151 | $e = '' . $n; |
152 | 152 | # e[0] &= 248; |
153 | 153 | $e[0] = self::intToChr( |
154 | - self::chrToInt($e[0]) & 248 |
|
154 | + self::chrToInt( $e[0] ) & 248 |
|
155 | 155 | ); |
156 | 156 | # e[31] &= 127; |
157 | 157 | # e[31] |= 64; |
158 | 158 | $e[31] = self::intToChr( |
159 | - (self::chrToInt($e[31]) & 127) | 64 |
|
159 | + ( self::chrToInt( $e[31] ) & 127 ) | 64 |
|
160 | 160 | ); |
161 | 161 | # fe_frombytes(x1,p); |
162 | - $x1 = self::fe_frombytes($p); |
|
162 | + $x1 = self::fe_frombytes( $p ); |
|
163 | 163 | # fe_1(x2); |
164 | 164 | $x2 = self::fe_1(); |
165 | 165 | # fe_0(z2); |
166 | 166 | $z2 = self::fe_0(); |
167 | 167 | # fe_copy(x3,x1); |
168 | - $x3 = self::fe_copy($x1); |
|
168 | + $x3 = self::fe_copy( $x1 ); |
|
169 | 169 | # fe_1(z3); |
170 | 170 | $z3 = self::fe_1(); |
171 | 171 | |
@@ -173,88 +173,88 @@ discard block |
||
173 | 173 | $swap = 0; |
174 | 174 | |
175 | 175 | # for (pos = 254;pos >= 0;--pos) { |
176 | - for ($pos = 254; $pos >= 0; --$pos) { |
|
176 | + for ( $pos = 254; $pos >= 0; --$pos ) { |
|
177 | 177 | # b = e[pos / 8] >> (pos & 7); |
178 | 178 | $b = self::chrToInt( |
179 | - $e[(int) floor($pos / 8)] |
|
180 | - ) >> ($pos & 7); |
|
179 | + $e[(int) floor( $pos / 8 )] |
|
180 | + ) >> ( $pos & 7 ); |
|
181 | 181 | # b &= 1; |
182 | 182 | $b &= 1; |
183 | 183 | # swap ^= b; |
184 | 184 | $swap ^= $b; |
185 | 185 | # fe_cswap(x2,x3,swap); |
186 | - self::fe_cswap($x2, $x3, $swap); |
|
186 | + self::fe_cswap( $x2, $x3, $swap ); |
|
187 | 187 | # fe_cswap(z2,z3,swap); |
188 | - self::fe_cswap($z2, $z3, $swap); |
|
188 | + self::fe_cswap( $z2, $z3, $swap ); |
|
189 | 189 | # swap = b; |
190 | 190 | $swap = $b; |
191 | 191 | # fe_sub(tmp0,x3,z3); |
192 | - $tmp0 = self::fe_sub($x3, $z3); |
|
192 | + $tmp0 = self::fe_sub( $x3, $z3 ); |
|
193 | 193 | # fe_sub(tmp1,x2,z2); |
194 | - $tmp1 = self::fe_sub($x2, $z2); |
|
194 | + $tmp1 = self::fe_sub( $x2, $z2 ); |
|
195 | 195 | |
196 | 196 | # fe_add(x2,x2,z2); |
197 | - $x2 = self::fe_add($x2, $z2); |
|
197 | + $x2 = self::fe_add( $x2, $z2 ); |
|
198 | 198 | |
199 | 199 | # fe_add(z2,x3,z3); |
200 | - $z2 = self::fe_add($x3, $z3); |
|
200 | + $z2 = self::fe_add( $x3, $z3 ); |
|
201 | 201 | |
202 | 202 | # fe_mul(z3,tmp0,x2); |
203 | - $z3 = self::fe_mul($tmp0, $x2); |
|
203 | + $z3 = self::fe_mul( $tmp0, $x2 ); |
|
204 | 204 | |
205 | 205 | # fe_mul(z2,z2,tmp1); |
206 | - $z2 = self::fe_mul($z2, $tmp1); |
|
206 | + $z2 = self::fe_mul( $z2, $tmp1 ); |
|
207 | 207 | |
208 | 208 | # fe_sq(tmp0,tmp1); |
209 | - $tmp0 = self::fe_sq($tmp1); |
|
209 | + $tmp0 = self::fe_sq( $tmp1 ); |
|
210 | 210 | |
211 | 211 | # fe_sq(tmp1,x2); |
212 | - $tmp1 = self::fe_sq($x2); |
|
212 | + $tmp1 = self::fe_sq( $x2 ); |
|
213 | 213 | |
214 | 214 | # fe_add(x3,z3,z2); |
215 | - $x3 = self::fe_add($z3, $z2); |
|
215 | + $x3 = self::fe_add( $z3, $z2 ); |
|
216 | 216 | |
217 | 217 | # fe_sub(z2,z3,z2); |
218 | - $z2 = self::fe_sub($z3, $z2); |
|
218 | + $z2 = self::fe_sub( $z3, $z2 ); |
|
219 | 219 | |
220 | 220 | # fe_mul(x2,tmp1,tmp0); |
221 | - $x2 = self::fe_mul($tmp1, $tmp0); |
|
221 | + $x2 = self::fe_mul( $tmp1, $tmp0 ); |
|
222 | 222 | |
223 | 223 | # fe_sub(tmp1,tmp1,tmp0); |
224 | - $tmp1 = self::fe_sub($tmp1, $tmp0); |
|
224 | + $tmp1 = self::fe_sub( $tmp1, $tmp0 ); |
|
225 | 225 | |
226 | 226 | # fe_sq(z2,z2); |
227 | - $z2 = self::fe_sq($z2); |
|
227 | + $z2 = self::fe_sq( $z2 ); |
|
228 | 228 | |
229 | 229 | # fe_mul121666(z3,tmp1); |
230 | - $z3 = self::fe_mul121666($tmp1); |
|
230 | + $z3 = self::fe_mul121666( $tmp1 ); |
|
231 | 231 | |
232 | 232 | # fe_sq(x3,x3); |
233 | - $x3 = self::fe_sq($x3); |
|
233 | + $x3 = self::fe_sq( $x3 ); |
|
234 | 234 | |
235 | 235 | # fe_add(tmp0,tmp0,z3); |
236 | - $tmp0 = self::fe_add($tmp0, $z3); |
|
236 | + $tmp0 = self::fe_add( $tmp0, $z3 ); |
|
237 | 237 | |
238 | 238 | # fe_mul(z3,x1,z2); |
239 | - $z3 = self::fe_mul($x1, $z2); |
|
239 | + $z3 = self::fe_mul( $x1, $z2 ); |
|
240 | 240 | |
241 | 241 | # fe_mul(z2,tmp1,tmp0); |
242 | - $z2 = self::fe_mul($tmp1, $tmp0); |
|
242 | + $z2 = self::fe_mul( $tmp1, $tmp0 ); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | # fe_cswap(x2,x3,swap); |
246 | - self::fe_cswap($x2, $x3, $swap); |
|
246 | + self::fe_cswap( $x2, $x3, $swap ); |
|
247 | 247 | |
248 | 248 | # fe_cswap(z2,z3,swap); |
249 | - self::fe_cswap($z2, $z3, $swap); |
|
249 | + self::fe_cswap( $z2, $z3, $swap ); |
|
250 | 250 | |
251 | 251 | # fe_invert(z2,z2); |
252 | - $z2 = self::fe_invert($z2); |
|
252 | + $z2 = self::fe_invert( $z2 ); |
|
253 | 253 | |
254 | 254 | # fe_mul(x2,x2,z2); |
255 | - $x2 = self::fe_mul($x2, $z2); |
|
255 | + $x2 = self::fe_mul( $x2, $z2 ); |
|
256 | 256 | # fe_tobytes(q,x2); |
257 | - return self::fe_tobytes($x2); |
|
257 | + return self::fe_tobytes( $x2 ); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY, |
269 | 269 | ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ |
270 | 270 | ) { |
271 | - $tempX = self::fe_add($edwardsZ, $edwardsY); |
|
272 | - $tempZ = self::fe_sub($edwardsZ, $edwardsY); |
|
273 | - $tempZ = self::fe_invert($tempZ); |
|
274 | - return self::fe_mul($tempX, $tempZ); |
|
271 | + $tempX = self::fe_add( $edwardsZ, $edwardsY ); |
|
272 | + $tempZ = self::fe_sub( $edwardsZ, $edwardsY ); |
|
273 | + $tempZ = self::fe_invert( $tempZ ); |
|
274 | + return self::fe_mul( $tempX, $tempZ ); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -281,31 +281,31 @@ discard block |
||
281 | 281 | * @return string |
282 | 282 | * @throws TypeError |
283 | 283 | */ |
284 | - public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
284 | + public static function crypto_scalarmult_curve25519_ref10_base( $n ) |
|
285 | 285 | { |
286 | 286 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
287 | 287 | $e = '' . $n; |
288 | 288 | |
289 | 289 | # e[0] &= 248; |
290 | 290 | $e[0] = self::intToChr( |
291 | - self::chrToInt($e[0]) & 248 |
|
291 | + self::chrToInt( $e[0] ) & 248 |
|
292 | 292 | ); |
293 | 293 | |
294 | 294 | # e[31] &= 127; |
295 | 295 | # e[31] |= 64; |
296 | 296 | $e[31] = self::intToChr( |
297 | - (self::chrToInt($e[31]) & 127) | 64 |
|
297 | + ( self::chrToInt( $e[31] ) & 127 ) | 64 |
|
298 | 298 | ); |
299 | 299 | |
300 | - $A = self::ge_scalarmult_base($e); |
|
300 | + $A = self::ge_scalarmult_base( $e ); |
|
301 | 301 | if ( |
302 | - !($A->Y instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
302 | + ! ( $A->Y instanceof ParagonIE_Sodium_Core_Curve25519_Fe ) |
|
303 | 303 | || |
304 | - !($A->Z instanceof ParagonIE_Sodium_Core_Curve25519_Fe) |
|
304 | + ! ( $A->Z instanceof ParagonIE_Sodium_Core_Curve25519_Fe ) |
|
305 | 305 | ) { |
306 | - throw new TypeError('Null points encountered'); |
|
306 | + throw new TypeError( 'Null points encountered' ); |
|
307 | 307 | } |
308 | - $pk = self::edwards_to_montgomery($A->Y, $A->Z); |
|
309 | - return self::fe_tobytes($pk); |
|
308 | + $pk = self::edwards_to_montgomery( $A->Y, $A->Z ); |
|
309 | + return self::fe_tobytes( $pk ); |
|
310 | 310 | } |
311 | 311 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_X25519 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_X25519 extends ParagonIE_Sodium_Core_Curve25519 |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_X25519 extends ParagonIE_Sodium_Core_Curve25519 { |
|
12 | 11 | /** |
13 | 12 | * Alters the objects passed to this method in place. |
14 | 13 | * |
@@ -83,8 +82,7 @@ discard block |
||
83 | 82 | * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
84 | 83 | * @return ParagonIE_Sodium_Core_Curve25519_Fe |
85 | 84 | */ |
86 | - public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
87 | - { |
|
85 | + public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) { |
|
88 | 86 | $h = array( |
89 | 87 | self::mul($f[0], 121666, 17), |
90 | 88 | self::mul($f[1], 121666, 17), |
@@ -145,8 +143,7 @@ discard block |
||
145 | 143 | * @param string $p |
146 | 144 | * @return string |
147 | 145 | */ |
148 | - public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
149 | - { |
|
146 | + public static function crypto_scalarmult_curve25519_ref10($n, $p) { |
|
150 | 147 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
151 | 148 | $e = '' . $n; |
152 | 149 | # e[0] &= 248; |
@@ -281,8 +278,7 @@ discard block |
||
281 | 278 | * @return string |
282 | 279 | * @throws TypeError |
283 | 280 | */ |
284 | - public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
285 | - { |
|
281 | + public static function crypto_scalarmult_curve25519_ref10_base($n) { |
|
286 | 282 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
287 | 283 | $e = '' . $n; |
288 | 284 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_ChaCha20_IetfCtx', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,29 +9,29 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class ParagonIE_Sodium_Core_ChaCha20_IetfCtx extends ParagonIE_Sodium_Core_ChaCha20_Ctx |
11 | 11 | { |
12 | - /** |
|
13 | - * ParagonIE_Sodium_Core_ChaCha20_IetfCtx constructor. |
|
14 | - * |
|
15 | - * @internal You should not use this directly from another application |
|
16 | - * |
|
17 | - * @param string $key ChaCha20 key. |
|
18 | - * @param string $iv Initialization Vector (a.k.a. nonce). |
|
19 | - * @param string $counter The initial counter value. |
|
20 | - * Defaults to 4 0x00 bytes. |
|
21 | - * @throws InvalidArgumentException |
|
22 | - */ |
|
23 | - public function __construct($key = '', $iv = '', $counter = '') |
|
24 | - { |
|
25 | - if (self::strlen($iv) !== 12) { |
|
26 | - throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.'); |
|
27 | - } |
|
28 | - parent::__construct($key, self::substr($iv, 0, 8), $counter); |
|
12 | + /** |
|
13 | + * ParagonIE_Sodium_Core_ChaCha20_IetfCtx constructor. |
|
14 | + * |
|
15 | + * @internal You should not use this directly from another application |
|
16 | + * |
|
17 | + * @param string $key ChaCha20 key. |
|
18 | + * @param string $iv Initialization Vector (a.k.a. nonce). |
|
19 | + * @param string $counter The initial counter value. |
|
20 | + * Defaults to 4 0x00 bytes. |
|
21 | + * @throws InvalidArgumentException |
|
22 | + */ |
|
23 | + public function __construct($key = '', $iv = '', $counter = '') |
|
24 | + { |
|
25 | + if (self::strlen($iv) !== 12) { |
|
26 | + throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.'); |
|
27 | + } |
|
28 | + parent::__construct($key, self::substr($iv, 0, 8), $counter); |
|
29 | 29 | |
30 | - if (!empty($counter)) { |
|
31 | - $this->container[12] = self::load_4(self::substr($counter, 0, 4)); |
|
32 | - } |
|
33 | - $this->container[13] = self::load_4(self::substr($iv, 0, 4)); |
|
34 | - $this->container[14] = self::load_4(self::substr($iv, 4, 4)); |
|
35 | - $this->container[15] = self::load_4(self::substr($iv, 8, 4)); |
|
36 | - } |
|
30 | + if (!empty($counter)) { |
|
31 | + $this->container[12] = self::load_4(self::substr($counter, 0, 4)); |
|
32 | + } |
|
33 | + $this->container[13] = self::load_4(self::substr($iv, 0, 4)); |
|
34 | + $this->container[14] = self::load_4(self::substr($iv, 4, 4)); |
|
35 | + $this->container[15] = self::load_4(self::substr($iv, 8, 4)); |
|
36 | + } |
|
37 | 37 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_ChaCha20_IetfCtx', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_ChaCha20_IetfCtx', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -20,18 +20,18 @@ discard block |
||
20 | 20 | * Defaults to 4 0x00 bytes. |
21 | 21 | * @throws InvalidArgumentException |
22 | 22 | */ |
23 | - public function __construct($key = '', $iv = '', $counter = '') |
|
23 | + public function __construct( $key = '', $iv = '', $counter = '' ) |
|
24 | 24 | { |
25 | - if (self::strlen($iv) !== 12) { |
|
26 | - throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.'); |
|
25 | + if ( self::strlen( $iv ) !== 12 ) { |
|
26 | + throw new InvalidArgumentException( 'ChaCha20 expects a 96-bit nonce in IETF mode.' ); |
|
27 | 27 | } |
28 | - parent::__construct($key, self::substr($iv, 0, 8), $counter); |
|
28 | + parent::__construct( $key, self::substr( $iv, 0, 8 ), $counter ); |
|
29 | 29 | |
30 | - if (!empty($counter)) { |
|
31 | - $this->container[12] = self::load_4(self::substr($counter, 0, 4)); |
|
30 | + if ( ! empty( $counter ) ) { |
|
31 | + $this->container[12] = self::load_4( self::substr( $counter, 0, 4 ) ); |
|
32 | 32 | } |
33 | - $this->container[13] = self::load_4(self::substr($iv, 0, 4)); |
|
34 | - $this->container[14] = self::load_4(self::substr($iv, 4, 4)); |
|
35 | - $this->container[15] = self::load_4(self::substr($iv, 8, 4)); |
|
33 | + $this->container[13] = self::load_4( self::substr( $iv, 0, 4 ) ); |
|
34 | + $this->container[14] = self::load_4( self::substr( $iv, 4, 4 ) ); |
|
35 | + $this->container[15] = self::load_4( self::substr( $iv, 8, 4 ) ); |
|
36 | 36 | } |
37 | 37 | } |
@@ -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 | * |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * Defaults to 4 0x00 bytes. |
21 | 20 | * @throws InvalidArgumentException |
22 | 21 | */ |
23 | - public function __construct($key = '', $iv = '', $counter = '') |
|
24 | - { |
|
22 | + public function __construct($key = '', $iv = '', $counter = '') { |
|
25 | 23 | if (self::strlen($iv) !== 12) { |
26 | 24 | throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.'); |
27 | 25 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_ChaCha20_Ctx', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,107 +9,107 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess |
11 | 11 | { |
12 | - /** |
|
13 | - * @var SplFixedArray<int, int> |
|
14 | - */ |
|
15 | - protected $container; |
|
12 | + /** |
|
13 | + * @var SplFixedArray<int, int> |
|
14 | + */ |
|
15 | + protected $container; |
|
16 | 16 | |
17 | - /** |
|
18 | - * ParagonIE_Sodium_Core_ChaCha20_Ctx constructor. |
|
19 | - * |
|
20 | - * @internal You should not use this directly from another application |
|
21 | - * |
|
22 | - * @param string $key ChaCha20 key. |
|
23 | - * @param string $iv Initialization Vector (a.k.a. nonce). |
|
24 | - * @param string $counter The initial counter value. |
|
25 | - * Defaults to 8 0x00 bytes. |
|
26 | - * @throws InvalidArgumentException |
|
27 | - */ |
|
28 | - public function __construct($key = '', $iv = '', $counter = '') |
|
29 | - { |
|
30 | - if (self::strlen($key) !== 32) { |
|
31 | - throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.'); |
|
32 | - } |
|
33 | - if (self::strlen($iv) !== 8) { |
|
34 | - throw new InvalidArgumentException('ChaCha20 expects a 64-bit nonce.'); |
|
35 | - } |
|
36 | - $this->container = new SplFixedArray(16); |
|
17 | + /** |
|
18 | + * ParagonIE_Sodium_Core_ChaCha20_Ctx constructor. |
|
19 | + * |
|
20 | + * @internal You should not use this directly from another application |
|
21 | + * |
|
22 | + * @param string $key ChaCha20 key. |
|
23 | + * @param string $iv Initialization Vector (a.k.a. nonce). |
|
24 | + * @param string $counter The initial counter value. |
|
25 | + * Defaults to 8 0x00 bytes. |
|
26 | + * @throws InvalidArgumentException |
|
27 | + */ |
|
28 | + public function __construct($key = '', $iv = '', $counter = '') |
|
29 | + { |
|
30 | + if (self::strlen($key) !== 32) { |
|
31 | + throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.'); |
|
32 | + } |
|
33 | + if (self::strlen($iv) !== 8) { |
|
34 | + throw new InvalidArgumentException('ChaCha20 expects a 64-bit nonce.'); |
|
35 | + } |
|
36 | + $this->container = new SplFixedArray(16); |
|
37 | 37 | |
38 | - /* "expand 32-byte k" as per ChaCha20 spec */ |
|
39 | - $this->container[0] = 0x61707865; |
|
40 | - $this->container[1] = 0x3320646e; |
|
41 | - $this->container[2] = 0x79622d32; |
|
42 | - $this->container[3] = 0x6b206574; |
|
43 | - $this->container[4] = self::load_4(self::substr($key, 0, 4)); |
|
44 | - $this->container[5] = self::load_4(self::substr($key, 4, 4)); |
|
45 | - $this->container[6] = self::load_4(self::substr($key, 8, 4)); |
|
46 | - $this->container[7] = self::load_4(self::substr($key, 12, 4)); |
|
47 | - $this->container[8] = self::load_4(self::substr($key, 16, 4)); |
|
48 | - $this->container[9] = self::load_4(self::substr($key, 20, 4)); |
|
49 | - $this->container[10] = self::load_4(self::substr($key, 24, 4)); |
|
50 | - $this->container[11] = self::load_4(self::substr($key, 28, 4)); |
|
38 | + /* "expand 32-byte k" as per ChaCha20 spec */ |
|
39 | + $this->container[0] = 0x61707865; |
|
40 | + $this->container[1] = 0x3320646e; |
|
41 | + $this->container[2] = 0x79622d32; |
|
42 | + $this->container[3] = 0x6b206574; |
|
43 | + $this->container[4] = self::load_4(self::substr($key, 0, 4)); |
|
44 | + $this->container[5] = self::load_4(self::substr($key, 4, 4)); |
|
45 | + $this->container[6] = self::load_4(self::substr($key, 8, 4)); |
|
46 | + $this->container[7] = self::load_4(self::substr($key, 12, 4)); |
|
47 | + $this->container[8] = self::load_4(self::substr($key, 16, 4)); |
|
48 | + $this->container[9] = self::load_4(self::substr($key, 20, 4)); |
|
49 | + $this->container[10] = self::load_4(self::substr($key, 24, 4)); |
|
50 | + $this->container[11] = self::load_4(self::substr($key, 28, 4)); |
|
51 | 51 | |
52 | - if (empty($counter)) { |
|
53 | - $this->container[12] = 0; |
|
54 | - $this->container[13] = 0; |
|
55 | - } else { |
|
56 | - $this->container[12] = self::load_4(self::substr($counter, 0, 4)); |
|
57 | - $this->container[13] = self::load_4(self::substr($counter, 4, 4)); |
|
58 | - } |
|
59 | - $this->container[14] = self::load_4(self::substr($iv, 0, 4)); |
|
60 | - $this->container[15] = self::load_4(self::substr($iv, 4, 4)); |
|
61 | - } |
|
52 | + if (empty($counter)) { |
|
53 | + $this->container[12] = 0; |
|
54 | + $this->container[13] = 0; |
|
55 | + } else { |
|
56 | + $this->container[12] = self::load_4(self::substr($counter, 0, 4)); |
|
57 | + $this->container[13] = self::load_4(self::substr($counter, 4, 4)); |
|
58 | + } |
|
59 | + $this->container[14] = self::load_4(self::substr($iv, 0, 4)); |
|
60 | + $this->container[15] = self::load_4(self::substr($iv, 4, 4)); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @internal You should not use this directly from another application |
|
65 | - * |
|
66 | - * @param int $offset |
|
67 | - * @param int $value |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function offsetSet($offset, $value) |
|
71 | - { |
|
72 | - if (!is_int($offset)) { |
|
73 | - throw new InvalidArgumentException('Expected an integer'); |
|
74 | - } |
|
75 | - if (!is_int($value)) { |
|
76 | - throw new InvalidArgumentException('Expected an integer'); |
|
77 | - } |
|
78 | - $this->container[$offset] = $value; |
|
79 | - } |
|
63 | + /** |
|
64 | + * @internal You should not use this directly from another application |
|
65 | + * |
|
66 | + * @param int $offset |
|
67 | + * @param int $value |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function offsetSet($offset, $value) |
|
71 | + { |
|
72 | + if (!is_int($offset)) { |
|
73 | + throw new InvalidArgumentException('Expected an integer'); |
|
74 | + } |
|
75 | + if (!is_int($value)) { |
|
76 | + throw new InvalidArgumentException('Expected an integer'); |
|
77 | + } |
|
78 | + $this->container[$offset] = $value; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @internal You should not use this directly from another application |
|
83 | - * |
|
84 | - * @param mixed $offset |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function offsetExists($offset) |
|
88 | - { |
|
89 | - return isset($this->container[$offset]); |
|
90 | - } |
|
81 | + /** |
|
82 | + * @internal You should not use this directly from another application |
|
83 | + * |
|
84 | + * @param mixed $offset |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function offsetExists($offset) |
|
88 | + { |
|
89 | + return isset($this->container[$offset]); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @internal You should not use this directly from another application |
|
94 | - * |
|
95 | - * @param mixed $offset |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public function offsetUnset($offset) |
|
99 | - { |
|
100 | - unset($this->container[$offset]); |
|
101 | - } |
|
92 | + /** |
|
93 | + * @internal You should not use this directly from another application |
|
94 | + * |
|
95 | + * @param mixed $offset |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public function offsetUnset($offset) |
|
99 | + { |
|
100 | + unset($this->container[$offset]); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @internal You should not use this directly from another application |
|
105 | - * |
|
106 | - * @param mixed $offset |
|
107 | - * @return mixed|null |
|
108 | - */ |
|
109 | - public function offsetGet($offset) |
|
110 | - { |
|
111 | - return isset($this->container[$offset]) |
|
112 | - ? $this->container[$offset] |
|
113 | - : null; |
|
114 | - } |
|
103 | + /** |
|
104 | + * @internal You should not use this directly from another application |
|
105 | + * |
|
106 | + * @param mixed $offset |
|
107 | + * @return mixed|null |
|
108 | + */ |
|
109 | + public function offsetGet($offset) |
|
110 | + { |
|
111 | + return isset($this->container[$offset]) |
|
112 | + ? $this->container[$offset] |
|
113 | + : null; |
|
114 | + } |
|
115 | 115 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_ChaCha20_Ctx', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_ChaCha20_Ctx', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -25,39 +25,39 @@ discard block |
||
25 | 25 | * Defaults to 8 0x00 bytes. |
26 | 26 | * @throws InvalidArgumentException |
27 | 27 | */ |
28 | - public function __construct($key = '', $iv = '', $counter = '') |
|
28 | + public function __construct( $key = '', $iv = '', $counter = '' ) |
|
29 | 29 | { |
30 | - if (self::strlen($key) !== 32) { |
|
31 | - throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.'); |
|
30 | + if ( self::strlen( $key ) !== 32 ) { |
|
31 | + throw new InvalidArgumentException( 'ChaCha20 expects a 256-bit key.' ); |
|
32 | 32 | } |
33 | - if (self::strlen($iv) !== 8) { |
|
34 | - throw new InvalidArgumentException('ChaCha20 expects a 64-bit nonce.'); |
|
33 | + if ( self::strlen( $iv ) !== 8 ) { |
|
34 | + throw new InvalidArgumentException( 'ChaCha20 expects a 64-bit nonce.' ); |
|
35 | 35 | } |
36 | - $this->container = new SplFixedArray(16); |
|
36 | + $this->container = new SplFixedArray( 16 ); |
|
37 | 37 | |
38 | 38 | /* "expand 32-byte k" as per ChaCha20 spec */ |
39 | 39 | $this->container[0] = 0x61707865; |
40 | 40 | $this->container[1] = 0x3320646e; |
41 | 41 | $this->container[2] = 0x79622d32; |
42 | 42 | $this->container[3] = 0x6b206574; |
43 | - $this->container[4] = self::load_4(self::substr($key, 0, 4)); |
|
44 | - $this->container[5] = self::load_4(self::substr($key, 4, 4)); |
|
45 | - $this->container[6] = self::load_4(self::substr($key, 8, 4)); |
|
46 | - $this->container[7] = self::load_4(self::substr($key, 12, 4)); |
|
47 | - $this->container[8] = self::load_4(self::substr($key, 16, 4)); |
|
48 | - $this->container[9] = self::load_4(self::substr($key, 20, 4)); |
|
49 | - $this->container[10] = self::load_4(self::substr($key, 24, 4)); |
|
50 | - $this->container[11] = self::load_4(self::substr($key, 28, 4)); |
|
43 | + $this->container[4] = self::load_4( self::substr( $key, 0, 4 ) ); |
|
44 | + $this->container[5] = self::load_4( self::substr( $key, 4, 4 ) ); |
|
45 | + $this->container[6] = self::load_4( self::substr( $key, 8, 4 ) ); |
|
46 | + $this->container[7] = self::load_4( self::substr( $key, 12, 4 ) ); |
|
47 | + $this->container[8] = self::load_4( self::substr( $key, 16, 4 ) ); |
|
48 | + $this->container[9] = self::load_4( self::substr( $key, 20, 4 ) ); |
|
49 | + $this->container[10] = self::load_4( self::substr( $key, 24, 4 ) ); |
|
50 | + $this->container[11] = self::load_4( self::substr( $key, 28, 4 ) ); |
|
51 | 51 | |
52 | - if (empty($counter)) { |
|
52 | + if ( empty( $counter ) ) { |
|
53 | 53 | $this->container[12] = 0; |
54 | 54 | $this->container[13] = 0; |
55 | 55 | } else { |
56 | - $this->container[12] = self::load_4(self::substr($counter, 0, 4)); |
|
57 | - $this->container[13] = self::load_4(self::substr($counter, 4, 4)); |
|
56 | + $this->container[12] = self::load_4( self::substr( $counter, 0, 4 ) ); |
|
57 | + $this->container[13] = self::load_4( self::substr( $counter, 4, 4 ) ); |
|
58 | 58 | } |
59 | - $this->container[14] = self::load_4(self::substr($iv, 0, 4)); |
|
60 | - $this->container[15] = self::load_4(self::substr($iv, 4, 4)); |
|
59 | + $this->container[14] = self::load_4( self::substr( $iv, 0, 4 ) ); |
|
60 | + $this->container[15] = self::load_4( self::substr( $iv, 4, 4 ) ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | * @param int $value |
68 | 68 | * @return void |
69 | 69 | */ |
70 | - public function offsetSet($offset, $value) |
|
70 | + public function offsetSet( $offset, $value ) |
|
71 | 71 | { |
72 | - if (!is_int($offset)) { |
|
73 | - throw new InvalidArgumentException('Expected an integer'); |
|
72 | + if ( ! is_int( $offset ) ) { |
|
73 | + throw new InvalidArgumentException( 'Expected an integer' ); |
|
74 | 74 | } |
75 | - if (!is_int($value)) { |
|
76 | - throw new InvalidArgumentException('Expected an integer'); |
|
75 | + if ( ! is_int( $value ) ) { |
|
76 | + throw new InvalidArgumentException( 'Expected an integer' ); |
|
77 | 77 | } |
78 | 78 | $this->container[$offset] = $value; |
79 | 79 | } |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @param mixed $offset |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | - public function offsetExists($offset) |
|
87 | + public function offsetExists( $offset ) |
|
88 | 88 | { |
89 | - return isset($this->container[$offset]); |
|
89 | + return isset( $this->container[$offset] ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param mixed $offset |
96 | 96 | * @return void |
97 | 97 | */ |
98 | - public function offsetUnset($offset) |
|
98 | + public function offsetUnset( $offset ) |
|
99 | 99 | { |
100 | - unset($this->container[$offset]); |
|
100 | + unset( $this->container[$offset] ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param mixed $offset |
107 | 107 | * @return mixed|null |
108 | 108 | */ |
109 | - public function offsetGet($offset) |
|
109 | + public function offsetGet( $offset ) |
|
110 | 110 | { |
111 | - return isset($this->container[$offset]) |
|
111 | + return isset( $this->container[$offset] ) |
|
112 | 112 | ? $this->container[$offset] |
113 | 113 | : null; |
114 | 114 | } |
@@ -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<int, int> |
14 | 13 | */ |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | * Defaults to 8 0x00 bytes. |
26 | 25 | * @throws InvalidArgumentException |
27 | 26 | */ |
28 | - public function __construct($key = '', $iv = '', $counter = '') |
|
29 | - { |
|
27 | + public function __construct($key = '', $iv = '', $counter = '') { |
|
30 | 28 | if (self::strlen($key) !== 32) { |
31 | 29 | throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.'); |
32 | 30 | } |
@@ -67,8 +65,7 @@ discard block |
||
67 | 65 | * @param int $value |
68 | 66 | * @return void |
69 | 67 | */ |
70 | - public function offsetSet($offset, $value) |
|
71 | - { |
|
68 | + public function offsetSet($offset, $value) { |
|
72 | 69 | if (!is_int($offset)) { |
73 | 70 | throw new InvalidArgumentException('Expected an integer'); |
74 | 71 | } |
@@ -84,8 +81,7 @@ discard block |
||
84 | 81 | * @param mixed $offset |
85 | 82 | * @return bool |
86 | 83 | */ |
87 | - public function offsetExists($offset) |
|
88 | - { |
|
84 | + public function offsetExists($offset) { |
|
89 | 85 | return isset($this->container[$offset]); |
90 | 86 | } |
91 | 87 | |
@@ -95,8 +91,7 @@ discard block |
||
95 | 91 | * @param mixed $offset |
96 | 92 | * @return void |
97 | 93 | */ |
98 | - public function offsetUnset($offset) |
|
99 | - { |
|
94 | + public function offsetUnset($offset) { |
|
100 | 95 | unset($this->container[$offset]); |
101 | 96 | } |
102 | 97 | |
@@ -106,8 +101,7 @@ discard block |
||
106 | 101 | * @param mixed $offset |
107 | 102 | * @return mixed|null |
108 | 103 | */ |
109 | - public function offsetGet($offset) |
|
110 | - { |
|
104 | + public function offsetGet($offset) { |
|
111 | 105 | return isset($this->container[$offset]) |
112 | 106 | ? $this->container[$offset] |
113 | 107 | : null; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (class_exists('ParagonIE_Sodium_Core_HChaCha20', false)) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,98 +9,98 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class ParagonIE_Sodium_Core_HChaCha20 extends ParagonIE_Sodium_Core_ChaCha20 |
11 | 11 | { |
12 | - /** |
|
13 | - * @param string $in |
|
14 | - * @param string $key |
|
15 | - * @param string|null $c |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public static function hChaCha20($in = '', $key = '', $c = null) |
|
19 | - { |
|
20 | - $ctx = array(); |
|
12 | + /** |
|
13 | + * @param string $in |
|
14 | + * @param string $key |
|
15 | + * @param string|null $c |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public static function hChaCha20($in = '', $key = '', $c = null) |
|
19 | + { |
|
20 | + $ctx = array(); |
|
21 | 21 | |
22 | - if ($c === null) { |
|
23 | - $ctx[0] = 0x61707865; |
|
24 | - $ctx[1] = 0x3320646e; |
|
25 | - $ctx[2] = 0x79622d32; |
|
26 | - $ctx[3] = 0x6b206574; |
|
27 | - } else { |
|
28 | - $ctx[0] = self::load_4(self::substr($c, 0, 4)); |
|
29 | - $ctx[1] = self::load_4(self::substr($c, 4, 4)); |
|
30 | - $ctx[2] = self::load_4(self::substr($c, 8, 4)); |
|
31 | - $ctx[3] = self::load_4(self::substr($c, 12, 4)); |
|
32 | - } |
|
33 | - $ctx[4] = self::load_4(self::substr($key, 0, 4)); |
|
34 | - $ctx[5] = self::load_4(self::substr($key, 4, 4)); |
|
35 | - $ctx[6] = self::load_4(self::substr($key, 8, 4)); |
|
36 | - $ctx[7] = self::load_4(self::substr($key, 12, 4)); |
|
37 | - $ctx[8] = self::load_4(self::substr($key, 16, 4)); |
|
38 | - $ctx[9] = self::load_4(self::substr($key, 20, 4)); |
|
39 | - $ctx[10] = self::load_4(self::substr($key, 24, 4)); |
|
40 | - $ctx[11] = self::load_4(self::substr($key, 28, 4)); |
|
41 | - $ctx[12] = self::load_4(self::substr($in, 0, 4)); |
|
42 | - $ctx[13] = self::load_4(self::substr($in, 4, 4)); |
|
43 | - $ctx[14] = self::load_4(self::substr($in, 8, 4)); |
|
44 | - $ctx[15] = self::load_4(self::substr($in, 12, 4)); |
|
45 | - return self::hChaCha20Bytes($ctx); |
|
46 | - } |
|
22 | + if ($c === null) { |
|
23 | + $ctx[0] = 0x61707865; |
|
24 | + $ctx[1] = 0x3320646e; |
|
25 | + $ctx[2] = 0x79622d32; |
|
26 | + $ctx[3] = 0x6b206574; |
|
27 | + } else { |
|
28 | + $ctx[0] = self::load_4(self::substr($c, 0, 4)); |
|
29 | + $ctx[1] = self::load_4(self::substr($c, 4, 4)); |
|
30 | + $ctx[2] = self::load_4(self::substr($c, 8, 4)); |
|
31 | + $ctx[3] = self::load_4(self::substr($c, 12, 4)); |
|
32 | + } |
|
33 | + $ctx[4] = self::load_4(self::substr($key, 0, 4)); |
|
34 | + $ctx[5] = self::load_4(self::substr($key, 4, 4)); |
|
35 | + $ctx[6] = self::load_4(self::substr($key, 8, 4)); |
|
36 | + $ctx[7] = self::load_4(self::substr($key, 12, 4)); |
|
37 | + $ctx[8] = self::load_4(self::substr($key, 16, 4)); |
|
38 | + $ctx[9] = self::load_4(self::substr($key, 20, 4)); |
|
39 | + $ctx[10] = self::load_4(self::substr($key, 24, 4)); |
|
40 | + $ctx[11] = self::load_4(self::substr($key, 28, 4)); |
|
41 | + $ctx[12] = self::load_4(self::substr($in, 0, 4)); |
|
42 | + $ctx[13] = self::load_4(self::substr($in, 4, 4)); |
|
43 | + $ctx[14] = self::load_4(self::substr($in, 8, 4)); |
|
44 | + $ctx[15] = self::load_4(self::substr($in, 12, 4)); |
|
45 | + return self::hChaCha20Bytes($ctx); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param array $ctx |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - protected static function hChaCha20Bytes(array $ctx) |
|
53 | - { |
|
54 | - $x0 = (int) $ctx[0]; |
|
55 | - $x1 = (int) $ctx[1]; |
|
56 | - $x2 = (int) $ctx[2]; |
|
57 | - $x3 = (int) $ctx[3]; |
|
58 | - $x4 = (int) $ctx[4]; |
|
59 | - $x5 = (int) $ctx[5]; |
|
60 | - $x6 = (int) $ctx[6]; |
|
61 | - $x7 = (int) $ctx[7]; |
|
62 | - $x8 = (int) $ctx[8]; |
|
63 | - $x9 = (int) $ctx[9]; |
|
64 | - $x10 = (int) $ctx[10]; |
|
65 | - $x11 = (int) $ctx[11]; |
|
66 | - $x12 = (int) $ctx[12]; |
|
67 | - $x13 = (int) $ctx[13]; |
|
68 | - $x14 = (int) $ctx[14]; |
|
69 | - $x15 = (int) $ctx[15]; |
|
48 | + /** |
|
49 | + * @param array $ctx |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + protected static function hChaCha20Bytes(array $ctx) |
|
53 | + { |
|
54 | + $x0 = (int) $ctx[0]; |
|
55 | + $x1 = (int) $ctx[1]; |
|
56 | + $x2 = (int) $ctx[2]; |
|
57 | + $x3 = (int) $ctx[3]; |
|
58 | + $x4 = (int) $ctx[4]; |
|
59 | + $x5 = (int) $ctx[5]; |
|
60 | + $x6 = (int) $ctx[6]; |
|
61 | + $x7 = (int) $ctx[7]; |
|
62 | + $x8 = (int) $ctx[8]; |
|
63 | + $x9 = (int) $ctx[9]; |
|
64 | + $x10 = (int) $ctx[10]; |
|
65 | + $x11 = (int) $ctx[11]; |
|
66 | + $x12 = (int) $ctx[12]; |
|
67 | + $x13 = (int) $ctx[13]; |
|
68 | + $x14 = (int) $ctx[14]; |
|
69 | + $x15 = (int) $ctx[15]; |
|
70 | 70 | |
71 | - for ($i = 0; $i < 10; ++$i) { |
|
72 | - # QUARTERROUND( x0, x4, x8, x12) |
|
73 | - list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
71 | + for ($i = 0; $i < 10; ++$i) { |
|
72 | + # QUARTERROUND( x0, x4, x8, x12) |
|
73 | + list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
74 | 74 | |
75 | - # QUARTERROUND( x1, x5, x9, x13) |
|
76 | - list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
75 | + # QUARTERROUND( x1, x5, x9, x13) |
|
76 | + list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
77 | 77 | |
78 | - # QUARTERROUND( x2, x6, x10, x14) |
|
79 | - list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
78 | + # QUARTERROUND( x2, x6, x10, x14) |
|
79 | + list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
80 | 80 | |
81 | - # QUARTERROUND( x3, x7, x11, x15) |
|
82 | - list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
81 | + # QUARTERROUND( x3, x7, x11, x15) |
|
82 | + list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
83 | 83 | |
84 | - # QUARTERROUND( x0, x5, x10, x15) |
|
85 | - list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
84 | + # QUARTERROUND( x0, x5, x10, x15) |
|
85 | + list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
86 | 86 | |
87 | - # QUARTERROUND( x1, x6, x11, x12) |
|
88 | - list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
87 | + # QUARTERROUND( x1, x6, x11, x12) |
|
88 | + list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
89 | 89 | |
90 | - # QUARTERROUND( x2, x7, x8, x13) |
|
91 | - list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
90 | + # QUARTERROUND( x2, x7, x8, x13) |
|
91 | + list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
92 | 92 | |
93 | - # QUARTERROUND( x3, x4, x9, x14) |
|
94 | - list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
95 | - } |
|
93 | + # QUARTERROUND( x3, x4, x9, x14) |
|
94 | + list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
95 | + } |
|
96 | 96 | |
97 | - return self::store32_le((int) ($x0 & 0xffffffff)) . |
|
98 | - self::store32_le((int) ($x1 & 0xffffffff)) . |
|
99 | - self::store32_le((int) ($x2 & 0xffffffff)) . |
|
100 | - self::store32_le((int) ($x3 & 0xffffffff)) . |
|
101 | - self::store32_le((int) ($x12 & 0xffffffff)) . |
|
102 | - self::store32_le((int) ($x13 & 0xffffffff)) . |
|
103 | - self::store32_le((int) ($x14 & 0xffffffff)) . |
|
104 | - self::store32_le((int) ($x15 & 0xffffffff)); |
|
105 | - } |
|
97 | + return self::store32_le((int) ($x0 & 0xffffffff)) . |
|
98 | + self::store32_le((int) ($x1 & 0xffffffff)) . |
|
99 | + self::store32_le((int) ($x2 & 0xffffffff)) . |
|
100 | + self::store32_le((int) ($x3 & 0xffffffff)) . |
|
101 | + self::store32_le((int) ($x12 & 0xffffffff)) . |
|
102 | + self::store32_le((int) ($x13 & 0xffffffff)) . |
|
103 | + self::store32_le((int) ($x14 & 0xffffffff)) . |
|
104 | + self::store32_le((int) ($x15 & 0xffffffff)); |
|
105 | + } |
|
106 | 106 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists('ParagonIE_Sodium_Core_HChaCha20', false)) { |
|
3 | +if ( class_exists( 'ParagonIE_Sodium_Core_HChaCha20', false ) ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -15,41 +15,41 @@ discard block |
||
15 | 15 | * @param string|null $c |
16 | 16 | * @return string |
17 | 17 | */ |
18 | - public static function hChaCha20($in = '', $key = '', $c = null) |
|
18 | + public static function hChaCha20( $in = '', $key = '', $c = null ) |
|
19 | 19 | { |
20 | 20 | $ctx = array(); |
21 | 21 | |
22 | - if ($c === null) { |
|
22 | + if ( $c === null ) { |
|
23 | 23 | $ctx[0] = 0x61707865; |
24 | 24 | $ctx[1] = 0x3320646e; |
25 | 25 | $ctx[2] = 0x79622d32; |
26 | 26 | $ctx[3] = 0x6b206574; |
27 | 27 | } else { |
28 | - $ctx[0] = self::load_4(self::substr($c, 0, 4)); |
|
29 | - $ctx[1] = self::load_4(self::substr($c, 4, 4)); |
|
30 | - $ctx[2] = self::load_4(self::substr($c, 8, 4)); |
|
31 | - $ctx[3] = self::load_4(self::substr($c, 12, 4)); |
|
28 | + $ctx[0] = self::load_4( self::substr( $c, 0, 4 ) ); |
|
29 | + $ctx[1] = self::load_4( self::substr( $c, 4, 4 ) ); |
|
30 | + $ctx[2] = self::load_4( self::substr( $c, 8, 4 ) ); |
|
31 | + $ctx[3] = self::load_4( self::substr( $c, 12, 4 ) ); |
|
32 | 32 | } |
33 | - $ctx[4] = self::load_4(self::substr($key, 0, 4)); |
|
34 | - $ctx[5] = self::load_4(self::substr($key, 4, 4)); |
|
35 | - $ctx[6] = self::load_4(self::substr($key, 8, 4)); |
|
36 | - $ctx[7] = self::load_4(self::substr($key, 12, 4)); |
|
37 | - $ctx[8] = self::load_4(self::substr($key, 16, 4)); |
|
38 | - $ctx[9] = self::load_4(self::substr($key, 20, 4)); |
|
39 | - $ctx[10] = self::load_4(self::substr($key, 24, 4)); |
|
40 | - $ctx[11] = self::load_4(self::substr($key, 28, 4)); |
|
41 | - $ctx[12] = self::load_4(self::substr($in, 0, 4)); |
|
42 | - $ctx[13] = self::load_4(self::substr($in, 4, 4)); |
|
43 | - $ctx[14] = self::load_4(self::substr($in, 8, 4)); |
|
44 | - $ctx[15] = self::load_4(self::substr($in, 12, 4)); |
|
45 | - return self::hChaCha20Bytes($ctx); |
|
33 | + $ctx[4] = self::load_4( self::substr( $key, 0, 4 ) ); |
|
34 | + $ctx[5] = self::load_4( self::substr( $key, 4, 4 ) ); |
|
35 | + $ctx[6] = self::load_4( self::substr( $key, 8, 4 ) ); |
|
36 | + $ctx[7] = self::load_4( self::substr( $key, 12, 4 ) ); |
|
37 | + $ctx[8] = self::load_4( self::substr( $key, 16, 4 ) ); |
|
38 | + $ctx[9] = self::load_4( self::substr( $key, 20, 4 ) ); |
|
39 | + $ctx[10] = self::load_4( self::substr( $key, 24, 4 ) ); |
|
40 | + $ctx[11] = self::load_4( self::substr( $key, 28, 4 ) ); |
|
41 | + $ctx[12] = self::load_4( self::substr( $in, 0, 4 ) ); |
|
42 | + $ctx[13] = self::load_4( self::substr( $in, 4, 4 ) ); |
|
43 | + $ctx[14] = self::load_4( self::substr( $in, 8, 4 ) ); |
|
44 | + $ctx[15] = self::load_4( self::substr( $in, 12, 4 ) ); |
|
45 | + return self::hChaCha20Bytes( $ctx ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @param array $ctx |
50 | 50 | * @return string |
51 | 51 | */ |
52 | - protected static function hChaCha20Bytes(array $ctx) |
|
52 | + protected static function hChaCha20Bytes( array $ctx ) |
|
53 | 53 | { |
54 | 54 | $x0 = (int) $ctx[0]; |
55 | 55 | $x1 = (int) $ctx[1]; |
@@ -68,39 +68,39 @@ discard block |
||
68 | 68 | $x14 = (int) $ctx[14]; |
69 | 69 | $x15 = (int) $ctx[15]; |
70 | 70 | |
71 | - for ($i = 0; $i < 10; ++$i) { |
|
71 | + for ( $i = 0; $i < 10; ++$i ) { |
|
72 | 72 | # QUARTERROUND( x0, x4, x8, x12) |
73 | - list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12); |
|
73 | + list( $x0, $x4, $x8, $x12 ) = self::quarterRound( $x0, $x4, $x8, $x12 ); |
|
74 | 74 | |
75 | 75 | # QUARTERROUND( x1, x5, x9, x13) |
76 | - list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13); |
|
76 | + list( $x1, $x5, $x9, $x13 ) = self::quarterRound( $x1, $x5, $x9, $x13 ); |
|
77 | 77 | |
78 | 78 | # QUARTERROUND( x2, x6, x10, x14) |
79 | - list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14); |
|
79 | + list( $x2, $x6, $x10, $x14 ) = self::quarterRound( $x2, $x6, $x10, $x14 ); |
|
80 | 80 | |
81 | 81 | # QUARTERROUND( x3, x7, x11, x15) |
82 | - list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15); |
|
82 | + list( $x3, $x7, $x11, $x15 ) = self::quarterRound( $x3, $x7, $x11, $x15 ); |
|
83 | 83 | |
84 | 84 | # QUARTERROUND( x0, x5, x10, x15) |
85 | - list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15); |
|
85 | + list( $x0, $x5, $x10, $x15 ) = self::quarterRound( $x0, $x5, $x10, $x15 ); |
|
86 | 86 | |
87 | 87 | # QUARTERROUND( x1, x6, x11, x12) |
88 | - list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12); |
|
88 | + list( $x1, $x6, $x11, $x12 ) = self::quarterRound( $x1, $x6, $x11, $x12 ); |
|
89 | 89 | |
90 | 90 | # QUARTERROUND( x2, x7, x8, x13) |
91 | - list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13); |
|
91 | + list( $x2, $x7, $x8, $x13 ) = self::quarterRound( $x2, $x7, $x8, $x13 ); |
|
92 | 92 | |
93 | 93 | # QUARTERROUND( x3, x4, x9, x14) |
94 | - list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14); |
|
94 | + list( $x3, $x4, $x9, $x14 ) = self::quarterRound( $x3, $x4, $x9, $x14 ); |
|
95 | 95 | } |
96 | 96 | |
97 | - return self::store32_le((int) ($x0 & 0xffffffff)) . |
|
98 | - self::store32_le((int) ($x1 & 0xffffffff)) . |
|
99 | - self::store32_le((int) ($x2 & 0xffffffff)) . |
|
100 | - self::store32_le((int) ($x3 & 0xffffffff)) . |
|
101 | - self::store32_le((int) ($x12 & 0xffffffff)) . |
|
102 | - self::store32_le((int) ($x13 & 0xffffffff)) . |
|
103 | - self::store32_le((int) ($x14 & 0xffffffff)) . |
|
104 | - self::store32_le((int) ($x15 & 0xffffffff)); |
|
97 | + return self::store32_le( (int) ( $x0 & 0xffffffff ) ) . |
|
98 | + self::store32_le( (int) ( $x1 & 0xffffffff ) ) . |
|
99 | + self::store32_le( (int) ( $x2 & 0xffffffff ) ) . |
|
100 | + self::store32_le( (int) ( $x3 & 0xffffffff ) ) . |
|
101 | + self::store32_le( (int) ( $x12 & 0xffffffff ) ) . |
|
102 | + self::store32_le( (int) ( $x13 & 0xffffffff ) ) . |
|
103 | + self::store32_le( (int) ( $x14 & 0xffffffff ) ) . |
|
104 | + self::store32_le( (int) ( $x15 & 0xffffffff ) ); |
|
105 | 105 | } |
106 | 106 | } |
@@ -7,16 +7,14 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_HChaCha20 |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_HChaCha20 extends ParagonIE_Sodium_Core_ChaCha20 |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_HChaCha20 extends ParagonIE_Sodium_Core_ChaCha20 { |
|
12 | 11 | /** |
13 | 12 | * @param string $in |
14 | 13 | * @param string $key |
15 | 14 | * @param string|null $c |
16 | 15 | * @return string |
17 | 16 | */ |
18 | - public static function hChaCha20($in = '', $key = '', $c = null) |
|
19 | - { |
|
17 | + public static function hChaCha20($in = '', $key = '', $c = null) { |
|
20 | 18 | $ctx = array(); |
21 | 19 | |
22 | 20 | if ($c === null) { |
@@ -49,8 +47,7 @@ discard block |
||
49 | 47 | * @param array $ctx |
50 | 48 | * @return string |
51 | 49 | */ |
52 | - protected static function hChaCha20Bytes(array $ctx) |
|
53 | - { |
|
50 | + protected static function hChaCha20Bytes(array $ctx) { |
|
54 | 51 | $x0 = (int) $ctx[0]; |
55 | 52 | $x1 = (int) $ctx[1]; |
56 | 53 | $x2 = (int) $ctx[2]; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (PHP_VERSION_ID < 50300) { |
4 | - return; |
|
4 | + return; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /* |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | * $x = Compat::crypto_aead_xchacha20poly1305_encrypt(...$args); |
20 | 20 | */ |
21 | 21 | spl_autoload_register(function ($class) { |
22 | - if ($class[0] === '\\') { |
|
23 | - $class = substr($class, 1); |
|
24 | - } |
|
25 | - $namespace = 'ParagonIE\\Sodium'; |
|
26 | - // Does the class use the namespace prefix? |
|
27 | - $len = strlen($namespace); |
|
28 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
29 | - // no, move to the next registered autoloader |
|
30 | - return false; |
|
31 | - } |
|
22 | + if ($class[0] === '\\') { |
|
23 | + $class = substr($class, 1); |
|
24 | + } |
|
25 | + $namespace = 'ParagonIE\\Sodium'; |
|
26 | + // Does the class use the namespace prefix? |
|
27 | + $len = strlen($namespace); |
|
28 | + if (strncmp($namespace, $class, $len) !== 0) { |
|
29 | + // no, move to the next registered autoloader |
|
30 | + return false; |
|
31 | + } |
|
32 | 32 | |
33 | - // Get the relative class name |
|
34 | - $relative_class = substr($class, $len); |
|
33 | + // Get the relative class name |
|
34 | + $relative_class = substr($class, $len); |
|
35 | 35 | |
36 | - // Replace the namespace prefix with the base directory, replace namespace |
|
37 | - // separators with directory separators in the relative class name, append |
|
38 | - // with .php |
|
39 | - $file = dirname(__DIR__) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; |
|
40 | - // if the file exists, require it |
|
41 | - if (file_exists($file)) { |
|
42 | - require_once $file; |
|
43 | - return true; |
|
44 | - } |
|
45 | - return false; |
|
36 | + // Replace the namespace prefix with the base directory, replace namespace |
|
37 | + // separators with directory separators in the relative class name, append |
|
38 | + // with .php |
|
39 | + $file = dirname(__DIR__) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; |
|
40 | + // if the file exists, require it |
|
41 | + if (file_exists($file)) { |
|
42 | + require_once $file; |
|
43 | + return true; |
|
44 | + } |
|
45 | + return false; |
|
46 | 46 | }); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (PHP_VERSION_ID < 50300) { |
|
3 | +if ( PHP_VERSION_ID < 50300 ) { |
|
4 | 4 | return; |
5 | 5 | } |
6 | 6 | |
@@ -18,27 +18,27 @@ discard block |
||
18 | 18 | * |
19 | 19 | * $x = Compat::crypto_aead_xchacha20poly1305_encrypt(...$args); |
20 | 20 | */ |
21 | -spl_autoload_register(function ($class) { |
|
22 | - if ($class[0] === '\\') { |
|
23 | - $class = substr($class, 1); |
|
21 | +spl_autoload_register( function ( $class ) { |
|
22 | + if ( $class[0] === '\\' ) { |
|
23 | + $class = substr( $class, 1 ); |
|
24 | 24 | } |
25 | 25 | $namespace = 'ParagonIE\\Sodium'; |
26 | 26 | // Does the class use the namespace prefix? |
27 | - $len = strlen($namespace); |
|
28 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
27 | + $len = strlen( $namespace ); |
|
28 | + if ( strncmp( $namespace, $class, $len ) !== 0 ) { |
|
29 | 29 | // no, move to the next registered autoloader |
30 | 30 | return false; |
31 | 31 | } |
32 | 32 | |
33 | 33 | // Get the relative class name |
34 | - $relative_class = substr($class, $len); |
|
34 | + $relative_class = substr( $class, $len ); |
|
35 | 35 | |
36 | 36 | // Replace the namespace prefix with the base directory, replace namespace |
37 | 37 | // separators with directory separators in the relative class name, append |
38 | 38 | // with .php |
39 | - $file = dirname(__DIR__) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; |
|
39 | + $file = dirname( __DIR__ ) . '/namespaced/' . str_replace( '\\', '/', $relative_class ) . '.php'; |
|
40 | 40 | // if the file exists, require it |
41 | - if (file_exists($file)) { |
|
41 | + if ( file_exists( $file ) ) { |
|
42 | 42 | require_once $file; |
43 | 43 | return true; |
44 | 44 | } |
@@ -1,48 +1,48 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!is_callable('sodiumCompatAutoloader')) { |
4 | - /** |
|
5 | - * Sodium_Compat autoloader. |
|
6 | - * |
|
7 | - * @param string $class Class name to be autoloaded. |
|
8 | - * |
|
9 | - * @return bool Stop autoloading? |
|
10 | - */ |
|
11 | - function sodiumCompatAutoader($class) |
|
12 | - { |
|
13 | - $namespace = 'ParagonIE_Sodium_'; |
|
14 | - // Does the class use the namespace prefix? |
|
15 | - $len = strlen($namespace); |
|
16 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
17 | - // no, move to the next registered autoloader |
|
18 | - return false; |
|
19 | - } |
|
4 | + /** |
|
5 | + * Sodium_Compat autoloader. |
|
6 | + * |
|
7 | + * @param string $class Class name to be autoloaded. |
|
8 | + * |
|
9 | + * @return bool Stop autoloading? |
|
10 | + */ |
|
11 | + function sodiumCompatAutoader($class) |
|
12 | + { |
|
13 | + $namespace = 'ParagonIE_Sodium_'; |
|
14 | + // Does the class use the namespace prefix? |
|
15 | + $len = strlen($namespace); |
|
16 | + if (strncmp($namespace, $class, $len) !== 0) { |
|
17 | + // no, move to the next registered autoloader |
|
18 | + return false; |
|
19 | + } |
|
20 | 20 | |
21 | - // Get the relative class name |
|
22 | - $relative_class = substr($class, $len); |
|
21 | + // Get the relative class name |
|
22 | + $relative_class = substr($class, $len); |
|
23 | 23 | |
24 | - // Replace the namespace prefix with the base directory, replace namespace |
|
25 | - // separators with directory separators in the relative class name, append |
|
26 | - // with .php |
|
27 | - $file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
|
28 | - // if the file exists, require it |
|
29 | - if (file_exists($file)) { |
|
30 | - require_once $file; |
|
31 | - return true; |
|
32 | - } |
|
33 | - return false; |
|
34 | - } |
|
24 | + // Replace the namespace prefix with the base directory, replace namespace |
|
25 | + // separators with directory separators in the relative class name, append |
|
26 | + // with .php |
|
27 | + $file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
|
28 | + // if the file exists, require it |
|
29 | + if (file_exists($file)) { |
|
30 | + require_once $file; |
|
31 | + return true; |
|
32 | + } |
|
33 | + return false; |
|
34 | + } |
|
35 | 35 | |
36 | - // Now that we have an autoloader, let's register it! |
|
37 | - spl_autoload_register('sodiumCompatAutoader'); |
|
36 | + // Now that we have an autoloader, let's register it! |
|
37 | + spl_autoload_register('sodiumCompatAutoader'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | if (PHP_VERSION_ID >= 50300) { |
41 | - // Namespaces didn't exist before 5.3.0, so don't even try to use this |
|
42 | - // unless PHP >= 5.3.0 |
|
43 | - require_once dirname(__FILE__) . '/lib/namespaced.php'; |
|
44 | - require_once dirname(__FILE__) . '/lib/sodium_compat.php'; |
|
41 | + // Namespaces didn't exist before 5.3.0, so don't even try to use this |
|
42 | + // unless PHP >= 5.3.0 |
|
43 | + require_once dirname(__FILE__) . '/lib/namespaced.php'; |
|
44 | + require_once dirname(__FILE__) . '/lib/sodium_compat.php'; |
|
45 | 45 | } |
46 | 46 | if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) { |
47 | - require_once dirname(__FILE__) . '/lib/php72compat.php'; |
|
47 | + require_once dirname(__FILE__) . '/lib/php72compat.php'; |
|
48 | 48 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!is_callable('sodiumCompatAutoloader')) { |
|
3 | +if ( ! is_callable( 'sodiumCompatAutoloader' ) ) { |
|
4 | 4 | /** |
5 | 5 | * Sodium_Compat autoloader. |
6 | 6 | * |
@@ -8,25 +8,25 @@ discard block |
||
8 | 8 | * |
9 | 9 | * @return bool Stop autoloading? |
10 | 10 | */ |
11 | - function sodiumCompatAutoader($class) |
|
11 | + function sodiumCompatAutoader( $class ) |
|
12 | 12 | { |
13 | 13 | $namespace = 'ParagonIE_Sodium_'; |
14 | 14 | // Does the class use the namespace prefix? |
15 | - $len = strlen($namespace); |
|
16 | - if (strncmp($namespace, $class, $len) !== 0) { |
|
15 | + $len = strlen( $namespace ); |
|
16 | + if ( strncmp( $namespace, $class, $len ) !== 0 ) { |
|
17 | 17 | // no, move to the next registered autoloader |
18 | 18 | return false; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Get the relative class name |
22 | - $relative_class = substr($class, $len); |
|
22 | + $relative_class = substr( $class, $len ); |
|
23 | 23 | |
24 | 24 | // Replace the namespace prefix with the base directory, replace namespace |
25 | 25 | // separators with directory separators in the relative class name, append |
26 | 26 | // with .php |
27 | - $file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
|
27 | + $file = dirname( __FILE__ ) . '/src/' . str_replace( '_', '/', $relative_class ) . '.php'; |
|
28 | 28 | // if the file exists, require it |
29 | - if (file_exists($file)) { |
|
29 | + if ( file_exists( $file ) ) { |
|
30 | 30 | require_once $file; |
31 | 31 | return true; |
32 | 32 | } |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | // Now that we have an autoloader, let's register it! |
37 | - spl_autoload_register('sodiumCompatAutoader'); |
|
37 | + spl_autoload_register( 'sodiumCompatAutoader' ); |
|
38 | 38 | } |
39 | 39 | |
40 | -if (PHP_VERSION_ID >= 50300) { |
|
40 | +if ( PHP_VERSION_ID >= 50300 ) { |
|
41 | 41 | // Namespaces didn't exist before 5.3.0, so don't even try to use this |
42 | 42 | // unless PHP >= 5.3.0 |
43 | - require_once dirname(__FILE__) . '/lib/namespaced.php'; |
|
44 | - require_once dirname(__FILE__) . '/lib/sodium_compat.php'; |
|
43 | + require_once dirname( __FILE__ ) . '/lib/namespaced.php'; |
|
44 | + require_once dirname( __FILE__ ) . '/lib/sodium_compat.php'; |
|
45 | 45 | } |
46 | -if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) { |
|
47 | - require_once dirname(__FILE__) . '/lib/php72compat.php'; |
|
46 | +if ( PHP_VERSION_ID < 70200 || ! extension_loaded( 'sodium' ) ) { |
|
47 | + require_once dirname( __FILE__ ) . '/lib/php72compat.php'; |
|
48 | 48 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @return bool Stop autoloading? |
10 | 10 | */ |
11 | - function sodiumCompatAutoader($class) |
|
12 | - { |
|
11 | + function sodiumCompatAutoader($class) { |
|
13 | 12 | $namespace = 'ParagonIE_Sodium_'; |
14 | 13 | // Does the class use the namespace prefix? |
15 | 14 | $len = strlen($namespace); |