- Timestamp:
- 06/16/2021 05:28:49 PM (4 years ago)
- Location:
- branches/5.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.7
-
branches/5.7/src/wp-includes/sodium_compat/src/Core/Ed25519.php
r48121 r51171 12 12 const KEYPAIR_BYTES = 96; 13 13 const SEED_BYTES = 32; 14 const SCALAR_BYTES = 32; 14 15 15 16 /** … … 478 479 return false; 479 480 } 481 482 /** 483 * @param string $s 484 * @return string 485 * @throws SodiumException 486 */ 487 public static function scalar_complement($s) 488 { 489 $t_ = self::L . str_repeat("\x00", 32); 490 sodium_increment($t_); 491 $s_ = $s . str_repeat("\x00", 32); 492 ParagonIE_Sodium_Compat::sub($t_, $s_); 493 return self::sc_reduce($t_); 494 } 495 496 /** 497 * @return string 498 * @throws SodiumException 499 */ 500 public static function scalar_random() 501 { 502 do { 503 $r = ParagonIE_Sodium_Compat::randombytes_buf(self::SCALAR_BYTES); 504 $r[self::SCALAR_BYTES - 1] = self::intToChr( 505 self::chrToInt($r[self::SCALAR_BYTES - 1]) & 0x1f 506 ); 507 } while ( 508 !self::check_S_lt_L($r) || ParagonIE_Sodium_Compat::is_zero($r) 509 ); 510 return $r; 511 } 512 513 /** 514 * @param string $s 515 * @return string 516 * @throws SodiumException 517 */ 518 public static function scalar_negate($s) 519 { 520 $t_ = self::L . str_repeat("\x00", 32) ; 521 $s_ = $s . str_repeat("\x00", 32) ; 522 ParagonIE_Sodium_Compat::sub($t_, $s_); 523 return self::sc_reduce($t_); 524 } 525 526 /** 527 * @param string $a 528 * @param string $b 529 * @return string 530 * @throws SodiumException 531 */ 532 public static function scalar_add($a, $b) 533 { 534 $a_ = $a . str_repeat("\x00", 32); 535 $b_ = $b . str_repeat("\x00", 32); 536 ParagonIE_Sodium_Compat::add($a_, $b_); 537 return self::sc_reduce($a_); 538 } 539 540 /** 541 * @param string $x 542 * @param string $y 543 * @return string 544 * @throws SodiumException 545 */ 546 public static function scalar_sub($x, $y) 547 { 548 $yn = self::scalar_negate($y); 549 return self::scalar_add($x, $yn); 550 } 480 551 }
Note: See TracChangeset
for help on using the changeset viewer.