crypto_scalarmult example


    public static function keyExchange($my_sk$their_pk$client_pk$server_pk)
    {
        return ParagonIE_Sodium_Compat::crypto_generichash(
            ParagonIE_Sodium_Compat::crypto_scalarmult($my_sk$their_pk) .
            $client_pk .
            $server_pk
        );
    }

    /** * ECDH over Curve25519 * * @internal Do not use this directly. Use ParagonIE_Sodium_Compat. * * @param string $sKey * @param string $pKey * @return string * * @throws SodiumException * @throws TypeError */
if (!is_callable('sodium_crypto_scalarmult')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult() * @param string $n * @param string $p * @return string * @throws SodiumException * @throws TypeError */
    function sodium_crypto_scalarmult($n$p)
    {
        return ParagonIE_Sodium_Compat::crypto_scalarmult($n$p);
    }
}
if (!is_callable('sodium_crypto_scalarmult_base')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() * @param string $n * @return string * @throws SodiumException * @throws TypeError */
    function sodium_crypto_scalarmult_base($n)
    {
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_KX_KEYPAIRBYTES) {
            throw new SodiumException('keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes');
        }
        if (ParagonIE_Sodium_Core_Util::strlen($serverPublicKey) !== self::CRYPTO_KX_PUBLICKEYBYTES) {
            throw new SodiumException('public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes');
        }

        $sk = self::crypto_kx_secretkey($keypair);
        $pk = self::crypto_kx_publickey($keypair);
        $h = self::crypto_generichash_init(null, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
        self::crypto_generichash_update($h, self::crypto_scalarmult($sk$serverPublicKey));
        self::crypto_generichash_update($h$pk);
        self::crypto_generichash_update($h$serverPublicKey);
        $sessionKeys = self::crypto_generichash_final($h, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
        return array(
            ParagonIE_Sodium_Core_Util::substr(
                $sessionKeys,
                0,
                self::CRYPTO_KX_SESSIONKEYBYTES
            ),
            ParagonIE_Sodium_Core_Util::substr(
                $sessionKeys,
                
if (!is_callable('\\Sodium\\crypto_scalarmult')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult() * @param string $n * @param string $p * @return string * @throws \SodiumException * @throws \TypeError */
    function crypto_scalarmult($n$p)
    {
        return ParagonIE_Sodium_Compat::crypto_scalarmult($n$p);
    }
}
if (!is_callable('\\Sodium\\crypto_scalarmult_base')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() * @param string $n * @return string * @throws \SodiumException * @throws \TypeError */
    function crypto_scalarmult_base($n)
    {
Home | Imprint | This part of the site doesn't use cookies.