59 #if defined( INC_ALL )
78 unsigned char *outdata)
88 #if defined(RC4_CHUNK)
120 # define RC4_STEP ( \
127 (RC4_CHUNK)d[(tx+ty)&0xff]\
130 if ( ( ((
unsigned long)indata & (
sizeof(RC4_CHUNK)-1)) |
131 ((
unsigned long)outdata & (
sizeof(RC4_CHUNK)-1)) ) == 0 )
133 RC4_CHUNK ichunk,otp;
134 const union {
long one;
char little; } is_endian = {1};
164 if (!is_endian.little)
166 # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
167 for (;len&-
sizeof(RC4_CHUNK);len-=
sizeof(RC4_CHUNK))
169 ichunk = *(RC4_CHUNK *)indata;
170 otp = RC4_STEP<<BESHFT(0);
171 otp |= RC4_STEP<<BESHFT(1);
172 otp |= RC4_STEP<<BESHFT(2);
173 otp |= RC4_STEP<<BESHFT(3);
174 if (
sizeof(RC4_CHUNK)==8)
176 otp |= RC4_STEP<<BESHFT(4);
177 otp |= RC4_STEP<<BESHFT(5);
178 otp |= RC4_STEP<<BESHFT(6);
179 otp |= RC4_STEP<<BESHFT(7);
181 *(RC4_CHUNK *)outdata = otp^ichunk;
182 indata +=
sizeof(RC4_CHUNK);
183 outdata +=
sizeof(RC4_CHUNK);
187 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
189 ichunk = *(RC4_CHUNK *)indata;
190 ochunk = *(RC4_CHUNK *)outdata;
193 mask <<= (
sizeof(RC4_CHUNK)-len)<<3;
194 switch (len&(
sizeof(RC4_CHUNK)-1))
196 case 7: otp = RC4_STEP<<i, i-=8;
197 case 6: otp |= RC4_STEP<<i, i-=8;
198 case 5: otp |= RC4_STEP<<i, i-=8;
199 case 4: otp |= RC4_STEP<<i, i-=8;
200 case 3: otp |= RC4_STEP<<i, i-=8;
201 case 2: otp |= RC4_STEP<<i, i-=8;
202 case 1: otp |= RC4_STEP<<i, i-=8;
210 ochunk |= (otp^ichunk) & mask;
211 *(RC4_CHUNK *)outdata = ochunk;
219 # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
220 for (;len&-
sizeof(RC4_CHUNK);len-=
sizeof(RC4_CHUNK))
222 ichunk = *(RC4_CHUNK *)indata;
227 if (
sizeof(RC4_CHUNK)==8)
229 otp |= RC4_STEP<<LESHFT(4);
230 otp |= RC4_STEP<<LESHFT(5);
231 otp |= RC4_STEP<<LESHFT(6);
232 otp |= RC4_STEP<<LESHFT(7);
234 *(RC4_CHUNK *)outdata = otp^ichunk;
235 indata +=
sizeof(RC4_CHUNK);
236 outdata +=
sizeof(RC4_CHUNK);
240 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
242 ichunk = *(RC4_CHUNK *)indata;
243 ochunk = *(RC4_CHUNK *)outdata;
246 mask >>= (
sizeof(RC4_CHUNK)-len)<<3;
247 switch (len&(
sizeof(RC4_CHUNK)-1))
249 case 7: otp = RC4_STEP, i+=8;
250 case 6: otp |= RC4_STEP<<i, i+=8;
251 case 5: otp |= RC4_STEP<<i, i+=8;
252 case 4: otp |= RC4_STEP<<i, i+=8;
253 case 3: otp |= RC4_STEP<<i, i+=8;
254 case 2: otp |= RC4_STEP<<i, i+=8;
255 case 1: otp |= RC4_STEP<<i, i+=8;
263 ochunk |= (otp^ichunk) & mask;
264 *(RC4_CHUNK *)outdata = ochunk;
272 #define LOOP(in,out) \
278 (out) = d[(tx+ty)&0xff]^ (in);
281 #define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
283 #define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
311 RC4_LOOP(indata,outdata,0);
if (--i == 0)
break;
312 RC4_LOOP(indata,outdata,1);
if (--i == 0)
break;
313 RC4_LOOP(indata,outdata,2);
if (--i == 0)
break;
314 RC4_LOOP(indata,outdata,3);
if (--i == 0)
break;
315 RC4_LOOP(indata,outdata,4);
if (--i == 0)
break;
316 RC4_LOOP(indata,outdata,5);
if (--i == 0)
break;
317 RC4_LOOP(indata,outdata,6);
if (--i == 0)
break;