2 //g++ -O3 one_round_new.cpp pixmap_io.o -o one_round_new -std=c++11
25 typedef __uint64_t mylong;
28 typedef unsigned char uchar;
33 struct timeval tstart;
34 gettimeofday(&tstart,0);
35 return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) );
38 double TimeStop(double t)
42 gettimeofday(&tend,0);
43 t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t;
50 uint xorshift32(const uint t)
52 /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
65 /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
76 __uint128_t g_lehmer64_state;
78 inline uint64_t splitmix64_stateless(uint64_t index) {
79 uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
80 z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
81 z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
86 inline void lehmer64_seed(uint64_t seed) {
87 g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) +
88 splitmix64_stateless(seed + 1);
91 inline uint64_t lehmer64() {
92 g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
94 return g_lehmer64_state >> 64;
101 void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
103 for(int i=0;i<size_tab;i++) {
104 inv_perm_tabs[tab[i]] = i;
109 void inverse_tables_int(int *tab, int size_tab,int *inv_perm_tabs) {
111 for(int i=0;i<size_tab;i++) {
112 inv_perm_tabs[tab[i]] = i;
119 void rc4key(uchar *key, uchar *sc, int size_DK) {
121 for(int i=0;i<256;i++) {
127 for(int i0=0; i0<256; i0++) {
128 j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
137 void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
143 for (int i=0;i<len;i++) {
146 for (int it = 0; it < rp; it++) {
148 for(int i0 = 0; i0<len; i0++) {
149 j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
158 void prga(uchar *sc, int ldata, uchar *r) {
162 for (int it=0; it<ldata; it++) {
164 j0 = (j0 + sc[i0])&0xFF;
168 r[it]=sc[(sc[i0]+sc[j0])&0xFF];
179 int main(int argc, char** argv) {
187 uchar Secretkey[key_size];
189 uchar counter[key_size];
195 for(int i=0;i<key_size;i++) {
196 DK[i]=lrand48()&0xFF;
217 rc4key(DK, Sbox1, 8);
220 rc4key(&DK[8], Sbox2, 8);
222 double t=TimeStart();
226 for(int nb=0;nb<nb_test;nb++) {
228 for(int i=0;i<256;i++) {
232 for(int i=0;i<256;i++) {
233 Sbox1[i]=Sbox1[Sbox2[i]];
236 for(int i=0;i<256;i++) {
237 Sbox2[i]=Sbox2[Temp[i]];
244 cout<<"Time sub nb times "<<nb_test<<" = "<<time<<endl;