Cryptography Reference
In-Depth Information
void aes_256_decrypt( const unsigned char *ciphertext,
const int ciphertext_len,
unsigned char plaintext[],
const unsigned char *iv,
const unsigned char *key )
{
aes_decrypt( ciphertext, ciphertext_len, plaintext, iv, key, 32 );
}
Here the function name dictates the key length. This isn't a good approach for
general scalability, but because AES is only defi ned for a few specifi c key lengths,
you're safe in this case. Notice that there's no aes_192_encrypt/_decrypt pair
here. AES 192 actually isn't used in SSL, so I don't cover it here.
AES is widely supported. In fact, recent Intel chips include assembly-level
AES instructions!
Of course, you want to be able to test this out, so create a main routine in aes.c,
blocked off by an #ifdef so that this fi le can be included in other applications,
as shown in Listing 2-45:
Listing 2-45: “aes.c” main routine for testing
#ifdef TEST_AES
int main( int argc, char *argv[ ] )
{
unsigned char *key;
unsigned char *input;
unsigned char *iv;
int key_len;
int input_len;
int iv_len;
if ( argc < 5 )
{
fprintf( stderr, “Usage: %s [-e|-d] <key> <iv> <input>\n”, argv[ 0 ] );
exit( 0 );
}
key_len = hex_decode( argv[ 2 ], &key );
iv_len = hex_decode( argv[ 3 ], &iv );
input_len = hex_decode( argv[ 4 ], &input );
if ( !strcmp( argv[ 1 ], “-e” ) )
{
unsigned char *ciphertext = ( unsigned char * ) malloc( input_len );
if ( key_len == 16 )
{
aes_128_encrypt( input, input_len, ciphertext, iv, key );
}
(Continued)
 
Search WWH ::




Custom Search