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,