Cryptography Reference
In-Depth Information
often the only option for — most wireless devices mandates its use! You should
add support for it because it's the only stream cipher defi ned for use in SSL, and
because its implementation is so simple; however, you should almost defi nitely
prefer 3DES or AES-256 for encryption of any valuable data.
As you can see, there are effectively no restrictions on the key length; the key
can be as long as 256 bytes (it could be longer, but the remaining bytes wouldn't
factor into the key scheduling algorithm). There are two standard, common key
lengths though — 40 bits and 128 bits. 40 bits is just 5 bytes (!) and is trivially
crackable. 128 bits is a decent-sized key for most crypto purposes.
Put together a simple main routine to test this, as shown in Listing 2-47.
Listing 2-47: “rc4.c” main routine for testing
#ifdef TEST_RC4
int main( int argc, char *argv[ ] )
{
unsigned char *key;
unsigned char *input;
unsigned char *output;
int key_len;
int input_len;
if ( argc < 4 )
{
fprintf( stderr, “Usage: %s [-e|-d] <key> <input>\n”, argv[ 0 ] );
exit( 0 );
}
key_len = hex_decode( argv[ 2 ], &key );
input_len = hex_decode( argv[ 3 ], &input );
output = malloc( input_len );
rc4_operate( input, input_len, output, key, key_len );
printf( “Results: “ );
show_hex( output, input_len );
free( key );
free( input );
return 0;
}
#endif
Again, you can use the hex_decode convenience function to allow you to pass
in arbitrary byte arrays and not just printable-ASCII input.
[jdavies@localhost ssl]$ ./rc4 -e abcdef abcdefghijklmnop
Results: daf70b86e76454eb975e3bfe2cce339c
 
Search WWH ::




Custom Search