wp/wp-includes/sodium_compat/src/Core/Ed25519.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
   274     public static function verify_detached($sig, $message, $pk)
   274     public static function verify_detached($sig, $message, $pk)
   275     {
   275     {
   276         if (self::strlen($sig) < 64) {
   276         if (self::strlen($sig) < 64) {
   277             throw new SodiumException('Signature is too short');
   277             throw new SodiumException('Signature is too short');
   278         }
   278         }
   279         if (self::check_S_lt_L(self::substr($sig, 32, 32))) {
   279         if ((self::chrToInt($sig[63]) & 240) && self::check_S_lt_L(self::substr($sig, 32, 32))) {
   280             throw new SodiumException('S < L - Invalid signature');
   280             throw new SodiumException('S < L - Invalid signature');
   281         }
   281         }
   282         if (self::small_order($sig)) {
   282         if (self::small_order($sig)) {
   283             throw new SodiumException('Signature is on too small of an order');
   283             throw new SodiumException('Signature is on too small of an order');
   284         }
   284         }
   374      * @throws SodiumException
   374      * @throws SodiumException
   375      * @throws TypeError
   375      * @throws TypeError
   376      */
   376      */
   377     public static function small_order($R)
   377     public static function small_order($R)
   378     {
   378     {
   379         /** @var array<int, array<int, int>> $blacklist */
   379         /** @var array<int, array<int, int>> $blocklist */
   380         $blacklist = array(
   380         $blocklist = array(
   381             /* 0 (order 4) */
   381             /* 0 (order 4) */
   382             array(
   382             array(
   383                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   383                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   384                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   384                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   385                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   385                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   461                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   461                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   462                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   462                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   463                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
   463                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
   464             )
   464             )
   465         );
   465         );
   466         /** @var int $countBlacklist */
   466         /** @var int $countBlocklist */
   467         $countBlacklist = count($blacklist);
   467         $countBlocklist = count($blocklist);
   468 
   468 
   469         for ($i = 0; $i < $countBlacklist; ++$i) {
   469         for ($i = 0; $i < $countBlocklist; ++$i) {
   470             $c = 0;
   470             $c = 0;
   471             for ($j = 0; $j < 32; ++$j) {
   471             for ($j = 0; $j < 32; ++$j) {
   472                 $c |= self::chrToInt($R[$j]) ^ (int) $blacklist[$i][$j];
   472                 $c |= self::chrToInt($R[$j]) ^ (int) $blocklist[$i][$j];
   473             }
   473             }
   474             if ($c === 0) {
   474             if ($c === 0) {
   475                 return true;
   475                 return true;
   476             }
   476             }
   477         }
   477         }