aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/templates/mult_diff_ldr.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_diff_ldr.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_diff_ldr.c')
-rw-r--r--pyecsca/codegen/templates/mult_diff_ldr.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/pyecsca/codegen/templates/mult_diff_ldr.c b/pyecsca/codegen/templates/mult_diff_ldr.c
new file mode 100644
index 0000000..2683116
--- /dev/null
+++ b/pyecsca/codegen/templates/mult_diff_ldr.c
@@ -0,0 +1,29 @@
+#include "mult.h"
+#include "point.h"
+
+void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) {
+ point_t *p0 = point_copy(&curve->neutral);
+ point_t *p1 = point_copy(point);
+ {%- if scalarmult.complete %}
+ int nbits = bn_bit_length(&curve->n) - 1;
+ {%- else %}
+ int nbits = bn_bit_length(scalar) - 1;
+ {%- endif %}
+
+ for (int i = nbits; i >= 0; i--) {
+ if (bn_get_bit(scalar, i) == 0) {
+ point_dadd(point, p0, p1, curve, p1);
+ point_dbl(p0, curve, p0);
+ } else {
+ point_dadd(point, p0, p1, curve, p0);
+ point_dbl(p1, curve, p1);
+ }
+ }
+
+ {%- if "scl" in scalarmult.formulas %}
+ point_scl(p0, curve, p0);
+ {%- endif %}
+ point_set(p0, out);
+ point_free(p0);
+ point_free(p1);
+} \ No newline at end of file