arcfour.c revision 2
2N/A * Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 2N/A * This file is part of Libgcrypt. 2N/A * Libgcrypt is free software; you can redistribute it and/or modify 2N/A * it under the terms of the GNU Lesser general Public License as 2N/A * published by the Free Software Foundation; either version 2.1 of 2N/A * the License, or (at your option) any later version. 2N/A * Libgcrypt is distributed in the hope that it will be useful, 2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2N/A * GNU Lesser General Public License for more details. 2N/A * You should have received a copy of the GNU Lesser General Public 2N/A * License along with this program; if not, write to the Free Software 2N/A * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 2N/A * For a description of the algorithm, see: 2N/A * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. 2N/A * ISBN 0-471-11709-9. Pages 397 ff. 2N/A i = i &
255;
/* The and-op seems to be faster than the mod-op. */ 2N/A if(
keylen <
40/
8 )
/* we want at least 40 bits */ 2N/A for (i=0; i <
256; i++ )
2N/A for (i=0; i <
256; i++ )
2N/A for (i=j=0; i <
256; i++ )
2N/A /* Test vector from Cryptlib labeled there: "from the 2N/A {
0x61,
0x8A,
0x63,
0xD2,
0xFB };
2N/A {
0xDC,
0xEE,
0x4C,
0xF9,
0x2C };
2N/A {
0xF1,
0x38,
0x29,
0xC9,
0xDE };
2N/A return "Arcfour encryption test 1 failed.";
2N/A return "Arcfour decryption test 1 failed.";