diff options
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb | 45 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb.op3 | 43 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb | 35 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb.op3 | 34 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb | 43 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb.op3 | 41 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb | 33 | ||||
| -rw-r--r-- | pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb.op3 | 32 | ||||
| -rw-r--r-- | pyecsca/ec/mod.py | 6 | ||||
| -rw-r--r-- | pyecsca/ec/mult.py | 6 | ||||
| -rw-r--r-- | pyecsca/ec/point.py | 9 | ||||
| -rw-r--r-- | pyecsca/sca/trace_set/hdf5.py | 3 | ||||
| -rw-r--r-- | test/ec/test_configuration.py | 4 | ||||
| -rw-r--r-- | test/ec/test_mult.py | 59 | ||||
| -rw-r--r-- | test/ec/utils.py | 7 |
15 files changed, 370 insertions, 30 deletions
diff --git a/pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb b/pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb new file mode 100644 index 0000000..e4d0c32 --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb @@ -0,0 +1,45 @@ +source 2016 Renes-Costello-Batina "Complete addition formulas for prime order elliptic curves", algorithm (4) +unified +compute t0 = X1 X2 +compute t1 = Y1 Y2 +compute t2 = Z1 Z2 +compute t3 = X1 + Y1 +compute t4 = X2 + Y2 +compute t3 = t3 t4 +compute t4 = t0 + t1 +compute t3 = t3 - t4 +compute t4 = Y1 + Z1 +compute X3 = Y2 + Z2 +compute t4 = t4 * X3 +compute X3 = t1 + t2 +compute t4 = t4 - X3 +compute X3 = X1 + Z1 +compute Y3 = X2 + Z2 +compute X3 = X3 Y3 +compute Y3 = t0 + t2 +compute Y3 = X3 - Y3 +compute Z3 = b t2 +compute X3 = Y3 - Z3 +compute Z3 = X3 + X3 +compute X3 = X3 + Z3 +compute Z3 = t1 - X3 +compute X3 = t1 + X3 +compute Y3 = b Y3 +compute t1 = t2 + t2 +compute t2 = t1 + t2 +compute Y3 = Y3 - t2 +compute Y3 = Y3 - t0 +compute t1 = Y3 + Y3 +compute Y3 = t1 + Y3 +compute t1 = t0 + t0 +compute t0 = t1 + t0 +compute t0 = t0 - t2 +compute t1 = t4 Y3 +compute t2 = t0 Y3 +compute Y3 = X3 Z3 +compute Y3 = Y3 + t2 +compute X3 = t3 X3 +compute X3 = X3 - t1 +compute Z3 = t4 Z3 +compute t1 = t3 t0 +compute Z3 = Z3 + t1
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb.op3 b/pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb.op3 new file mode 100644 index 0000000..0cd47b3 --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective-3/addition/add-2016-rcb.op3 @@ -0,0 +1,43 @@ +t0 = X1*X2 +t1 = Y1*Y2 +t2 = Z1*Z2 +t3 = X1+Y1 +t4 = X2+Y2 +t3 = t3*t4 +t4 = t0+t1 +t3 = t3-t4 +t4 = Y1+Z1 +X3 = Y2+Z2 +t4 = t4*X3 +X3 = t1+t2 +t4 = t4-X3 +X3 = X1+Z1 +Y3 = X2+Z2 +X3 = X3*Y3 +Y3 = t0+t2 +Y3 = X3-Y3 +Z3 = b*t2 +X3 = Y3-Z3 +Z3 = X3+X3 +X3 = X3+Z3 +Z3 = t1-X3 +X3 = t1+X3 +Y3 = b*Y3 +t1 = t2+t2 +t2 = t1+t2 +Y3 = Y3-t2 +Y3 = Y3-t0 +t1 = Y3+Y3 +Y3 = t1+Y3 +t1 = t0+t0 +t0 = t1+t0 +t0 = t0-t2 +t1 = t4*Y3 +t2 = t0*Y3 +Y3 = X3*Z3 +Y3 = Y3+t2 +X3 = t3*X3 +X3 = X3-t1 +Z3 = t4*Z3 +t1 = t3*t0 +Z3 = Z3+t1
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb b/pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb new file mode 100644 index 0000000..d40242e --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb @@ -0,0 +1,35 @@ +source 2016 Renes-Costello-Batina "Complete addition formulas for prime order elliptic curves", algorithm (6) +compute t0 = X1^2 +compute t1 = Y1^2 +compute t2 = Z1^2 +compute t3 = X1 Y1 +compute t3 = t3 + t3 +compute Z3 = X1 Z1 +compute Z3 = Z3 + Z3 +compute Y3 = b t2 +compute Y3 = Y3 - Z3 +compute X3 = Y3 + Y3 +compute Y3 = Y3 + X3 +compute X3 = t1 - Y3 +compute Y3 = t1 + Y3 +compute Y3 = X3 Y3 +compute X3 = X3 t3 +compute t3 = t2 + t2 +compute t2 = t2 + t3 +compute Z3 = b Z3 +compute Z3 = Z3 - t2 +compute Z3 = Z3 - t0 +compute t3 = Z3 + Z3 +compute Z3 = Z3 + t3 +compute t3 = t0 + t0 +compute t0 = t3 + t0 +compute t0 = t0 - t2 +compute t0 = t0 Z3 +compute Y3 = Y3 + t0 +compute t0 = X1 Z1 +compute t0 = t0 + t0 +compute Z3 = t0 Z3 +compute X3 = X3 - Z3 +compute Z3 = t0 t1 +compute Z3 = Z3 + Z3 +compute Z3 = Z3 + Z3
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb.op3 b/pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb.op3 new file mode 100644 index 0000000..3b75d41 --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective-3/doubling/dbl-2016-rcb.op3 @@ -0,0 +1,34 @@ +t0 = X1^2 +t1 = Y1^2 +t2 = Z1^2 +t3 = X1*Y1 +t3 = t3+t3 +Z3 = X1*Z1 +Z3 = Z3+Z3 +Y3 = b*t2 +Y3 = Y3-Z3 +X3 = Y3+Y3 +Y3 = Y3+X3 +X3 = t1-Y3 +Y3 = t1+Y3 +Y3 = X3*Y3 +X3 = X3*t3 +t3 = t2+t2 +t2 = t2+t3 +Z3 = b*Z3 +Z3 = Z3-t2 +Z3 = Z3-t0 +t3 = Z3+Z3 +Z3 = Z3+t3 +t3 = t0+t0 +t0 = t3+t0 +t0 = t0-t2 +t0 = t0*Z3 +Y3 = Y3+t0 +t0 = X1*Z1 +t0 = t0+t0 +Z3 = t0*Z3 +X3 = X3-Z3 +Z3 = t0*t1 +Z3 = Z3+Z3 +Z3 = Z3+Z3
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb b/pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb new file mode 100644 index 0000000..400228b --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb @@ -0,0 +1,43 @@ +source 2016 Renes-Costello-Batina "Complete addition formulas for prime order elliptic curves", algorithm (1) +unified +compute b3 = 3 b +compute t0 = X1 X2 +compute t1 = Y1 Y2 +compute t2 = Z1 Z2 +compute t3 = X1 + Y1 +compute t4 = X2 + Y2 +compute t3 = t3 t4 +compute t4 = t0 + t1 +compute t3 = t3 - t4 +compute t4 = X1 + Z1 +compute t5 = X2 + Z2 +compute t4 = t4 * t5 +compute t5 = t0 + t2 +compute t4 = t4 - t5 +compute t5 = Y1 + Z1 +compute X3 = Y2 + Z2 +compute t5 = t5 X3 +compute X3 = t1 + t2 +compute t5 = t5 - X3 +compute Z3 = a t4 +compute X3 = b3 t2 +compute Z3 = X3 + Z3 +compute X3 = t1 - Z3 +compute Z3 = t1 + Z3 +compute Y3 = X3 Z3 +compute t1 = t0 + t0 +compute t1 = t1 + t0 +compute t2 = a t2 +compute t4 = b3 t4 +compute t1 = t1 + t2 +compute t2 = t0 - t2 +compute t2 = a t2 +compute t4 = t4 + t2 +compute t0 = t1 t4 +compute Y3 = Y3 + t0 +compute t0 = t5 t4 +compute X3 = t3 X3 +compute X3 = X3 - t0 +compute t0 = t3 t1 +compute Z3 = t5 Z3 +compute Z3 = Z3 + t0
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb.op3 b/pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb.op3 new file mode 100644 index 0000000..7e4a236 --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective/addition/add-2016-rcb.op3 @@ -0,0 +1,41 @@ +b3 = 3*b +t0 = X1*X2 +t1 = Y1*Y2 +t2 = Z1*Z2 +t3 = X1+Y1 +t4 = X2+Y2 +t3 = t3*t4 +t4 = t0+t1 +t3 = t3-t4 +t4 = X1+Z1 +t5 = X2+Z2 +t4 = t4*t5 +t5 = t0+t2 +t4 = t4-t5 +t5 = Y1+Z1 +X3 = Y2+Z2 +t5 = t5*X3 +X3 = t1+t2 +t5 = t5-X3 +Z3 = a*t4 +X3 = b3*t2 +Z3 = X3+Z3 +X3 = t1-Z3 +Z3 = t1+Z3 +Y3 = X3*Z3 +t1 = t0+t0 +t1 = t1+t0 +t2 = a*t2 +t4 = b3*t4 +t1 = t1+t2 +t2 = t0-t2 +t2 = a*t2 +t4 = t4+t2 +t0 = t1*t4 +Y3 = Y3+t0 +t0 = t5*t4 +X3 = t3*X3 +X3 = X3-t0 +t0 = t3*t1 +Z3 = t5*Z3 +Z3 = Z3+t0
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb b/pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb new file mode 100644 index 0000000..a031579 --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb @@ -0,0 +1,33 @@ +source 2016 Renes-Costello-Batina "Complete addition formulas for prime order elliptic curves", algorithm (3) +compute b3 = 3 b +compute t0 = X1^2 +compute t1 = Y1^2 +compute t2 = Z1^2 +compute t3 = X1 Y1 +compute t3 = t3 + t3 +compute Z3 = X1 Z1 +compute Z3 = Z3 + Z3 +compute X3 = a Z3 +compute Y3 = b3 t2 +compute Y3 = X3 + Y3 +compute X3 = t1 - Y3 +compute Y3 = t1 + Y3 +compute Y3 = X3 Y3 +compute X3 = t3 X3 +compute Z3 = b3 Z3 +compute t2 = a t2 +compute t3 = t0 - t2 +compute t3 = a t3 +compute t3 = t3 + Z3 +compute Z3 = t0 + t0 +compute t0 = Z3 + t0 +compute t0 = t0 + t2 +compute t0 = t0 t3 +compute Y3 = Y3 + t0 +compute t2 = Y1 Z1 +compute t2 = t2 + t2 +compute t0 = t2 t3 +compute X3 = X3 - t0 +compute Z3 = t2 t1 +compute Z3 = Z3 + Z3 +compute Z3 = Z3 + Z3
\ No newline at end of file diff --git a/pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb.op3 b/pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb.op3 new file mode 100644 index 0000000..8b933ac --- /dev/null +++ b/pyecsca/ec/efd/shortw/projective/doubling/dbl-2016-rcb.op3 @@ -0,0 +1,32 @@ +b3 = 3*b +t0 = X1^2 +t1 = Y1^2 +t2 = Z1^2 +t3 = X1*Y1 +t3 = t3+t3 +Z3 = X1*Z1 +Z3 = Z3+Z3 +X3 = a*Z3 +Y3 = b3*t2 +Y3 = X3+Y3 +X3 = t1-Y3 +Y3 = t1+Y3 +Y3 = X3*Y3 +X3 = t3*X3 +Z3 = b3*Z3 +t2 = a*t2 +t3 = t0-t2 +t3 = a*t3 +t3 = t3+Z3 +Z3 = t0+t0 +t0 = Z3+t0 +t0 = t0+t2 +t0 = t0*t3 +Y3 = Y3+t0 +t2 = Y1*Z1 +t2 = t2+t2 +t0 = t2*t3 +X3 = X3-t0 +Z3 = t2*t1 +Z3 = Z3+Z3 +Z3 = Z3+Z3
\ No newline at end of file diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py index 1fa3f9d..ec5dfe6 100644 --- a/pyecsca/ec/mod.py +++ b/pyecsca/ec/mod.py @@ -136,6 +136,9 @@ class Mod(object): q, r = divmod(self.x, divisor.x) return Mod(q, self.n), Mod(r, self.n) + def __bytes__(self): + return self.x.to_bytes((self.n.bit_length() + 7) // 8, byteorder="big") + @staticmethod def random(n: int): with RandomModAction(n): @@ -224,6 +227,9 @@ class Undefined(Mod): def __divmod__(self, divisor): raise NotImplementedError + def __bytes__(self): + raise NotImplementedError + def __int__(self): raise NotImplementedError diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py index def7dab..57c034a 100644 --- a/pyecsca/ec/mult.py +++ b/pyecsca/ec/mult.py @@ -407,10 +407,10 @@ class WindowNAFMultiplier(ScalarMultiplier): self._points_neg = {} current_point = point double_point = self._dbl(point) - for i in range(1, (self.width + 1) // 2 + 1): - self._points[2 ** i - 1] = current_point + for i in range(0, 2**(self.width - 2)): + self._points[2*i + 1] = current_point if self.precompute_negation: - self._points_neg[2 ** i - 1] = self._neg(current_point) + self._points_neg[2*i + 1] = self._neg(current_point) current_point = self._add(current_point, double_point) def multiply(self, scalar: int) -> Point: diff --git a/pyecsca/ec/point.py b/pyecsca/ec/point.py index f20d5e0..fe515ae 100644 --- a/pyecsca/ec/point.py +++ b/pyecsca/ec/point.py @@ -97,6 +97,12 @@ class Point(object): return False return self.to_affine() == other.to_affine() + def __bytes__(self): + res = b"\x04" + for k in sorted(self.coords.keys()): + res += bytes(self.coords[k]) + return res + def __eq__(self, other): if not isinstance(other, Point): return False @@ -133,6 +139,9 @@ class InfinityPoint(Point): def equals(self, other) -> bool: return self == other + def __bytes__(self): + return b"\x00" + def __eq__(self, other): if type(other) is not InfinityPoint: return False diff --git a/pyecsca/sca/trace_set/hdf5.py b/pyecsca/sca/trace_set/hdf5.py index 01f8303..b8a1ad1 100644 --- a/pyecsca/sca/trace_set/hdf5.py +++ b/pyecsca/sca/trace_set/hdf5.py @@ -62,8 +62,7 @@ class HDF5TraceSet(TraceSet): def append(self, value: Trace): if self._file is not None: - last = sorted(list(map(int, self._file.keys())))[-1] - key = last + 1 + key = sorted(list(map(int, self._file.keys())))[-1] + 1 if self._file.keys() else 0 self._file[str(key)] = value.samples value.samples = self._file[str(key)] if value.meta: diff --git a/test/ec/test_configuration.py b/test/ec/test_configuration.py index e184ca3..54e4827 100644 --- a/test/ec/test_configuration.py +++ b/test/ec/test_configuration.py @@ -29,7 +29,7 @@ class ConfigurationTests(TestCase): model = ShortWeierstrassModel() coords = model.coordinates["projective"] configs = list(all_configurations(model=model, coords=coords, **self.base_independents())) - self.assertEqual(len(configs), 1344) + self.assertEqual(len(configs), 1960) def test_mult_class(self): model = ShortWeierstrassModel() @@ -37,7 +37,7 @@ class ConfigurationTests(TestCase): scalarmult = LTRMultiplier configs = list(all_configurations(model=model, coords=coords, scalarmult=scalarmult, **self.base_independents())) - self.assertEqual(len(configs), 384) + self.assertEqual(len(configs), 560) def test_one(self): model = ShortWeierstrassModel() diff --git a/test/ec/test_mult.py b/test/ec/test_mult.py index 5b3683f..5d7e66b 100644 --- a/test/ec/test_mult.py +++ b/test/ec/test_mult.py @@ -8,6 +8,7 @@ from pyecsca.ec.mult import (LTRMultiplier, RTLMultiplier, LadderMultiplier, Bin DifferentialLadderMultiplier, CoronMultiplier) from pyecsca.ec.point import InfinityPoint +from .utils import cartesian class ScalarMultiplierTests(TestCase): @@ -45,6 +46,7 @@ class ScalarMultiplierTests(TestCase): @parameterized.expand([ ("scaled", "add-1998-cmo", "dbl-1998-cmo", "z"), + ("complete", "add-2016-rcb", "dbl-2016-rcb", None), ("none", "add-1998-cmo", "dbl-1998-cmo", None) ]) def test_rtl(self, name, add, dbl, scale): @@ -52,6 +54,7 @@ class ScalarMultiplierTests(TestCase): @parameterized.expand([ ("scaled", "add-1998-cmo", "dbl-1998-cmo", "z"), + ("complete", "add-2016-rcb", "dbl-2016-rcb", None), ("none", "add-1998-cmo", "dbl-1998-cmo", None) ]) def test_ltr(self, name, add, dbl, scale): @@ -69,6 +72,7 @@ class ScalarMultiplierTests(TestCase): @parameterized.expand([ ("scaled", "add-1998-cmo", "dbl-1998-cmo", "z"), + ("complete", "add-2016-rcb", "dbl-2016-rcb", None), ("none", "add-1998-cmo", "dbl-1998-cmo", None) ]) def test_coron(self, name, add, dbl, scale): @@ -83,6 +87,7 @@ class ScalarMultiplierTests(TestCase): @parameterized.expand([ ("scaled", "add-1998-cmo", "dbl-1998-cmo", "z"), + ("complete", "add-2016-rcb", "dbl-2016-rcb", None), ("none", "add-1998-cmo", "dbl-1998-cmo", None) ]) def test_simple_ladder(self, name, add, dbl, scale): @@ -113,6 +118,7 @@ class ScalarMultiplierTests(TestCase): @parameterized.expand([ ("scaled", "add-1998-cmo", "dbl-1998-cmo", "neg", "z"), + ("complete", "add-2016-rcb", "dbl-2016-rcb", "neg", None), ("none", "add-1998-cmo", "dbl-1998-cmo", "neg", None) ]) def test_binary_naf(self, name, add, dbl, neg, scale): @@ -120,16 +126,20 @@ class ScalarMultiplierTests(TestCase): @parameterized.expand([ ("scaled3", "add-1998-cmo", "dbl-1998-cmo", "neg", 3, "z"), - ("none3", "add-1998-cmo", "dbl-1998-cmo", "neg", 3, None) + ("none3", "add-1998-cmo", "dbl-1998-cmo", "neg", 3, None), + ("complete3", "add-2016-rcb", "dbl-2016-rcb", "neg", 3, None), + ("scaled5", "add-1998-cmo", "dbl-1998-cmo", "neg", 5, "z"), + ("none5", "add-1998-cmo", "dbl-1998-cmo", "neg", 5, None), + ("complete5", "add-2016-rcb", "dbl-2016-rcb", "neg", 5, None), ]) def test_window_naf(self, name, add, dbl, neg, width, scale): 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(10) - other = mult.multiply(5) + res = mult.multiply(157*789) + other = mult.multiply(157) mult.init(self.secp128r1, other) - other = mult.multiply(2) + other = mult.multiply(789) self.assertPointEquality(res, other, scale) mult.init(self.secp128r1, self.base) self.assertEqual(InfinityPoint(self.coords), mult.multiply(0)) @@ -137,22 +147,25 @@ class ScalarMultiplierTests(TestCase): mult = WindowNAFMultiplier(*formulas[:3], width, *formulas[3:], precompute_negation=True) mult.init(self.secp128r1, self.base) - res_precompute = mult.multiply(10) + res_precompute = mult.multiply(157*789) self.assertPointEquality(res_precompute, res, scale) - @parameterized.expand([ + @parameterized.expand(cartesian([ ("10", 10), ("2355498743", 2355498743), ("325385790209017329644351321912443757746", 325385790209017329644351321912443757746) - ]) - def test_basic_multipliers(self, name, num): - ltr = LTRMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], self.coords.formulas["z"]) + ],[ + ("add-1998-cmo", "dbl-1998-cmo"), + ("add-2016-rcb", "dbl-2016-rcb") + ])) + def test_basic_multipliers(self, name, num, add, dbl): + ltr = LTRMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["z"]) with self.assertRaises(ValueError): ltr.multiply(1) ltr.init(self.secp128r1, self.base) res_ltr = ltr.multiply(num) - rtl = RTLMultiplier(self.coords.formulas["add-1998-cmo"], + rtl = RTLMultiplier(self.coords.formulas[add], self.coords.formulas["dbl-1998-cmo"], self.coords.formulas["z"]) with self.assertRaises(ValueError): rtl.multiply(1) @@ -160,11 +173,11 @@ class ScalarMultiplierTests(TestCase): res_rtl = rtl.multiply(num) self.assertEqual(res_ltr, res_rtl) - ltr_always = LTRMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], self.coords.formulas["z"], + ltr_always = LTRMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["z"], always=True) - rtl_always = RTLMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], self.coords.formulas["z"], + rtl_always = RTLMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["z"], always=True) ltr_always.init(self.secp128r1, self.base) rtl_always.init(self.secp128r1, self.base) @@ -173,8 +186,8 @@ class ScalarMultiplierTests(TestCase): self.assertEqual(res_ltr, res_ltr_always) self.assertEqual(res_rtl, res_rtl_always) - bnaf = BinaryNAFMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], + bnaf = BinaryNAFMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["neg"], self.coords.formulas["z"]) with self.assertRaises(ValueError): bnaf.multiply(1) @@ -182,8 +195,8 @@ class ScalarMultiplierTests(TestCase): res_bnaf = bnaf.multiply(num) self.assertEqual(res_bnaf, res_ltr) - wnaf = WindowNAFMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], + wnaf = WindowNAFMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["neg"], 3, self.coords.formulas["z"]) with self.assertRaises(ValueError): wnaf.multiply(1) @@ -191,8 +204,8 @@ class ScalarMultiplierTests(TestCase): res_wnaf = wnaf.multiply(num) self.assertEqual(res_wnaf, res_ltr) - ladder = SimpleLadderMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], + ladder = SimpleLadderMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["z"]) with self.assertRaises(ValueError): ladder.multiply(1) @@ -200,8 +213,8 @@ class ScalarMultiplierTests(TestCase): res_ladder = ladder.multiply(num) self.assertEqual(res_ladder, res_ltr) - coron = CoronMultiplier(self.coords.formulas["add-1998-cmo"], - self.coords.formulas["dbl-1998-cmo"], + coron = CoronMultiplier(self.coords.formulas[add], + self.coords.formulas[dbl], self.coords.formulas["z"]) with self.assertRaises(ValueError): coron.multiply(1) diff --git a/test/ec/utils.py b/test/ec/utils.py index bedfed2..e1812b3 100644 --- a/test/ec/utils.py +++ b/test/ec/utils.py @@ -1,3 +1,10 @@ +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 |
