diff options
| -rw-r--r-- | .github/workflows/perf.yml | 6 | ||||
| -rw-r--r-- | .github/workflows/test.yml | 6 | ||||
| -rw-r--r-- | pyecsca/sca/re/zvp.py | 20 |
3 files changed, 17 insertions, 15 deletions
diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index fff2b8c..1bcd949 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -6,7 +6,7 @@ env: LLVM_CONFIG: /usr/bin/llvm-config-10 PS_PACKAGES: libps4000 libps5000 libps6000 GMP_PACKAGES: libgmp-dev libmpfr-dev libmpc-dev - OTHER_PACKAGES: swig gcc libpcsclite-dev llvm-10 libllvm10 llvm-10-dev + OTHER_PACKAGES: swig gcc libpcsclite-dev llvm-10 libllvm10 llvm-10-dev libpari-dev pari-gp pari-seadata jobs: perf: @@ -53,8 +53,8 @@ jobs: - name: Install dependencies run: | python -m pip install -U pip setuptools wheel - if [ $USE_GMP == 1 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, gmp, test, dev]"; fi - if [ $USE_GMP == 0 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, test, dev]"; fi + if [ $USE_GMP == 1 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, pari, gmp, test, dev]"; fi + if [ $USE_GMP == 0 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, pari, test, dev]"; fi - name: Perf run: | make perf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09736e4..cba342e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ env: LLVM_CONFIG: /usr/bin/llvm-config-10 PS_PACKAGES: libps4000 libps5000 libps6000 GMP_PACKAGES: libgmp-dev libmpfr-dev libmpc-dev - OTHER_PACKAGES: swig gcc libpcsclite-dev llvm-10 libllvm10 llvm-10-dev + OTHER_PACKAGES: swig gcc libpcsclite-dev llvm-10 libllvm10 llvm-10-dev libpari-dev pari-gp pari-seadata jobs: test: @@ -53,8 +53,8 @@ jobs: - name: Install dependencies run: | python -m pip install -U pip setuptools wheel - if [ $USE_GMP == 1 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, gmp, test, dev]"; fi - if [ $USE_GMP == 0 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, test, dev]"; fi + if [ $USE_GMP == 1 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, pari, gmp, test, dev]"; fi + if [ $USE_GMP == 0 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, pari, test, dev]"; fi - name: Test run: | make test diff --git a/pyecsca/sca/re/zvp.py b/pyecsca/sca/re/zvp.py index 21915da..517299f 100644 --- a/pyecsca/sca/re/zvp.py +++ b/pyecsca/sca/re/zvp.py @@ -8,13 +8,6 @@ from public import public from astunparse import unparse from sympy import FF, Poly, Monomial, Symbol, Expr, sympify, symbols, div -from tqdm.auto import tqdm - -try: - import cypari2 -except ModuleNotFoundError: - pass - from .rpa import MultipleContext from ...ec.context import local from ...ec.curve import EllipticCurve @@ -34,6 +27,15 @@ from ...ec.params import DomainParameters from ...ec.point import Point +has_pari = False +try: + import cypari2 + + has_pari = True +except ImportError: + cypari2 = None + + @public def unroll_formula_expr(formula: Formula) -> List[Tuple[str, Expr]]: """ @@ -504,7 +506,7 @@ def zvp_points(poly: Poly, curve: EllipticCurve, k: int, n: int) -> Set[Point]: def solve_easy_dcp(xonly_polynomial: Poly, curve: EllipticCurve) -> Set[Point]: points = set() final = subs_curve_params(xonly_polynomial, curve) - if "cypari2" in dir(): + if has_pari: pari = cypari2.Pari() polynomial = pari(str(xonly_polynomial.expr).replace("**", "^")) roots = list(map(int, pari.polrootsmod(polynomial, curve.prime))) @@ -517,7 +519,7 @@ def solve_easy_dcp(xonly_polynomial: Poly, curve: EllipticCurve) -> Set[Point]: def solve_hard_dcp(xonly_polynomial: Poly, curve: EllipticCurve, k: int) -> Set[Point]: points = set() - if "cypari2" in dir(): + if has_pari: roots = solve_hard_dcp_cypari(xonly_polynomial, curve, k) else: # Substitute in the mult-by-k map |
