Cryptography Reference
In-Depth Information
has been widely implemented in SSL; this is the RC4 algorithm, examined in
the next section.
Understanding and Implementing the RC4 Algorithm
RC4 was invented by Ron Rivest (whose name comes up again in Chapter 3),
who also invented RC2 (and RC5 and RC6). RC4 is actually not an open standard
like AES and DES are. In fact, in spite of the fact that it's specifi cally named as
one of the fi ve encryption algorithms available for use with SSL, the details of
how RC4 works have never been offi cially published. However, they've been
widely distributed, and an IETF draft specifi cation of the algorithm — referred
to as an RC4-compatible algorithm for trademark purposes — has been submit-
ted for review although it's not yet offi cially published.
After the complexity of DES and AES, you may be pleasantly surprised at the
simplicity of RC4. First, a 256-byte key schedule is computed from the key, which
can be essentially any length. After that, each byte of the plaintext is XORed
with one byte of the key schedule after permuting the key schedule. This goes
on until the plaintext is completely encrypted. Decrypting is the exact same
process. Because there's no concept of CBC, there's no need for an initialization
vector either. An example of the RC4 operation is shown in Listing 2-46.
Listing 2-46: “rc4.c” rc4_operate
static void rc4_operate( const unsigned char *plaintext,
int plaintext_len,
unsigned char *ciphertext,
const unsigned char *key,
int key_len )
{
int i, j;
unsigned char S[ 256 ];
unsigned char tmp;
// KSA (key scheduling algorithm)
for ( i = 0; i < 256; i++ )
{
S[ i ] = i;
}
S is the key schedule. The fi rst step in computing the key schedule is to ini-
tialize each element with its index as shown in Figure 2-14:
012345678...
012345678...
Figure 2-14: Initial RC4 key schedule
 
Search WWH ::




Custom Search