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

md5.hpp

Go to the documentation of this file.
00001 /* 00002 * MD5 00003 * Written by Julien Couot. 00004 * Original C version written by Ulrich Drepper. 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 */ 00020 00021 /** 00022 * \file md5.hpp 00023 * Compute md5. 00024 */ 00025 00026 //--------------------------------------------------------------------------- 00027 // For compilers that support precompilation, includes "wx.h". 00028 #include <wx/wxprec.h> 00029 00030 #ifdef __BORLANDC__ 00031 #pragma hdrstop 00032 #endif 00033 00034 #ifndef WX_PRECOMP 00035 // Include your minimal set of headers here, or wx.h 00036 #include <wx/wx.h> 00037 #endif 00038 #include "checksum.hpp" 00039 //--------------------------------------------------------------------------- 00040 00041 00042 /** 00043 * Computes the MD5 checksum from a byte stream. 00044 * 00045 * This class is a rewrite in C++ of the md5 checksum computing algorithm 00046 * present in the GNU coreutils. Please see the <A HREF="http://www.gnu.org/"> 00047 * GNU projet website</A> for more informations. 00048 * 00049 * Using this class in very simple:<BR> 00050 * Use the @link update(const wxByte*, unsigned int) update @endlink 00051 * method to provide to the class the bytes for computing the checksum. 00052 * 00053 * The MD5 checksum value can be gotten by two ways: 00054 * <UL> 00055 * <LI>The @link getValue(void*) const getValue @endlink method which puts the 00056 * MD5 checksum value in an array of 16 bytes.</LI> 00057 * <LI>The @link getValue(const bool) const getValue @endlink method which 00058 * returns the MD5 checksum value in a string.</LI> 00059 * </UL> 00060 * The MD5 checksum computing can be reseted by the @link reset() reset @endlink 00061 * method. 00062 */ 00063 class MD5 : public Checksum 00064 { 00065 protected: 00066 // Change the following types if needed. 00067 // typedef unsigned long md5_uint32_t; ///< unsigned 4 bytes integer. 00068 // typedef unsigned short md5_uint16_t; ///< unsigned 2 bytes integer. 00069 // typedef unsigned char md5_uint8_t; ///< unsigned 1 byte integer. 00070 // typedef unsigned long int md5_uintptr_t; ///< unsigned 4 bytes integer. 00071 00072 // State of computation between the single steps. 00073 wxUint32 A_; ///< First part of the state of computation. 00074 wxUint32 B_; ///< Second part of the state of computation. 00075 wxUint32 C_; ///< Third part of the state of computation. 00076 wxUint32 D_; ///< Fourth part of the state of computation. 00077 00078 wxUint32 total[2]; ///< Number of bits mod 2^64. 00079 wxUint32 buflen; ///< Current size of the input buffer. 00080 wxByte ibuffer[128]; ///< Input buffer. 00081 00082 /** 00083 * The bytes used to pad the buffer to the next 64-byte boundary (RFC 1321, 00084 * 3.1: Step 1). 00085 */ 00086 static const wxByte fillbuf[64]; 00087 00088 public: 00089 /** 00090 * Default constructor. 00091 */ 00092 MD5(); 00093 00094 /** 00095 * Resets the MD5 checksum to initial state of computation. 00096 */ 00097 void reset(); 00098 00099 /** 00100 * Returns the MD5 checksum value in the first 16 bytes of the given adress. 00101 * 00102 * @param buffer The buffer where the MD5 checksum value will be stored. 00103 * @return The adress of the buffer. 00104 * @remarks On some systems it is required that <CODE>buffer</CODE> is 00105 * correctly aligned for a 32 bits value. 00106 * @remarks The memory for the 16 bytes must have been allocated before calling 00107 * this method. 00108 */ 00109 void* getValue(void* buffer) const; 00110 00111 /** 00112 * Returns the MD5 checksum value in a string. 00113 * 00114 * @param hexInUpperCase If <CODE>true</CODE> the hexadecimal letters will 00115 * be in uppercase. 00116 * @return The current checksum value. 00117 */ 00118 wxString getValue(const bool hexInUpperCase = false) const; 00119 00120 /** 00121 * Updates the MD5 checksum with specified array of bytes. 00122 * 00123 * @param buf The byte array to update the MD5 checksum with. 00124 * @param len The number of bytes to use for the update. 00125 */ 00126 void update(const wxByte* buf, unsigned int len); 00127 00128 protected: 00129 /** 00130 * Process the remaining bytes in the internal buffer and the usual 00131 * prolog according to the standard. 00132 */ 00133 void finish(); 00134 00135 /** 00136 * Process <i>len</i> bytes of <i>buf</i>, accumulating context in 00137 * <i>this</i>. 00138 * It is assumed that <CODE>len % 64 == 0</CODE>. 00139 * 00140 * @param buf The buffer to process. 00141 * @param len The number of bytes to process. 00142 */ 00143 void process_block(const void* buf, size_t len); 00144 }; 00145 //---------------------------------------------------------------------------

Generated on Sun May 30 13:37:45 2004 for wxChecksums by doxygen 1.3.7