From b43c5dba0ec18fe5a5204537855ea2b73fc674c6 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 23 Dec 2019 02:05:35 +0100 Subject: Implement multipliers. --- pyecsca/codegen/templates/mult_diff_ldr.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pyecsca/codegen/templates/mult_diff_ldr.c (limited to 'pyecsca/codegen/templates/mult_diff_ldr.c') diff --git a/pyecsca/codegen/templates/mult_diff_ldr.c b/pyecsca/codegen/templates/mult_diff_ldr.c new file mode 100644 index 0000000..2683116 --- /dev/null +++ b/pyecsca/codegen/templates/mult_diff_ldr.c @@ -0,0 +1,29 @@ +#include "mult.h" +#include "point.h" + +void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { + point_t *p0 = point_copy(&curve->neutral); + point_t *p1 = point_copy(point); + {%- if scalarmult.complete %} + int nbits = bn_bit_length(&curve->n) - 1; + {%- else %} + int nbits = bn_bit_length(scalar) - 1; + {%- endif %} + + for (int i = nbits; i >= 0; i--) { + if (bn_get_bit(scalar, i) == 0) { + point_dadd(point, p0, p1, curve, p1); + point_dbl(p0, curve, p0); + } else { + point_dadd(point, p0, p1, curve, p0); + point_dbl(p1, curve, p1); + } + } + + {%- if "scl" in scalarmult.formulas %} + point_scl(p0, curve, p0); + {%- endif %} + point_set(p0, out); + point_free(p0); + point_free(p1); +} \ No newline at end of file -- cgit v1.3.1