int inLen,
byte[] z)
throws InvalidCipherTextException
{
byte[] M = null;
KeyParameter macKey = null;
KDFParameters kParam = new KDFParameters(z, param.getDerivationV());
int macKeySize = param.getMacKeySize();
kdf.init(kParam);
inLen -= mac.getMacSize();
if (cipher == null) // stream mode
{
byte[] buf = new byte[inLen + (macKeySize / 8)];
M = new byte[inLen];
kdf.generateBytes(buf, 0, buf.length);
for (int i = 0; i != inLen; i++)
{
M[i] = (byte)(in_enc[inOff + i] ^ buf[i]);
}
macKey = new KeyParameter(buf, inLen, (macKeySize / 8));
}
else
{
int cipherKeySize = ((IESWithCipherParameters)param).getCipherKeySize();
byte[] buf = new byte[(cipherKeySize / 8) + (macKeySize / 8)];
cipher.init(false, new KeyParameter(buf, 0, (cipherKeySize / 8)));
byte[] tmp = new byte[cipher.getOutputSize(inLen)];
int off = cipher.processBytes(in_enc, inOff, inLen, tmp, 0);
off += cipher.doFinal(tmp, off);
M = new byte[off];
System.arraycopy(tmp, 0, M, 0, off);
macKey = new KeyParameter(buf, (cipherKeySize / 8), (macKeySize / 8));
}
byte[] macIV = param.getEncodingV();
mac.init(macKey);