diff options
| author | J08nY | 2020-03-02 00:03:57 +0100 |
|---|---|---|
| committer | J08nY | 2020-03-02 00:03:57 +0100 |
| commit | b3e45bf773cec6ecf3f2a702c0b48c9dbfab0c04 (patch) | |
| tree | 8a232cf9298772e88bfee7f39b973f0e9009cae3 /pyecsca/codegen/templates | |
| parent | 0341d359dc67ced3f1e65d1d11af3590c1f0992f (diff) | |
| download | pyecsca-codegen-b3e45bf773cec6ecf3f2a702c0b48c9dbfab0c04.tar.gz pyecsca-codegen-b3e45bf773cec6ecf3f2a702c0b48c9dbfab0c04.tar.zst pyecsca-codegen-b3e45bf773cec6ecf3f2a702c0b48c9dbfab0c04.zip | |
Add reduction functions, add global trigger for whole cmd.
Diffstat (limited to 'pyecsca/codegen/templates')
| -rw-r--r-- | pyecsca/codegen/templates/Makefile | 2 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/action.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/curve.c | 7 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/defs.h | 2 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult.c | 12 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_bnaf.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_coron.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_diff_ldr.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_ldr.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_ltr.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_rtl.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_simple_ldr.c | 6 |
12 files changed, 30 insertions, 39 deletions
diff --git a/pyecsca/codegen/templates/Makefile b/pyecsca/codegen/templates/Makefile index be1ab08..8721d4c 100644 --- a/pyecsca/codegen/templates/Makefile +++ b/pyecsca/codegen/templates/Makefile @@ -4,7 +4,7 @@ SRC += main.c bn/bn.c asn1/asn1.c hash/hash.c prng/prng.c $(wildcard gen/*.c) PLATFORM = {{ platform }} -CDEFS += -DHASH={{ hash_type }} -DMOD_RAND={{ mod_rand }} +CDEFS += -DHASH={{ hash_type }} -DMOD_RAND={{ mod_rand }} -DREDUCTION={{ reduction }} MKDIR_LIST += hash prng asn1 bn gen diff --git a/pyecsca/codegen/templates/action.c b/pyecsca/codegen/templates/action.c index 258e599..939c6a0 100644 --- a/pyecsca/codegen/templates/action.c +++ b/pyecsca/codegen/templates/action.c @@ -69,13 +69,13 @@ uint32_t action_vector = 0; void action_start(uint32_t action) { if (action_vector & action) { - trigger_high(); + trigger_flip(); } } void action_end(uint32_t action) { if (action_vector & action) { - trigger_low(); + trigger_flip(); } } diff --git a/pyecsca/codegen/templates/curve.c b/pyecsca/codegen/templates/curve.c index a3a6592..f99b8d4 100644 --- a/pyecsca/codegen/templates/curve.c +++ b/pyecsca/codegen/templates/curve.c @@ -7,6 +7,8 @@ curve_t* curve_new(void) { {%- for param in params + ["p", "n", "h"] %} bn_init(&result->{{ param }}); {%- endfor %} + bn_red_init(&result->p_red); + bn_red_init(&result->n_red); result->generator = point_new(); result->neutral = point_new(); @@ -17,6 +19,8 @@ void curve_free(curve_t *curve) { {%- for param in params + ["p", "n", "h"] %} bn_clear(&curve->{{ param }}); {%- endfor %} + bn_red_clear(&curve->p_red); + bn_red_clear(&curve->n_red); if (curve->generator) { point_free(curve->generator); } @@ -30,6 +34,9 @@ void curve_set_param(curve_t *curve, char name, const bn_t *value) { switch (name) { {%- for param in params + ["p", "n", "h"] %} case '{{ param }}': bn_copy(value, &curve->{{ param }}); + {% if param in ("p", "n") %} + bn_red_setup(value, &curve->{{ param }}_red); + {%- endif %} break; {%- endfor %} } diff --git a/pyecsca/codegen/templates/defs.h b/pyecsca/codegen/templates/defs.h index 071e8a3..5a3875f 100644 --- a/pyecsca/codegen/templates/defs.h +++ b/pyecsca/codegen/templates/defs.h @@ -13,10 +13,12 @@ typedef struct { typedef struct { bn_t p; + red_t p_red; {%- for param in params %} bn_t {{ param }}; {%- endfor %} bn_t n; + red_t n_red; bn_t h; point_t *generator; point_t *neutral; diff --git a/pyecsca/codegen/templates/mult.c b/pyecsca/codegen/templates/mult.c index f611e95..0603bc0 100644 --- a/pyecsca/codegen/templates/mult.c +++ b/pyecsca/codegen/templates/mult.c @@ -27,4 +27,14 @@ {% include "mult_bnaf.c" %} -{%- endif -%} +{%- endif %} + + +#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") }} + scalar_mult_inner(scalar, point, curve, out); + {{ end_action("mult") }} +}
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_bnaf.c b/pyecsca/codegen/templates/mult_bnaf.c index 10a93fe..33e7302 100644 --- a/pyecsca/codegen/templates/mult_bnaf.c +++ b/pyecsca/codegen/templates/mult_bnaf.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_t *neg = point_new(); point_neg(point, curve, neg); point_t *q = point_copy(curve->neutral); @@ -28,5 +25,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_set(q, out); point_free(neg); point_free(q); - {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_coron.c b/pyecsca/codegen/templates/mult_coron.c index a2b1085..05e6804 100644 --- a/pyecsca/codegen/templates/mult_coron.c +++ b/pyecsca/codegen/templates/mult_coron.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_t *p0 = point_copy(point); point_t *p1 = point_new(); @@ -22,5 +19,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_set(p0, out); point_free(p0); point_free(p1); - {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_diff_ldr.c b/pyecsca/codegen/templates/mult_diff_ldr.c index 3dd445e..ae74053 100644 --- a/pyecsca/codegen/templates/mult_diff_ldr.c +++ b/pyecsca/codegen/templates/mult_diff_ldr.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +void scalar_mult_inner(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 %} @@ -29,5 +26,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_set(p0, out); point_free(p0); point_free(p1); - {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_ldr.c b/pyecsca/codegen/templates/mult_ldr.c index b51f3fa..06d1472 100644 --- a/pyecsca/codegen/templates/mult_ldr.c +++ b/pyecsca/codegen/templates/mult_ldr.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { {%- if scalarmult.complete %} point_t *p0 = point_copy(curve->neutral); point_t *p1 = point_copy(point); @@ -30,5 +27,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_set(p0, out); point_free(p0); point_free(p1); - {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_ltr.c b/pyecsca/codegen/templates/mult_ltr.c index 187b536..f8bee19 100644 --- a/pyecsca/codegen/templates/mult_ltr.c +++ b/pyecsca/codegen/templates/mult_ltr.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { {%- if scalarmult.complete %} point_t *q = point_copy(point); point_t *r = point_copy(curve->neutral); @@ -39,5 +36,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { {%- if scalarmult.always %} point_free(dummy); {%- endif %} - {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_rtl.c b/pyecsca/codegen/templates/mult_rtl.c index acddf45..9db12fb 100644 --- a/pyecsca/codegen/templates/mult_rtl.c +++ b/pyecsca/codegen/templates/mult_rtl.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +void scalar_mult_inner(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); @@ -37,5 +34,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { {%- if scalarmult.always %} point_free(dummy); {%- endif %} - {{ end_action("mult") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/mult_simple_ldr.c b/pyecsca/codegen/templates/mult_simple_ldr.c index 8db5b41..c393290 100644 --- a/pyecsca/codegen/templates/mult_simple_ldr.c +++ b/pyecsca/codegen/templates/mult_simple_ldr.c @@ -1,10 +1,7 @@ #include "mult.h" #include "point.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") }} +void scalar_mult_inner(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 %} @@ -29,5 +26,4 @@ void scalar_mult(bn_t *scalar, point_t *point, curve_t *curve, point_t *out) { point_set(p0, out); point_free(p0); point_free(p1); - {{ end_action("mult") }} }
\ No newline at end of file |
