Next Previous Table Of Contents

The MD5 Class

#include <chnhash/md5.hpp>

Overview

The MD5 class provides an implementation of Rivest's MD5 algorithm as specified in RFC 1321
[RIV]. As the MD5 class is a subclass of the ChainHash and the MD4ish classes, the variables and methods presented there are not redescribed here. Note that collisions in the MD5 compression function have recently been discovered [DOBb], so the use of this hash function is deprecated. Such a collision is demonstrated by the program tests/collide/md5cmpc.cpp. Since this hash function is ubiquitious, however, it is included for the sake of compatability.

Public Methods

Constructor

MD5();
Creates an MD5 instance and initializes the chain variables to values specified in RFC 1321
[RIV].

Destructor

~MD5();
Frees the chain variables.

Compress

static void Compress(const u32* iv, const u32* block, u32* result);
Calculates the value of the MD5 compression function at the point determined by the starting chain variable values pointed to by iv and the block pointed to by block. The result is written into the dwords pointed to by result.

More speficially, iv[0] should equal a, iv[1] should equal b, iv[2] should equal c, and iv[3] should equal d, all before the updating. Within block[i], the jth most significant byte should be equal to the 4*i+(4-j)th byte of the block. On return, result[0] will equal a, result[1] will equal b, result[2] will equal c, and result[3] will equal d, all after the updating.

Compress

static void Compress(const void* iv, const void* block, void* result);
This method writes into the memory pointed to by result a low endian byte string giving the concatenation of the new values of the chain variables when the compression function is evaluated at the point determined by the block pointed to by block, and concatenation of the chain variables pointed to by iv.

iv is to point to a low endian byte string giving the concatenation of the chain variables, while block is to point to a byte string giving the value of the block in the order

b[0]b[1]b[2]b[3]...b[63].

Next Previous Table Of Contents