- Timestamp:
- 12/09/2019 04:40:11 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/sodium_compat/src/Core/BLAKE2b.php
r46586 r46858 89 89 $l = ($x[1] + $y[1]) & 0xffffffff; 90 90 return self::new64( 91 $x[0] + $y[0] + (91 (int) ($x[0] + $y[0] + ( 92 92 ($l < $x[1]) ? 1 : 0 93 ) ,94 $l93 )), 94 (int) $l 95 95 ); 96 96 } … … 133 133 } 134 134 return self::new64( 135 (int) ( $x[0] ^ $y[0]),136 (int) ( $x[1] ^ $y[1])135 (int) (($x[0] ^ $y[0]) & 0xffffffff), 136 (int) (($x[1] ^ $y[1]) & 0xffffffff) 137 137 ); 138 138 } … … 300 300 protected static function context() 301 301 { 302 $ctx = new SplFixedArray( 5);302 $ctx = new SplFixedArray(6); 303 303 $ctx[0] = new SplFixedArray(8); // h 304 304 $ctx[1] = new SplFixedArray(2); // t … … 306 306 $ctx[3] = new SplFixedArray(256); // buf 307 307 $ctx[4] = 0; // buflen 308 $ctx[5] = 0; // last_node (uint8_t) 308 309 309 310 for ($i = 8; $i--;) { … … 551 552 * @param SplFixedArray|null $key 552 553 * @param int $outlen 554 * @param SplFixedArray|null $salt 555 * @param SplFixedArray|null $personal 553 556 * @return SplFixedArray 554 557 * @throws SodiumException … … 560 563 * @psalm-suppress MixedArrayOffset 561 564 */ 562 public static function init($key = null, $outlen = 64) 563 { 565 public static function init( 566 $key = null, 567 $outlen = 64, 568 $salt = null, 569 $personal = null 570 ) { 564 571 self::pseudoConstructor(); 565 572 $klen = 0; … … 579 586 580 587 $p = new SplFixedArray(64); 588 // Zero our param buffer... 581 589 for ($i = 64; --$i;) { 582 590 $p[$i] = 0; … … 588 596 $p[3] = 1; // depth 589 597 598 if ($salt instanceof SplFixedArray) { 599 // salt: [32] through [47] 600 for ($i = 0; $i < 16; ++$i) { 601 $p[32 + $i] = (int) $salt[$i]; 602 } 603 } 604 if ($personal instanceof SplFixedArray) { 605 // personal: [48] through [63] 606 for ($i = 0; $i < 16; ++$i) { 607 $p[48 + $i] = (int) $personal[$i]; 608 } 609 } 610 590 611 $ctx[0][0] = self::xor64( 591 612 $ctx[0][0], 592 613 self::load64($p, 0) 593 614 ); 615 if ($salt instanceof SplFixedArray || $personal instanceof SplFixedArray) { 616 // We need to do what blake2b_init_param() does: 617 for ($i = 1; $i < 8; ++$i) { 618 $ctx[0][$i] = self::xor64( 619 $ctx[0][$i], 620 self::load64($p, $i << 3) 621 ); 622 } 623 } 594 624 595 625 if ($klen > 0 && $key instanceof SplFixedArray) { … … 602 632 } 603 633 self::update($ctx, $block, 128); 634 $ctx[4] = 128; 604 635 } 605 636 … … 694 725 )); 695 726 # uint8_t last_node; 696 return $str . "\x00";727 return $str . self::intToChr($ctx[5]) . str_repeat("\x00", 23); 697 728 } 698 729 … … 747 778 $ctx[3] = self::stringToSplFixedArray(self::substr($string, 96, 256)); 748 779 749 750 780 # uint8_t buf[2 * 128]; 751 781 $int = 0;
Note: See TracChangeset
for help on using the changeset viewer.