public int doFinal(byte[] out, int outOff) { int blockSize = cipher.getBlockSize(); byte[] lu; if (bufOff == blockSize) { lu = Lu; } else { new ISO7816d4Padding().addPadding(buf, bufOff); lu = Lu2; } for (int i = 0; i < mac.length; i++) { buf[i] ^= lu[i]; } cipher.processBlock(buf, 0, mac, 0); System.arraycopy(mac, 0, out, outOff, macSize); reset(); return macSize; }
public int doFinal(byte[] out, int outOff) { int blockSize = cipher.getBlockSize(); byte[] lu; if (bufOff == blockSize) { lu = Lu; } else { new ISO7816d4Padding().addPadding(buf, bufOff); lu = Lu2; } for (int i = 0; i < mac.length; i++) { buf[i] ^= lu[i]; } cipher.processBlock(buf, 0, mac, 0); System.arraycopy(mac, 0, out, outOff, macSize); reset(); return macSize; }
public void init(CipherParameters params) { validate(params); cipher.init(true, params); //initializes the L, Lu, Lu2 numbers byte[] L = new byte[ZEROES.length]; cipher.processBlock(ZEROES, 0, L, 0); Lu = doubleLu(L); Lu2 = doubleLu(Lu); reset(); }
public void init(CipherParameters params) { validate(params); cipher.init(true, params); //initializes the L, Lu, Lu2 numbers L = new byte[ZEROES.length]; cipher.processBlock(ZEROES, 0, L, 0); Lu = doubleLu(L); Lu2 = doubleLu(Lu); reset(); }
public static byte[] generateCmac(byte[] key, String msg) throws UnsupportedEncodingException { CMac cmac = new CMac(new AESFastEngine()); byte[] data = msg.getBytes("UTF-8"); byte[] output = new byte[cmac.getMacSize()]; cmac.init(new KeyParameter(key)); cmac.reset(); cmac.update(data, 0, data.length); cmac.doFinal(output, 0); return output; }