Path: blob/master/attacks/ecc/parameter_recovery.py
2589 views
def attack(p, x1, y1, x2, y2):1"""2Recovers the a and b parameters from an elliptic curve when two points are known.3:param p: the prime of the curve base ring4:param x1: the x coordinate of the first point5:param y1: the y coordinate of the first point6:param x2: the x coordinate of the second point7:param y2: the y coordinate of the second point8:return: a tuple containing the a and b parameters of the elliptic curve9"""10a = pow(x1 - x2, -1, p) * (pow(y1, 2, p) - pow(y2, 2, p) - (pow(x1, 3, p) - pow(x2, 3, p))) % p11b = (pow(y1, 2, p) - pow(x1, 3, p) - a * x1) % p12return int(a), int(b)131415