From 9e250c72f9c70af3a3a7448e50c23a7ad0ea1bd5 Mon Sep 17 00:00:00 2001 From: couturie Date: Wed, 6 Sep 2017 14:04:26 +0200 Subject: [PATCH] new --- OneRoundIoT/OneRound/Makefile | 11 +- OneRoundIoT/OneRound/one_round_par.cpp | 2 + OneRoundIoT/OneRound/one_round_par2.cpp | 778 ++++++++++++++++++++++++ 3 files changed, 790 insertions(+), 1 deletion(-) create mode 100644 OneRoundIoT/OneRound/one_round_par2.cpp diff --git a/OneRoundIoT/OneRound/Makefile b/OneRoundIoT/OneRound/Makefile index 9da9adc..8f0c0cf 100644 --- a/OneRoundIoT/OneRound/Makefile +++ b/OneRoundIoT/OneRound/Makefile @@ -20,14 +20,23 @@ endif one_round_new.o: one_round_new.cpp $(CXX) -c -o $@ $< $(CFLAGS) + + one_round_par.o: one_round_par.cpp $(CXX) -fopenmp -c -o $@ $< $(CFLAGS) +one_round_par2.o: one_round_par2.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) + +one_round_par2: pixmap_io.o one_round_par2.o + $(CXX) -fopenmp -o $@ $^ $(CFLAGS) + clean: - rm -rf *.o one_round_new + rm -rf *.o one_round_new one_round_par one_round_par2 diff --git a/OneRoundIoT/OneRound/one_round_par.cpp b/OneRoundIoT/OneRound/one_round_par.cpp index bd23683..8519fe2 100644 --- a/OneRoundIoT/OneRound/one_round_par.cpp +++ b/OneRoundIoT/OneRound/one_round_par.cpp @@ -144,6 +144,7 @@ void rotate(uchar *RM1, uchar *RM2, int size, int n) } + template 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) { @@ -267,6 +268,7 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, in } + template void encrypt(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, int debug, int num) { diff --git a/OneRoundIoT/OneRound/one_round_par2.cpp b/OneRoundIoT/OneRound/one_round_par2.cpp new file mode 100644 index 0000000..e42a6d5 --- /dev/null +++ b/OneRoundIoT/OneRound/one_round_par2.cpp @@ -0,0 +1,778 @@ +//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 +#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]; + + + + + + 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 "<