From 8e00adae426382415bedd563ac3aa284cf78a4ae Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Tue, 4 Dec 2018 14:24:52 +0100 Subject: [PATCH] initialize hmac computations --- client/Makefile | 7 +++++-- client/d4.c | 8 +++++++- client/d4.h | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/client/Makefile b/client/Makefile index 1428026..c42a097 100644 --- a/client/Makefile +++ b/client/Makefile @@ -1,2 +1,5 @@ -d4: d4.c - gcc -Wall -o d4 d4.c -luuid +d4: d4.o others/hmac/sha2.o others/hmac/hmac.o + gcc -Wall -o d4 d4.o others/hmac/hmac.o others/hmac/sha2.o -luuid + +d4.o: d4.c + gcc -Wall -c d4.c diff --git a/client/d4.c b/client/d4.c index 588689a..66256f8 100644 --- a/client/d4.c +++ b/client/d4.c @@ -143,6 +143,12 @@ void d4_prepare_header(d4_t* d4) } // If UUID cannot be parsed it is set to 0 d4->header.type = atoi(d4->conf[TYPE]); + + d4->ctx = calloc(sizeof(hmac_sha256_ctx),1); + if (d4->ctx) { + //FIXME check cast of the key + hmac_sha256_init(d4->ctx, (uint8_t*)d4->conf[KEY], strlen(d4->conf[KEY])); + } } void d4_update_header(d4_t* d4, ssize_t nread) { @@ -150,7 +156,6 @@ void d4_update_header(d4_t* d4, ssize_t nread) { bzero(&tv,sizeof(struct timeval)); gettimeofday(&tv,NULL); d4->header.timestamp = tv.tv_sec; - //TODO hmac d4->header.size=nread; } @@ -172,6 +177,7 @@ void d4_transfert(d4_t* d4) nread = read(d4->source.fd, buf, d4->snaplen); if ( nread > 0 ) { d4_update_header(d4, nread); + //TODO hmac header and payload write(d4->destination.fd, &d4->header, sizeof(d4->header)); write(d4->destination.fd,buf,nread); } else{ diff --git a/client/d4.h b/client/d4.h index 756b600..2baba17 100644 --- a/client/d4.h +++ b/client/d4.h @@ -1,6 +1,8 @@ #ifndef D4_H #define D4_H +#include "others/hmac/hmac_sha2.h" + #define ND4PARAMS 7 #define NERRORS 100 #define SZCONFVALUE 1024 @@ -49,6 +51,7 @@ typedef struct d4_s { char errors[NERRORS][SZERRVALUE]; int err_idx; d4_header_t header; + hmac_sha256_ctx *ctx; } d4_t;