From: Mikko Rasa Date: Sat, 16 Apr 2016 13:54:15 +0000 (+0300) Subject: Use BlockHash as base class of MD5 as well X-Git-Url: http://git.tdb.fi/?p=libs%2Fcrypto.git;a=commitdiff_plain Use BlockHash as base class of MD5 as well --- diff --git a/source/md5.cpp b/source/md5.cpp index 94e6ba9..fdf517f 100644 --- a/source/md5.cpp +++ b/source/md5.cpp @@ -77,39 +77,12 @@ 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)); } -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) diff --git a/source/md5.h b/source/md5.h index f47723c..32b468b 100644 --- a/source/md5.h +++ b/source/md5.h @@ -2,18 +2,16 @@ #define MSP_CRYPTO_MD5_H_ #include -#include "hash.h" +#include "blockhash.h" namespace Msp { namespace Crypto { -class MD5: public Hash +class MD5: public BlockHash<64> { private: UInt32 buffer[4]; UInt64 processed_bytes; - char unprocessed[64]; - unsigned unprocessed_bytes; static UInt32 sin_table[64]; static unsigned rotate_table[16]; @@ -28,12 +26,10 @@ private: 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: - void process_block(const char *); + virtual void process_block(const char *); template static void perform_round(UInt32 *, const UInt32 *);