7 typedef unsigned char uchar;
9 uint64_t xorshift64( const uint64_t state)
18 static inline uint64_t splitmix64_stateless(uint64_t index) {
19 uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
20 z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
21 z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
27 struct timeval tstart;
28 gettimeofday(&tstart,0);
29 return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) );
32 double TimeStop(double t)
36 gettimeofday(&tend,0);
37 t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t;
42 uint xorshift32(const uint t)
44 /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
53 void rc4key(uchar *key, uchar *sc, int size_DK) {
55 for(int i=0;i<256;i++) {
61 for(int i0=0; i0<256; i0++) {
62 j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
70 void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
76 for (int i=0;i<len;i++) {
79 for (int it = 0; it < rp; it++) {
81 for(int i0 = 0; i0<len; i0++) {
82 j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
93 printf("%d %d \n",sizeof(__uint64_t),sizeof(ulong));
102 for(int i=0;i<64;i++)
103 DK[i]=splitmix64_stateless(i);
107 rc4key(DK, Sbox1, 8);
109 rc4key(&DK[8], Sbox2, 8);
111 const int bufsize=4096;
113 rc4keyperm(&DK[16], bufsize, 1, Pbox, 16);
121 uint64_t Val[bufsize];
122 for(int i=0;i<bufsize;i++)
123 Val[i]=splitmix64_stateless(i+DK[i&63]);
127 double t=TimeStart();
128 for(int iter=0;iter<size;iter++) {
129 for(int j=0;j<bufsize;j++) {
130 Val[j]^=xorshift64(Val[Pbox[j]])^plain[j];
136 uchar *ptr=(uchar*)Val;
137 for(int j=0;j<bufsize*8;j++)
138 ptr[j]^=Sbox2[Sbox1[ptr[j]+DK[j&63]]];
139 rc4keyperm(ptr, bufsize, 1, Pbox, 16);
144 double time=TimeStop(t);
145 printf("time %e\n",size*bufsize*8/time);