示例#1
0
    def __add__(self, other):
        """Add two points on the same elliptic curve.

        Args:
            | self (fastecdsa.point.Point): a point :math:`P` on the curve
            | other (fastecdsa.point.Point): a point :math:`Q` on the curve

        Returns:
            fastecdsa.point.Point: A point :math:`R` such that :math:`R = P + Q`
        """
        if self.curve is not other.curve:
            raise CurveMismatchError(self.curve, other.curve)
        else:
            x, y = curvemath.add(
                str(self.x),
                str(self.y),
                str(other.x),
                str(other.y),
                str(self.curve.p),
                str(self.curve.a),
                str(self.curve.b),
                str(self.curve.q),
                str(self.curve.gx),
                str(self.curve.gy)
            )
            return Point(int(x), int(y), self.curve)
示例#2
0
    def __add__(self, other):
        """Add two points on the same elliptic curve.

        Args:
            | self (:class:`Point`): a point :math:`P` on the curve
            | other (:class:`Point`): a point :math:`Q` on the curve

        Returns:
            :class:`Point`: A point :math:`R` such that :math:`R = P + Q`
        """
        validate_type(other, Point)

        if self == self.IDENTITY_ELEMENT:
            return other
        elif other == self.IDENTITY_ELEMENT:
            return self
        elif self.curve is not other.curve:
            raise CurveMismatchError(self.curve, other.curve)
        elif self == -other:
            return self.IDENTITY_ELEMENT
        else:
            x, y = curvemath.add(str(self.x), str(self.y), str(other.x),
                                 str(other.y), str(self.curve.p),
                                 str(self.curve.a), str(self.curve.b),
                                 str(self.curve.q), str(self.curve.gx),
                                 str(self.curve.gy))
            return Point(int(x), int(y), self.curve)