diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ec/test_context.py | 7 | ||||
| -rw-r--r-- | test/ec/test_mod.py | 2 | ||||
| -rw-r--r-- | test/ec/test_op.py | 3 | ||||
| -rw-r--r-- | test/ec/test_regress.py | 8 | ||||
| -rw-r--r-- | test/ec/utils.py | 11 | ||||
| -rw-r--r-- | test/sca/test_align.py | 9 | ||||
| -rw-r--r-- | test/sca/test_filter.py | 2 | ||||
| -rw-r--r-- | test/sca/test_match.py | 2 | ||||
| -rw-r--r-- | test/sca/test_sampling.py | 2 | ||||
| -rw-r--r-- | test/sca/test_target.py | 3 | ||||
| -rw-r--r-- | test/sca/test_traceset.py | 1 |
11 files changed, 27 insertions, 23 deletions
diff --git a/test/ec/test_context.py b/test/ec/test_context.py index 04dbc7d..6691985 100644 --- a/test/ec/test_context.py +++ b/test/ec/test_context.py @@ -10,7 +10,7 @@ from pyecsca.ec.context import ( Tree, PathContext, ) -from pyecsca.ec.key_generation import KeygenAction, KeyGeneration +from pyecsca.ec.key_generation import KeyGeneration from pyecsca.ec.params import get_params from pyecsca.ec.mod import RandomModAction from pyecsca.ec.mult import LTRMultiplier, ScalarMultiplicationAction @@ -83,9 +83,8 @@ class ContextTests(TestCase): self.assertEqual(result, action.result) def test_default_no_enter(self): - with local(DefaultContext()) as default: - with self.assertRaises(ValueError): - default.exit_action(RandomModAction(7)) + with local(DefaultContext()) as default, self.assertRaises(ValueError): + default.exit_action(RandomModAction(7)) def test_path(self): with local(PathContext([0, 1])) as ctx: diff --git a/test/ec/test_mod.py b/test/ec/test_mod.py index 2c45447..864cc2e 100644 --- a/test/ec/test_mod.py +++ b/test/ec/test_mod.py @@ -190,7 +190,7 @@ class ModTests(TestCase): self.assertIsInstance(Mod(5, 7), RawMod) def test_symbolic(self): - x, y = symbols("x y") + x = symbols("x") p = 13 k = FF(p) sx = SymbolicMod(x, p) diff --git a/test/ec/test_op.py b/test/ec/test_op.py index c09914f..77669fb 100644 --- a/test/ec/test_op.py +++ b/test/ec/test_op.py @@ -44,6 +44,7 @@ class OpTests(TestCase): class OpResultTests(TestCase): def test_str(self): - for op, char in zip((ast.Add(), ast.Sub(), ast.Mult(), ast.Div()), "+-*/"): + for op in (OpType.Add, OpType.Sub, OpType.Mult, OpType.Div): res = OpResult("X1", Mod(0, 5), op, Mod(2, 5), Mod(3, 5)) self.assertEqual(str(res), "X1") + self.assertEqual(repr(res), f"X1 = 2{op.op_str}3") diff --git a/test/ec/test_regress.py b/test/ec/test_regress.py index e02cc8e..ad3e096 100644 --- a/test/ec/test_regress.py +++ b/test/ec/test_regress.py @@ -1,7 +1,9 @@ +from typing import cast from unittest import TestCase from pyecsca.ec.coordinates import AffineCoordinateModel from pyecsca.ec.curve import EllipticCurve +from pyecsca.ec.formula import AdditionFormula, DoublingFormula, ScalingFormula from pyecsca.ec.mod import Mod from pyecsca.ec.model import MontgomeryModel, EdwardsModel from pyecsca.ec.params import get_params @@ -14,9 +16,9 @@ class RegressionTests(TestCase): secp128r1 = get_params("secg", "secp128r1", "projective") base = secp128r1.generator coords = secp128r1.curve.coordinate_model - add = coords.formulas["add-1998-cmo"] - dbl = coords.formulas["dbl-1998-cmo"] - scl = coords.formulas["z"] + add = cast(AdditionFormula, coords.formulas["add-1998-cmo"]) + dbl = cast(DoublingFormula, coords.formulas["dbl-1998-cmo"]) + scl = cast(ScalingFormula, coords.formulas["z"]) mult = LTRMultiplier( add, dbl, scl, always=False, complete=False, short_circuit=True ) diff --git a/test/ec/utils.py b/test/ec/utils.py index 84c568d..c702d5b 100644 --- a/test/ec/utils.py +++ b/test/ec/utils.py @@ -47,12 +47,19 @@ class Profiler(object): if self._output_directory is None or self._benchmark_name is None: return git_commit = ( - run(["git", "rev-parse", "--short", "HEAD"], stdout=PIPE, stderr=DEVNULL) + run( + ["git", "rev-parse", "--short", "HEAD"], + stdout=PIPE, + stderr=DEVNULL, + check=False, + ) .stdout.strip() .decode() ) git_dirty = ( - run(["git", "diff", "--quiet"], stdout=DEVNULL, stderr=DEVNULL).returncode + run( + ["git", "diff", "--quiet"], stdout=DEVNULL, stderr=DEVNULL, check=False + ).returncode != 0 ) version = git_commit + ("-dirty" if git_dirty else "") diff --git a/test/sca/test_align.py b/test/sca/test_align.py index 607b297..1db71b3 100644 --- a/test/sca/test_align.py +++ b/test/sca/test_align.py @@ -37,11 +37,14 @@ class AlignTests(Plottable): result[1].samples, np.array([10, 50, 80, 50, 20, 0, 0, 0], dtype=np.dtype("i1")), ) + self.assertEqual(len(offsets), 2) + self.assertEqual(offsets[0], 0) + self.assertEqual(offsets[1], 3) @slow def test_large_align(self): example = InspectorTraceSet.read("test/data/example.trs") - result, offsets = align_correlation( + result, _ = align_correlation( *example, reference_offset=100000, reference_length=20000, max_offset=15000 ) self.assertIsNotNone(result) @@ -61,7 +64,7 @@ class AlignTests(Plottable): ) a = Trace(first_arr) b = Trace(second_arr) - result, offsets = align_peaks( + result, _ = align_peaks( a, b, reference_offset=2, reference_length=5, max_offset=3 ) self.assertEqual(np.argmax(result[0].samples), np.argmax(result[1].samples)) @@ -75,7 +78,7 @@ class AlignTests(Plottable): ) a = Trace(first_arr) b = Trace(second_arr) - result, offsets = align_sad( + result, _ = align_sad( a, b, reference_offset=2, reference_length=5, max_offset=3 ) self.assertEqual(len(result), 2) diff --git a/test/sca/test_filter.py b/test/sca/test_filter.py index 9d63ea3..91f037c 100644 --- a/test/sca/test_filter.py +++ b/test/sca/test_filter.py @@ -1,5 +1,3 @@ -from unittest import TestCase - import numpy as np from pyecsca.sca import ( Trace, diff --git a/test/sca/test_match.py b/test/sca/test_match.py index 9ba81a3..d39e8c3 100644 --- a/test/sca/test_match.py +++ b/test/sca/test_match.py @@ -1,5 +1,3 @@ -from unittest import TestCase - import numpy as np from pyecsca.sca import Trace, match_pattern, match_part, pad diff --git a/test/sca/test_sampling.py b/test/sca/test_sampling.py index 4a54b4d..fcebf2d 100644 --- a/test/sca/test_sampling.py +++ b/test/sca/test_sampling.py @@ -1,5 +1,3 @@ -from unittest import TestCase - import numpy as np from pyecsca.sca import ( Trace, diff --git a/test/sca/test_target.py b/test/sca/test_target.py index 4168152..299e127 100644 --- a/test/sca/test_target.py +++ b/test/sca/test_target.py @@ -10,7 +10,6 @@ from pyecsca.ec.key_generation import KeyGeneration from pyecsca.ec.mod import Mod from pyecsca.ec.mult import LTRMultiplier from pyecsca.ec.params import DomainParameters, get_params -from pyecsca.ec.point import Point from pyecsca.ec.signature import SignatureResult, ECDSA_SHA1 from pyecsca.sca.target import ( BinaryTarget, @@ -340,7 +339,7 @@ class ECTesterTargetTests(TestCase): self.secp256r1_projective.curve.coordinate_model.formulas["dbl-2016-rcb"], ) keygen = KeyGeneration(copy(mult), self.secp256r1_projective) - priv, pubkey_projective = keygen.generate() + _, pubkey_projective = keygen.generate() ecdh_resp = self.target.ecdh_direct( KeypairEnum.KEYPAIR_LOCAL, diff --git a/test/sca/test_traceset.py b/test/sca/test_traceset.py index 515790e..e79e5d2 100644 --- a/test/sca/test_traceset.py +++ b/test/sca/test_traceset.py @@ -1,7 +1,6 @@ import os.path import shutil import tempfile -from copy import deepcopy from unittest import TestCase import numpy as np |
