private OcbBlockCipher InitCipher(bool forEncryption, AeadParameters parameters) { OcbBlockCipher c = new OcbBlockCipher(new AesFastEngine(), new AesFastEngine()); c.Init(forEncryption, parameters); return(c); }
private void DoTestExceptions() { IAeadBlockCipher ocb = CreateOcbCipher(); try { ocb = new OcbBlockCipher(new DesEngine(), new DesEngine()); Fail("incorrect block size not picked up"); } catch (ArgumentException) { // expected } try { ocb.Init(false, new KeyParameter(new byte[16])); Fail("illegal argument not picked up"); } catch (ArgumentException) { // expected } // TODO //AEADTestUtil.testReset(this, createOCBCipher(), createOCBCipher(), new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[15])); //AEADTestUtil.testTampering(this, ocb, new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[15])); }
private void RunLongerTestCase(int aesKeySize, int tagLen, byte[] expectedOutput) { KeyParameter key = new KeyParameter(new byte[aesKeySize / 8]); byte[] N = new byte[12]; IAeadBlockCipher c1 = new OcbBlockCipher(new AesFastEngine(), new AesFastEngine()); c1.Init(true, new AeadParameters(key, tagLen, N)); IAeadBlockCipher c2 = new OcbBlockCipher(new AesFastEngine(), new AesFastEngine()); long total = 0; byte[] S = new byte[128]; for (int i = 0; i < 128; ++i) { N[11] = (byte)i; c2.Init(true, new AeadParameters(key, tagLen, N)); total += UpdateCiphers(c1, c2, S, i, true, true); total += UpdateCiphers(c1, c2, S, i, false, true); total += UpdateCiphers(c1, c2, S, i, true, false); } long expectedTotal = 16256 + (48 * tagLen); if (total != expectedTotal) { Fail("test generated the wrong amount of input: " + total); } byte[] output = new byte[c1.GetOutputSize(0)]; c1.DoFinal(output, 0); if (!AreEqual(expectedOutput, output)) { Fail("incorrect encrypt in long-form test"); } }