diff options
| author | Andrej Bátora | 2023-12-07 15:50:22 +0100 |
|---|---|---|
| committer | GitHub | 2023-12-07 15:50:22 +0100 |
| commit | f7a1d8cac5aafe98b89bfdea7744206dd6db84f5 (patch) | |
| tree | e6038cca4dcab095006e4f9eab978d1ec5c19001 /pyecsca/codegen | |
| parent | b187a92f77a354039054a2f107565f69f4aff21f (diff) | |
| parent | 4402971348d442d24693f1a7298662c476b9dcd3 (diff) | |
| download | pyecsca-codegen-f7a1d8cac5aafe98b89bfdea7744206dd6db84f5.tar.gz pyecsca-codegen-f7a1d8cac5aafe98b89bfdea7744206dd6db84f5.tar.zst pyecsca-codegen-f7a1d8cac5aafe98b89bfdea7744206dd6db84f5.zip | |
Merge branch 'J08nY:master' into fix/naming
Diffstat (limited to 'pyecsca/codegen')
| -rw-r--r-- | pyecsca/codegen/formulas.h | 2 | ||||
| -rw-r--r-- | pyecsca/codegen/point.h | 7 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_add.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_dadd.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_dbl.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_ladd.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_neg.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_scl.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formula_tpl.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/formulas.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult.c | 3 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/ops.c | 9 |
12 files changed, 47 insertions, 8 deletions
diff --git a/pyecsca/codegen/formulas.h b/pyecsca/codegen/formulas.h index 763b85d..9e3152b 100644 --- a/pyecsca/codegen/formulas.h +++ b/pyecsca/codegen/formulas.h @@ -3,6 +3,8 @@ void formulas_init(void); +void formulas_zero(void); + void formulas_clear(void); #endif //FORMULAS_H_
\ No newline at end of file diff --git a/pyecsca/codegen/point.h b/pyecsca/codegen/point.h index fd3736e..f3a3ba2 100644 --- a/pyecsca/codegen/point.h +++ b/pyecsca/codegen/point.h @@ -25,30 +25,37 @@ void point_from_affine(bn_t *x, bn_t *y, const curve_t *curve, point_t *out); void point_add(const point_t *one, const point_t *other, const curve_t *curve, point_t *out_one); bool point_add_init(void); +void point_add_zero(void); void point_add_clear(void); void point_dbl(const point_t *one, const curve_t *curve, point_t *out_one); bool point_dbl_init(void); +void point_dbl_zero(void); void point_dbl_clear(void); void point_tpl(const point_t *one, const curve_t *curve, point_t *out_one); bool point_tpl_init(void); +void point_tpl_zero(void); void point_tpl_clear(void); void point_neg(const point_t *one, const curve_t *curve, point_t *out_one); bool point_neg_init(void); +void point_neg_zero(void); void point_neg_clear(void); void point_scl(const point_t *one, const curve_t *curve, point_t *out_one); bool point_scl_init(void); +void point_scl_zero(void); void point_scl_clear(void); void point_dadd(const point_t *one, const point_t *other, const point_t *diff, const curve_t *curve, point_t *out_one); bool point_dadd_init(void); +void point_dadd_zero(void); void point_dadd_clear(void); void point_ladd(const point_t *one, const point_t *other, const point_t *diff, const curve_t *curve, point_t *out_one, point_t *out_other); bool point_ladd_init(void); +void point_ladd_zero(void); void point_ladd_clear(void); void point_accumulate(const point_t *one, const point_t *other, const curve_t *curve, point_t *out_one); diff --git a/pyecsca/codegen/templates/formula_add.c b/pyecsca/codegen/templates/formula_add.c index 39d12b6..6026601 100644 --- a/pyecsca/codegen/templates/formula_add.c +++ b/pyecsca/codegen/templates/formula_add.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_add(const point_t *one, const point_t *other, const curve_t *curve, point_t *out_one) { +__attribute__((noinline)) void point_add(const point_t *one, const point_t *other, const curve_t *curve, point_t *out_one) { {{ start_action("add") }} //NOP_128(); {%- if short_circuit %} diff --git a/pyecsca/codegen/templates/formula_dadd.c b/pyecsca/codegen/templates/formula_dadd.c index 855cf5d..de9c977 100644 --- a/pyecsca/codegen/templates/formula_dadd.c +++ b/pyecsca/codegen/templates/formula_dadd.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_dadd(const point_t *one, const point_t *other, const point_t *diff, const curve_t *curve, point_t *out_one) { +__attribute__((noinline)) void point_dadd(const point_t *one, const point_t *other, const point_t *diff, const curve_t *curve, point_t *out_one) { {{ start_action("dadd") }} //NOP_128(); // TODO: short-circuits diff --git a/pyecsca/codegen/templates/formula_dbl.c b/pyecsca/codegen/templates/formula_dbl.c index 3c10bd7..451b0ee 100644 --- a/pyecsca/codegen/templates/formula_dbl.c +++ b/pyecsca/codegen/templates/formula_dbl.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_dbl(const point_t *one, const curve_t *curve, point_t *out_one) { +__attribute__((noinline)) void point_dbl(const point_t *one, const curve_t *curve, point_t *out_one) { {{ start_action("dbl") }} //NOP_128(); {%- if short_circuit %} diff --git a/pyecsca/codegen/templates/formula_ladd.c b/pyecsca/codegen/templates/formula_ladd.c index 2eaa531..2656708 100644 --- a/pyecsca/codegen/templates/formula_ladd.c +++ b/pyecsca/codegen/templates/formula_ladd.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_ladd(const point_t *one, const point_t *other, const point_t *diff, const curve_t *curve, point_t *out_one, point_t *out_other) { +__attribute__((noinline)) void point_ladd(const point_t *one, const point_t *other, const point_t *diff, const curve_t *curve, point_t *out_one, point_t *out_other) { {{ start_action("ladd") }} //NOP_128(); // TODO: short-circuits diff --git a/pyecsca/codegen/templates/formula_neg.c b/pyecsca/codegen/templates/formula_neg.c index 4eaf62d..93fbe20 100644 --- a/pyecsca/codegen/templates/formula_neg.c +++ b/pyecsca/codegen/templates/formula_neg.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_neg(const point_t *one, const curve_t *curve, point_t *out_one) { +__attribute__((noinline)) void point_neg(const point_t *one, const curve_t *curve, point_t *out_one) { {{ start_action("neg") }} //NOP_128(); {%- if short_circuit %} diff --git a/pyecsca/codegen/templates/formula_scl.c b/pyecsca/codegen/templates/formula_scl.c index dfcfcbe..48ac52e 100644 --- a/pyecsca/codegen/templates/formula_scl.c +++ b/pyecsca/codegen/templates/formula_scl.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_scl(const point_t *one, const curve_t *curve, point_t *out_one) { +__attribute__((noinline)) void point_scl(const point_t *one, const curve_t *curve, point_t *out_one) { {{ start_action("scl") }} //NOP_128(); {%- if short_circuit %} diff --git a/pyecsca/codegen/templates/formula_tpl.c b/pyecsca/codegen/templates/formula_tpl.c index 40cf114..d280bad 100644 --- a/pyecsca/codegen/templates/formula_tpl.c +++ b/pyecsca/codegen/templates/formula_tpl.c @@ -6,9 +6,11 @@ {{ ops.render_static_init(allocations, formula.shortname) }} +{{ ops.render_static_zero(allocations, formula.shortname) }} + {{ ops.render_static_clear(frees, formula.shortname) }} -void point_tpl(const point_t *one, const curve_t *curve, point_t *out_one) { +__attribute__((noinline)) void point_tpl(const point_t *one, const curve_t *curve, point_t *out_one) { {{ start_action("tpl") }} //NOP_128(); {%- if short_circuit %} diff --git a/pyecsca/codegen/templates/formulas.c b/pyecsca/codegen/templates/formulas.c index 7135727..f17ea13 100644 --- a/pyecsca/codegen/templates/formulas.c +++ b/pyecsca/codegen/templates/formulas.c @@ -8,6 +8,12 @@ void formulas_init(void) { {%- endfor %} } +void formulas_zero(void) { + {%- for name in names %} + point_{{ name }}_zero(); + {%- endfor %} +} + void formulas_clear(void) { {%- for name in names %} point_{{ name }}_clear(); diff --git a/pyecsca/codegen/templates/mult.c b/pyecsca/codegen/templates/mult.c index 22a385d..0144e36 100644 --- a/pyecsca/codegen/templates/mult.c +++ b/pyecsca/codegen/templates/mult.c @@ -53,12 +53,13 @@ {%- endif %} - +#include "formulas.h" #include "action.h" {% from "action.c" import start_action, end_action %} void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { {{ start_action("mult") }} + formulas_zero(); scalar_mult_inner(scalar, point, curve, out); {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/ops.c b/pyecsca/codegen/templates/ops.c index ee322a8..30a7622 100644 --- a/pyecsca/codegen/templates/ops.c +++ b/pyecsca/codegen/templates/ops.c @@ -55,6 +55,15 @@ } {%- endmacro %} +{% macro render_static_zero(allocations, name) -%} + void point_{{ name }}_zero(void) { + {%- for alloc in allocations -%} + bn_from_int(0, &{{alloc}}); + {%- endfor -%} + } +{%- endmacro %} + + {% macro render_static_clear(frees, name) -%} void point_{{ name }}_clear(void) { {{ render_frees(frees) }} |
