]> AND Private Git Repository - Cipher_code.git/blobdiff - OneRoundIoT/OneRound/one_round_hash_new.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
GROS BUG PRGA !!!!!!!!!!!!!!!!!!!!!!!!! A CORRIGER PARTOUT !!!!!!!!!
[Cipher_code.git] / OneRoundIoT / OneRound / one_round_hash_new.cpp
index a76f70a4034be7dfea44559ff104c03deff2c553..84e1ee61e2481d75aa9ce332299a3325838f0a84 100644 (file)
@@ -135,7 +135,7 @@ void prga(uchar *sc, int ldata, uchar *r) {
   }
 }
 
-
+inline uchar  circ(uchar x,int n) {return (x << n) | (x >> (8 - n));}
 
 
 //the proposed hash function, which is based on DSD structure. Sensitivity is ensured by employing the binary diffusion
@@ -168,50 +168,68 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, int *PboxRM, uchar *Sbox1,
       X[a+3]=RM1[a+3]^seq_in[ind2+a+3];
     }
 
-/*    Y[0]=Sbox1[X[0]^X[h-1]];
-    for(int a=1;a<h;a++) {
-      Y[a]=Sbox1[Y[a-1]^X[a-1]];
-    }
 
-    Z[h-1]=Sbox2[Y[h-1]^Y[0]];
-    for(int a=h-1;a>0;a--) {
-      Z[a-1]=Sbox2[Z[a]^Y[a]];
-    }
-*/
 
     Y[0]=X[0]^X[h-1];
-    for(int a=1;a<h;a++) {
+    Y[1]=Y[0]^X[0];
+    Y[2]=Y[1]^X[1];
+    Y[3]=Y[2]^X[2];
+    for(int a=4;a<h;a+=4) {
       Y[a]=Y[a-1]^X[a-1];
+      Y[a+1]=Y[a]^X[a];
+      Y[a+2]=Y[a+1]^X[a+1];
+      Y[a+3]=Y[a+2]^X[a+2];
     }
 
     for(int a=0;a<h;a+=4) {
       Y[a]=Sbox1[Y[a]];
+      Y[a+1]=Sbox1[Y[a+1]];
+      Y[a+2]=Sbox1[Y[a+2]];
+      Y[a+3]=Sbox1[Y[a+3]];
     }
-    
-    Z[h-1]=Y[h-1]^Y[0];
-    for(int a=h-1;a>0;a--) {
-      Z[a-1]=Z[a]^Y[a];
-    }
+  
 
-    for(int a=0;a<h;a+=4) {
-      Z[a]=Sbox2[Z[a]];
+    RM1[h-1]=Y[h-1]^Y[0];
+    RM1[h-2]=RM1[h-1]^Y[h-1];
+    RM1[h-3]=RM1[h-2]^Y[h-2];
+    RM1[h-4]=RM1[h-3]^Y[h-3];
+    for(int a=h-4;a>0;a-=4) {
+      RM1[a-1]=RM1[a]^Y[a];
+      RM1[a-2]=RM1[a-1]^Y[a-1];
+      RM1[a-3]=RM1[a-2]^Y[a-2];
+      RM1[a-4]=RM1[a-3]^Y[a-3];
     }
+    
 
     
+    // Z[h-1]=Y[h-1]^Y[0];
+    // Z[h-2]=Z[h-1]^Y[h-1];
+    // for(int a=h-2;a>0;a-=2) {
+    //   Z[a-1]=Z[a]^Y[a];
+    //   Z[a-2]=Z[a-1]^Y[a-1];
+    // }
     
-    for(int a=0;a<h;a+=4) {
-      /*     RM1[a]=Z[a];
-      RM1[a+1]=Z[a+1];
-      RM1[a+2]=Z[a+2];
-      RM1[a+3]=Z[a+3];
-      */
-
-      RM1[a]=Z[a]^RM1[PboxRM[a]];
-      RM1[a+1]=Z[a+1]^RM1[PboxRM[a+1]];
-      RM1[a+2]=Z[a+2]^RM1[PboxRM[a+2]];
-      RM1[a+3]=Z[a+3]^RM1[PboxRM[a+3]];
+    // /*
+    // Z[h-1]=Y[h-1]^Y[0];
+    // Z[h-2]=Z[h-1]^Y[h-1];
+    // Z[h-3]=Z[h-2]^Y[h-2];
+    // Z[h-4]=Z[h-3]^Y[h-3];
+    // for(int a=h-4;a>0;a-=4) {
+    //   Z[a-1]=Z[a]^Y[a];
+    //   Z[a]=Z[a+1]^Y[a+1];
+    //   Z[a+1]=Z[a+2]^Y[a+2];
+    //   Z[a+2]=Z[a+3]^Y[a+3];
+    // }
+    // */
+    
+    // for(int a=0;a<h;a+=4) {
+    //   RM1[a]=Z[a];
+    //   RM1[a+1]=Z[a+1];
+    //   RM1[a+2]=Z[a+2];
+    //   RM1[a+3]=Z[a+3];
       
-    }
+
+    // }
     
   }
 
@@ -410,7 +428,7 @@ int main(int argc, char** argv) {
   
   time+=TimeStop(t);
   cout<<"Hash Time  "<<time<<endl;
-
+  cout<<(double)imsize*nb_test/time<<"\t";
 
   for(int i=0;i<h;i++){
     cout<<(int)RM1[i]<<" ";