]> git.tdb.fi Git - libs/crypto.git/commitdiff
Use BlockHash as base class of MD5 as well master
authorMikko Rasa <tdb@tdb.fi>
Sat, 16 Apr 2016 13:54:15 +0000 (16:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 16 Apr 2016 13:54:48 +0000 (16:54 +0300)
source/md5.cpp
source/md5.h

index 94e6ba923a14ff93ec4b6d2a976acbaf45803a1a..fdf517f8678dcc16212a79cffff2e95c050238a6 100644 (file)
@@ -77,39 +77,12 @@ 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));
 }
 
-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
 {
        if(len<16)
 unsigned MD5::get_digest(char *digest, unsigned len) const
 {
        if(len<16)
index f47723c5b49ff619f1d6237620bb955c6ff7eba5..32b468b02ccd33f3f3b35203edcae16d40149262 100644 (file)
@@ -2,18 +2,16 @@
 #define MSP_CRYPTO_MD5_H_
 
 #include <msp/core/inttypes.h>
 #define MSP_CRYPTO_MD5_H_
 
 #include <msp/core/inttypes.h>
-#include "hash.h"
+#include "blockhash.h"
 
 namespace Msp {
 namespace Crypto {
 
 
 namespace Msp {
 namespace Crypto {
 
-class MD5: public Hash
+class MD5: public BlockHash<64>
 {
 private:
        UInt32 buffer[4];
        UInt64 processed_bytes;
 {
 private:
        UInt32 buffer[4];
        UInt64 processed_bytes;
-       char unprocessed[64];
-       unsigned unprocessed_bytes;
 
        static UInt32 sin_table[64];
        static unsigned rotate_table[16];
 
        static UInt32 sin_table[64];
        static unsigned rotate_table[16];
@@ -28,12 +26,10 @@ private:
 public:
        virtual unsigned get_digest_size() const { return 16; }
 
 public:
        virtual unsigned get_digest_size() const { return 16; }
 
-       using Hash::update;
-       virtual void update(const char *, unsigned);
        virtual unsigned get_digest(char *, unsigned) const;
 
 private:
        virtual unsigned get_digest(char *, unsigned) const;
 
 private:
-       void process_block(const char *);
+       virtual void process_block(const char *);
 
        template<unsigned, unsigned, unsigned>
        static void perform_round(UInt32 *, const UInt32 *);
 
        template<unsigned, unsigned, unsigned>
        static void perform_round(UInt32 *, const UInt32 *);