From f1db4350eede84fe1dddead262a32becc1306fda Mon Sep 17 00:00:00 2001 From: couturie Date: Mon, 16 Apr 2018 16:54:21 +0200 Subject: [PATCH] first version of one_round_auth --- OneRoundIoT/OneRound/Makefile | 12 + OneRoundIoT/OneRound/one_round_auth.cpp | 802 ++++++++++++++++++++++++ OneRoundIoT/openssl/openssl_evp_gcm.c | 2 +- 3 files changed, 815 insertions(+), 1 deletion(-) create mode 100644 OneRoundIoT/OneRound/one_round_auth.cpp diff --git a/OneRoundIoT/OneRound/Makefile b/OneRoundIoT/OneRound/Makefile index a82d3fa..c3775dd 100644 --- a/OneRoundIoT/OneRound/Makefile +++ b/OneRoundIoT/OneRound/Makefile @@ -20,6 +20,12 @@ endif one_round_new.o: one_round_new.cpp $(CXX) -c -o $@ $< $(CFLAGS) +one_round_new3.o: one_round_new3.cpp + $(CXX) -c -o $@ $< $(CFLAGS) + +one_round_auth.o: one_round_auth.cpp + $(CXX) -c -o $@ $< $(CFLAGS) + one_round_hash.o: one_round_hash.cpp $(CXX) -c -o $@ $< $(CFLAGS) @@ -35,6 +41,9 @@ one_round_par2.o: one_round_par2.cpp one_round_new: pixmap_io.o one_round_new.o $(CXX) -o $@ $^ $(CFLAGS) +one_round_new3: pixmap_io.o one_round_new3.o + $(CXX) -o $@ $^ $(CFLAGS) + one_round_par2: pixmap_io.o one_round_par2.o $(CXX) -fopenmp -o $@ $^ $(CFLAGS) @@ -46,5 +55,8 @@ one_round_hash: pixmap_io.o one_round_hash.o one_round_hash_new: pixmap_io.o one_round_hash_new.o $(CXX) -o $@ $^ $(CFLAGS) +one_round_auth: pixmap_io.o one_round_auth.o + $(CXX) -o $@ $^ $(CFLAGS) + clean: rm -rf *.o one_round_new one_round_hash one_round_par2 one_round_hash_new diff --git a/OneRoundIoT/OneRound/one_round_auth.cpp b/OneRoundIoT/OneRound/one_round_auth.cpp new file mode 100644 index 0000000..9062cad --- /dev/null +++ b/OneRoundIoT/OneRound/one_round_auth.cpp @@ -0,0 +1,802 @@ +//gcc pixmap_io.c -c +//g++ -O3 one_round_new.cpp pixmap_io.o -o one_round_new -std=c++11 + +#include +#include +#include +#include +#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 encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,uchar *RM2,int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, int enc) { + + +// uchar *X=new uchar[h2]; +// uchar *fX=new uchar[h2]; + uchar X[h2]; + uchar fX[h2]; + uchar X2[h]; + uchar Y[h]; + uchar Z[h]; + + int ind1,ind2; + + + for(int a=0;a0;a--) { + Z[a-1]=Z[a]^Y[a]; + } + + + for(int a=0;a0;a--) { + Z[a-1]=Z[a]^Y[a]; + } + + + for(int a=0;a +void encrypt(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, int debug) { + + +/* uchar *X=new uchar[h2]; + uchar *fX=new uchar[h2]; + unsigned int *lX=(unsigned int*)X; + unsigned int *lseq_in=(unsigned int*)seq_in; +*/ + uchar X[h2]; + uchar fX[h2]; +// unsigned int *lX=(unsigned int*)X; +// unsigned int *lseq_in=(unsigned int*)seq_in; + + + for(int it=0;it +void decrypt(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, int *PboxRM, uchar *Inv_Sbox1, uchar *Inv_Sbox2, int debug) { + + + /*uchar *fX=new uchar[h2]; + uchar *Inv_Sbox1=new uchar[256]; + uchar *Inv_Sbox2=new uchar[256]; + */ + uchar fX[h2]; + + + + for(int it=0;it(seq, seq2,len,RM1,RM3,Pbox,PboxRM,Sbox1,Sbox2,1); + else + encrypt<4*4>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0); + + } + break; + case 8: + for(i=0;i(seq, seq2,len,RM1,RM3,Pbox,PboxRM,Sbox1,Sbox2,1); + else + encrypt<8*8>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0); + + } + break; + case 16: + for(i=0;i(seq, seq2,len,RM1,RM3,Pbox,PboxRM,Sbox1,Sbox2,1); + else + encrypt<16*16>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0); + + } + break; + case 32: + for(i=0;i(seq, seq2,len,RM1,RM3,Pbox,PboxRM,Sbox1,Sbox2,1); + else + encrypt<32*32>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0); + + } + break; + case 64: + for(i=0;i(seq, seq2,len,RM1,RM3,Pbox,PboxRM,Sbox1,Sbox2,1); + else + encrypt<64*64>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0); + + } + break; + case 128: + for(i=0;i(seq, seq2,len,RM1,RM3,Pbox,PboxRM,Sbox1,Sbox2,1); + else + encrypt<128*128>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,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) { + seq2[impb]++; + } + + if(tgpb>=0 && tgpb(seq2, seq,len,RM2,RM4,Pbox,PboxRM,Sbox1,Sbox2,0); + else + decrypt<4*4>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0); + } + break; + case 8: + for(i=0;i(seq2, seq,len,RM2,RM4,Pbox,PboxRM,Sbox1,Sbox2,0); + else + decrypt<8*8>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0); + } + break; + case 16: + for(i=0;i(seq2, seq,len,RM2,RM4,Pbox,PboxRM,Sbox1,Sbox2,0); + else + decrypt<16*16>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0); + } + break; + case 32: + for(i=0;i(seq2, seq,len,RM2,RM4,Pbox,PboxRM,Sbox1,Sbox2,0); + else + decrypt<32*32>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0); + } + break; + case 64: + for(i=0;i(seq2, seq,len,RM2,RM4,Pbox,PboxRM,Sbox1,Sbox2,0); + else + decrypt<64*64>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0); + } + break; + case 128: + for(i=0;i(seq2, seq,len,RM2,RM4,Pbox,PboxRM,Sbox1,Sbox2,0); + else + decrypt<128*128>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0); + } + break; + } + + time_decrypt+=TimeStop(t); + //cout<<"Time decrypt " + cout<<(double)imsize*nb_test/time_decrypt<<"\t"; + + + cout<<"\nTAG 2"<