From d7b1b0a02049045042632ad2f2d86c6489c20cde Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Couturier?= Date: Sat, 29 Feb 2020 09:41:52 +0100 Subject: [PATCH 1/1] new --- OneRoundIoT/OneRound/rc4_hash2.cpp | 13 +++---- OneRoundIoT/OneRound/rc4_hash3.cpp | 59 ++++++++---------------------- 2 files changed, 20 insertions(+), 52 deletions(-) diff --git a/OneRoundIoT/OneRound/rc4_hash2.cpp b/OneRoundIoT/OneRound/rc4_hash2.cpp index 10f9823..386ddf7 100644 --- a/OneRoundIoT/OneRound/rc4_hash2.cpp +++ b/OneRoundIoT/OneRound/rc4_hash2.cpp @@ -168,9 +168,6 @@ 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; @@ -182,8 +179,6 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, uchar *S, int h) { for(int it=0;it>3; // Mix with dynamic RM @@ -192,7 +187,7 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, uchar *S, int h) { for(int a=0;a<(h>>3);a++) { rm[a]=rm[a]^ss[ind1+a]; - sum+=rm[a]; + sum^=rm[a]; } @@ -200,8 +195,8 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, uchar *S, int h) { rm[0]=xorshift64(sum); for(int a=1;a<(h>>3);a++) { - rm[a]^=xorshift64(rm[a-1]); - //rm[a]^=splitmix64(rm[a-1]); + rm[a]=xorshift64(rm[a-1]); + //rm[a]=splitmix64(rm[a-1]); } @@ -303,10 +298,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]); diff --git a/OneRoundIoT/OneRound/rc4_hash3.cpp b/OneRoundIoT/OneRound/rc4_hash3.cpp index 5c9061c..07269d0 100644 --- a/OneRoundIoT/OneRound/rc4_hash3.cpp +++ b/OneRoundIoT/OneRound/rc4_hash3.cpp @@ -146,15 +146,7 @@ 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) { uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15)); @@ -176,49 +168,26 @@ 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; + uint64_t *rm=(uint64_t*)RM1; + // uint64_t *xx=(uint64_t*)X; + uint64_t *ss=(uint64_t*)seq_in; - + int a; for(int it=0;it>3; // Mix with dynamic RM - uint64_t sum=0; - /* for(int a=0;a>3);a++) { + rm[a]=rm[a]^ss[ind1+a]; + rm[a]=xorshift64(rm[a] ^ rm[a-1]); + } + rm[0]=xorshift64(rm[a] ^ rm[0] ); } @@ -317,10 +286,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]); -- 2.39.5