Ejemplo n.º 1
0
        private void CheckTestVector_RFC5794(String[] tv)
        {
            string name = "'" + tv[0] + "'";

            IBlockCipher c         = new AriaEngine();
            int          blockSize = c.GetBlockSize();

            IsTrue("Wrong block size returned from getBlockSize() for " + name, 16 == blockSize);

            KeyParameter key = new KeyParameter(Hex.Decode(tv[1]));

            byte[] plaintext  = Hex.Decode(tv[2]);
            byte[] ciphertext = Hex.Decode(tv[3]);

            IsTrue("Unexpected plaintext length for " + name, blockSize == plaintext.Length);
            IsTrue("Unexpected ciphertext length for " + name, blockSize == ciphertext.Length);

            c.Init(true, key);

            byte[] actual = new byte[blockSize];
            int    num    = c.ProcessBlock(plaintext, 0, actual, 0);

            IsTrue("Wrong length returned from processBlock() (encryption) for " + name, blockSize == num);
            IsTrue("Incorrect ciphertext computed for " + name, Arrays.AreEqual(ciphertext, actual));

            c.Init(false, key);
            num = c.ProcessBlock(ciphertext, 0, actual, 0);

            IsTrue("Wrong length returned from processBlock() (decryption) for " + name, blockSize == num);
            IsTrue("Incorrect plaintext computed for " + name, Arrays.AreEqual(plaintext, actual));
        }
Ejemplo n.º 2
0
        private void CheckRandomRoundtrips()
        {
            AriaEngine ce = new AriaEngine();
            AriaEngine cd = new AriaEngine();

            byte[] txt = new byte[ce.GetBlockSize()];
            byte[] enc = new byte[ce.GetBlockSize()];
            byte[] dec = new byte[ce.GetBlockSize()];

            for (int keyLen = 16; keyLen <= 32; keyLen += 8)
            {
                byte[] K = new byte[keyLen];

                R.NextBytes(K);

                KeyParameter key = new KeyParameter(K);
                ce.Init(true, key);
                cd.Init(false, key);

                R.NextBytes(txt);

                for (int i = 0; i < 100; ++i)
                {
                    ce.ProcessBlock(txt, 0, enc, 0);
                    cd.ProcessBlock(enc, 0, dec, 0);

                    IsTrue(Arrays.AreEqual(txt, dec));

                    Array.Copy(enc, 0, txt, 0, enc.Length);
                }
            }
        }