Ryan Rueger

ryan@rueg.re / picture / key / home
aboutsummaryrefslogtreecommitdiffhomepage
path: root/theta_lib/theta_structures/montgomery_theta.py
diff options
context:
space:
mode:
authorRyan Rueger <git@rueg.re>2025-03-01 20:25:41 +0100
committerRyan Rueger <git@rueg.re>2025-03-01 22:11:11 +0100
commitd40de259097c5e8d8fd35539560ca7c3d47523e7 (patch)
tree18e0f94350a2329060c2a19b56b0e3e2fdae56f1 /theta_lib/theta_structures/montgomery_theta.py
downloadpegasis-d40de259097c5e8d8fd35539560ca7c3d47523e7.tar.gz
pegasis-d40de259097c5e8d8fd35539560ca7c3d47523e7.tar.bz2
pegasis-d40de259097c5e8d8fd35539560ca7c3d47523e7.zip
Initial Commit
Co-Authored-By: Damien Robert <Damien.Olivier.Robert+git@gmail.com> Co-Authored-By: Frederik Vercauteren <frederik.vercauteren@gmail.com> Co-Authored-By: Jonathan Komada Eriksen <jonathan.eriksen97@gmail.com> Co-Authored-By: Pierrick Dartois <pierrickdartois@icloud.com> Co-Authored-By: Riccardo Invernizzi <nidadoni@gmail.com> Co-Authored-By: Ryan Rueger <git@rueg.re> [0.01s] Co-Authored-By: Benjamin Wesolowski <benjamin@pasch.umpa.ens-lyon.fr> Co-Authored-By: Arthur Herlédan Le Merdy <ahlm@riseup.net> Co-Authored-By: Boris Fouotsa <tako.fouotsa@epfl.ch>
Diffstat (limited to 'theta_lib/theta_structures/montgomery_theta.py')
-rw-r--r--theta_lib/theta_structures/montgomery_theta.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/theta_lib/theta_structures/montgomery_theta.py b/theta_lib/theta_structures/montgomery_theta.py
new file mode 100644
index 0000000..6dddb2b
--- /dev/null
+++ b/theta_lib/theta_structures/montgomery_theta.py
@@ -0,0 +1,68 @@
+from sage.all import *
+
+def torsion_to_theta_null_point(P):
+ r=P[0]
+ s=P[2]
+ return (r+s,r-s)
+
+def montgomery_point_to_theta_point(O,P):
+ if P[0]==P[2]==0:
+ return O
+ else:
+ a,b=O
+ return (a*(P[0]-P[2]),b*(P[0]+P[2]))
+
+def theta_point_to_montgomery_point(E,O,P,twist=False):
+ a,b=O
+
+ x=a*P[1]+b*P[0]
+ z=a*P[1]-b*P[0]
+
+ if twist:
+ x=-x
+
+ if z==0:
+ return E(0)
+ else:
+ x=x/z
+
+ a_inv=E.a_invariants()
+
+ A =a_inv[1]
+ if a_inv != (0,A,0,1,0):
+ raise ValueError("The elliptic curve E is not in the Montgomery model.")
+
+ y2=x*(x**2+A*x+1)
+ if not is_square(y2):
+ raise ValueError("The Montgomery point is not on the base field.")
+ else:
+ y=y2.sqrt()
+ return E([x,y,1])
+
+def lift_kummer_montgomery_point(E,x,z=1):
+ if z==0:
+ return E(0)
+ elif z!=1:
+ x=x/z
+
+ a_inv=E.a_invariants()
+
+ A =a_inv[1]
+ if a_inv != (0,A,0,1,0):
+ raise ValueError("The elliptic curve E is not in the Montgomery model.")
+
+ y2=x*(x**2+A*x+1)
+ if not is_square(y2):
+ raise ValueError("The Montgomery point is not on the base field.")
+ else:
+ y=y2.sqrt()
+ return E([x,y,1])
+
+def null_point_to_montgomery_coeff(a,b):
+ return -2*(a**4+b**4)/(a**4-b**4)
+
+
+
+
+
+