public EccPoint Add(EccPoint pointA, EccPoint pointB) { // Any point added to infinity is itself if (pointA.Infinity) { return(pointB); } // Any point added to infinity is itself if (pointB.Infinity) { return(pointA); } // Any point added to its inverse is infinity if (pointA.Equals(Negate(pointB))) { return(new EccPoint("infinity")); } // Cannot add two identical points, use Double instead if (pointA.Equals(pointB)) { return(Double(pointA)); } var numerator = _operator.Subtract(pointB.Y, pointA.Y); var denominator = _operator.Subtract(pointB.X, pointA.X); var lambda = _operator.Divide(numerator, denominator); var x = _operator.Subtract(_operator.Subtract(_operator.Multiply(lambda, lambda), pointA.X), pointB.X); var y = _operator.Subtract(_operator.Multiply(_operator.Subtract(pointA.X, x), lambda), pointA.Y); return(new EccPoint(x, y)); }
public EccPoint Add(EccPoint pointA, EccPoint pointB) { // Any point added to infinity is itself if (pointA.Infinity) { return(pointB); } // Any point added to infinity is itself if (pointB.Infinity) { return(pointA); } // Any point added to its inverse is infinity if (pointA.Equals(Negate(pointB))) { return(new EccPoint("infinity")); } // Cannot add two identical points, use Double instead if (pointA.Equals(pointB)) { return(Double(pointA)); } var numerator = _operator.Add(pointA.Y, pointB.Y); var denominator = _operator.Add(pointA.X, pointB.X); if (denominator == 0) { return(new EccPoint("infinity")); } var lambda = _operator.Multiply(numerator, _operator.Inverse(denominator)); // x = lambda * lambda + lambda + x1 + x2 + a var x = _operator.Add(_operator.Add(_operator.Add(_operator.Add(_operator.Multiply(lambda, lambda), lambda), pointA.X), pointB.X), CoefficientA); // y = lambda * (x1 + x3) + x + y1 var y = _operator.Add(_operator.Add(_operator.Multiply(_operator.Add(pointA.X, x), lambda), x), pointA.Y); return(new EccPoint(x, y)); }
public EccPoint Multiply(EccPoint startPoint, BigInteger scalar) { // Intentional normal modulo, this is what CAVS does scalar %= OrderN; if (startPoint.Equals(BasePointG) && HasPrecomputedValues) { return(FastMultiply(scalar)); } else { return(Multiply(startPoint, new NonAdjacentBitString(scalar))); } }