import hashlib


def gen_server_hash(server_id, shared_secret, public_key):
    """Generates the server hash for use in authentication.

    Parameters
    ----------
    server_id : :class:`str`
        The server id found in :class:`~.EncryptionRequestPacket`.
    shared_secret
        The shared secret gotten from :func:`gen_shared_secret`.
    public_key
        The public key found in :class:`~.EncryptionRequestPacket`.

    Returns
    -------
    :class:`str`
        The server hash.
    """

    h = hashlib.sha1()

    h.update(server_id.encode("ascii"))
    h.update(shared_secret)
    h.update(public_key)

    return f"{int.from_bytes(h.digest(), byteorder='big', signed=True):x}"