From f153e394724a6d34b1532eafed901e6648ad1b59 Mon Sep 17 00:00:00 2001 From: couturie Date: Mon, 4 Sep 2017 20:44:59 +0200 Subject: [PATCH] new --- OneRoundIoT/OneRound/Makefile | 15 +- OneRoundIoT/OneRound/one_round_new.cpp | 3 +- OneRoundIoT/OneRound/one_round_par.cpp | 759 +++++++++++++++++++++++++ 3 files changed, 770 insertions(+), 7 deletions(-) create mode 100644 OneRoundIoT/OneRound/one_round_par.cpp diff --git a/OneRoundIoT/OneRound/Makefile b/OneRoundIoT/OneRound/Makefile index 8f7867c..9da9adc 100644 --- a/OneRoundIoT/OneRound/Makefile +++ b/OneRoundIoT/OneRound/Makefile @@ -13,16 +13,21 @@ endif endif -OBJ = pixmap_io.o one_round_new.o %.o: %.c $(C) -c -o $@ $< $(CFLAGS) -%.o: %.cpp +one_round_new.o: one_round_new.cpp $(CXX) -c -o $@ $< $(CFLAGS) -one_round_new: $(OBJ) - $(CXX) -o $@ $^ $(CFLAGS) +one_round_par.o: one_round_par.cpp + $(CXX) -fopenmp -c -o $@ $< $(CFLAGS) + +one_round_new: pixmap_io.o one_round_new.o + $(CXX) -o $@ $^ $(CFLAGS) + +one_round_par: pixmap_io.o one_round_par.o + $(CXX) -fopenmp -o $@ $^ $(CFLAGS) clean: - rm -rf $(OBJ) one_round_new + rm -rf *.o one_round_new diff --git a/OneRoundIoT/OneRound/one_round_new.cpp b/OneRoundIoT/OneRound/one_round_new.cpp index d64021d..9c58017 100644 --- a/OneRoundIoT/OneRound/one_round_new.cpp +++ b/OneRoundIoT/OneRound/one_round_new.cpp @@ -534,8 +534,7 @@ int main(int argc, char** argv) { for(int i=0;i +#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=0; + + + + + + + +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,int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, int enc, int num) { + + + uchar X[h2]; + uchar fX[h2*num]; + uchar RM2[h2*num]; + + + + + 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, int num) { + + +/* 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*num]; + uchar fX[h2*num]; + uchar RM2[h2*num]; +// unsigned int *lX=(unsigned int*)X; +// unsigned int *lseq_in=(unsigned int*)seq_in; + +#pragma omp parallel for + 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, int num) { + + + /*uchar *fX=new uchar[h2]; + uchar *Inv_Sbox1=new uchar[256]; + uchar *Inv_Sbox2=new uchar[256]; + */ + uchar fX[h2*num]; + uchar RM2[h2*num]; + +#pragma omp parallel for + for(int it=0;it(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1,num); + else + encrypt<4*4>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0,num); + + } + break; + case 8: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1,num); + else + encrypt<8*8>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0,num); + + } + break; + case 16: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1,num); + else + encrypt<16*16>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0,num); + + } + break; + case 32: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1,num); + else + encrypt<32*32>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0,num); + + } + break; + case 64: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1,num); + else + encrypt<64*64>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0,num); + + } + break; + case 128: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1,num); + else + encrypt<128*128>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,0,num); + + } + break; + } + time+=TimeStop(t); + cout<<"Time encrypt "<(seq2, seq,len,RM2,Pbox,PboxRM,Sbox1,Sbox2,0,num); + else + decrypt<4*4>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0,num); + } + break; + case 8: + for(i=0;i(seq2, seq,len,RM2,Pbox,PboxRM,Sbox1,Sbox2,0,num); + else + decrypt<8*8>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0,num); + } + break; + case 16: + for(i=0;i(seq2, seq,len,RM2,Pbox,PboxRM,Sbox1,Sbox2,0,num); + else + decrypt<16*16>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0,num); + } + break; + case 32: + for(i=0;i(seq2, seq,len,RM2,Pbox,PboxRM,Sbox1,Sbox2,0,num); + else + decrypt<32*32>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0,num); + } + break; + case 64: + for(i=0;i(seq2, seq,len,RM2,Pbox,PboxRM,Sbox1,Sbox2,0,num); + else + decrypt<64*64>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0,num); + } + break; + case 128: + for(i=0;i(seq2, seq,len,RM2,Pbox,PboxRM,Sbox1,Sbox2,0,num); + else + decrypt<128*128>(seq2,seq,len,RM2,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,0,num); + } + break; + + + } + + time+=TimeStop(t); + cout<<"Time decrypt "<