}
public void performTest()
throws Exception
{
Mac mac = Mac.getInstance("AESCMAC", "BC");
//128 bytes key
SecretKeySpec key = new SecretKeySpec(keyBytes128, "AES");
// 0 bytes message - 128 bytes key
mac.init(key);
mac.update(input0, 0, input0.length);
byte[] out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k128_m0))
{
fail("Failed - expected " + new String(Hex.encode(output_k128_m0))
+ " got " + new String(Hex.encode(out)));
}
// 16 bytes message - 128 bytes key
mac.init(key);
mac.update(input16, 0, input16.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k128_m16))
{
fail("Failed - expected " + new String(Hex.encode(output_k128_m16))
+ " got " + new String(Hex.encode(out)));
}
// 40 bytes message - 128 bytes key
mac.init(key);
mac.update(input40, 0, input40.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k128_m40))
{
fail("Failed - expected " + new String(Hex.encode(output_k128_m40))
+ " got " + new String(Hex.encode(out)));
}
// 64 bytes message - 128 bytes key
mac.init(key);
mac.update(input64, 0, input64.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k128_m64))
{
fail("Failed - expected " + new String(Hex.encode(output_k128_m64))
+ " got " + new String(Hex.encode(out)));
}
//192 bytes key
key = new SecretKeySpec(keyBytes192, "AES");
// 0 bytes message - 192 bytes key
mac.init(key);
mac.update(input0, 0, input0.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k192_m0))
{
fail("Failed - expected " + new String(Hex.encode(output_k192_m0))
+ " got " + new String(Hex.encode(out)));
}
// 16 bytes message - 192 bytes key
mac.init(key);
mac.update(input16, 0, input16.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k192_m16))
{
fail("Failed - expected " + new String(Hex.encode(output_k192_m16))
+ " got " + new String(Hex.encode(out)));
}
// 40 bytes message - 192 bytes key
mac.init(key);
mac.update(input40, 0, input40.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k192_m40))
{
fail("Failed - expected " + new String(Hex.encode(output_k192_m40))
+ " got " + new String(Hex.encode(out)));
}
// 64 bytes message - 192 bytes key
mac.init(key);
mac.update(input64, 0, input64.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k192_m64))
{
fail("Failed - expected " + new String(Hex.encode(output_k192_m64))
+ " got " + new String(Hex.encode(out)));
}
//256 bytes key
key = new SecretKeySpec(keyBytes256, "AES");
// 0 bytes message - 256 bytes key
mac.init(key);
mac.update(input0, 0, input0.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k256_m0))
{
fail("Failed - expected " + new String(Hex.encode(output_k256_m0))
+ " got " + new String(Hex.encode(out)));
}
// 16 bytes message - 256 bytes key
mac.init(key);
mac.update(input16, 0, input16.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k256_m16))
{
fail("Failed - expected " + new String(Hex.encode(output_k256_m16))
+ " got " + new String(Hex.encode(out)));
}
// 40 bytes message - 256 bytes key
mac.init(key);
mac.update(input40, 0, input40.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k256_m40))
{
fail("Failed - expected " + new String(Hex.encode(output_k256_m40))
+ " got " + new String(Hex.encode(out)));
}
// 64 bytes message - 256 bytes key
mac.init(key);
mac.update(input64, 0, input64.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_k256_m64))
{
fail("Failed - expected " + new String(Hex.encode(output_k256_m64))
+ " got " + new String(Hex.encode(out)));
}
mac = Mac.getInstance("DESedeCMAC", "BC");
//DESede
key = new SecretKeySpec(keyBytes128, "DESede");
// 0 bytes message - 128 bytes key
mac.init(key);
mac.update(input0, 0, input0.length);
out = new byte[mac.getMacLength()];
mac.doFinal(out, 0);
if (!areEqual(out, output_des_ede))
{
fail("Failed - expected " + new String(Hex.encode(output_des_ede))
+ " got " + new String(Hex.encode(out)));