Ticket #47186: 47186-update_sodium_compat_to_v1_9_2.patch
| File 47186-update_sodium_compat_to_v1_9_2.patch, 11.7 KB (added by , 7 years ago) |
|---|
-
wp-includes/sodium_compat/lib/php72compat.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
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; 256 256 } catch (Exception $ex) { … … 271 271 */ 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 } 277 277 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) { -
wp-includes/sodium_compat/src/Crypto.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
819 819 */ 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 826 826 ); -
wp-includes/sodium_compat/src/Core32/Int64.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
205 205 */ 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); 210 213 /** @var int $int */ … … 268 271 $a3 &= 0xffff; 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 } 278 281 … … 317 320 ); 318 321 } 319 322 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 $r = array_fill(0, $a_l + $b_l + 1, 0); 334 $base = 1 << $baseLog2; 335 for ($i = 0; $i < $a_l; ++$i) { 336 $a_i = $a[$i]; 337 for ($j = 0; $j < $a_l; ++$j) { 338 $b_j = $b[$j]; 339 $product = ($a_i * $b_j) + $r[$i + $j]; 340 $carry = ($product >> $baseLog2 & 0xffff); 341 $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff; 342 $r[$i + $j + 1] += $carry; 343 } 344 } 345 return array_slice($r, 0, 5); 346 } 347 348 /** 349 * @param int $int 350 * @return ParagonIE_Sodium_Core32_Int64 351 */ 352 public function mulIntFast($int) 353 { 354 // Handle negative numbers 355 $aNeg = ($this->limbs[0] >> 15) & 1; 356 $bNeg = ($int >> 31) & 1; 357 $a = array_reverse($this->limbs); 358 $b = array( 359 $int & 0xffff, 360 ($int >> 16) & 0xffff, 361 -$bNeg & 0xffff, 362 -$bNeg & 0xffff 363 ); 364 if ($aNeg) { 365 for ($i = 0; $i < 4; ++$i) { 366 $a[$i] = ($a[$i] ^ 0xffff) & 0xffff; 367 } 368 ++$a[0]; 369 } 370 if ($bNeg) { 371 for ($i = 0; $i < 4; ++$i) { 372 $b[$i] = ($b[$i] ^ 0xffff) & 0xffff; 373 } 374 ++$b[0]; 375 } 376 // Multiply 377 $res = $this->multiplyLong($a, $b); 378 379 // Re-apply negation to results 380 if ($aNeg !== $bNeg) { 381 for ($i = 0; $i < 4; ++$i) { 382 $res[$i] = (0xffff ^ $res[$i]) & 0xffff; 383 } 384 // Handle integer overflow 385 $c = 1; 386 for ($i = 0; $i < 4; ++$i) { 387 $res[$i] += $c; 388 $c = $res[$i] >> 16; 389 $res[$i] &= 0xffff; 390 } 391 } 392 393 // Return our values 394 $return = new ParagonIE_Sodium_Core32_Int64(); 395 $return->limbs = array( 396 $res[3] & 0xffff, 397 $res[2] & 0xffff, 398 $res[1] & 0xffff, 399 $res[0] & 0xffff 400 ); 401 if (count($res) > 4) { 402 $return->overflow = $res[4] & 0xffff; 403 } 404 $return->unsignedInt = $this->unsignedInt; 405 return $return; 406 } 407 408 /** 409 * @param ParagonIE_Sodium_Core32_Int64 $right 410 * @return ParagonIE_Sodium_Core32_Int64 411 */ 412 public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right) 413 { 414 $aNeg = ($this->limbs[0] >> 15) & 1; 415 $bNeg = ($right->limbs[0] >> 15) & 1; 416 417 $a = array_reverse($this->limbs); 418 $b = array_reverse($right->limbs); 419 if ($aNeg) { 420 for ($i = 0; $i < 4; ++$i) { 421 $a[$i] = ($a[$i] ^ 0xffff) & 0xffff; 422 } 423 ++$a[0]; 424 } 425 if ($bNeg) { 426 for ($i = 0; $i < 4; ++$i) { 427 $b[$i] = ($b[$i] ^ 0xffff) & 0xffff; 428 } 429 ++$b[0]; 430 } 431 $res = $this->multiplyLong($a, $b); 432 if ($aNeg !== $bNeg) { 433 if ($aNeg !== $bNeg) { 434 for ($i = 0; $i < 4; ++$i) { 435 $res[$i] = ($res[$i] ^ 0xffff) & 0xffff; 436 } 437 $c = 1; 438 for ($i = 0; $i < 4; ++$i) { 439 $res[$i] += $c; 440 $c = $res[$i] >> 16; 441 $res[$i] &= 0xffff; 442 } 443 } 444 } 445 $return = new ParagonIE_Sodium_Core32_Int64(); 446 $return->limbs = array( 447 $res[3] & 0xffff, 448 $res[2] & 0xffff, 449 $res[1] & 0xffff, 450 $res[0] & 0xffff 451 ); 452 if (count($res) > 4) { 453 $return->overflow = $res[4]; 454 } 455 return $return; 456 } 457 320 458 /** 321 459 * @param ParagonIE_Sodium_Core32_Int64 $int 322 460 * @param int $size … … 327 465 */ 328 466 public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0) 329 467 { 468 if (ParagonIE_Sodium_Compat::$fastMult) { 469 return $this->mulInt64Fast($int); 470 } 330 471 ParagonIE_Sodium_Core32_Util::declareScalarType($size, 'int', 2); 331 472 if (!$size) { 332 473 $size = 63; -
wp-includes/sodium_compat/src/Compat.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
669 669 * This mode uses a 64-bit random nonce with a 64-bit counter. 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 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 676 677 * 677 678 * @return string The original plaintext message 678 679 * @throws SodiumException … … 683 684 $ciphertext = '', 684 685 $assocData = '', 685 686 $nonce = '', 686 $key = '' 687 $key = '', 688 $dontFallback = false 687 689 ) { 688 690 /* Type checks: */ 689 691 ParagonIE_Sodium_Core_Util::declareScalarType($ciphertext, 'string', 1); … … 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'); 703 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 } 715 } 704 716 705 717 if (PHP_INT_SIZE === 4) { 706 718 return ParagonIE_Sodium_Crypto32::aead_xchacha20poly1305_ietf_decrypt( … … 727 739 * This mode uses a 64-bit random nonce with a 64-bit counter. 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 736 749 * authentication code appended … … 742 755 $plaintext = '', 743 756 $assocData = '', 744 757 $nonce = '', 745 $key = '' 758 $key = '', 759 $dontFallback = false 746 760 ) { 747 761 /* Type checks: */ 748 762 ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1); … … 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'); 759 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 } 783 } 760 784 761 785 if (PHP_INT_SIZE === 4) { 762 786 return ParagonIE_Sodium_Crypto32::aead_xchacha20poly1305_ietf_encrypt(