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];
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];
- }*/
+ }
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) {
}
}
+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,uchar* MAC,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) {
+ MAC[a]=Sbox2[IV[a]];
+ MAC[a+1]=Sbox2[IV[a+1]];
+ MAC[a+2]=Sbox2[IV[a+2]];
+ MAC[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,uchar* MAC,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) {
+ MAC[a]=Sbox2[IV[a]];
+ MAC[a+1]=Sbox2[IV[a+1]];
+ MAC[a+2]=Sbox2[IV[a+2]];
+ MAC[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
uchar RM[h*h*2+256];
uchar IV1[h];
uchar IV2[h];
- uchar MAC[2*h];
+ uchar MAC[h];
+
+
mylong myrand=0;
double t=TimeStart();
+ for(int i=0;i<h;i++) {
+ IV1[i]=i;
+ IV2[i]=i;
+ MAC[i]=i;
+ }
+
+
+
for(int i=0;i<nb_test;i++) {
rc4key(DK, Sbox1, 8);
int i;
switch(h) {
- /* case 16:
+
+ case 16:
for(i=0;i<nb_test;i++)
{
- if(cbcprng)
- encrypt_cbc_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
- if(cbcrm)
- encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
- if(ecbrm)
- encrypt_ecb_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
- if(ecbprng)
- encrypt_ecb_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
- }
- break;*/
+ if(v1b)
+ encrypt_authenticate_algorithm<16>(seq, seq2, len, RM, Pbox, PboxSRM, Sbox1, Sbox2, IV1, MAC, myrand);
+ if(v2b1)
+ encrypt_authenticate_algorithm_2Blocks<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b2)
+ encrypt_authenticate_algorithm_2Blocks_V2<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b3)
+ encrypt_authenticate_algorithm_2Blocks_V3<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,MAC,myrand);
+ }
+ break;
+
+
case 32:
for(i=0;i<nb_test;i++)
{
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,MAC,myrand);
}
break;
+
+ case 64:
+ for(i=0;i<nb_test;i++)
+ {
+ if(v1b)
+ encrypt_authenticate_algorithm<64>(seq, seq2, len, RM, Pbox, PboxSRM, Sbox1, Sbox2, IV1, MAC, myrand);
+ if(v2b1)
+ encrypt_authenticate_algorithm_2Blocks<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b2)
+ encrypt_authenticate_algorithm_2Blocks_V2<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b3)
+ encrypt_authenticate_algorithm_2Blocks_V3<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV1,MAC,myrand);
+ }
+ break;
+
+
+
}
cout<<"Time encrypt "<<time_encrypt<<endl;
cout<<(double)imsize*nb_test/time_encrypt<<"\t";
+ /* for(int i=0;i<h;i++)
+ printf("%d ",MAC[i]);
+ printf("\n");
+ */
if(lena) {
for(int i=0;i<oneD;i++) {
store_RGB_pixmap("lena2.ppm", data_R, data_G, data_B, width, height);
}
+ for(int i=0;i<h;i++) {
+ IV1[i]=i;
+ IV2[i]=i;
+ MAC[i]=i;
+ }
+
xorseed=myrand;
// lehmer64_seed(myrand);
time_decrypt=0;
t=TimeStart();
switch(h) {
- /* case 16:
+ case 16:
for(i=0;i<nb_test;i++) {
- if(cbcprng)
- decrypt_cbc_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
- if(cbcrm)
- decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
- if(ecbrm)
- decrypt_ecb_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
- if(ecbprng)
- decrypt_ecb_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
- }
- break;*/
+ if(v1b)
+ decrypt_authenticate_algorithm<16>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,MAC,myrand);
+ if(v2b1)
+ decrypt_authenticate_algorithm_2Blocks<16>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b2)
+ decrypt_authenticate_algorithm_2Blocks_V2<16>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b3)
+ decrypt_authenticate_algorithm_2Blocks_V3<16>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,MAC,myrand);
+ }
+ break;
+
case 32:
for(i=0;i<nb_test;i++) {
if(v1b)
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,MAC,myrand);
+ }
+ break;
+
+ case 64:
+ for(i=0;i<nb_test;i++) {
+ if(v1b)
+ decrypt_authenticate_algorithm<64>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,MAC,myrand);
+ if(v2b1)
+ decrypt_authenticate_algorithm_2Blocks<64>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b2)
+ decrypt_authenticate_algorithm_2Blocks_V2<64>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,IV2,MAC,myrand);
+ if(v2b3)
+ decrypt_authenticate_algorithm_2Blocks_V3<64>(seq2, seq,len,RM,Pbox,PboxSRM,Inv_Sbox1,Inv_Sbox2,Sbox1,Sbox2,IV1,MAC,myrand);
}
break;
+
+
+
+
}
+
time_decrypt+=TimeStop(t);
// cout<<"Time decrypt "<<time_decrypt<<endl;
cout<<(double)imsize*nb_test/time_decrypt<<"\t";
-
+ /* for(int i=0;i<h;i++)
+ printf("%d ",MAC[i]);
+ printf("\n");
+ */
+
if(lena) {
for(int i=0;i<oneD;i++) {
data_R[i]=seq[i];