Changeset 45355 for branches/5.2
- Timestamp:
- 05/17/2019 05:19:21 PM (5 years ago)
- Location:
- branches/5.2
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.2
-
branches/5.2/src/wp-includes/sodium_compat/LICENSE
r44953 r45355 2 2 * ISC License 3 3 * 4 * Copyright (c) 2016-201 94 * Copyright (c) 2016-2018 5 5 * Paragon Initiative Enterprises <security at paragonie dot com> 6 6 * 7 * Copyright (c) 2013-201 97 * Copyright (c) 2013-2018 8 8 * Frank Denis <j at pureftpd dot org> 9 9 * -
branches/5.2/src/wp-includes/sodium_compat/composer.json
r44953 r45355 51 51 }, 52 52 "require": { 53 "php": "^5.2.4|^5.3|^5.4|^5.5|^5.6|^7 ",53 "php": "^5.2.4|^5.3|^5.4|^5.5|^5.6|^7|^8", 54 54 "paragonie/random_compat": ">=1" 55 55 }, -
branches/5.2/src/wp-includes/sodium_compat/lib/php72compat.php
r44953 r45355 108 108 * @param string $nonce 109 109 * @param string $key 110 * @return string 110 * @return string|bool 111 111 */ 112 112 function sodium_crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) … … 154 154 * @param string $nonce 155 155 * @param string $key 156 * @return string 156 * @return string|bool 157 157 */ 158 158 function sodium_crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) … … 200 200 * @param string $nonce 201 201 * @param string $key 202 * @return string 202 * @return string|bool 203 203 */ 204 204 function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) … … 246 246 * @param string $nonce 247 247 * @param string $key 248 * @return string 248 * @return string|bool 249 249 */ 250 250 function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) 251 251 { 252 252 try { 253 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key );253 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key, true); 254 254 } catch (Error $ex) { 255 255 return false; … … 272 272 function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) 273 273 { 274 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key );274 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key, true); 275 275 } 276 276 } … … 953 953 /** 954 954 * @see ParagonIE_Sodium_Compat::increment() 955 * @param &string $string955 * @param string $string 956 956 * @return void 957 957 * @throws SodiumException … … 1010 1010 /** 1011 1011 * @see ParagonIE_Sodium_Compat::memzero() 1012 * @param string &$str1012 * @param string $str 1013 1013 * @return void 1014 1014 * @throws SodiumException -
branches/5.2/src/wp-includes/sodium_compat/lib/sodium_compat.php
r44953 r45355 46 46 * @param string $key 47 47 * @return string|bool 48 * @throws \SodiumException49 * @throws \TypeError50 48 */ 51 49 function crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) … … 53 51 try { 54 52 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); 55 } catch ( Error $ex) {56 return false; 57 } catch ( Exception $ex) {53 } catch (\TypeError $ex) { 54 return false; 55 } catch (\SodiumException $ex) { 58 56 return false; 59 57 } … … 94 92 * @param string $key 95 93 * @return string|bool 96 * @throws \SodiumException97 * @throws \TypeError98 94 */ 99 95 function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) … … 101 97 try { 102 98 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key); 103 } catch ( Error $ex) {104 return false; 105 } catch ( Exception $ex) {99 } catch (\TypeError $ex) { 100 return false; 101 } catch (\SodiumException $ex) { 106 102 return false; 107 103 } … … 132 128 * @param string $key 133 129 * @return string|bool 134 * @throws \SodiumException135 * @throws \TypeError136 130 */ 137 131 function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) … … 139 133 try { 140 134 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key); 141 } catch ( Error $ex) {142 return false; 143 } catch ( Exception $ex) {135 } catch (\TypeError $ex) { 136 return false; 137 } catch (\SodiumException $ex) { 144 138 return false; 145 139 } … … 239 233 * @param string $kp 240 234 * @return string|bool 241 * @throws \SodiumException242 * @throws \TypeError243 235 */ 244 236 function crypto_box_open($message, $nonce, $kp) … … 246 238 try { 247 239 return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp); 248 } catch ( Error $ex) {249 return false; 250 } catch ( Exception $ex) {240 } catch (\TypeError $ex) { 241 return false; 242 } catch (\SodiumException $ex) { 251 243 return false; 252 244 } … … 299 291 * @param string $kp 300 292 * @return string|bool 301 * @throws \TypeError302 293 */ 303 294 function crypto_box_seal_open($message, $kp) … … 305 296 try { 306 297 return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp); 307 } catch (\ Error $ex) {308 return false; 309 } catch (\ Exception $ex) {298 } catch (\TypeError $ex) { 299 return false; 300 } catch (\SodiumException $ex) { 310 301 return false; 311 302 } … … 544 535 * @param string $key 545 536 * @return string|bool 546 * @throws \SodiumException547 * @throws \TypeError548 537 */ 549 538 function crypto_secretbox_open($message, $nonce, $key) … … 551 540 try { 552 541 return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key); 553 } catch ( Error $ex) {554 return false; 555 } catch ( Exception $ex) {542 } catch (\TypeError $ex) { 543 return false; 544 } catch (\SodiumException $ex) { 556 545 return false; 557 546 } … … 623 612 try { 624 613 return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk); 625 } catch (\ Error $ex) {626 return false; 627 } catch (\ Exception $ex) {614 } catch (\TypeError $ex) { 615 return false; 616 } catch (\SodiumException $ex) { 628 617 return false; 629 618 } … … 811 800 * @param int $upperLimit 812 801 * @return int 813 * @throws \ Exception802 * @throws \SodiumException 814 803 * @throws \Error 815 804 */ -
branches/5.2/src/wp-includes/sodium_compat/namespaced/Core/Salsa20.php
r44953 r45355 2 2 namespace ParagonIE\Sodium\Core; 3 3 4 class S ipHashextends \ParagonIE_Sodium_Core_Salsa204 class Salsa20 extends \ParagonIE_Sodium_Core_Salsa20 5 5 { 6 6 -
branches/5.2/src/wp-includes/sodium_compat/namespaced/Core/Xsalsa20.php
r44953 r45355 2 2 namespace ParagonIE\Sodium\Core; 3 3 4 class Xsalsa20 extends \ParagonIE_Sodium_Core_X salsa204 class Xsalsa20 extends \ParagonIE_Sodium_Core_XSalsa20 5 5 { 6 6 -
branches/5.2/src/wp-includes/sodium_compat/src/Compat.php
r44953 r45355 145 145 * @param string $left The left operand; must be a string 146 146 * @param string $right The right operand; must be a string 147 * @return int < 0 if the left operand is less than the right148 * = 0 if both strings are equal149 * > 0 if the right operand is less than the left147 * @return int If < 0 if the left operand is less than the right 148 * If = 0 if both strings are equal 149 * If > 0 if the right operand is less than the left 150 150 * @throws SodiumException 151 151 * @throws TypeError … … 670 670 * IETF mode uses a 96-bit random nonce with a 32-bit counter. 671 671 * 672 * @param string $ciphertext Encrypted message (with Poly1305 MAC appended) 673 * @param string $assocData Authenticated Associated Data (unencrypted) 674 * @param string $nonce Number to be used only Once; must be 8 bytes 675 * @param string $key Encryption key 676 * 677 * @return string The original plaintext message 672 * @param string $ciphertext Encrypted message (with Poly1305 MAC appended) 673 * @param string $assocData Authenticated Associated Data (unencrypted) 674 * @param string $nonce Number to be used only Once; must be 8 bytes 675 * @param string $key Encryption key 676 * @param bool $dontFallback Don't fallback to ext/sodium 677 * 678 * @return string|bool The original plaintext message 678 679 * @throws SodiumException 679 680 * @throws TypeError … … 684 685 $assocData = '', 685 686 $nonce = '', 686 $key = '' 687 $key = '', 688 $dontFallback = false 687 689 ) { 688 690 /* Type checks: */ … … 701 703 if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES) { 702 704 throw new SodiumException('Message must be at least CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES long'); 705 } 706 if (self::useNewSodiumAPI() && !$dontFallback) { 707 if (is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) { 708 return sodium_crypto_aead_xchacha20poly1305_ietf_decrypt( 709 $ciphertext, 710 $assocData, 711 $nonce, 712 $key 713 ); 714 } 703 715 } 704 716 … … 728 740 * IETF mode uses a 96-bit random nonce with a 32-bit counter. 729 741 * 730 * @param string $plaintext Message to be encrypted 731 * @param string $assocData Authenticated Associated Data (unencrypted) 732 * @param string $nonce Number to be used only Once; must be 8 bytes 733 * @param string $key Encryption key 742 * @param string $plaintext Message to be encrypted 743 * @param string $assocData Authenticated Associated Data (unencrypted) 744 * @param string $nonce Number to be used only Once; must be 8 bytes 745 * @param string $key Encryption key 746 * @param bool $dontFallback Don't fallback to ext/sodium 734 747 * 735 748 * @return string Ciphertext with a 16-byte Poly1305 message … … 743 756 $assocData = '', 744 757 $nonce = '', 745 $key = '' 758 $key = '', 759 $dontFallback = false 746 760 ) { 747 761 /* Type checks: */ … … 757 771 if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES) { 758 772 throw new SodiumException('Key must be CRYPTO_AEAD_XCHACHA20POLY1305_KEYBYTES long'); 773 } 774 if (self::useNewSodiumAPI() && !$dontFallback) { 775 if (is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) { 776 return sodium_crypto_aead_xchacha20poly1305_ietf_encrypt( 777 $plaintext, 778 $assocData, 779 $nonce, 780 $key 781 ); 782 } 759 783 } 760 784 … … 1280 1304 * Get the final BLAKE2b hash output for a given context. 1281 1305 * 1282 * @param string &$ctx BLAKE2 hashing context. Generated by crypto_generichash_init(). 1283 * @param int $length Hash output size. 1284 * @return string Final BLAKE2b hash. 1285 * @throws SodiumException 1286 * @throws TypeError 1287 * @psalm-suppress MixedArgument 1306 * @param string $ctx BLAKE2 hashing context. Generated by crypto_generichash_init(). 1307 * @param int $length Hash output size. 1308 * @return string Final BLAKE2b hash. 1309 * @throws SodiumException 1310 * @throws TypeError 1311 * @psalm-suppress MixedArgument 1312 * @psalm-suppress ReferenceConstraintViolation 1288 1313 */ 1289 1314 public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GENERICHASH_BYTES) … … 1358 1383 * Update a BLAKE2b hashing context with additional data. 1359 1384 * 1360 * @param string &$ctx BLAKE2 hashing context. Generated by crypto_generichash_init(). 1361 * $ctx is passed by reference and gets updated in-place. 1385 * @param string $ctx BLAKE2 hashing context. Generated by crypto_generichash_init(). 1386 * $ctx is passed by reference and gets updated in-place. 1387 * @param-out string $ctx 1362 1388 * @param string $message The message to append to the existing hash state. 1363 1389 * @return void … … 1365 1391 * @throws TypeError 1366 1392 * @psalm-suppress MixedArgument 1393 * @psalm-suppress ReferenceConstraintViolation 1367 1394 */ 1368 1395 public static function crypto_generichash_update(&$ctx, $message) … … 2611 2638 * 2612 2639 * @param string|null $var 2640 * @param-out string|null $var 2613 2641 * 2614 2642 * @return void … … 2623 2651 2624 2652 if (self::useNewSodiumAPI()) { 2653 /** @psalm-suppress MixedArgument */ 2625 2654 sodium_memzero($var); 2626 2655 return; … … 2727 2756 2728 2757 /** 2758 * Runtime testing method for 32-bit platforms. 2759 * 2760 * Usage: If runtime_speed_test() returns FALSE, then our 32-bit 2761 * implementation is to slow to use safely without risking timeouts. 2762 * If this happens, install sodium from PECL to get acceptable 2763 * performance. 2764 * 2765 * @param int $iterations Number of multiplications to attempt 2766 * @param int $maxTimeout Milliseconds 2767 * @return bool TRUE if we're fast enough, FALSE is not 2768 * @throws SodiumException 2769 */ 2770 public static function runtime_speed_test($iterations, $maxTimeout) 2771 { 2772 if (self::polyfill_is_fast()) { 2773 return true; 2774 } 2775 /** @var float $end */ 2776 $end = 0.0; 2777 /** @var float $start */ 2778 $start = microtime(true); 2779 /** @var ParagonIE_Sodium_Core32_Int64 $a */ 2780 $a = ParagonIE_Sodium_Core32_Int64::fromInt(random_int(3, 1 << 16)); 2781 for ($i = 0; $i < $iterations; ++$i) { 2782 /** @var ParagonIE_Sodium_Core32_Int64 $b */ 2783 $b = ParagonIE_Sodium_Core32_Int64::fromInt(random_int(3, 1 << 16)); 2784 $a->mulInt64($b); 2785 } 2786 /** @var float $end */ 2787 $end = microtime(true); 2788 /** @var int $diff */ 2789 $diff = (int) ceil(($end - $start) * 1000); 2790 return $diff < $maxTimeout; 2791 } 2792 2793 /** 2729 2794 * This emulates libsodium's version_string() function, except ours is 2730 2795 * prefixed with 'polyfill-'. -
branches/5.2/src/wp-includes/sodium_compat/src/Core/BLAKE2b.php
r44953 r45355 257 257 return; 258 258 } 259 /** @psalm-suppress MixedOperand */ 259 260 $u[$uIdx] >>= 8; 260 261 } … … 643 644 * @internal You should not use this directly from another application 644 645 * 645 * @param SplFixedArray [SplFixedArray]$ctx646 * @param SplFixedArray $ctx 646 647 * @return string 647 648 * @throws TypeError -
branches/5.2/src/wp-includes/sodium_compat/src/Core/ChaCha20/Ctx.php
r44953 r45355 84 84 * @internal You should not use this directly from another application 85 85 * 86 * @param mixed$offset86 * @param int $offset 87 87 * @return bool 88 * @psalm-suppress MixedArrayOffset89 88 */ 90 89 public function offsetExists($offset) … … 96 95 * @internal You should not use this directly from another application 97 96 * 98 * @param mixed$offset97 * @param int $offset 99 98 * @return void 100 99 * @psalm-suppress MixedArrayOffset … … 108 107 * @internal You should not use this directly from another application 109 108 * 110 * @param mixed$offset109 * @param int $offset 111 110 * @return mixed|null 112 111 * @psalm-suppress MixedArrayOffset -
branches/5.2/src/wp-includes/sodium_compat/src/Core/Curve25519/Fe.php
r44953 r45355 13 13 { 14 14 /** 15 * @var array 15 * @var array<int, int> 16 16 */ 17 17 protected $container = array(); … … 25 25 * @internal You should not use this directly from another application 26 26 * 27 * @param array $array27 * @param array<int, int> $array 28 28 * @param bool $save_indexes 29 29 * @return self … … 38 38 } 39 39 $array = array_values($array); 40 /** @var array<int, int> $keys */ 40 41 41 42 $obj = new ParagonIE_Sodium_Core_Curve25519_Fe(); … … 55 56 * @internal You should not use this directly from another application 56 57 * 57 * @param mixed$offset58 * @param mixed$value58 * @param int|null $offset 59 * @param int $value 59 60 * @return void 60 61 * @psalm-suppress MixedArrayOffset … … 75 76 * @internal You should not use this directly from another application 76 77 * 77 * @param mixed$offset78 * @param int $offset 78 79 * @return bool 79 80 * @psalm-suppress MixedArrayOffset … … 87 88 * @internal You should not use this directly from another application 88 89 * 89 * @param mixed$offset90 * @param int $offset 90 91 * @return void 91 92 * @psalm-suppress MixedArrayOffset … … 99 100 * @internal You should not use this directly from another application 100 101 * 101 * @param mixed$offset102 * @return mixed|null102 * @param int $offset 103 * @return int 103 104 * @psalm-suppress MixedArrayOffset 104 105 */ 105 106 public function offsetGet($offset) 106 107 { 107 return isset($this->container[$offset]) 108 ? $this->container[$offset] 109 : null; 108 if (!isset($this->container[$offset])) { 109 $this->container[$offset] = 0; 110 } 111 return (int) ($this->container[$offset]); 110 112 } 111 113 -
branches/5.2/src/wp-includes/sodium_compat/src/Core/Util.php
r44953 r45355 818 818 $sub = (string) substr($str, $start, $length); 819 819 } 820 if ( isset($sub)) {820 if ($sub !== '') { 821 821 return $sub; 822 822 } -
branches/5.2/src/wp-includes/sodium_compat/src/Core32/BLAKE2b.php
r44953 r45355 575 575 * @internal You should not use this directly from another application 576 576 * 577 * @param SplFixedArray [SplFixedArray]$ctx577 * @param SplFixedArray $ctx 578 578 * @return string 579 579 * @throws TypeError -
branches/5.2/src/wp-includes/sodium_compat/src/Core32/ChaCha20/Ctx.php
r44953 r45355 90 90 * @internal You should not use this directly from another application 91 91 * 92 * @param mixed$offset92 * @param int $offset 93 93 * @return bool 94 94 * @psalm-suppress MixedArrayOffset … … 102 102 * @internal You should not use this directly from another application 103 103 * 104 * @param mixed$offset104 * @param int $offset 105 105 * @return void 106 106 * @psalm-suppress MixedArrayOffset … … 114 114 * @internal You should not use this directly from another application 115 115 * 116 * @param mixed$offset116 * @param int $offset 117 117 * @return mixed|null 118 118 * @psalm-suppress MixedArrayOffset -
branches/5.2/src/wp-includes/sodium_compat/src/Core32/Int32.php
r44953 r45355 152 152 153 153 /** 154 * @param array<int, int> $a 155 * @param array<int, int> $b 156 * @param int $baseLog2 157 * @return array<int, int> 158 */ 159 public function multiplyLong(array $a, array $b, $baseLog2 = 16) 160 { 161 $a_l = count($a); 162 $b_l = count($b); 163 /** @var array<int, int> $r */ 164 $r = array_fill(0, $a_l + $b_l + 1, 0); 165 $base = 1 << $baseLog2; 166 for ($i = 0; $i < $a_l; ++$i) { 167 $a_i = $a[$i]; 168 for ($j = 0; $j < $a_l; ++$j) { 169 $b_j = $b[$j]; 170 $product = ($a_i * $b_j) + $r[$i + $j]; 171 $carry = ($product >> $baseLog2 & 0xffff); 172 $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff; 173 $r[$i + $j + 1] += $carry; 174 } 175 } 176 return array_slice($r, 0, 5); 177 } 178 179 /** 180 * @param int $int 181 * @return ParagonIE_Sodium_Core32_Int32 182 */ 183 public function mulIntFast($int) 184 { 185 // Handle negative numbers 186 $aNeg = ($this->limbs[0] >> 15) & 1; 187 $bNeg = ($int >> 31) & 1; 188 $a = array_reverse($this->limbs); 189 $b = array( 190 $int & 0xffff, 191 ($int >> 16) & 0xffff 192 ); 193 if ($aNeg) { 194 for ($i = 0; $i < 2; ++$i) { 195 $a[$i] = ($a[$i] ^ 0xffff) & 0xffff; 196 } 197 ++$a[0]; 198 } 199 if ($bNeg) { 200 for ($i = 0; $i < 2; ++$i) { 201 $b[$i] = ($b[$i] ^ 0xffff) & 0xffff; 202 } 203 ++$b[0]; 204 } 205 // Multiply 206 $res = $this->multiplyLong($a, $b); 207 208 // Re-apply negation to results 209 if ($aNeg !== $bNeg) { 210 for ($i = 0; $i < 2; ++$i) { 211 $res[$i] = (0xffff ^ $res[$i]) & 0xffff; 212 } 213 // Handle integer overflow 214 $c = 1; 215 for ($i = 0; $i < 2; ++$i) { 216 $res[$i] += $c; 217 $c = $res[$i] >> 16; 218 $res[$i] &= 0xffff; 219 } 220 } 221 222 // Return our values 223 $return = new ParagonIE_Sodium_Core32_Int32(); 224 $return->limbs = array( 225 $res[1] & 0xffff, 226 $res[0] & 0xffff 227 ); 228 if (count($res) > 2) { 229 $return->overflow = $res[2] & 0xffff; 230 } 231 $return->unsignedInt = $this->unsignedInt; 232 return $return; 233 } 234 235 /** 236 * @param ParagonIE_Sodium_Core32_Int32 $right 237 * @return ParagonIE_Sodium_Core32_Int32 238 */ 239 public function mulInt32Fast(ParagonIE_Sodium_Core32_Int32 $right) 240 { 241 $aNeg = ($this->limbs[0] >> 15) & 1; 242 $bNeg = ($right->limbs[0] >> 15) & 1; 243 244 $a = array_reverse($this->limbs); 245 $b = array_reverse($right->limbs); 246 if ($aNeg) { 247 for ($i = 0; $i < 2; ++$i) { 248 $a[$i] = ($a[$i] ^ 0xffff) & 0xffff; 249 } 250 ++$a[0]; 251 } 252 if ($bNeg) { 253 for ($i = 0; $i < 2; ++$i) { 254 $b[$i] = ($b[$i] ^ 0xffff) & 0xffff; 255 } 256 ++$b[0]; 257 } 258 $res = $this->multiplyLong($a, $b); 259 if ($aNeg !== $bNeg) { 260 if ($aNeg !== $bNeg) { 261 for ($i = 0; $i < 2; ++$i) { 262 $res[$i] = ($res[$i] ^ 0xffff) & 0xffff; 263 } 264 $c = 1; 265 for ($i = 0; $i < 2; ++$i) { 266 $res[$i] += $c; 267 $c = $res[$i] >> 16; 268 $res[$i] &= 0xffff; 269 } 270 } 271 } 272 $return = new ParagonIE_Sodium_Core32_Int32(); 273 $return->limbs = array( 274 $res[1] & 0xffff, 275 $res[0] & 0xffff 276 ); 277 if (count($res) > 2) { 278 $return->overflow = $res[2]; 279 } 280 return $return; 281 } 282 283 /** 154 284 * @param int $int 155 285 * @param int $size … … 162 292 ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1); 163 293 ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2); 294 if (ParagonIE_Sodium_Compat::$fastMult) { 295 return $this->mulIntFast((int) $int); 296 } 164 297 /** @var int $int */ 165 298 $int = (int) $int; … … 219 352 { 220 353 ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2); 354 if (ParagonIE_Sodium_Compat::$fastMult) { 355 return $this->mulInt32Fast($int); 356 } 221 357 if (!$size) { 222 358 $size = 31; … … 492 628 return $this->shiftLeft(-$c); 493 629 } else { 494 if ( is_null($c)) {630 if (!is_int($c)) { 495 631 throw new TypeError(); 496 632 } -
branches/5.2/src/wp-includes/sodium_compat/src/Core32/Int64.php
r44953 r45355 206 206 public function mulInt($int = 0, $size = 0) 207 207 { 208 if (ParagonIE_Sodium_Compat::$fastMult) { 209 return $this->mulIntFast($int); 210 } 208 211 ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1); 209 212 ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2); … … 269 272 270 273 $int >>= 1; 271 $return->limbs[0] = $ret0;272 $return->limbs[1] = $ret1;273 $return->limbs[2] = $ret2;274 $return->limbs[3] = $ret3;275 }274 } 275 $return->limbs[0] = $ret0; 276 $return->limbs[1] = $ret1; 277 $return->limbs[2] = $ret2; 278 $return->limbs[3] = $ret3; 276 279 return $return; 277 280 } … … 319 322 320 323 /** 324 * @param array<int, int> $a 325 * @param array<int, int> $b 326 * @param int $baseLog2 327 * @return array<int, int> 328 */ 329 public function multiplyLong(array $a, array $b, $baseLog2 = 16) 330 { 331 $a_l = count($a); 332 $b_l = count($b); 333 /** @var array<int, int> $r */ 334 $r = array_fill(0, $a_l + $b_l + 1, 0); 335 $base = 1 << $baseLog2; 336 for ($i = 0; $i < $a_l; ++$i) { 337 $a_i = $a[$i]; 338 for ($j = 0; $j < $a_l; ++$j) { 339 $b_j = $b[$j]; 340 $product = ($a_i * $b_j) + $r[$i + $j]; 341 $carry = ($product >> $baseLog2 & 0xffff); 342 $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff; 343 $r[$i + $j + 1] += $carry; 344 } 345 } 346 return array_slice($r, 0, 5); 347 } 348 349 /** 350 * @param int $int 351 * @return ParagonIE_Sodium_Core32_Int64 352 */ 353 public function mulIntFast($int) 354 { 355 // Handle negative numbers 356 $aNeg = ($this->limbs[0] >> 15) & 1; 357 $bNeg = ($int >> 31) & 1; 358 $a = array_reverse($this->limbs); 359 $b = array( 360 $int & 0xffff, 361 ($int >> 16) & 0xffff, 362 -$bNeg & 0xffff, 363 -$bNeg & 0xffff 364 ); 365 if ($aNeg) { 366 for ($i = 0; $i < 4; ++$i) { 367 $a[$i] = ($a[$i] ^ 0xffff) & 0xffff; 368 } 369 ++$a[0]; 370 } 371 if ($bNeg) { 372 for ($i = 0; $i < 4; ++$i) { 373 $b[$i] = ($b[$i] ^ 0xffff) & 0xffff; 374 } 375 ++$b[0]; 376 } 377 // Multiply 378 $res = $this->multiplyLong($a, $b); 379 380 // Re-apply negation to results 381 if ($aNeg !== $bNeg) { 382 for ($i = 0; $i < 4; ++$i) { 383 $res[$i] = (0xffff ^ $res[$i]) & 0xffff; 384 } 385 // Handle integer overflow 386 $c = 1; 387 for ($i = 0; $i < 4; ++$i) { 388 $res[$i] += $c; 389 $c = $res[$i] >> 16; 390 $res[$i] &= 0xffff; 391 } 392 } 393 394 // Return our values 395 $return = new ParagonIE_Sodium_Core32_Int64(); 396 $return->limbs = array( 397 $res[3] & 0xffff, 398 $res[2] & 0xffff, 399 $res[1] & 0xffff, 400 $res[0] & 0xffff 401 ); 402 if (count($res) > 4) { 403 $return->overflow = $res[4] & 0xffff; 404 } 405 $return->unsignedInt = $this->unsignedInt; 406 return $return; 407 } 408 409 /** 410 * @param ParagonIE_Sodium_Core32_Int64 $right 411 * @return ParagonIE_Sodium_Core32_Int64 412 */ 413 public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right) 414 { 415 $aNeg = ($this->limbs[0] >> 15) & 1; 416 $bNeg = ($right->limbs[0] >> 15) & 1; 417 418 $a = array_reverse($this->limbs); 419 $b = array_reverse($right->limbs); 420 if ($aNeg) { 421 for ($i = 0; $i < 4; ++$i) { 422 $a[$i] = ($a[$i] ^ 0xffff) & 0xffff; 423 } 424 ++$a[0]; 425 } 426 if ($bNeg) { 427 for ($i = 0; $i < 4; ++$i) { 428 $b[$i] = ($b[$i] ^ 0xffff) & 0xffff; 429 } 430 ++$b[0]; 431 } 432 $res = $this->multiplyLong($a, $b); 433 if ($aNeg !== $bNeg) { 434 if ($aNeg !== $bNeg) { 435 for ($i = 0; $i < 4; ++$i) { 436 $res[$i] = ($res[$i] ^ 0xffff) & 0xffff; 437 } 438 $c = 1; 439 for ($i = 0; $i < 4; ++$i) { 440 $res[$i] += $c; 441 $c = $res[$i] >> 16; 442 $res[$i] &= 0xffff; 443 } 444 } 445 } 446 $return = new ParagonIE_Sodium_Core32_Int64(); 447 $return->limbs = array( 448 $res[3] & 0xffff, 449 $res[2] & 0xffff, 450 $res[1] & 0xffff, 451 $res[0] & 0xffff 452 ); 453 if (count($res) > 4) { 454 $return->overflow = $res[4]; 455 } 456 return $return; 457 } 458 459 /** 321 460 * @param ParagonIE_Sodium_Core32_Int64 $int 322 461 * @param int $size … … 328 467 public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0) 329 468 { 469 if (ParagonIE_Sodium_Compat::$fastMult) { 470 return $this->mulInt64Fast($int); 471 } 330 472 ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2); 331 473 if (!$size) { … … 567 709 return $this->shiftRight(-$c); 568 710 } else { 569 if ( is_null($c)) {711 if (!is_int($c)) { 570 712 throw new TypeError(); 571 713 } … … 592 734 { 593 735 ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); 736 $c = (int) $c; 737 /** @var int $c */ 594 738 $return = new ParagonIE_Sodium_Core32_Int64(); 595 739 $return->unsignedInt = $this->unsignedInt; 596 740 $c &= 63; 597 /** @var int $c */598 741 599 742 $negative = -(($this->limbs[0] >> 15) & 1); -
branches/5.2/src/wp-includes/sodium_compat/src/Core32/X25519.php
r44953 r45355 103 103 public static function fe_mul121666(ParagonIE_Sodium_Core32_Curve25519_Fe $f) 104 104 { 105 /** @var array<int, ParagonIE_Sodium_Core32_Int 32> $h */105 /** @var array<int, ParagonIE_Sodium_Core32_Int64> $h */ 106 106 $h = array(); 107 107 for ($i = 0; $i < 10; ++$i) { … … 109 109 } 110 110 111 /** @var ParagonIE_Sodium_Core32_Int32 $carry9 */112 111 $carry9 = $h[9]->addInt(1 << 24)->shiftRight(25); 113 112 $h[0] = $h[0]->addInt64($carry9->mulInt(19, 5)); 114 113 $h[9] = $h[9]->subInt64($carry9->shiftLeft(25)); 115 114 116 /** @var ParagonIE_Sodium_Core32_Int32 $carry1 */117 115 $carry1 = $h[1]->addInt(1 << 24)->shiftRight(25); 118 116 $h[2] = $h[2]->addInt64($carry1); 119 117 $h[1] = $h[1]->subInt64($carry1->shiftLeft(25)); 120 118 121 /** @var ParagonIE_Sodium_Core32_Int32 $carry3 */122 119 $carry3 = $h[3]->addInt(1 << 24)->shiftRight(25); 123 120 $h[4] = $h[4]->addInt64($carry3); 124 121 $h[3] = $h[3]->subInt64($carry3->shiftLeft(25)); 125 122 126 /** @var ParagonIE_Sodium_Core32_Int32 $carry5 */127 123 $carry5 = $h[5]->addInt(1 << 24)->shiftRight(25); 128 124 $h[6] = $h[6]->addInt64($carry5); 129 125 $h[5] = $h[5]->subInt64($carry5->shiftLeft(25)); 130 126 131 /** @var ParagonIE_Sodium_Core32_Int32 $carry7 */132 127 $carry7 = $h[7]->addInt(1 << 24)->shiftRight(25); 133 128 $h[8] = $h[8]->addInt64($carry7); 134 129 $h[7] = $h[7]->subInt64($carry7->shiftLeft(25)); 135 130 136 /** @var ParagonIE_Sodium_Core32_Int32 $carry0 */137 131 $carry0 = $h[0]->addInt(1 << 25)->shiftRight(26); 138 132 $h[1] = $h[1]->addInt64($carry0); 139 133 $h[0] = $h[0]->subInt64($carry0->shiftLeft(26)); 140 134 141 /** @var ParagonIE_Sodium_Core32_Int32 $carry2 */142 135 $carry2 = $h[2]->addInt(1 << 25)->shiftRight(26); 143 136 $h[3] = $h[3]->addInt64($carry2); 144 137 $h[2] = $h[2]->subInt64($carry2->shiftLeft(26)); 145 138 146 /** @var ParagonIE_Sodium_Core32_Int32 $carry4 */147 139 $carry4 = $h[4]->addInt(1 << 25)->shiftRight(26); 148 140 $h[5] = $h[5]->addInt64($carry4); 149 141 $h[4] = $h[4]->subInt64($carry4->shiftLeft(26)); 150 142 151 /** @var ParagonIE_Sodium_Core32_Int32 $carry6 */152 143 $carry6 = $h[6]->addInt(1 << 25)->shiftRight(26); 153 144 $h[7] = $h[7]->addInt64($carry6); 154 145 $h[6] = $h[6]->subInt64($carry6->shiftLeft(26)); 155 146 156 /** @var ParagonIE_Sodium_Core32_Int32 $carry8 */157 147 $carry8 = $h[8]->addInt(1 << 25)->shiftRight(26); 158 148 $h[9] = $h[9]->addInt64($carry8); -
branches/5.2/src/wp-includes/sodium_compat/src/Crypto.php
r44953 r45355 820 820 public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) 821 821 { 822 return self::generichash(823 self::scalarmult($my_sk, $their_pk) .822 return ParagonIE_Sodium_Compat::crypto_generichash( 823 ParagonIE_Sodium_Compat::crypto_scalarmult($my_sk, $their_pk) . 824 824 $client_pk . 825 825 $server_pk -
branches/5.2/src/wp-includes/sodium_compat/src/File.php
r44953 r45355 591 591 $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64); 592 592 593 /** @var resource $hs */594 593 $hs = hash_init('sha512'); 595 594 hash_update($hs, self::substr($az, 32, 32)); … … 611 610 ); 612 611 613 /** @var resource $hs */614 612 $hs = hash_init('sha512'); 615 613 hash_update($hs, self::substr($sig, 0, 32)); … … 720 718 $A = ParagonIE_Sodium_Core_Ed25519::ge_frombytes_negate_vartime($publicKey); 721 719 722 /** @var resource $hs */723 720 $hs = hash_init('sha512'); 724 721 hash_update($hs, self::substr($sig, 0, 32)); … … 1080 1077 * @param resource $fp 1081 1078 * @param int $size 1082 * @return mixed (resource on PHP < 7.2, object on PHP >= 7.2)1079 * @return resource|object Resource on PHP < 7.2, HashContext object on PHP >= 7.2 1083 1080 * @throws SodiumException 1084 1081 * @throws TypeError … … 1096 1093 throw new TypeError('Argument 1 must be a resource, ' . gettype($hash) . ' given.'); 1097 1094 } 1098 1099 1095 } else { 1100 1096 if (!is_object($hash)) { … … 1102 1098 } 1103 1099 } 1100 1104 1101 if (!is_resource($fp)) { 1105 1102 throw new TypeError('Argument 2 must be a resource, ' . gettype($fp) . ' given.'); … … 1168 1165 $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64); 1169 1166 1170 /** @var resource $hs */1171 1167 $hs = hash_init('sha512'); 1172 1168 hash_update($hs, self::substr($az, 32, 32)); … … 1188 1184 ); 1189 1185 1190 /** @var resource $hs */1191 1186 $hs = hash_init('sha512'); 1192 1187 hash_update($hs, self::substr($sig, 0, 32)); … … 1273 1268 $A = ParagonIE_Sodium_Core32_Ed25519::ge_frombytes_negate_vartime($publicKey); 1274 1269 1275 /** @var resource $hs */1276 1270 $hs = hash_init('sha512'); 1277 1271 hash_update($hs, self::substr($sig, 0, 32));
Note: See TracChangeset
for help on using the changeset viewer.