Example #1
0
        /// <summary>
        /// Generates a request packet.
        /// </summary>
        /// <returns></returns>
        public DiffieHellman GenerateRequest()
        {
            // Generate the parameters.
            prime = BigInteger.genPseudoPrime(bits, 30, random);
            mine  = BigInteger.genPseudoPrime(bits, 30, random);
            g     = BigInteger.genPseudoPrime(bits, 30, random);

            // Gemerate the string.
            PayloadWriter pw = new PayloadWriter();

            pw.WriteBigInteger(prime);
            pw.WriteBigInteger(g);

            // Generate the send BigInt.
            using (BigInteger send = g.modPow(mine, prime))
            {
                pw.WriteBigInteger(send);
            }
            representation = pw.ToByteArray();
            return(this);
        }
Example #2
0
        /// <summary>
        /// Generate a response packet.
        /// </summary>
        /// <param name="request">The string representation of the request.</param>
        /// <returns></returns>
        public DiffieHellman GenerateResponse(PayloadReader pr)
        {
            // Generate the would-be fields.
            using (BigInteger prime = pr.ReadBigInteger())
                using (BigInteger g = pr.ReadBigInteger())
                    using (BigInteger mine = BigInteger.genPseudoPrime(bits, 30, random))
                    {
                        // Generate the key.
                        using (BigInteger given = pr.ReadBigInteger())
                            using (BigInteger key = given.modPow(mine, prime))
                            {
                                this.key = key.getBytes();
                            }
                        // Generate the response.
                        using (BigInteger send = g.modPow(mine, prime))
                        {
                            PayloadWriter pw = new PayloadWriter();
                            pw.WriteBigInteger(send);
                            this.representation = pw.ToByteArray();
                        }
                    }

            return(this);
        }