4 swap_byte (unsigned char *a
, unsigned char *b
)
6 unsigned char swapByte
;
14 prepare_key (unsigned char *key_data_ptr
, int key_data_len
, RC4_KEY
*key
)
21 state
= &key
->state
[0];
22 for (counter
= 0; counter
< 256; counter
++)
23 state
[counter
] = counter
;
28 for (counter
= 0; counter
< 256; counter
++)
30 index2
= (key_data_ptr
[index1
] + state
[counter
] + index2
) % 256;
31 swap_byte (&state
[counter
], &state
[index2
]);
33 index1
= (index1
+ 1) % key_data_len
;
38 rc4 (unsigned char *buffer_ptr
, unsigned buffer_len
, RC4_KEY
*key
)
43 unsigned char xorIndex
;
50 for (counter
= 0; counter
< buffer_len
; counter
++)
53 y
= (state
[x
] + y
) % 256;
54 swap_byte (&state
[x
], &state
[y
]);
56 xorIndex
= (state
[x
] + state
[y
]) % 256;
58 buffer_ptr
[counter
] ^= state
[xorIndex
];