protected EllipticCurve(MyBigInteger a, MyBigInteger b, MyBigInteger p, Func <MyBigInteger, MyBigInteger, MyBigInteger> equation) { this.a = a; this.b = b; this.p = p; this.Zero = new EllipticCurvePoint(a.Zero(), b.Zero()); this.equation = equation; }
public EllipticCurvePoint Add(EllipticCurvePoint first, EllipticCurvePoint second) { if (first is InfinityPoint) { return(second); } if (second is InfinityPoint) { return(first); } if (AreOpposite(first, second)) { return(new InfinityPoint()); } return(AreDifferent(first, second) ? AddDifferent(first, second) : DoublePoint(first)); }
public EllipticCurvePoint Add(EllipticCurvePoint first, EllipticCurvePoint second) { if (Zero.Equals(first)) { return(second); } if (Zero.Equals(second)) { return(first); } if (AreOpposite(first, second)) { return(Zero); } return(AreDifferent(first, second) ? AddDifferent(first, second) : DoublePoint(first)); }
public bool Contains(EllipticCurvePoint point) { var res = equation(point.X, point.Y) % p; return(res == point.X.Zero()); }
protected abstract EllipticCurvePoint AddDifferent(EllipticCurvePoint first, EllipticCurvePoint second);
protected abstract EllipticCurvePoint DoublePoint(EllipticCurvePoint point);
protected abstract bool AreDifferent(EllipticCurvePoint first, EllipticCurvePoint second);
protected abstract bool AreOpposite(EllipticCurvePoint first, EllipticCurvePoint second);