From 493692c718afc65e4ab01b078bb6368235220599 Mon Sep 17 00:00:00 2001 From: couturier Date: Wed, 3 Nov 2021 21:34:07 +0100 Subject: [PATCH] new --- OneRoundIoT/openssl/Makefile | 4 + .../openssl/openssl_evp_chacha20_poly1305.c | 371 ++++++++++++++++++ 2 files changed, 375 insertions(+) create mode 100755 OneRoundIoT/openssl/openssl_evp_chacha20_poly1305.c diff --git a/OneRoundIoT/openssl/Makefile b/OneRoundIoT/openssl/Makefile index b88f1c9..150f06a 100644 --- a/OneRoundIoT/openssl/Makefile +++ b/OneRoundIoT/openssl/Makefile @@ -7,6 +7,7 @@ OBJ4 = pixmap_io.o aesccm.o OBJ5 = pixmap_io.o openssl_evp_gcm.o OBJ6 = pixmap_io.o openssl_evp_hmac.o OBJ7 = pixmap_io.o openssl_evp_ocb.o +OBJ8 = pixmap_io.o openssl_chacha20_poly1305.o openssl_evp: $(OBJ) $(C) -o $@ $^ $(CFLAGS) @@ -30,6 +31,9 @@ openssl_evp_hmac: $(OBJ6) openssl_evp_ocb: $(OBJ7) $(C) -o $@ $^ $(CFLAGS) +openssl_evp_chacha20_poly1305: $(OBJ7) + $(C) -o $@ $^ $(CFLAGS) + %.o: %.c $(C) -c -o $@ $< -O3 diff --git a/OneRoundIoT/openssl/openssl_evp_chacha20_poly1305.c b/OneRoundIoT/openssl/openssl_evp_chacha20_poly1305.c new file mode 100755 index 0000000..dbe0bc3 --- /dev/null +++ b/OneRoundIoT/openssl/openssl_evp_chacha20_poly1305.c @@ -0,0 +1,371 @@ +//gcc pixmap_io.c -c +//gcc openssl_evp.c pixmap_io.o -o openssl_evp -I /usr/include/openssl/ -lcrypto -O3 -std=c99 + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "pixmap_io.h" + +typedef unsigned char uchar; + +int nb_test=1; +int ctr=0; + +double TimeStart() +{ + struct timeval tstart; + gettimeofday(&tstart,0); + return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) ); +} + +double TimeStop(double t) +{ + struct timeval tend; + + gettimeofday(&tend,0); + t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t; + return (t); +} + + +void printBytes(unsigned char *buf, size_t len) { + for(int i=0; i ecb + if(ctr) { + if(1 != EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, key, iv)) + handleErrors(); + } + else + if(1 != EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, key, iv)) + handleErrors(); + + /* Provide the message to be decrypted, and obtain the plaintext output. + * EVP_DecryptUpdate can be called multiple times if necessary + */ + +/* static double time=0; + double t=0; + t=TimeStart(); +*/ + for(int i=0;i