From: couturie Date: Mon, 22 Oct 2018 19:11:04 +0000 (+0200) Subject: GROS BUG PRGA !!!!!!!!!!!!!!!!!!!!!!!!! A CORRIGER PARTOUT !!!!!!!!! X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/8ecaf9b70f89bea2b5f99256ea91716eb438b4a9?ds=sidebyside GROS BUG PRGA !!!!!!!!!!!!!!!!!!!!!!!!! A CORRIGER PARTOUT !!!!!!!!! --- diff --git a/OneRoundIoT/EnhancedOneRound/Makefile b/OneRoundIoT/EnhancedOneRound/Makefile index 43e0b73..da280af 100644 --- a/OneRoundIoT/EnhancedOneRound/Makefile +++ b/OneRoundIoT/EnhancedOneRound/Makefile @@ -3,12 +3,12 @@ C=gcc uname_m := $(shell uname -m) ifeq ($(uname_m),armv7l) -CFLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -lrt `pkg-config --cflags --libs glib-2.0` +CFLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -lrt `pkg-config --cflags --libs glib-2.0` else ifeq ($(uname_m),armv6l) -CFLAGS=-O3 -march=armv6 -mfpu=vfp -mfloat-abi=hard -lrt `pkg-config --cflags --libs glib-2.0` +CFLAGS=-O3 -march=armv6 -mfpu=vfp -mfloat-abi=hard -lrt `pkg-config --cflags --libs glib-2.0` else -CFLAGS=-O3 `pkg-config --cflags --libs glib-2.0` +CFLAGS=-O3 `pkg-config --cflags --libs glib-2.0` endif endif diff --git a/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp b/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp index 954a127..37ecfaf 100644 --- a/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp +++ b/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp @@ -31,8 +31,10 @@ using namespace std; int key_size=256; int nb_test=1; +int cbcprng=0; int cbc=0; - +int ecb=0; +int ecbprng=0; @@ -61,87 +63,838 @@ double TimeStop(double 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; -} +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; +} + +ulong xorshift64(ulong t) +{ + /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */ + ulong x = t; + x ^= x >> 12; // a + x ^= x << 25; // b + x ^= x >> 27; // c + + + return x; +} + +__uint128_t g_lehmer64_state; + +inline uint64_t splitmix64_stateless(uint64_t index) { + uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15)); + z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9); + z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB); + return z ^ (z >> 31); +} + + +inline void lehmer64_seed(uint64_t seed) { + g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) + + splitmix64_stateless(seed + 1); +} + +inline uint64_t lehmer64() { + g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5); + ; + return g_lehmer64_state >> 64; +} + + + + + +void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) { + + for(int i=0;i +void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) { + + uchar X[h]; + uchar Y[h]; + uchar fX[h]; + uchar gY[h]; + uchar RM1[h]; + uchar RM2[h]; + uchar tmp[h]; + ulong *rm1=(ulong*)RM1; + ulong *rm2=(ulong*)RM2; + + for(int it=0;it>3);a++) { + myrand=lehmer64(); + rm1[a]=myrand; + myrand=lehmer64(); + rm2[a]=myrand; + } + + + + for(int a=0;a +void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, ulong myrand, int debug) { + + uchar invfX[h]; + uchar invgY[h]; + uchar fX[h]; + uchar gY[h]; + uchar RM1[h]; + uchar RM2[h]; + uchar tmp[h]; + ulong *rm1=(ulong*)RM1; + ulong *rm2=(ulong*)RM2; + + for(int it=0;it>3);a++) { + myrand=lehmer64(); + rm1[a]=myrand; + myrand=lehmer64(); + rm2[a]=myrand; + } + + + + for(int a=0;a +void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) { + + uchar X[h]; + uchar Y[h]; + uchar fX[h]; + uchar gY[h]; + uchar *RM1; + uchar *RM2; + + for(int it=0;it +void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) { + + uchar invfX[h]; + uchar invgY[h]; + uchar fX[h]; + uchar gY[h]; + uchar *RM1; + uchar *RM2; + + for(int it=0;it +void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) { + + uchar X[h]; + uchar Y[h]; + uchar fX[h]; + uchar gY[h]; + uchar IV1[h]; + uchar IV2[h]; + uchar RM1[h]; + uchar RM2[h]; + uchar tmp[h]; + ulong *rm1=(ulong*)RM1; + ulong *rm2=(ulong*)RM2; + + for(int it=0;it>3);a++) { + myrand=lehmer64(); + rm1[a]=myrand; + myrand=lehmer64(); + rm2[a]=myrand; + } + + + + for(int a=0;a +void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) { + + uchar invfX[h]; + uchar invgY[h]; + uchar fX[h]; + uchar gY[h]; + uchar IV1[h]; + uchar IV2[h]; + uchar RM1[h]; + uchar RM2[h]; + uchar tmp[h]; + ulong *rm1=(ulong*)RM1; + ulong *rm2=(ulong*)RM2; + + for(int it=0;it>3);a++) { + myrand=lehmer64(); + rm1[a]=myrand; + myrand=lehmer64(); + rm2[a]=myrand; + } + + for(int a=0;a -void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) { +void encrypt_cbc_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) { uchar X[h]; uchar Y[h]; uchar fX[h]; uchar gY[h]; + uchar IV1[h]; + uchar IV2[h]; uchar *RM1; uchar *RM2; - + uchar tmp[h]; + + for(int a=0;a -void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) { +void decrypt_cbc_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) { uchar invfX[h]; uchar invgY[h]; uchar fX[h]; uchar gY[h]; + uchar IV1[h]; + uchar IV2[h]; uchar *RM1; uchar *RM2; + uchar tmp[h]; + + for(int a=0;a void encrypt_cbc(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) { @@ -565,6 +1489,8 @@ void decrypt_cbc(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, i } +*/ + int main(int argc, char** argv) { @@ -578,18 +1504,23 @@ int main(int argc, char** argv) { for(int i=1; i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); if(cbc) - encrypt_cbc<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); - else + encrypt_cbc_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) encrypt_ecb<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } break; case 8: for(i=0;i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); if(cbc) - encrypt_cbc<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); - else + encrypt_cbc_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) encrypt_ecb<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } break; case 16: for(i=0;i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); if(cbc) - encrypt_cbc<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); - else + encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) encrypt_ecb<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } break; case 32: for(i=0;i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); if(cbc) - encrypt_cbc<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); - else + encrypt_cbc_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) encrypt_ecb<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } break; case 64: for(i=0;i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); if(cbc) - encrypt_cbc<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); - else + encrypt_cbc_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) encrypt_ecb<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } @@ -829,11 +1769,25 @@ int main(int argc, char** argv) { case 128: for(i=0;i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); if(cbc) - encrypt_cbc<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); - else + encrypt_cbc_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) encrypt_ecb<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + } + break; + case 256: + for(i=0;i(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(cbc) + encrypt_cbc_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + if(ecb) + encrypt_ecb<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + } break; } @@ -852,58 +1806,78 @@ int main(int argc, char** argv) { } - + lehmer64_seed(myrand); time_decrypt=0; t=TimeStart(); switch(h) { case 4: for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); if(cbc) - decrypt_cbc<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); - else + decrypt_cbc_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(ecb) decrypt_ecb<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 8: for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); if(cbc) - decrypt_cbc<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); - else + decrypt_cbc_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(ecb) decrypt_ecb<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 16: for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); if(cbc) - decrypt_cbc<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); - else + decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(ecb) decrypt_ecb<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 32: for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_cbc_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); else decrypt_ecb<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 64: for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); if(cbc) - decrypt_cbc<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); - else + decrypt_cbc_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(ecb) decrypt_ecb<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 128: for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); if(cbc) - decrypt_cbc<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); - else + decrypt_cbc_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(ecb) decrypt_ecb<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; + case 256: + for(i=0;i(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(cbc) + decrypt_cbc_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + if(ecb) + decrypt_ecb<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + } + break; } time_decrypt+=TimeStop(t); diff --git a/OneRoundIoT/OneRound/one_round_hash.cpp b/OneRoundIoT/OneRound/one_round_hash.cpp index 2688609..9733449 100644 --- a/OneRoundIoT/OneRound/one_round_hash.cpp +++ b/OneRoundIoT/OneRound/one_round_hash.cpp @@ -128,7 +128,7 @@ void prga(uchar *sc, int ldata, uchar *r) { uchar j0=0; for (int it=0; it