aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/templates/formula_add.c
blob: 48bab07f2915a9aed267dee681a75071f4697066 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "point.h"
#include "action.h"
#include "hal/hal.h"
{% import "ops.c" as ops %}
{% from "action.c" import start_action, end_action %}

{{ ops.render_static_init(allocations, formula.shortname) }}

{{ ops.render_static_zero(allocations, formula.shortname) }}

{{ ops.render_static_clear(frees, formula.shortname) }}

__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 %}
		if (point_equals(one, curve->neutral)) {
			point_set(other, out_one);
			goto end;
		}
		if (point_equals(other, curve->neutral)) {
			point_set(one, out_one);
			goto end;
		}
	{%- endif %}
	{{ ops.render_initializations(initializations) }}
	{{ ops.render_ops(operations) }}
	{{ ops.render_returns(returns) }}
	//NOP_128();
end:
	{{ end_action("add") }}
}