Changeset 60905
- Timestamp:
- 10/06/2025 03:46:40 PM (2 months ago)
- Location:
- trunk/src/wp-includes/sodium_compat/src
- Files:
-
- 16 edited
-
Compat.php (modified) (14 diffs)
-
Core/Base64/Original.php (modified) (1 diff)
-
Core/Base64/UrlSafe.php (modified) (1 diff)
-
Core/ChaCha20.php (modified) (4 diffs)
-
Core/ChaCha20/Ctx.php (modified) (2 diffs)
-
Core/ChaCha20/IetfCtx.php (modified) (1 diff)
-
Core/Curve25519.php (modified) (19 diffs)
-
Core/Curve25519/Fe.php (modified) (7 diffs)
-
Core/Ed25519.php (modified) (5 diffs)
-
Core/HChaCha20.php (modified) (1 diff)
-
Core/Poly1305.php (modified) (1 diff)
-
Core/Util.php (modified) (5 diffs)
-
Core/X25519.php (modified) (2 diffs)
-
Core/XChaCha20.php (modified) (4 diffs)
-
Crypto.php (modified) (2 diffs)
-
File.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/sodium_compat/src/Compat.php
r58752 r60905 26 26 } 27 27 28 /** 29 * @api 30 */ 28 31 class ParagonIE_Sodium_Compat 29 32 { … … 205 208 /** @var string $encoded */ 206 209 $encoded = (string) $encoded; 207 if (ParagonIE_Sodium_Core_Util::strlen($encoded) === 0) {208 return '';209 }210 210 211 211 // Just strip before decoding … … 219 219 return ParagonIE_Sodium_Core_Base64_Original::decode($encoded, true); 220 220 case self::BASE64_VARIANT_ORIGINAL_NO_PADDING: 221 return ParagonIE_Sodium_Core_Base64_Original::decode ($encoded, false);221 return ParagonIE_Sodium_Core_Base64_Original::decodeNoPadding($encoded); 222 222 case self::BASE64_VARIANT_URLSAFE: 223 223 return ParagonIE_Sodium_Core_Base64_UrlSafe::decode($encoded, true); 224 224 case self::BASE64_VARIANT_URLSAFE_NO_PADDING: 225 return ParagonIE_Sodium_Core_Base64_UrlSafe::decode ($encoded, false);225 return ParagonIE_Sodium_Core_Base64_UrlSafe::decodeNoPadding($encoded); 226 226 default: 227 227 throw new SodiumException('invalid base64 variant identifier'); … … 231 231 throw $ex; 232 232 } 233 throw new SodiumException('invalid base64 string' );233 throw new SodiumException('invalid base64 string', 0, $ex); 234 234 } 235 235 } … … 357 357 /* Input validation: */ 358 358 if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_AEGIS128L_NPUBBYTES) { 359 throw new SodiumException('Nonce must be CRYPTO_AEAD_AEGIS _128L_NPUBBYTES long');359 throw new SodiumException('Nonce must be CRYPTO_AEAD_AEGIS128L_NPUBBYTES long'); 360 360 } 361 361 if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_AEGIS128L_KEYBYTES) { … … 411 411 /* Input validation: */ 412 412 if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_AEGIS128L_NPUBBYTES) { 413 throw new SodiumException('Nonce must be CRYPTO_AEAD_AEGIS128L_ KEYBYTES long');413 throw new SodiumException('Nonce must be CRYPTO_AEAD_AEGIS128L_NPUBBYTES long'); 414 414 } 415 415 if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_AEGIS128L_KEYBYTES) { … … 520 520 /* Input validation: */ 521 521 if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_AEGIS256_NPUBBYTES) { 522 throw new SodiumException('Nonce must be CRYPTO_AEAD_AEGIS 128L_KEYBYTES long');522 throw new SodiumException('Nonce must be CRYPTO_AEAD_AEGIS256_NPUBBYTES long'); 523 523 } 524 524 if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_AEGIS256_KEYBYTES) { 525 throw new SodiumException('Key must be CRYPTO_AEAD_AEGIS 128L_KEYBYTES long');525 throw new SodiumException('Key must be CRYPTO_AEAD_AEGIS256_KEYBYTES long'); 526 526 } 527 527 … … 563 563 return false; 564 564 } 565 if (!extension_loaded('openssl')) { 566 return false; 567 } 565 568 if (!is_callable('openssl_encrypt') || !is_callable('openssl_decrypt')) { 566 569 // OpenSSL isn't installed … … 615 618 if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_AES256GCM_ABYTES) { 616 619 throw new SodiumException('Message must be at least CRYPTO_AEAD_AES256GCM_ABYTES long'); 620 } 621 if (!extension_loaded('openssl')) { 622 throw new SodiumException('The OpenSSL extension is not installed'); 617 623 } 618 624 if (!is_callable('openssl_decrypt')) { … … 676 682 } 677 683 684 if (!extension_loaded('openssl')) { 685 throw new SodiumException('The OpenSSL extension is not installed'); 686 } 678 687 if (!is_callable('openssl_encrypt')) { 679 688 throw new SodiumException('The OpenSSL extension is not installed, or openssl_encrypt() is not available'); … … 824 833 /* Input validation: */ 825 834 if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES) { 826 throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_ NPUBBYTES long');835 throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long'); 827 836 } 828 837 if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) { 829 throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_ KEYBYTES long');838 throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES long'); 830 839 } 831 840 … … 902 911 } 903 912 if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) { 904 throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_ KEYBYTES long');913 throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES long'); 905 914 } 906 915 if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_CHACHA20POLY1305_ABYTES) { 907 throw new SodiumException('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_ ABYTES long');916 throw new SodiumException('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES long'); 908 917 } 909 918 … … 2782 2791 throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); 2783 2792 } 2793 if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_SECRETBOX_MACBYTES) { 2794 throw new SodiumException("Ciphertext must be at least CRYPTO_SECRETBOX_MACBYTES long"); 2795 } 2784 2796 2785 2797 if (PHP_INT_SIZE === 4) { … … 3712 3724 3713 3725 $len = ParagonIE_Sodium_Core_Util::strlen($var); 3726 if ($len < 1) { 3727 throw new SodiumException('Argument 1 cannot be empty'); 3728 } 3714 3729 $c = 1; 3715 3730 $copy = ''; -
trunk/src/wp-includes/sodium_compat/src/Core/Base64/Original.php
r46858 r60905 186 186 return $dest; 187 187 } 188 189 /** 190 * @param string $encodedString 191 * @return string 192 */ 193 public static function decodeNoPadding( 194 #[SensitiveParameter] 195 $encodedString 196 ) { 197 $srcLen = strlen($encodedString); 198 if ($srcLen === 0) { 199 return ''; 200 } 201 if (($srcLen & 3) === 0) { 202 // If $strLen is not zero, and it is divisible by 4, then it's at least 4. 203 if ($encodedString[$srcLen - 1] === '=' || $encodedString[$srcLen - 2] === '=') { 204 throw new InvalidArgumentException( 205 "decodeNoPadding() doesn't tolerate padding" 206 ); 207 } 208 } 209 return self::decode( 210 $encodedString, 211 true 212 ); 213 } 188 214 // COPY ParagonIE_Sodium_Core_Base64_Common ENDING HERE 189 215 -
trunk/src/wp-includes/sodium_compat/src/Core/Base64/UrlSafe.php
r46858 r60905 186 186 return $dest; 187 187 } 188 189 /** 190 * @param string $encodedString 191 * @return string 192 */ 193 public static function decodeNoPadding( 194 #[SensitiveParameter] 195 $encodedString 196 ) { 197 $srcLen = strlen($encodedString); 198 if ($srcLen === 0) { 199 return ''; 200 } 201 if (($srcLen & 3) === 0) { 202 // If $strLen is not zero, and it is divisible by 4, then it's at least 4. 203 if ($encodedString[$srcLen - 1] === '=' || $encodedString[$srcLen - 2] === '=') { 204 throw new InvalidArgumentException( 205 "decodeNoPadding() doesn't tolerate padding" 206 ); 207 } 208 } 209 return self::decode( 210 $encodedString, 211 true 212 ); 213 } 214 188 215 // COPY ParagonIE_Sodium_Core_Base64_Common ENDING HERE 189 216 /** -
trunk/src/wp-includes/sodium_compat/src/Core/ChaCha20.php
r46586 r60905 330 330 * @throws TypeError 331 331 */ 332 public static function stream($len = 64, $nonce = '', $key = '')332 public static function stream($len, $nonce, $key) 333 333 { 334 334 return self::encryptBytes( … … 348 348 * @throws TypeError 349 349 */ 350 public static function ietfStream($len, $nonce = '', $key = '')350 public static function ietfStream($len, $nonce, $key) 351 351 { 352 352 return self::encryptBytes( … … 367 367 * @throws TypeError 368 368 */ 369 public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '')369 public static function ietfStreamXorIc($message, $nonce, $key, $ic = '') 370 370 { 371 371 return self::encryptBytes( … … 386 386 * @throws TypeError 387 387 */ 388 public static function streamXorIc($message, $nonce = '', $key = '', $ic = '')388 public static function streamXorIc($message, $nonce, $key, $ic = '') 389 389 { 390 390 return self::encryptBytes( -
trunk/src/wp-includes/sodium_compat/src/Core/ChaCha20/Ctx.php
r51591 r60905 51 51 $this->container[11] = self::load_4(self::substr($key, 28, 4)); 52 52 53 if (empty($counter)) { 54 $this->container[12] = 0; 55 $this->container[13] = 0; 56 } else { 57 $this->container[12] = self::load_4(self::substr($counter, 0, 4)); 58 $this->container[13] = self::load_4(self::substr($counter, 4, 4)); 59 } 53 $counter = $this->initCounter($counter); 54 $this->container[12] = self::load_4(self::substr($counter, 0, 4)); 55 $this->container[13] = self::load_4(self::substr($counter, 4, 4)); 60 56 $this->container[14] = self::load_4(self::substr($iv, 0, 4)); 61 57 $this->container[15] = self::load_4(self::substr($iv, 4, 4)); … … 121 117 : null; 122 118 } 119 120 /** 121 * Initialize (pad) a counter value. 122 * @throws SodiumException 123 * 124 * @param string $ctr 125 * @return string 126 */ 127 public function initCounter( 128 #[SensitiveParameter] 129 $ctr 130 ) { 131 $len = self::strlen($ctr); 132 if ($len === 0) { 133 return str_repeat("\0", 8); 134 } 135 if ($len < 8) { 136 return $ctr . str_repeat("\0", 8 - $len); 137 } 138 if ($len > 8) { 139 throw new SodiumException("counter cannot be more than 8 bytes"); 140 } 141 return $ctr; 142 } 123 143 } -
trunk/src/wp-includes/sodium_compat/src/Core/ChaCha20/IetfCtx.php
r46586 r60905 27 27 throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.'); 28 28 } 29 $counter = $this->initCounter($counter); 29 30 parent::__construct($key, self::substr($iv, 0, 8), $counter); 30 31 if (!empty($counter)) { 32 $this->container[12] = self::load_4(self::substr($counter, 0, 4)); 33 } 31 $this->container[12] = self::load_4(self::substr($counter, 0, 4)); 34 32 $this->container[13] = self::load_4(self::substr($iv, 0, 4)); 35 33 $this->container[14] = self::load_4(self::substr($iv, 4, 4)); -
trunk/src/wp-includes/sodium_compat/src/Core/Curve25519.php
r52988 r60905 25 25 public static function fe_0() 26 26 { 27 return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( 28 array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 29 ); 27 return new ParagonIE_Sodium_Core_Curve25519_Fe(); 30 28 } 31 29 … … 39 37 public static function fe_1() 40 38 { 41 return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(42 array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0)43 );39 $fe = new ParagonIE_Sodium_Core_Curve25519_Fe(); 40 $fe->e0 = 1; 41 return $fe; 44 42 } 45 43 … … 59 57 ParagonIE_Sodium_Core_Curve25519_Fe $g 60 58 ) { 61 /** @var array<int, int> $arr */ 62 $arr = array(); 63 for ($i = 0; $i < 10; ++$i) { 64 $arr[$i] = (int) ($f[$i] + $g[$i]); 65 } 66 return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($arr); 59 return new ParagonIE_Sodium_Core_Curve25519_Fe( 60 (int)($f->e0 + $g->e0), 61 (int)($f->e1 + $g->e1), 62 (int)($f->e2 + $g->e2), 63 (int)($f->e3 + $g->e3), 64 (int)($f->e4 + $g->e4), 65 (int)($f->e5 + $g->e5), 66 (int)($f->e6 + $g->e6), 67 (int)($f->e7 + $g->e7), 68 (int)($f->e8 + $g->e8), 69 (int)($f->e9 + $g->e9) 70 ); 67 71 } 68 72 … … 83 87 $b = 0 84 88 ) { 85 /** @var array<int, int> $h */ 86 $h = array(); 89 $h = new ParagonIE_Sodium_Core_Curve25519_Fe(); 87 90 $b *= -1; 88 for ($i = 0; $i < 10; ++$i) { 89 $x = (($f[$i] ^ $g[$i]) & $b); 90 $h[$i] = ($f[$i]) ^ $x; 91 } 92 return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); 91 $x = (($f->e0 ^ $g->e0) & $b); $h->e0 = $f->e0 ^ $x; 92 $x = (($f->e1 ^ $g->e1) & $b); $h->e1 = $f->e1 ^ $x; 93 $x = (($f->e2 ^ $g->e2) & $b); $h->e2 = $f->e2 ^ $x; 94 $x = (($f->e3 ^ $g->e3) & $b); $h->e3 = $f->e3 ^ $x; 95 $x = (($f->e4 ^ $g->e4) & $b); $h->e4 = $f->e4 ^ $x; 96 $x = (($f->e5 ^ $g->e5) & $b); $h->e5 = $f->e5 ^ $x; 97 $x = (($f->e6 ^ $g->e6) & $b); $h->e6 = $f->e6 ^ $x; 98 $x = (($f->e7 ^ $g->e7) & $b); $h->e7 = $f->e7 ^ $x; 99 $x = (($f->e8 ^ $g->e8) & $b); $h->e8 = $f->e8 ^ $x; 100 $x = (($f->e9 ^ $g->e9) & $b); $h->e9 = $f->e9 ^ $x; 101 return $h; 93 102 } 94 103 … … 103 112 public static function fe_copy(ParagonIE_Sodium_Core_Curve25519_Fe $f) 104 113 { 105 $h = clone $f; 106 return $h; 114 return clone $f; 107 115 } 108 116 … … 166 174 $h8 -= $carry8 << 26; 167 175 168 return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( 169 array( 170 (int) $h0, 171 (int) $h1, 172 (int) $h2, 173 (int) $h3, 174 (int) $h4, 175 (int) $h5, 176 (int) $h6, 177 (int) $h7, 178 (int) $h8, 179 (int) $h9 180 ) 176 return new ParagonIE_Sodium_Core_Curve25519_Fe( 177 (int) $h0, 178 (int) $h1, 179 (int) $h2, 180 (int) $h3, 181 (int) $h4, 182 (int) $h5, 183 (int) $h6, 184 (int) $h7, 185 (int) $h8, 186 (int) $h9 181 187 ); 182 188 } … … 192 198 public static function fe_tobytes(ParagonIE_Sodium_Core_Curve25519_Fe $h) 193 199 { 194 $h0 = (int) $h [0];195 $h1 = (int) $h [1];196 $h2 = (int) $h [2];197 $h3 = (int) $h [3];198 $h4 = (int) $h [4];199 $h5 = (int) $h [5];200 $h6 = (int) $h [6];201 $h7 = (int) $h [7];202 $h8 = (int) $h [8];203 $h9 = (int) $h [9];200 $h0 = (int) $h->e0; 201 $h1 = (int) $h->e1; 202 $h2 = (int) $h->e2; 203 $h3 = (int) $h->e3; 204 $h4 = (int) $h->e4; 205 $h5 = (int) $h->e5; 206 $h6 = (int) $h->e6; 207 $h7 = (int) $h->e7; 208 $h8 = (int) $h->e8; 209 $h9 = (int) $h->e9; 204 210 205 211 $q = (self::mul($h9, 19, 5) + (1 << 24)) >> 25; … … 346 352 $f = self::fe_normalize($f); 347 353 $g = self::fe_normalize($g); 348 $f0 = $f [0];349 $f1 = $f [1];350 $f2 = $f [2];351 $f3 = $f [3];352 $f4 = $f [4];353 $f5 = $f [5];354 $f6 = $f [6];355 $f7 = $f [7];356 $f8 = $f [8];357 $f9 = $f [9];358 $g0 = $g [0];359 $g1 = $g [1];360 $g2 = $g [2];361 $g3 = $g [3];362 $g4 = $g [4];363 $g5 = $g [5];364 $g6 = $g [6];365 $g7 = $g [7];366 $g8 = $g [8];367 $g9 = $g [9];354 $f0 = $f->e0; 355 $f1 = $f->e1; 356 $f2 = $f->e2; 357 $f3 = $f->e3; 358 $f4 = $f->e4; 359 $f5 = $f->e5; 360 $f6 = $f->e6; 361 $f7 = $f->e7; 362 $f8 = $f->e8; 363 $f9 = $f->e9; 364 $g0 = $g->e0; 365 $g1 = $g->e1; 366 $g2 = $g->e2; 367 $g3 = $g->e3; 368 $g4 = $g->e4; 369 $g5 = $g->e5; 370 $g6 = $g->e6; 371 $g7 = $g->e7; 372 $g8 = $g->e8; 373 $g9 = $g->e9; 368 374 $g1_19 = self::mul($g1, 19, 5); 369 375 $g2_19 = self::mul($g2, 19, 5); … … 536 542 537 543 return self::fe_normalize( 538 ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( 539 array( 540 (int) $h0, 541 (int) $h1, 542 (int) $h2, 543 (int) $h3, 544 (int) $h4, 545 (int) $h5, 546 (int) $h6, 547 (int) $h7, 548 (int) $h8, 549 (int) $h9 550 ) 544 new ParagonIE_Sodium_Core_Curve25519_Fe( 545 (int) $h0, 546 (int) $h1, 547 (int) $h2, 548 (int) $h3, 549 (int) $h4, 550 (int) $h5, 551 (int) $h6, 552 (int) $h7, 553 (int) $h8, 554 (int) $h9 551 555 ) 552 556 ); … … 566 570 public static function fe_neg(ParagonIE_Sodium_Core_Curve25519_Fe $f) 567 571 { 568 $h = new ParagonIE_Sodium_Core_Curve25519_Fe(); 569 for ($i = 0; $i < 10; ++$i) { 570 $h[$i] = -$f[$i]; 571 } 572 return self::fe_normalize($h); 572 return self::fe_normalize( 573 new ParagonIE_Sodium_Core_Curve25519_Fe( 574 -$f->e0, 575 -$f->e1, 576 -$f->e2, 577 -$f->e3, 578 -$f->e4, 579 -$f->e5, 580 -$f->e6, 581 -$f->e7, 582 -$f->e8, 583 -$f->e9 584 ) 585 ); 573 586 } 574 587 … … 586 599 { 587 600 $f = self::fe_normalize($f); 588 $f0 = (int) $f [0];589 $f1 = (int) $f [1];590 $f2 = (int) $f [2];591 $f3 = (int) $f [3];592 $f4 = (int) $f [4];593 $f5 = (int) $f [5];594 $f6 = (int) $f [6];595 $f7 = (int) $f [7];596 $f8 = (int) $f [8];597 $f9 = (int) $f [9];601 $f0 = (int) $f->e0; 602 $f1 = (int) $f->e1; 603 $f2 = (int) $f->e2; 604 $f3 = (int) $f->e3; 605 $f4 = (int) $f->e4; 606 $f5 = (int) $f->e5; 607 $f6 = (int) $f->e6; 608 $f7 = (int) $f->e7; 609 $f8 = (int) $f->e8; 610 $f9 = (int) $f->e9; 598 611 599 612 $f0_2 = $f0 << 1; … … 720 733 721 734 return self::fe_normalize( 722 ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( 723 array( 724 (int) $h0, 725 (int) $h1, 726 (int) $h2, 727 (int) $h3, 728 (int) $h4, 729 (int) $h5, 730 (int) $h6, 731 (int) $h7, 732 (int) $h8, 733 (int) $h9 734 ) 735 new ParagonIE_Sodium_Core_Curve25519_Fe( 736 (int) $h0, 737 (int) $h1, 738 (int) $h2, 739 (int) $h3, 740 (int) $h4, 741 (int) $h5, 742 (int) $h6, 743 (int) $h7, 744 (int) $h8, 745 (int) $h9 735 746 ) 736 747 ); … … 751 762 { 752 763 $f = self::fe_normalize($f); 753 $f0 = (int) $f [0];754 $f1 = (int) $f [1];755 $f2 = (int) $f [2];756 $f3 = (int) $f [3];757 $f4 = (int) $f [4];758 $f5 = (int) $f [5];759 $f6 = (int) $f [6];760 $f7 = (int) $f [7];761 $f8 = (int) $f [8];762 $f9 = (int) $f [9];764 $f0 = (int) $f->e0; 765 $f1 = (int) $f->e1; 766 $f2 = (int) $f->e2; 767 $f3 = (int) $f->e3; 768 $f4 = (int) $f->e4; 769 $f5 = (int) $f->e5; 770 $f6 = (int) $f->e6; 771 $f7 = (int) $f->e7; 772 $f8 = (int) $f->e8; 773 $f9 = (int) $f->e9; 763 774 764 775 $f0_2 = $f0 << 1; … … 886 897 887 898 return self::fe_normalize( 888 ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( 889 array( 890 (int) $h0, 891 (int) $h1, 892 (int) $h2, 893 (int) $h3, 894 (int) $h4, 895 (int) $h5, 896 (int) $h6, 897 (int) $h7, 898 (int) $h8, 899 (int) $h9 900 ) 899 new ParagonIE_Sodium_Core_Curve25519_Fe( 900 (int) $h0, 901 (int) $h1, 902 (int) $h2, 903 (int) $h3, 904 (int) $h4, 905 (int) $h5, 906 (int) $h6, 907 (int) $h7, 908 (int) $h8, 909 (int) $h9 901 910 ) 902 911 ); … … 1100 1109 { 1101 1110 return self::fe_normalize( 1102 ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( 1103 array( 1104 (int) ($f[0] - $g[0]), 1105 (int) ($f[1] - $g[1]), 1106 (int) ($f[2] - $g[2]), 1107 (int) ($f[3] - $g[3]), 1108 (int) ($f[4] - $g[4]), 1109 (int) ($f[5] - $g[5]), 1110 (int) ($f[6] - $g[6]), 1111 (int) ($f[7] - $g[7]), 1112 (int) ($f[8] - $g[8]), 1113 (int) ($f[9] - $g[9]) 1114 ) 1111 new ParagonIE_Sodium_Core_Curve25519_Fe( 1112 (int) ($f->e0 - $g->e0), 1113 (int) ($f->e1 - $g->e1), 1114 (int) ($f->e2 - $g->e2), 1115 (int) ($f->e3 - $g->e3), 1116 (int) ($f->e4 - $g->e4), 1117 (int) ($f->e5 - $g->e5), 1118 (int) ($f->e6 - $g->e6), 1119 (int) ($f->e7 - $g->e7), 1120 (int) ($f->e8 - $g->e8), 1121 (int) ($f->e9 - $g->e9) 1115 1122 ) 1116 1123 ); … … 2801 2808 */ 2802 2809 $arr = array( 2803 (int) ( $s0 >> 0),2804 (int) ( $s0 >> 8),2805 (int) ( ($s0 >> 16) | $s1 << 5),2806 (int) ( $s1 >> 3),2807 (int) ( $s1 >> 11),2808 (int) ( ($s1 >> 19) | $s2 << 2),2809 (int) ( $s2 >> 6),2810 (int) ( ($s2 >> 14) | $s3 << 7),2811 (int) ( $s3 >> 1),2812 (int) ( $s3 >> 9),2813 (int) ( ($s3 >> 17) | $s4 << 4),2814 (int) ( $s4 >> 4),2815 (int) ( $s4 >> 12),2816 (int) ( ($s4 >> 20) | $s5 << 1),2817 (int) ( $s5 >> 7),2818 (int) ( ($s5 >> 15) | $s6 << 6),2819 (int) ( $s6 >> 2),2820 (int) ( $s6 >> 10),2821 (int) ( ($s6 >> 18) | $s7 << 3),2822 (int) ( $s7 >> 5),2823 (int) ( $s7 >> 13),2824 (int) ( $s8 >> 0),2825 (int) ( $s8 >> 8),2826 (int) ( ($s8 >> 16) | $s9 << 5),2827 (int) ( $s9 >> 3),2828 (int) ( $s9 >> 11),2829 (int) ( ($s9 >> 19) | $s10 << 2),2830 (int) ( $s10 >> 6),2831 (int) ( ($s10 >> 14) | $s11 << 7),2832 (int) ( $s11 >> 1),2833 (int) ( $s11 >> 9),2834 (int) $s11 >> 172810 (int) (0xff & ($s0 >> 0)), 2811 (int) (0xff & ($s0 >> 8)), 2812 (int) (0xff & (($s0 >> 16) | $s1 << 5)), 2813 (int) (0xff & ($s1 >> 3)), 2814 (int) (0xff & ($s1 >> 11)), 2815 (int) (0xff & (($s1 >> 19) | $s2 << 2)), 2816 (int) (0xff & ($s2 >> 6)), 2817 (int) (0xff & (($s2 >> 14) | $s3 << 7)), 2818 (int) (0xff & ($s3 >> 1)), 2819 (int) (0xff & ($s3 >> 9)), 2820 (int) (0xff & (($s3 >> 17) | $s4 << 4)), 2821 (int) (0xff & ($s4 >> 4)), 2822 (int) (0xff & ($s4 >> 12)), 2823 (int) (0xff & (($s4 >> 20) | $s5 << 1)), 2824 (int) (0xff & ($s5 >> 7)), 2825 (int) (0xff & (($s5 >> 15) | $s6 << 6)), 2826 (int) (0xff & ($s6 >> 2)), 2827 (int) (0xff & ($s6 >> 10)), 2828 (int) (0xff & (($s6 >> 18) | $s7 << 3)), 2829 (int) (0xff & ($s7 >> 5)), 2830 (int) (0xff & ($s7 >> 13)), 2831 (int) (0xff & ($s8 >> 0)), 2832 (int) (0xff & ($s8 >> 8)), 2833 (int) (0xff & (($s8 >> 16) | $s9 << 5)), 2834 (int) (0xff & ($s9 >> 3)), 2835 (int) (0xff & ($s9 >> 11)), 2836 (int) (0xff & (($s9 >> 19) | $s10 << 2)), 2837 (int) (0xff & ($s10 >> 6)), 2838 (int) (0xff & (($s10 >> 14) | $s11 << 7)), 2839 (int) (0xff & ($s11 >> 1)), 2840 (int) (0xff & ($s11 >> 9)), 2841 (int) (0xff & ($s11 >> 17)) 2835 2842 ); 2836 2843 return self::intArrayToString($arr); … … 3795 3802 $s_[0] &= 248; 3796 3803 $s_[31] |= 64; 3797 $s_[31] &= 12 8;3804 $s_[31] &= 127; 3798 3805 return self::intArrayToString($s_); 3799 3806 } … … 3812 3819 3813 3820 $g = self::fe_copy($f); 3821 $e = array( 3822 $g->e0, $g->e1, $g->e2, $g->e3, $g->e4, 3823 $g->e5, $g->e6, $g->e7, $g->e8, $g->e9 3824 ); 3814 3825 for ($i = 0; $i < 10; ++$i) { 3815 $mask = -(($ g[$i] >> $x) & 1);3826 $mask = -(($e[$i] >> $x) & 1); 3816 3827 3817 3828 /* 3818 * Get two candidate normalized values for $ g[$i], depending on the sign of $g[$i]:3829 * Get two candidate normalized values for $e[$i], depending on the sign of $e[$i]: 3819 3830 */ 3820 $a = $ g[$i] & 0x7ffffff;3821 $b = -((-$ g[$i]) & 0x7ffffff);3831 $a = $e[$i] & 0x7ffffff; 3832 $b = -((-$e[$i]) & 0x7ffffff); 3822 3833 3823 3834 /* … … 3826 3837 * The following is equivalent to this ternary: 3827 3838 * 3828 * $ g[$i] = (($g[$i] >> $x) & 1) ? $a : $b;3839 * $e[$i] = (($e[$i] >> $x) & 1) ? $a : $b; 3829 3840 * 3830 3841 * Except what's written doesn't contain timing leaks. 3831 3842 */ 3832 $g[$i] = ($a ^ (($a ^ $b) & $mask)); 3833 } 3843 $e[$i] = ($a ^ (($a ^ $b) & $mask)); 3844 } 3845 $g->e0 = $e[0]; 3846 $g->e1 = $e[1]; 3847 $g->e2 = $e[2]; 3848 $g->e3 = $e[3]; 3849 $g->e4 = $e[4]; 3850 $g->e5 = $e[5]; 3851 $g->e6 = $e[6]; 3852 $g->e7 = $e[7]; 3853 $g->e8 = $e[8]; 3854 $g->e9 = $e[9]; 3834 3855 return $g; 3835 3856 } -
trunk/src/wp-includes/sodium_compat/src/Core/Curve25519/Fe.php
r51591 r60905 13 13 { 14 14 /** 15 * @var array<int, int> 16 */ 17 protected $container = array(); 18 19 /** 20 * @var int 21 */ 22 protected $size = 10; 23 24 /** 25 * @internal You should not use this directly from another application 26 * 27 * @param array<int, int> $array 28 * @param bool $save_indexes 15 * @var int 16 */ 17 public $e0 = 0; 18 19 /** 20 * @var int 21 */ 22 public $e1 = 0; 23 24 /** 25 * @var int 26 */ 27 public $e2 = 0; 28 29 /** 30 * @var int 31 */ 32 public $e3 = 0; 33 34 /** 35 * @var int 36 */ 37 public $e4 = 0; 38 39 /** 40 * @var int 41 */ 42 public $e5 = 0; 43 44 /** 45 * @var int 46 */ 47 public $e6 = 0; 48 49 /** 50 * @var int 51 */ 52 public $e7 = 0; 53 54 /** 55 * @var int 56 */ 57 public $e8 = 0; 58 59 /** 60 * @var int 61 */ 62 public $e9 = 0; 63 64 /** 65 * @param int $e0 66 * @param int $e1 67 * @param int $e2 68 * @param int $e3 69 * @param int $e4 70 * @param int $e5 71 * @param int $e6 72 * @param int $e7 73 * @param int $e8 74 * @param int $e9 75 */ 76 public function __construct( 77 $e0 = 0, 78 $e1 = 0, 79 $e2 = 0, 80 $e3 = 0, 81 $e4 = 0, 82 $e5 = 0, 83 $e6 = 0, 84 $e7 = 0, 85 $e8 = 0, 86 $e9 = 0 87 ) { 88 $this->e0 = $e0; 89 $this->e1 = $e1; 90 $this->e2 = $e2; 91 $this->e3 = $e3; 92 $this->e4 = $e4; 93 $this->e5 = $e5; 94 $this->e6 = $e6; 95 $this->e7 = $e7; 96 $this->e8 = $e8; 97 $this->e9 = $e9; 98 } 99 100 /** 101 * @internal You should not use this directly from another application 102 * 103 * @param array $array 29 104 * @return self 30 105 */ 31 public static function fromArray($array, $save_indexes = null) 32 { 33 $count = count($array); 34 if ($save_indexes) { 35 $keys = array_keys($array); 36 } else { 37 $keys = range(0, $count - 1); 38 } 39 $array = array_values($array); 40 /** @var array<int, int> $keys */ 41 106 public static function fromArray($array) 107 { 42 108 $obj = new ParagonIE_Sodium_Core_Curve25519_Fe(); 43 if ($save_indexes) { 44 for ($i = 0; $i < $count; ++$i) { 45 $obj->offsetSet($keys[$i], $array[$i]); 46 } 47 } else { 48 for ($i = 0; $i < $count; ++$i) { 49 $obj->offsetSet($i, $array[$i]); 50 } 51 } 109 $obj->e0 = isset($array[0]) ? (int) $array[0] : 0; 110 $obj->e1 = isset($array[1]) ? (int) $array[1] : 0; 111 $obj->e2 = isset($array[2]) ? (int) $array[2] : 0; 112 $obj->e3 = isset($array[3]) ? (int) $array[3] : 0; 113 $obj->e4 = isset($array[4]) ? (int) $array[4] : 0; 114 $obj->e5 = isset($array[5]) ? (int) $array[5] : 0; 115 $obj->e6 = isset($array[6]) ? (int) $array[6] : 0; 116 $obj->e7 = isset($array[7]) ? (int) $array[7] : 0; 117 $obj->e8 = isset($array[8]) ? (int) $array[8] : 0; 118 $obj->e9 = isset($array[9]) ? (int) $array[9] : 0; 52 119 return $obj; 53 120 } … … 59 126 * @param int $value 60 127 * @return void 61 * @psalm-suppress MixedArrayOffset62 128 */ 63 129 #[ReturnTypeWillChange] … … 67 133 throw new InvalidArgumentException('Expected an integer'); 68 134 } 69 if (is_null($offset)) { 70 $this->container[] = $value; 71 } else { 72 $this->container[$offset] = $value; 135 switch ($offset) { 136 case 0: 137 $this->e0 = $value; 138 break; 139 case 1: 140 $this->e1 = $value; 141 break; 142 case 2: 143 $this->e2 = $value; 144 break; 145 case 3: 146 $this->e3 = $value; 147 break; 148 case 4: 149 $this->e4 = $value; 150 break; 151 case 5: 152 $this->e5 = $value; 153 break; 154 case 6: 155 $this->e6 = $value; 156 break; 157 case 7: 158 $this->e7 = $value; 159 break; 160 case 8: 161 $this->e8 = $value; 162 break; 163 case 9: 164 $this->e9 = $value; 165 break; 166 default: 167 throw new OutOfBoundsException('Index out of bounds'); 73 168 } 74 169 } … … 79 174 * @param int $offset 80 175 * @return bool 81 * @psalm-suppress MixedArrayOffset82 176 */ 83 177 #[ReturnTypeWillChange] 84 178 public function offsetExists($offset) 85 179 { 86 return isset($this->container[$offset]);180 return $offset >= 0 && $offset < 10; 87 181 } 88 182 … … 92 186 * @param int $offset 93 187 * @return void 94 * @psalm-suppress MixedArrayOffset95 188 */ 96 189 #[ReturnTypeWillChange] 97 190 public function offsetUnset($offset) 98 191 { 99 unset($this->container[$offset]); 192 switch ($offset) { 193 case 0: 194 $this->e0 = 0; 195 break; 196 case 1: 197 $this->e1 = 0; 198 break; 199 case 2: 200 $this->e2 = 0; 201 break; 202 case 3: 203 $this->e3 = 0; 204 break; 205 case 4: 206 $this->e4 = 0; 207 break; 208 case 5: 209 $this->e5 = 0; 210 break; 211 case 6: 212 $this->e6 = 0; 213 break; 214 case 7: 215 $this->e7 = 0; 216 break; 217 case 8: 218 $this->e8 = 0; 219 break; 220 case 9: 221 $this->e9 = 0; 222 break; 223 default: 224 throw new OutOfBoundsException('Index out of bounds'); 225 } 100 226 } 101 227 … … 105 231 * @param int $offset 106 232 * @return int 107 * @psalm-suppress MixedArrayOffset108 233 */ 109 234 #[ReturnTypeWillChange] 110 235 public function offsetGet($offset) 111 236 { 112 if (!isset($this->container[$offset])) { 113 $this->container[$offset] = 0; 114 } 115 return (int) ($this->container[$offset]); 237 switch ($offset) { 238 case 0: 239 return (int) $this->e0; 240 case 1: 241 return (int) $this->e1; 242 case 2: 243 return (int) $this->e2; 244 case 3: 245 return (int) $this->e3; 246 case 4: 247 return (int) $this->e4; 248 case 5: 249 return (int) $this->e5; 250 case 6: 251 return (int) $this->e6; 252 case 7: 253 return (int) $this->e7; 254 case 8: 255 return (int) $this->e8; 256 case 9: 257 return (int) $this->e9; 258 default: 259 throw new OutOfBoundsException('Index out of bounds'); 260 } 116 261 } 117 262 … … 123 268 public function __debugInfo() 124 269 { 125 return array(implode(', ', $this->container)); 270 return array( 271 implode(', ', array( 272 $this->e0, $this->e1, $this->e2, $this->e3, $this->e4, 273 $this->e5, $this->e6, $this->e7, $this->e8, $this->e9 274 )) 275 ); 126 276 } 127 277 } -
trunk/src/wp-includes/sodium_compat/src/Core/Ed25519.php
r54150 r60905 47 47 { 48 48 if (self::strlen($seed) !== self::SEED_BYTES) { 49 throw new RangeException('crypto_sign keypair seed must be 32 bytes long');49 throw new SodiumException('crypto_sign keypair seed must be 32 bytes long'); 50 50 } 51 51 … … 66 66 { 67 67 if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { 68 throw new RangeException('crypto_sign keypair must be 96 bytes long');68 throw new SodiumException('crypto_sign keypair must be 96 bytes long'); 69 69 } 70 70 return self::substr($keypair, 0, 64); … … 81 81 { 82 82 if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { 83 throw new RangeException('crypto_sign keypair must be 96 bytes long');83 throw new SodiumException('crypto_sign keypair must be 96 bytes long'); 84 84 } 85 85 return self::substr($keypair, 64, 32); … … 213 213 public static function sign_detached($message, $sk) 214 214 { 215 if (self::strlen($sk) !== 64) { 216 throw new SodiumException('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES long'); 217 } 215 218 # crypto_hash_sha512(az, sk, 32); 216 219 $az = hash('sha512', self::substr($sk, 0, 32), true); … … 278 281 public static function verify_detached($sig, $message, $pk) 279 282 { 280 if (self::strlen($sig) < 64) { 281 throw new SodiumException('Signature is too short'); 283 if (self::strlen($sig) !== 64) { 284 throw new SodiumException('Argument 1 must be CRYPTO_SIGN_BYTES long'); 285 } 286 if (self::strlen($pk) !== 32) { 287 throw new SodiumException('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES long'); 282 288 } 283 289 if ((self::chrToInt($sig[63]) & 240) && self::check_S_lt_L(self::substr($sig, 32, 32))) { -
trunk/src/wp-includes/sodium_compat/src/Core/HChaCha20.php
r46586 r60905 15 15 * @param string|null $c 16 16 * @return string 17 * 18 * @throws SodiumException 17 19 * @throws TypeError 18 20 */ 19 public static function hChaCha20($in = '', $key = '', $c = null)21 public static function hChaCha20($in, $key, $c = null) 20 22 { 23 if (self::strlen($in) !== 16) { 24 throw new SodiumException('Argument 1 must be 16 bytes'); 25 } 26 if (self::strlen($key) !== 32) { 27 throw new SodiumException('Argument 2 must be 32 bytes'); 28 } 21 29 $ctx = array(); 22 30 -
trunk/src/wp-includes/sodium_compat/src/Core/Poly1305.php
r46586 r60905 23 23 public static function onetimeauth($m, $key) 24 24 { 25 if (self::strlen($key) <32) {25 if (self::strlen($key) !== 32) { 26 26 throw new InvalidArgumentException( 27 27 'Key must be 32 bytes long.' -
trunk/src/wp-includes/sodium_compat/src/Core/Util.php
r58752 r60905 182 182 $left = str_pad($left, $len, "\x00", STR_PAD_RIGHT); 183 183 $right = str_pad($right, $len, "\x00", STR_PAD_RIGHT); 184 } elseif ($leftLen !== $rightLen) { 185 throw new SodiumException("Argument #1 and argument #2 must have the same length"); 184 186 } 185 187 … … 337 339 * @param bool $strictPadding 338 340 * @return string (raw binary) 339 * @throws RangeException 341 * 342 * @throws SodiumException 340 343 * @throws TypeError 341 344 */ … … 355 358 $hex_len = self::strlen($hexString); 356 359 $state = 0; 357 if (($hex_len & 1) !== 0) {358 if ($strictPadding) {359 throw new RangeException(360 'Expected an even number of hexadecimal characters'361 );362 } else {363 $hexString = '0' . $hexString;364 ++$hex_len;365 }366 }367 360 368 361 $chunk = unpack('C*', $hexString); … … 391 384 $state ^= 1; 392 385 } 386 if ($strictPadding && $state !== 0) { 387 throw new SodiumException( 388 'Expected an even number of hexadecimal characters' 389 ); 390 } 393 391 return $bin; 394 392 } … … 535 533 public static function memcmp($left, $right) 536 534 { 537 if (self::hashEquals($left, $right)) { 538 return 0; 539 } 540 return -1; 535 $e = (int) !self::hashEquals($left, $right); 536 return 0 - $e; 541 537 } 542 538 -
trunk/src/wp-includes/sodium_compat/src/Core/X25519.php
r46586 r60905 26 26 $b = 0 27 27 ) { 28 $f0 = (int) $f[0];29 $f1 = (int) $f[1];30 $f2 = (int) $f[2];31 $f3 = (int) $f[3];32 $f4 = (int) $f[4];33 $f5 = (int) $f[5];34 $f6 = (int) $f[6];35 $f7 = (int) $f[7];36 $f8 = (int) $f[8];37 $f9 = (int) $f[9];38 $g0 = (int) $g[0];39 $g1 = (int) $g[1];40 $g2 = (int) $g[2];41 $g3 = (int) $g[3];42 $g4 = (int) $g[4];43 $g5 = (int) $g[5];44 $g6 = (int) $g[6];45 $g7 = (int) $g[7];46 $g8 = (int) $g[8];47 $g9 = (int) $g[9];48 28 $b = -$b; 49 $x0 = ($f 0 ^ $g0) & $b;50 $x1 = ($f 1 ^ $g1) & $b;51 $x2 = ($f 2 ^ $g2) & $b;52 $x3 = ($f 3 ^ $g3) & $b;53 $x4 = ($f 4 ^ $g4) & $b;54 $x5 = ($f 5 ^ $g5) & $b;55 $x6 = ($f 6 ^ $g6) & $b;56 $x7 = ($f 7 ^ $g7) & $b;57 $x8 = ($f 8 ^ $g8) & $b;58 $x9 = ($f 9 ^ $g9) & $b;59 $f [0] = $f0 ^$x0;60 $f [1] = $f1 ^$x1;61 $f [2] = $f2 ^$x2;62 $f [3] = $f3 ^$x3;63 $f [4] = $f4 ^$x4;64 $f [5] = $f5 ^$x5;65 $f [6] = $f6 ^$x6;66 $f [7] = $f7 ^$x7;67 $f [8] = $f8 ^$x8;68 $f [9] = $f9 ^$x9;69 $g [0] = $g0 ^$x0;70 $g [1] = $g1 ^$x1;71 $g [2] = $g2 ^$x2;72 $g [3] = $g3 ^$x3;73 $g [4] = $g4 ^$x4;74 $g [5] = $g5 ^$x5;75 $g [6] = $g6 ^$x6;76 $g [7] = $g7 ^$x7;77 $g [8] = $g8 ^$x8;78 $g [9] = $g9 ^$x9;29 $x0 = ($f->e0 ^ $g->e0) & $b; 30 $x1 = ($f->e1 ^ $g->e1) & $b; 31 $x2 = ($f->e2 ^ $g->e2) & $b; 32 $x3 = ($f->e3 ^ $g->e3) & $b; 33 $x4 = ($f->e4 ^ $g->e4) & $b; 34 $x5 = ($f->e5 ^ $g->e5) & $b; 35 $x6 = ($f->e6 ^ $g->e6) & $b; 36 $x7 = ($f->e7 ^ $g->e7) & $b; 37 $x8 = ($f->e8 ^ $g->e8) & $b; 38 $x9 = ($f->e9 ^ $g->e9) & $b; 39 $f->e0 ^= $x0; 40 $f->e1 ^= $x1; 41 $f->e2 ^= $x2; 42 $f->e3 ^= $x3; 43 $f->e4 ^= $x4; 44 $f->e5 ^= $x5; 45 $f->e6 ^= $x6; 46 $f->e7 ^= $x7; 47 $f->e8 ^= $x8; 48 $f->e9 ^= $x9; 49 $g->e0 ^= $x0; 50 $g->e1 ^= $x1; 51 $g->e2 ^= $x2; 52 $g->e3 ^= $x3; 53 $g->e4 ^= $x4; 54 $g->e5 ^= $x5; 55 $g->e6 ^= $x6; 56 $g->e7 ^= $x7; 57 $g->e8 ^= $x8; 58 $g->e9 ^= $x9; 79 59 } 80 60 … … 87 67 public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) 88 68 { 89 $h = array( 90 self::mul((int) $f[0], 121666, 17), 91 self::mul((int) $f[1], 121666, 17), 92 self::mul((int) $f[2], 121666, 17), 93 self::mul((int) $f[3], 121666, 17), 94 self::mul((int) $f[4], 121666, 17), 95 self::mul((int) $f[5], 121666, 17), 96 self::mul((int) $f[6], 121666, 17), 97 self::mul((int) $f[7], 121666, 17), 98 self::mul((int) $f[8], 121666, 17), 99 self::mul((int) $f[9], 121666, 17) 100 ); 101 102 /** @var int $carry9 */ 103 $carry9 = ($h[9] + (1 << 24)) >> 25; 104 $h[0] += self::mul($carry9, 19, 5); 105 $h[9] -= $carry9 << 25; 106 /** @var int $carry1 */ 107 $carry1 = ($h[1] + (1 << 24)) >> 25; 108 $h[2] += $carry1; 109 $h[1] -= $carry1 << 25; 110 /** @var int $carry3 */ 111 $carry3 = ($h[3] + (1 << 24)) >> 25; 112 $h[4] += $carry3; 113 $h[3] -= $carry3 << 25; 114 /** @var int $carry5 */ 115 $carry5 = ($h[5] + (1 << 24)) >> 25; 116 $h[6] += $carry5; 117 $h[5] -= $carry5 << 25; 118 /** @var int $carry7 */ 119 $carry7 = ($h[7] + (1 << 24)) >> 25; 120 $h[8] += $carry7; 121 $h[7] -= $carry7 << 25; 122 123 /** @var int $carry0 */ 124 $carry0 = ($h[0] + (1 << 25)) >> 26; 125 $h[1] += $carry0; 126 $h[0] -= $carry0 << 26; 127 /** @var int $carry2 */ 128 $carry2 = ($h[2] + (1 << 25)) >> 26; 129 $h[3] += $carry2; 130 $h[2] -= $carry2 << 26; 131 /** @var int $carry4 */ 132 $carry4 = ($h[4] + (1 << 25)) >> 26; 133 $h[5] += $carry4; 134 $h[4] -= $carry4 << 26; 135 /** @var int $carry6 */ 136 $carry6 = ($h[6] + (1 << 25)) >> 26; 137 $h[7] += $carry6; 138 $h[6] -= $carry6 << 26; 139 /** @var int $carry8 */ 140 $carry8 = ($h[8] + (1 << 25)) >> 26; 141 $h[9] += $carry8; 142 $h[8] -= $carry8 << 26; 143 144 foreach ($h as $i => $value) { 145 $h[$i] = (int) $value; 146 } 147 return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); 69 $h0 = self::mul($f->e0, 121666, 17); 70 $h1 = self::mul($f->e1, 121666, 17); 71 $h2 = self::mul($f->e2, 121666, 17); 72 $h3 = self::mul($f->e3, 121666, 17); 73 $h4 = self::mul($f->e4, 121666, 17); 74 $h5 = self::mul($f->e5, 121666, 17); 75 $h6 = self::mul($f->e6, 121666, 17); 76 $h7 = self::mul($f->e7, 121666, 17); 77 $h8 = self::mul($f->e8, 121666, 17); 78 $h9 = self::mul($f->e9, 121666, 17); 79 80 $carry9 = ($h9 + (1 << 24)) >> 25; 81 $h0 += self::mul($carry9, 19, 5); 82 $h9 -= $carry9 << 25; 83 84 $carry1 = ($h1 + (1 << 24)) >> 25; 85 $h2 += $carry1; 86 $h1 -= $carry1 << 25; 87 88 $carry3 = ($h3 + (1 << 24)) >> 25; 89 $h4 += $carry3; 90 $h3 -= $carry3 << 25; 91 92 $carry5 = ($h5 + (1 << 24)) >> 25; 93 $h6 += $carry5; 94 $h5 -= $carry5 << 25; 95 96 $carry7 = ($h7 + (1 << 24)) >> 25; 97 $h8 += $carry7; 98 $h7 -= $carry7 << 25; 99 100 101 $carry0 = ($h0 + (1 << 25)) >> 26; 102 $h1 += $carry0; 103 $h0 -= $carry0 << 26; 104 105 $carry2 = ($h2 + (1 << 25)) >> 26; 106 $h3 += $carry2; 107 $h2 -= $carry2 << 26; 108 109 $carry4 = ($h4 + (1 << 25)) >> 26; 110 $h5 += $carry4; 111 $h4 -= $carry4 << 26; 112 113 $carry6 = ($h6 + (1 << 25)) >> 26; 114 $h7 += $carry6; 115 $h6 -= $carry6 << 26; 116 117 $carry8 = ($h8 + (1 << 25)) >> 26; 118 $h9 += $carry8; 119 $h8 -= $carry8 << 26; 120 return new ParagonIE_Sodium_Core_Curve25519_Fe($h0, $h1, $h2, $h3, $h4, $h5, $h6, $h7, $h8, $h9); 148 121 } 149 122 -
trunk/src/wp-includes/sodium_compat/src/Core/XChaCha20.php
r46858 r60905 20 20 * @throws TypeError 21 21 */ 22 public static function stream($len = 64, $nonce = '', $key = '')22 public static function stream($len, $nonce, $key) 23 23 { 24 24 if (self::strlen($nonce) !== 24) { … … 47 47 * @throws TypeError 48 48 */ 49 public static function ietfStream($len = 64, $nonce = '', $key = '')49 public static function ietfStream($len, $nonce, $key) 50 50 { 51 51 if (self::strlen($nonce) !== 24) { … … 75 75 * @throws TypeError 76 76 */ 77 public static function streamXorIc($message, $nonce = '', $key = '', $ic = '')77 public static function streamXorIc($message, $nonce, $key, $ic = '') 78 78 { 79 79 if (self::strlen($nonce) !== 24) { … … 101 101 * @throws TypeError 102 102 */ 103 public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '')103 public static function ietfStreamXorIc($message, $nonce, $key, $ic = '') 104 104 { 105 105 if (self::strlen($nonce) !== 24) { -
trunk/src/wp-includes/sodium_compat/src/Crypto.php
r46858 r60905 1189 1189 1190 1190 /** @var string $subkey */ 1191 $subkey = ParagonIE_Sodium_Core_HChaCha20::hchacha20($nonce, $key); 1191 $subkey = ParagonIE_Sodium_Core_HChaCha20::hchacha20( 1192 ParagonIE_Sodium_Core_Util::substr($nonce, 0, 16), 1193 $key 1194 ); 1192 1195 1193 1196 /** @var string $block0 */ … … 1245 1248 1246 1249 # crypto_core_hchacha20(state->k, out, k, NULL); 1247 $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20($out, $key); 1250 $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( 1251 ParagonIE_Sodium_Core_Util::substr($out, 0, 16), 1252 $key 1253 ); 1248 1254 $state = new ParagonIE_Sodium_Core_SecretStream_State( 1249 1255 $subkey, -
trunk/src/wp-includes/sodium_compat/src/File.php
r58752 r60905 126 126 } 127 127 128 if (!file_exists($inputFile)) { 129 throw new SodiumException('Input file does not exist'); 130 } 128 131 /** @var int $size */ 129 132 $size = filesize($inputFile); … … 139 142 140 143 /** @var resource $ofp */ 141 $ofp = fopen($outputFile, 'wb');144 $ofp = @fopen($outputFile, 'wb'); 142 145 if (!is_resource($ofp)) { 143 146 fclose($ifp); … … 194 197 } 195 198 199 if (!file_exists($inputFile)) { 200 throw new SodiumException('Input file does not exist'); 201 } 196 202 /** @var int $size */ 197 203 $size = filesize($inputFile); … … 207 213 208 214 /** @var resource $ofp */ 209 $ofp = fopen($outputFile, 'wb');215 $ofp = @fopen($outputFile, 'wb'); 210 216 if (!is_resource($ofp)) { 211 217 fclose($ifp); … … 304 310 $publicKey = ParagonIE_Sodium_Compat::crypto_box_publickey($ecdhKeypair); 305 311 312 if (!file_exists($inputFile)) { 313 throw new SodiumException('Input file does not exist'); 314 } 306 315 /** @var int $size */ 307 316 $size = filesize($inputFile); … … 317 326 318 327 /** @var resource $ofp */ 319 $ofp = fopen($outputFile, 'wb');328 $ofp = @fopen($outputFile, 'wb'); 320 329 if (!is_resource($ofp)) { 321 330 fclose($ifp); … … 409 418 } 410 419 420 if (!file_exists($filePath)) { 421 throw new SodiumException('File does not exist'); 422 } 411 423 /** @var int $size */ 412 424 $size = filesize($filePath); … … 480 492 } 481 493 494 if (!file_exists($inputFile)) { 495 throw new SodiumException('Input file does not exist'); 496 } 482 497 /** @var int $size */ 483 498 $size = filesize($inputFile); … … 487 502 488 503 /** @var resource $ifp */ 489 $ifp = fopen($inputFile, 'rb');504 $ifp = @fopen($inputFile, 'rb'); 490 505 if (!is_resource($ifp)) { 491 506 throw new SodiumException('Could not open input file for reading'); … … 544 559 /* Input validation: */ 545 560 if (self::strlen($nonce) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_NONCEBYTES) { 546 throw new TypeError('Argument 4must be CRYPTO_SECRETBOX_NONCEBYTES bytes');561 throw new TypeError('Argument 3 must be CRYPTO_SECRETBOX_NONCEBYTES bytes'); 547 562 } 548 563 if (self::strlen($key) !== ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_KEYBYTES) { 549 throw new TypeError('Argument 4 must be CRYPTO_SECRETBOXBOX_KEYBYTES bytes'); 550 } 551 564 throw new TypeError('Argument 4 must be CRYPTO_SECRETBOX_KEYBYTES bytes'); 565 } 566 567 if (!file_exists($inputFile)) { 568 throw new SodiumException('Input file does not exist'); 569 } 552 570 /** @var int $size */ 553 571 $size = filesize($inputFile); … … 563 581 564 582 /** @var resource $ofp */ 565 $ofp = fopen($outputFile, 'wb');583 $ofp = @fopen($outputFile, 'wb'); 566 584 if (!is_resource($ofp)) { 567 585 fclose($ifp); … … 614 632 } 615 633 634 if (!file_exists($filePath)) { 635 throw new SodiumException('File does not exist'); 636 } 616 637 /** @var int $size */ 617 638 $size = filesize($filePath); … … 745 766 } 746 767 768 if (!file_exists($filePath)) { 769 throw new SodiumException('File does not exist'); 770 } 747 771 /** @var int $size */ 748 772 $size = filesize($filePath);
Note: See TracChangeset
for help on using the changeset viewer.