From 8c3f50503153ecdea17d7b52812a4419c6dfbf0f Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 21 Feb 2023 10:33:36 +0100 Subject: Separate init and deinit from the main function. --- pyecsca/codegen/templates/main.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'pyecsca/codegen') diff --git a/pyecsca/codegen/templates/main.c b/pyecsca/codegen/templates/main.c index 2c1ce22..7854961 100644 --- a/pyecsca/codegen/templates/main.c +++ b/pyecsca/codegen/templates/main.c @@ -559,8 +559,8 @@ static uint8_t cmd_set_trigger(uint8_t *data, uint16_t len) { return 0; } -int main(void) { - // Initalize the platform, UART, triggers. +void init(void) { + // Initalize the platform, UART, triggers. platform_init(); init_uart(); trigger_setup(); @@ -574,6 +574,18 @@ int main(void) { curve = curve_new(); pubkey = point_new(); bn_init(&privkey); +} + +void deinit(void) { + // Clear up allocated stuff. + bn_clear(&privkey); + curve_free(curve); + point_free(pubkey); + formulas_clear(); +} + +int main(void) { + init(); // Add the SimpleSerial commands. simpleserial_init(); @@ -600,10 +612,6 @@ int main(void) { while(simpleserial_get()); //led_ok(0); - // Clear up allocated stuff. - bn_clear(&privkey); - curve_free(curve); - point_free(pubkey); - formulas_clear(); + deinit(); return 0; -} \ No newline at end of file +} -- cgit v1.3.1