From: Raphaƫl Couturier Date: Fri, 28 Aug 2020 05:16:39 +0000 (+0200) Subject: new X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/149268e31dcc62cf18eddd1b8ffa37cf81acbbca?ds=inline;hp=43dcec640e3ca462625fe259f0b2bb5660ac8131 new --- diff --git a/OneRoundIoT/OneRound/Makefile b/OneRoundIoT/OneRound/Makefile index 250dc55..38b4eab 100644 --- a/OneRoundIoT/OneRound/Makefile +++ b/OneRoundIoT/OneRound/Makefile @@ -23,6 +23,10 @@ one_round_new.o: one_round_new.cpp one_round_new3.o: one_round_new3.cpp $(CXX) -c -o $@ $< $(CFLAGS) +one_round_new4.o: one_round_new4.cpp + $(CXX) -c -o $@ $< $(CFLAGS) + + one_round_steph.o: one_round_steph.cpp $(CXX) -c -o $@ $< $(CFLAGS) @@ -52,6 +56,9 @@ one_round_new: pixmap_io.o one_round_new.o one_round_new3: pixmap_io.o one_round_new3.o $(CXX) -o $@ $^ $(CFLAGS) +one_round_new4: pixmap_io.o one_round_new4.o + $(CXX) -o $@ $^ $(CFLAGS) + one_round_steph: pixmap_io.o one_round_steph.o $(CXX) -o $@ $^ $(CFLAGS) @@ -85,4 +92,4 @@ 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 rc4_hash rc4_hash2 rc4_hash3 one_round_steph + rm -rf *.o one_round_new one_round_new4 one_round_hash one_round_par2 one_round_hash_new rc4_hash rc4_hash2 rc4_hash3 one_round_steph diff --git a/OneRoundIoT/OneRound/one_round_hash_new3.cpp b/OneRoundIoT/OneRound/one_round_hash_new3.cpp index db0ea08..5e9bf8a 100644 --- a/OneRoundIoT/OneRound/one_round_hash_new3.cpp +++ b/OneRoundIoT/OneRound/one_round_hash_new3.cpp @@ -172,22 +172,6 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, int *Pbox,int *PboxRM, ucha } - /* for(int a=0;a +#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); +} + + + + +uint xorshift32(const uint t) +{ + /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */ + uint x = t; + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + return x; +} + +uint64_t xorshift64( const uint64_t state) +{ + uint64_t x = state; + x^= x << 13; + x^= x >> 7; + x^= x << 17; + return x; +} + + + + +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, uint64_t myrand,int enc) { + + + uchar X[h2]; + uchar fX[h2]; + + int ind1,ind2; + + + 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, uint64_t myrand, int debug) { + + uchar X[h2]; + + + for(int it=0;it +void decrypt(uchar* seq_in, uchar *seq_out, int len, uchar* RM1, int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint64_t myrand, int debug) { + + + + uchar X[h2]; + + + + for(int it=0;it>=8; + seq_out[ind2+a+1]=Inv_Sbox2[fX[a+1]]^(mm&255); + mm>>=8; + seq_out[ind2+a+2]=Inv_Sbox1[fX[a+2]]^(mm&255); + mm>>=8; + seq_out[ind2+a+3]=Inv_Sbox2[fX[a+3]]^(mm&255); + } + */ + + for(int a=0;a

(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,1); + else + encrypt<4*4>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + + } + break; + case 8: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,1); + else + encrypt<8*8>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + + } + break; + case 16: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,1); + else + encrypt<16*16>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + + } + break; + case 32: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,1); + else + encrypt<32*32>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + + } + break; + case 64: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,1); + else + encrypt<64*64>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + + } + break; + case 128: + for(i=0;i(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,1); + else + encrypt<128*128>(seq, seq2,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + + } + break; + } + time_encrypt+=TimeStop(t); + //cout<<"Time encrypt "<< + cout<<(double)imsize*nb_test/time_encrypt<<"\t"; + + + if(lena) { + for(int i=0;i(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + else + decrypt<4*4>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; + case 8: + for(i=0;i(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + else + decrypt<8*8>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; + case 16: + for(i=0;i(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + else + decrypt<16*16>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; + case 32: + for(i=0;i(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + else + decrypt<32*32>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; + case 64: + for(i=0;i(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + else + decrypt<64*64>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; + case 128: + for(i=0;i(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); + else + decrypt<128*128>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; + } + + time_decrypt+=TimeStop(t); + //cout<<"Time decrypt " + cout<<(double)imsize*nb_test/time_decrypt<<"\t"; + + if(lena) { + for(int i=0;i