aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2021-05-12 22:25:51 +0200
committerJ08nY2021-05-12 22:25:51 +0200
commit063ea46670a0bf6ffff59e8189179f68688d2028 (patch)
tree0389d8d096074f3022018fde16dcd8dc03fbc239
parente949a8f717409d0bdf10eaa5dc19c4aac476ce73 (diff)
downloadpyecsca-063ea46670a0bf6ffff59e8189179f68688d2028.tar.gz
pyecsca-063ea46670a0bf6ffff59e8189179f68688d2028.tar.zst
pyecsca-063ea46670a0bf6ffff59e8189179f68688d2028.zip
-rw-r--r--pyecsca/sca/re/rpa.py11
-rw-r--r--test/sca/test_rpa.py8
2 files changed, 17 insertions, 2 deletions
diff --git a/pyecsca/sca/re/rpa.py b/pyecsca/sca/re/rpa.py
index f21429a..4330fb4 100644
--- a/pyecsca/sca/re/rpa.py
+++ b/pyecsca/sca/re/rpa.py
@@ -36,8 +36,15 @@ class MultipleContext(Context):
def enter_action(self, action: Action) -> None:
if isinstance(action, (ScalarMultiplicationAction, PrecomputationAction)):
- self.base = action.point
- self.points = {self.base: 1}
+ if self.base:
+ # If we already did some computation with this context try to see if we are building on top of it.
+ if self.base != action.point:
+ # If we are not building on top of it we have to forget stuff and set a new base and mapping.
+ self.base = action.point
+ self.points = {self.base: 1}
+ else:
+ self.base = action.point
+ self.points = {self.base: 1}
self.inside = True
def exit_action(self, action: Action) -> None:
diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py
index ac8392e..b33915e 100644
--- a/test/sca/test_rpa.py
+++ b/test/sca/test_rpa.py
@@ -26,6 +26,7 @@ class MultipleContextTests(TestCase):
@parameterized.expand(
[
+ ("5", 5),
("10", 10),
("2355498743", 2355498743),
(
@@ -63,6 +64,13 @@ class MultipleContextTests(TestCase):
muls = list(ctx.points.values())
self.assertListEqual(muls, [1, 2, 3, 5])
+ def test_window(self):
+ mult = WindowNAFMultiplier(self.add, self.dbl, self.neg, 3, precompute_negation=True)
+ with local(MultipleContext()) as ctx:
+ mult.init(self.secp128r1, self.base)
+ mult.multiply(5)
+ print(ctx.points.values())
+
def test_ladder(self):
curve25519 = get_params("other", "Curve25519", "xz")
base = curve25519.generator