X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/aab4f66d038fc5892e7ff9fb280f8c6d0c858b66..4bacb7dfd38d6c9831bd6f35a275ab6c5c815a14:/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp?ds=sidebyside diff --git a/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp b/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp index b34f756..e3b9858 100644 --- a/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp +++ b/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp @@ -38,7 +38,7 @@ int ecbprng=0; - +typedef __uint64_t mylong; typedef unsigned char uchar; @@ -74,12 +74,12 @@ uint xorshift32(const uint t) } -ulong xorseed; +mylong xorseed; -ulong xorshift64() +mylong xorshift64() { /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */ - ulong x = xorseed; + mylong x = xorseed; x ^= x >> 12; // a x ^= x << 25; // b x ^= x >> 27; // c @@ -191,7 +191,7 @@ void prga(uchar *sc, int ldata, uchar *r) { template -void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) { +void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, mylong myrand, int debug) { uchar X[h]; uchar Y[h]; @@ -200,8 +200,8 @@ void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo uchar *RM1=&RM[0]; uchar *RM2=&RM[h]; uchar tmp[h]; - ulong *rm1=(ulong*)RM1; - ulong *rm2=(ulong*)RM2; + mylong *rm1=(mylong*)RM1; + mylong *rm2=(mylong*)RM2; @@ -319,7 +319,7 @@ void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo template -void decrypt_ecb_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, ulong myrand, int debug) { +void decrypt_ecb_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, mylong myrand, int debug) { uchar invfX[h]; uchar invgY[h]; @@ -328,8 +328,8 @@ void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb uchar RM1[h]; uchar RM2[h]; uchar tmp[h]; - ulong *rm1=(ulong*)RM1; - ulong *rm2=(ulong*)RM2; + mylong *rm1=(mylong*)RM1; + mylong *rm2=(mylong*)RM2; for(int it=0;it -void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) { +void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *IV, int debug) { uchar X[h]; uchar Y[h]; uchar fX[h]; uchar gY[h]; - uchar RM1[h]; - uchar RM2[h]; + uchar IV1[h]; + uchar IV2[h]; + uchar *RM1; + uchar *RM2; uchar tmp[h]; - ulong *rm1=(ulong*)RM1; - ulong *rm2=(ulong*)RM2; + + + + for(int a=0;a>3);a++) { - myrand=xorshift64(); - rm1[a]=myrand; - myrand=xorshift64(); - rm2[a]=myrand; - } + RM1=&RM[PboxSRM[it]*h]; + RM2=&RM[h*h+PboxSRM[len/2-it]*h]; + for(int a=0;a -void decrypt_ecb_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, ulong myrand, int debug) { +void decrypt_ecb_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, uchar *IV, int debug) { uchar invfX[h]; uchar invgY[h]; uchar fX[h]; uchar gY[h]; - uchar RM1[h]; - uchar RM2[h]; + uchar IV1[h]; + uchar IV2[h]; + uchar *RM1; + uchar *RM2; uchar tmp[h]; - ulong *rm1=(ulong*)RM1; - ulong *rm2=(ulong*)RM2; + + + + for(int a=0;a>3);a++) { - myrand=xorshift64(); - rm1[a]=myrand; - myrand=xorshift64(); - rm2[a]=myrand; - } + RM1=&RM[PboxSRM[it]*h]; + RM2=&RM[h*h+PboxSRM[len/2-it]*h]; @@ -868,8 +903,8 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo uchar *RM1=&RM[0]; uchar *RM2=&RM[h]; uchar tmp[h]; - ulong *rm1=(ulong*)RM1; - ulong *rm2=(ulong*)RM2; + mylong *rm1=(mylong*)RM1; + mylong *rm2=(mylong*)RM2; @@ -1042,8 +1077,8 @@ void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb // uchar RM1[h]; // uchar RM2[h]; uchar tmp[h]; - ulong *rm1=(ulong*)RM1; - ulong *rm2=(ulong*)RM2; + mylong *rm1=(mylong*)RM1; + mylong *rm2=(mylong*)RM2; for(int it=0;it(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } @@ -1998,7 +2033,7 @@ int main(int argc, char** argv) { if(cbcrm) encrypt_cbc_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } @@ -2011,7 +2046,7 @@ int main(int argc, char** argv) { if(cbcrm) encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } @@ -2024,7 +2059,7 @@ int main(int argc, char** argv) { if(cbcrm) encrypt_cbc_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); } @@ -2037,7 +2072,7 @@ int main(int argc, char** argv) { if(cbcrm) encrypt_cbc_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); @@ -2051,7 +2086,7 @@ int main(int argc, char** argv) { if(cbcrm) encrypt_cbc_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); @@ -2065,7 +2100,7 @@ int main(int argc, char** argv) { if(cbcrm) encrypt_cbc_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbrm) - encrypt_ecb_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); + encrypt_ecb_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0); if(ecbprng) encrypt_ecb_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0); @@ -2099,7 +2134,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2111,7 +2146,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2123,7 +2158,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2135,7 +2170,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2147,7 +2182,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2159,7 +2194,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2171,7 +2206,7 @@ int main(int argc, char** argv) { if(cbcrm) decrypt_cbc_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbrm) - decrypt_ecb_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt_ecb_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0); if(ecbprng) decrypt_ecb_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } @@ -2202,6 +2237,5 @@ int main(int argc, char** argv) { } - return 0; }