Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }