Cryptography Reference
In-Depth Information
void md5_block_operate( const unsigned char *input,
unsigned int hash[ MD5_RESULT_SIZE ] )
{
int a, b, c, d, x_i, s_i;
int i, j;
unsigned int x[ 16 ];
unsigned int tmp_hash[ MD5_RESULT_SIZE ];
memcpy( tmp_hash, hash, MD5_RESULT_SIZE * sizeof( unsigned int ) );
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 ) ];
}
for ( i = 0; i < 64; i++ )
{
a = 3 - ( ( i + 3 ) % 4 );
b = 3 - ( ( i + 2 ) % 4 );
c = 3 - ( ( i + 1 ) % 4 );
d = 3 - ( i % 4 );
if ( i < 16 )
{
tmp_hash[ a ] += F( tmp_hash[ b ], tmp_hash[ c ], tmp_hash[ d ] );
x_i = i;
}
else if ( i < 32 )
{
tmp_hash[ a ] += G( tmp_hash[ b ], tmp_hash[ c ], tmp_hash[ d ] );
x_i = ( 1 + ( ( i - 16 ) * 5 ) ) % 16;
}
else if ( i < 48 )
{
tmp_hash[ a ] += H( tmp_hash[ b ], tmp_hash[ c ], tmp_hash[ d ] );
x_i = ( 5 + ( ( i - 32 ) * 3 ) ) % 16;
}
else
{
tmp_hash[ a ] += I( tmp_hash[ b ], tmp_hash[ c ], tmp_hash[ d ] );
x_i = ( ( i - 48 ) * 7 ) % 16;
}
s_i = s[ i / 16 ][ i % 4 ];
tmp_hash[ a ] += x[ x_i ] + ( unsigned int )
( BASE_T * fabs( sin( ( double ) i + 1 ) ) );
tmp_hash[ a ] = ( tmp_hash[ a ] << s_i ) | ( tmp_hash[ a ] >> ( 32 - s_i ) );
(Continued)
Search WWH ::




Custom Search