Cryptography Reference
In-Depth Information
else if ( !( strcmp( argv[ 1 ], “-sha1” ) ) )
{
hash = malloc( sizeof( int ) * SHA1_RESULT_SIZE );
memcpy( hash, sha1_initial_hash, sizeof( int ) * SHA1_RESULT_SIZE );
hash_len = SHA1_RESULT_SIZE;
digest_hash( decoded_input, decoded_len, hash,
sha1_block_operate, sha1_finalize );
}
else
{
fprintf( stderr, “unsupported digest algorithm '%s'\n”, argv[ 1 ] );
exit( 0 );
}
{
unsigned char *display_hash = ( unsigned char * ) hash;
for ( i = 0; i < ( hash_len * 4 ); i++ )
{
printf( “%.02x”, display_hash[ i ] );
}
printf( “\n” );
}
free( hash );
free( decoded_input );
return 0;
}
#endif
Compile and run this to see it in action:
jdavies@localhost$ digest -md5 abc
900150983cd24fb0d6963f7d28e17f72
jdavies@localhost$ digest -sha1 abc
a9993e364706816aba3e25717850c26c9cd0d89d
Notice that the SHA-1 output is a bit longer than the MD5 output; MD5 gives
you 128 bits, and SHA-1 gives you 160.
Even More Collision Resistance with the SHA-256
Digest Algorithm
Even SHA, with its 160 bits of output, is no longer considered suffi cient to effec-
tively guard against hash collisions. There have been three new standardized
SHA extensions named SHA-256 , SHA-384 and SHA-512. In general, the SHA- n
algorithm produces n bits of output. You don't examine them all here, but go
ahead and add support for SHA-256 because it's rapidly becoming the minimum
Search WWH ::




Custom Search