X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/2b28ebca4ad3d5461f91c6580748b04e5a7eb1e6..d85382e55c19510223800d572b1628aca5b5f188:/OneRoundIoT/OneRound/one_round_par2.cpp?ds=sidebyside diff --git a/OneRoundIoT/OneRound/one_round_par2.cpp b/OneRoundIoT/OneRound/one_round_par2.cpp index f579622..4a069b4 100644 --- a/OneRoundIoT/OneRound/one_round_par2.cpp +++ b/OneRoundIoT/OneRound/one_round_par2.cpp @@ -166,10 +166,13 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, in uchar X[h2]; - for(int a=0;a<h2;a++) { - X[a]=Sbox1[a&0xFF]; //Warning according to the size of h2, we can be outsize of Sbox1[a] - } + 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]; + } int offset=p*loc_len; @@ -191,72 +194,36 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, in } - /*for(int a=0;a<h2;a+=4){ - fX[a]=RM1[X[a]]; - fX[a+1]=RM1[X[a+1]]; - fX[a+2]=RM1[X[a+2]]; - fX[a+3]=RM1[X[a+3]]; - }*/ - - for(int a=0;a<h2;a+=4){ - fX[a]=X[a]; - fX[a+1]=X[a+1]; - fX[a+2]=X[a+2]; - fX[a+3]=X[a+3]; + for(int a=0;a<h2;a+=4) { + X[a]=X[Sbox1[a]]; + X[a+1]=X[Sbox1[a+1]]; + X[a+2]=X[Sbox1[a+2]]; + X[a+3]=X[Sbox1[a+3]]; } - - + + + for(int a=0;a<h2;a+=4) { + fX[a]=X[a]^RM2[a]; + fX[a+1]=X[a+1]^RM2[a+1]; + fX[a+2]=X[a+2]^RM2[a+2]; + fX[a+3]=X[a+3]^RM2[a+3]; + } - /* if(it<513) { - for(int a=0;a<h2;a++) - printf("%d ",fX[a]); - printf("\n"); - }*/ - *(int*)&fX[0]^=it; - - /* if(it<513) { - for(int a=0;a<h2;a++) - printf("%d ",fX[a]); - printf("\n"); - }*/ - - - /*for(int a=0;a<h2;a+=4) { - fX[id*h2+a]=fX[id*h2+a]^RM1[id*h2+a]; - fX[id*h2+a+1]=fX[id*h2+a+1]^RM1[id*h2+a+1]; - fX[id*h2+a+2]=fX[id*h2+a+2]^RM1[id*h2+a+2]; - fX[id*h2+a+3]=fX[id*h2+a+3]^RM1[id*h2+a+3]; - }*/ - - - - - for(int a=0;a<h2;a+=4) { fX[a]=Sbox2[fX[a]]; fX[a+1]=Sbox2[fX[a+1]]; fX[a+2]=Sbox2[fX[a+2]]; fX[a+3]=Sbox2[fX[a+3]]; - } + }*/ // rotate(RM1, &RM2[id*h2], h2, Pbox[it]%h2); - for(int a=0;a<h2;a+=4) { - RM2[a]=RM2[PboxRM[a]]; - RM2[a+1]=RM2[PboxRM[a+1]]; - RM2[a+2]=RM2[PboxRM[a+2]]; - RM2[a+3]=RM2[PboxRM[a+3]]; - } - for(int a=0;a<h2;a+=4) { - fX[a]=fX[a]^RM2[a]; - fX[a+1]=fX[a+1]^RM2[a+1]; - fX[a+2]=fX[a+2]^RM2[a+2]; - fX[a+3]=fX[a+3]^RM2[a+3]; - } + + @@ -274,7 +241,17 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, in seq_out[ind1+a+2]=fX[a+2]; seq_out[ind1+a+3]=fX[a+3]; } - + + + + for(int a=0;a<h2;a+=4) { + RM2[a]=RM2[PboxRM[a]]; + RM2[a+1]=RM2[PboxRM[a+1]]; + RM2[a+2]=RM2[PboxRM[a+2]]; + RM2[a+3]=RM2[PboxRM[a+3]]; + } + + /*for(int a=0;a<h2;a+=4) { RM1[id*h2+a]=RM1[id*h2+PboxRM[a]]; RM1[id*h2+a+1]=RM1[id*h2+PboxRM[a+1]]; @@ -605,12 +582,6 @@ int main(int argc, char** argv) { int num=omp_get_max_threads(); cout<<"num "<<num<<endl; - uchar RM1[num*(h * h)]; - uchar RM2[num*(h * h)]; - prga(sc, num*(h * h), RM1); - for(int i=0;i<num*h2;i++) { - RM2[i]=RM1[i]; - } @@ -618,10 +589,30 @@ int main(int argc, char** argv) { - uchar keyp[16]; - for (int i = 48; i < 64; i++) - keyp[i-48] = DK[i]; + + uchar RM1[num*(h * h)]; + uchar RM2[num*(h * h)]; + /*for(int i=0;i<num;i++) { + + rc4key(&DK[48+i*16], sc, 16); + prga(sc, h2, &RM1[h2*i]); + for(int a=0;a<h2;a++) { + cout<<(int)RM1[h2*i+a]<<" "; + } + cout<<endl<<endl; + }*/ + + rc4key(&DK[48], sc, 16); + prga(sc, h2*num, RM1); + + rc4key(&DK[64], sc, 16); + prga(sc, h2, RM2); + + + + + // cout<<len<<endl; int *Pbox=new int[len]; @@ -629,15 +620,14 @@ int main(int argc, char** argv) { int *PboxRM=new int[h2]; - rc4keyperm(keyp, len, rp, Pbox, 16); + rc4keyperm(&DK[48+16*num], len, rp, Pbox, 16); -// printf("len %d\n",len); - for(int i=0;i<len;i++) { -// printf("%d \n",Pbox[i]); - } - + rc4keyperm(RM2, h2, rp, PboxRM, h2); + for(int i=0;i<num*h2;i++) { + RM2[i]=RM1[i]; + } double time=0; double t=TimeStart();