Commit b1f17f08 authored by yids's avatar yids

- added cleanup function

- some testing stuff
parent 3c9a3635
......@@ -3,11 +3,11 @@
CFILES=blink.c
OBJS=../libs/avrnacl/avrnacl_small/obj/randombytes.o ../libs/avrnacl/avrnacl_small/obj/libnacl.a
CFLAGS=-Os -g3 -pedantic -std=gnu99 -DARDUINO -I../libs/avrnacl/randombytes -I../libs/avrnacl/avrnacl_small/include
CFLAGS=-Os -ggdb3 -pedantic -std=gnu99 -DARDUINO -I../libs/avrnacl/randombytes -I../libs/avrnacl/avrnacl_small/include
OPTIMIZE = -O3
CC=avr-gcc
MCU=atmega328
MCU=atmega2560
F_CPU=F_CPU=16000000UL
AVRDUDE_PROGRAMMERID=stk200 /* Programmer ids are listed in /etc/avrdude.conf */
......@@ -25,13 +25,13 @@ upload:
avrdude -carduino -p atmega328p -P $(AVRDUDE_PORT) -b57600 -U flash:w:lib-test.hex
simulavr:
simulavr -G -d $(MCU) --file lib-test.elf &
simulavr -t -g -d $(MCU) --file lib-test.elf -W 0x20,- &
sleep 1
avr-gdb -se lib-test.elf --eval-command="target remote localhost:1212" --eval-command="load"
killall simulavr
simulavr-ddd:
simulavr -G -d $(MCU) --file lib-test.elf &
simulavr -g -d $(MCU) --file lib-test.elf &
sleep 1
ddd --debugger 'avr-gdb -se lib-test.elf --eval-command="target remote localhost:1212" --eval-command="load"'
killall simulavr
......
......@@ -11,6 +11,9 @@
#include <util/setbaud.h>
#include </usr/local/include/simavr/avr/avr_mcu_section.h>
#define special_output_port (*((volatile char *)0x20))
char tx_priv_key[crypto_box_SECRETKEYBYTES] = {0x23, 0x4D, 0x77, 0xFFFFFFF7, 0x09, 0x70, 0x46, 0xFFFFFF82, 0xFFFFFFC7, 0x0B, 0x70, 0x39, 0xFFFFFFDA, 0x24, 0x4A, 0xFFFFFF9C, 0x28, 0x7A, 0xFFFFFFD8, 0xFFFFFFCE, 0x7B, 0xFFFFFFEF, 0xFFFFFFFB, 0x75, 0x7E, 0x34, 0x16, 0xFFFFFF99, 0xFFFFFFF6, 0x60, 0x08, 0x0A };
char tx_comp_p[crypto_box_PUBLICKEYBYTES] = {0xFFFFFFC1, 0xFFFFFFEF, 0xFFFFFF89, 0xFFFFFFA8, 0x66, 0x44, 0xFFFFFFD6, 0x72, 0x26, 0xFFFFFF84, 0xFFFFFFA9, 0xFFFFFFF5, 0xFFFFFF9A, 0xFFFFFFFC, 0xFFFFFF88, 0x38, 0xFFFFFFA3, 0x1D, 0x71, 0x05, 0xFFFFFFB9, 0x0A, 0x0F, 0xFFFFFFF3, 0xFFFFFF93, 0xFFFFFFEF, 0x48, 0xFFFFFFA1, 0xFFFFFFB7, 0x49, 0xFFFFFF90, 0x6D};
......@@ -23,14 +26,20 @@ char clear_message[] = "dit is een test berichtje :) ";
struct pl_ctx * context;
void debug_puts(const char *str)
{
const char *c;
for(c = str; *c; c++)
special_output_port = *c;
}
int main(void)
{
uart_init();
uart_print("haaalloo");
// uart_init();
// uart_print("haaalloo");
debug_puts("start main\n");
struct pl_keypair *tx_kp;
struct pl_ctx *tx_ctx;
......@@ -49,9 +58,11 @@ int main(void)
memcpy(tx_ctx->receiver_public_key, rx_comp_p, crypto_box_PUBLICKEYBYTES);
memcpy(tx_ctx->msg->msg, clear_message, MSG_SIZE);
debug_puts("loaded msg\n");
pl_send_message(tx_ctx);
//debug_puts("processed msg\n");
//uart_print("set keys and proces msg\n");
// pl_send_message(tx_ctx);
// uart_print("set keys and proces msg\n");
//******** rx ***********/
......
......@@ -57,6 +57,8 @@ int main()
break;
}
write(STDOUT_FILENO,tx_ctx->msg, sizeof(struct pl_pagermessage)); // dump to stdout
pl_cleanup(tx_ctx);
free(pubkey);
////// RRRRXXXX /////////
return 0;
}
......@@ -117,7 +117,11 @@ inline int pl_send_message(struct pl_ctx *ctx) {
memset(temp_plain, '\0', crypto_box_ZEROBYTES);
memcpy(temp_plain + crypto_box_ZEROBYTES, ctx->msg->msg, PLAIN_MSG_SIZE);
//char nonce[crypto_box_NONCEBYTES];
#ifdef ARDUINO
memset(&ctx->msg->nonce, 0, crypto_box_NONCEBYTES); //FIXME this is for testing purposes and should be changed
#else
randombytes(ctx->msg->nonce, crypto_box_NONCEBYTES);
#endif
rc = crypto_box(temp_encrypted, temp_plain, crypto_box_ZEROBYTES + PLAIN_MSG_SIZE, ctx->msg->nonce, ctx->receiver_public_key, ctx->kp->secret_key);
if( rc != 0 )
return -1;
......@@ -518,4 +522,26 @@ int pl_inbox_display_all(struct pl_ctx *ctx)
}
}
pl_cleanup(struct pl_ctx *ctx)
{
#ifndef ARDUINO
struct list_kp * list_kp;
struct list_public_key * list_pk;
struct list_inbox * list_inbox;
printf("cleaning up...\n");
for(list_kp = ctx->keypairs; list_kp != NULL; list_kp = list_kp->next)
free(list_kp->kp);
for(list_pk = ctx->public_keys; list_pk != NULL; list_pk = list_pk->next)
free(list_pk->public_key);
for(list_inbox = ctx->inbox; list_inbox != NULL; list_inbox = list_inbox->next)
free(list_inbox->msg);
free(ctx->kp);
free(ctx->msg);
//free(ctx->receiver_public_key);
free(ctx->keypairs);
free(ctx->public_keys);
free(ctx->inbox);
free(ctx);
#endif
}
......@@ -119,7 +119,7 @@ int pl_inbox_display(struct pl_ctx *ctx);
int pl_inbox_next(struct pl_ctx *ctx);
int pl_inbox_prev(struct pl_ctx *ctx);
int pl_inbox_delete(struct pl_ctx *ctx);
pl_cleanup(struct pl_ctx *ctx);
int is_zero( const char *data, int len );
#ifdef __cplusplus
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment