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

md5.h

Go to the documentation of this file.
00001 //============================================== 00002 // copyright : (C) 2003-2005 by Will Stokes 00003 //============================================== 00004 // This program is free software; you can redistribute it 00005 // and/or modify it under the terms of the GNU General 00006 // Public License as published by the Free Software 00007 // Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 //============================================== 00010 00011 //===================================== 00015 //===================================== 00016 00017 00018 // MD5.CC - source code for the C++/object oriented translation and 00019 // modification of MD5. 00020 00021 // Translation and modification (c) 1995 by Mordechai T. Abzug 00022 00023 // This translation/ modification is provided "as is," without express or 00024 // implied warranty of any kind. 00025 00026 // The translator/ modifier does not claim (1) that MD5 will do what you think 00027 // it does; (2) that this translation/ modification is accurate; or (3) that 00028 // this software is "merchantible." (Language for this disclaimer partially 00029 // copied from the disclaimer below). 00030 00031 /* based on: 00032 00033 MD5.H - header file for MD5C.C 00034 MDDRIVER.C - test driver for MD2, MD4 and MD5 00035 00036 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 00037 rights reserved. 00038 00039 License to copy and use this software is granted provided that it 00040 is identified as the "RSA Data Security, Inc. MD5 Message-Digest 00041 Algorithm" in all material mentioning or referencing this software 00042 or this function. 00043 00044 License is also granted to make and use derivative works provided 00045 that such works are identified as "derived from the RSA Data 00046 Security, Inc. MD5 Message-Digest Algorithm" in all material 00047 mentioning or referencing the derived work. 00048 00049 RSA Data Security, Inc. makes no representations concerning either 00050 the merchantability of this software or the suitability of this 00051 software for any particular purpose. It is provided "as is" 00052 without express or implied warranty of any kind. 00053 00054 These notices must be retained in any copies of any part of this 00055 documentation and/or software. 00056 00057 */ 00058 00059 #include <fstream> 00060 #include <qstring.h> 00061 00062 #ifndef BACKEND_TOOLS_MD5_H 00063 #define BACKEND_TOOLS_MD5_H 00064 00065 class MD5 { 00066 00067 public: 00068 // methods for controlled operation: 00069 MD5 (); // simple initializer 00070 void update (unsigned char *input, unsigned int input_length); 00071 void update (std::istream& stream); 00072 void update (FILE *file); 00073 void update (std::ifstream& stream); 00074 void finalize (); 00075 00076 // constructors for special circumstances. All these constructors finalize 00077 // the MD5 context. 00078 MD5 (unsigned char *string); // digest string, finalize 00079 MD5 (std::istream& stream); // digest stream, finalize 00080 MD5 (FILE *file); // digest file, close, finalize 00081 MD5 (std::ifstream& stream); // digest stream, close, finalize 00082 00083 // methods to acquire finalized result 00084 unsigned char *raw_digest (); // digest as a 16-byte binary array 00085 QString hex_digest (); // digest as a 33-byte ascii-hex string 00086 00087 00088 private: 00089 00090 // first, some types: 00091 typedef unsigned int uint4; // assumes integer is 4 words long 00092 typedef unsigned short int uint2; // assumes short integer is 2 words long 00093 typedef unsigned char uint1; // assumes char is 1 word long 00094 00095 // next, the private data: 00096 uint4 state[4]; 00097 uint4 count[2]; // number of *bits*, mod 2^64 00098 uint1 buffer[64]; // input buffer 00099 uint1 digest[16]; 00100 uint1 finalized; 00101 00102 // last, the private methods, mostly static: 00103 void init (); // called by all constructors 00104 void transform (uint1 *buffer); // does the real update work. Note 00105 // that length is implied to be 64. 00106 00107 static void encode (uint1 *dest, uint4 *src, uint4 length); 00108 static void decode (uint4 *dest, uint1 *src, uint4 length); 00109 static void memcpy (uint1 *dest, uint1 *src, uint4 length); 00110 static void memset (uint1 *start, uint1 val, uint4 length); 00111 00112 static inline uint4 rotate_left (uint4 x, uint4 n); 00113 static inline uint4 F (uint4 x, uint4 y, uint4 z); 00114 static inline uint4 G (uint4 x, uint4 y, uint4 z); 00115 static inline uint4 H (uint4 x, uint4 y, uint4 z); 00116 static inline uint4 I (uint4 x, uint4 y, uint4 z); 00117 static inline void FF (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 00118 uint4 s, uint4 ac); 00119 static inline void GG (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 00120 uint4 s, uint4 ac); 00121 static inline void HH (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 00122 uint4 s, uint4 ac); 00123 static inline void II (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 00124 uint4 s, uint4 ac); 00125 00126 }; 00127 00128 //returns md5 for a given file 00129 QString getMD5(std::ifstream& stream); 00130 00131 //compares md5's for two files 00132 //returns -1 if unable ot open file 00133 //returns 0 if files are different 00134 //returns 1 if files are same 00135 bool filesMatch(std::ifstream& stream, QString oldMD5); 00136 00137 #endif //BACKEND_TOOLS_MD5_H

Generated on Sun Mar 4 19:42:56 2007 for AlbumShaper by doxygen 1.3.7