aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/templates
diff options
context:
space:
mode:
authorJ08nY2023-10-01 22:55:17 +0200
committerJ08nY2023-10-01 22:55:17 +0200
commit7889941ce0c198113509738c1f0e84bb7826080f (patch)
tree692a96904713e56810ebdafa1906faeeb6260f59 /pyecsca/codegen/templates
parent9e01e2c7d9dfdadc653c05e80ed0f6aa235597ff (diff)
downloadpyecsca-codegen-7889941ce0c198113509738c1f0e84bb7826080f.tar.gz
pyecsca-codegen-7889941ce0c198113509738c1f0e84bb7826080f.tar.zst
pyecsca-codegen-7889941ce0c198113509738c1f0e84bb7826080f.zip
Add Sliding window multiplier.
Diffstat (limited to 'pyecsca/codegen/templates')
-rw-r--r--pyecsca/codegen/templates/mult_sliding_w.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/pyecsca/codegen/templates/mult_sliding_w.c b/pyecsca/codegen/templates/mult_sliding_w.c
new file mode 100644
index 0000000..87135cc
--- /dev/null
+++ b/pyecsca/codegen/templates/mult_sliding_w.c
@@ -0,0 +1,42 @@
+#include "mult.h"
+#include "point.h"
+
+static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) {
+ point_t *q = point_copy(curve->neutral);
+ point_t *points[{{ 2 ** (scalarmult.width - 1) }}];
+
+ point_t *current = point_copy(point);
+ point_t *dbl = point_new();
+ point_dbl(current, curve, dbl);
+ for (long i = 0; i < {{ 2 ** (scalarmult.width - 1) }}; i++) {
+ points[i] = point_copy(current);
+ point_add(current, dbl, curve, current);
+ }
+ point_free(current);
+ point_free(dbl);
+
+ {% if scalarmult.recoding_direction == ProcessingDirection.LTR %}
+ wsliding_t *ws = bn_wsliding_ltr(scalar, {{ scalarmult.width }});
+ {% elif scalarmult.recoding_direction == ProcessingDirection.RTL %}
+ wsliding_t *ws = bn_wsliding_rtl(scalar, {{ scalarmult.width }});
+ {% endif %}
+
+ for (long i = 0; i < ws->length; i++) {
+ point_dbl(q, curve, q);
+ uint8_t val = ws->data[i];
+ if (val) {
+ point_accumulate(q, points[(val - 1) / 2], curve, q);
+ }
+ }
+ free(ws->data);
+ free(ws);
+
+ {%- if "scl" in scalarmult.formulas %}
+ point_scl(q, curve, q);
+ {%- endif %}
+ point_set(q, out);
+ for (long i = 0; i < {{ 2 ** (scalarmult.width - 1) }}; i++) {
+ point_free(points[i]);
+ }
+ point_free(q);
+} \ No newline at end of file