@Override public byte[] getMAC(byte[] key, byte[] data) { BlockCipher cipher = new DESEngine(); Mac mac = new ISO9797Alg3Mac(cipher, 64, new ISO7816d4Padding()); KeyParameter keyP = new KeyParameter(key); mac.init(keyP); mac.update(data, 0, data.length); byte[] out = new byte[8]; mac.doFinal(out, 0); return out; }
public DES9797Alg3with7816d4() { super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding())); }
public DES9797Alg3() { super(new ISO9797Alg3Mac(new DESEngine())); }
public void performTest() { KeyParameter key = new KeyParameter(keyBytes); BlockCipher cipher = new DESEngine(); Mac mac = new ISO9797Alg3Mac(cipher); // // standard DAC - zero IV // mac.init(key); mac.update(input1, 0, input1.length); byte[] out = new byte[8]; mac.doFinal(out, 0); if (!areEqual(out, output1)) { fail("Failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out))); } // // reset // mac.reset(); mac.init(key); for (int i = 0; i != input1.length / 2; i++) { mac.update(input1[i]); } mac.update(input1, input1.length / 2, input1.length - (input1.length / 2)); mac.doFinal(out, 0); if (!areEqual(out, output1)) { fail("Reset failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out))); } testMacWithIv(); }
@Override public byte[] getMAC(byte[] data) { byte[] n = new byte[8 + data.length]; System.arraycopy(sscBytes, 0, n, 0, 8); System.arraycopy(data, 0, n, 8, data.length); BlockCipher cipher = new DESEngine(); Mac mac = new ISO9797Alg3Mac(cipher, 64, new ISO7816d4Padding()); ParametersWithIV parameterIV = new ParametersWithIV(keyP, IV); mac.init(parameterIV); mac.update(n, 0, n.length); byte[] out = new byte[8]; mac.doFinal(out, 0); return out; }
@Override public MACCalculator _createMACCalculator() { final BlockCipher cipher = new DESEngine(); return new MACCalculatorImpl(new ISO9797Alg3Mac(cipher, new ISO7816d4Padding()), 24, cipher.getBlockSize()); }
@Override public MACCalculator _createMACCalculator() { final BlockCipher cipher = new DESEngine(); return new MACCalculatorImpl(new ISO9797Alg3Mac(cipher), 24, cipher.getBlockSize()); }