public byte[] unwrap(byte[] input, int inOff, int inLen)
throws InvalidCipherTextException
{
byte[] decKey = new byte[inLen - mac.getMacSize()];
cipher.processBlock(input, inOff, decKey, 0);
cipher.processBlock(input, inOff + 8, decKey, 8);
cipher.processBlock(input, inOff + 16, decKey, 16);
cipher.processBlock(input, inOff + 24, decKey, 24);
byte[] macResult = new byte[mac.getMacSize()];
mac.update(decKey, 0, decKey.length);
mac.doFinal(macResult, 0);
byte[] macExpected = new byte[mac.getMacSize()];
System.arraycopy(input, inOff + inLen - 4, macExpected, 0, mac.getMacSize());
if (!Arrays.constantTimeAreEqual(macResult, macExpected))
{
throw new IllegalStateException("mac mismatch");
}
return decKey;
}
}