This source file includes following definitions.
- arcfour_stream
- arcfour_setkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include <config.h>
28
29 #include "arcfour.h"
30
31 void
32 arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf,
33 size_t length)
34 {
35 uint8_t i = context->idx_i;
36 uint8_t j = context->idx_j;
37 char *sbox = context->sbox;
38
39 for (; length > 0; length--)
40 {
41 char t;
42
43 i++;
44 j += sbox[i];
45 t = sbox[i];
46 sbox[i] = sbox[j];
47 sbox[j] = t;
48 *outbuf++ = (*inbuf++
49 ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]);
50 }
51
52 context->idx_i = i;
53 context->idx_j = j;
54 }
55
56 void
57 arcfour_setkey (arcfour_context * context, const char *key, size_t keylen)
58 {
59 size_t i, j, k;
60 char *sbox = context->sbox;
61
62 context->idx_i = context->idx_j = 0;
63 for (i = 0; i < ARCFOUR_SBOX_SIZE; i++)
64 sbox[i] = i;
65 for (i = j = k = 0; i < ARCFOUR_SBOX_SIZE; i++)
66 {
67 char t;
68 j = (j + sbox[i] + key[k]) % ARCFOUR_SBOX_SIZE;
69 t = sbox[i];
70 sbox[i] = sbox[j];
71 sbox[j] = t;
72 if (++k == keylen)
73 k = 0;
74 }
75 }