Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_MATH_MD5_CHECKSUM_H__
00009 #define __SP_MATH_MD5_CHECKSUM_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spMath.hpp"
00014
00015
00016 namespace sp
00017 {
00018 namespace math
00019 {
00020
00021
00027 class UInt128
00028 {
00029
00030 public:
00031
00032 UInt128() :
00033 High_ (0),
00034 Low_ (0)
00035 {
00036 }
00037 UInt128(u64 HighWord, u64 LowWord) :
00038 High_ (HighWord ),
00039 Low_ (LowWord )
00040 {
00041 }
00042 UInt128(u32 Word3, u32 Word2, u32 Word1, u32 Word0) :
00043 High_ (static_cast<u64>(Word3) << 8 | Word2),
00044 Low_ (static_cast<u64>(Word1) << 8 | Word0)
00045 {
00046 }
00047 UInt128(const UInt128 &Other) :
00048 High_ (Other.High_),
00049 Low_ (Other.Low_ )
00050 {
00051 }
00052 ~UInt128()
00053 {
00054 }
00055
00056
00057
00058 inline bool operator == (const UInt128 &Other) const
00059 {
00060 return High_ == Other.High_ && Low_ == Other.Low_;
00061 }
00062 inline bool operator != (const UInt128 &Other) const
00063 {
00064 return High_ != Other.High_ || Low_ != Other.Low_;
00065 }
00066
00067 #define BITWISE_OP(x) \
00068 inline UInt128& operator x (const UInt128 &Other) \
00069 { \
00070 High_ x Other.High_; \
00071 Low_ x Other.Low_; \
00072 return *this; \
00073 }
00074
00075 BITWISE_OP(=)
00076 BITWISE_OP(&=)
00077 BITWISE_OP(|=)
00078 BITWISE_OP(^=)
00079
00080 #undef BITWISE_OP
00081
00082
00083
00084 inline UInt128& invert()
00085 {
00086 High_ = ~High_;
00087 Low_ = ~Low_;
00088 return *this;
00089 }
00090
00091 inline u64 getHighWord() const
00092 {
00093 return High_;
00094 }
00095 inline u64 getLowWord() const
00096 {
00097 return Low_;
00098 }
00099
00100 private:
00101
00102
00103
00104 u64 High_;
00105 u64 Low_;
00106
00107 };
00108
00109
00122 class SP_EXPORT MD5CheckSum
00123 {
00124
00125 public:
00126
00127 MD5CheckSum();
00128 MD5CheckSum(const void* Buffer, u32 Size);
00129 MD5CheckSum(const MD5CheckSum &Other);
00130 ~MD5CheckSum();
00131
00132
00133
00135 bool valid() const;
00136
00138 io::stringc getHexString() const;
00139
00140
00141
00142 inline MD5CheckSum& operator = (const MD5CheckSum &Other)
00143 {
00144 CheckSum_ = Other.CheckSum_;
00145 return *this;
00146 }
00147
00148 inline bool operator == (const MD5CheckSum &Other) const
00149 {
00150 return CheckSum_ == Other.CheckSum_;
00151 }
00152 inline bool operator != (const MD5CheckSum &Other) const
00153 {
00154 return CheckSum_ != Other.CheckSum_;
00155 }
00156
00158 inline UInt128 get() const
00159 {
00160 return CheckSum_;
00161 }
00162
00163 private:
00164
00165
00166
00167 void computeCheckSum(const void* Buffer, u32 Size);
00168
00169 UInt128 getF(const UInt128 &B, const UInt128 &C, const UInt128 &D) const;
00170 UInt128 getG(const UInt128 &B, const UInt128 &C, const UInt128 &D) const;
00171 UInt128 getH(const UInt128 &B, const UInt128 &C, const UInt128 &D) const;
00172 UInt128 getI(const UInt128 &B, const UInt128 &C, const UInt128 &D) const;
00173
00174
00175
00176 UInt128 CheckSum_;
00177
00178 };
00179
00180
00181 }
00182
00183 }
00184
00185
00186 #endif
00187
00188
00189
00190