Reputation: 41
I want to do point subtraction on an elliptic curve on a prime field. I tried taking the points to be subtracted as (x,-y log(p))
but my answer doesn't seem to match.
This is how I tried to do the subtraction:
s9=point_addition(s6.a,s6.b,((s8.a)%211) ,-((s8.b)%211));
here s9
, s6
and s8
are all structures with two int
.
and this is my function which does the point addition:
structure point_addition(int x1, int y1, int x2, int y2)
{
int s,xL,yL;
if((x1-x2)!=0)
{
if ((((y1-y2)/(x1-x2)) % 211)>0)
s=(((y1-y2)/(x1-x2)) % 211);
else
s=(((y1-y2)/(x1-x2)) % 211) + 211;
if ((((s*s)-(x1+x2)) % 211)>0)
xL= (((s*s)-(x1+x2)) % 211) ;
else
xL= (((s*s)-(x1+x2)) % 211) + 211;
if(((-y1+s*(x1-x2)) % 211)>0)
yL= ((-y1+s*(x1-xL)) % 211);
else
yL= ((-y1+s*(x1-x2)) % 211) + 211;
}
else
{
xL= 198 ;
yL= 139;
}
s7.a= xL;
s7.b= yL;
return s7 ;
}
The programs doesn't seem to give me the correct co-ordinates Please help me with this coding for elliptic curve cryptography.
Upvotes: 3
Views: 2798
Reputation: 41
I don`t understand what you are doing there exactly, what your log(p) is supposed to mean and where your domain parameters enter, but subtracting is easy: Negate the y-coordinate (-Y = modulus - y) and then plainly add as usual.
If you want a reference for your calculations, you might use my open source software "Academic Signature" from this link It is quite transparent with its calculations and produces e.g. results of ECDSA-signatures in human readable hex notation. I am not sure at the moment though, if it can do calculations with such short moduli you are working with.
The manual featuring descriptions on how to program ECC-operations correctly and how to use the software is there: Link to ecc Manual
Regards Michael Anders
Upvotes: 1
Reputation: 403
See GregS's comment about division mod p. You need to find the inverse of the denominator and then multiply. To calculate the modular inverse you could use the extended euclidean algorithm.
Also the way you're negating the y coordinate then adding 211 later is a bit odd. Best to keep field elements in the proper range when passing as arguments, e.g. to obtain -y mod p, use p-y.
And I assume this is just a learning exercise since you're using a very small field :)
Upvotes: 2