39 (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
46static const unsigned char fillbuf[64] = { 0x80, 0 };
51#define FF(b, c, d) (d ^ (b & (c ^ d)))
52#define FG(b, c, d) FF(d, b, c)
53#define FH(b, c, d) (b ^ c ^ d)
54#define FI(b, c, d) (c ^ (b | ~d))
79 md5ctx->
total[0] += len;
80 if (md5ctx->
total[0] < len)
99#define OP(a, b, c, d, s, T) \
102 a += FF(b, c, d) + (*cwp++ = SWAP(*words)) + T; \
110#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
120 OP(
A,
B,
C,
D, 7, 0xd76aa478);
121 OP(
D,
A,
B,
C, 12, 0xe8c7b756);
122 OP(
C,
D,
A,
B, 17, 0x242070db);
123 OP(
B,
C,
D,
A, 22, 0xc1bdceee);
124 OP(
A,
B,
C,
D, 7, 0xf57c0faf);
125 OP(
D,
A,
B,
C, 12, 0x4787c62a);
126 OP(
C,
D,
A,
B, 17, 0xa8304613);
127 OP(
B,
C,
D,
A, 22, 0xfd469501);
128 OP(
A,
B,
C,
D, 7, 0x698098d8);
129 OP(
D,
A,
B,
C, 12, 0x8b44f7af);
130 OP(
C,
D,
A,
B, 17, 0xffff5bb1);
131 OP(
B,
C,
D,
A, 22, 0x895cd7be);
132 OP(
A,
B,
C,
D, 7, 0x6b901122);
133 OP(
D,
A,
B,
C, 12, 0xfd987193);
134 OP(
C,
D,
A,
B, 17, 0xa679438e);
135 OP(
B,
C,
D,
A, 22, 0x49b40821);
141#define OP(f, a, b, c, d, k, s, T) \
144 a += f(b, c, d) + correct_words[k] + T; \
150 OP(
FG,
A,
B,
C,
D, 1, 5, 0xf61e2562);
151 OP(
FG,
D,
A,
B,
C, 6, 9, 0xc040b340);
152 OP(
FG,
C,
D,
A,
B, 11, 14, 0x265e5a51);
153 OP(
FG,
B,
C,
D,
A, 0, 20, 0xe9b6c7aa);
154 OP(
FG,
A,
B,
C,
D, 5, 5, 0xd62f105d);
155 OP(
FG,
D,
A,
B,
C, 10, 9, 0x02441453);
156 OP(
FG,
C,
D,
A,
B, 15, 14, 0xd8a1e681);
157 OP(
FG,
B,
C,
D,
A, 4, 20, 0xe7d3fbc8);
158 OP(
FG,
A,
B,
C,
D, 9, 5, 0x21e1cde6);
159 OP(
FG,
D,
A,
B,
C, 14, 9, 0xc33707d6);
160 OP(
FG,
C,
D,
A,
B, 3, 14, 0xf4d50d87);
161 OP(
FG,
B,
C,
D,
A, 8, 20, 0x455a14ed);
162 OP(
FG,
A,
B,
C,
D, 13, 5, 0xa9e3e905);
163 OP(
FG,
D,
A,
B,
C, 2, 9, 0xfcefa3f8);
164 OP(
FG,
C,
D,
A,
B, 7, 14, 0x676f02d9);
165 OP(
FG,
B,
C,
D,
A, 12, 20, 0x8d2a4c8a);
168 OP(
FH,
A,
B,
C,
D, 5, 4, 0xfffa3942);
169 OP(
FH,
D,
A,
B,
C, 8, 11, 0x8771f681);
170 OP(
FH,
C,
D,
A,
B, 11, 16, 0x6d9d6122);
171 OP(
FH,
B,
C,
D,
A, 14, 23, 0xfde5380c);
172 OP(
FH,
A,
B,
C,
D, 1, 4, 0xa4beea44);
173 OP(
FH,
D,
A,
B,
C, 4, 11, 0x4bdecfa9);
174 OP(
FH,
C,
D,
A,
B, 7, 16, 0xf6bb4b60);
175 OP(
FH,
B,
C,
D,
A, 10, 23, 0xbebfbc70);
176 OP(
FH,
A,
B,
C,
D, 13, 4, 0x289b7ec6);
177 OP(
FH,
D,
A,
B,
C, 0, 11, 0xeaa127fa);
178 OP(
FH,
C,
D,
A,
B, 3, 16, 0xd4ef3085);
179 OP(
FH,
B,
C,
D,
A, 6, 23, 0x04881d05);
180 OP(
FH,
A,
B,
C,
D, 9, 4, 0xd9d4d039);
181 OP(
FH,
D,
A,
B,
C, 12, 11, 0xe6db99e5);
182 OP(
FH,
C,
D,
A,
B, 15, 16, 0x1fa27cf8);
183 OP(
FH,
B,
C,
D,
A, 2, 23, 0xc4ac5665);
186 OP(
FI,
A,
B,
C,
D, 0, 6, 0xf4292244);
187 OP(
FI,
D,
A,
B,
C, 7, 10, 0x432aff97);
188 OP(
FI,
C,
D,
A,
B, 14, 15, 0xab9423a7);
189 OP(
FI,
B,
C,
D,
A, 5, 21, 0xfc93a039);
190 OP(
FI,
A,
B,
C,
D, 12, 6, 0x655b59c3);
191 OP(
FI,
D,
A,
B,
C, 3, 10, 0x8f0ccc92);
192 OP(
FI,
C,
D,
A,
B, 10, 15, 0xffeff47d);
193 OP(
FI,
B,
C,
D,
A, 1, 21, 0x85845dd1);
194 OP(
FI,
A,
B,
C,
D, 8, 6, 0x6fa87e4f);
195 OP(
FI,
D,
A,
B,
C, 15, 10, 0xfe2ce6e0);
196 OP(
FI,
C,
D,
A,
B, 6, 15, 0xa3014314);
197 OP(
FI,
B,
C,
D,
A, 13, 21, 0x4e0811a1);
198 OP(
FI,
A,
B,
C,
D, 4, 6, 0xf7537e82);
199 OP(
FI,
D,
A,
B,
C, 11, 10, 0xbd3af235);
200 OP(
FI,
C,
D,
A,
B, 2, 15, 0x2ad7d2bb);
201 OP(
FI,
B,
C,
D,
A, 9, 21, 0xeb86d391);
228 memcpy(cp, &v,
sizeof(v));
242 if (!md5ctx || !resbuf)
266 md5ctx->
A = 0x67452301;
267 md5ctx->
B = 0xefcdab89;
268 md5ctx->
C = 0x98badcfe;
269 md5ctx->
D = 0x10325476;
271 md5ctx->
total[0] = 0;
272 md5ctx->
total[1] = 0;
292 size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
295 md5ctx->
total[0] += bytes;
296 if (md5ctx->
total[0] < bytes)
303 memcpy(&((
char *) md5ctx->
buffer)[bytes],
fillbuf, (size - 2) * 4 - bytes);
338 struct Md5Ctx md5ctx = { 0 };
382 size_t left_over = md5ctx->
buflen;
383 size_t add = ((128 - left_over) >
buflen) ?
buflen : (128 - left_over);
385 memcpy(&((
char *) md5ctx->
buffer)[left_over], buf, add);
394 memcpy(md5ctx->
buffer, &((
char *) md5ctx->
buffer)[(left_over + add) & ~63],
398 buf = (
const char *) buf + add;
405#if !defined(_STRING_ARCH_unaligned)
406#define alignof(type) \
413#define UNALIGNED_P(p) (((size_t) p) % alignof(md5_uint32) != 0)
419 buf = (
const char *) buf + 64;
427 buf = (
const char *) buf + (
buflen & ~63);
435 size_t left_over = md5ctx->
buflen;
437 memcpy(&((
char *) md5ctx->
buffer)[left_over], buf,
buflen);
443 memmove(md5ctx->
buffer, &md5ctx->
buffer[16], left_over);
445 md5ctx->
buflen = left_over;
458 if (!digest || !resbuf)
461 const unsigned char *c = digest;
462 sprintf(resbuf,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
463 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10],
464 c[11], c[12], c[13], c[14], c[15]);
void * mutt_md5(const char *str, void *buf)
Calculate the MD5 hash of a NULL-terminated string.
void mutt_md5_process_bytes(const void *buf, size_t buflen, struct Md5Ctx *md5ctx)
Process a block of data.
static void * mutt_md5_read_ctx(const struct Md5Ctx *md5ctx, void *resbuf)
Read from the context into a buffer.
#define OP(a, b, c, d, s, T)
void * mutt_md5_bytes(const void *buffer, size_t len, void *resbuf)
Calculate the MD5 hash of a buffer.
void mutt_md5_process(const char *str, struct Md5Ctx *md5ctx)
Process a NULL-terminated string.
static void mutt_md5_process_block(const void *buffer, size_t len, struct Md5Ctx *md5ctx)
Process a block with MD5.
static void set_uint32(char *cp, md5_uint32 v)
Write a 32 bit number.
void mutt_md5_init_ctx(struct Md5Ctx *md5ctx)
Initialise the MD5 computation.
void * mutt_md5_finish_ctx(struct Md5Ctx *md5ctx, void *resbuf)
Process the remaining bytes in the buffer.
void mutt_md5_toascii(const void *digest, char *resbuf)
Convert a binary MD5 digest into ASCII Hexadecimal.
static const unsigned char fillbuf[64]
This array contains the bytes used to pad the buffer to the next 64-byte boundary.
Calculate the MD5 checksum of a buffer.
Cursor for the MD5 hashing.