aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/mult
diff options
context:
space:
mode:
Diffstat (limited to 'pyecsca/codegen/mult')
-rw-r--r--pyecsca/codegen/mult/double_and_add.c15
1 files changed, 14 insertions, 1 deletions
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