Cryptography Reference
In-Depth Information
unsigned int H( unsigned int x, unsigned int y, unsigned int z )
{
return ( x ^ y ^ z );
}
unsigned int I( unsigned int x, unsigned int y, unsigned int z )
{
return y ^ ( x | ~z );
}
The purpose of these functions is simply to shuffl e bits in an unpredictable
way; don't look for any deep meaning here.
Notice that this is implemented using unsigned integers. As it turns out,
MD5, unlike any of the other cryptographic algorithms in this topic, operates
on little-endian numbers, which makes implementation a tad easier on an Intel-
based machine — although MD5 has an odd concept of “little endian” in places.
The function F is invoked 16 times — once for each input block — and then
G is invoked 16 times, and then H, and then I. So, what are the inputs to F, G,
H, and I? They're actually permutations of A, B, C, and D — remember that the
hash was referred to as A, B, C, and D. The results of F, G, H, and I are added to
A, B, C, and D along with each of the input blocks, as well as a set of constants,
shifted, and added again. In all cases, adds are performed modulo 32 — that is,
they're allowed to silently overfl ow in a 32-bit register. After all 64 operations,
the fi nal values of A, B, C, and D are concatenated together to become the hash
of a 512-bit input block.
More specifi cally, each of the 64 transformations on A, B, C, and D involve
applying one of the four functions F, G, H, or I to some permutation of A, B, C,
or D, adding it to the other, adding the value of input block (i % 4), adding the
value of 4294967296 * abs(sin(i)), rotating by a per-round amount, and adding
the whole mess to yet one more of the A, B, C, or D hash blocks.
A Secure Hashing Example
If this is all making your head spin, it's supposed to. Secure hashing algo-
rithms are necessarily complex. In general, they derive their security from
their complexity:
1. Definea ROUND macro that will be expanded 64 times, as shown in
Listing 4-3.
Listing 4-3: “md5.c” ROUND macro
#define BASE_T 4294967296.0
#define ROUND( F, a, b, c, d, k, s, i ) \
a = ( a + F( b, c, d ) + x[ k ] + \
(Continued)
 
Search WWH ::




Custom Search