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

Private GIT Repository
update makefile
[Cipher_code.git] / OneRoundIoT / OneRound / one_round_auth.cpp
index c47f54648010c0188bfc88e99463ab403310c3c9..9c137ed092b286dd3998ca3cf6e8afc6795b11bc 100644 (file)
@@ -133,6 +133,55 @@ void prga(uchar *sc, int ldata, uchar *r) {
 }
 
 
+template<int h>
+void myhash(uchar *X, uchar* RM2, uchar *Sbox2) {
+  uchar Y[h];
+  uchar X2[h];
+
+  for(int k=0;k<h;k++) {
+    
+      
+    for(int a=0;a<h;a+=4) {
+      X2[a]=RM2[a]^X[k*h+a];
+      X2[a+1]=RM2[a+1]^X[k*h+a+1];
+      X2[a+2]=RM2[a+2]^X[k*h+a+2];
+      X2[a+3]=RM2[a+3]^X[k*h+a+3];
+    }
+
+
+    Y[0]=X2[0]^X2[h-1];
+    Y[1]=Y[0]^X2[0];
+    Y[2]=Y[1]^X2[1];
+    Y[3]=Y[2]^X2[2];
+    for(int a=4;a<h;a+=4) {
+      Y[a]=Y[a-1]^X2[a-1];
+      Y[a+1]=Y[a]^X2[a];
+      Y[a+2]=Y[a+1]^X2[a+1];
+      Y[a+3]=Y[a+2]^X2[a+2];
+    }
+    
+    
+    for(int a=0;a<h;a+=4) {
+      Y[a]=Sbox2[Y[a]];
+      Y[a+1]=Sbox2[Y[a+1]];
+      Y[a+2]=Sbox2[Y[a+2]];
+      Y[a+3]=Sbox2[Y[a+3]];
+    }
+    
+    
+    
+    RM2[h-1]=Y[h-1]^Y[0];
+    RM2[h-2]=RM2[h-1]^Y[h-1];
+    RM2[h-3]=RM2[h-2]^Y[h-2];
+    RM2[h-4]=RM2[h-3]^Y[h-3];
+    for(int a=h-4;a>0;a-=4) {
+      RM2[a-1]=RM2[a]^Y[a];
+      RM2[a-2]=RM2[a-1]^Y[a-1];
+      RM2[a-3]=RM2[a-2]^Y[a-2];
+      RM2[a-4]=RM2[a-3]^Y[a-3];
+    }
+  }
+}
 
 
 template<int h2, int h>
@@ -191,48 +240,7 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,uchar *RM2,in
     }
 
     if(!enc) {
-
-      for(int k=0;k<h;k++) {
-
-      
-       for(int a=0;a<h;a+=4) {
-         X2[a]=RM2[a]^seq_in[ind2+k*h+a];
-         X2[a+1]=RM2[a+1]^seq_in[ind2+k*h+a+1];
-         X2[a+2]=RM2[a+2]^seq_in[ind2+k*h+a+2];
-         X2[a+3]=RM2[a+3]^seq_in[ind2+k*h+a+3];
-       }
-       
-       Y[0]=X[0]^X[h-1];
-       for(int a=1;a<h;a++) {
-         Y[a]=Y[a-1]^X2[a-1];
-       }
-       
-       for(int a=0;a<h;a+=4) {
-         Y[a]=Sbox2[Y[a]];
-         Y[a+1]=Sbox2[Y[a+1]];
-         Y[a+2]=Sbox2[Y[a+2]];
-         Y[a+3]=Sbox2[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) {
-         RM2[a]=Z[a];
-         RM2[a+1]=Z[a+1];
-         RM2[a+2]=Z[a+2];
-         RM2[a+3]=Z[a+3];
-       }
-       
-      }
-
+      myhash<h>(&seq_in[ind2], RM2, Sbox2);
     }
 
 
@@ -248,47 +256,7 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,uchar *RM2,in
     }
 
     if(enc) {
-
-      for(int k=0;k<h;k++) {
-
-      
-       for(int a=0;a<h;a+=4) {
-         X2[a]=RM2[a]^fX[k*h+a];
-         X2[a+1]=RM2[a+1]^fX[k*h+a+1];
-         X2[a+2]=RM2[a+2]^fX[k*h+a+2];
-         X2[a+3]=RM2[a+3]^fX[k*h+a+3];
-       }
-       
-       Y[0]=X[0]^X[h-1];
-       for(int a=1;a<h;a++) {
-         Y[a]=Y[a-1]^X2[a-1];
-       }
-       
-       for(int a=0;a<h;a+=4) {
-         Y[a]=Sbox2[Y[a]];
-         Y[a+1]=Sbox2[Y[a+1]];
-         Y[a+2]=Sbox2[Y[a+2]];
-         Y[a+3]=Sbox2[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) {
-         RM2[a]=Z[a];
-         RM2[a+1]=Z[a+1];
-         RM2[a+2]=Z[a+2];
-         RM2[a+3]=Z[a+3];
-       }
-      }
-
+      myhash<h>(fX, RM2, Sbox2);
     }
       
     for(int a=0;a<h2;a+=4) {
@@ -298,6 +266,7 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,uchar *RM2,in
       RM1[a+3]=RM1[PboxRM[a+3]];
     }
   }
+      
 }
 
 
@@ -457,7 +426,7 @@ int main(int argc, char** argv) {
   
 
       
-  int seed=time(NULL);
+  int seed=12;//time(NULL);
 //  cout<<seed<<endl;
   srand48(seed);
 
@@ -594,7 +563,9 @@ int main(int argc, char** argv) {
 
 
 
-
+  for(int i=0;i<h;i++)
+    printf("%d ",RM3[i]);
+  printf("\n");