diff --git a/Makefile b/Makefile index 9cef5d9..b86edbd 100644 --- a/Makefile +++ b/Makefile @@ -5,24 +5,24 @@ OJB = $(SRC:.c=.o) OUT = build CC = /usr/bin/gcc -CFLAGS = -ansi -Wall -fsanitize=address -std=c99 -O0 -CFDEBUG = -ansi -Wall -g -std=c99 +CFLAGS = -ansi -Wall -std=c99 -O0 +CFDEBUG = -ansi -Wall -fsanitize=address -g -std=c99 RM = /bin/rm -fr -TEST = -D TEST_TECH -PART = -D PART_ +TEST_F = -D TEST_TECH +TEST = -D TEST_ EVE = -D EVE_ %.o: %.c $(CC) -c $(CFLAGS) build: - $(CC) $(SRC) $(PART)$(part) $(EVE)$(eve) $(CFLAGS) -o $(OUT)/main.o + $(CC) $(SRC) $(TEST)$(test) $(EVE)$(eve) $(CFLAGS) -o $(OUT)/main.o build_test: - $(CC) $(SRC) $(CFLAGS) $(TEST) -o $(OUT)/main.o + $(CC) $(SRC) $(CFLAGS) $(TEST_F) -o $(OUT)/main.o debug: - $(CC) $(SRC) $(PART)$(part) $(CFDEBUG) -o $(OUT)/main.o + $(CC) $(SRC) $(TEST)$(test) $(CFDEBUG) -o $(OUT)/main.o clean: $(RM) $(OBJ) $(OUT)/main.o diff --git a/src/main.c b/src/main.c index c731bd7..814914a 100644 --- a/src/main.c +++ b/src/main.c @@ -45,27 +45,29 @@ main(int argc, char *argv[]) #ifdef TEST_TECH char *test = "yay"; printf("Testing char_arr_to_uint32 and uint32_to_char_arr: \n"); - printf("%s\n", uint32_to_char_arr(char_arr_to_uint32(test))); + char *res = uint32_to_char_arr(char_arr_to_uint32(test)); + printf("%s\n", ); + free(res); #endif printf("\n--- MSG ---\nas 0x: "); -#ifdef PART_ZERO +#ifdef TEST_ZERO msg = 0; printf("0x00000000\n"); #endif -#ifdef PART_MAX +#ifdef TEST_MAX msg = UINT32_MAX; printf("0xffffffff\n"); #endif -#ifdef PART_MID +#ifdef TEST_MID printf("0x0000ffff\n"); /* is UINT16_MAX, but keeping this way for corrector convenience */ msg = UINT32_MAX & UINT16_MAX; #endif -#ifdef PART_NAME +#ifdef TEST_NAME msg = *(uint32_t *)"bob"; printf("%u\n", msg); #endif @@ -83,10 +85,12 @@ main(int argc, char *argv[]) printf("--- VERIF ---\n%d\n", verif(key, msg, tag)); + printf("\n--- ALICE ---\n"); printf("sends msg: %u\nsends tag: %u\n", msg, tag); printf("knows key: %u\n", key); + printf("\n--- EVE ---\n"); printf("recieves msg: %u\nrecieves tag: %u\n", msg, tag); struct eve tmp = { msg, tag }; @@ -94,11 +98,14 @@ main(int argc, char *argv[]) msg = tmp.msg, tag = tmp.tag; printf("sends msg: %u\nsends tag: %u\n", msg, tag); + printf("\n--- BOB ---\n"); printf("recieves msg: %u\nrecieves tag: %u\n", msg, tag); printf("knows key: %u\n", key); + char res = verif(msg, tag, key); printf("verifies: %s\n", res ? "TRUE" : "FALSE"); + if (res) { msg_char = uint32_to_char_arr(msg); printf("msg as char *: %s\n", msg_char); @@ -160,11 +167,13 @@ char_arr_to_uint32(char *arr) static char * uint32_to_char_arr(uint32_t n) { - char *res = calloc(4, 1); + char *res = calloc(5, 1); res[0] = MID_BITS(n, 0, 8); res[1] = MID_BITS(n, 8, 16); res[2] = MID_BITS(n, 16, 24); res[3] = MID_BITS(n, 24, 32); + /* care for terminating nullbyte ! */ + res[4] = '\0'; return res; }