X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/f468314fbb129d22a901c316d2276d25923c9f47..aab4f66d038fc5892e7ff9fb280f8c6d0c858b66:/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp?ds=sidebyside diff --git a/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp b/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp index 22a7a90..b34f756 100644 --- a/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp +++ b/OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp @@ -73,18 +73,22 @@ uint xorshift32(const uint t) return x; } -ulong xorshift64(ulong t) + +ulong xorseed; + +ulong xorshift64() { /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */ - ulong x = t; + ulong x = xorseed; x ^= x >> 12; // a x ^= x << 25; // b x ^= x >> 27; // c - return x; + return xorseed=x; } +/* __uint128_t g_lehmer64_state; inline uint64_t splitmix64_stateless(uint64_t index) { @@ -106,7 +110,7 @@ inline uint64_t lehmer64() { return g_lehmer64_state >> 64; } - +*/ @@ -193,11 +197,13 @@ void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo uchar Y[h]; uchar fX[h]; uchar gY[h]; - uchar RM1[h]; - uchar RM2[h]; + uchar *RM1=&RM[0]; + uchar *RM2=&RM[h]; uchar tmp[h]; ulong *rm1=(ulong*)RM1; ulong *rm2=(ulong*)RM2; + + for(int it=0;it>3);a++) { - myrand=lehmer64(); + myrand=xorshift64(); rm1[a]=myrand; - myrand=lehmer64(); + myrand=xorshift64(); rm2[a]=myrand; } @@ -324,6 +330,7 @@ void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb uchar tmp[h]; ulong *rm1=(ulong*)RM1; ulong *rm2=(ulong*)RM2; + for(int it=0;it>3);a++) { - myrand=lehmer64(); + myrand=xorshift64(); rm1[a]=myrand; - myrand=lehmer64(); + myrand=xorshift64(); rm2[a]=myrand; } @@ -457,9 +464,9 @@ void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, for(int a=0;a<(h>>3);a++) { - myrand=lehmer64(); + myrand=xorshift64(); rm1[a]=myrand; - myrand=lehmer64(); + myrand=xorshift64(); rm2[a]=myrand; } @@ -583,9 +590,9 @@ void decrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox for(int a=0;a<(h>>3);a++) { - myrand=lehmer64(); + myrand=xorshift64(); rm1[a]=myrand; - myrand=lehmer64(); + myrand=xorshift64(); rm2[a]=myrand; } @@ -858,11 +865,14 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo uchar gY[h]; uchar IV1[h]; uchar IV2[h]; - uchar RM1[h]; - uchar RM2[h]; + uchar *RM1=&RM[0]; + uchar *RM2=&RM[h]; uchar tmp[h]; ulong *rm1=(ulong*)RM1; ulong *rm2=(ulong*)RM2; + + + for(int it=0;it>3);a++) { - myrand=lehmer64(); + myrand=xorshift64(); rm1[a]=myrand; - myrand=lehmer64(); + myrand=xorshift64(); rm2[a]=myrand; } @@ -1027,8 +1037,10 @@ void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb uchar gY[h]; uchar IV1[h]; uchar IV2[h]; - uchar RM1[h]; - uchar RM2[h]; + uchar *RM1=&RM[0]; + uchar *RM2=&RM[h]; +// uchar RM1[h]; +// uchar RM2[h]; uchar tmp[h]; ulong *rm1=(ulong*)RM1; ulong *rm2=(ulong*)RM2; @@ -1039,9 +1051,9 @@ void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb for(int a=0;a<(h>>3);a++) { - myrand=lehmer64(); + myrand=xorshift64(); rm1[a]=myrand; - myrand=lehmer64(); + myrand=xorshift64(); rm2[a]=myrand; } @@ -1958,8 +1970,8 @@ int main(int argc, char** argv) { inverse_tables(Sbox2,256,Inv_Sbox2); - - lehmer64_seed(myrand); + xorseed=myrand; +// lehmer64_seed(myrand); time_encrypt=0; t=TimeStart(); @@ -2074,8 +2086,9 @@ int main(int argc, char** argv) { store_RGB_pixmap("lena2.ppm", data_R, data_G, data_B, width, height); } - - lehmer64_seed(myrand); + + xorseed=myrand; + // lehmer64_seed(myrand); time_decrypt=0; t=TimeStart(); switch(h) {