Score:1

Finite field Elliptic Curve line intersection

cn flag

I want to find the curve points that intersects an arbirtary line, not just tangent line or a line through curve points. An example:

p = 1303
b = 7

input : arbitrary points : (1, 1),(2, 2)
output : curve points : (319,319),(356,356),(629,629)

(319,319) 319^3+7 ≡ 319^2 ≡ 127 (mod p)
(356,356) 356^3+7 ≡ 356^2 ≡ 345 (mod p) 
(629,629) 629^3+7 ≡ 629^2 ≡ 832 (mod p)

The line should wrap around the field

Here is the wolfram alpha exact form real solution for query ;
solve x , (mx+b)^2=x^3+7

enter image description here

Immediately getting issues with $\sqrt[3]2$ which has no solutions mod 1303 $\not ∃ x \in \mathbb{F}_p : x^3 \equiv 2$
p = 1303
squarerrot x^((p+2)/9) , 326 for p = 1303 cuberoot x^((p+1)/4) , 145 for p = 1303 Could try substituting $\sqrt[3]2$ with two to the power of one third? 190 I doubt it will work so I'm putting it putting it off until the weekend Cuberoot of 3 is 88

EDIT: Turns out it doesn't matter if the roots make sense , the "cuberoot" of 2 ( = 1217) cubed is 1111

Added another variable for the slope because I figured you need a ratio. I have not tested it much but it returns 629 for (1,1,0) which is a correct solution.

The input should ideally be two points not three scalars though.

P = 1303
def sqrtp(x):
    return pow(x, (P + 1) // 4, P)
def cbrtp(x):
    return pow(x, (P + 2) / 9, P)
def modinv(x):
    return pow(x, (P - 2), P)
cbrt2 = cbrtp(2)

def sect(m,n,b):
  L = 27*(b**2 - 7)*n**2 + 18*b*m**3*n + 2*m**6
  U = (-6*b*m*n - m**4) % P
  T = cbrtp(sqrtp(L**2 + 4*U**3) + L) % P
  x = T * modinv((3 * cbrt2 * n)) -  ( cbrt2 * U) * modinv(3*n*T) + m**2 * modinv(3*n)
  # x =  (2*m**2*T + cbrt2*(cbrt2*T**2 - 2*U)) * modinv(6*n*T) doesn't work
  return x % P

print sect(1,1,0)

Using just one division instead of 3 doesn't seem to work.

enter image description here

Checking where a line intersects the curve is a similar concept to point addition

The calculation shouldn't be overly more complicated just because the line is not defined by curve points?

kelalaka avatar
in flag
Welcome to Cryptography.SE. Your first center is not clear and the curve is not defined, too. Are you asking a line passing through 3 points? this is easy, take $P$ and $Q$ calculate $R = P+Q$ then $P,Q,-R$ on the same line. An [image](https://crypto.stackexchange.com/a/87545/18298) from this answer (or [here](https://crypto.stackexchange.com/q/87546/18298) )might help you to visualize.
PrincePolka avatar
cn flag
I only find algorithms that assume inputs are points satifying the curve equation
kelalaka avatar
in flag
Could you write your problem more explicitly? What do mean points that intersect an arbitrary line? A point can lie on a line or not.
PrincePolka avatar
cn flag
The input is two points, on or off the elliptic curve that forms a line. The output should be points that are both on the elliptic curve, and on the line formed by the two arbitrary points.
kelalaka avatar
in flag
In this case, form the line equation and intersect with the curve. $y = mx +c$ and take square and equate to the right part of the curve equation and solve!
fgrieu avatar
ng flag
Hint: check that your numbers are consistent with the unstated: that the curve is $y^2\equiv x^3+b\pmod p$; is that a proper curve (there's a condition to test for $b$ w.r.t. $p$)? If so, what about writing the equation for the line going thru the arbitrary points as if $x$ and $y$ where in the familiar $\mathbb R$, stating that same equation in $\mathbb F_p$ (the field modulo $p$), and solving the system of two equations?
Score:2
in flag

The first step is forming the line equation with the slope; $y = mx+c$, and in your case $m=1$ and $c=0$. Now equate this with the curve equation $y^2 = x^3 + 7$;

$$x^2 = x^3 + 7$$ and this forms

$$f(x) = x^3 -x^2 + 7 $$

We need to find the roots in the field $\operatorname{GF}(1303)$. SageMath is your friend here

R.<x> = GF(1303)[]
px = 1
py = 1
qx = 2
qy = 2
m = R((qy-py)/(qx-px))
print("slope = ",m)
c = py - m*px
print("c = ", c)
g = m*x + c
f = x^3 + 7

h = f - g^2

h.roots()

and outputs

slope =  1
c =  0
[(629, 1), (356, 1), (319, 1)]

And here the images of the curve, red line the line you choose, and the points that the red line intersects with the curve are the points that the red line and black lines intersect.

enter image description here.

kelalaka avatar
in flag
I hope this was not an HW!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.