Cryptography Reference
In-Depth Information
if ( argc < 4 )
{
fprintf( stderr, “usage: %s [-sha1|md5] [0x]<key> [0x]<text>\n”, argv[ 0 ] );
exit( 0 );
}
if ( !( strcmp( argv[ 1 ], “-sha1” ) ) )
{
new_sha1_digest( &digest );
}
else if ( !( strcmp( argv[ 1 ], “-md5” ) ) )
{
new_md5_digest( &digest );
}
else
{
fprintf( stderr, “usage: %s [-sha1|md5] <key> <text>\n”, argv[ 0 ] );
exit( 1 );
}
key_len = hex_decode( argv[ 2 ], &key );
text_len = hex_decode( argv[ 3 ], &text );
hmac( key, key_len, text, text_len, &digest );
for ( i = 0; i < digest.hash_len * sizeof( int ); i++ )
{
printf( “%.02x”, ( ( unsigned char *) digest.hash )[ i ] );
}
printf( “\n” );
free( digest.hash );
free( key );
free( text );
return 0;
}
#endif
To compute an HMAC, call it like this:
jdavies@localhost$ hmac -md5 Jefe “what do ya want for nothing?”
750c783e6ab0b503eaa86e310a5db738
Where Does All of This Fit into SSL?
You may still be wondering what all this has to do with SSL. After all, you have
secure key exchange and symmetric cryptography. Where does the HMAC
function fi t in?
Search WWH ::




Custom Search