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)); } }
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)); } }
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 (SHX engine = new SHX()) { engine.Initialize(true, new KeyParams(Key)); for (int i = 0; i != Count; i++) { engine.Transform(outBytes, outBytes); } } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("Serpent MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } }