wp/wp-includes/sodium_compat/src/Core32/Ed25519.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   205      * @param string $message
   205      * @param string $message
   206      * @param string $sk
   206      * @param string $sk
   207      * @return string
   207      * @return string
   208      * @throws SodiumException
   208      * @throws SodiumException
   209      * @throws TypeError
   209      * @throws TypeError
       
   210      * @psalm-suppress PossiblyInvalidArgument
   210      */
   211      */
   211     public static function sign_detached($message, $sk)
   212     public static function sign_detached($message, $sk)
   212     {
   213     {
   213         # crypto_hash_sha512(az, sk, 32);
   214         # crypto_hash_sha512(az, sk, 32);
   214         $az =  hash('sha512', self::substr($sk, 0, 32), true);
   215         $az =  hash('sha512', self::substr($sk, 0, 32), true);
   222         # crypto_hash_sha512_init(&hs);
   223         # crypto_hash_sha512_init(&hs);
   223         # crypto_hash_sha512_update(&hs, az + 32, 32);
   224         # crypto_hash_sha512_update(&hs, az + 32, 32);
   224         # crypto_hash_sha512_update(&hs, m, mlen);
   225         # crypto_hash_sha512_update(&hs, m, mlen);
   225         # crypto_hash_sha512_final(&hs, nonce);
   226         # crypto_hash_sha512_final(&hs, nonce);
   226         $hs = hash_init('sha512');
   227         $hs = hash_init('sha512');
   227         hash_update($hs, self::substr($az, 32, 32));
   228         self::hash_update($hs, self::substr($az, 32, 32));
   228         hash_update($hs, $message);
   229         self::hash_update($hs, $message);
   229         $nonceHash = hash_final($hs, true);
   230         $nonceHash = hash_final($hs, true);
   230 
   231 
   231         # memmove(sig + 32, sk + 32, 32);
   232         # memmove(sig + 32, sk + 32, 32);
   232         $pk = self::substr($sk, 32, 32);
   233         $pk = self::substr($sk, 32, 32);
   233 
   234 
   242         # crypto_hash_sha512_init(&hs);
   243         # crypto_hash_sha512_init(&hs);
   243         # crypto_hash_sha512_update(&hs, sig, 64);
   244         # crypto_hash_sha512_update(&hs, sig, 64);
   244         # crypto_hash_sha512_update(&hs, m, mlen);
   245         # crypto_hash_sha512_update(&hs, m, mlen);
   245         # crypto_hash_sha512_final(&hs, hram);
   246         # crypto_hash_sha512_final(&hs, hram);
   246         $hs = hash_init('sha512');
   247         $hs = hash_init('sha512');
   247         hash_update($hs, self::substr($sig, 0, 32));
   248         self::hash_update($hs, self::substr($sig, 0, 32));
   248         hash_update($hs, self::substr($pk, 0, 32));
   249         self::hash_update($hs, self::substr($pk, 0, 32));
   249         hash_update($hs, $message);
   250         self::hash_update($hs, $message);
   250         $hramHash = hash_final($hs, true);
   251         $hramHash = hash_final($hs, true);
   251 
   252 
   252         # sc_reduce(hram);
   253         # sc_reduce(hram);
   253         # sc_muladd(sig + 32, hram, az, nonce);
   254         # sc_muladd(sig + 32, hram, az, nonce);
   254         $hram = self::sc_reduce($hramHash);
   255         $hram = self::sc_reduce($hramHash);