CLucene - a full-featured, c++ search engine
API Documentation
00001 00002 // MD5.cpp 00003 // Implementation file for MD5 class 00004 // 00005 // This C++ Class implementation of the original RSA Data Security, Inc. 00006 // MD5 Message-Digest Algorithm is copyright (c) 2002, Gary McNickle. 00007 // All rights reserved. This software is a derivative of the "RSA Data 00008 // Security, Inc. MD5 Message-Digest Algorithm" 00009 // 00010 // You may use this software free of any charge, but without any 00011 // warranty or implied warranty, provided that you follow the terms 00012 // of the original RSA copyright, listed below. 00013 // 00014 // Original RSA Data Security, Inc. Copyright notice 00016 // 00017 // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 00018 // rights reserved. 00019 // 00020 // License to copy and use this software is granted provided that it 00021 // is identified as the "RSA Data Security, Inc. MD5 Message-Digest 00022 // Algorithm" in all material mentioning or referencing this software 00023 // or this function. 00024 // License is also granted to make and use derivative works provided 00025 // that such works are identified as "derived from the RSA Data 00026 // Security, Inc. MD5 Message-Digest Algorithm" in all material 00027 // mentioning or referencing the derived work. 00028 // RSA Data Security, Inc. makes no representations concerning either 00029 // the merchantability of this software or the suitability of this 00030 // software for any particular purpose. It is provided "as is" 00031 // without express or implied warranty of any kind. 00032 // These notices must be retained in any copies of any part of this 00033 // documentation and/or software. 00035 00036 /*------------------------------------------------------------------------------ 00037 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00038 * 00039 * Distributable under the terms of either the Apache License (Version 2.0) or 00040 * the GNU Lesser General Public License, as specified in the COPYING file. 00041 ------------------------------------------------------------------------------*/ 00042 00043 #ifndef _lucene_util_MD5Digester_H 00044 #define _lucene_util_MD5Digester_H 00045 00046 #if defined(_LUCENE_PRAGMA_ONCE) 00047 # pragma once 00048 #endif 00049 00050 CL_NS_DEF(util) 00051 00052 typedef unsigned short int uint2; 00053 00054 char* PrintMD5(uint8_t md5Digest[16]); 00055 char* MD5String(char* szString); 00056 char* MD5File(char* szFilename); 00057 00058 class md5 00059 { 00060 // Methods 00061 public: 00062 md5() { Init(); } 00063 void Init(); 00064 void Update(uint8_t* chInput, uint32_t nInputLen); 00065 void Finalize(); 00066 uint8_t* Digest() { return m_Digest; } 00067 00068 private: 00069 00070 void Transform(uint8_t* block); 00071 void Encode(uint8_t* dest, uint32_t* src, uint32_t nLength); 00072 void Decode(uint32_t* dest, uint8_t* src, uint32_t nLength); 00073 00074 00075 inline uint32_t rotate_left(uint32_t x, uint32_t n) 00076 { return ((x << n) | (x >> (32-n))); } 00077 00078 inline uint32_t F(uint32_t x, uint32_t y, uint32_t z) 00079 { return ((x & y) | (~x & z)); } 00080 00081 inline uint32_t G(uint32_t x, uint32_t y, uint32_t z) 00082 { return ((x & z) | (y & ~z)); } 00083 00084 inline uint32_t H(uint32_t x, uint32_t y, uint32_t z) 00085 { return (x ^ y ^ z); } 00086 00087 inline uint32_t I(uint32_t x, uint32_t y, uint32_t z) 00088 { return (y ^ (x | ~z)); } 00089 00090 inline void FF(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) 00091 { a += F(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } 00092 00093 inline void GG(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) 00094 { a += G(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } 00095 00096 inline void HH(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) 00097 { a += H(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } 00098 00099 inline void II(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) 00100 { a += I(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } 00101 00102 // Data 00103 private: 00104 uint32_t m_State[4]; 00105 uint32_t m_Count[2]; 00106 uint8_t m_Buffer[64]; 00107 uint8_t m_Digest[16]; 00108 uint8_t m_Finalized; 00109 00110 }; 00111 00112 CL_NS_END 00113 #endif