From 8a56c7a95e662862cfe78b834ccb091e95d5372f Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 25 Nov 2019 17:45:35 +0100 Subject: Add libtommath, HOST build, and a simple PRNG. --- pyecsca/codegen/mult/double_and_add.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pyecsca/codegen/mult') diff --git a/pyecsca/codegen/mult/double_and_add.c b/pyecsca/codegen/mult/double_and_add.c index 91ad6e3..1fd3c9e 100644 --- a/pyecsca/codegen/mult/double_and_add.c +++ b/pyecsca/codegen/mult/double_and_add.c @@ -1,5 +1,18 @@ #include "mult.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); + + int nbits = bn_bit_length(curve->n); + for (int i = nbits; i >= 0; i--) { + point_dbl(r, curve, r); + if (bn_get_bit(scalar, i) == 1) { + point_add(q, r, curve, r); + } + } + point_scl(r, curve, r); + point_set(r, out); + point_free(q); + point_free(r); } \ No newline at end of file -- cgit v1.3.1