130
130
from sage .rings .integer import Integer
131
131
from sage .rings .integer_ring import ZZ
132
132
from sage .rings .rational_field import QQ
133
+ from sage .rings .finite_rings .integer_mod import Mod
133
134
from sage .rings .real_mpfr import RealField
134
135
from sage .rings .real_mpfr import RR
135
136
import sage .groups .generic as generic
@@ -1935,6 +1936,13 @@ def tate_pairing(self, Q, n, k, q=None):
1935
1936
...
1936
1937
ValueError: The point P must be n-torsion
1937
1938
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
+
1938
1946
The Tate pairing is only defined for points on curves defined over finite fields::
1939
1947
1940
1948
sage: E = EllipticCurve([0,1])
@@ -1973,6 +1981,9 @@ def tate_pairing(self, Q, n, k, q=None):
1973
1981
q = K .base_ring ().order ()
1974
1982
else :
1975
1983
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" )
1976
1987
1977
1988
if pari .ellmul (E , P , n ) != [0 ]:
1978
1989
raise ValueError ("The point P must be n-torsion" )
@@ -1981,8 +1992,6 @@ def tate_pairing(self, Q, n, k, q=None):
1981
1992
# must perform the exponentation ourselves using the supplied
1982
1993
# k value
1983
1994
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?
1986
1995
exp = Integer ((q ** k - 1 )/ n )
1987
1996
return K (ePQ ** exp ) # Cast the PARI type back to the base ring
1988
1997
0 commit comments