X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/121b99635da1e62a424bea25d9d54fb0845cba43..2f7c730dc00e0060885091f4002d903a233c6db4:/OneRoundIoT/OneRound/rc4_hash3.cpp diff --git a/OneRoundIoT/OneRound/rc4_hash3.cpp b/OneRoundIoT/OneRound/rc4_hash3.cpp index 5c9061c..3cb1e07 100644 --- a/OneRoundIoT/OneRound/rc4_hash3.cpp +++ b/OneRoundIoT/OneRound/rc4_hash3.cpp @@ -138,7 +138,7 @@ void prga(uchar *sc, uchar *X, int ldata, uchar *r, int h) { inline uchar circ(uchar x,int n) {return (x << n) | (x >> (8 - n));} -uint64_t xorshift64( const uint64_t state) +inline static uint64_t xorshift64( const uint64_t state) { uint64_t x = state; x^= x << 13; @@ -146,17 +146,9 @@ uint64_t xorshift64( const uint64_t state) x^= x << 17; 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; -} -static inline uint64_t splitmix64(uint64_t index) { + +inline static uint64_t splitmix64(uint64_t index) { uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15)); z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9); z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB); @@ -171,54 +163,20 @@ static inline uint64_t splitmix64(uint64_t index) { //the proposed hash function, which is based on DSD structure. Sensitivity is ensured by employing the binary diffusion -void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, uchar *S, int h) { - - - // Goal: Calculate the hash value - // Output: RM (hash value) - -// uchar *X=new uchar[h2]; -// uchar *fX=new uchar[h2]; - uchar X[h]; - int ind1,ind2; - - - uint32_t *rm=(uint32_t*)RM1; - uint32_t *xx=(uint32_t*)X; - uint32_t *ss=(uint32_t*)seq_in; +void hash_DSD_BIN(uint64_t * ss, uint64_t* rm,int len,int h) { + int ind1=0; for(int it=0;it<len;it++) { - //ind1=Pbox[it]*h; - //ind2=Pbox[(it+len/2)]*h; - - ind1=it*h/4; - // Mix with dynamic RM - uint64_t sum=0; - /* for(int a=0;a<h;a+=4) { - X[a]=RM1[a]^seq_in[ind1+a]; - X[a+1]=RM1[a+1]^seq_in[ind1+a+1]; - X[a+2]=RM1[a+2]^seq_in[ind1+a+2]; - X[a+3]=RM1[a+3]^seq_in[ind1+a+3]; - } - */ - - - for(int a=0;a<h/4;a++) { - xx[a]=rm[a]^ss[ind1+a]; - sum+=xx[a]; - } - - - - - rm[0]=xorshift32(sum); - for(int a=1;a<h/4;a++) { - rm[a]^=xorshift32(rm[a-1]); - } - + rm[0]=rm[h-1]^ss[ind1]; + rm[0]=xorshift64(rm[0] ); + for(int a=1;a<h;a++) { + rm[a]=rm[a-1]^ss[ind1+a]; + rm[a]=xorshift64(rm[a]); + } + ind1+=h; } @@ -317,10 +275,12 @@ int main(int argc, char** argv) { if(change==1) { seq[4]++; + // seq[5]--; } if(change==2) { seq[9]++; + // seq[10]--; } printf("seq 4 %d\n",seq[4]); @@ -393,10 +353,15 @@ int main(int argc, char** argv) { time=0; + uint64_t *rm=(uint64_t*)RM1; + uint64_t *ss=(uint64_t*)seq; + + + t=TimeStart(); for(int i=0;i<nb_test;i++) { - hash_DSD_BIN(seq, RM1,len,Sbox1,h); + hash_DSD_BIN(ss, rm,len,h>>3); }