diff options
| author | J08nY | 2019-12-23 02:05:35 +0100 |
|---|---|---|
| committer | J08nY | 2019-12-23 02:05:35 +0100 |
| commit | b43c5dba0ec18fe5a5204537855ea2b73fc674c6 (patch) | |
| tree | 879c946cb9036f6db721fc44c37635c295ee2003 /pyecsca/codegen/templates/mult_diff_ldr.c | |
| parent | 878d95c4e4dadf882a205316a07bc0642f773256 (diff) | |
| download | pyecsca-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.c | 29 |
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 |
