1 /* arcfour.c --- The arcfour stream cipher
2 * Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software
5 * This file is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2, or (at your
8 * option) any later version.
10 * This file is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this file; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 void Arcfour::stream(char *outbuf, size_t length) {
28 for (; length > 0; length--) {
36 *outbuf++ = (sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]);
43 Arcfour::Arcfour(const char *key, size_t keylen) {
46 for (i = 0; i < ARCFOUR_SBOX_SIZE; i++)
48 for (i = j = k = 0; i < ARCFOUR_SBOX_SIZE; i++) {
50 j = (j + sbox[i] + key[k]) % ARCFOUR_SBOX_SIZE;