Newer
Older
#ifdef RCSID
RCSID("$Id$");
#endif
#define SWAP(a,b) do { int _t = a; a = b; b = _t; } while(0)
void arcfour_set_key(struct arcfour_ctx *ctx, const UINT8 *key, UINT32 len)
register UINT8 j; /* Depends on the eight-bitness of these variables. */
/* Initialize context */
i = 0;
do ctx->S[i] = i; while (++i < 256);
/* Expand key */
i = j = k = 0;
do {
j += ctx->S[i] + key[k];
SWAP(ctx->S[i], ctx->S[j]);
k = (k+1) % len; /* Repeat key if needed */
} while(++i < 256);
ctx->i = ctx->j = 0;
}
void arcfour_crypt(struct arcfour_ctx *ctx, UINT8 *dest,
const UINT8 *src, UINT32 len)
register UINT8 i, j;
i++; i &= 0xff;
j += ctx->S[i]; j &= 0xff;