If you know how to add - it is enough to perform the subtraction:
M = P - Q = P + (-Q) - here M point is P point minus Q point, which is the same as P point plus (-Q) point. So you make the addition of points P and (-Q).
If Q point has coordinates (Qx, Qy), so (-Q) point will have coordinates (Qx, modulo - Qy)
Now you can easily can make a subtraction:
M = P - Q = (Px, Py) - (Qx, Qy) = (Px, Py) + (Qx, modulo - Qy)
Perhaps there is an implementation in C++ or Python code?
python
p=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F #field
n=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 #curve
def inv(a,p):
u, v = a%p, p
x1, x2 = 1, 0
while u != 1 :
#q = v//u
#r = v-q*u
q, r = divmod(v,u)
x = x2-q*x1
v = u
u = r
x2 = x1
x1 = x
return x1%p
def add(ax, ay, bx, by): #A + B -> C
bxax_inv = inv(bx-ax, p) #1/(x2-x1)
m = ( (by-ay) * bxax_inv ) % p #m = (y2-y1)/(x2-x1)
cx = (m*m - ax - bx) % p
cy = (m * (ax - cx) - ay) % p
return cx, cy
def sub(ax, ay, bx, by,): #A - B -> C
bxax_inv = inv(bx-ax, p) #1/(x2-x1)
m = ((p-by-ay) * inverse) % p
cx = (m*m - ax - bx) % p
cy = (m * (ax - cx) - ay) % p
return cx, cy