Cryptography Reference
In-Depth Information
In spite of this, MD5 is fairly popular; TLS mandates its use! Fortunately for
the TLS-using public, it does so in a reasonably secure way — or, at least, a not
terribly insecure way — so that the TLS protocol itself is not weakened by the
inclusion of MD5.
Increasing Collision Resistance with the SHA-1 Digest
Algorithm
Secure Hash Algorithm ( SHA-1 ) is similar to MD5. The only principal difference
is in the block operation itself. The other two superfi cial differences are that
SHA-1 produces a 160-bit (20-byte) hash rather than a 128-bit (16-byte) hash,
and SHA-1 deals with big-endian rather than little-endian numbers. Like MD5,
SHA-1 operates on 512-bit blocks, and the fi nal output is the sum (modulo 32) of
the results of all of the blocks. The operation itself is slightly simpler; you start
by breaking the 512-bit input into 16 4-byte values x. You then compute 80 four-
byte W values from the original input where the following is rotated left once:
W[0<t<16] = x[t] , and W[17<7<80] = W[ t - 3 ] xor W[ t - 8 ] xor
W[ t - 14 ] xor W[ t - 16 ]
This W array serves the same purpose as the 4294967296 * abs(sin(i)) com-
putation in MD5, but is a bit easier to compute and is also based on the input.
After that, the hash is split up into fi ve four-byte values a, b, c, d, and e,
which are operated on in a series of 80 rounds, similar to the operation in
MD5 — although in this case, somewhat easier to implement in a loop. At each
stage, a rotation, an addition of another hash integer, an addition of an indexed
constant, an addition of the W array, and an addition of a function whose opera-
tion depends on the round number is applied to the active hash value, and then
the hash values are cycled so that a new one becomes the active one.
Understanding SHA-1 Block Computation
If you understood the MD5 computation in Listing 4-4, you should have no
trouble making sense of the SHA-1 block computation in Listing 4-8.
Listing 4-8: “sha.c” bit manipulation, initialization and block operation
static const int k[] = {
0x5a827999, // 0 <= t <= 19
0x6ed9eba1, // 20 <= t <= 39
0x8f1bbcdc, // 40 <= t <= 59
0xca62c1d6 // 60 <= t <= 79
};
// ch is functions 0 - 19
unsigned int ch( unsigned int x, unsigned int y, unsigned int z )
(Continued)
 
Search WWH ::




Custom Search