Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

MD4.cpp

Go to the documentation of this file.
00001 //
00002 // Free implementation of the MD4 hash algorithm
00003 // MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
00004 //
00005 
00006 /*
00007         Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
00008 
00009         License to copy and use this software is granted provided that it
00010         is identified as the "RSA Data Security, Inc. MD4 Message-Digest
00011         Algorithm" in all material mentioning or referencing this software
00012         or this function.
00013 
00014         License is also granted to make and use derivative works provided
00015         that such works are identified as "derived from the RSA Data
00016         Security, Inc. MD4 Message-Digest Algorithm" in all material
00017         mentioning or referencing the derived work.  
00018 
00019         RSA Data Security, Inc. makes no representations concerning either
00020         the merchantability of this software or the suitability of this
00021         software for any particular purpose. It is provided "as is"
00022         without express or implied warranty of any kind.  
00023 
00024         These notices must be retained in any copies of any part of this
00025         documentation and/or software.  
00026 */
00027 
00028 #include "StdAfx.h"
00029 //#include "Shareaza.h"
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 // MD4 initialization. Begins an MD4 operation, writing a new context
00050 
00051 void CMD4::Reset()
00052 {
00053         // Clear counts
00054         m_nCount[0] = m_nCount[1] = 0;
00055         // Load magic initialization constants
00056         m_nState[0] = 0x67452301;
00057         m_nState[1] = 0xefcdab89;
00058         m_nState[2] = 0x98badcfe;
00059         m_nState[3] = 0x10325476;
00060 }
00061 
00062 // Fetch hash
00063 void CMD4::GetHash(MD4* pHash)
00064 {
00065         memcpy(pHash->b, m_nState, 16);
00066 }
00067 
00068 // MD4 block update operation. Continues an MD4 message-digest
00069 //     operation, processing another message block, and updating the
00070 //     context
00071 void CMD4::Add(LPCVOID pData, DWORD nLength)
00072 {
00073         MD4_Add_p5(this, pData, nLength);
00074 }
00075 
00076 // MD4 finalization. Ends an MD4 message-digest operation, writing the
00077 //     the message digest and zeroizing the context.
00078 
00079 void CMD4::Finish()
00080 {
00081         unsigned int bits[2], index = 0;
00082         // Save number of bits
00083         bits[1] = ( m_nCount[1] << 3 ) + ( m_nCount[0] >> 29);
00084         bits[0] = m_nCount[0] << 3;
00085         // Pad out to 56 mod 64.
00086         index = (unsigned int)(m_nCount[0] & 0x3f);
00087         MD4_Add_p5(this, MD4_PADDING, (index < 56) ? (56 - index) : (120 - index) );
00088         // Append length (before padding)
00089         MD4_Add_p5(this, bits, 8 );
00090 }

Generated on Thu Dec 15 10:39:44 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2