namespace {
template<unsigned N>
-inline UInt32 func(UInt32, UInt32, UInt32);
+UInt32 func(UInt32, UInt32, UInt32);
template<>
-UInt32 func<1>(UInt32 x, UInt32 y, UInt32 z)
+inline UInt32 func<1>(UInt32 x, UInt32 y, UInt32 z)
{
return (y&x) | (z&~x);
}
template<>
-UInt32 func<2>(UInt32 x, UInt32 y, UInt32 z)
+inline UInt32 func<2>(UInt32 x, UInt32 y, UInt32 z)
{
return (x&z) | (y&~z);
}
template<>
-UInt32 func<3>(UInt32 x, UInt32 y, UInt32 z)
+inline UInt32 func<3>(UInt32 x, UInt32 y, UInt32 z)
{
return x^y^z;
}
template<>
-UInt32 func<4>(UInt32 x, UInt32 y, UInt32 z)
+inline UInt32 func<4>(UInt32 x, UInt32 y, UInt32 z)
{
return y^(x|~z);
}
buffer[2] = 0x98badcfe;
buffer[3] = 0x10325476;
processed_bytes = 0;
- unprocessed_bytes = 0;
if(!sin_table[0])
for(unsigned i=0; i<64; ++i)
sin_table[i] = 4294967296.0*abs(sin((i+1)*1.0));
-
- if(!rotate_table[0])
- {
- for(unsigned i=0; i<4; ++i)
- rotate_table[i] = 7+i*5;
- for(unsigned i=0; i<4; ++i)
- rotate_table[4+i] = 5+i*4+i*i/3;
- for(unsigned i=0; i<4; ++i)
- rotate_table[8+i] = 4+i*7;
- for(unsigned i=0; i<4; ++i)
- rotate_table[12+i] = 6+i*4+i*i/3;
- }
-}
-
-void MD5::update(const char *data, unsigned len)
-{
- if(unprocessed_bytes && unprocessed_bytes+len>=64)
- {
- unsigned needed = 64-unprocessed_bytes;
- copy(data, data+needed, unprocessed+unprocessed_bytes);
- process_block(unprocessed);
- data += needed;
- len -= needed;
- unprocessed_bytes = 0;
- }
-
- while(len>=64)
- {
- process_block(data);
- data += 64;
- len -= 64;
- }
-
- if(len>0)
- {
- copy(data, data+len, unprocessed+unprocessed_bytes);
- unprocessed_bytes += len;
- }
}
unsigned MD5::get_digest(char *digest, unsigned len) const