Ejemplo n.º 1
0
        private void ECBTest(byte[] Key, byte[, ][] Input, byte[, ][] Output)
        {
            byte[] outBytes = new byte[16];
            int    index    = 0;

            if (Key.Length == 24)
            {
                index = 2;
            }
            else if (Key.Length == 32)
            {
                index = 4;
            }

            using (ECB mode = new ECB(new RHX()))
            {
                mode.Initialize(true, new KeyParams(Key));

                for (int i = 0; i < 4; i++)
                {
                    mode.Transform(Input[index, i], outBytes);

                    if (Evaluate.AreEqual(outBytes, Output[index, i]) == false)
                    {
                        throw new Exception("ECB Mode: Encrypted arrays are not equal!");
                    }
                }
            }

            index++;

            using (ECB mode = new ECB(new RHX()))
            {
                mode.Initialize(false, new KeyParams(Key));

                for (int i = 0; i < 4; i++)
                {
                    mode.Transform(Input[index, i], outBytes);

                    if (Evaluate.AreEqual(outBytes, _output[index, i]) == false)
                    {
                        throw new Exception("ECB Mode: Decrypted arrays are not equal!");
                    }
                }
            }
        }