Init() public méthode

public Init ( bool forEncryption, ICipherParameters parameters ) : void
forEncryption bool
parameters ICipherParameters
Résultat void
Exemple #1
0
		private void randomTest(
			SecureRandom srng)
		{
			int DAT_LEN = srng.Next(1024);
			byte[] nonce = new byte[NONCE_LEN];
			byte[] authen = new byte[AUTHEN_LEN];
			byte[] datIn = new byte[DAT_LEN];
			byte[] key = new byte[16];
			srng.NextBytes(nonce);
			srng.NextBytes(authen);
			srng.NextBytes(datIn);
			srng.NextBytes(key);

			AesFastEngine engine = new AesFastEngine();
			KeyParameter sessKey = new KeyParameter(key);
			EaxBlockCipher eaxCipher = new EaxBlockCipher(engine);

			AeadParameters parameters = new AeadParameters(sessKey, MAC_LEN * 8, nonce, authen);
			eaxCipher.Init(true, parameters);

			byte[] intrDat = new byte[eaxCipher.GetOutputSize(datIn.Length)];
			int outOff = eaxCipher.ProcessBytes(datIn, 0, DAT_LEN, intrDat, 0);
			outOff += eaxCipher.DoFinal(intrDat, outOff);

			eaxCipher.Init(false, parameters);
			byte[] datOut = new byte[eaxCipher.GetOutputSize(outOff)];
			int resultLen = eaxCipher.ProcessBytes(intrDat, 0, outOff, datOut, 0);
			eaxCipher.DoFinal(datOut, resultLen);

			if (!AreEqual(datIn, datOut))
			{
				Fail("EAX roundtrip failed to match");
			}
		}
Exemple #2
0
        private void checkVectors(
            int count,
            string additionalDataType,
            byte[] k,
            int macSize,
            byte[] n,
            byte[] a,
            byte[] sa,
            byte[] p,
            byte[] t,
            byte[] c)
        {
			EaxBlockCipher encEax = new EaxBlockCipher(new AesFastEngine());
			EaxBlockCipher decEax = new EaxBlockCipher(new AesFastEngine());

			AeadParameters parameters = new AeadParameters(new KeyParameter(k), macSize, n, a);
			encEax.Init(true, parameters);
			decEax.Init(false, parameters);

            runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c);
            runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c);

            // key reuse test
            parameters = new AeadParameters(null, macSize, n, a);
            encEax.Init(true, parameters);
            decEax.Init(false, parameters);

            runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c);
            runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c);
        }
Exemple #3
0
        private void checkVectors(
			int				count,
			byte[]			k,
			int				macSize,
			byte[]			n,
			byte[]			a,
			byte[]			p,
			byte[]			t,
			byte[]			c)
        {
            EaxBlockCipher encEax = new EaxBlockCipher(new AesFastEngine());
            EaxBlockCipher decEax = new EaxBlockCipher(new AesFastEngine());

            AeadParameters parameters = new AeadParameters(new KeyParameter(k), macSize, n, a);
            encEax.Init(true, parameters);
            decEax.Init(false, parameters);

            runCheckVectors(count, encEax, decEax, p, t, c);
            runCheckVectors(count, encEax, decEax, p, t, c);
        }
Exemple #4
0
		public override void PerformTest()
		{
			checkVectors(1, K1, 128, N1, A1, P1, T1, C1);
			checkVectors(2, K2, 128, N2, A2, P2, T2, C2);
			checkVectors(3, K3, 128, N3, A3, P3, T3, C3);
			checkVectors(4, K4, 128, N4, A4, P4, T4, C4);
			checkVectors(5, K5, 128, N5, A5, P5, T5, C5);
			checkVectors(6, K6, 128, N6, A6, P6, T6, C6);
			checkVectors(7, K7, 128, N7, A7, P7, T7, C7);
			checkVectors(8, K8, 128, N8, A8, P8, T8, C8);
			checkVectors(9, K9, 128, N9, A9, P9, T9, C9);
			checkVectors(10, K10, 128, N10, A10, P10, T10, C10);
			checkVectors(11, K11, 32, N11, A11, P11, T11, C11);

			EaxBlockCipher eax = new EaxBlockCipher(new AesEngine());
			ivParamTest(1, eax, K1, N1);

			//
			// exception tests
			//

			try
			{
				eax.Init(false, new AeadParameters(new KeyParameter(K1), 32, N2, A2));

				byte[] enc = new byte[C2.Length]; 
				int len = eax.ProcessBytes(C2, 0, C2.Length, enc, 0);

				len += eax.DoFinal(enc, len);

				Fail("invalid cipher text not picked up");
			}
			catch (InvalidCipherTextException)
			{
				// expected
			}

			try
			{
				eax.Init(false, new KeyParameter(K1));

				Fail("illegal argument not picked up");
			}
			catch (ArgumentException)
			{
				// expected
			}

			randomTests();
		}
        private void DoEax(byte[] key, byte[] iv, byte[] pt, byte[] aad, int tagLength, byte[] expected)
        {
            EaxBlockCipher c = new EaxBlockCipher(new SerpentEngine());

            c.Init(true, new AeadParameters(new KeyParameter(key), tagLength, iv, aad));

            byte[] output = new byte[expected.Length];

            int len = c.ProcessBytes(pt, 0, pt.Length, output, 0);

            c.DoFinal(output, len);

            if (!Arrays.AreEqual(expected, output))
            {
                Fail("EAX test failed");
            }
        }