aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJ08nY2025-03-12 17:24:40 +0100
committerJ08nY2025-03-12 17:58:49 +0100
commite4c50355c50934e508d9b6d4a957be17d12d8b25 (patch)
tree95f1821e4c3d762e61f44047a39838429a857010 /test
parentcbeabc60d545dcc29f8ab45e602670d332dc0645 (diff)
downloadpyecsca-e4c50355c50934e508d9b6d4a957be17d12d8b25.tar.gz
pyecsca-e4c50355c50934e508d9b6d4a957be17d12d8b25.tar.zst
pyecsca-e4c50355c50934e508d9b6d4a957be17d12d8b25.zip
Diffstat (limited to 'test')
-rw-r--r--test/sca/test_rpa.py29
-rw-r--r--test/sca/test_rpa_context.py21
2 files changed, 48 insertions, 2 deletions
diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py
index 6d58597..8d843a4 100644
--- a/test/sca/test_rpa.py
+++ b/test/sca/test_rpa.py
@@ -1,3 +1,5 @@
+from functools import partial
+
import pytest
from math import isqrt
@@ -94,9 +96,36 @@ def test_multiples_kind(rpa_params):
17, rpa_params, RTLMultiplier, RTLMultiplier, True, True,
kind="necessary"
)
+ multiples_precomp = multiples_computed(
+ 17, rpa_params, RTLMultiplier, RTLMultiplier, True, True,
+ kind="precomp+necessary"
+ )
+ assert multiples_all != multiples_input
+ assert multiples_all != multiples_necessary
+ assert multiples_input != multiples_necessary
+ assert multiples_precomp == multiples_necessary
+
+ wnaf = partial(WindowNAFMultiplier, width=4)
+ multiples_all = multiples_computed(
+ 0xff, rpa_params, WindowNAFMultiplier, wnaf, True, True,
+ kind="all"
+ )
+ multiples_input = multiples_computed(
+ 0xff, rpa_params, WindowNAFMultiplier, wnaf, True, True,
+ kind="input"
+ )
+ multiples_necessary = multiples_computed(
+ 0xff, rpa_params, WindowNAFMultiplier, wnaf, True, True,
+ kind="necessary"
+ )
+ multiples_precomp = multiples_computed(
+ 0xff, rpa_params, WindowNAFMultiplier, wnaf, True, True,
+ kind="precomp+necessary"
+ )
assert multiples_all != multiples_input
assert multiples_all != multiples_necessary
assert multiples_input != multiples_necessary
+ assert multiples_precomp != multiples_necessary
def test_x0_point(rpa_params):
diff --git a/test/sca/test_rpa_context.py b/test/sca/test_rpa_context.py
index 7520516..44eea5b 100644
--- a/test/sca/test_rpa_context.py
+++ b/test/sca/test_rpa_context.py
@@ -9,7 +9,6 @@ from pyecsca.ec.formula import (
DoublingFormula,
ScalingFormula,
)
-from pyecsca.ec.mod import Mod
from pyecsca.ec.mult import (
LTRMultiplier,
BinaryNAFMultiplier,
@@ -85,9 +84,10 @@ def test_precomp(secp128r1, add, dbl, neg, scale):
def test_window(secp128r1, add, dbl, neg):
mult = WindowNAFMultiplier(add, dbl, neg, 3, precompute_negation=True)
- with local(MultipleContext()):
+ with local(MultipleContext()) as ctx:
mult.init(secp128r1, secp128r1.generator)
mult.multiply(5)
+ assert ctx.precomp
def test_ladder(curve25519):
@@ -111,3 +111,20 @@ def test_ladder(curve25519):
dadd_mult.multiply(1339278426732672313)
muls = list(ctx.points.values())
assert muls[-2] == 1339278426732672313
+
+
+def test_keep_base(secp128r1, add, dbl):
+ mult = LTRMultiplier(
+ add,
+ dbl,
+ always=False,
+ complete=False,
+ short_circuit=True,
+ )
+
+ with local(MultipleContext(keep_base=True)) as ctx:
+ mult.init(secp128r1, secp128r1.generator)
+ r = mult.multiply(5)
+ mult.init(secp128r1, r)
+ mult.multiply(10)
+ assert 50 in ctx.points.values()