diff options
Diffstat (limited to 'pyecsca/codegen/templates')
| -rw-r--r-- | pyecsca/codegen/templates/action.c | 84 | ||||
| -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/main.c | 27 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_bnaf.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_coron.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_diff_ldr.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_ldr.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_ltr.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_rtl.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_simple_ldr.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/point.c | 6 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/rand.c | 16 |
18 files changed, 183 insertions, 6 deletions
diff --git a/pyecsca/codegen/templates/action.c b/pyecsca/codegen/templates/action.c new file mode 100644 index 0000000..258e599 --- /dev/null +++ b/pyecsca/codegen/templates/action.c @@ -0,0 +1,84 @@ +{% macro start_action(action) %} + {% if action == "add" %} + action_start((uint32_t) (1 << 0)); + {% elif action == "dadd" %} + action_start((uint32_t) (1 << 1)); + {% elif action == "dbl" %} + action_start((uint32_t) (1 << 2)); + {% elif action == "ladd" %} + action_start((uint32_t) (1 << 3)); + {% elif action == "neg" %} + action_start((uint32_t) (1 << 4)); + {% elif action == "scl" %} + action_start((uint32_t) (1 << 5)); + {% elif action == "tpl" %} + action_start((uint32_t) (1 << 6)); + {% elif action == "mult" %} + action_start((uint32_t) (1 << 7)); + {% elif action == "keygen" %} + action_start((uint32_t) (1 << 8)); + {% elif action == "ecdh" %} + action_start((uint32_t) (1 << 9)); + {% elif action == "ecdsa_sign" %} + action_start((uint32_t) (1 << 10)); + {% elif action == "ecdsa_verify" %} + action_start((uint32_t) (1 << 11)); + {% elif action == "coord_map" %} + action_start((uint32_t) (1 << 12)); + {% elif action == "random_mod" %} + action_start((uint32_t) (1 << 13)); + {% endif %} +{%- endmacro %} + +{% macro end_action(action) %} + {% if action == "add" %} + action_end((uint32_t) (1 << 0)); + {% elif action == "dadd" %} + action_end((uint32_t) (1 << 1)); + {% elif action == "dbl" %} + action_end((uint32_t) (1 << 2)); + {% elif action == "ladd" %} + action_end((uint32_t) (1 << 3)); + {% elif action == "neg" %} + action_end((uint32_t) (1 << 4)); + {% elif action == "scl" %} + action_end((uint32_t) (1 << 5)); + {% elif action == "tpl" %} + action_end((uint32_t) (1 << 6)); + {% elif action == "mult" %} + action_end((uint32_t) (1 << 7)); + {% elif action == "keygen" %} + action_end((uint32_t) (1 << 8)); + {% elif action == "ecdh" %} + action_end((uint32_t) (1 << 9)); + {% elif action == "ecdsa_sign" %} + action_end((uint32_t) (1 << 10)); + {% elif action == "ecdsa_verify" %} + action_end((uint32_t) (1 << 11)); + {% elif action == "coord_map" %} + action_end((uint32_t) (1 << 12)); + {% elif action == "random_mod" %} + action_end((uint32_t) (1 << 13)); + {% endif %} +{%- endmacro %} + +#include "hal/hal.h" +#include <stdint.h> + +uint32_t action_vector = 0; + +void action_start(uint32_t action) { + if (action_vector & action) { + trigger_high(); + } +} + +void action_end(uint32_t action) { + if (action_vector & action) { + trigger_low(); + } +} + +void action_set(uint32_t new_vector) { + action_vector = new_vector; +} diff --git a/pyecsca/codegen/templates/formula_add.c b/pyecsca/codegen/templates/formula_add.c index 0a04757..4b4ea88 100644 --- a/pyecsca/codegen/templates/formula_add.c +++ b/pyecsca/codegen/templates/formula_add.c @@ -1,11 +1,14 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, 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) { + {{ start_action("add") }} {%- if short_circuit %} if (point_equals(one, curve->neutral)) { point_set(other, out_one); @@ -18,4 +21,5 @@ void point_add(const point_t *one, const point_t *other, const curve_t *curve, p {%- endif %} {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("add") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/formula_dadd.c b/pyecsca/codegen/templates/formula_dadd.c index 0cdefe6..d409cce 100644 --- a/pyecsca/codegen/templates/formula_dadd.c +++ b/pyecsca/codegen/templates/formula_dadd.c @@ -1,12 +1,16 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, 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) { + {{ start_action("dadd") }} // TODO: short-circuits {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("dadd") }} } diff --git a/pyecsca/codegen/templates/formula_dbl.c b/pyecsca/codegen/templates/formula_dbl.c index 6410e7c..e70846e 100644 --- a/pyecsca/codegen/templates/formula_dbl.c +++ b/pyecsca/codegen/templates/formula_dbl.c @@ -1,11 +1,14 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, formula.shortname) }} {{ ops.render_static_clear(frees, formula.shortname) }} void point_dbl(const point_t *one, const curve_t *curve, point_t *out_one) { + {{ start_action("dbl") }} {%- if short_circuit %} if (point_equals(one, curve->neutral)) { point_set(one, out_one); @@ -14,4 +17,5 @@ void point_dbl(const point_t *one, const curve_t *curve, point_t *out_one) { {%- endif %} {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("dbl") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/formula_ladd.c b/pyecsca/codegen/templates/formula_ladd.c index 32903e9..1ac62ec 100644 --- a/pyecsca/codegen/templates/formula_ladd.c +++ b/pyecsca/codegen/templates/formula_ladd.c @@ -1,12 +1,16 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, 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) { + {{ start_action("ladd") }} // TODO: short-circuits {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("ladd") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/formula_neg.c b/pyecsca/codegen/templates/formula_neg.c index c728e70..39a4f5c 100644 --- a/pyecsca/codegen/templates/formula_neg.c +++ b/pyecsca/codegen/templates/formula_neg.c @@ -1,11 +1,14 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, formula.shortname) }} {{ ops.render_static_clear(frees, formula.shortname) }} void point_neg(const point_t *one, const curve_t *curve, point_t *out_one) { + {{ start_action("neg") }} {%- if short_circuit %} if (point_equals(one, curve->neutral)) { point_set(one, out_one); @@ -14,4 +17,5 @@ void point_neg(const point_t *one, const curve_t *curve, point_t *out_one) { {%- endif %} {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("neg") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/formula_scl.c b/pyecsca/codegen/templates/formula_scl.c index b49fa8a..cc46724 100644 --- a/pyecsca/codegen/templates/formula_scl.c +++ b/pyecsca/codegen/templates/formula_scl.c @@ -1,11 +1,14 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, formula.shortname) }} {{ ops.render_static_clear(frees, formula.shortname) }} void point_scl(const point_t *one, const curve_t *curve, point_t *out_one) { + {{ start_action("scl") }} {%- if short_circuit %} if (point_equals(one, curve->neutral)) { point_set(one, out_one); @@ -14,4 +17,5 @@ void point_scl(const point_t *one, const curve_t *curve, point_t *out_one) { {%- endif %} {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("scl") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/formula_tpl.c b/pyecsca/codegen/templates/formula_tpl.c index 73f34d2..b1863c2 100644 --- a/pyecsca/codegen/templates/formula_tpl.c +++ b/pyecsca/codegen/templates/formula_tpl.c @@ -1,11 +1,14 @@ #include "point.h" +#include "action.h" {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} {{ ops.render_static_init(allocations, initializations, formula.shortname) }} {{ ops.render_static_clear(frees, formula.shortname) }} void point_tpl(const point_t *one, const curve_t *curve, point_t *out_one) { + {{ start_action("tpl") }} {%- if short_circuit %} if (point_equals(one, curve->neutral)) { point_set(one, out_one); @@ -14,4 +17,5 @@ void point_tpl(const point_t *one, const curve_t *curve, point_t *out_one) { {%- endif %} {{ ops.render_ops(operations) }} {{ ops.render_returns(returns) }} + {{ end_action("tpl") }} }
\ No newline at end of file diff --git a/pyecsca/codegen/templates/main.c b/pyecsca/codegen/templates/main.c index d3616aa..9ca0c7b 100644 --- a/pyecsca/codegen/templates/main.c +++ b/pyecsca/codegen/templates/main.c @@ -10,11 +10,16 @@ #include "curve.h" #include "fat.h" #include "formulas.h" +#include "action.h" +#include "rand.h" + #include <stdlib.h> #include <stdint.h> #include <string.h> #include <stdbool.h> +{% from "action.c" import start_action, end_action %} + static point_t *pubkey; static bn_t privkey; @@ -106,7 +111,7 @@ static uint8_t cmd_set_params(uint8_t *data, uint16_t len) { static uint8_t cmd_generate(uint8_t *data, uint16_t len) { // generate a keypair, export privkey and affine pubkey - trigger_high(); + {{ start_action("keygen") }} bn_rand_mod(&privkey, &curve->n); size_t priv_size = bn_to_bin_size(&privkey); size_t coord_size = bn_to_bin_size(&curve->p); @@ -126,7 +131,7 @@ static uint8_t cmd_generate(uint8_t *data, uint16_t len) { bn_to_binpad(&y, pub + coord_size, coord_size); bn_clear(&x); bn_clear(&y); - trigger_low(); + {{ end_action("keygen") }} simpleserial_put('s', priv_size, priv); simpleserial_put('w', coord_size * 2, pub); @@ -189,7 +194,6 @@ static void parse_scalar_mult(const char *path, const uint8_t *data, size_t len, static uint8_t cmd_scalar_mult(uint8_t *data, uint16_t len) { // perform base point scalar mult with supplied scalar. - trigger_high(); bn_t scalar; bn_init(&scalar); parse_data(data, len, "", parse_scalar_mult, (void *) &scalar); size_t coord_size = bn_to_bin_size(&curve->p); @@ -204,7 +208,6 @@ static uint8_t cmd_scalar_mult(uint8_t *data, uint16_t len) { {%- endfor %} bn_clear(&scalar); point_free(result); - trigger_low(); simpleserial_put('w', coord_size * {{ curve_variables | length }}, res); return 0; @@ -228,7 +231,7 @@ static void parse_ecdh(const char *path, const uint8_t *data, size_t len, void * static uint8_t cmd_ecdh(uint8_t *data, uint16_t len) { //perform ECDH with provided point (and current privkey), output shared secret - trigger_high(); + {{ start_action("ecdh") }} point_t *other = point_new(); fat_t affine[2] = {fat_empty, fat_empty}; parse_data(data, len, "", parse_ecdh, (void *) affine); @@ -267,7 +270,7 @@ static uint8_t cmd_ecdh(uint8_t *data, uint16_t len) { bn_clear(&y); point_free(result); point_free(other); - trigger_low(); + {{ end_action("ecdh") }} simpleserial_put('r', h_size, h_out); return 0; @@ -295,6 +298,7 @@ static void parse_ecdsa_sig(const char *path, const uint8_t *data, size_t len, v static uint8_t cmd_ecdsa_sign(uint8_t *data, uint16_t len) { //perform ECDSA signature on supplied data, output signature + {{ start_action("ecdsa_sign") }} fat_t msg = fat_empty; parse_data(data, len, "", parse_ecdsa_msg, (void *) &msg); @@ -339,6 +343,7 @@ static uint8_t cmd_ecdsa_sign(uint8_t *data, uint16_t len) { size_t result_len = 0; uint8_t *result = asn1_der_encode(&r, &s, &result_len); + {{ end_action("ecdsa_sign") }} simpleserial_put('s', result_len, result); free(result); @@ -352,6 +357,7 @@ static uint8_t cmd_ecdsa_sign(uint8_t *data, uint16_t len) { static uint8_t cmd_ecdsa_verify(uint8_t *data, uint16_t len) { //perform ECDSA verification on supplied data and signature (and current pubkey), output status + {{ start_action("ecdsa_verify") }} fat_t msg = fat_empty; parse_data(data, len, "", parse_ecdsa_msg, (void *) &msg); fat_t sig = fat_empty; @@ -403,6 +409,7 @@ static uint8_t cmd_ecdsa_verify(uint8_t *data, uint16_t len) { bool result = bn_eq(&orig_r, &x); uint8_t res_data[1] = {(uint8_t) result}; + {{ end_action("ecdsa_verify") }} simpleserial_put('v', 1, res_data); point_free(p1); @@ -426,6 +433,13 @@ static uint8_t cmd_debug(uint8_t *data, uint16_t len) { return 0; } +static uint8_t cmd_set_trigger(uint8_t *data, uint16_t len) { + uint32_t vector = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; + action_set(vector); + + return 0; +} + int main(void) { platform_init(); init_uart(); @@ -454,6 +468,7 @@ int main(void) { simpleserial_addcmd('a', MAX_SS_LEN, cmd_ecdsa_sign); simpleserial_addcmd('r', MAX_SS_LEN, cmd_ecdsa_verify); {%- endif %} + simpleserial_addcmd('t', MAX_SS_LEN, cmd_set_trigger); simpleserial_addcmd('d', MAX_SS_LEN, cmd_debug); led_ok(1); diff --git a/pyecsca/codegen/templates/mult_bnaf.c b/pyecsca/codegen/templates/mult_bnaf.c index 9ede934..10a93fe 100644 --- a/pyecsca/codegen/templates/mult_bnaf.c +++ b/pyecsca/codegen/templates/mult_bnaf.c @@ -1,7 +1,10 @@ #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") }} point_t *neg = point_new(); point_neg(point, curve, neg); point_t *q = point_copy(curve->neutral); @@ -25,4 +28,5 @@ 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 d8e8a0d..a2b1085 100644 --- a/pyecsca/codegen/templates/mult_coron.c +++ b/pyecsca/codegen/templates/mult_coron.c @@ -1,7 +1,10 @@ #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") }} point_t *p0 = point_copy(point); point_t *p1 = point_new(); @@ -19,4 +22,5 @@ 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 2683116..3dd445e 100644 --- a/pyecsca/codegen/templates/mult_diff_ldr.c +++ b/pyecsca/codegen/templates/mult_diff_ldr.c @@ -1,7 +1,10 @@ #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") }} point_t *p0 = point_copy(&curve->neutral); point_t *p1 = point_copy(point); {%- if scalarmult.complete %} @@ -26,4 +29,5 @@ 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 c7c5246..b51f3fa 100644 --- a/pyecsca/codegen/templates/mult_ldr.c +++ b/pyecsca/codegen/templates/mult_ldr.c @@ -1,7 +1,10 @@ #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") }} {%- if scalarmult.complete %} point_t *p0 = point_copy(curve->neutral); point_t *p1 = point_copy(point); @@ -27,4 +30,5 @@ 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 5b08b80..187b536 100644 --- a/pyecsca/codegen/templates/mult_ltr.c +++ b/pyecsca/codegen/templates/mult_ltr.c @@ -1,7 +1,10 @@ #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") }} {%- if scalarmult.complete %} point_t *q = point_copy(point); point_t *r = point_copy(curve->neutral); @@ -36,4 +39,5 @@ 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 ba40a66..acddf45 100644 --- a/pyecsca/codegen/templates/mult_rtl.c +++ b/pyecsca/codegen/templates/mult_rtl.c @@ -1,7 +1,10 @@ #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") }} point_t *q = point_copy(point); point_t *r = point_copy(curve->neutral); @@ -34,4 +37,5 @@ 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 438a44b..8db5b41 100644 --- a/pyecsca/codegen/templates/mult_simple_ldr.c +++ b/pyecsca/codegen/templates/mult_simple_ldr.c @@ -1,7 +1,10 @@ #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") }} point_t *p0 = point_copy(&curve->neutral); point_t *p1 = point_copy(point); {%- if scalarmult.complete %} @@ -26,4 +29,5 @@ 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/point.c b/pyecsca/codegen/templates/point.c index a3c9f59..0096516 100644 --- a/pyecsca/codegen/templates/point.c +++ b/pyecsca/codegen/templates/point.c @@ -1,6 +1,8 @@ #include "point.h" +#include "action.h" #include <stdlib.h> {% import "ops.c" as ops %} +{% from "action.c" import start_action, end_action %} point_t *point_new(void) { point_t *result = malloc(sizeof(point_t)); @@ -75,6 +77,7 @@ bool point_equals_affine(const point_t *one, const point_t *other, const curve_t } void point_to_affine(const point_t *point, const curve_t *curve, bn_t *out_x, bn_t *out_y) { + {{ start_action("coord_map") }} {{ ops.render_all(allocations, initializations, operations, returns, frees, "err") }} if (err != BN_OKAY) { return; @@ -92,9 +95,11 @@ void point_to_affine(const point_t *point, const curve_t *curve, bn_t *out_x, bn {%- for free in to_affine_frees %} bn_clear(&{{ free }}); {%- endfor %} + {{ end_action("coord_map") }} } void point_from_affine(bn_t *x, bn_t *y, const curve_t *curve, point_t *out) { + {{ start_action("coord_map") }} {# XXX: This just works for the stuff currently in EFD. #} {%- for variable in variables %} {%- if variable in ("X", "Y") %} @@ -107,4 +112,5 @@ void point_from_affine(bn_t *x, bn_t *y, const curve_t *curve, point_t *out) { bn_mod_mul(x, y, &curve->p, &out->T); {%- endif %} {%- endfor %} + {{ end_action("coord_map") }} } diff --git a/pyecsca/codegen/templates/rand.c b/pyecsca/codegen/templates/rand.c new file mode 100644 index 0000000..e39c829 --- /dev/null +++ b/pyecsca/codegen/templates/rand.c @@ -0,0 +1,16 @@ +#include "bn/bn.h" +#include "action.h" +{% from "action.c" import start_action, end_action %} + +bn_err bn_rand_mod(bn_t *out, const bn_t *mod) { + {{ start_action("random_mod") }} + + #if MOD_RAND == MOD_RAND_SAMPLE + bn_err err = bn_rand_mod_sample(out, mod); + #elif MOD_RAND == MOD_RAND_REDUCE + bn_err err = bn_rand_mod_reduce(out, mod); + #endif + + {{ end_action("random_mod") }} + return err; +}
\ No newline at end of file |
