summaryrefslogtreecommitdiffstats
path: root/doc/rc4.doc
blob: 4b2897eb74349e9a02f39cf6e1676ead2eee68d6 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
The RC4 library.
RC4 is a stream cipher that operates on a byte stream.  It can be used with
any length key but I would recommend normally using 16 bytes.

This library requires the inclusion of 'rc4.h'.

The RC4 encryption function takes what is called an RC4_KEY as an argument.
The RC4_KEY is generated by the RC4_set_key function from the key bytes.

RC4, being a stream cipher, does not have an encryption or decryption mode.
It produces a stream of bytes that the input stream is xor'ed against and
so decryption is just a case of 'encrypting' again with the same key.

I have only put in one 'mode' for RC4 which is the normal one.  This means
there is no initialisation vector and there is no feedback of the cipher
text into the cipher.  This implies that you should not ever use the
same key twice if you can help it.  If you do, you leave yourself open to
known plain text attacks; if you know the plain text and
corresponding cipher text in one message, all messages that used the same
key can have the cipher text decoded for the corresponding positions in the
cipher stream.

The main positive feature of RC4 is that it is a very fast cipher; about 4
times faster that DES.  This makes it ideally suited to protocols where the
key is randomly chosen, like SSL.

The functions are as follows:

void RC4_set_key(
RC4_KEY *key;
int len;
unsigned char *data);
	This function initialises the RC4_KEY structure with the key passed
	in 'data', which is 'len' bytes long.  The key data can be any
	length but 16 bytes seems to be a good number.

void RC4(
RC4_KEY *key;
unsigned long len;
unsigned char *in;
unsigned char *out);
	Do the actual RC4 encryption/decryption.  Using the 'key', 'len'
	bytes are transformed from 'in' to 'out'.  As mentioned above,
	decryption is the operation as encryption.