91 static void MD5Transform(
UINT4 [4],
unsigned char [64]);
92 static void Encode(
unsigned char *,
UINT4 *,
unsigned int);
93 static void Decode(
UINT4 *,
unsigned char *,
unsigned int);
95 static unsigned char PADDING[64] = {
96 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
103 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
104 #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
105 #define H(x, y, z) ((x) ^ (y) ^ (z))
106 #define I(x, y, z) ((y) ^ ((x) | (~z)))
110 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
115 #define FF(a, b, c, d, x, s, ac) { \
116 (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
117 (a) = ROTATE_LEFT ((a), (s)); \
120 #define GG(a, b, c, d, x, s, ac) { \
121 (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
122 (a) = ROTATE_LEFT ((a), (s)); \
125 #define HH(a, b, c, d, x, s, ac) { \
126 (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
127 (a) = ROTATE_LEFT ((a), (s)); \
130 #define II(a, b, c, d, x, s, ac) { \
131 (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
132 (a) = ROTATE_LEFT ((a), (s)); \
142 context->
state[0] = 0x67452301;
143 context->
state[1] = 0xefcdab89;
144 context->
state[2] = 0x98badcfe;
145 context->
state[3] = 0x10325476;
153 unsigned char *
input,
154 unsigned int inputLen)
156 unsigned int i, bufindex, partLen;
159 bufindex = (
unsigned int)((context->
count[0] >> 3) & 0x3F);
162 if ((context->
count[0] += ((
UINT4)inputLen << 3))
163 < ((
UINT4)inputLen << 3))
167 partLen = 64 - bufindex;
170 if (inputLen >= partLen) {
171 memcpy((
void *)&context->
buffer[bufindex], (
void *)input, partLen);
174 for (i = partLen; i + 63 < inputLen; i += 64)
175 MD5Transform(context->
state, &input[i]);
183 memcpy((
void *)&context->
buffer[bufindex], (
void *)&input[i], inputLen-i);
189 static void MD5_Final(
unsigned char digest[16],
192 unsigned char bits[8];
193 unsigned int count, padLen;
196 Encode (bits, context->
count, 8);
199 count = (
unsigned int)((context->
count[0] >> 3) & 0x3f);
200 padLen = (count < 56) ? (56 - count) : (120 -
count);
207 Encode (digest, context->
state, 16);
210 memset ((
void *)context, 0,
sizeof (*context));
215 unsigned char block[64])
217 UINT4 a = state[0],
b = state[1],
c = state[2], d = state[3],
x[16];
219 Decode (x, block, 64);
222 FF (a, b, c, d, x[ 0],
S11, 0xd76aa478);
223 FF (d, a, b, c, x[ 1],
S12, 0xe8c7b756);
224 FF (c, d, a, b, x[ 2],
S13, 0x242070db);
225 FF (b, c, d, a, x[ 3],
S14, 0xc1bdceee);
226 FF (a, b, c, d, x[ 4],
S11, 0xf57c0faf);
227 FF (d, a, b, c, x[ 5],
S12, 0x4787c62a);
228 FF (c, d, a, b, x[ 6],
S13, 0xa8304613);
229 FF (b, c, d, a, x[ 7],
S14, 0xfd469501);
230 FF (a, b, c, d, x[ 8],
S11, 0x698098d8);
231 FF (d, a, b, c, x[ 9],
S12, 0x8b44f7af);
232 FF (c, d, a, b, x[10],
S13, 0xffff5bb1);
233 FF (b, c, d, a, x[11],
S14, 0x895cd7be);
234 FF (a, b, c, d, x[12],
S11, 0x6b901122);
235 FF (d, a, b, c, x[13],
S12, 0xfd987193);
236 FF (c, d, a, b, x[14],
S13, 0xa679438e);
237 FF (b, c, d, a, x[15],
S14, 0x49b40821);
240 GG (a, b, c, d, x[ 1],
S21, 0xf61e2562);
241 GG (d, a, b, c, x[ 6],
S22, 0xc040b340);
242 GG (c, d, a, b, x[11],
S23, 0x265e5a51);
243 GG (b, c, d, a, x[ 0],
S24, 0xe9b6c7aa);
244 GG (a, b, c, d, x[ 5],
S21, 0xd62f105d);
245 GG (d, a, b, c, x[10],
S22, 0x2441453);
246 GG (c, d, a, b, x[15],
S23, 0xd8a1e681);
247 GG (b, c, d, a, x[ 4],
S24, 0xe7d3fbc8);
248 GG (a, b, c, d, x[ 9],
S21, 0x21e1cde6);
249 GG (d, a, b, c, x[14],
S22, 0xc33707d6);
250 GG (c, d, a, b, x[ 3],
S23, 0xf4d50d87);
251 GG (b, c, d, a, x[ 8],
S24, 0x455a14ed);
252 GG (a, b, c, d, x[13],
S21, 0xa9e3e905);
253 GG (d, a, b, c, x[ 2],
S22, 0xfcefa3f8);
254 GG (c, d, a, b, x[ 7],
S23, 0x676f02d9);
255 GG (b, c, d, a, x[12],
S24, 0x8d2a4c8a);
258 HH (a, b, c, d, x[ 5],
S31, 0xfffa3942);
259 HH (d, a, b, c, x[ 8],
S32, 0x8771f681);
260 HH (c, d, a, b, x[11],
S33, 0x6d9d6122);
261 HH (b, c, d, a, x[14],
S34, 0xfde5380c);
262 HH (a, b, c, d, x[ 1],
S31, 0xa4beea44);
263 HH (d, a, b, c, x[ 4],
S32, 0x4bdecfa9);
264 HH (c, d, a, b, x[ 7],
S33, 0xf6bb4b60);
265 HH (b, c, d, a, x[10],
S34, 0xbebfbc70);
266 HH (a, b, c, d, x[13],
S31, 0x289b7ec6);
267 HH (d, a, b, c, x[ 0],
S32, 0xeaa127fa);
268 HH (c, d, a, b, x[ 3],
S33, 0xd4ef3085);
269 HH (b, c, d, a, x[ 6],
S34, 0x4881d05);
270 HH (a, b, c, d, x[ 9],
S31, 0xd9d4d039);
271 HH (d, a, b, c, x[12],
S32, 0xe6db99e5);
272 HH (c, d, a, b, x[15],
S33, 0x1fa27cf8);
273 HH (b, c, d, a, x[ 2],
S34, 0xc4ac5665);
276 II (a, b, c, d, x[ 0],
S41, 0xf4292244);
277 II (d, a, b, c, x[ 7],
S42, 0x432aff97);
278 II (c, d, a, b, x[14],
S43, 0xab9423a7);
279 II (b, c, d, a, x[ 5],
S44, 0xfc93a039);
280 II (a, b, c, d, x[12],
S41, 0x655b59c3);
281 II (d, a, b, c, x[ 3],
S42, 0x8f0ccc92);
282 II (c, d, a, b, x[10],
S43, 0xffeff47d);
283 II (b, c, d, a, x[ 1],
S44, 0x85845dd1);
284 II (a, b, c, d, x[ 8],
S41, 0x6fa87e4f);
285 II (d, a, b, c, x[15],
S42, 0xfe2ce6e0);
286 II (c, d, a, b, x[ 6],
S43, 0xa3014314);
287 II (b, c, d, a, x[13],
S44, 0x4e0811a1);
288 II (a, b, c, d, x[ 4],
S41, 0xf7537e82);
289 II (d, a, b, c, x[11],
S42, 0xbd3af235);
290 II (c, d, a, b, x[ 2],
S43, 0x2ad7d2bb);
291 II (b, c, d, a, x[ 9],
S44, 0xeb86d391);
299 memset((
void *)x, 0,
sizeof (x));
305 static void Encode (
unsigned char *output,
311 for (i = 0, j = 0; j <
len; i++, j += 4) {
312 output[
j] = (
unsigned char)(input[i] & 0xff);
313 output[j+1] = (
unsigned char)((input[i] >> 8) & 0xff);
314 output[j+2] = (
unsigned char)((input[i] >> 16) & 0xff);
315 output[j+3] = (
unsigned char)((input[i] >> 24) & 0xff);
322 static void Decode (
UINT4 *output,
323 unsigned char *input,
328 for (i = 0, j = 0; j <
len; i++, j += 4)
329 output[i] = ((
UINT4)input[j]) | (((
UINT4)input[j+1]) << 8) |
330 (((
UINT4)input[j+2]) << 16) | (((
UINT4)input[j+3]) << 24);
335 #include <openssl/md5.h>
342 unsigned char *input)
346 MD5_Update(&ctx, input, strlen((
char *)input));
void Curl_md5it(unsigned char *outbuffer, unsigned char *input)
void MD5_Final(MD5_CTX *ctx, unsigned char digest[16])
#define GG(a, b, c, d, x, s, ac)
void MD5_Update(MD5_CTX *ctx, unsigned char const *buf, unsigned int len)
#define II(a, b, c, d, x, s, ac)
GLuint GLuint GLsizei count
#define HH(a, b, c, d, x, s, ac)
void MD5_Init(MD5_CTX *ctx)
GLenum GLenum GLenum input
GLubyte GLubyte GLubyte a
#define FF(a, b, c, d, x, s, ac)