public
DESCRIPTION: Gets the MD5 checksum for data in a BYTE array
RETURNS: CString : the hexadecimal MD5 checksum for the specified data
ARGUMENTS: BYTE* pBuf : pointer to the BYTE array
UINT nLength : number of BYTEs of data to be checksumed
NOTES: Provides an interface to the CMD5Checksum class. Any data that can
be cast to a BYTE array of known length can be checksummed by this
function. Typically, CString and char arrays will be checksumed,
although this function can be used to check the integrity of any BYTE array.
A buffer of zero length can be checksummed; all buffers of zero length
will return the same checksum.
*****************************************************************************************/
CString CMD5Checksum::GetMD5(BYTE* pBuf, UINT nLength)
{
//entry invariants
AfxIsValidAddress(pBuf,nLength,FALSE);
//calculate and return the checksum
CMD5Checksum MD5Checksum;
MD5Checksum.Update( pBuf, nLength );
return MD5Checksum.Final();
}
/*****************************************************************************************
FUNCTION: CMD5Checksum::RotateLeft
DETAILS: private
DESCRIPTION: Rotates the bits in a 32 bit DWORD left by a specified amount
RETURNS: The rotated DWORD
ARGUMENTS: DWORD x : the value to be rotated
int n : the number of bits to rotate by
*****************************************************************************************/
DWORD CMD5Checksum::RotateLeft(DWORD x, int n)
{
//check that DWORD is 4 bytes long - true in Visual C++ 6 and 32 bit Windows
ASSERT( sizeof(x) == 4 );
//rotate and return x
return (x << n) | (x >> (32-n));
}
/*****************************************************************************************
FUNCTION: CMD5Checksum::FF
DETAILS: protected
DESCRIPTION: Implementation of basic MD5 transformation algorithm
RETURNS: none
ARGUMENTS: DWORD &A, B, C, D : Current (partial) checksum
DWORD X : Input data
DWORD S : MD5_SXX Transformation constant
DWORD T : MD5_TXX Transformation constant
NOTES: None
*****************************************************************************************/
void CMD5Checksum::FF( DWORD& A, DWORD B, DWORD C, DWORD D, DWORD X, DWORD S, DWORD T)
{
DWORD F = (B & C) | (~B & D);
A += F + X + T;
A = RotateLeft(A, S);
A += B;
}
/*****************************************************************************************
FUNCTION: CMD5Checksum::GG
DETAILS: protected
DESCRIPTION: Implementation of basic MD5 transformation algorithm
RETURNS