00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef BZF_MD5_H
00034 #define BZF_MD5_H
00035
00036 #include <string>
00037 #include <iostream>
00038
00039
00076 class MD5 {
00077
00078 public:
00079 typedef unsigned int size_type;
00080
00083 MD5();
00084
00089 MD5(const std::string& text);
00090
00096 void update(const unsigned char *buf, size_type length);
00097
00103 void update(const char *buf, size_type length);
00104
00108 MD5& finalize();
00109
00114 std::string hexdigest() const;
00115
00116
00121 void print(std::ostream & os) const;
00122
00123 private:
00124 void init();
00125 typedef unsigned char uint1;
00126 typedef unsigned int uint4;
00127 enum {blocksize = 64};
00128
00129 void transform(const uint1 block[blocksize]);
00130 static void decode(uint4 output[], const uint1 input[], size_type len);
00131 static void encode(uint1 output[], const uint4 input[], size_type len);
00132
00133 bool finalized;
00134 uint1 buffer[blocksize];
00135 uint4 count[2];
00136 uint4 state[4];
00137 uint1 digest[16];
00138
00139
00140 static inline uint4 F(uint4 x, uint4 y, uint4 z);
00141 static inline uint4 G(uint4 x, uint4 y, uint4 z);
00142 static inline uint4 H(uint4 x, uint4 y, uint4 z);
00143 static inline uint4 I(uint4 x, uint4 y, uint4 z);
00144 static inline uint4 rotate_left(uint4 x, int n);
00145 static inline void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00146 static inline void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00147 static inline void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00148 static inline void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac);
00149 };
00150
00157 std::ostream& operator<<(std::ostream& os, const MD5 & md5);
00158
00169 std::string md5(const std::string str);
00170
00171 #endif