]> AND Private Git Repository - Cipher_code.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
authorRaphaël Couturier <raphael.couturier@univ-fcomte.fr>
Tue, 3 Aug 2021 11:00:07 +0000 (13:00 +0200)
committerRaphaël Couturier <raphael.couturier@univ-fcomte.fr>
Tue, 3 Aug 2021 11:00:07 +0000 (13:00 +0200)
OneRoundHash/oneroundhash.cpp

index 8eb527bf2a451851d152aeb3145389219c498550..642dc07f64b71f12a01aaea3ce9723950b217aa5 100644 (file)
@@ -34,6 +34,7 @@ int nb_test=1;
 int v1b=0;
 int v2b1=0;
 int v2b2=0;
 int v1b=0;
 int v2b1=0;
 int v2b2=0;
+int v2b3=0;
 
 
 
 
 
 
@@ -209,18 +210,13 @@ void encrypt_authenticate_algorithm(uchar* seq_in, uchar *seq_out,  int len, uch
       rm2[a]=myrand;
     }  
 
       rm2[a]=myrand;
     }  
 
-    for(int a=0;a<h;a+=4) {
-      X[a]=seq_in[ind2+a];
-      X[a+1]=seq_in[ind2+a+1];
-      X[a+2]=seq_in[ind2+a+2];
-      X[a+3]=seq_in[ind2+a+3];
-    }
+  
 
     for(int a=0;a<h;a+=4) {
 
     for(int a=0;a<h;a+=4) {
-      tmp[a]=Sbox1[X[a]^RM1[a]];
-      tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]];
-      tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]];
-      tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]];
+      tmp[a]=Sbox1[seq_in[ind2+a]^RM1[a]];
+      tmp[a+1]=Sbox1[seq_in[ind2+a+1]^RM1[a+1]];
+      tmp[a+2]=Sbox1[seq_in[ind2+a+2]^RM1[a+2]];
+      tmp[a+3]=Sbox1[seq_in[ind2+a+3]^RM1[a+3]];
     }
     
     for(int a=0;a<h;a+=4) {
     }
     
     for(int a=0;a<h;a+=4) {
@@ -278,7 +274,7 @@ void decrypt_authenticate_algorithm(uchar* seq_in, uchar *seq_out,  int len, uch
       rm2[a]=myrand;
     }  
 
       rm2[a]=myrand;
     }  
 
-    /*  for(int a=0;a<h;a+=4) {
+    /*    for(int a=0;a<h;a+=4) {
       X[a]=seq_in[ind2+a];
       X[a+1]=seq_in[ind2+a+1];
       X[a+2]=seq_in[ind2+a+2];
       X[a]=seq_in[ind2+a];
       X[a+1]=seq_in[ind2+a+1];
       X[a+2]=seq_in[ind2+a+2];
@@ -292,18 +288,18 @@ void decrypt_authenticate_algorithm(uchar* seq_in, uchar *seq_out,  int len, uch
       tmp[a+3]=Inv_Sbox2[seq_in[ind2+a+3]]^RM2[a+3];
     }
     
       tmp[a+3]=Inv_Sbox2[seq_in[ind2+a+3]]^RM2[a+3];
     }
     
-    /*  for(int a=0;a<h;a+=4) {
+    for(int a=0;a<h;a+=4) {
       X[a]=Inv_Sbox1[tmp[a]]^RM1[a];
       X[a+1]=Inv_Sbox1[tmp[a+1]]^RM1[a+1];
       X[a+2]=Inv_Sbox1[tmp[a+2]]^RM1[a+2];
       X[a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
       X[a]=Inv_Sbox1[tmp[a]]^RM1[a];
       X[a+1]=Inv_Sbox1[tmp[a+1]]^RM1[a+1];
       X[a+2]=Inv_Sbox1[tmp[a+2]]^RM1[a+2];
       X[a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
-      }*/
+    }
       
     for(int a=0;a<h;a+=4) {
       
     for(int a=0;a<h;a+=4) {
-      seq_out[ind1+a]=Inv_Sbox1[tmp[a]]^RM1[a];
-      seq_out[ind1+a+1]=Inv_Sbox1[tmp[a+1]]^RM1[a+1];
-      seq_out[ind1+a+2]=Inv_Sbox1[tmp[a+2]]^RM1[a+2];
-      seq_out[ind1+a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
+      seq_out[ind1+a]=X[a];
+      seq_out[ind1+a+1]=X[a+1];
+      seq_out[ind1+a+2]=X[a+2];
+      seq_out[ind1+a+3]=X[a+3];
     }
 
     for(int a=0;a<h;a+=4) {
     }
 
     for(int a=0;a<h;a+=4) {
@@ -749,7 +745,111 @@ void decrypt_authenticate_algorithm_2Blocks_V2(uchar* seq_in, uchar *seq_out,  i
   }
 }
 
   }
 }
 
+template<int h>
+void encrypt_authenticate_algorithm_2Blocks_V3(uchar* seq_in, uchar *seq_out,  int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar* IV,mylong myrand) {
+  uchar RM1[h];
+  uchar tmp1[h];
+  mylong *rm1=(mylong*)RM1;
+
+  for(int it=0;it<len/2;it++) {
+    int ind1=Pbox[it]*h;
+    int ind2=Pbox[it+len/2]*h;
+    
+    for(int a=0;a<(h>>3);a++) {
+      myrand=xorshift64();
+      rm1[a]=myrand;
+    }  
+
+    for(int a=0;a<h;a+=4) {
+      tmp1[a]=Sbox1[seq_in[ind1+a]^RM1[a]];
+      tmp1[a+1]=Sbox1[seq_in[ind1+a+1]^RM1[a+1]];
+      tmp1[a+2]=Sbox1[seq_in[ind1+a+2]^RM1[a+2]];
+      tmp1[a+3]=Sbox1[seq_in[ind1+a+3]^RM1[a+3]];
+    }
+    
+    for(int a=0;a<h;a+=4) {
+      seq_out[ind2+a]=Sbox2[seq_in[ind2+a]^tmp1[a]];
+      seq_out[ind2+a+1]=Sbox2[seq_in[ind2+a+1]^tmp1[a+1]];
+      seq_out[ind2+a+2]=Sbox2[seq_in[ind2+a+2]^tmp1[a+2]];
+      seq_out[ind2+a+3]=Sbox2[seq_in[ind2+a+3]^tmp1[a+3]];
+    }
+       
 
 
+    for(int a=0;a<h;a+=4) {
+      seq_out[ind1+a]=Sbox2[tmp1[a]];
+      seq_out[ind1+a+1]=Sbox2[tmp1[a+1]];
+      seq_out[ind1+a+2]=Sbox2[tmp1[a+2]];
+      seq_out[ind1+a+3]=Sbox2[tmp1[a+3]];
+    }
+
+    for(int a=0;a<h;a+=4) {
+      IV[a]=Sbox1[IV[a]^seq_out[ind2+a]]^tmp1[a];
+      IV[a+1]=Sbox1[IV[a+1]^seq_out[ind2+a+1]]^tmp1[a+1];
+      IV[a+2]=Sbox1[IV[a+2]^seq_out[ind2+a+2]]^tmp1[a+2];
+      IV[a+3]=Sbox1[IV[a+3]^seq_out[ind2+a+3]]^tmp1[a+3];
+    }
+
+  }
+    for(int a=0;a<h;a+=4) {
+      IV[a]=Sbox2[IV[a]];
+      IV[a+1]=Sbox2[IV[a+1]];
+      IV[a+2]=Sbox2[IV[a+2]];
+      IV[a+3]=Sbox2[IV[a+3]];
+  }
+}
+
+
+template<int h>
+void decrypt_authenticate_algorithm_2Blocks_V3(uchar* seq_in, uchar *seq_out,  int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Inv_Sbox1, uchar *Inv_Sbox2 ,uchar *Sbox1, uchar *Sbox2, uchar* IV,mylong myrand) {
+  uchar RM1[h];
+  uchar tmp1[h];
+  mylong *rm1=(mylong*)RM1;
+
+  for(int it=0;it<len/2;it++) {
+    int ind1=Pbox[it]*h;
+    int ind2=Pbox[it+len/2]*h;
+    
+    for(int a=0;a<(h>>3);a++) {
+      myrand=xorshift64();
+      rm1[a]=myrand;
+    }  
+
+    for(int a=0;a<h;a+=4) {
+      tmp1[a]=Inv_Sbox2[seq_in[ind1+a]];
+      tmp1[a+1]=Inv_Sbox2[seq_in[ind1+a+1]];
+      tmp1[a+2]=Inv_Sbox2[seq_in[ind1+a+2]];
+      tmp1[a+3]=Inv_Sbox2[seq_in[ind1+a+3]];
+    }
+
+    for(int a=0;a<h;a+=4) {
+      seq_out[ind2+a]=Inv_Sbox2[seq_in[ind2+a]]^tmp1[a];
+      seq_out[ind2+a+1]=Inv_Sbox2[seq_in[ind2+a+1]]^tmp1[a+1];
+      seq_out[ind2+a+2]=Inv_Sbox2[seq_in[ind2+a+2]]^tmp1[a+2];
+      seq_out[ind2+a+3]=Inv_Sbox2[seq_in[ind2+a+3]]^tmp1[a+3];
+    }
+       
+    for(int a=0;a<h;a+=4) {
+     seq_out[ind1+a]  =Inv_Sbox1[tmp1[a]]^RM1[a];
+     seq_out[ind1+a+1]=Inv_Sbox1[tmp1[a+1]]^RM1[a+1];
+     seq_out[ind1+a+2]=Inv_Sbox1[tmp1[a+2]]^RM1[a+2];
+     seq_out[ind1+a+3]=Inv_Sbox1[tmp1[a+3]]^RM1[a+3];
+    }
+    
+    for(int a=0;a<h;a+=4) {
+      IV[a]=Sbox1[IV[a]^seq_in[ind2+a]]^tmp1[a];
+      IV[a+1]=Sbox1[IV[a+1]^seq_in[ind2+a+1]]^tmp1[a+1];
+      IV[a+2]=Sbox1[IV[a+2]^seq_in[ind2+a+2]]^tmp1[a+2];
+      IV[a+3]=Sbox1[IV[a+3]^seq_in[ind2+a+3]]^tmp1[a+3];
+    }
+
+  }
+  for(int a=0;a<h;a+=4) {
+    IV[a]=Sbox2[IV[a]];
+    IV[a+1]=Sbox2[IV[a+1]];
+    IV[a+2]=Sbox2[IV[a+2]];
+    IV[a+3]=Sbox2[IV[a+3]];
+  }
+}
 
 
 int main(int argc, char** argv) {
 
 
 int main(int argc, char** argv) {
@@ -766,6 +866,7 @@ int main(int argc, char** argv) {
     if(strncmp(argv[i],"v1b",3)==0) v1b=1;       
     if(strncmp(argv[i],"v2b1",4)==0) v2b1=1;
     if(strncmp(argv[i],"v2b2",4)==0) v2b2 = 1;
     if(strncmp(argv[i],"v1b",3)==0) v1b=1;       
     if(strncmp(argv[i],"v2b1",4)==0) v2b1=1;
     if(strncmp(argv[i],"v2b2",4)==0) v2b2 = 1;
+    if(strncmp(argv[i],"v2b3",4)==0) v2b3 = 1;
     if(strncmp(argv[i],"h",1)==0) h = atoi(&(argv[i][1]));          //size of block
     if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7]));          //SIZE of the buffer
     if(strncmp(argv[i],"lena",4)==0) lena = atoi(&(argv[i][4]));          //Use Lena or buffer
     if(strncmp(argv[i],"h",1)==0) h = atoi(&(argv[i][1]));          //size of block
     if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7]));          //SIZE of the buffer
     if(strncmp(argv[i],"lena",4)==0) lena = atoi(&(argv[i][4]));          //Use Lena or buffer
@@ -996,6 +1097,8 @@ int main(int argc, char** argv) {
        encrypt_authenticate_algorithm_2Blocks<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
       if(v2b2)
        encrypt_authenticate_algorithm_2Blocks_V2<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
        encrypt_authenticate_algorithm_2Blocks<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
       if(v2b2)
        encrypt_authenticate_algorithm_2Blocks_V2<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+      if(v2b3)
+       encrypt_authenticate_algorithm_2Blocks_V3<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,myrand);
     }
     break;
   }
     }
     break;
   }
@@ -1041,6 +1144,8 @@ int main(int argc, char** argv) {
        decrypt_authenticate_algorithm_2Blocks<32>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
       if(v2b2)
        decrypt_authenticate_algorithm_2Blocks_V2<32>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
        decrypt_authenticate_algorithm_2Blocks<32>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
       if(v2b2)
        decrypt_authenticate_algorithm_2Blocks_V2<32>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+      if(v2b3)
+       decrypt_authenticate_algorithm_2Blocks_V3<32>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,myrand);
     }
     break;
   }
     }
     break;
   }