def _finishEphemeralDH(self, remoteDHpublicKey):
        """
        Completes the Diffie-Hellman key agreement started by
        _startEphemeralDH, and forgets the ephemeral secret key.

        @type remoteDHpublicKey: L{int}
        @rtype: L{bytes}
        @return: The new shared secret, in SSH C{mpint} format.

        """

        remoteKey = dh.DHPublicNumbers(
            remoteDHpublicKey,
            dh.DHParameterNumbers(self.p, self.g)
        ).public_key(default_backend())
        secret = self.dhSecretKey.exchange(remoteKey)
        del self.dhSecretKey

        # The result of a Diffie-Hellman exchange is an integer, but
        # the Cryptography module returns it as bytes in a form that
        # is only vaguely documented. We fix it up to match the SSH
        # MP-integer format as described in RFC4251.
        secret = secret.lstrip(b'\x00')
        ch = ord(secret[0:1])
        if ch & 0x80:  # High bit set?
            # Make room for the sign bit
            prefix = struct.pack('>L', len(secret) + 1) + b'\x00'
        else:
            prefix = struct.pack('>L', len(secret))
        return prefix + secret

        Completes the Diffie-Hellman key agreement started by
        _startEphemeralDH, and forgets the ephemeral secret key.

        @type remoteDHpublicKey: L{int}
        @rtype: L{bytes}
        @return: The new shared secret, in SSH C{mpint} format.

        
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/ssh/transport.py