Clean KeyExchange Implementation [SSL]

05/29/2012 10:40 _DreadNought_#16
Quote:
Originally Posted by Korvacs View Post
Code:
public class KeyExchange
    {
        public ClientKeyPacket CKeyPacket;
        public byte[] ClientIV = new byte[8];
        public DH Exchange;
        public bool Exchanged;
        public byte[] ServerIV = new byte[8];
        public ServerKeyPacket SKeyPacket;

        public KeyExchange()
        {
            Random random = new Random();
            random.NextBytes(this.ServerIV);
            random.NextBytes(this.ClientIV);
            string str = "E7A69EBDF105F2A6BBDEAD7E798F76A209AD73FB466431E2E7352ED262F8C558F10BEFEA977DE9E21DCEE9B04D245F300ECCBBA03E72630556D011023F9E857F";
            string str2 = "05";
            this.Exchange = new DH(BigNumber.FromHexString(str), BigNumber.FromHexString(str2));
            this.Exchange.GenerateKeys();
            this.SKeyPacket = new ServerKeyPacket(this.ClientIV, this.ServerIV, str, str2, this.Exchange.PublicKey.ToHexString());
        }

        public void HandleClientKeyPacket(ClientKeyPacket CKeyPacket, GameCryptographer Cryptographer)
        {
            Cryptographer.Blowfish.SetKey(this.Exchange.ComputeKey(BigNumber.FromHexString(CKeyPacket.PublicKey)));
            Cryptographer.Blowfish.EncryptIV = new byte[8];
            Cryptographer.Blowfish.DecryptIV = new byte[8];
        }

        public void ResetIVs(GameCryptographer Cryptographer)
        {
            Cryptographer.Blowfish.DecryptIV = new byte[8];
            Cryptographer.Blowfish.EncryptIV = new byte[8];
        }
    }
^ Publicly available.
Yeah you took that straight from your wiki, Ult & Haydz's implementation, There's not really much competitiveness with them.

There implementation is "as messy" as mine, All I have is an extra method, and its near enough the same regarding "messyness", so I don't see how you can call my work messy & not the implementation you just linked.
05/29/2012 10:54 Korvacs#17
Its much more readable imo, neater, less code etc.

I personally would rewrite most of the other classes to be neater aswell, or just use external calls instead, and the packets i would rewrite again to be far in a away more organised than yours/other examples.

Your example imo is in no way as improved as you believe it to be...