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_rtl.c | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pyecsca/codegen/templates/mult_rtl.c (limited to 'pyecsca/codegen/templates/mult_rtl.c') diff --git a/pyecsca/codegen/templates/mult_rtl.c b/pyecsca/codegen/templates/mult_rtl.c new file mode 100644 index 0000000..af437e0 --- /dev/null +++ b/pyecsca/codegen/templates/mult_rtl.c @@ -0,0 +1,37 @@ +#include "mult.h" +#include "point.h" + +void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { + point_t *q = point_copy(point); + point_t *r = point_copy(curve->neutral); + + {%- if scalarmult.always %} + point_t *dummy = point_new(); + {%- endif %} + bn_t copy; + bn_init(©); + bn_copy(scalar, ©); + + while (!bn_is_0(©)) { + if (bn_get_bit(©, i) == 1) { + point_add(q, r, curve, r); + } else { + {%- if scalarmult.always %} + point_add(q, r, curve, dummy); + {%- endif %} + } + point_dbl(q, curve, q); + bn_rsh(©, 1, ©); + } + {%- if "scl" in scalarmult.formulas %} + point_scl(r, curve, r); + {%- endif %} + + point_set(r, out); + point_free(q); + point_free(r); + bn_clear(©); + {%- if scalarmult.always %} + point_free(dummy); + {%- endif %} +} \ No newline at end of file -- cgit v1.3.1