int v1b=0;
int v2b1=0;
int v2b2=0;
+int v2b3=0;
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) {
- 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) {
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+3]=seq_in[ind2+a+3];
}
-
+ */
for(int a=0;a<h;a+=4) {
- tmp[a]=Inv_Sbox2[X[a]]^RM2[a];
- tmp[a+1]=Inv_Sbox2[X[a+1]]^RM2[a+1];
- tmp[a+2]=Inv_Sbox2[X[a+2]]^RM2[a+2];
- tmp[a+3]=Inv_Sbox2[X[a+3]]^RM2[a+3];
+ tmp[a]=Inv_Sbox2[seq_in[ind2+a]]^RM2[a];
+ tmp[a+1]=Inv_Sbox2[seq_in[ind2+a+1]]^RM2[a+1];
+ tmp[a+2]=Inv_Sbox2[seq_in[ind2+a+2]]^RM2[a+2];
+ tmp[a+3]=Inv_Sbox2[seq_in[ind2+a+3]]^RM2[a+3];
}
for(int a=0;a<h;a+=4) {
}
}
+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) {
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
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;
}
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;
}