int key_size=256;
int nb_test=1;
+int cbcprng=0;
int cbc=0;
-
+int ecb=0;
+int ecbprng=0;
-uint xorshift32(const uint t)
-{
- /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
- uint x = t;
- x ^= x << 13;
- x ^= x >> 17;
- x ^= x << 5;
- return x;
-}
+uint xorshift32(const uint t)
+{
+ /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
+ uint x = t;
+ x ^= x << 13;
+ x ^= x >> 17;
+ x ^= x << 5;
+ return x;
+}
+
+ulong xorshift64(ulong t)
+{
+ /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
+ ulong x = t;
+ x ^= x >> 12; // a
+ x ^= x << 25; // b
+ x ^= x >> 27; // c
+
+
+ return x;
+}
+
+__uint128_t g_lehmer64_state;
+
+inline uint64_t splitmix64_stateless(uint64_t index) {
+ uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
+ z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
+ z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
+ return z ^ (z >> 31);
+}
+
+
+inline void lehmer64_seed(uint64_t seed) {
+ g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) +
+ splitmix64_stateless(seed + 1);
+}
+
+inline uint64_t lehmer64() {
+ g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
+ ;
+ return g_lehmer64_state >> 64;
+}
+
+
+
+
+
+void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
+
+ for(int i=0;i<size_tab;i++) {
+ inv_perm_tabs[tab[i]] = i;
+ }
+
+}
+
+void inverse_tables_int(int *tab, int size_tab,int *inv_perm_tabs) {
+
+ for(int i=0;i<size_tab;i++) {
+ inv_perm_tabs[tab[i]] = i;
+ }
+
+}
+
+
+
+void rc4key(uchar *key, uchar *sc, int size_DK) {
+
+ for(int i=0;i<256;i++) {
+ sc[i]=i;
+ }
+
+
+ uchar j0 = 0;
+ for(int i0=0; i0<256; i0++) {
+ j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
+ uchar tmp = sc[i0];
+ sc[i0] = sc[j0 ];
+ sc[j0] = tmp;
+ }
+}
+
+
+
+void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
+
+ //sc=1:len;
+
+
+
+ for (int i=0;i<len;i++) {
+ sc[i]=i;
+ }
+ for (int it = 0; it < rp; it++) {
+ int j0 = 1;
+ for(int i0 = 0; i0<len; i0++) {
+ j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
+ int tmp = sc[i0];
+ sc[i0] = sc[j0];
+ sc[j0] = tmp;
+ }
+
+ }
+}
+
+void prga(uchar *sc, int ldata, uchar *r) {
+ uchar i0=0;
+ uchar j0=0;
+
+ for (int it=0; it<ldata; it++) {
+ i0 = ((i0+1)%255);
+ j0 = (j0 + sc[i0])&0xFF;
+ uchar tmp = sc[i0];
+ sc[i0] = sc[j0];
+ sc[j0] = tmp;
+ r[it]=sc[(sc[i0]+sc[j0])&0xFF];
+ }
+}
+
+
+
+
+
+
+template<int h>
+void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) {
+
+ uchar X[h];
+ uchar Y[h];
+ uchar fX[h];
+ uchar gY[h];
+ uchar RM1[h];
+ uchar RM2[h];
+ uchar tmp[h];
+ ulong *rm1=(ulong*)RM1;
+ ulong *rm2=(ulong*)RM2;
+
+ 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=lehmer64();
+ rm1[a]=myrand;
+ myrand=lehmer64();
+ 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[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h;a+=4) {
+ gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
+ gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
+ gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
+ gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[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];
+ }
+
+
+
+ }
+
+
+
+
+}
+
+
+
+
+
+
+
+
+template<int h>
+void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, ulong myrand, int debug) {
+
+ uchar invfX[h];
+ uchar invgY[h];
+ uchar fX[h];
+ uchar gY[h];
+ uchar RM1[h];
+ uchar RM2[h];
+ uchar tmp[h];
+ ulong *rm1=(ulong*)RM1;
+ ulong *rm2=(ulong*)RM2;
+
+ 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=lehmer64();
+ rm1[a]=myrand;
+ myrand=lehmer64();
+ rm2[a]=myrand;
+ }
+
+
+
+ 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)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]^RM1[a+2];
+ invfX[a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
+
+ }
+
+
+ /*
+ for(int a=0;a<h;a+=4) {
+ invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
+ invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
+ invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
+ invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[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];
+ }
+
+
+
+ }
+
+
+
+
+}
+
+
+
+/*
+
+template<int h>
+void encrypt_ecb(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 *RM1;
+ uchar *RM2;
+
+ 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]]^Y[a]];
+ fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]]^Y[a+1]];
+ fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]]^Y[a+2]];
+ fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]]^Y[a+3]];
+ }
+
+ for(int a=0;a<h;a+=4) {
+ gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
+ gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
+ gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
+ gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[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];
+ }
+
+
+
+ }
+
+
+
+
+}
+
+
+
+
+
+
+
+
+template<int h>
+void decrypt_ecb(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 *RM1;
+ uchar *RM2;
+
+ 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_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
+ invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
+ invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
+ invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
+ }
+
+
+
+ for(int a=0;a<h;a+=4) {
+ invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
+ invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
+ invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
+ invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[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];
+ }
+
+
+
+ }
+
+
+
+
+}
+
+*/
+
+
+
+
+
+template<int h>
+void encrypt_cbc_prng(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[h];
+ uchar RM2[h];
+ uchar tmp[h];
+ ulong *rm1=(ulong*)RM1;
+ ulong *rm2=(ulong*)RM2;
+
+ 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=lehmer64();
+ rm1[a]=myrand;
+ myrand=lehmer64();
+ 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) {
+ 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) {
+ tmp[a]=X[a]^RM1[a]^IV1[a];
+ tmp[a+1]=X[a+1]^RM1[a+1]^IV1[a+1];
+ tmp[a+2]=X[a+2]^RM1[a+2]^IV1[a+2];
+ tmp[a+3]=X[a+3]^RM1[a+3]^IV1[a+3];
+ }
+
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Sbox1[tmp[a]];
+ tmp[a+1]=Sbox1[tmp[a+1]];
+ tmp[a+2]=Sbox1[tmp[a+2]];
+ tmp[a+3]=Sbox1[tmp[a+3]];
+ }
+
+
+ /*for(int a=0;a<h;a+=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]];
+ tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]];
+
+ }
+ */
+
+ for(int a=0;a<h;a+=4) {
+ gY[a]=Sbox1[tmp[a]^RM2[a]];
+ gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
+ gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
+ gY[a+3]=Sbox1[tmp[a+3]^RM2[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_prng(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[h];
+ uchar RM2[h];
+ uchar tmp[h];
+ ulong *rm1=(ulong*)RM1;
+ ulong *rm2=(ulong*)RM2;
+
+ 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=lehmer64();
+ rm1[a]=myrand;
+ myrand=lehmer64();
+ rm2[a]=myrand;
+ }
+
+ 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) {
+ tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
+ tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
+ tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
+ tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
+ }
+
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Inv_Sbox2[tmp[a]];
+ tmp[a+1]=Inv_Sbox2[tmp[a+1]];
+ tmp[a+2]=Inv_Sbox2[tmp[a+2]];
+ tmp[a+3]=Inv_Sbox2[tmp[a+3]];
+ }
-void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
+
+ for(int a=0;a<h;a+=4) {
+ invgY[a]=tmp[a]^fX[a]^IV2[a];
+ invgY[a+1]=tmp[a+1]^fX[a+1]^IV2[a+1];
+ invgY[a+2]=tmp[a+2]^fX[a+2]^IV2[a+2];
+ invgY[a+3]=tmp[a+3]^fX[a+3]^IV2[a+3];
+ }
- for(int i=0;i<size_tab;i++) {
- inv_perm_tabs[tab[i]] = i;
- }
-}
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
+ tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
+ tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
+ tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
-void inverse_tables_int(int *tab, int size_tab,int *inv_perm_tabs) {
+ }
- for(int i=0;i<size_tab;i++) {
- inv_perm_tabs[tab[i]] = i;
- }
-}
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Inv_Sbox1[tmp[a]];
+ tmp[a+1]=Inv_Sbox1[tmp[a+1]];
+ tmp[a+2]=Inv_Sbox1[tmp[a+2]];
+ tmp[a+3]=Inv_Sbox1[tmp[a+3]];
+ }
-void rc4key(uchar *key, uchar *sc, int size_DK) {
- for(int i=0;i<256;i++) {
- sc[i]=i;
- }
+ for(int a=0;a<h;a+=4) {
+ invfX[a]=tmp[a]^RM1[a]^IV1[a];
+ invfX[a+1]=tmp[a+1]^RM1[a+1]^IV1[a+1];
+ invfX[a+2]=tmp[a+2]^RM1[a+2]^IV1[a+2];
+ invfX[a+3]=tmp[a+3]^RM1[a+3]^IV1[a+3];
- uchar j0 = 0;
- for(int i0=0; i0<256; i0++) {
- j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
- uchar tmp = sc[i0];
- sc[i0] = sc[j0 ];
- sc[j0] = tmp;
- }
-}
+ }
+ 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];
+ }
-void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
+ 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];
+ }
- //sc=1:len;
+ 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];
+ }
-
- for (int i=0;i<len;i++) {
- sc[i]=i;
}
- for (int it = 0; it < rp; it++) {
- int j0 = 1;
- for(int i0 = 0; i0<len; i0++) {
- j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
- int tmp = sc[i0];
- sc[i0] = sc[j0];
- sc[j0] = tmp;
- }
+
- }
-}
-void prga(uchar *sc, int ldata, uchar *r) {
- uchar i0=0;
- uchar j0=0;
- for (int it=0; it<ldata; it++) {
- i0 = ((i0+1)&0xFE); //%255);
- j0 = (j0 + sc[i0])&0xFF;
- uchar tmp = sc[i0];
- sc[i0] = sc[j0];
- sc[j0] = tmp;
- r[it]=sc[(sc[i0]+sc[j0])&0xFF];
- }
}
+
+
template<int h>
-void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
+void encrypt_cbc_rm(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;
-
+ uchar tmp[h];
+
+ for(int a=0;a<h;a+=4) {
+ IV1[a]=RM[h+a];
+ IV1[a+1]=RM[h+a+1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fX[a+3]^Y[a+3]^IV2[a+3]];
+
+ }
+ */
+
+ for(int a=0;a<h;a+=4) {
+ gY[a]=Sbox1[tmp[a]^RM2[a]];
+ gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
+ gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
+ gY[a+3]=Sbox1[tmp[a+3]^RM2[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[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_ecb(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) {
+void decrypt_cbc_rm(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;
+ uchar tmp[h];
+
+ for(int a=0;a<h;a+=4) {
+ IV1[a]=RM[h+a];
+ IV1[a+1]=RM[h+a+1];
+ IV1[a+2]=RM[h+a+2];
+ IV1[a+3]=RM[h+a+3];
+ }
+
+ for(int a=0;a<h;a+=4) {
+ IV2[a]=RM[h*h+a];
+ IV2[a+1]=RM[h*h+a+1];
+ IV2[a+2]=RM[h*h+a+2];
+ IV2[a+3]=RM[h*h+a+3];
+
+ }
+
+
for(int it=0;it<len/2;it++) {
int ind1=Pbox[it]*h;
RM1=&RM[PboxSRM[it]*h];
RM2=&RM[h*h+PboxSRM[it]*h];
+
for(int a=0;a<h;a+=4) {
fX[a+3]=seq_in[ind1+a+3];
}
+
for(int a=0;a<h;a+=4) {
- invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
- invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
- invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
- invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
- }
+ tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
+ tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
+ tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
+ tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
+ }
+
+
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Inv_Sbox2[tmp[a]];
+ tmp[a+1]=Inv_Sbox2[tmp[a+1]];
+ tmp[a+2]=Inv_Sbox2[tmp[a+2]];
+ tmp[a+3]=Inv_Sbox2[tmp[a+3]];
+ }
for(int a=0;a<h;a+=4) {
- invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
- invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
- invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
- invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3];
+ invgY[a]=tmp[a]^fX[a]^IV2[a];
+ invgY[a+1]=tmp[a+1]^fX[a+1]^IV2[a+1];
+ invgY[a+2]=tmp[a+2]^fX[a+2]^IV2[a+2];
+ invgY[a+3]=tmp[a+3]^fX[a+3]^IV2[a+3];
+ }
+
+
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
+ tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
+ tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
+ tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
+
+ }
+
+
+ for(int a=0;a<h;a+=4) {
+ tmp[a]=Inv_Sbox1[tmp[a]];
+ tmp[a+1]=Inv_Sbox1[tmp[a+1]];
+ tmp[a+2]=Inv_Sbox1[tmp[a+2]];
+ tmp[a+3]=Inv_Sbox1[tmp[a+3]];
+
+ }
+
+
+
+
+ for(int a=0;a<h;a+=4) {
+ invfX[a]=tmp[a]^RM1[a]^IV1[a];
+ invfX[a+1]=tmp[a+1]^RM1[a+1]^IV1[a+1];
+ invfX[a+2]=tmp[a+2]^RM1[a+2]^IV1[a+2];
+ invfX[a+3]=tmp[a+3]^RM1[a+3]^IV1[a+3];
}
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];
+ }
}
+/*
+
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) {
}
+*/
+
int main(int argc, char** argv) {
for(int i=1; i<argc; i++){
if(strncmp(argv[i],"nb",2)==0) nb_test = atoi(&(argv[i][2])); //nb of test
- if(strncmp(argv[i],"cbc",3)==0) cbc = atoi(&(argv[i][3])); //CBC ? 1 otherwise CBC like
+ if(strncmp(argv[i],"cbc",3)==0) cbc=1;
+ if(strncmp(argv[i],"cbcprng",7)==0) {cbcprng=1;cbc=0;}
+ if(strncmp(argv[i],"ecb",3)==0) ecb = 1;
+ if(strncmp(argv[i],"ecbprng",7)==0) {ecbprng=1; ecb=0;}
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
}
-/* printf("nb times %d\n",nb_test);
- printf("ctr %d\n",ctr);
+ printf("nb times %d\n",nb_test);
+ printf("cbc %d\n",cbc);
+ printf("cbcprng %d\n",cbcprng);
+ printf("ecb %d\n",ecb);
printf("h %d\n",h);
printf("lena %d\n",lena);
printf("size_buf %d\n",size_buf);
-*/
+
int h2=h*h;
uchar Sbox2[256];
uchar Inv_Sbox1[256];
uchar Inv_Sbox2[256];
- uchar sc[256];
+ uchar sc[h2*2];
uchar RM[h2*2];
- uint myrand=0;
+ ulong myrand=0;
double time_encrypt=0;
myrand=0;
- for(int i=0;i<32;i++) {
+ for(int i=0;i<64;i++) {
myrand|=DK[i]&1;
myrand<<=1;
}
- uint myrand_copy=myrand;
-
+ lehmer64_seed(myrand);
time_encrypt=0;
t=TimeStart();
case 4:
for(i=0;i<nb_test;i++)
{
+ if(cbcprng)
+ encrypt_cbc_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
if(cbc)
- encrypt_cbc<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
- else
+ encrypt_cbc_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
encrypt_ecb<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
}
break;
case 8:
for(i=0;i<nb_test;i++)
{
+ if(cbcprng)
+ encrypt_cbc_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
if(cbc)
- encrypt_cbc<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
- else
+ encrypt_cbc_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
encrypt_ecb<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
}
break;
case 16:
for(i=0;i<nb_test;i++)
{
+ if(cbcprng)
+ encrypt_cbc_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
if(cbc)
- encrypt_cbc<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
- else
+ encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
encrypt_ecb<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
}
break;
case 32:
for(i=0;i<nb_test;i++)
{
+ if(cbcprng)
+ encrypt_cbc_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
if(cbc)
- encrypt_cbc<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
- else
+ encrypt_cbc_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
encrypt_ecb<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
}
break;
case 64:
for(i=0;i<nb_test;i++)
{
+ if(cbcprng)
+ encrypt_cbc_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
if(cbc)
- encrypt_cbc<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
- else
+ encrypt_cbc_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
encrypt_ecb<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
}
case 128:
for(i=0;i<nb_test;i++)
{
+ if(cbcprng)
+ encrypt_cbc_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
if(cbc)
- encrypt_cbc<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
- else
+ encrypt_cbc_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
encrypt_ecb<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ }
+ break;
+ case 256:
+ for(i=0;i<nb_test;i++)
+ {
+ if(cbcprng)
+ encrypt_cbc_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(cbc)
+ encrypt_cbc_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+ if(ecb)
+ encrypt_ecb<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+
}
break;
}
}
-
+ lehmer64_seed(myrand);
time_decrypt=0;
t=TimeStart();
switch(h) {
case 4:
for(i=0;i<nb_test;i++) {
+ if(cbcprng)
+ decrypt_cbc_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
if(cbc)
- decrypt_cbc<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
- else
+ decrypt_cbc_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(ecb)
decrypt_ecb<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 8:
for(i=0;i<nb_test;i++) {
+ if(cbcprng)
+ decrypt_cbc_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
if(cbc)
- decrypt_cbc<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
- else
+ decrypt_cbc_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(ecb)
decrypt_ecb<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
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,myrand,0);
if(cbc)
- decrypt_cbc<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
- else
+ decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(ecb)
decrypt_ecb<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 32:
for(i=0;i<nb_test;i++) {
if(cbc)
- decrypt_cbc<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ decrypt_cbc_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
else
decrypt_ecb<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 64:
for(i=0;i<nb_test;i++) {
+ if(cbcprng)
+ decrypt_cbc_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
if(cbc)
- decrypt_cbc<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
- else
+ decrypt_cbc_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(ecb)
decrypt_ecb<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
case 128:
for(i=0;i<nb_test;i++) {
+ if(cbcprng)
+ decrypt_cbc_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
if(cbc)
- decrypt_cbc<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
- else
+ decrypt_cbc_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(ecb)
decrypt_ecb<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
}
break;
+ case 256:
+ for(i=0;i<nb_test;i++) {
+ if(cbcprng)
+ decrypt_cbc_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(cbc)
+ decrypt_cbc_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ if(ecb)
+ decrypt_ecb<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+ }
+ break;
}
time_decrypt+=TimeStop(t);