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