byte[] MACc2s;
byte[] MACs2c;
byte[] K = kex.getK();
byte[] H = kex.getH();
Digest hash = kex.getHash();
Cipher s2ccipher;
Cipher c2scipher;
Mac s2cmac;
Mac c2smac;
Compression s2ccomp;
Compression c2scomp;
if (sessionId == null) {
sessionId = new byte[H.length];
System.arraycopy(H, 0, sessionId, 0, H.length);
}
Buffer buffer = new Buffer();
buffer.putMPInt(K);
buffer.putRawBytes(H);
buffer.putByte((byte) 0x41);
buffer.putRawBytes(sessionId);
int pos = buffer.available();
byte[] buf = buffer.array();
hash.update(buf, 0, pos);
IVc2s = hash.digest();
int j = pos - sessionId.length - 1;
buf[j]++;
hash.update(buf, 0, pos);
IVs2c = hash.digest();
buf[j]++;
hash.update(buf, 0, pos);
Ec2s = hash.digest();
buf[j]++;
hash.update(buf, 0, pos);
Es2c = hash.digest();
buf[j]++;
hash.update(buf, 0, pos);
MACc2s = hash.digest();
buf[j]++;
hash.update(buf, 0, pos);
MACs2c = hash.digest();
s2ccipher = NamedFactory.Utils.create(factoryManager.getCipherFactories(), negotiated[SshConstants.PROPOSAL_ENC_ALGS_STOC]);
Es2c = resizeKey(Es2c, s2ccipher.getBlockSize(), hash, K, H);
s2ccipher.init(isServer ? Cipher.Mode.Encrypt : Cipher.Mode.Decrypt, Es2c, IVs2c);
s2cmac = NamedFactory.Utils.create(factoryManager.getMacFactories(), negotiated[SshConstants.PROPOSAL_MAC_ALGS_STOC]);
MACs2c = resizeKey(MACs2c, s2cmac.getBlockSize(), hash, K, H);
s2cmac.init(MACs2c);
c2scipher = NamedFactory.Utils.create(factoryManager.getCipherFactories(), negotiated[SshConstants.PROPOSAL_ENC_ALGS_CTOS]);
Ec2s = resizeKey(Ec2s, c2scipher.getBlockSize(), hash, K, H);
c2scipher.init(isServer ? Cipher.Mode.Decrypt : Cipher.Mode.Encrypt, Ec2s, IVc2s);
c2smac = NamedFactory.Utils.create(factoryManager.getMacFactories(), negotiated[SshConstants.PROPOSAL_MAC_ALGS_CTOS]);
MACc2s = resizeKey(MACc2s, c2smac.getBlockSize(), hash, K, H);
c2smac.init(MACc2s);