コード例 #1
0
ファイル: SerpentTest.cs プロジェクト: modulexcite/CEX
        private void MonteCarloTest(byte[] Key, byte[] Input, byte[] Output, int Count = 100)
        {
            byte[] outBytes = new byte[Input.Length];
            Array.Copy(Input, 0, outBytes, 0, outBytes.Length);

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

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

            if (Compare.AreEqual(outBytes, Output) == false)
                throw new Exception("Serpent MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes));
        }
コード例 #2
0
ファイル: SerpentTest.cs プロジェクト: modulexcite/CEX
        private void VectorTest(byte[] Key, byte[] Input, byte[] Output)
        {
            byte[] outBytes = new byte[Output.Length];

            using (SPX enc = new SPX())
            {
                enc.Initialize(true, new KeyParams(Key));
                enc.EncryptBlock(Input, outBytes);
            }

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

            using (SPX dec = new SPX())
            {
                dec.Initialize(false, new KeyParams(Key));
                dec.DecryptBlock(Output, outBytes);
            }

            if (Compare.AreEqual(Input, outBytes) == false)
                throw new Exception("SerpentVector: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes));
        }
コード例 #3
0
ファイル: SerpentTest.cs プロジェクト: modulexcite/CEX
        private void KeyTest()
        {
            byte[] inBytes = new byte[16];
            byte[] outBytes = new byte[16];
            byte[] decBytes = new byte[16];
            byte[] key = new byte[64];

            for (int i = 0; i < 16; i++)
                inBytes[i] = (byte)i;
            for (int i = 0; i < 64; i++)
                key[i] = (byte)i;

            using (SPX engine = new SPX())
            {
                engine.Initialize(true, new KeyParams(key));
                engine.EncryptBlock(inBytes, outBytes);

                engine.Initialize(false, new KeyParams(key));
                engine.DecryptBlock(outBytes, decBytes);
            }

            if (Compare.AreEqual(inBytes, decBytes) == false)
                throw new Exception("Serpent: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(inBytes) + " Received: " + HexConverter.ToString(decBytes));
        }