aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--pyecsca/ec/divpoly.py7
-rw-r--r--pyecsca/sca/re/zvp.py3
2 files changed, 6 insertions, 4 deletions
diff --git a/pyecsca/ec/divpoly.py b/pyecsca/ec/divpoly.py
index c66d75d..6621b76 100644
--- a/pyecsca/ec/divpoly.py
+++ b/pyecsca/ec/divpoly.py
@@ -1,7 +1,7 @@
"""
Provides functions for computing division polynomials and the multiplication-by-n map on an elliptic curve.
"""
-from typing import Tuple, Dict, Set, Mapping
+from typing import Tuple, Dict, Set, Mapping, Optional
from public import public
from sympy import symbols, FF, Poly
@@ -203,12 +203,13 @@ def divpoly(curve: EllipticCurve, n: int, two_torsion_multiplicity: int = 2) ->
@public
-def mult_by_n(curve: EllipticCurve, n: int) -> Tuple[Tuple[Poly, Poly], Tuple[Poly, Poly]]:
+def mult_by_n(curve: EllipticCurve, n: int, x_only: bool = False) -> Tuple[Tuple[Poly, Poly], Optional[Tuple[Poly, Poly]]]:
"""
Compute the multiplication-by-n map on an elliptic curve.
:param curve: Curve to compute on.
:param n: Scalar.
+ :param x_only: Whether to skip the my computation.
:return: A tuple (mx, my) where each is a tuple (numerator, denominator).
"""
xs, ys = symbols("x y")
@@ -241,6 +242,8 @@ def mult_by_n(curve: EllipticCurve, n: int) -> Tuple[Tuple[Poly, Poly], Tuple[Po
# > lc = K(mx_denom.LC())
# > mx = (mx_num.quo(lc), mx_denom.monic())
mx = (mx_num, mx_denom)
+ if x_only:
+ return mx, None
# The following lines compute
# my = ((2*y+a1*x+a3)*mx.derivative(x)/m - a1*mx-a3)/2
diff --git a/pyecsca/sca/re/zvp.py b/pyecsca/sca/re/zvp.py
index a92e860..108c9ac 100644
--- a/pyecsca/sca/re/zvp.py
+++ b/pyecsca/sca/re/zvp.py
@@ -190,8 +190,7 @@ def subs_dlog(poly: Poly, k: int, curve: EllipticCurve):
new_gens = set(gens)
new_gens.remove(x2)
- mx, my = mult_by_n(curve, k)
- # TODO: my is unnecessary here so maybe add a function to not compute it (speedup).
+ mx, _ = mult_by_n(curve, k, x_only=True)
u, v = mx[0].subs("x", x1), mx[1].subs("x", x1)
# The polynomials are quite dense, hence it makes sense