public void performTest()
throws Exception
{
SecretKey key = new SecretKeySpec(keyBytes, "DES");
byte[] out;
Mac mac;
mac = Mac.getInstance("DESMac", "BC");
//
// standard DAC - zero IV
//
mac.init(key);
mac.update(input, 0, input.length);
out = mac.doFinal();
if (!areEqual(out, output1))
{
fail("Failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out)));
}
//
// mac with IV.
//
mac.init(key, new IvParameterSpec(ivBytes));
mac.update(input, 0, input.length);
out = mac.doFinal();
if (!areEqual(out, output2))
{
fail("Failed - expected " + new String(Hex.encode(output2)) + " got " + new String(Hex.encode(out)));
}
//
// CFB mac with IV - 8 bit CFB mode
//
mac = Mac.getInstance("DESMac/CFB8", "BC");
mac.init(key, new IvParameterSpec(ivBytes));
mac.update(input, 0, input.length);
out = mac.doFinal();
if (!areEqual(out, output3))
{
fail("Failed - expected " + new String(Hex.encode(output3)) + " got " + new String(Hex.encode(out)));
}
//
// ISO9797 algorithm 3 using DESEDE
//
key = new SecretKeySpec(keyBytesISO9797, "DESEDE");
mac = Mac.getInstance("ISO9797ALG3", "BC");
mac.init(key);
mac.update(inputISO9797, 0, inputISO9797.length);
out = mac.doFinal();
if (!areEqual(out, outputISO9797))
{
fail("Failed - expected " + new String(Hex.encode(outputISO9797)) + " got " + new String(Hex.encode(out)));
}
//
// 64bit DESede Mac
//
key = new SecretKeySpec(keyBytesISO9797, "DESEDE");
mac = Mac.getInstance("DESEDE64", "BC");
mac.init(key);
mac.update(inputDesEDE64, 0, inputDesEDE64.length);
out = mac.doFinal();
if (!areEqual(out, outputDesEDE64))
{
fail("Failed - expected " + new String(Hex.encode(outputDesEDE64)) + " got " + new String(Hex.encode(out)));
}