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)
#define MSP_CRYPTO_MD5_H_
#include <msp/core/inttypes.h>
-#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];
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<unsigned, unsigned, unsigned>
static void perform_round(UInt32 *, const UInt32 *);