aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/templates
diff options
context:
space:
mode:
authorJ08nY2020-02-28 15:03:36 +0100
committerJ08nY2020-02-28 15:03:36 +0100
commitb387d00511a03dc20e15ac55fcbf07f3dfa79ce0 (patch)
tree6f7c7cb0168366b2862a6e42e20067652cbc443b /pyecsca/codegen/templates
parent4eafe2d49fc7406861609c5af12b850741bbe5a0 (diff)
downloadpyecsca-codegen-b387d00511a03dc20e15ac55fcbf07f3dfa79ce0.tar.gz
pyecsca-codegen-b387d00511a03dc20e15ac55fcbf07f3dfa79ce0.tar.zst
pyecsca-codegen-b387d00511a03dc20e15ac55fcbf07f3dfa79ce0.zip
Update libtommath, use multi init and clear.
Diffstat (limited to 'pyecsca/codegen/templates')
-rw-r--r--pyecsca/codegen/templates/ops.c31
-rw-r--r--pyecsca/codegen/templates/point.c5
2 files changed, 22 insertions, 14 deletions
diff --git a/pyecsca/codegen/templates/ops.c b/pyecsca/codegen/templates/ops.c
index 623c585..64a4ab4 100644
--- a/pyecsca/codegen/templates/ops.c
+++ b/pyecsca/codegen/templates/ops.c
@@ -1,7 +1,8 @@
-{% macro render_full_allocs(allocations) -%}
+{% macro render_full_allocs(allocations, err_name="err") -%}
{%- for alloc in allocations %}
- bn_t {{ alloc }}; bn_init(&{{ alloc }});
+ bn_t {{ alloc }};
{%- endfor %}
+ {{ err_name }} = bn_init_multi(&{{ allocations | join(", &") }}, NULL);
{%- endmacro %}
{% macro render_static_allocs(allocations) -%}
@@ -10,10 +11,8 @@
{%- endfor %}
{%- endmacro %}
-{% macro render_init_allocs(allocations) -%}
- {%- for alloc in allocations %}
- bn_init(&{{ alloc }});
- {%- endfor %}
+{% macro render_init_allocs(allocations, err_name="err") -%}
+ {{err_name}} = bn_init_multi(&{{ allocations | join(", &") }}, NULL);
{%- endmacro %}
{% macro render_initializations(initializations) -%}
@@ -35,17 +34,22 @@
{%- endmacro %}
{% macro render_frees(frees) -%}
- {%- for free in frees %}
- bn_clear(&{{ free }});
- {%- endfor %}
+ {% if frees %}
+ bn_clear_multi(&{{ frees | join(", &") }}, NULL);
+ {%- endif %}
{%- endmacro %}
{% macro render_static_init(allocations, initializations, name) -%}
{{ render_static_allocs(allocations) }}
- void point_{{ name }}_init(void) {
- {{ render_init_allocs(allocations) }}
+ bool point_{{ name }}_init(void) {
+ bn_err err;
+ {{ render_init_allocs(allocations, "err") }}
+ if (err != BN_OKAY) {
+ return false;
+ }
{{ render_initializations(initializations) }}
+ return true;
}
{%- endmacro %}
@@ -55,8 +59,9 @@
}
{%- endmacro %}
-{% macro render_all(allocations, initializations, operations, returns, frees) -%}
- {{ render_full_allocs(allocations) }}
+{% macro render_all(allocations, initializations, operations, returns, frees, err_name="err") -%}
+ bn_err {{err_name}};
+ {{ render_full_allocs(allocations, err_name) }}
{{ render_initializations(initializations) }}
{{ render_ops(operations) }}
{{ render_returns(returns) }}
diff --git a/pyecsca/codegen/templates/point.c b/pyecsca/codegen/templates/point.c
index aebb7c7..a3c9f59 100644
--- a/pyecsca/codegen/templates/point.c
+++ b/pyecsca/codegen/templates/point.c
@@ -75,7 +75,10 @@ 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) {
- {{ ops.render_all(allocations, initializations, operations, returns, frees) }}
+ {{ ops.render_all(allocations, initializations, operations, returns, frees, "err") }}
+ if (err != BN_OKAY) {
+ return;
+ }
{%- if "x" in allocations %}
if (out_x) {
bn_copy(&x, out_x);