aboutsummaryrefslogtreecommitdiff
path: root/test/ec
diff options
context:
space:
mode:
authorJ08nY2024-08-26 17:27:18 +0200
committerJ08nY2024-08-26 17:27:18 +0200
commit89a5183ad410e0a9b9a8c872b4548e1c32f9f83f (patch)
tree1ed1ff5caf58ecf1a252cca1a3f51dbf6e57ec91 /test/ec
parent481f567792d05e6a4e09121a7358252b11706ee8 (diff)
downloadpyecsca-89a5183ad410e0a9b9a8c872b4548e1c32f9f83f.tar.gz
pyecsca-89a5183ad410e0a9b9a8c872b4548e1c32f9f83f.tar.zst
pyecsca-89a5183ad410e0a9b9a8c872b4548e1c32f9f83f.zip
Diffstat (limited to 'test/ec')
-rw-r--r--test/ec/test_formula.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/test/ec/test_formula.py b/test/ec/test_formula.py
index c0350cb..137f243 100644
--- a/test/ec/test_formula.py
+++ b/test/ec/test_formula.py
@@ -1,6 +1,7 @@
import pickle
from operator import itemgetter
from typing import Tuple
+import multiprocessing as mp
import pytest
from sympy import FF, symbols
@@ -111,18 +112,27 @@ def test_assumptions(secp128r1, mdbl):
@pytest.mark.parametrize(
"formula,category,curve,coords",
- [("dbl-1998-hnm", "secg", "secp128r1", "jacobian"),
- ("add-2015-rcb", "secg", "secp128r1", "projective"),
- ("dbl-1987-m-2", "other", "Curve25519", "xz"),
- ("add-20090311-hwcd", "other", "E-222", "projective")]
+ [
+ ("dbl-1998-hnm", "secg", "secp128r1", "jacobian"),
+ ("add-2015-rcb", "secg", "secp128r1", "projective"),
+ ("dbl-1987-m-2", "other", "Curve25519", "xz"),
+ ("add-20090311-hwcd", "other", "E-222", "projective"),
+ ],
)
def test_eval(formula, category, curve, coords):
params = get_params(category, curve, coords)
f = params.curve.coordinate_model.formulas[formula]
points_aff = [params.curve.affine_random() for _ in range(f.num_inputs)]
- points = [point.to_model(params.curve.coordinate_model, params.curve) for point in points_aff]
- expected = params.curve.affine_double(*points_aff) if f.shortname == "dbl" else params.curve.affine_add(*points_aff)
+ points = [
+ point.to_model(params.curve.coordinate_model, params.curve)
+ for point in points_aff
+ ]
+ expected = (
+ params.curve.affine_double(*points_aff)
+ if f.shortname == "dbl"
+ else params.curve.affine_add(*points_aff)
+ )
res = f(
params.curve.prime,
@@ -418,9 +428,12 @@ def library_formula_params(request) -> Tuple[CodeFormula, DomainParameters]:
name, model, coords_name, param_spec, formula_type = request.param
model = model()
coordinate_model = model.coordinates[coords_name]
- with as_file(files(pyecsca.ec).joinpath("data", "formulas", name)) as meta_path, as_file(
- files(pyecsca.ec).joinpath("data", "formulas", name + ".op3")
- ) as op3_path:
+ with (
+ as_file(files(pyecsca.ec).joinpath("data", "formulas", name)) as meta_path,
+ as_file(
+ files(pyecsca.ec).joinpath("data", "formulas", name + ".op3")
+ ) as op3_path,
+ ):
formula = formula_type(meta_path, op3_path, name, coordinate_model).to_code()
params = get_params(*param_spec, coords_name)
return formula, params
@@ -550,3 +563,11 @@ def test_formula_expand_parallel(add):
assert len(res) > 1
other = expand_formula_set({add})
assert res == other
+
+
+def test_formula_expand_deterministic(add):
+ ctx = mp.get_context("spawn")
+ with ctx.Pool(4) as p:
+ results = p.map(expand_formula_set, [{add}] * 10)
+ for result in results:
+ assert result == results[0]