1 /* Droids-corp, Eirbot, Microb Technology 2005 - Zer0
2 * Inspired by the ARC4 implementation by Christophe Devine
3 * The original licence is below
4 * Implementation for RC4
8 * \brief Implementation for the RC4 module.
10 * \todo Test the module.
12 * \test No tests for the moment.
14 * This module provides RC4 cryptographic functions.
18 * An implementation of the ARC4 algorithm
20 * Copyright (C) 2001-2003 Christophe Devine
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 void rc4_init(uint8_t *key, uint8_t length )
55 for( i = 1; i !=0 ; i++ )
65 j = (uint8_t) ( j + a + key[k] );
66 m[i] = m[j]; m[j] = a;
67 if( ++k >= length ) k = 0;
69 for( i = 1; i != 0 ; i++ )
72 j = (uint8_t) ( j + a + key[k] );
73 m[i] = m[j]; m[j] = a;
74 if( ++k >= length ) k = 0;
80 uint8_t rc4_crypt_char(uint8_t data)
84 s.x = (uint8_t) ( s.x + 1 );
86 s.y = (uint8_t) ( s.y + a );
87 s.m[s.x] = b = s.m[s.y];
89 data ^= s.m[(uint8_t) ( a + b )];