X-Git-Url: http://git.tdb.fi/?p=libs%2Fcrypto.git;a=blobdiff_plain;f=source%2Fmd5.cpp;h=fdf517f8678dcc16212a79cffff2e95c050238a6;hp=c989526e03ac515466a5fd55472ff0dabe82bc03;hb=af23707dc5f78bc2889252ce04d486a3ddfdaeca;hpb=d3e8e21dbc3091c96e4d36d3b7308745a2f81314 diff --git a/source/md5.cpp b/source/md5.cpp index c989526..fdf517f 100644 --- a/source/md5.cpp +++ b/source/md5.cpp @@ -10,28 +10,28 @@ namespace Crypto { namespace { template -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); } @@ -77,49 +77,10 @@ void MD5::init() 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