aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen
diff options
context:
space:
mode:
authorJ08nY2025-10-02 14:03:40 +0200
committerJ08nY2025-10-02 14:03:40 +0200
commitdc1241a76f5658a481613817a71c62fbb9234250 (patch)
tree6b1c5a74cb11c36443b8693eeefca0ddc8b27b20 /pyecsca/codegen
parent9e4e4c77ec7e23fe7668ab836c89cc7a84c9389a (diff)
downloadpyecsca-codegen-dc1241a76f5658a481613817a71c62fbb9234250.tar.gz
pyecsca-codegen-dc1241a76f5658a481613817a71c62fbb9234250.tar.zst
pyecsca-codegen-dc1241a76f5658a481613817a71c62fbb9234250.zip
Full equivalence.
Diffstat (limited to 'pyecsca/codegen')
-rw-r--r--pyecsca/codegen/templates/mult_comb.c13
-rw-r--r--pyecsca/codegen/templates/mult_rtl.c8
2 files changed, 20 insertions, 1 deletions
diff --git a/pyecsca/codegen/templates/mult_comb.c b/pyecsca/codegen/templates/mult_comb.c
index 9df9796..a0fbd10 100644
--- a/pyecsca/codegen/templates/mult_comb.c
+++ b/pyecsca/codegen/templates/mult_comb.c
@@ -39,6 +39,10 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin
bn_from_int(1, &base);
bn_lsh(&base, d, &base);
+ {% if scalarmult.always %}
+ point_t *dummy = point_new();
+ {% endif %}
+
large_base_t *bs = bn_convert_base_large(scalar, &base);
for (int i = d - 1; i >= 0; i--) {
point_dbl(q, curve, q);
@@ -50,6 +54,15 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin
}
if (word) {
point_accumulate(q, points[word], curve, q);
+ } else {
+ {% if scalarmult.always %}
+ int j = i % {{ 2**scalarmult.width }};
+ if (j == 0) {
+ point_accumulate(q, point, curve, dummy);
+ } else {
+ point_accumulate(q, points[j], curve, dummy);
+ }
+ {% endif %}
}
}
for (int i = 0; i < bs->length; i++) {
diff --git a/pyecsca/codegen/templates/mult_rtl.c b/pyecsca/codegen/templates/mult_rtl.c
index 71949b4..119ee7e 100644
--- a/pyecsca/codegen/templates/mult_rtl.c
+++ b/pyecsca/codegen/templates/mult_rtl.c
@@ -5,6 +5,12 @@ void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *ou
point_t *q = point_copy(point);
point_t *r = point_copy(curve->neutral);
+ {% if scalarmult.complete %}
+ size_t bits = bn_bit_length(&curve->n);
+ {% else %}
+ size_t bits = bn_bit_length(scalar);
+ {% endif %}
+
{%- if scalarmult.always %}
point_t *dummy = point_new();
{%- endif %}
@@ -12,7 +18,7 @@ void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *ou
bn_init(&copy);
bn_copy(scalar, &copy);
- while (!bn_is_0(&copy)) {
+ for (int i = 0; i < bits; i++) {
if (bn_get_bit(&copy, 0) == 1) {
point_accumulate(r, q, curve, r);
} else {