|
|
#ifndef __MD5_DIGEST_HEADER__
#define __MD5_DIGEST_HEADER__
/////////////////////////////////////////////////////////////////////////
// MD5.cpp
// Implementation file for MD5 class
//
// This C++ Class implementation of the original RSA Data Security, Inc.
// MD5 Message-Digest Algorithm is copyright (c) 2002, Gary McNickle.
// All rights reserved. This software is a derivative of the "RSA Data
// Security, Inc. MD5 Message-Digest Algorithm"
//
// You may use this software free of any charge, but without any
// warranty or implied warranty, provided that you follow the terms
// of the original RSA copyright, listed below.
//
// Original RSA Data Security, Inc. Copyright notice
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
// rights reserved.
//
// License to copy and use this software is granted provided that it
// is identified as the "RSA Data Security, Inc. MD5 Message-Digest
// Algorithm" in all material mentioning or referencing this software
// or this function.
// License is also granted to make and use derivative works provided
// that such works are identified as "derived from the RSA Data
// Security, Inc. MD5 Message-Digest Algorithm" in all material
// mentioning or referencing the derived work.
// RSA Data Security, Inc. makes no representations concerning either
// the merchantability of this software or the suitability of this
// software for any particular purpose. It is provided "as is"
// without express or implied warranty of any kind.
// These notices must be retained in any copies of any part of this
// documentation and/or software.
/////////////////////////////////////////////////////////////////////////
typedef unsigned int u_int4;typedef unsigned short int u_int2;typedef unsigned char u_char;
char* PrintMD5(u_char md5Digest[16]);char* MD5String(char* szString);char* MD5File(char* szFilename);
class md5{ // Methods
public: md5() { Init(); } void Init(); void Update(u_char* chInput, u_int4 nInputLen); void Finalize(); u_char* Digest() { return m_Digest; }
private:
void Transform(u_char* block); void Encode(u_char* dest, u_int4* src, u_int4 nLength); void Decode(u_int4* dest, u_char* src, u_int4 nLength);
inline u_int4 rotate_left(u_int4 x, u_int4 n) { return ((x << n) | (x >> (32-n))); }
inline u_int4 F(u_int4 x, u_int4 y, u_int4 z) { return ((x & y) | (~x & z)); }
inline u_int4 G(u_int4 x, u_int4 y, u_int4 z) { return ((x & z) | (y & ~z)); }
inline u_int4 H(u_int4 x, u_int4 y, u_int4 z) { return (x ^ y ^ z); }
inline u_int4 I(u_int4 x, u_int4 y, u_int4 z) { return (y ^ (x | ~z)); }
inline void FF(u_int4& a, u_int4 b, u_int4 c, u_int4 d, u_int4 x, u_int4 s, u_int4 ac) { a += F(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
inline void GG(u_int4& a, u_int4 b, u_int4 c, u_int4 d, u_int4 x, u_int4 s, u_int4 ac) { a += G(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
inline void HH(u_int4& a, u_int4 b, u_int4 c, u_int4 d, u_int4 x, u_int4 s, u_int4 ac) { a += H(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
inline void II(u_int4& a, u_int4 b, u_int4 c, u_int4 d, u_int4 x, u_int4 s, u_int4 ac) { a += I(b, c, d) + x + ac; a = rotate_left(a, s); a += b; }
// Data
private: u_int4 m_State[4]; u_int4 m_Count[2]; u_char m_Buffer[64]; u_char m_Digest[16]; u_char m_Finalized;};
#endif
|