aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/templates/mult_rtl.c
diff options
context:
space:
mode:
authorJ08nY2019-12-23 02:05:35 +0100
committerJ08nY2019-12-23 02:05:35 +0100
commitb43c5dba0ec18fe5a5204537855ea2b73fc674c6 (patch)
tree879c946cb9036f6db721fc44c37635c295ee2003 /pyecsca/codegen/templates/mult_rtl.c
parent878d95c4e4dadf882a205316a07bc0642f773256 (diff)
downloadpyecsca-codegen-b43c5dba0ec18fe5a5204537855ea2b73fc674c6.tar.gz
pyecsca-codegen-b43c5dba0ec18fe5a5204537855ea2b73fc674c6.tar.zst
pyecsca-codegen-b43c5dba0ec18fe5a5204537855ea2b73fc674c6.zip
Implement multipliers.
Diffstat (limited to 'pyecsca/codegen/templates/mult_rtl.c')
-rw-r--r--pyecsca/codegen/templates/mult_rtl.c37
1 files changed, 37 insertions, 0 deletions
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(&copy);
+ bn_copy(scalar, &copy);
+
+ while (!bn_is_0(&copy)) {
+ if (bn_get_bit(&copy, 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(&copy, 1, &copy);
+ }
+ {%- if "scl" in scalarmult.formulas %}
+ point_scl(r, curve, r);
+ {%- endif %}
+
+ point_set(r, out);
+ point_free(q);
+ point_free(r);
+ bn_clear(&copy);
+ {%- if scalarmult.always %}
+ point_free(dummy);
+ {%- endif %}
+} \ No newline at end of file