private void checkVectors( int count, CcmBlockCipher ccm, string additionalDataType, byte[] k, int macSize, byte[] n, byte[] a, byte[] sa, byte[] p, byte[] t, byte[] c) { KeyParameter keyParam = (k == null) ? null : new KeyParameter(k); ccm.Init(true, new AeadParameters(keyParam, macSize, n, a)); byte[] enc = new byte[c.Length]; if (sa != null) { ccm.ProcessAadBytes(sa, 0, sa.Length); } int len = ccm.ProcessBytes(p, 0, p.Length, enc, 0); len += ccm.DoFinal(enc, len); // ccm.Init(true, new AeadParameters(new KeyParameter(k), macSize, n, a)); // // byte[] enc = ccm.ProcessPacket(p, 0, p.Length); if (!AreEqual(c, enc)) { Fail("encrypted stream fails to match in test " + count + " with " + additionalDataType); } // ccm.Init(false, new AeadParameters(new KeyParameter(k), macSize, n, a)); // // byte[] dec = ccm.ProcessPacket(enc, 0, enc.Length); ccm.Init(false, new AeadParameters(new KeyParameter(k), macSize, n, a)); byte[] tmp = new byte[enc.Length]; if (sa != null) { ccm.ProcessAadBytes(sa, 0, sa.Length); } len = ccm.ProcessBytes(enc, 0, enc.Length, tmp, 0); len += ccm.DoFinal(tmp, len); byte[] dec = new byte[len]; Array.Copy(tmp, 0, dec, 0, len); if (!AreEqual(p, dec)) { Fail("decrypted stream fails to match in test " + count + " with " + additionalDataType, Hex.ToHexString(p), Hex.ToHexString(dec)); } if (!AreEqual(t, ccm.GetMac())) { Fail("MAC fails to match in test " + count + " with " + additionalDataType); } }