aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/ec
diff options
context:
space:
mode:
authorJ08nY2020-02-12 21:00:20 +0100
committerJ08nY2020-02-12 21:00:20 +0100
commit85afbe7548d59d5ca5a8d17b32926f99235f5211 (patch)
tree5645730f38ff87bcbdfe76539dee2e7961df4901 /test/ec
parent11bd56b296f1620932f098a6037f0807e7f6616f (diff)
downloadpyecsca-85afbe7548d59d5ca5a8d17b32926f99235f5211.tar.gz
pyecsca-85afbe7548d59d5ca5a8d17b32926f99235f5211.tar.zst
pyecsca-85afbe7548d59d5ca5a8d17b32926f99235f5211.zip
Add the concept of a configuration. Add enumeration of configurations.
Diffstat (limited to 'test/ec')
-rw-r--r--test/ec/test_configuration.py53
-rw-r--r--test/ec/test_context.py39
-rw-r--r--test/ec/test_formula.py4
3 files changed, 92 insertions, 4 deletions
diff --git a/test/ec/test_configuration.py b/test/ec/test_configuration.py
new file mode 100644
index 0000000..560074b
--- /dev/null
+++ b/test/ec/test_configuration.py
@@ -0,0 +1,53 @@
+from unittest import TestCase
+
+from pyecsca.ec.configuration import (all_configurations, HashType, RandomMod, Multiplication,
+ Squaring, Reduction)
+from pyecsca.ec.model import ShortWeierstrassModel
+from pyecsca.ec.mult import LTRMultiplier
+from test.sca.utils import slow
+
+
+class ConfigurationTests(TestCase):
+
+ @slow
+ def test_all(self):
+ j = 0
+ for _ in all_configurations(model=ShortWeierstrassModel()):
+ j += 1
+ print(j)
+
+ def test_mult_class(self):
+ model = ShortWeierstrassModel()
+ coords = model.coordinates["projective"]
+ scalarmult = LTRMultiplier
+ hash_type = HashType.SHA1
+ mod_rand = RandomMod.SAMPLE
+ mult = Multiplication.BASE
+ sqr = Squaring.BASE
+ red = Reduction.BASE
+ configs = list(all_configurations(model=model, coords=coords, scalarmult=scalarmult,
+ hash_type=hash_type, mod_rand=mod_rand, mult=mult,
+ sqr=sqr, red=red))
+ self.assertEqual(len(configs), 384)
+
+ def test_one(self):
+ model = ShortWeierstrassModel()
+ coords = model.coordinates["projective"]
+ scalarmult = {
+ "cls": LTRMultiplier,
+ "add": coords.formulas["add-1998-cmo"],
+ "dbl": coords.formulas["dbl-1998-cmo"],
+ "scl": None,
+ "always": True,
+ "complete": False,
+ "short_circuit": True
+ }
+ hash_type = HashType.SHA1
+ mod_rand = RandomMod.SAMPLE
+ mult = Multiplication.BASE
+ sqr = Squaring.BASE
+ red = Reduction.BASE
+ configs = list(all_configurations(model=model, coords=coords, scalarmult=scalarmult,
+ hash_type=hash_type, mod_rand=mod_rand, mult=mult,
+ sqr=sqr, red=red))
+ self.assertEqual(len(configs), 1)
diff --git a/test/ec/test_context.py b/test/ec/test_context.py
index 3f46c9d..ea87b7f 100644
--- a/test/ec/test_context.py
+++ b/test/ec/test_context.py
@@ -1,11 +1,48 @@
from unittest import TestCase
from pyecsca.ec.context import (local, DefaultContext, NullContext, getcontext,
- setcontext, resetcontext)
+ setcontext, resetcontext, Tree)
from pyecsca.ec.curves import get_params
from pyecsca.ec.mult import LTRMultiplier, ScalarMultiplicationAction
+class TreeTests(TestCase):
+
+ def test_walk_by_key(self):
+ tree = Tree()
+ tree["a"] = Tree()
+ tree["a"]["1"] = Tree()
+ tree["a"]["2"] = Tree()
+ self.assertIn("a", tree)
+ self.assertIsInstance(tree.get_by_key([]), Tree)
+ self.assertIsInstance(tree.get_by_key(["a"]), Tree)
+ self.assertIsInstance(tree.get_by_key(["a", "1"]), Tree)
+
+ def test_walk_by_index(self):
+ tree = Tree()
+ a = Tree()
+ tree["a"] = a
+ d = Tree()
+ b = Tree()
+ tree["a"]["d"] = d
+ tree["a"]["b"] = b
+ self.assertIn("a", tree)
+ with self.assertRaises(ValueError):
+ tree.get_by_index([])
+
+ self.assertEqual(tree.get_by_index([0]), ("a", a))
+ self.assertEqual(tree.get_by_index([0, 0]), ("d", d))
+
+ def test_repr(self):
+ tree = Tree()
+ tree["a"] = Tree()
+ tree["a"]["1"] = Tree()
+ tree["a"]["2"] = Tree()
+ txt = tree.repr()
+ self.assertEqual(txt.count("\t"), 2)
+ self.assertEqual(txt.count("\n"), 3)
+
+
class ContextTests(TestCase):
def setUp(self):
diff --git a/test/ec/test_formula.py b/test/ec/test_formula.py
index cedbe1f..6f8037a 100644
--- a/test/ec/test_formula.py
+++ b/test/ec/test_formula.py
@@ -1,8 +1,6 @@
from unittest import TestCase
from pyecsca.ec.curves import get_params
-from pyecsca.ec.key_generation import KeyGeneration
-from pyecsca.ec.mult import LTRMultiplier
class FormulaTests(TestCase):
@@ -32,4 +30,4 @@ class FormulaTests(TestCase):
self.assertEqual(self.add.num_inversions, 0)
self.assertEqual(self.add.num_powers, 0)
self.assertEqual(self.add.num_squarings, 6)
- self.assertEqual(self.add.num_addsubs, 10) \ No newline at end of file
+ self.assertEqual(self.add.num_addsubs, 10)