From 3a0ebdac2067e5695b632a12345fae0b6ba75c83 Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 1 Oct 2025 16:11:33 +0200 Subject: Fix impls and most equivalence tests. --- pyecsca/codegen/bn/bn.c | 6 +++--- pyecsca/codegen/templates/mult_simple_ldr.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'pyecsca/codegen') diff --git a/pyecsca/codegen/bn/bn.c b/pyecsca/codegen/bn/bn.c index f41a1d7..7f91cfd 100644 --- a/pyecsca/codegen/bn/bn.c +++ b/pyecsca/codegen/bn/bn.c @@ -542,8 +542,8 @@ wsliding_t *bn_wsliding_rtl(const bn_t *bn, int w) { wsliding_t *result = NULL; int blen = bn_bit_length(bn); - uint8_t arr[blen + 2]; - memset(arr, 0, (blen + 2) * sizeof(uint8_t)); + uint8_t arr[blen + w]; + memset(arr, 0, (blen + w) * sizeof(uint8_t)); bn_t k; if (mp_init(&k) != BN_OKAY) { @@ -557,7 +557,7 @@ wsliding_t *bn_wsliding_rtl(const bn_t *bn, int w) { } int i = 0; - while (!bn_is_0(&k) && !(bn_get_sign(&k) == BN_NEG)) { + while (mp_cmp_d(&k, 0) == MP_GT) { if (!bn_get_bit(&k, 0)) { arr[i++] = 0; bn_rsh(&k, 1, &k); diff --git a/pyecsca/codegen/templates/mult_simple_ldr.c b/pyecsca/codegen/templates/mult_simple_ldr.c index ceb257a..33bfcd9 100644 --- a/pyecsca/codegen/templates/mult_simple_ldr.c +++ b/pyecsca/codegen/templates/mult_simple_ldr.c @@ -11,7 +11,7 @@ void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *ou {%- endif %} for (int i = nbits; i >= 0; i--) { - if (bn_get_bit(scalar, i) == 1) { + if (bn_get_bit(scalar, i) == 0) { point_add(p0, p1, curve, p1); point_dbl(p0, curve, p0); } else { -- cgit v1.3.1