2 #ifndef __standalone_hashpp_header_defined__
3 #define __standalone_hashpp_header_defined__
13 class Error
: public std::runtime_error
16 Error(const std::string
& msg
): std::runtime_error(msg
)
20 virtual ~Error() throw()
27 * The HashObject "superclass".
28 * For maximum portability, rely -only- on functions provided in HashObject.
33 typedef unsigned int size_type
;
39 virtual void update(const std::string
& input
) = 0;
40 virtual void update(const char* input
, size_type length
) = 0;
41 virtual void update(char input
) = 0;
42 virtual void updateFromFile(const std::string
& path
);
43 virtual void finalize() = 0;
44 virtual std::string
hexDigest() = 0;
49 class MD5
: public Object
52 typedef unsigned char uint1
; // 8bit
53 typedef unsigned int uint4
; // 32bit
56 static std::string
GenMD5(const std::string
& str
, unsigned int length
=0);
78 // apply MD5 algo on a block
79 void transform(const uint1 block
[blocksize
]);
81 // decodes input (unsigned char) into output (uint4).
82 // Assumes len is a multiple of 4.
83 void decode(uint4 output
[], const uint1 input
[], size_type len
);
86 // encodes input (uint4) into output (unsigned char). Assumes len is
88 void encode(uint1 output
[], const uint4 input
[], size_type len
);
90 // low level logic operations
91 uint4
logic_F(uint4 x
, uint4 y
, uint4 z
);
93 uint4
logic_G(uint4 x
, uint4 y
, uint4 z
);
95 uint4
logic_H(uint4 x
, uint4 y
, uint4 z
);
97 uint4
logic_I(uint4 x
, uint4 y
, uint4 z
);
99 uint4
rotate_left(uint4 x
, int n
);
101 void rot_round1(uint4
&a
, uint4 b
, uint4 c
, uint4 d
,
102 uint4 x
, uint4 s
, uint4 ac
);
104 void rot_round2(uint4
&a
, uint4 b
, uint4 c
, uint4 d
,
105 uint4 x
, uint4 s
, uint4 ac
);
107 void rot_round3(uint4
&a
, uint4 b
, uint4 c
, uint4 d
,
108 uint4 x
, uint4 s
, uint4 ac
);
110 void rot_round4(uint4
&a
, uint4 b
, uint4 c
, uint4 d
,
111 uint4 x
, uint4 s
, uint4 ac
);
116 void update(const std::string
& input
);
117 void update(const unsigned char* input
, size_type length
);
118 void update(const char* input
, size_type length
);
119 void update(char input
);
122 std::string
hexDigest();
125 class SHA1
: public Object
128 static std::string
GenSHA1(const std::string
& data
, unsigned int length
=0);
131 // Message digest buffers
132 std::vector
<unsigned int> H
;
134 // 512-bit message blocks
135 unsigned int* Message_Block
;
140 // Message length in bits
141 unsigned int Length_Low
;
143 // Message length in bits
144 unsigned int Length_High
;
146 // Index into message block array
147 int Message_Block_Index
;
149 // Is the digest computed?
152 // Is the message digest corruped?
155 // is the digest finalized?
159 void ProcessMessageBlock();
161 unsigned int CircularShift(int bits
, unsigned int word
);
167 void update(const std::string
& data
);
168 void update(const char* message_array
, unsigned int length
);
169 void update(char message_element
);
170 bool result(int* message_digest_array
);
172 std::string
hexDigest();
177 #endif /* __standalone_hashpp_header_defined__ */