00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "StdAfx.h"
00029
00030 #include "MD4.h"
00031
00032 CMD4::CMD4()
00033 {
00034 Reset();
00035 }
00036
00037 CMD4::~CMD4()
00038 {
00039 }
00040
00041 static unsigned char MD4_PADDING[64] = {
00042 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00043 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00044 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
00045 };
00046
00047 extern "C" void MD4_Add_p5(CMD4*, LPCVOID pData, DWORD nLength);
00048
00049
00050
00051 void CMD4::Reset()
00052 {
00053
00054 m_nCount[0] = m_nCount[1] = 0;
00055
00056 m_nState[0] = 0x67452301;
00057 m_nState[1] = 0xefcdab89;
00058 m_nState[2] = 0x98badcfe;
00059 m_nState[3] = 0x10325476;
00060 }
00061
00062
00063 void CMD4::GetHash(MD4* pHash)
00064 {
00065 memcpy(pHash->b, m_nState, 16);
00066 }
00067
00068
00069
00070
00071 void CMD4::Add(LPCVOID pData, DWORD nLength)
00072 {
00073 MD4_Add_p5(this, pData, nLength);
00074 }
00075
00076
00077
00078
00079 void CMD4::Finish()
00080 {
00081 unsigned int bits[2], index = 0;
00082
00083 bits[1] = ( m_nCount[1] << 3 ) + ( m_nCount[0] >> 29);
00084 bits[0] = m_nCount[0] << 3;
00085
00086 index = (unsigned int)(m_nCount[0] & 0x3f);
00087 MD4_Add_p5(this, MD4_PADDING, (index < 56) ? (56 - index) : (120 - index) );
00088
00089 MD4_Add_p5(this, bits, 8 );
00090 }