diff options
| author | J08nY | 2024-07-15 18:15:45 +0200 |
|---|---|---|
| committer | J08nY | 2024-07-15 18:15:45 +0200 |
| commit | 06e005a48af4a704b38f933f500f03a0af2630d3 (patch) | |
| tree | 1712620fc37c5d5798913af491a7e2b851251fd5 /test/sca | |
| parent | ba894fe889d003f2766b7bb90503960fd0429cd5 (diff) | |
| download | pyecsca-06e005a48af4a704b38f933f500f03a0af2630d3.tar.gz pyecsca-06e005a48af4a704b38f933f500f03a0af2630d3.tar.zst pyecsca-06e005a48af4a704b38f933f500f03a0af2630d3.zip | |
Move to function based Mod dispatch.
Diffstat (limited to 'test/sca')
| -rw-r--r-- | test/sca/test_leakage_models.py | 16 | ||||
| -rw-r--r-- | test/sca/test_rpa.py | 26 | ||||
| -rw-r--r-- | test/sca/test_zvp.py | 6 |
3 files changed, 24 insertions, 24 deletions
diff --git a/test/sca/test_leakage_models.py b/test/sca/test_leakage_models.py index 592a100..08a3b07 100644 --- a/test/sca/test_leakage_models.py +++ b/test/sca/test_leakage_models.py @@ -1,6 +1,6 @@ from pyecsca.ec.context import local, DefaultContext from pyecsca.ec.formula import FormulaAction, OpResult -from pyecsca.ec.mod import Mod +from pyecsca.ec.mod import Mod, mod from pyecsca.ec.mult import LTRMultiplier from pyecsca.ec.op import OpType from pyecsca.sca.attack.leakage_model import Identity, Bit, Slice, HammingWeight, HammingDistance, BitLength @@ -8,13 +8,13 @@ import pytest def test_identity(): - val = Mod(3, 7) + val = mod(3, 7) lm = Identity() assert lm(val) == 3 def test_bit(): - val = Mod(3, 7) + val = mod(3, 7) lm = Bit(0) assert lm(val) == 1 lm = Bit(4) @@ -24,7 +24,7 @@ def test_bit(): def test_slice(): - val = Mod(0b11110000, 0xf00) + val = mod(0b11110000, 0xf00) lm = Slice(0, 4) assert lm(val) == 0 lm = Slice(1, 5) @@ -36,20 +36,20 @@ def test_slice(): def test_hamming_weight(): - val = Mod(0b11110000, 0xf00) + val = mod(0b11110000, 0xf00) lm = HammingWeight() assert lm(val) == 4 def test_hamming_distance(): - a = Mod(0b11110000, 0xf00) - b = Mod(0b00010000, 0xf00) + a = mod(0b11110000, 0xf00) + b = mod(0b00010000, 0xf00) lm = HammingDistance() assert lm(a, b) == 3 def test_bit_length(): - a = Mod(0b11110000, 0xf00) + a = mod(0b11110000, 0xf00) lm = BitLength() assert lm(a) == 8 diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py index fe38c41..2fa533d 100644 --- a/test/sca/test_rpa.py +++ b/test/sca/test_rpa.py @@ -3,7 +3,7 @@ import pytest from pyecsca.ec.context import local from pyecsca.ec.model import ShortWeierstrassModel from pyecsca.ec.curve import EllipticCurve -from pyecsca.ec.mod import Mod +from pyecsca.ec.mod import Mod, mod from pyecsca.ec.mult import ( LTRMultiplier, RTLMultiplier, @@ -57,15 +57,15 @@ def neg(coords): @pytest.fixture() def rpa_params(model, coords): p = 0x85D265945A4F5681 - a = Mod(0x7FC57B4110698BC0, p) - b = Mod(0x37113EA591B04527, p) - gx = Mod(0x80D2D78FDDB97597, p) - gy = Mod(0x5586D818B7910930, p) + a = mod(0x7FC57B4110698BC0, p) + b = mod(0x37113EA591B04527, p) + gx = mod(0x80D2D78FDDB97597, p) + gy = mod(0x5586D818B7910930, p) # (0x4880bcf620852a54, 0) RPA point # (0, 0x6bed3155c9ada064) RPA point - infty = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p)) - g = Point(coords, X=gx, Y=gy, Z=Mod(1, p)) + infty = Point(coords, X=mod(0, p), Y=mod(1, p), Z=mod(0, p)) + g = Point(coords, X=gx, Y=gy, Z=mod(1, p)) curve = EllipticCurve(model, coords, p, infty, dict(a=a, b=b)) return DomainParameters(curve, g, 0x85D265932D90785C, 1) @@ -85,15 +85,15 @@ def test_0y_point(rpa_params): @pytest.fixture() def distinguish_params(model, coords): p = 0xcb5e1d94a6168511 - a = Mod(0xb166ca7d2dfbf69f, p) - b = Mod(0x855bb40cb6937c4b, p) - gx = Mod(0x253b2638bd13d6f4, p) - gy = Mod(0x1e91a1a182287e71, p) + a = mod(0xb166ca7d2dfbf69f, p) + b = mod(0x855bb40cb6937c4b, p) + gx = mod(0x253b2638bd13d6f4, p) + gy = mod(0x1e91a1a182287e71, p) # (0x4880bcf620852a54, 0) RPA point # (0, 0x6bed3155c9ada064) RPA point - infty = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p)) - g = Point(coords, X=gx, Y=gy, Z=Mod(1, p)) + infty = Point(coords, X=mod(0, p), Y=mod(1, p), Z=mod(0, p)) + g = Point(coords, X=gx, Y=gy, Z=mod(1, p)) curve = EllipticCurve(model, coords, p, infty, dict(a=a, b=b)) return DomainParameters(curve, g, 0xcb5e1d94601a3ac5, 1) diff --git a/test/sca/test_zvp.py b/test/sca/test_zvp.py index 99b7105..f266e55 100644 --- a/test/sca/test_zvp.py +++ b/test/sca/test_zvp.py @@ -1,7 +1,7 @@ import pytest from pyecsca.ec.coordinates import AffineCoordinateModel -from pyecsca.ec.mod import Mod +from pyecsca.ec.mod import Mod, mod from pyecsca.ec.mult import LTRMultiplier, AccumulationOrder from pyecsca.ec.point import Point from pyecsca.sca.re.zvp import ( @@ -233,8 +233,8 @@ def test_zvp(secp128r1, formula): def test_points(secp128r1, poly_str, point, k): pt = Point( AffineCoordinateModel(secp128r1.curve.model), - x=Mod(point[0], secp128r1.curve.prime), - y=Mod(point[1], secp128r1.curve.prime), + x=mod(point[0], secp128r1.curve.prime), + y=mod(point[1], secp128r1.curve.prime), ) poly_expr = sympify(poly_str) poly = Poly(poly_expr, domain=FF(secp128r1.curve.prime)) |
