Esempio n. 1
0
            public ECPoint Add(ECPoint b)
            {
                if (IsInfinity())
                {
                    return(b);
                }
                if (b.IsInfinity())
                {
                    return(this);
                }

                var u = Mod(b.y.ToInt() * z - y.ToInt() * b.z, curve.q);
                var v = Mod(b.x.ToInt() * z - x.ToInt() * b.z, curve.q);

                if (BigInteger.Zero.Equals(v))
                {
                    if (BigInteger.Zero.Equals(u))
                    {
                        return(Twice());
                    }
                    return(curve.infinity);
                }

                var v2 = BigInteger.Pow(v, 2);
                var v3 = v2 * v;

                var x1v2 = x.ToInt() * v2;
                var zu2  = BigInteger.Pow(u, 2) * z;

                var x3 = Mod((((zu2 - (x1v2 << 1)) * b.z) - v3) * v, curve.q);
                var y3 = Mod((((((x1v2 * 3) * u) - (y.ToInt() * v3)) - (zu2 * u)) * b.z) + (u * v3), curve.q);
                var z3 = Mod((v3 * z) * b.z, curve.q);

                return(new ECPoint(curve, curve.FromBigInteger(x3), curve.FromBigInteger(y3), z3));
            }