From a192918e4a83ec711dd109921ebc9fdb39fa6512 Mon Sep 17 00:00:00 2001 From: couturie Date: Tue, 17 Apr 2018 15:02:39 +0200 Subject: [PATCH 1/1] old one round authentication --- Old_one_round/Makefile | 43 ++ Old_one_round/one_round_light_auth.cpp | 704 +++++++++++++++++++++++++ 2 files changed, 747 insertions(+) create mode 100644 Old_one_round/Makefile create mode 100644 Old_one_round/one_round_light_auth.cpp diff --git a/Old_one_round/Makefile b/Old_one_round/Makefile new file mode 100644 index 0000000..4049886 --- /dev/null +++ b/Old_one_round/Makefile @@ -0,0 +1,43 @@ +CXX=g++ +C=gcc + +uname_m := $(shell uname -m) +ifeq ($(uname_m),armv7l) +CFLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -lrt +else +ifeq ($(uname_m),armv6l) +CFLAGS=-O3 -march=armv6 -mfpu=vfp -mfloat-abi=hard -lrt +else +CFLAGS=-O3 +endif +endif + + + +%.o: %.c + $(C) -c -o $@ $< $(CFLAGS) + +one_round_light.o: one_round_light.cpp + $(CXX) -c -o $@ $< $(CFLAGS) + +one_round_light_v2.o: one_round_light_v2.cpp + $(CXX) -c -o $@ $< $(CFLAGS) + +one_round_light_auth.o: one_round_light_auth.cpp + $(CXX) -c -o $@ $< $(CFLAGS) + + + +one_round_light: pixmap_io.o one_round_light.o + $(CXX) -o $@ $^ $(CFLAGS) + +one_round_light_v2: pixmap_io.o one_round_light_v2.o + $(CXX) -o $@ $^ $(CFLAGS) + + +one_round_light_auth: pixmap_io.o one_round_light_auth.o + $(CXX) -fopenmp -o $@ $^ $(CFLAGS) + + +clean: + rm -rf *.o one_round_light one_round_light_v2 one_round_light_auth diff --git a/Old_one_round/one_round_light_auth.cpp b/Old_one_round/one_round_light_auth.cpp new file mode 100644 index 0000000..138efb6 --- /dev/null +++ b/Old_one_round/one_round_light_auth.cpp @@ -0,0 +1,704 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + + +extern "C" { + int load_RGB_pixmap(char *filename, int *width, int *height, unsigned char**R_data, unsigned char**G_data, unsigned char**B_data); + void store_RGB_pixmap(char *filename, unsigned char *R_data, unsigned char *G_data, unsigned char *B_data, int width, int height); +} + + +//using namespace CryptoPP; +using namespace std; + + +int key_size=256; +int nb_test=1; +int ctr=1; + + + + + + + +typedef unsigned char uchar; + + +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 inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) { + + for(int i=0;i +void myhash(uchar *X, uchar* RM2, uchar *Sbox2) { + uchar Y[h]; + uchar X2[h]; + + for(int k=0;k0;a-=4) { + RM2[a-1]=RM2[a]^Y[a]; + RM2[a-2]=RM2[a-1]^Y[a-1]; + RM2[a-3]=RM2[a-2]^Y[a-2]; + RM2[a-4]=RM2[a-3]^Y[a-3]; + } + } +} + + + + + + +template +void encrypt(uchar* seq,int len,uchar* RM1,uchar *RM2,uchar *RM3,int *Pbox, uchar *Sbox1, uchar *Sbox2, uchar *Sbox3, int debug) { + + + uchar X[h2]; + uchar Y[h2]; + uchar fX[h2]; + uchar gY[h2]; + + for(int it=0;it(X, RM3, Sbox3); + } + +} + + +template +void decrypt(uchar* seq,int len,uchar* RM1,uchar *RM2,uchar *RM3,int *Pbox, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uchar *Sbox3, int debug) { + + + uchar fX[h2]; + uchar gY[h2]; + uchar X[h2]; + + for(int it=0;it(X, RM3, Sbox3); + } + + + + + for(int it=len-1;it>=0;it--) { + int ind1=it*h2; + int ind2=Pbox[it]*h2; + + + + + + for(int a=0;a(seq,len,RM1,RM2,RM3,Pbox,Sbox1,Sbox2,Sbox3,0); + + } + break; + case 8: + for(i=0;i(seq, len,RM1,RM2,RM3,Pbox,Sbox1,Sbox2,Sbox3,0); + } + break; + case 16: + for(i=0;i(seq,len,RM1,RM2,RM3,Pbox,Sbox1,Sbox2,Sbox3,0); + } + break; + case 32: + for(i=0;i(seq,len,RM1,RM2,RM3,Pbox,Sbox1,Sbox2,Sbox3,0); + } + break; + case 64: + for(i=0;i(seq,len,RM1,RM2,RM3,Pbox,Sbox1,Sbox2,Sbox3,0); + } + break; + case 128: + for(i=0;i(seq,len,RM1,RM2,RM3,Pbox,Sbox1,Sbox2,Sbox3,0); + } + break; + } + + + + + time_encrypt+=TimeStop(t); + //cout<<"Time encrypt "<< + cout<<(double)imsize*nb_test/time_encrypt<<"\t"; + + + if(lena) { + for(int i=0;i=0) { + seq[impb]++; + } + + if(tgpb>=0 && tgpb(seq,len,RM1,RM2,RM4,Pbox,Inv_Sbox1,Inv_Sbox2,Sbox3,0); + } + break; + case 8: + for(i=0;i(seq,len,RM1,RM2,RM4,Pbox,Inv_Sbox1,Inv_Sbox2,Sbox3,0); + } + break; + case 16: + for(i=0;i(seq,len,RM1,RM2,RM4,Pbox,Inv_Sbox1,Inv_Sbox2,Sbox3,0); + } + break; + case 32: + for(i=0;i(seq,len,RM1,RM2,RM4,Pbox,Inv_Sbox1,Inv_Sbox2,Sbox3,0); + } + break; + case 64: + for(i=0;i(seq,len,RM1,RM2,RM4,Pbox,Inv_Sbox1,Inv_Sbox2,Sbox3,0); + } + break; + case 128: + for(i=0;i(seq,len,RM1,RM2,RM4,Pbox,Inv_Sbox1,Inv_Sbox2,Sbox3,0); + } + break; + } + + time_decrypt+=TimeStop(t); + //cout<<"Time decrypt " + cout<<(double)imsize*nb_test/time_decrypt<<"\t"; + + + cout<<"\nTAG 2"<