- Timestamp:
- 12/09/2019 04:44:58 PM (5 years ago)
- Location:
- branches/5.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.3
-
branches/5.3/src/wp-includes/sodium_compat/src/Core32/BLAKE2b.php
r45344 r46859 224 224 protected static function context() 225 225 { 226 $ctx = new SplFixedArray( 5);226 $ctx = new SplFixedArray(6); 227 227 $ctx[0] = new SplFixedArray(8); // h 228 228 $ctx[1] = new SplFixedArray(2); // t … … 230 230 $ctx[3] = new SplFixedArray(256); // buf 231 231 $ctx[4] = 0; // buflen 232 $ctx[5] = 0; // last_node (uint8_t) 232 233 233 234 for ($i = 8; $i--;) { … … 483 484 * @param SplFixedArray|null $key 484 485 * @param int $outlen 486 * @param SplFixedArray|null $salt 487 * @param SplFixedArray|null $personal 485 488 * @return SplFixedArray 486 489 * @throws SodiumException … … 492 495 * @psalm-suppress MixedMethodCall 493 496 */ 494 public static function init($key = null, $outlen = 64) 495 { 497 public static function init( 498 $key = null, 499 $outlen = 64, 500 $salt = null, 501 $personal = null 502 ) { 496 503 self::pseudoConstructor(); 497 504 $klen = 0; … … 511 518 512 519 $p = new SplFixedArray(64); 520 // Zero our param buffer... 513 521 for ($i = 64; --$i;) { 514 522 $p[$i] = 0; … … 520 528 $p[3] = 1; // depth 521 529 530 if ($salt instanceof SplFixedArray) { 531 // salt: [32] through [47] 532 for ($i = 0; $i < 16; ++$i) { 533 $p[32 + $i] = (int) $salt[$i]; 534 } 535 } 536 if ($personal instanceof SplFixedArray) { 537 // personal: [48] through [63] 538 for ($i = 0; $i < 16; ++$i) { 539 $p[48 + $i] = (int) $personal[$i]; 540 } 541 } 542 522 543 $ctx[0][0] = self::xor64( 523 544 $ctx[0][0], … … 525 546 ); 526 547 548 if ($salt instanceof SplFixedArray || $personal instanceof SplFixedArray) { 549 // We need to do what blake2b_init_param() does: 550 for ($i = 1; $i < 8; ++$i) { 551 $ctx[0][$i] = self::xor64( 552 $ctx[0][$i], 553 self::load64($p, $i << 3) 554 ); 555 } 556 } 557 527 558 if ($klen > 0 && $key instanceof SplFixedArray) { 528 559 $block = new SplFixedArray(128); … … 534 565 } 535 566 self::update($ctx, $block, 128); 567 $ctx[4] = 128; 536 568 } 537 569 … … 596 628 /** @var ParagonIE_Sodium_Core32_Int64 $ctxAi */ 597 629 $ctxAi = $ctxA[$i]; 598 $str .= $ctxAi->to String();630 $str .= $ctxAi->toReverseString(); 599 631 } 600 632 … … 609 641 $ctxA2 = $ctxA[1]; 610 642 611 $str .= $ctxA1->to String();612 $str .= $ctxA2->to String();643 $str .= $ctxA1->toReverseString(); 644 $str .= $ctxA2->toReverseString(); 613 645 } 614 646 … … 625 657 self::intToChr(($ctx4 >> 16) & 0xff), 626 658 self::intToChr(($ctx4 >> 24) & 0xff), 659 "\x00\x00\x00\x00" 660 /* 627 661 self::intToChr(($ctx4 >> 32) & 0xff), 628 662 self::intToChr(($ctx4 >> 40) & 0xff), 629 663 self::intToChr(($ctx4 >> 48) & 0xff), 630 664 self::intToChr(($ctx4 >> 56) & 0xff) 665 */ 631 666 )); 632 667 # uint8_t last_node; 633 return $str . "\x00";668 return $str . self::intToChr($ctx[5]) . str_repeat("\x00", 23); 634 669 } 635 670 … … 653 688 # uint64_t h[8]; 654 689 for ($i = 0; $i < 8; ++$i) { 655 $ctx[0][$i] = ParagonIE_Sodium_Core32_Int64::from String(690 $ctx[0][$i] = ParagonIE_Sodium_Core32_Int64::fromReverseString( 656 691 self::substr($string, (($i << 3) + 0), 8) 657 692 ); … … 661 696 # uint64_t f[2]; 662 697 for ($i = 1; $i < 3; ++$i) { 663 $ctx[$i][1] = ParagonIE_Sodium_Core32_Int64::from String(698 $ctx[$i][1] = ParagonIE_Sodium_Core32_Int64::fromReverseString( 664 699 self::substr($string, 72 + (($i - 1) << 4), 8) 665 700 ); 666 $ctx[$i][0] = ParagonIE_Sodium_Core32_Int64::from String(701 $ctx[$i][0] = ParagonIE_Sodium_Core32_Int64::fromReverseString( 667 702 self::substr($string, 64 + (($i - 1) << 4), 8) 668 703 ); … … 671 706 # uint8_t buf[2 * 128]; 672 707 $ctx[3] = self::stringToSplFixedArray(self::substr($string, 96, 256)); 673 674 708 675 709 # uint8_t buf[2 * 128];
Note: See TracChangeset
for help on using the changeset viewer.