diff options
| author | J08nY | 2025-10-24 22:56:08 +0200 |
|---|---|---|
| committer | J08nY | 2025-10-24 22:56:08 +0200 |
| commit | 7976afc6c0b765fe78e032c19c7c40c7cee11f51 (patch) | |
| tree | 6973513fce239dd46a661376ab4b70768aa53a9a /test/ec/test_countermeasures.py | |
| parent | 5cc7934961314d934968298ec9c1a0655d6e48fa (diff) | |
| download | pyecsca-7976afc6c0b765fe78e032c19c7c40c7cee11f51.tar.gz pyecsca-7976afc6c0b765fe78e032c19c7c40c7cee11f51.tar.zst pyecsca-7976afc6c0b765fe78e032c19c7c40c7cee11f51.zip | |
Diffstat (limited to 'test/ec/test_countermeasures.py')
| -rw-r--r-- | test/ec/test_countermeasures.py | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/test/ec/test_countermeasures.py b/test/ec/test_countermeasures.py index c3a6ee3..b802525 100644 --- a/test/ec/test_countermeasures.py +++ b/test/ec/test_countermeasures.py @@ -1,5 +1,4 @@ from itertools import product -from copy import copy import pytest @@ -13,6 +12,7 @@ from pyecsca.ec.countermeasures import ( ) from pyecsca.ec.mod import mod from pyecsca.ec.mult import * +from pyecsca.sca.re.rpa import multiple_graph @pytest.fixture(params=["add-1998-cmo-2", "add-2015-rcb"]) @@ -338,6 +338,66 @@ def test_combination(scalar, one, two, secp128r1): ], ) @pytest.mark.parametrize( + "one,two", + product( + ( + GroupScalarRandomization, + AdditiveSplitting, + MultiplicativeSplitting, + EuclideanSplitting, + BrumleyTuveri, + PointBlinding, + ), + repeat=2, + ), +) +def test_combination_multiples(scalar, one, two, secp128r1): + if one == two: + pytest.skip("Skip identical combinations.") + if one == PointBlinding or two == PointBlinding: + pytest.xfail("PointBlinding will never work with multiple graphs.") + + for i in range(2**two.nmults): + bits = format(i, f"0{two.nmults}b") + + def partial(*args, **kwargs): + mult = LTRMultiplier(*args, **kwargs) + + add = FakeAdditionFormula(secp128r1.curve.coordinate_model) + neg = FakeNegationFormula(secp128r1.curve.coordinate_model) + + if one in (AdditiveSplitting, EuclideanSplitting): + layer_one = one.from_single(mult, add=add) + elif one == PointBlinding: + layer_one = one.from_single(mult, neg=neg) + else: + layer_one = one.from_single(mult) + + if two in (AdditiveSplitting, EuclideanSplitting): + kws = {"add": add} + elif two == PointBlinding: + kws = {"neg": neg} + else: + kws = {} + + args = [layer_one if bit == "1" else mult for bit in bits] + combo = two(*args, **kws) + return combo + + res = multiple_graph(scalar, secp128r1, LTRMultiplier, partial) + assert res is not None + + +@pytest.mark.parametrize( + "scalar", + [ + 3253857902090173296443513219124437746, + 1234567893141592653589793238464338327, + 86728612699079982903603364383639280149, + 60032993417060801067503559426926851620, + ], +) +@pytest.mark.parametrize( "ctr", ( GroupScalarRandomization, |
