aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJ08nY2023-10-08 20:57:24 +0200
committerJ08nY2023-10-08 20:57:24 +0200
commit1c2e383d8e8df323b4cebb302869fc15599961a0 (patch)
treedfdfbf9a12acd1662cba56b46b30d8337ae81918 /test
parent71579306e7c63123426e5bda105e3ab850fbbb20 (diff)
downloadpyecsca-codegen-1c2e383d8e8df323b4cebb302869fc15599961a0.tar.gz
pyecsca-codegen-1c2e383d8e8df323b4cebb302869fc15599961a0.tar.zst
pyecsca-codegen-1c2e383d8e8df323b4cebb302869fc15599961a0.zip
Add fixed-base multipliers with precomputation.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/test_bn.c14
-rw-r--r--test/test_impl.py59
3 files changed, 66 insertions, 9 deletions
diff --git a/test/Makefile b/test/Makefile
index 4b8fc78..d13b487 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,3 @@
test_bn: test_bn.c ../pyecsca/codegen/bn/bn.c
- gcc -o $@ $^ -I ../pyecsca/codegen/ -I ../pyecsca/codegen/tommath/ -L ../pyecsca/codegen/tommath/ -l:libtommath-HOST.a \ No newline at end of file
+ gcc -o $@ $^ -fsanitize=address -fsanitize=undefined -I ../pyecsca/codegen/ -I ../pyecsca/codegen/tommath/ -L ../pyecsca/codegen/tommath/ -l:libtommath-HOST.a \ No newline at end of file
diff --git a/test/test_bn.c b/test/test_bn.c
index 9e3fd6f..66de22f 100644
--- a/test/test_bn.c
+++ b/test/test_bn.c
@@ -59,21 +59,21 @@ int test_wsliding_rtl() {
}
int test_convert_base() {
- printf("test_convert-base: ");
+ printf("test_convert_base: ");
bn_t bn;
bn_init(&bn);
- bn_from_int(5, &bn);
- base_t *bs = bn_convert_base(&bn, 2);
+ bn_from_int(11, &bn);
+ small_base_t *bs = bn_convert_base_small(&bn, 2);
if (bs == NULL) {
printf("NULL\n");
return 1;
}
- if (bs->length != 3) {
- printf("Bad length (%li instead of 3)\n", bs->length);
+ if (bs->length != 4) {
+ printf("Bad length (%li instead of 4)\n", bs->length);
return 1;
}
- uint8_t expected[3] = {1, 0, 1};
- for (int i = 0; i < 3; i++) {
+ uint8_t expected[4] = {1, 1, 0, 1};
+ for (int i = 0; i < 4; i++) {
if (bs->data[i] != expected[i]) {
printf("Bad data (%i insead of %i)\n", bs->data[i], expected[i]);
return 1;
diff --git a/test/test_impl.py b/test/test_impl.py
index cb5b583..da42c33 100644
--- a/test/test_impl.py
+++ b/test/test_impl.py
@@ -16,6 +16,9 @@ from pyecsca.ec.mult import (
ProcessingDirection,
ScalarMultiplier,
FixedWindowLTRMultiplier,
+ FullPrecompMultiplier,
+ BGMWMultiplier,
+ CombMultiplier,
)
from pyecsca.ec.signature import ECDSA_SHA1, SignatureResult
@@ -167,6 +170,60 @@ def additional(request):
),
id="FIX2",
),
+ pytest.param(
+ (
+ FullPrecompMultiplier,
+ "precomp",
+ ["add-1998-cmo", "dbl-1998-cmo"],
+ {"direction": ProcessingDirection.LTR},
+ ),
+ id="PRE1",
+ ),
+ pytest.param(
+ (
+ FullPrecompMultiplier,
+ "precomp",
+ ["add-1998-cmo", "dbl-1998-cmo"],
+ {"direction": ProcessingDirection.RTL},
+ ),
+ id="PRE2",
+ ),
+ pytest.param(
+ (
+ BGMWMultiplier,
+ "bgmw",
+ ["add-1998-cmo", "dbl-1998-cmo"],
+ {"width": 3, "direction": ProcessingDirection.LTR},
+ ),
+ id="BGMW1",
+ ),
+ pytest.param(
+ (
+ BGMWMultiplier,
+ "bgmw",
+ ["add-1998-cmo", "dbl-1998-cmo"],
+ {"width": 5, "direction": ProcessingDirection.RTL},
+ ),
+ id="BGMW2",
+ ),
+ pytest.param(
+ (
+ CombMultiplier,
+ "comb",
+ ["add-1998-cmo", "dbl-1998-cmo"],
+ {"width": 3},
+ ),
+ id="Comb1",
+ ),
+ pytest.param(
+ (
+ CombMultiplier,
+ "comb",
+ ["add-1998-cmo", "dbl-1998-cmo"],
+ {"width": 5},
+ ),
+ id="Comb2",
+ ),
],
)
def target(request, additional, secp128r1) -> ImplTarget:
@@ -189,7 +246,7 @@ def target(request, additional, secp128r1) -> ImplTarget:
],
env={
"CFLAGS": "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
- }
+ },
)
assert res.exit_code == 0
target = HostTarget(