Cryptography Reference
In-Depth Information
{
return ( x & y ) ^ ( ~x & z );
}
// parity is functions 20 - 39 & 60 - 79
unsigned int parity( unsigned int x, unsigned int y, unsigned int z )
{
return x ^ y ^ z;
}
// maj is functions 40 - 59
unsigned int maj( unsigned int x, unsigned int y, unsigned int z )
{
return ( x & y ) ^ ( x & z ) ^ ( y & z );
}
#define SHA1_RESULT_SIZE 5
void sha1_block_operate( const unsigned char *block,
unsigned int hash[ SHA1_RESULT_SIZE ] )
{
unsigned int W[ 80 ];
unsigned int t = 0;
unsigned int a, b, c, d, e, T;
// First 16 blocks of W are the original 16 blocks of the input
for ( t = 0; t < 80; t++ )
{
if ( t < 16 )
{
W[ t ] = ( block[ ( t * 4 ) ] << 24 ) |
( block[ ( t * 4 ) + 1 ] << 16 ) |
( block[ ( t * 4 ) + 2 ] << 8 ) |
( block[ ( t * 4 ) + 3 ] );
}
else
{
W[ t ] = W[ t - 3 ] ^
W[ t - 8 ] ^
W[ t - 14 ] ^
W[ t - 16 ];
// Rotate left operation, simulated in C
W[ t ] = ( W[ t ] << 1 ) | ( ( W[ t ] & 0x80000000 ) >> 31 );
}
}
a = hash[ 0 ];
b = hash[ 1 ];
c = hash[ 2 ];
d = hash[ 3 ];
e = hash[ 4 ];
Search WWH ::




Custom Search