Esempio n. 1
0
        private byte[] ISetupKeys(plBufferedStream s, int gval)
        {
            BigNum b = BigNum.Random(512);
            BigNum n = new BigNum(fN);
            BigNum x = new BigNum(fX);

            // Calculate seeds
            BigNum client_seed = x.PowMod(b, n);
            BigNum server_seed = new BigNum(gval).PowMod(b, n);
            byte[] cliSeed = client_seed.ToLittleArray();
            IWriteNetClientConnect(s, server_seed.ToLittleArray());

            // Dispose of this crap...
            b.Dispose();
            n.Dispose();
            x.Dispose();
            client_seed.Dispose();
            server_seed.Dispose();

            return cliSeed;
        }
Esempio n. 2
0
        private bool ISetupKeys(int g)
        {
            BigNum b = new BigNum(Helpers.StrongRandom(64));
            BigNum N = new BigNum(fN);
            BigNum X = new BigNum(fX);

            //Calculate seeds
            BigNum client_seed = X.PowMod(b, N);
            BigNum server_seed = new BigNum(g).PowMod(b, N);

            //Dump data
            fDhData = server_seed.ToArray();
            fClientSeed = client_seed.ToArray();

            //Explicitly dispose unmanaged OpenSSL resources
            b.Dispose();
            N.Dispose();
            X.Dispose();
            client_seed.Dispose();
            server_seed.Dispose();
            return true;
        }
Esempio n. 3
-1
        protected bool SetupEncryption(byte[] pubKey, byte[] privKey)
        {
            NetworkStream ns = new NetworkStream(fSocket, false);
            plBufferedStream temp = new plBufferedStream(ns);
            byte[] yData = IReadNetCliConnect(temp);

            if (yData != null) {
                BigNum Y = new BigNum(yData);
                BigNum N = new BigNum(pubKey);
                BigNum K = new BigNum(privKey);

                // Generate some randomness and do Y**K%N to get the key components
                byte[] server_seed = RNG.Random(7);
                BigNum client_seed = Y.PowMod(K, N);
                byte[] seed_data = client_seed.ToLittleArray();

                // Grab the first 7 bytes and xor it with some randomness to make our key
                byte[] key = new byte[7];
                for (int i = 0; i < key.Length; i++)
                    if (i >= seed_data.Length) key[i] = server_seed[i];
                    else key[i] = (byte)(seed_data[i] ^ server_seed[i]);

                // Final setup
                fStream = new plBufferedStream(new pnSocketStream(fSocket, key));
                IWriteNetCliEncrypt(temp, server_seed);

                // Explicitly clean up some resources so that we don't pressure the GC too much.
                // Those explicit finalizers really suck.
                Y.Dispose();
                N.Dispose();
                K.Dispose();
                client_seed.Dispose();
            } else
                // Write the error code to the unencrypted buffer
                temp.WriteByte(plNetCore.kNetCliError);

            temp.Flush();
            temp.Close();
            ns.Close();

            return (yData != null);
        }