00001 00031 #ifndef LL_LLMD5_H 00032 #define LL_LLMD5_H 00033 00034 // LLMD5.CC - source code for the C++/object oriented translation and 00035 // modification of MD5. 00036 00037 // Translation and modification (c) 1995 by Mordechai T. Abzug 00038 00039 // This translation/ modification is provided "as is," without express or 00040 // implied warranty of any kind. 00041 00042 // The translator/ modifier does not claim (1) that MD5 will do what you think 00043 // it does; (2) that this translation/ modification is accurate; or (3) that 00044 // this software is "merchantible." (Language for this disclaimer partially 00045 // copied from the disclaimer below). 00046 00047 /* based on: 00048 00049 MD5.H - header file for MD5C.C 00050 MDDRIVER.C - test driver for MD2, MD4 and MD5 00051 00052 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 00053 rights reserved. 00054 00055 License to copy and use this software is granted provided that it 00056 is identified as the "RSA Data Security, Inc. MD5 Message-Digest 00057 Algorithm" in all material mentioning or referencing this software 00058 or this function. 00059 00060 License is also granted to make and use derivative works provided 00061 that such works are identified as "derived from the RSA Data 00062 Security, Inc. MD5 Message-Digest Algorithm" in all material 00063 mentioning or referencing the derived work. 00064 00065 RSA Data Security, Inc. makes no representations concerning either 00066 the merchantability of this software or the suitability of this 00067 software for any particular purpose. It is provided "as is" 00068 without express or implied warranty of any kind. 00069 00070 These notices must be retained in any copies of any part of this 00071 documentation and/or software. 00072 00073 */ 00074 00075 // use for the raw digest output 00076 const int MD5RAW_BYTES = 16; 00077 00078 // use for outputting hex digests 00079 const int MD5HEX_STR_SIZE = 33; // char hex[MD5HEX_STR_SIZE]; with null 00080 const int MD5HEX_STR_BYTES = 32; // message system fixed size 00081 00082 class LLMD5 { 00083 // first, some types: 00084 typedef unsigned int uint4; // assumes integer is 4 words long 00085 typedef unsigned short int uint2; // assumes short integer is 2 words long 00086 typedef unsigned char uint1; // assumes char is 1 word long 00087 00088 // how many bytes to grab at a time when checking files 00089 static const int BLOCK_LEN; 00090 00091 public: 00092 // methods for controlled operation: 00093 LLMD5 (); // simple initializer 00094 void update (const uint1 *input, const uint4 input_length); 00095 void update (std::istream& stream); 00096 void update (FILE *file); 00097 void finalize (); 00098 00099 // constructors for special circumstances. All these constructors finalize 00100 // the MD5 context. 00101 LLMD5 (const unsigned char *string); // digest string, finalize 00102 LLMD5 (std::istream& stream); // digest stream, finalize 00103 LLMD5 (FILE *file); // digest file, close, finalize 00104 LLMD5 (const unsigned char *string, const unsigned int number); 00105 00106 // methods to acquire finalized result 00107 void raw_digest(unsigned char *array); // provide 16-byte array for binary data 00108 void hex_digest(char *string); // provide 33-byte array for ascii-hex string 00109 friend std::ostream& operator<< (std::ostream&, LLMD5 context); 00110 00111 00112 00113 private: 00114 00115 00116 // next, the private data: 00117 uint4 state[4]; 00118 uint4 count[2]; // number of *bits*, mod 2^64 00119 uint1 buffer[64]; // input buffer 00120 uint1 digest[16]; 00121 uint1 finalized; 00122 00123 // last, the private methods, mostly static: 00124 void init (); // called by all constructors 00125 void transform (const uint1 *buffer); // does the real update work. Note 00126 // that length is implied to be 64. 00127 00128 static void encode (uint1 *dest, const uint4 *src, const uint4 length); 00129 static void decode (uint4 *dest, const uint1 *src, const uint4 length); 00130 00131 }; 00132 00133 #endif // LL_LLMD5_H