public EllipticCurvePoint Twice(EllipticCurvePoint a) { if (EllipticCurvePoint.IsInfinity(a)) { return(a); } BigInteger sigma = a.X.InverseGF(curve.P).MultGF(a.Y, curve.P).AddGF(a.X); BigInteger x = sigma.SquareGF(curve.P).AddGF(sigma).AddGF(curve.A); BigInteger y = a.X.SquareGF(curve.P).AddGF(sigma.AddGF(BigInteger.One).MultGF(x, curve.P)); var result = new EllipticCurvePoint(x, y); //CheckOnCurve(result); return(result); }
public static BigInteger InverseGF(this BigInteger value, BigInteger modulus) { BigInteger b = 1, c = 0, u = value, v = modulus; while (u.GetBitCount() > 1) { int j = u.GetBitCount() - v.GetBitCount(); if (j < 0) { (u, v) = (v, u); (c, b) = (b, c); j = -j; } u = u.AddGF(v << j); b = b.AddGF(c << j); } return(b); }