/* arcfour.c --- The arcfour stream cipher
- * Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ * Copyright (C) 2000-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this file; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * along with this file; if not, see <http://www.gnu.org/licenses/>.
*
*/
* ISBN 0-471-11709-9. Pages 397 ff.
*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
#include "arcfour.h"
void
arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf,
- size_t length)
+ size_t length)
{
- size_t i = context->idx_i;
- size_t j = context->idx_j;
+ uint8_t i = context->idx_i;
+ uint8_t j = context->idx_j;
char *sbox = context->sbox;
for (; length > 0; length--)
{
char t;
- i = (i + 1) % ARCFOUR_SBOX_SIZE;
- j = (j + sbox[i]) % ARCFOUR_SBOX_SIZE;
+ i++;
+ j += sbox[i];
t = sbox[i];
sbox[i] = sbox[j];
sbox[j] = t;
*outbuf++ = (*inbuf++
- ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]);
+ ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]);
}
context->idx_i = i;
sbox[i] = sbox[j];
sbox[j] = t;
if (++k == keylen)
- k = 0;
+ k = 0;
}
}