Example #1
0
        private void VectorTest(byte[] Key, byte[] Input, byte[] Output)
        {
            byte[] outBytes = new byte[Output.Length];

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

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

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

            if (Evaluate.AreEqual(Input, outBytes) == false)
            {
                throw new Exception("SerpentVector: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes));
            }
        }
Example #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 (SHX engine = new SHX())
            {
                engine.Initialize(true, new KeyParams(key));
                engine.EncryptBlock(inBytes, outBytes);

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

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