diff options
| -rwxr-xr-x | test/data/target.py | 2 | ||||
| -rw-r--r-- | test/ec/test_curve.py | 1 | ||||
| -rw-r--r-- | test/ec/test_mod.py | 2 | ||||
| -rw-r--r-- | test/ec/test_mult.py | 6 | ||||
| -rw-r--r-- | test/ec/test_op.py | 3 | ||||
| -rw-r--r-- | test/ec/test_point.py | 2 | ||||
| -rw-r--r-- | test/ec/utils.py | 4 | ||||
| -rw-r--r-- | test/sca/test_align.py | 12 | ||||
| -rw-r--r-- | test/sca/test_combine.py | 1 | ||||
| -rw-r--r-- | test/sca/test_process.py | 2 | ||||
| -rw-r--r-- | test/sca/test_rpa.py | 4 | ||||
| -rw-r--r-- | test/sca/test_target.py | 2 | ||||
| -rw-r--r-- | test/sca/utils.py | 3 |
13 files changed, 25 insertions, 19 deletions
diff --git a/test/data/target.py b/test/data/target.py index 9e6e0e0..72fc463 100755 --- a/test/data/target.py +++ b/test/data/target.py @@ -15,4 +15,4 @@ if __name__ == "__main__": stdout.write(c) stdout.write("\n") elif char == "x": - break
\ No newline at end of file + break diff --git a/test/ec/test_curve.py b/test/ec/test_curve.py index cbc1d14..c358c68 100644 --- a/test/ec/test_curve.py +++ b/test/ec/test_curve.py @@ -134,4 +134,3 @@ class CurveTests(TestCase): affine_curve.decode_point(unhexlify("7a161ff7528b899b2d0c28607ca52c5b86")) with self.assertRaises(ValueError): affine_curve.decode_point(unhexlify("03161ff7528b899b2d0c28607ca52c5b88")) - diff --git a/test/ec/test_mod.py b/test/ec/test_mod.py index d21238b..4c0c483 100644 --- a/test/ec/test_mod.py +++ b/test/ec/test_mod.py @@ -74,7 +74,7 @@ class ModTests(TestCase): a = Mod(5, 7) self.assertEqual(a**(-1), a.inverse()) self.assertEqual(a**0, Mod(1, 7)) - self.assertEqual(a**(-2),a.inverse()**2) + self.assertEqual(a**(-2), a.inverse()**2) def test_wrong_mod(self): a = Mod(5, 7) diff --git a/test/ec/test_mult.py b/test/ec/test_mult.py index a1c6725..19db2b2 100644 --- a/test/ec/test_mult.py +++ b/test/ec/test_mult.py @@ -136,7 +136,7 @@ class ScalarMultiplierTests(TestCase): formulas = self.get_formulas(self.coords, add, dbl, neg, scale) mult = WindowNAFMultiplier(*formulas[:3], width, *formulas[3:]) mult.init(self.secp128r1, self.base) - res = mult.multiply(157*789) + res = mult.multiply(157 * 789) other = mult.multiply(157) mult.init(self.secp128r1, other) other = mult.multiply(789) @@ -147,14 +147,14 @@ class ScalarMultiplierTests(TestCase): mult = WindowNAFMultiplier(*formulas[:3], width, *formulas[3:], precompute_negation=True) mult.init(self.secp128r1, self.base) - res_precompute = mult.multiply(157*789) + res_precompute = mult.multiply(157 * 789) self.assertPointEquality(res_precompute, res, scale) @parameterized.expand(cartesian([ ("10", 10), ("2355498743", 2355498743), ("325385790209017329644351321912443757746", 325385790209017329644351321912443757746) - ],[ + ], [ ("add-1998-cmo", "dbl-1998-cmo"), ("add-2016-rcb", "dbl-2016-rcb") ])) diff --git a/test/ec/test_op.py b/test/ec/test_op.py index 9471148..019e0e8 100644 --- a/test/ec/test_op.py +++ b/test/ec/test_op.py @@ -38,9 +38,10 @@ class OpTests(TestCase): res = op(**locals) self.assertEqual(res, result) + class OpResultTests(TestCase): def test_str(self): for op, char in zip((ast.Add(), ast.Sub(), ast.Mult(), ast.Div()), "+-*/"): res = OpResult("X1", Mod(0, 5), op, Mod(2, 5), Mod(3, 5)) - self.assertEqual(str(res), "X1")
\ No newline at end of file + self.assertEqual(str(res), "X1") diff --git a/test/ec/test_point.py b/test/ec/test_point.py index 0fabbf1..9bff800 100644 --- a/test/ec/test_point.py +++ b/test/ec/test_point.py @@ -48,7 +48,7 @@ class PointTests(TestCase): infty = InfinityPoint(AffineCoordinateModel(self.secp128r1.curve.model)) other_infty = infty.to_model(self.coords, self.secp128r1.curve) self.assertIsInstance(other_infty, InfinityPoint) - + with self.assertRaises(ValueError): self.base.to_model(self.coords, self.secp128r1.curve) diff --git a/test/ec/utils.py b/test/ec/utils.py index e1812b3..67a9cc0 100644 --- a/test/ec/utils.py +++ b/test/ec/utils.py @@ -1,10 +1,12 @@ from itertools import product from functools import reduce + def slow(func): func.slow = 1 return func + def cartesian(*items): for cart in product(*items): - yield reduce(lambda x, y: x + y, cart)
\ No newline at end of file + yield reduce(lambda x, y: x + y, cart) diff --git a/test/sca/test_align.py b/test/sca/test_align.py index 3325041..2630b24 100644 --- a/test/sca/test_align.py +++ b/test/sca/test_align.py @@ -22,7 +22,7 @@ class AlignTests(Plottable): @slow def test_large_align(self): example = InspectorTraceSet.read("test/data/example.trs") - result, offsets = align_correlation(*example, reference_offset=100000, reference_length=20000, max_offset=15000) + result, offsets = align_correlation(*example, reference_offset=100000, reference_length=20000, max_offset=15000) self.assertIsNotNone(result) @slow @@ -36,7 +36,7 @@ class AlignTests(Plottable): second_arr = np.array([10, 10, 10, 10, 90, 40, 50, 20, 10, 17, 16, 10], dtype=np.dtype("i1")) a = Trace(first_arr) b = Trace(second_arr) - result, offsets = align_peaks(a, b, reference_offset=2, reference_length=5, max_offset=3) + result, offsets = 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)) def test_sad_align(self): @@ -44,13 +44,13 @@ class AlignTests(Plottable): second_arr = np.array([10, 10, 90, 40, 50, 20, 10, 17, 16, 10, 10], dtype=np.dtype("i1")) a = Trace(first_arr) b = Trace(second_arr) - result, offsets = align_sad(a, b, reference_offset=2, reference_length=5, max_offset=3) + result, offsets = align_sad(a, b, reference_offset=2, reference_length=5, max_offset=3) self.assertEqual(len(result), 2) def test_dtw_align_scale(self): - first_arr = np.array( [10, 64, 14, 120, 15, 30, 10, 15, 20, 15, 15, 10, 10, 8, 10, 12, 10, 13, 9], dtype=np.dtype("f2")) - second_arr = np.array([10, 10, 60, 40, 90, 20, 10, 17, 16, 10, 10, 10, 10, 10, 17, 12, 10], dtype=np.dtype("f2")) - third_arr = np.array( [10, 30, 20, 21, 15, 8, 10, 37, 21, 77, 20, 28, 25, 10, 9, 10, 15, 9, 10], dtype=np.dtype("f2")) + first_arr = np.array([10, 64, 14, 120, 15, 30, 10, 15, 20, 15, 15, 10, 10, 8, 10, 12, 10, 13, 9], dtype=np.dtype("f2")) + second_arr = np.array([10, 10, 60, 40, 90, 20, 10, 17, 16, 10, 10, 10, 10, 10, 17, 12, 10], dtype=np.dtype("f2")) + third_arr = np.array([10, 30, 20, 21, 15, 8, 10, 37, 21, 77, 20, 28, 25, 10, 9, 10, 15, 9, 10], dtype=np.dtype("f2")) a = Trace(first_arr) b = Trace(second_arr) c = Trace(third_arr) diff --git a/test/sca/test_combine.py b/test/sca/test_combine.py index f746674..51f7f02 100644 --- a/test/sca/test_combine.py +++ b/test/sca/test_combine.py @@ -63,4 +63,3 @@ class CombineTests(TestCase): self.assertIsInstance(result, CombinedTrace) self.assertEqual(result.samples[0], -10) self.assertEqual(result.samples[1], 38) - diff --git a/test/sca/test_process.py b/test/sca/test_process.py index d1bbddb..4525d01 100644 --- a/test/sca/test_process.py +++ b/test/sca/test_process.py @@ -47,4 +47,4 @@ class ProcessTests(TestCase): def test_normalize_wl(self): result = normalize_wl(self._trace) - self.assertIsNotNone(result)
\ No newline at end of file + self.assertIsNotNone(result) diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py index 71c846c..0c96e86 100644 --- a/test/sca/test_rpa.py +++ b/test/sca/test_rpa.py @@ -59,7 +59,11 @@ class MultipleContextTests(TestCase): with local(MultipleContext()) as ctx: ladd_mult.init(curve25519, base) ladd_mult.multiply(1339278426732672313) + muls = list(ctx.points.values()) + self.assertEqual(muls[-2], 1339278426732672313) dadd_mult = DifferentialLadderMultiplier(dadd, dbl, scale) with local(MultipleContext()) as ctx: dadd_mult.init(curve25519, base) dadd_mult.multiply(1339278426732672313) + muls = list(ctx.points.values()) + self.assertEqual(muls[-2], 1339278426732672313) diff --git a/test/sca/test_target.py b/test/sca/test_target.py index d31da69..a0f4fec 100644 --- a/test/sca/test_target.py +++ b/test/sca/test_target.py @@ -50,7 +50,7 @@ class BinaryTargetTests(TestCase): target_path = join(dirname(realpath(__file__)), "..", "data", "target.py") target = TestTarget(target_path) with self.assertRaises(ValueError): - target.write(bytes([1,2,3,4])) + target.write(bytes([1, 2, 3, 4])) with self.assertRaises(ValueError): target.read(5) target.disconnect() diff --git a/test/sca/utils.py b/test/sca/utils.py index 7b3ae97..0a996cd 100644 --- a/test/sca/utils.py +++ b/test/sca/utils.py @@ -1,5 +1,6 @@ from os import mkdir, getenv, getcwd from os.path import join, exists, split +from typing import Dict from unittest import TestCase import matplotlib.pyplot as plt @@ -19,7 +20,7 @@ def disabled(func): return func -cases = {} +cases: Dict[str, int] = {} class Plottable(TestCase): |
