Skip to content

Commit d118f1c

Browse files
committed
Check that n divides (q^k - 1)
1 parent a0603ee commit d118f1c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/sage/schemes/elliptic_curves/ell_point.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
from sage.rings.integer import Integer
131131
from sage.rings.integer_ring import ZZ
132132
from sage.rings.rational_field import QQ
133+
from sage.rings.finite_rings.integer_mod import Mod
133134
from sage.rings.real_mpfr import RealField
134135
from sage.rings.real_mpfr import RR
135136
import sage.groups.generic as generic
@@ -1935,6 +1936,13 @@ def tate_pairing(self, Q, n, k, q=None):
19351936
...
19361937
ValueError: The point P must be n-torsion
19371938
1939+
We must have that ``n`` divides ``q^k - 1``, this is only checked when q is supplied::
1940+
1941+
sage: P.tate_pairing(Q, 7282, 2, q=123)
1942+
Traceback (most recent call last):
1943+
...
1944+
ValueError: n does not divide (q^k - 1) for the supplied value of q
1945+
19381946
The Tate pairing is only defined for points on curves defined over finite fields::
19391947
19401948
sage: E = EllipticCurve([0,1])
@@ -1973,6 +1981,9 @@ def tate_pairing(self, Q, n, k, q=None):
19731981
q = K.base_ring().order()
19741982
else:
19751983
raise ValueError("Unexpected field degree: set keyword argument q equal to the size of the base field (big field is GF(q^%s))." % k)
1984+
# The user has supplied q, so we check here that it's a sensible value
1985+
elif Mod(q, n)**k != 1:
1986+
raise ValueError("n does not divide (q^k - 1) for the supplied value of q")
19761987

19771988
if pari.ellmul(E, P, n) != [0]:
19781989
raise ValueError("The point P must be n-torsion")
@@ -1981,8 +1992,6 @@ def tate_pairing(self, Q, n, k, q=None):
19811992
# must perform the exponentation ourselves using the supplied
19821993
# k value
19831994
ePQ = pari.elltatepairing(E, P, Q, n)
1984-
# TODO: if n or k is chosen badly, this could error, should we
1985-
# handle this explicitly by ensuring n divides q^k - 1?
19861995
exp = Integer((q**k - 1)/n)
19871996
return K(ePQ**exp) # Cast the PARI type back to the base ring
19881997

0 commit comments

Comments
 (0)