'Called to handle the beginning of a non-group key exchange.
Unlike other message types, this is not dispatched automatically.  It
is called from C{ssh_KEX_DH_GEX_REQUEST_OLD} because an extra check is
required to determine if this is really a KEXDH_INIT message or if it
is a KEX_DH_GEX_REQUEST_OLD message.
The KEXDH_INIT payload::
integer e (the client\'s Diffie-Hellman public key)
We send the KEXDH_REPLY with our host key and signature.
@type packet: L{bytes}
@param packet: The message data.'

def _ssh_KEXDH_INIT(self, packet):

    (clientDHpublicKey, foo) = getMP(packet)
    y = _getRandomNumber(randbytes.secureRandom, 512)
    (self.g, self.p) = _kex.getDHGeneratorAndPrime(self.kexAlg)
    serverDHpublicKey = _MPpow(self.g, y, self.p)
    sharedSecret = _MPpow(clientDHpublicKey, y, self.p)
    h = sha1()
    h.update(NS(self.otherVersionString))
    h.update(NS(self.ourVersionString))
    h.update(NS(self.otherKexInitPayload))
    h.update(NS(self.ourKexInitPayload))
    h.update(NS(self.factory.publicKeys[self.keyAlg].blob()))
    h.update(MP(clientDHpublicKey))
    h.update(serverDHpublicKey)
    h.update(sharedSecret)
    exchangeHash = h.digest()
    self.sendPacket(MSG_KEXDH_REPLY, ((NS(self.factory.publicKeys[self.keyAlg].blob()) + serverDHpublicKey) + NS(self.factory.privateKeys[self.keyAlg].sign(exchangeHash))))
    self._keySetup(sharedSecret, exchangeHash)
