I’m learning the ECC cryptogarphy these days and tring to write a program to calculate the results of point addition. However, I found that the results are different when using different coordinate systems and I cannot figure out the mistakes. I chose the BLS12-377 curve and started from the affine system. Here are my codes:
m = (3 * x1 * x1) * inverse(2 * y1,p)
x3 = m * m - x1 - x2
y3 = y1 + m * (x3 - x1)
result_x = x3 % p
result_y = -y3 % p
The results are correct but the speed is too slow. I have learned from the paper Twisted Edwards Curves and I tried to use the extended twisted Edwards coordinates to speed up my design. Unfortunately, the results are not the same. Here are my codes:
Z1 = 1
Z2 = 1
T1 = X1 * Y1 * Z1 % p
T2 = X2 * Y2 * Z2 % p
A = (Y1 - X1) * (Y2 - X2)
B = (Y1 + X1) * (Y2 + X2)
C = (k * T1 * T2)
D = (2 * Z1 * Z2)
E = (B - A)
F = (D - C)
G = (D + C)
H = (B + A)
X3 = (E * F) % p
Y3 = (G * H) % p
T3 = (E * H) % p
Z3 = (F * G) % p
inverse_element = inverse(Z3,p)
x_affine = (X3 * inverse_element) % p
y_affine = (Y3 * inverse_element) % p
I set Z1 and Z2 as 1 to get the calculation simper.So where are the mistakes? I have tried other coordinates such as the projection coordinate, the results are correct. But once I choose this system, the results are wrong. I have checked the formula carefully and it has no mistakes.
Chen Cheng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.