37#if !defined(md5_INCLUDED)
54typedef struct md5_state_s {
60#if defined(__cplusplus)
74#if defined(__cplusplus)
133#if !defined(MD5_STATIC)
138#if defined(ARCH_IS_BIG_ENDIAN)
139#define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
141#define BYTE_ORDER (0)
144#define T_MASK ((md5_word_t)~0)
145#define T1 (T_MASK ^ 0x28955b87)
146#define T2 (T_MASK ^ 0x173848a9)
147#define T3 (0x242070db)
148#define T4 (T_MASK ^ 0x3e423111)
149#define T5 (T_MASK ^ 0x0a83f050)
150#define T6 (0x4787c62a)
151#define T7 (T_MASK ^ 0x57cfb9ec)
152#define T8 (T_MASK ^ 0x02b96afe)
153#define T9 (0x698098d8)
154#define T10 (T_MASK ^ 0x74bb0850)
155#define T11 (T_MASK ^ 0x0000a44e)
156#define T12 (T_MASK ^ 0x76a32841)
157#define T13 (0x6b901122)
158#define T14 (T_MASK ^ 0x02678e6c)
159#define T15 (T_MASK ^ 0x5986bc71)
160#define T16 (0x49b40821)
161#define T17 (T_MASK ^ 0x09e1da9d)
162#define T18 (T_MASK ^ 0x3fbf4cbf)
163#define T19 (0x265e5a51)
164#define T20 (T_MASK ^ 0x16493855)
165#define T21 (T_MASK ^ 0x29d0efa2)
166#define T22 (0x02441453)
167#define T23 (T_MASK ^ 0x275e197e)
168#define T24 (T_MASK ^ 0x182c0437)
169#define T25 (0x21e1cde6)
170#define T26 (T_MASK ^ 0x3cc8f829)
171#define T27 (T_MASK ^ 0x0b2af278)
172#define T28 (0x455a14ed)
173#define T29 (T_MASK ^ 0x561c16fa)
174#define T30 (T_MASK ^ 0x03105c07)
175#define T31 (0x676f02d9)
176#define T32 (T_MASK ^ 0x72d5b375)
177#define T33 (T_MASK ^ 0x0005c6bd)
178#define T34 (T_MASK ^ 0x788e097e)
179#define T35 (0x6d9d6122)
180#define T36 (T_MASK ^ 0x021ac7f3)
181#define T37 (T_MASK ^ 0x5b4115bb)
182#define T38 (0x4bdecfa9)
183#define T39 (T_MASK ^ 0x0944b49f)
184#define T40 (T_MASK ^ 0x4140438f)
185#define T41 (0x289b7ec6)
186#define T42 (T_MASK ^ 0x155ed805)
187#define T43 (T_MASK ^ 0x2b10cf7a)
188#define T44 (0x04881d05)
189#define T45 (T_MASK ^ 0x262b2fc6)
190#define T46 (T_MASK ^ 0x1924661a)
191#define T47 (0x1fa27cf8)
192#define T48 (T_MASK ^ 0x3b53a99a)
193#define T49 (T_MASK ^ 0x0bd6ddbb)
194#define T50 (0x432aff97)
195#define T51 (T_MASK ^ 0x546bdc58)
196#define T52 (T_MASK ^ 0x036c5fc6)
197#define T53 (0x655b59c3)
198#define T54 (T_MASK ^ 0x70f3336d)
199#define T55 (T_MASK ^ 0x00100b82)
200#define T56 (T_MASK ^ 0x7a7ba22e)
201#define T57 (0x6fa87e4f)
202#define T58 (T_MASK ^ 0x01d3191f)
203#define T59 (T_MASK ^ 0x5cfebceb)
204#define T60 (0x4e0811a1)
205#define T61 (T_MASK ^ 0x08ac817d)
206#define T62 (T_MASK ^ 0x42c50dca)
207#define T63 (0x2ad7d2bb)
208#define T64 (T_MASK ^ 0x14792c6e)
213 md5_word_t a = pms->abcd[0],
b = pms->abcd[1],
c = pms->abcd[2],
232 static const int w = 1;
251 memcpy(xbuf,
data, 64);
273 for (i = 0; i < 16; ++i, xp += 4)
281#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
286#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
287#define SET(a, b, c, d, k, s, Ti) \
288 t = a + F(b, c, d) + X[k] + Ti; \
289 a = ROTATE_LEFT(t, s) + b
313#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
314#define SET(a, b, c, d, k, s, Ti) \
315 t = a + G(b, c, d) + X[k] + Ti; \
316 a = ROTATE_LEFT(t, s) + b
340#define H(x, y, z) ((x) ^ (y) ^ (z))
341#define SET(a, b, c, d, k, s, Ti) \
342 t = a + H(b, c, d) + X[k] + Ti; \
343 a = ROTATE_LEFT(t, s) + b
367#define I(x, y, z) ((y) ^ ((x) | ~(z)))
368#define SET(a, b, c, d, k, s, Ti) \
369 t = a + I(b, c, d) + X[k] + Ti; \
370 a = ROTATE_LEFT(t, s) + b
403 pms->count[0] = pms->count[1] = 0;
404 pms->abcd[0] = 0x67452301;
405 pms->abcd[1] =
T_MASK ^ 0x10325476;
406 pms->abcd[2] =
T_MASK ^ 0x67452301;
407 pms->abcd[3] = 0x10325476;
414 size_t left = nbytes;
415 size_t offset = (pms->count[0] >> 3) & 63;
423 pms->count[0] += nbits;
424 if (pms->count[0] < nbits)
429 size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
431 memcpy(pms->buf + offset, p, copy);
432 if (offset + copy < 64)
440 for (; left >= 64; p += 64, left -= 64)
445 memcpy(pms->buf, p, left);
451 static const md5_byte_t pad[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
454 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
455 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
460 for (i = 0; i < 8; ++i)
463 md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
466 for (i = 0; i < 16; ++i)
467 digest[i] = (
md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
struct md5_state_s md5_state_t
#define SET(a, b, c, d, k, s, Ti)
MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
MD5_STATIC void md5_init(md5_state_t *pms)
MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes)
static void md5_process(md5_state_t *pms, const md5_byte_t *data)