#include "mult.h" #include "point.h" void scalar_mult_inner(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(©, 0) == 1) { point_add(r, q, curve, r); } else { {%- if scalarmult.always %} point_add(r, q, 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 %} }