*/
public void testEquality(TestHarness harness)
{
harness.checkPoint("testEquality");
String macName;
IMac gnu = null;
Mac jce = null;
byte[] in = this.getClass().getName().getBytes();
byte[] ba1, ba2;
HashMap attrib = new HashMap();
for (Iterator it = MacFactory.getNames().iterator(); it.hasNext();)
{
macName = (String) it.next();
// we dont provide OMAC based on NullCipher through the JCE. skip
if (macName.equals("omac-null"))
continue;
AlgorithmParameterSpec params = null;
if (macName.equalsIgnoreCase("UMAC32"))
{
byte[] nonce = new byte[16];
for (int i = 0; i < nonce.length; i++)
nonce[i] = (byte) i;
params = new UMac32ParameterSpec(nonce);
attrib.put(UMac32.NONCE_MATERIAL, nonce);
}
else if (macName.equalsIgnoreCase("TMMH16"))
{
IRandom rand1 = new MDGenerator();
rand1.init(new HashMap());
Integer tagLen = new Integer(4);
params = new TMMHParameterSpec(rand1, tagLen);
IRandom rand2 = new MDGenerator();
rand2.init(new HashMap());
attrib.put(TMMH16.KEYSTREAM, rand2);
attrib.put(TMMH16.TAG_LENGTH, tagLen);
}
try
{
gnu = MacFactory.getInstance(macName);
harness.check(gnu != null, "MacFactory.getInstance(" + macName
+ ")");
}
catch (InternalError x)
{
harness.fail("MacFactory.getInstance(" + macName + "): "
+ String.valueOf(x));
}
try
{
jce = Mac.getInstance(macName, Registry.GNU_CRYPTO);
harness.check(jce != null, "Mac.getInstance()");
}
catch (Exception x)
{
harness.debug(x);
harness.fail("Mac.getInstance(" + macName + "): "
+ String.valueOf(x));
}
byte[] kb = null;
if (macName.equalsIgnoreCase("UMAC32")
|| macName.equalsIgnoreCase("UHASH32"))
kb = new byte[16];
else if (macName.toLowerCase().startsWith(Registry.OMAC_PREFIX))
{
IBlockCipher cipher = CipherFactory.getInstance(
macName.substring(Registry.OMAC_PREFIX.length()));
if (cipher != null)
kb = new byte[cipher.defaultKeySize()];
else
kb = new byte[gnu.macSize()];
}
else
kb = new byte[gnu.macSize()];
for (int i = 0; i < kb.length; i++)
kb[i] = (byte) i;
attrib.put(IMac.MAC_KEY_MATERIAL, kb);
try
{
gnu.init(attrib);
if (macName.equalsIgnoreCase("TMMH16"))
jce.init(null, params);
else
jce.init(new SecretKeySpec(kb, macName), params);
}
catch (Exception x)
{
harness.debug(x);
harness.fail("Mac.getInstance(" + macName + "): "
+ String.valueOf(x));
}
gnu.update(in, 0, in.length);
ba1 = gnu.digest();
ba2 = jce.doFinal(in);
harness.check(Arrays.equals(ba1, ba2), "testEquality(" + macName + ")");
}
}