uchar Y[h];
uchar fX[h];
uchar gY[h];
- uchar *RM1=&RM[0];
- uchar *RM2=&RM[h];
+ uchar RM1[h];
+ uchar RM2[h];
uchar tmp[h];
mylong *rm1=(mylong*)RM1;
mylong *rm2=(mylong*)RM2;
RM1=&RM[PboxSRM[it]*h];
- RM2=&RM[h*h+PboxSRM[len/2-it]*h];
+ RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
RM1=&RM[PboxSRM[it]*h];
- RM2=&RM[h*h+PboxSRM[len/2-it]*h];
+ RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
}
+
+
for(int it=0;it<len/2;it++) {
int ind1=Pbox[it]*h;
int ind2=Pbox[it+len/2]*h;
RM1=&RM[PboxSRM[it]*h];
- RM2=&RM[h*h+PboxSRM[len/2-it]*h];
+ RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
+
+
+
for(int a=0;a<h;a+=4) {
X[a]=seq_in[ind2+a];
X[a+1]=seq_in[ind2+a+1];
}
*/
+
+
for(int a=0;a<h;a+=4) {
seq_out[ind2+a]=gY[a];
seq_out[ind2+a+1]=gY[a+1];
seq_out[ind1+a+2]=fX[a+2];
seq_out[ind1+a+3]=fX[a+3];
}
+
for(int a=0;a<h;a+=4) {
IV1[a]=fX[a];
IV1[a+1]=fX[a+1];
RM1=&RM[PboxSRM[it]*h];
- RM2=&RM[h*h+PboxSRM[len/2-it]*h];
+ RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
-/*
-
-template<int h>
-void encrypt_cbc(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
-
- uchar X[h];
- uchar Y[h];
- uchar fX[h];
- uchar gY[h];
- uchar IV1[h];
- uchar IV2[h];
- uchar *RM1;
- uchar *RM2;
-
- int h2=h*h;
-
-
-
-
- for(int a=0;a<h;a+=4) {
- myrand=xorshift32(myrand);
- uint mm=myrand;
- IV1[a]=(mm&255);
- mm>>=8;
- IV1[a+1]=(mm&255);
- mm>>=8;
- IV1[a+2]=(mm&255);
- mm>>=8;
- IV1[a+3]=(mm&255);
- }
-
- for(int a=0;a<h;a+=4) {
- myrand=xorshift32(myrand);
- uint mm=myrand;
- IV2[a]=(mm&255);
- mm>>=8;
- IV2[a+1]=(mm&255);
- mm>>=8;
- IV2[a+2]=(mm&255);
- mm>>=8;
- IV2[a+3]=(mm&255);
-
- }
-
-
-
- for(int it=0;it<len/2;it++) {
- int ind1=Pbox[it]*h;
- int ind2=Pbox[it+len/2]*h;
-
-
-
- RM1=&RM[PboxSRM[it]*h];
- RM2=&RM[h*h+PboxSRM[it]*h];
-
-
- 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) {
- Y[a]=seq_in[ind1+a];
- Y[a+1]=seq_in[ind1+a+1];
- Y[a+2]=seq_in[ind1+a+2];
- Y[a+3]=seq_in[ind1+a+3];
- }
-
-
- for(int a=0;a<h;a+=4) {
- fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
- fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
- fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
- fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
- }
-
- for(int a=0;a<h;a+=4) {
- gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
- gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
- gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]]^RM2[a+2]];
- gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
-
- }
-
- for(int a=0;a<h;a+=4) {
- seq_out[ind2+a]=gY[a];
- seq_out[ind2+a+1]=gY[a+1];
- seq_out[ind2+a+2]=gY[a+2];
- seq_out[ind2+a+3]=gY[a+3];
- }
-
- for(int a=0;a<h;a+=4) {
- seq_out[ind1+a]=fX[a];
- seq_out[ind1+a+1]=fX[a+1];
- seq_out[ind1+a+2]=fX[a+2];
- seq_out[ind1+a+3]=fX[a+3];
- }
- for(int a=0;a<h;a+=4) {
- IV1[a]=fX[a];
- IV1[a+1]=fX[a+1];
- IV1[a+2]=fX[a+2];
- IV1[a+3]=fX[a+3];
- }
-
- for(int a=0;a<h;a+=4) {
- IV2[a]=gY[a];
- IV2[a+1]=gY[a+1];
- IV2[a+2]=gY[a+2];
- IV2[a+3]=gY[a+3];
- }
-
- }
-
-
-
-
-}
-
-
-
-
-
-
-
-
-template<int h>
-void decrypt_cbc(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) {
-
- uchar invfX[h];
- uchar invgY[h];
- uchar fX[h];
- uchar gY[h];
- uchar IV1[h];
- uchar IV2[h];
- uchar *RM1;
- uchar *RM2;
-
- for(int a=0;a<h;a+=4) {
- myrand=xorshift32(myrand);
- uint mm=myrand;
- IV1[a]=(mm&255);
- mm>>=8;
- IV1[a+1]=(mm&255);
- mm>>=8;
- IV1[a+2]=(mm&255);
- mm>>=8;
- IV1[a+3]=(mm&255);
- }
-
- for(int a=0;a<h;a+=4) {
- myrand=xorshift32(myrand);
- uint mm=myrand;
- IV2[a]=(mm&255);
- mm>>=8;
- IV2[a+1]=(mm&255);
- mm>>=8;
- IV2[a+2]=(mm&255);
- mm>>=8;
- IV2[a+3]=(mm&255);
-
- }
-
-
-
-
-
-
- for(int it=0;it<len/2;it++) {
- int ind1=Pbox[it]*h;
- int ind2=Pbox[it+len/2]*h;
-
-
- RM1=&RM[PboxSRM[it]*h];
- RM2=&RM[h*h+PboxSRM[it]*h];
-
-
- for(int a=0;a<h;a+=4) {
- gY[a]=seq_in[ind2+a];
- gY[a+1]=seq_in[ind2+a+1];
- gY[a+2]=seq_in[ind2+a+2];
- gY[a+3]=seq_in[ind2+a+3];
- }
-
- for(int a=0;a<h;a+=4) {
- fX[a]=seq_in[ind1+a];
- fX[a+1]=seq_in[ind1+a+1];
- fX[a+2]=seq_in[ind1+a+2];
- fX[a+3]=seq_in[ind1+a+3];
- }
-
-
- for(int a=0;a<h;a+=4) {
- invgY[a]=Inv_Sbox1[gY[a]]^RM2[a];
- invgY[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
- invgY[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
- invgY[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
- }
-
-
- for(int a=0;a<h;a+=4) {
- invgY[a]=Inv_Sbox2[invgY[a]]^fX[a]^IV2[a];
- invgY[a+1]=Inv_Sbox2[invgY[a+1]]^fX[a+1]^IV2[a+1];
- invgY[a+2]=Inv_Sbox2[invgY[a+2]]^fX[a+2]^IV2[a+2];
- invgY[a+3]=Inv_Sbox2[invgY[a+3]]^fX[a+3]^IV2[a+3];
- }
-
-
- for(int a=0;a<h;a+=4) {
- invfX[a]=Inv_Sbox2[fX[a]]^invgY[a];
- invfX[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
- invfX[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
- invfX[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
-
- }
-
- for(int a=0;a<h;a+=4) {
- invfX[a]=Inv_Sbox1[invfX[a]]^RM1[a]^IV1[a];
- invfX[a+1]=Inv_Sbox1[invfX[a+1]]^RM1[a+1]^IV1[a+1];
- invfX[a+2]=Inv_Sbox1[invfX[a+2]]^RM1[a+2]^IV1[a+2];
- invfX[a+3]=Inv_Sbox1[invfX[a+3]]^RM1[a+3]^IV1[a+3];
-
- }
-
-
- for(int a=0;a<h;a+=4) {
- seq_out[ind2+a]=invfX[a];
- seq_out[ind2+a+1]=invfX[a+1];
- seq_out[ind2+a+2]=invfX[a+2];
- seq_out[ind2+a+3]=invfX[a+3];
- }
-
- for(int a=0;a<h;a+=4) {
- seq_out[ind1+a]=invgY[a];
- seq_out[ind1+a+1]=invgY[a+1];
- seq_out[ind1+a+2]=invgY[a+2];
- seq_out[ind1+a+3]=invgY[a+3];
- }
- for(int a=0;a<h;a+=4) {
- IV1[a]=fX[a];
- IV1[a+1]=fX[a+1];
- IV1[a+2]=fX[a+2];
- IV1[a+3]=fX[a+3];
- }
-
- for(int a=0;a<h;a+=4) {
- IV2[a]=gY[a];
- IV2[a+1]=gY[a+1];
- IV2[a+2]=gY[a+2];
- IV2[a+3]=gY[a+3];
- }
-
-
- }
-
-
-
-
-}
-*/
-
-
int main(int argc, char** argv) {
else {
width=height=size_buf;
imsize=width*height;
+ cout<<"imsize "<<imsize<<endl;
buffer=new uchar[imsize];
for(int i=0;i<imsize;i++) {
buffer[i]=lrand48();
-
+
int total_len=imsize;
int rp=1;
}
break;
- case 256:
+ case 256:
+
for(i=0;i<nb_test;i++)
{
if(cbcprng)
}
break;
}
+
+
time_encrypt+=TimeStop(t);
//cout<<"Time encrypt "<<
cout<<(double)imsize*nb_test/time_encrypt<<"\t";
break;
}
+
+
time_decrypt+=TimeStop(t);
- //cout<<"Time decrypt "
+// cout<<"Time decrypt "<<time_decrypt<<endl;
cout<<(double)imsize*nb_test/time_decrypt<<"\t";
if(lena) {
equal=false;
}
}
-// cout<<"RESULT CORRECT: "<<equal<<endl;
+ cout<<"RESULT CORRECT: "<<equal<<endl;
}