public override void PerformTest() { CcmBlockCipher ccm = new CcmBlockCipher(new AesEngine()); checkVectors(0, ccm, K1, 32, N1, A1, P1, T1, C1); checkVectors(1, ccm, K2, 48, N2, A2, P2, T2, C2); checkVectors(2, ccm, K3, 64, N3, A3, P3, T3, C3); ivParamTest(0, ccm, K1, N1); // // 4 has a reduced associated text which needs to be replicated // byte[] a4 = new byte[65536]; // 524288 / 8 for (int i = 0; i < a4.Length; i += A4.Length) { Array.Copy(A4, 0, a4, i, A4.Length); } checkVectors(3, ccm, K4, 112, N4, a4, P4, T4, C4); // // long data test // checkVectors(4, ccm, K4, 112, N4, A4, A4, T5, C5); // decryption with output specified, non-zero offset. ccm.Init(false, new AeadParameters(new KeyParameter(K2), 48, N2, A2)); byte[] inBuf = new byte[C2.Length + 10]; byte[] outBuf = new byte[ccm.GetOutputSize(C2.Length) + 10]; Array.Copy(C2, 0, inBuf, 10, C2.Length); int len = ccm.ProcessPacket(inBuf, 10, C2.Length, outBuf, 10); byte[] output = ccm.ProcessPacket(C2, 0, C2.Length); if (len != output.Length || !isEqual(output, outBuf, 10)) { Fail("decryption output incorrect"); } // encryption with output specified, non-zero offset. ccm.Init(true, new AeadParameters(new KeyParameter(K2), 48, N2, A2)); int inLen = len; inBuf = outBuf; outBuf = new byte[ccm.GetOutputSize(inLen) + 10]; len = ccm.ProcessPacket(inBuf, 10, inLen, outBuf, 10); output = ccm.ProcessPacket(inBuf, 10, inLen); if (len != output.Length || !isEqual(output, outBuf, 10)) { Fail("encryption output incorrect"); } // // exception tests // try { ccm.Init(false, new AeadParameters(new KeyParameter(K1), 32, N2, A2)); ccm.ProcessPacket(C2, 0, C2.Length); Fail("invalid cipher text not picked up"); } catch (InvalidCipherTextException) { // expected } try { ccm = new CcmBlockCipher(new DesEngine()); Fail("incorrect block size not picked up"); } catch (ArgumentException) { // expected } try { ccm.Init(false, new KeyParameter(K1)); Fail("illegal argument not picked up"); } catch (ArgumentException) { // expected } }
public override void PerformTest() { CcmBlockCipher ccm = new CcmBlockCipher(new AesEngine()); checkVectors(0, ccm, K1, 32, N1, A1, P1, T1, C1); checkVectors(1, ccm, K2, 48, N2, A2, P2, T2, C2); checkVectors(2, ccm, K3, 64, N3, A3, P3, T3, C3); ivParamTest(0, ccm, K1, N1); // // 4 has a reduced associated text which needs to be replicated // byte[] a4 = new byte[65536]; // 524288 / 8 for (int i = 0; i < a4.Length; i += A4.Length) { Array.Copy(A4, 0, a4, i, A4.Length); } checkVectors(3, ccm, K4, 112, N4, a4, P4, T4, C4); // // long data test // checkVectors(4, ccm, K4, 112, N4, A4, A4, T5, C5); // // exception tests // try { ccm.Init(false, new AeadParameters(new KeyParameter(K1), 32, N2, A2)); ccm.ProcessPacket(C2, 0, C2.Length); Fail("invalid cipher text not picked up"); } catch (InvalidCipherTextException) { // expected } try { ccm = new CcmBlockCipher(new DesEngine()); Fail("incorrect block size not picked up"); } catch (ArgumentException) { // expected } try { ccm.Init(false, new KeyParameter(K1)); Fail("illegal argument not picked up"); } catch (ArgumentException) { // expected } }