3 This file is part of the Crypto-avr-lib/microcrypt-lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * License: GPLv3 or later
24 * Description: Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
28 /* +---+---+---------------------+
29 * | i | j | ......<256>........ |
30 * +---+---+---------------------+
36 ; this function initialises the context
37 ; param1: 16-bit pointer to a ctx struct
39 ; param2: 16-bit pointer to a key
41 ; param1: 8-bit integer indicating keylength in byte
49 movw r26, r24 /* X points to ctx */
50 movw r30, r22 /* Z points to key */
52 st X+, r1 /* X points to S */
59 adiw r24, 2 /* r24:r25 points to S */
60 clr r21 /* r21 is j */
61 mov r18, r20 /* r18 is keyindex counter */
66 add r21, r19 /* j+= key[i%length] */
71 add r21, r19 /* j += S[i] */
73 dec r18 /* check the key-index counter */
77 3: /* now swap(S[i], S[j]) */ /* r19 is still S[i] */
80 adc r29, r0 /* Y points to S[j]*/
93 uint8_t arcfour_gen(arcfour_ctx_t *c){
98 c->s[c->j] = c->s[c->i];
100 return c->s[(c->s[c->j] + c->s[c->i]) & 0xff];
106 ; this function initialises the context
107 ; param1: 16-bit pointer to a ctx struct
121 st Z+, r19 /* i,j loaded&saved; X->S[i]; Z->S[0]; r20=S[i] */
124 ld r21, Z /* X->S[i]; Z->S[j]; r20=S[i]; r21=S[j]*/
129 movw r26, r24 /* X and Z point to S */