]> git.tdb.fi Git - libs/crypto.git/blobdiff - source/md5.cpp
Use BlockHash as base class of MD5 as well
[libs/crypto.git] / source / md5.cpp
index c989526e03ac515466a5fd55472ff0dabe82bc03..fdf517f8678dcc16212a79cffff2e95c050238a6 100644 (file)
@@ -10,28 +10,28 @@ namespace Crypto {
 namespace {
 
 template<unsigned N>
 namespace {
 
 template<unsigned N>
-inline UInt32 func(UInt32, UInt32, UInt32);
+UInt32 func(UInt32, UInt32, UInt32);
 
 template<>
 
 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<>
 {
        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<>
 {
        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<>
 {
        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);
 }
 {
        return y^(x|~z);
 }
@@ -77,49 +77,10 @@ void MD5::init()
        buffer[2] = 0x98badcfe;
        buffer[3] = 0x10325476;
        processed_bytes = 0;
        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(!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
 }
 
 unsigned MD5::get_digest(char *digest, unsigned len) const