Esempio n. 1
0
        /// <summary>
        /// I/O and KAT tests run on the base engine accessors
        /// </summary>
        /// <returns>State</returns>
        public string Test()
        {
            byte[] key = new byte[32];
            byte[] iv = new byte[16];
            byte[] data = new byte[2048];
            IBlockCipher inCipher;
            IBlockCipher outCipher;

            try
            {
                inCipher = new RDX();
                outCipher = new RDX();
                // run the AES I/O test vectors
                for (int i = 0; i != _cipherTests.Length; i += 3)
                    TestIO(inCipher, outCipher, HexConverter.Decode(_cipherTests[i]), HexConverter.Decode(_cipherTests[i + 1]), HexConverter.Decode(_cipherTests[i + 2]));

                for (int i = 0; i != _cipherTests.Length; i += 3)
                    TestIO(inCipher, outCipher, HexConverter.Decode(_cipherTests[i]), HexConverter.Decode(_cipherTests[i + 1]), HexConverter.Decode(_cipherTests[i + 2]));

                using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
                {
                    rng.GetBytes(key);
                    rng.GetBytes(data);
                }

                OnProgress(new TestEventArgs("Passed AES known vector method tests.."));

                // test transforms
                TestIO2(new RDX(), key, data);
                TestIO2(new SPX(), key, data);
                TestIO2(new TFX(), key, data);

                OnProgress(new TestEventArgs("Passed I/O initialization and access tests.."));

                return SUCCESS;
            }
            catch (Exception Ex)
            {
                string message = Ex.Message == null ? "" : Ex.Message;
                throw new Exception(FAILURE + message);
            }
        }
Esempio n. 2
0
        private void VectorTest(byte[] Key, byte[] Input, byte[] Output)
        {
            byte[] outBytes = new byte[Input.Length];
            byte[] outBytes2 = new byte[Input.Length];

            using (RDX engine = new RDX(Input.Length))
            {
                engine.Initialize(true, new KeyParams(Key));
                engine.Transform(Input, outBytes);

                if (Compare.AreEqual(outBytes, Output) == false)
                    throw new Exception("Rijndael: Encrypted arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes));

                engine.Initialize(false, new KeyParams(Key));
                engine.Transform(Output, outBytes);

                if (Compare.AreEqual(outBytes, Input) == false)
                    throw new Exception("Rijndael: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes));
            }
        }
Esempio n. 3
0
        private byte[] EncryptRDX(byte[] Key, byte[] Data)
        {
            int blocks = Data.Length / 16;
            byte[] outputData = new byte[Data.Length];

            using (RDX transform = new RDX())
            {
                transform.Initialize(true, new KeyParams(Key));

                for (int i = 0; i < blocks; i++)
                    transform.Transform(Data, i * 16, outputData, i * 16);
            }

            return outputData;
        }
Esempio n. 4
0
        private void MonteCarloTest(byte[] Key, byte[] Input, byte[] Output)
        {
            byte[] outBytes = new byte[Input.Length];
            Array.Copy(Input, 0, outBytes, 0, outBytes.Length);

            using (RDX engine = new RDX())
            {
                engine.Initialize(true, new KeyParams(Key));

                for (int i = 0; i != 10000; i++)
                    engine.Transform(outBytes, outBytes);
            }

            if (Compare.AreEqual(outBytes, Output) == false)
                throw new Exception("AES MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes));

            using (RDX engine = new RDX())
            {
                engine.Initialize(false, new KeyParams(Key));

                for (int i = 0; i != 10000; i++)
                    engine.Transform(outBytes, outBytes);
            }

            if (Compare.AreEqual(outBytes, Input) == false)
                throw new Exception("AES MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes));
        }