Cryptography Reference
In-Depth Information
4. After W has been computed, the individual fi ve hash integers are copied
into a , b , c , d , and e for computation; at each round, a new T value is
computed according to
T = ( ( a << 5 ) | ( a >> 27 ) ) e k[ ( t / 20 ) ] W[ t ]
ch/parity/maj(b,c,d);
5. a , b , c , d , and e are then rotated through each other, just as in MD5, and, for
good measure, c is rotated left 30 positions as well. Although the mechan-
ics are slightly different, this is very similar to what was done with MD5.
You don't really have to try to make sense of the mechanics of this. It's sup-
posed to be impossible to do so. As long as the details are correct, you can safely
think of the block operation function as a true black-box function.
Understanding the SHA-1 Input Processing Function
The input processing function of SHA-1 is almost identical to that of MD5. The
length is appended, in bits, at the very end of the last block, each block is 512
bits, the hash must be initialized to a standard value before input begins, and
the hash computations of each block are added to one another, modulo 32, to
produce the fi nal result. The function in Listing 4-9, which computes SHA-1
hashes of a given input block, differs from md5_hash in only a few places, which
are highlighted in bold .
Listing 4-9: “sha.c” SHA-1 hash algorithm
#define SHA1_INPUT_BLOCK_SIZE 56
#define SHA1_BLOCK_SIZE 64
unsigned int sha1_initial_hash[ ] = {
0x67452301,
0xefcdab89,
0x98badcfe,
0x10325476,
0xc3d2e1f0
};
int sha1_hash( unsigned char *input, int len,
unsigned int hash[ SHA1_RESULT_SIZE ] )
{
unsigned char padded_block[ SHA1_BLOCK_SIZE ];
int length_in_bits = len * 8;
hash[ 0 ] = sha1_initial_hash[ 0 ];
hash[ 1 ] = sha1_initial_hash[ 1 ];
 
Search WWH ::




Custom Search