Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide Q.log(P) instead of P.discrete_log(Q) for elliptic-curve points #37152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/ell_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ def abelian_group(self):

S = n//nQ * P
T = n2 * Q
S.set_order(nQ//n2, check=False) # for .discrete_log()
x = S.discrete_log(T)
S.set_order(nQ//n2, check=False) # for .log()
x = T.log(S)
Q -= x * n1//nQ * P

assert not n2 * Q # by construction
Expand Down
53 changes: 40 additions & 13 deletions src/sage/schemes/elliptic_curves/ell_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -3842,10 +3842,11 @@

return Q

def discrete_log(self, Q):
def log(self, base):
r"""
Return the discrete logarithm of `Q` to base `P` = ``self``,
that is, an integer `x` such that `xP = Q`.
Return the discrete logarithm of this point to the given ``base``.
In other words, return an integer `x` such that `xP = Q` where
`P` is ``base`` and `Q` is this point.

A :class:`ValueError` is raised if there is no solution.

Expand Down Expand Up @@ -3873,7 +3874,7 @@

INPUT:

- ``Q`` (point) -- another point on the same curve as ``self``.
- ``base`` (point) -- another point on the same curve as ``self``.

OUTPUT:

Expand All @@ -3896,7 +3897,7 @@
762
sage: P = E.gens()[0]
sage: Q = 400*P
sage: P.discrete_log(Q)
sage: Q.log(P)
400

TESTS:
Expand All @@ -3910,27 +3911,53 @@
sage: E = EllipticCurve(j=GF((p,e),'a').random_element())
sage: P = E.random_point()
sage: Q = randrange(2**999) * P
sage: x = P.discrete_log(Q)
sage: x = Q.log(P)
sage: x*P == Q
True
"""
if Q not in self.parent():
if base not in self.parent():
raise ValueError('not a point on the same curve')
n = self.order()
if n*Q:
raise ValueError('ECDLog problem has no solution (order of Q does not divide order of P)')
n = base.order()
if n*self:
raise ValueError('ECDLog problem has no solution (order does not divide order of base)')
E = self.curve()
F = E.base_ring()
p = F.cardinality()
if F.is_prime_field() and n == p:
# Anomalous case
return self.padic_elliptic_logarithm(Q, p)
return base.padic_elliptic_logarithm(self, p)

Check warning on line 3928 in src/sage/schemes/elliptic_curves/ell_point.py

View check run for this annotation

Codecov / codecov/patch

src/sage/schemes/elliptic_curves/ell_point.py#L3928

Added line #L3928 was not covered by tests
elif hasattr(E, '_order') and E._order.gcd(n**2) == n:
pass # cyclic rational n-torsion -> okay
elif self.weil_pairing(Q, n) != 1:
elif base.weil_pairing(self, n) != 1:
raise ValueError('ECDLog problem has no solution (non-trivial Weil pairing)')

return ZZ(pari.elllog(self.curve(), Q, self, n))
return ZZ(pari.elllog(self.curve(), self, base, n))

def discrete_log(self, Q):
r"""
Legacy version of :meth:`log` with its arguments swapped.

Note that this method uses the opposite argument ordering
of all other logarithm methods in Sage; see :issue:`37150`.

EXAMPLES::

sage: E = EllipticCurve(j=GF(101)(5))
sage: P, = E.gens()
sage: (2*P).log(P)
2
sage: (2*P).discrete_log(P)
doctest:warning ...
DeprecationWarning: The syntax P.discrete_log(Q) ... Please update your code. ...
45
sage: P.discrete_log(2*P)
2
"""
from sage.misc.superseded import deprecation
deprecation(37150, 'The syntax P.discrete_log(Q) is being replaced by '
'Q.log(P) to make the argument ordering of logarithm'
' methods in Sage uniform. Please update your code.')
return Q.log(self)

def padic_elliptic_logarithm(self,Q, p):
r"""
Expand Down
Loading