int inLen,
byte[] z)
throws InvalidCipherTextException
{
byte[] C = null;
KeyParameter macKey = null;
KDFParameters kParam = new KDFParameters(z, param.getDerivationV());
int c_text_length = 0;
int macKeySize = param.getMacKeySize();
if (cipher == null) // stream mode
{
byte[] buf = generateKdfBytes(kParam, inLen + (macKeySize / 8));
C = new byte[inLen + mac.getMacSize()];
c_text_length = inLen;
for (int i = 0; i != inLen; i++)
{
C[i] = (byte)(in[inOff + i] ^ buf[i]);
}
macKey = new KeyParameter(buf, inLen, (macKeySize / 8));
}
else
{
int cipherKeySize = ((IESWithCipherParameters)param).getCipherKeySize();
byte[] buf = generateKdfBytes(kParam, (cipherKeySize / 8) + (macKeySize / 8));
cipher.init(true, new KeyParameter(buf, 0, (cipherKeySize / 8)));
c_text_length = cipher.getOutputSize(inLen);
byte[] tmp = new byte[c_text_length];
int len = cipher.processBytes(in, inOff, inLen, tmp, 0);
len += cipher.doFinal(tmp, len);
C = new byte[len + mac.getMacSize()];
c_text_length = len;
System.arraycopy(tmp, 0, C, 0, len);
macKey = new KeyParameter(buf, (cipherKeySize / 8), (macKeySize / 8));
}
byte[] macIV = param.getEncodingV();
mac.init(macKey);