for(int a=0;a<h2;a+=4) {
- X[a]=Sbox1[a&0xFF]; //Warning according to the size of h2, we can be outsize of Sbox1[a]
- X[a+1]=Sbox1[(a+1)&0xFF];
- X[a+2]=Sbox1[(a+2)&0xFF];
- X[a+3]=Sbox1[(a+3)&0xFF];
+ myrand=xorshift32(myrand);
+ uint mm=myrand;
+
+ X[a]=Sbox2[mm&255];
+ mm>>=8;
+ X[a+1]=Sbox1[mm&255];
+ mm>>=8;
+ X[a+2]=Sbox2[mm&255];
+ mm>>=8;
+ X[a+3]=Sbox1[mm&255];
}
}
+ for(int a=0;a<h2;a+=4) {
+
+ myrand=xorshift32(myrand);
+ uint mm=myrand;
+
+ X[a]=X[a]^(mm&255);
+ mm>>=8;
+ X[a+1]=X[a+1]^(mm&255);
+ mm>>=8;
+ X[a+2]=X[a+2]^(mm&255);
+ mm>>=8;
+ X[a+3]=X[a+3]^(mm&255);
+ }
+
+
+
+
+
for(int a=0;a<h2;a+=4) {
X[a]=Sbox1[X[a]];
- X[a+1]=Sbox1[X[a+1]];
+ X[a+1]=Sbox2[X[a+1]];
X[a+2]=Sbox1[X[a+2]];
- X[a+3]=Sbox1[X[a+3]];
+ X[a+3]=Sbox2[X[a+3]];
}
for(int a=0;a<h2;a+=4) {
- fX[a]=X[a]^RM1[a];
- fX[a+1]=X[a+1]^RM1[a+1];
- fX[a+2]=X[a+2]^RM1[a+2];
- fX[a+3]=X[a+3]^RM1[a+3];
+ X[a]=X[a]^RM1[a];
+ X[a+1]=X[a+1]^RM1[a+1];
+ X[a+2]=X[a+2]^RM1[a+2];
+ X[a+3]=X[a+3]^RM1[a+3];
}
for(int a=0;a<h2;a+=4) {
+ fX[a]=X[a]^seq_in[ind2+a];
+ fX[a+1]=X[a+1]^seq_in[ind2+a+1];
+ fX[a+2]=X[a+2]^seq_in[ind2+a+2];
+ fX[a+3]=X[a+3]^seq_in[ind2+a+3];
- myrand=xorshift32(myrand);
- uint mm=myrand;
-
- fX[a]=fX[a]^seq_in[ind2+a]^(mm&255);
- mm>>=8;
- fX[a+1]=fX[a+1]^seq_in[ind2+a+1]^(mm&255);
- mm>>=8;
- fX[a+2]=fX[a+2]^seq_in[ind2+a+2]^(mm&255);
- mm>>=8;
- fX[a+3]=fX[a+3]^seq_in[ind2+a+3]^(mm&255);
}
for(int a=0;a<h2;a+=4){
fX[a]=Sbox1[X[a]];
- fX[a+1]=Sbox1[X[a+1]];
+ fX[a+1]=Sbox2[X[a+1]];
fX[a+2]=Sbox1[X[a+2]];
- fX[a+3]=Sbox1[X[a+3]];
+ fX[a+3]=Sbox2[X[a+3]];
}
for(int a=0;a<h2;a+=4) {
seq_out[ind1+a]=Sbox2[fX[a]];
- seq_out[ind1+a+1]=Sbox2[fX[a+1]];
+ seq_out[ind1+a+1]=Sbox1[fX[a+1]];
seq_out[ind1+a+2]=Sbox2[fX[a+2]];
- seq_out[ind1+a+3]=Sbox2[fX[a+3]];
+ seq_out[ind1+a+3]=Sbox1[fX[a+3]];
}
for(int a=0;a<h2;a+=4) {
- RM1[a]=RM1[PboxRM[a]];
- RM1[a+1]=RM1[PboxRM[a+1]];
- RM1[a+2]=RM1[PboxRM[a+2]];
- RM1[a+3]=RM1[PboxRM[a+3]];
+ RM1[a]=Sbox1[RM1[PboxRM[a]]];
+ RM1[a+1]=Sbox2[RM1[PboxRM[a+1]]];
+ RM1[a+2]=Sbox1[RM1[PboxRM[a+2]]];
+ RM1[a+3]=Sbox2[RM1[PboxRM[a+3]]];
}
template<int h2>
-void decrypt(uchar* seq_in, uchar *seq_out, int len, uchar* RM1, int *Pbox, int *PboxRM, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) {
+void decrypt(uchar* seq_in, uchar *seq_out, int len, uchar* RM1, int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) {
}
for(int a=0;a<h2;a+=4) {
fX[a]=Inv_Sbox2[fX[a]];
- fX[a+1]=Inv_Sbox2[fX[a+1]];
+ fX[a+1]=Inv_Sbox1[fX[a+1]];
fX[a+2]=Inv_Sbox2[fX[a+2]];
- fX[a+3]=Inv_Sbox2[fX[a+3]];
+ fX[a+3]=Inv_Sbox1[fX[a+3]];
}
for(int a=0;a<h2;a+=4) {
fX[a]=fX[a]^RM1[a];
fX[a+3]=fX[a+3]^RM1[a+3];
}
+
for(int a=0;a<h2;a+=4) {
- RM1[a]=RM1[PboxRM[a]];
- RM1[a+1]=RM1[PboxRM[a+1]];
- RM1[a+2]=RM1[PboxRM[a+2]];
- RM1[a+3]=RM1[PboxRM[a+3]];
+ RM1[a]=Sbox1[RM1[PboxRM[a]]];
+ RM1[a+1]=Sbox2[RM1[PboxRM[a+1]]];
+ RM1[a+2]=Sbox1[RM1[PboxRM[a+2]]];
+ RM1[a+3]=Sbox2[RM1[PboxRM[a+3]]];
}
+
for(int a=0;a<h2;a+=4) {
myrand=xorshift32(myrand);
uint mm=myrand;
seq_out[ind2+a]=Inv_Sbox1[fX[a]]^(mm&255);
mm>>=8;
- seq_out[ind2+a+1]=Inv_Sbox1[fX[a+1]]^(mm&255);
+ seq_out[ind2+a+1]=Inv_Sbox2[fX[a+1]]^(mm&255);
mm>>=8;
seq_out[ind2+a+2]=Inv_Sbox1[fX[a+2]]^(mm&255);
mm>>=8;
- seq_out[ind2+a+3]=Inv_Sbox1[fX[a+3]]^(mm&255);
+ seq_out[ind2+a+3]=Inv_Sbox2[fX[a+3]]^(mm&255);
}
if(ctr)
encrypt_ctr<4*4>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0);
else
- decrypt<4*4>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt<4*4>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 8:
if(ctr)
encrypt_ctr<8*8>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0);
else
- decrypt<8*8>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt<8*8>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 16:
if(ctr)
encrypt_ctr<16*16>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0);
else
- decrypt<16*16>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt<16*16>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 32:
if(ctr)
encrypt_ctr<32*32>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0);
else
- decrypt<32*32>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt<32*32>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 64:
if(ctr)
encrypt_ctr<64*64>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0);
else
- decrypt<64*64>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt<64*64>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 128:
if(ctr)
encrypt_ctr<128*128>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0);
else
- decrypt<128*128>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt<128*128>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
}