diff options
| author | J08nY | 2023-08-01 21:19:34 +0200 |
|---|---|---|
| committer | J08nY | 2023-08-01 21:19:34 +0200 |
| commit | 14a27ac5cb34ec16547e9a1c689713dc24c94a78 (patch) | |
| tree | 2392f450381da9a67336fa15170b9b6f755d6cf9 | |
| parent | a702c701187c92b9e6f8d7b889430f1c368bf330 (diff) | |
| download | pyecsca-14a27ac5cb34ec16547e9a1c689713dc24c94a78.tar.gz pyecsca-14a27ac5cb34ec16547e9a1c689713dc24c94a78.tar.zst pyecsca-14a27ac5cb34ec16547e9a1c689713dc24c94a78.zip | |
| -rw-r--r-- | pyecsca/ec/divpoly.py | 15 | ||||
| -rwxr-xr-x | test/ec/perf_divpoly.py | 30 |
2 files changed, 39 insertions, 6 deletions
diff --git a/pyecsca/ec/divpoly.py b/pyecsca/ec/divpoly.py index 460b861..c92ef64 100644 --- a/pyecsca/ec/divpoly.py +++ b/pyecsca/ec/divpoly.py @@ -1,3 +1,6 @@ +""" +Provides functions for computing division polynomials and the multiplication-by-n map on an elliptic curve. +""" from typing import Tuple, Dict, Set, Mapping from sympy import symbols, FF, Poly @@ -167,10 +170,10 @@ def divpoly(curve: EllipticCurve, n: int, two_torsion_multiplicity: int = 2) -> """ Compute the n-th division polynomial. - :param curve: - :param n: - :param two_torsion_multiplicity: - :return: + :param curve: Curve to compute on. + :param n: Scalar. + :param two_torsion_multiplicity: Same as sagemath. + :return: The division polynomial. """ f: Poly = divpoly0(curve, n)[n] a1, a2, a3, a4, a6 = a_invariants(curve) @@ -199,7 +202,7 @@ def mult_by_n(curve: EllipticCurve, n: int) -> Tuple[Tuple[Poly, Poly], Tuple[Po :param curve: Curve to compute on. :param n: Scalar. - :return: + :return: A tuple (mx, my) where each is a tuple (numerator, denominator). """ xs, ys = symbols("x y") K = FF(curve.prime) @@ -208,7 +211,7 @@ def mult_by_n(curve: EllipticCurve, n: int) -> Tuple[Tuple[Poly, Poly], Tuple[Po Kxy = lambda r: Poly(r, xs, ys, domain=K) # noqa if n == 1: - return x + return x, y a1, a2, a3, a4, a6 = a_invariants(curve) diff --git a/test/ec/perf_divpoly.py b/test/ec/perf_divpoly.py new file mode 100755 index 0000000..2937af1 --- /dev/null +++ b/test/ec/perf_divpoly.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +import click + +from pyecsca.ec.divpoly import mult_by_n +from pyecsca.ec.params import get_params +from datetime import datetime + + +@click.command() +@click.option("-n", type=click.INT, default=21) +def main(n): + p256 = get_params("secg", "secp256r1", "projective") + + ns = [] + durs = [] + mems = [] + for i in range(2, n): + start = datetime.now() + mx, my = mult_by_n(p256.curve, i) + end = datetime.now() + duration = (end - start).total_seconds() + memory = (mx[0].degree() + mx[1].degree() + my[0].degree() + my[1].degree()) * 32 + ns.append(i) + durs.append((end - start).total_seconds()) + mems.append(memory) + print(i, duration, memory, sep=",") + + +if __name__ == "__main__": + main() |
