} while (x.compareTo(q) >= 0);
e = G.modPow(x, p);
KexDHInitMessage init = new KexDHInitMessage();
init.setE(e);
transport.writeMessage(init);
KexDHReplyMessage reply = (KexDHReplyMessage)transport
.readMessage(NAMESPACE);
BigInteger f = reply.getF();
k = f.modPow(x, p);
byte[] ks = reply.getKS();
if (!hv.isTrusted(transport, reply.getKeyFormat(), ks)) {
throw new SSHException("Server host key not trusted");
}
SSHPublicKey pubkey = pkf.decode(ks);
Signature verifier = pubkey.getVerifier();
dg.reset();
dg.update(Utils.encodeBytes(transport.getVC()));
dg.update(Utils.encodeBytes(transport.getVS()));
dg.update(Utils.encodeBytes(transport.getIC()));
dg.update(Utils.encodeBytes(transport.getIS()));
dg.update(Utils.encodeBytes(reply.getKS()));
dg.update(Utils.encodeBigInt(e));
dg.update(Utils.encodeBigInt(f));
dg.update(Utils.encodeBigInt(k));
h = dg.digest();
try {
verifier.update(h);
if(!verifier.verify(reply.getSigBlob())) {
GlieseLogger.LOGGER.warn("Server authentication failed.");
throw new SSHException("Server authentication failed.");
}
} catch (SignatureException se) {
// FIXME