equal
deleted
inserted
replaced
48 * @return SplFixedArray |
48 * @return SplFixedArray |
49 * @psalm-suppress MixedAssignment |
49 * @psalm-suppress MixedAssignment |
50 */ |
50 */ |
51 public static function new64($high, $low) |
51 public static function new64($high, $low) |
52 { |
52 { |
|
53 if (PHP_INT_SIZE === 4) { |
|
54 throw new SodiumException("Error, use 32-bit"); |
|
55 } |
53 $i64 = new SplFixedArray(2); |
56 $i64 = new SplFixedArray(2); |
54 $i64[0] = $high & 0xffffffff; |
57 $i64[0] = $high & 0xffffffff; |
55 $i64[1] = $low & 0xffffffff; |
58 $i64[1] = $low & 0xffffffff; |
56 return $i64; |
59 return $i64; |
57 } |
60 } |
84 * @psalm-suppress MixedAssignment |
87 * @psalm-suppress MixedAssignment |
85 * @psalm-suppress MixedOperand |
88 * @psalm-suppress MixedOperand |
86 */ |
89 */ |
87 protected static function add64($x, $y) |
90 protected static function add64($x, $y) |
88 { |
91 { |
|
92 if (PHP_INT_SIZE === 4) { |
|
93 throw new SodiumException("Error, use 32-bit"); |
|
94 } |
89 $l = ($x[1] + $y[1]) & 0xffffffff; |
95 $l = ($x[1] + $y[1]) & 0xffffffff; |
90 return self::new64( |
96 return self::new64( |
91 (int) ($x[0] + $y[0] + ( |
97 (int) ($x[0] + $y[0] + ( |
92 ($l < $x[1]) ? 1 : 0 |
98 ($l < $x[1]) ? 1 : 0 |
93 )), |
99 )), |
117 * @throws SodiumException |
123 * @throws SodiumException |
118 * @throws TypeError |
124 * @throws TypeError |
119 */ |
125 */ |
120 protected static function xor64(SplFixedArray $x, SplFixedArray $y) |
126 protected static function xor64(SplFixedArray $x, SplFixedArray $y) |
121 { |
127 { |
|
128 if (PHP_INT_SIZE === 4) { |
|
129 throw new SodiumException("Error, use 32-bit"); |
|
130 } |
122 if (!is_numeric($x[0])) { |
131 if (!is_numeric($x[0])) { |
123 throw new SodiumException('x[0] is not an integer'); |
132 throw new SodiumException('x[0] is not an integer'); |
124 } |
133 } |
125 if (!is_numeric($x[1])) { |
134 if (!is_numeric($x[1])) { |
126 throw new SodiumException('x[1] is not an integer'); |
135 throw new SodiumException('x[1] is not an integer'); |
145 * @return SplFixedArray |
154 * @return SplFixedArray |
146 * @psalm-suppress MixedAssignment |
155 * @psalm-suppress MixedAssignment |
147 */ |
156 */ |
148 public static function rotr64($x, $c) |
157 public static function rotr64($x, $c) |
149 { |
158 { |
|
159 if (PHP_INT_SIZE === 4) { |
|
160 throw new SodiumException("Error, use 32-bit"); |
|
161 } |
150 if ($c >= 64) { |
162 if ($c >= 64) { |
151 $c %= 64; |
163 $c %= 64; |
152 } |
164 } |
153 if ($c >= 32) { |
165 if ($c >= 32) { |
154 /** @var int $tmp */ |
166 /** @var int $tmp */ |
162 } |
174 } |
163 |
175 |
164 $l0 = 0; |
176 $l0 = 0; |
165 $c = 64 - $c; |
177 $c = 64 - $c; |
166 |
178 |
|
179 /** @var int $c */ |
167 if ($c < 32) { |
180 if ($c < 32) { |
168 /** @var int $h0 */ |
|
169 $h0 = ((int) ($x[0]) << $c) | ( |
181 $h0 = ((int) ($x[0]) << $c) | ( |
170 ( |
182 ( |
171 (int) ($x[1]) & ((1 << $c) - 1) |
183 (int) ($x[1]) & ((1 << $c) - 1) |
172 << |
184 << |
173 (32 - $c) |
185 (32 - $c) |
174 ) >> (32 - $c) |
186 ) >> (32 - $c) |
175 ); |
187 ); |
176 /** @var int $l0 */ |
|
177 $l0 = (int) ($x[1]) << $c; |
188 $l0 = (int) ($x[1]) << $c; |
178 } else { |
189 } else { |
179 /** @var int $h0 */ |
|
180 $h0 = (int) ($x[1]) << ($c - 32); |
190 $h0 = (int) ($x[1]) << ($c - 32); |
181 } |
191 } |
182 |
192 |
183 $h1 = 0; |
193 $h1 = 0; |
184 $c1 = 64 - $c; |
194 $c1 = 64 - $c; |
185 |
195 |
186 if ($c1 < 32) { |
196 if ($c1 < 32) { |
187 /** @var int $h1 */ |
|
188 $h1 = (int) ($x[0]) >> $c1; |
197 $h1 = (int) ($x[0]) >> $c1; |
189 /** @var int $l1 */ |
|
190 $l1 = ((int) ($x[1]) >> $c1) | ((int) ($x[0]) & ((1 << $c1) - 1)) << (32 - $c1); |
198 $l1 = ((int) ($x[1]) >> $c1) | ((int) ($x[0]) & ((1 << $c1) - 1)) << (32 - $c1); |
191 } else { |
199 } else { |
192 /** @var int $l1 */ |
|
193 $l1 = (int) ($x[0]) >> ($c1 - 32); |
200 $l1 = (int) ($x[0]) >> ($c1 - 32); |
194 } |
201 } |
195 |
202 |
196 return self::new64($h0 | $h1, $l0 | $l1); |
203 return self::new64($h0 | $h1, $l0 | $l1); |
197 } |
204 } |