95 static void md5_digest(
char *md5str,
unsigned char *digest);
106 for (i = 0; i < 16; i++) {
107 sprintf(md5str,
"%02x", digest[i]);
134 static void md5_transform(
unsigned int[4],
const unsigned char[64]);
135 static void md5_encode(
unsigned char *,
unsigned int *,
unsigned int);
136 static void md5_decode(
unsigned int *,
const unsigned char *,
unsigned int);
140 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
147 #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 148 #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 149 #define H(x, y, z) ((x) ^ (y) ^ (z)) 150 #define I(x, y, z) ((y) ^ ((x) | (~z))) 154 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 159 #define FF(a, b, c, d, x, s, ac) { \ 160 (a) += F ((b), (c), (d)) + (x) + (unsigned int)(ac); \ 161 (a) = ROTATE_LEFT ((a), (s)); \ 164 #define GG(a, b, c, d, x, s, ac) { \ 165 (a) += G ((b), (c), (d)) + (x) + (unsigned int)(ac); \ 166 (a) = ROTATE_LEFT ((a), (s)); \ 169 #define HH(a, b, c, d, x, s, ac) { \ 170 (a) += H ((b), (c), (d)) + (x) + (unsigned int)(ac); \ 171 (a) = ROTATE_LEFT ((a), (s)); \ 174 #define II(a, b, c, d, x, s, ac) { \ 175 (a) += I ((b), (c), (d)) + (x) + (unsigned int)(ac); \ 176 (a) = ROTATE_LEFT ((a), (s)); \ 184 context->state[0] = 0x67452301;
185 context->state[1] = 0xefcdab89;
186 context->state[2] = 0x98badcfe;
187 context->state[3] = 0x10325476;
196 unsigned int inputLen)
198 unsigned int i, index, partLen;
201 index = (
unsigned int) ((
context->count[0] >> 3) & 0x3F);
204 if ((
context->count[0] += ((
unsigned int) inputLen << 3))
205 < ((
unsigned int) inputLen << 3))
207 context->count[1] += ((
unsigned int) inputLen >> 29);
209 partLen = 64 - index;
212 if (inputLen >= partLen) {
213 memcpy((
unsigned char*) &
context->buffer[index],
214 (
unsigned char*) input, partLen);
217 for (i = partLen; i + 63 < inputLen; i += 64)
225 memcpy((
unsigned char*) &
context->buffer[index], (
unsigned char*) & input[i],
235 unsigned char bits[8];
236 unsigned int index, padLen;
243 index = (
unsigned int) ((
context->count[0] >> 3) & 0x3f);
244 padLen = (index < 56) ? (56 - index) : (120 - index);
263 unsigned int state[4];
264 const unsigned char block[64];
266 unsigned int a = state[0], b = state[1], c = state[2], d = state[3], x[16];
271 FF(a, b, c, d, x[0],
S11, 0xd76aa478);
272 FF(d, a, b, c, x[1],
S12, 0xe8c7b756);
273 FF(c, d, a, b, x[2],
S13, 0x242070db);
274 FF(b, c, d, a, x[3],
S14, 0xc1bdceee);
275 FF(a, b, c, d, x[4],
S11, 0xf57c0faf);
276 FF(d, a, b, c, x[5],
S12, 0x4787c62a);
277 FF(c, d, a, b, x[6],
S13, 0xa8304613);
278 FF(b, c, d, a, x[7],
S14, 0xfd469501);
279 FF(a, b, c, d, x[8],
S11, 0x698098d8);
280 FF(d, a, b, c, x[9],
S12, 0x8b44f7af);
281 FF(c, d, a, b, x[10],
S13, 0xffff5bb1);
282 FF(b, c, d, a, x[11],
S14, 0x895cd7be);
283 FF(a, b, c, d, x[12],
S11, 0x6b901122);
284 FF(d, a, b, c, x[13],
S12, 0xfd987193);
285 FF(c, d, a, b, x[14],
S13, 0xa679438e);
286 FF(b, c, d, a, x[15],
S14, 0x49b40821);
289 GG(a, b, c, d, x[1],
S21, 0xf61e2562);
290 GG(d, a, b, c, x[6],
S22, 0xc040b340);
291 GG(c, d, a, b, x[11],
S23, 0x265e5a51);
292 GG(b, c, d, a, x[0],
S24, 0xe9b6c7aa);
293 GG(a, b, c, d, x[5],
S21, 0xd62f105d);
294 GG(d, a, b, c, x[10],
S22, 0x2441453);
295 GG(c, d, a, b, x[15],
S23, 0xd8a1e681);
296 GG(b, c, d, a, x[4],
S24, 0xe7d3fbc8);
297 GG(a, b, c, d, x[9],
S21, 0x21e1cde6);
298 GG(d, a, b, c, x[14],
S22, 0xc33707d6);
299 GG(c, d, a, b, x[3],
S23, 0xf4d50d87);
300 GG(b, c, d, a, x[8],
S24, 0x455a14ed);
301 GG(a, b, c, d, x[13],
S21, 0xa9e3e905);
302 GG(d, a, b, c, x[2],
S22, 0xfcefa3f8);
303 GG(c, d, a, b, x[7],
S23, 0x676f02d9);
304 GG(b, c, d, a, x[12],
S24, 0x8d2a4c8a);
307 HH(a, b, c, d, x[5],
S31, 0xfffa3942);
308 HH(d, a, b, c, x[8],
S32, 0x8771f681);
309 HH(c, d, a, b, x[11],
S33, 0x6d9d6122);
310 HH(b, c, d, a, x[14],
S34, 0xfde5380c);
311 HH(a, b, c, d, x[1],
S31, 0xa4beea44);
312 HH(d, a, b, c, x[4],
S32, 0x4bdecfa9);
313 HH(c, d, a, b, x[7],
S33, 0xf6bb4b60);
314 HH(b, c, d, a, x[10],
S34, 0xbebfbc70);
315 HH(a, b, c, d, x[13],
S31, 0x289b7ec6);
316 HH(d, a, b, c, x[0],
S32, 0xeaa127fa);
317 HH(c, d, a, b, x[3],
S33, 0xd4ef3085);
318 HH(b, c, d, a, x[6],
S34, 0x4881d05);
319 HH(a, b, c, d, x[9],
S31, 0xd9d4d039);
320 HH(d, a, b, c, x[12],
S32, 0xe6db99e5);
321 HH(c, d, a, b, x[15],
S33, 0x1fa27cf8);
322 HH(b, c, d, a, x[2],
S34, 0xc4ac5665);
325 II(a, b, c, d, x[0],
S41, 0xf4292244);
326 II(d, a, b, c, x[7],
S42, 0x432aff97);
327 II(c, d, a, b, x[14],
S43, 0xab9423a7);
328 II(b, c, d, a, x[5],
S44, 0xfc93a039);
329 II(a, b, c, d, x[12],
S41, 0x655b59c3);
330 II(d, a, b, c, x[3],
S42, 0x8f0ccc92);
331 II(c, d, a, b, x[10],
S43, 0xffeff47d);
332 II(b, c, d, a, x[1],
S44, 0x85845dd1);
333 II(a, b, c, d, x[8],
S41, 0x6fa87e4f);
334 II(d, a, b, c, x[15],
S42, 0xfe2ce6e0);
335 II(c, d, a, b, x[6],
S43, 0xa3014314);
336 II(b, c, d, a, x[13],
S44, 0x4e0811a1);
337 II(a, b, c, d, x[4],
S41, 0xf7537e82);
338 II(d, a, b, c, x[11],
S42, 0xbd3af235);
339 II(c, d, a, b, x[2],
S43, 0x2ad7d2bb);
340 II(b, c, d, a, x[9],
S44, 0xeb86d391);
348 memset((
unsigned char*) x, 0,
sizeof(x));
356 unsigned char *output;
362 for (i = 0, j = 0; j < len; i++, j += 4) {
363 output[j] = (
unsigned char) (input[i] & 0xff);
364 output[j + 1] = (
unsigned char) ((input[i] >> 8) & 0xff);
365 output[j + 2] = (
unsigned char) ((input[i] >> 16) & 0xff);
366 output[j + 3] = (
unsigned char) ((input[i] >> 24) & 0xff);
375 unsigned int *output;
376 const unsigned char *input;
381 for (i = 0, j = 0; j < len; i++, j += 4)
382 output[i] = ((
unsigned int) input[j]) | (((
unsigned int) input[j + 1]) << 8) |
383 (((
unsigned int) input[j + 2]) << 16) | (((
unsigned int) input[j + 3]) << 24);
390 unsigned char digest[16];
Octstr * md5(Octstr *data)
static void md5_digest(char *md5str, unsigned char *digest)
static void md5_final(unsigned char[16], md5_ctx *)
#define GG(a, b, c, d, x, s, ac)
static void md5_transform(unsigned int[4], const unsigned char[64])
static void md5_update(md5_ctx *, const unsigned char *, unsigned int)
#define octstr_get_cstr(ostr)
#define II(a, b, c, d, x, s, ac)
static void md5_decode(unsigned int *, const unsigned char *, unsigned int)
#define HH(a, b, c, d, x, s, ac)
static void md5_encode(unsigned char *, unsigned int *, unsigned int)
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
#define FF(a, b, c, d, x, s, ac)
static void md5_init(md5_ctx *)
long octstr_len(const Octstr *ostr)
static unsigned char PADDING[64]
#define octstr_create_from_data(data, len)
Octstr * md5digest(Octstr *data)