Cryptography Reference
In-Depth Information
( unsigned int ) ( BASE_T * fabs( sin( ( double ) i ) ) ) ); \
a = ( a << s ) | ( a >> ( 32 - s ) ); \
a += b;
This macro takes as input the function to be performed, a , b , c and d ; a
value k which is an offset into the input; a value s which is an amount
to rotate; and a value i which is the operation number. Notice that i is
used to compute the value of 4294967296 * abs(sin(i)) on each invocation.
Technically speaking, these values ought to be precomputed because
they'll never change.
2. Using this macro, the MD5 block operation function is straightforward,
if a bit tedious, to code, as in Listing 4-4:
Listing 4-4: “md5.c” md5_block_operate function
// Size of MD5 hash in ints (128 bits)
#define MD5_RESULT_SIZE 4
void md5_block_operate( const unsigned char *input,
unsigned int hash[ MD5_RESULT_SIZE ] )
{
unsigned int a, b, c, d;
int j;
unsigned int x[ 16 ];
a = hash[ 0 ];
b = hash[ 1 ];
c = hash[ 2 ];
d = hash[ 3 ];
for ( j = 0; j < 16; j++ )
{
x[ j ] = input[ ( j * 4 ) + 3 ] << 24 |
input[ ( j * 4 ) + 2 ] << 16 |
input[ ( j * 4 ) + 1 ] << 8 |
input[ ( j * 4 ) ];
}
// Round 1
ROUND( F, a, b, c, d, 0, 7, 1 );
ROUND( F, d, a, b, c, 1, 12, 2 );
ROUND( F, c, d, a, b, 2, 17, 3 );
ROUND( F, b, c, d, a, 3, 22, 4 );
ROUND( F, a, b, c, d, 4, 7, 5 );
ROUND( F, d, a, b, c, 5, 12, 6 );
ROUND( F, c, d, a, b, 6, 17, 7 );
ROUND( F, b, c, d, a, 7, 22, 8 );
ROUND( F, a, b, c, d, 8, 7, 9 );
ROUND( F, d, a, b, c, 9, 12, 10 );
 
Search WWH ::




Custom Search