Cryptography Reference
In-Depth Information
des_encrypt
and
des_decrypt
as you did to
des_operate
. The benefi t of
this approach is that
des_encrypt
and
des3_encrypt
have identical function
signatures. Later on, when you actually start developing the SSL framework,
you take advantage of this and use function pointers to refer to your bulk
encryption routines. You see this at work in the next section on AES, which
is the last block cipher bulk encryption routine you examine. Notice also
that I've removed the padding; for SSL purposes, you want to leave the pad-
ding up to the caller.
You can easily extend the test main routine in des.c to perform 3DES as shown
in Listing 2-28; just check the length of the input key. If the input key is eight
bytes, perform “single DES”; if it's 24 bytes, perform 3DES. Note that the block
size, and therefore the initialization vector, is still eight bytes for 3DES; it's just
the key that's longer.
Listing 2-28:
“des.c” main routine with 3DES support
...
if ( !( strcmp( argv[ 1 ], “-e” ) ) )
{
if ( key_len == 24 )
{
des3_encrypt( input, input_len, output, iv, key );
}
else
{
des_encrypt( input, input_len, output, iv, key );
}
show_hex( output, out_len );
}
else if ( !( strcmp( argv[ 1 ], “-d” ) ) )
{
if ( key_len == 24 )
{
des3_decrypt( input, input_len, output, iv, key );
}
else
{
des_decrypt( input, input_len, output, iv, key );
}
For example,
[jdavies@localhost ssl]$ ./des -e twentyfourcharacterinput initialz abcdefgh
c0c48bc47e87ce17
[jdavies@localhost ssl]$ ./des -d twentyfourcharacterinput initialz \
0xc0c48bc47e87ce17
6162636465666768
Search WWH ::
Custom Search