def __mul__(self, scalar: int): """Multiply a :class:`Point` on an elliptic curve by an integer. Args: | self (:class:`Point`): a point :math:`P` on the curve | other (int): an integer :math:`d \in \mathbb{Z_q}` where :math:`q` is the order of the curve that :math:`P` is on Returns: :class:`Point`: A point :math:`R` such that :math:`R = P * d` """ validate_type(scalar, int) if scalar == 0: return self.IDENTITY_ELEMENT x, y = curvemath.mul(str(self.x), str(self.y), str(scalar), str(self.curve.p), str(self.curve.a), str(self.curve.b), str(self.curve.q), str(self.curve.gx), str(self.curve.gy)) x = int(x) y = int(y) if x == 0 and y == 0: return self.IDENTITY_ELEMENT return Point(x, y, self.curve)
def __mul__(self, scalar): """Multiply a :class:`Point`s on an elliptic curve by an integer. Args: | self (fastecdsa.point.Point): a point :math:`P` on the curve | other (long): an integer :math:`d \in \mathbb{Z_q}` where :math:`q` is the order of the curve that :math:`P` is on Returns: fastecdsa.point.Point: A point :math:`R` such that :math:`R = P * d` """ try: d = int(scalar) % self.curve.q except ValueError: raise TypeError('Curve point multiplication must be by an integer') else: x, y = curvemath.mul( str(self.x), str(self.y), str(d), 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)
def __mul__(self, scalar): e = scalar if self.__order: e = e % self.__order if e == 0: return INFINITY if self == INFINITY: return INFINITY try: d = int(scalar) % self.__order except ValueError: raise TypeError('Curve point multiplication must be by an integer') else: x, y = curvemath.mul( str(self.__x), str(self.__y), str(d), str(self.__curve.p()), str(self.__curve.a()), str(self.__curve.b()), str(self.__order), # hardcode secp256k1 generator x and y. TODO: refactor str(0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 ), str(0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 )) return Point(self.curve(), int(x), int(y), self.order())