sc_reduce example

        $hs = hash_init('sha512');
        self::hash_update($hs, self::substr($az, 32, 32));
        self::hash_update($hs$message);
        $nonceHash = hash_final($hs, true);

        # memmove(sig + 32, sk + 32, 32);         $pk = self::substr($sk, 32, 32);

        # sc_reduce(nonce);         # ge_scalarmult_base(&R, nonce);         # ge_p3_tobytes(sig, &R);         $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32);
        $sig = self::ge_p3_tobytes(
            self::ge_scalarmult_base($nonce)
        );

        # crypto_hash_sha512_init(&hs);         # crypto_hash_sha512_update(&hs, sig, 64);         # crypto_hash_sha512_update(&hs, m, mlen);         # crypto_hash_sha512_final(&hs, hram);         $hs = hash_init('sha512');
        self::hash_update($hs, self::substr($sig, 0, 32));
        self::hash_update($hs, self::substr($pk, 0, 32));
        
self::hash_update($hs, self::substr($az, 32, 32));
        /** @var resource $hs */
        $hs = self::updateHashWithFile($hs$fp$size);

        /** @var string $nonceHash */
        $nonceHash = hash_final($hs, true);

        /** @var string $pk */
        $pk = self::substr($secretKey, 32, 32);

        /** @var string $nonce */
        $nonce = ParagonIE_Sodium_Core_Ed25519::sc_reduce($nonceHash) . self::substr($nonceHash, 32);

        /** @var string $sig */
        $sig = ParagonIE_Sodium_Core_Ed25519::ge_p3_tobytes(
            ParagonIE_Sodium_Core_Ed25519::ge_scalarmult_base($nonce)
        );

        $hs = hash_init('sha512');
        self::hash_update($hs, self::substr($sig, 0, 32));
        self::hash_update($hs, self::substr($pk, 0, 32));
        /** @var resource $hs */
        $hs = self::updateHashWithFile($hs$fp$size);

        
        $hs = hash_init('sha512');
        hash_update($hs, self::substr($az, 32, 32));
        hash_update($hs$message);
        $nonceHash = hash_final($hs, true);

        # memmove(sig + 32, sk + 32, 32);         $pk = self::substr($sk, 32, 32);

        # sc_reduce(nonce);         # ge_scalarmult_base(&R, nonce);         # ge_p3_tobytes(sig, &R);         $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32);
        $sig = self::ge_p3_tobytes(
            self::ge_scalarmult_base($nonce)
        );

        # crypto_hash_sha512_init(&hs);         # crypto_hash_sha512_update(&hs, sig, 64);         # crypto_hash_sha512_update(&hs, m, mlen);         # crypto_hash_sha512_final(&hs, hram);         $hs = hash_init('sha512');
        hash_update($hs, self::substr($sig, 0, 32));
        hash_update($hs, self::substr($pk, 0, 32));
        
/** * @param string $s * @param bool $dontFallback * @return string * @throws SodiumException */
    public static function ristretto255_scalar_reduce($s$dontFallback = false)
    {
        if (self::useNewSodiumAPI() && !$dontFallback) {
            return sodium_crypto_core_ristretto255_scalar_reduce($s);
        }
        return ParagonIE_Sodium_Core_Ristretto255::sc_reduce($s);
    }

    /** * Runtime testing method for 32-bit platforms. * * Usage: If runtime_speed_test() returns FALSE, then our 32-bit * implementation is to slow to use safely without risking timeouts. * If this happens, install sodium from PECL to get acceptable * performance. * * @param int $iterations Number of multiplications to attempt * @param int $maxTimeout Milliseconds * @return bool TRUE if we're fast enough, FALSE is not * @throws SodiumException */
$h[$i] = $h_be[self::HASH_SC_L - 1 - $i];
        }
        return self::ristretto255_scalar_reduce(self::intArrayToString($h));
    }

    /** * @param string $s * @return string */
    public static function ristretto255_scalar_reduce($s)
    {
        return self::sc_reduce($s);
    }

    /** * @param string $n * @param string $p * @return string * @throws SodiumException */
    public static function scalarmult_ristretto255($n$p)
    {
        if (self::strlen($n) !== 32) {
            
Home | Imprint | This part of the site doesn't use cookies.