71 unsigned char *outdata)
74 register RC4_INT x,y,tx,ty;
81 #if defined(RC4_CHUNK)
113 # define RC4_STEP ( \
120 (RC4_CHUNK)d[(tx+ty)&0xff]\
123 if ( ( ((
size_t)indata & (
sizeof(RC4_CHUNK)-1)) |
124 ((
size_t)outdata & (
sizeof(RC4_CHUNK)-1)) ) == 0 )
126 RC4_CHUNK ichunk,otp;
127 const union {
long one;
char little; } is_endian = {1};
157 if (!is_endian.little)
159 # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
160 for (;len&(0-
sizeof(RC4_CHUNK));len-=
sizeof(RC4_CHUNK))
162 ichunk = *(RC4_CHUNK *)indata;
163 otp = RC4_STEP<<BESHFT(0);
164 otp |= RC4_STEP<<BESHFT(1);
165 otp |= RC4_STEP<<BESHFT(2);
166 otp |= RC4_STEP<<BESHFT(3);
167 if (
sizeof(RC4_CHUNK)==8)
169 otp |= RC4_STEP<<BESHFT(4);
170 otp |= RC4_STEP<<BESHFT(5);
171 otp |= RC4_STEP<<BESHFT(6);
172 otp |= RC4_STEP<<BESHFT(7);
174 *(RC4_CHUNK *)outdata = otp^ichunk;
175 indata +=
sizeof(RC4_CHUNK);
176 outdata +=
sizeof(RC4_CHUNK);
180 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
182 ichunk = *(RC4_CHUNK *)indata;
183 ochunk = *(RC4_CHUNK *)outdata;
186 mask <<= (
sizeof(RC4_CHUNK)-len)<<3;
187 switch (len&(
sizeof(RC4_CHUNK)-1))
189 case 7: otp = RC4_STEP<<i, i-=8;
190 case 6: otp |= RC4_STEP<<i, i-=8;
191 case 5: otp |= RC4_STEP<<i, i-=8;
192 case 4: otp |= RC4_STEP<<i, i-=8;
193 case 3: otp |= RC4_STEP<<i, i-=8;
194 case 2: otp |= RC4_STEP<<i, i-=8;
195 case 1: otp |= RC4_STEP<<i, i-=8;
203 ochunk |= (otp^ichunk) & mask;
204 *(RC4_CHUNK *)outdata = ochunk;
212 # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
213 for (;len&(0-
sizeof(RC4_CHUNK));len-=
sizeof(RC4_CHUNK))
215 ichunk = *(RC4_CHUNK *)indata;
220 if (
sizeof(RC4_CHUNK)==8)
222 otp |= RC4_STEP<<LESHFT(4);
223 otp |= RC4_STEP<<LESHFT(5);
224 otp |= RC4_STEP<<LESHFT(6);
225 otp |= RC4_STEP<<LESHFT(7);
227 *(RC4_CHUNK *)outdata = otp^ichunk;
228 indata +=
sizeof(RC4_CHUNK);
229 outdata +=
sizeof(RC4_CHUNK);
233 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
235 ichunk = *(RC4_CHUNK *)indata;
236 ochunk = *(RC4_CHUNK *)outdata;
239 mask >>= (
sizeof(RC4_CHUNK)-len)<<3;
240 switch (len&(
sizeof(RC4_CHUNK)-1))
242 case 7: otp = RC4_STEP, i+=8;
243 case 6: otp |= RC4_STEP<<i, i+=8;
244 case 5: otp |= RC4_STEP<<i, i+=8;
245 case 4: otp |= RC4_STEP<<i, i+=8;
246 case 3: otp |= RC4_STEP<<i, i+=8;
247 case 2: otp |= RC4_STEP<<i, i+=8;
248 case 1: otp |= RC4_STEP<<i, i+=8;
256 ochunk |= (otp^ichunk) & mask;
257 *(RC4_CHUNK *)outdata = ochunk;
265 #define LOOP(in,out) \
271 (out) = d[(tx+ty)&0xff]^ (in);
274 #define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
276 #define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
304 RC4_LOOP(indata,outdata,0);
if (--i == 0)
break;
305 RC4_LOOP(indata,outdata,1);
if (--i == 0)
break;
306 RC4_LOOP(indata,outdata,2);
if (--i == 0)
break;
307 RC4_LOOP(indata,outdata,3);
if (--i == 0)
break;
308 RC4_LOOP(indata,outdata,4);
if (--i == 0)
break;
309 RC4_LOOP(indata,outdata,5);
if (--i == 0)
break;
310 RC4_LOOP(indata,outdata,6);
if (--i == 0)
break;