54 typedef struct md5_state_s {
138 #ifdef 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)
215 a = pms->abcd[0], b = pms->abcd[1],
216 c = pms->abcd[2],
d = pms->abcd[3];
234 static const int w = 1;
249 memcpy(xbuf, data, 64);
271 for (i = 0; i < 16; ++i, xp += 4)
272 xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
277 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
282 #define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
283 #define SET(a, b, c, d, k, s, Ti)\
284 t = a + F(b,c,d) + X[k] + Ti;\
285 a = ROTATE_LEFT(t, s) + b
308 #define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
309 #define SET(a, b, c, d, k, s, Ti)\
310 t = a + G(b,c,d) + X[k] + Ti;\
311 a = ROTATE_LEFT(t, s) + b
334 #define H(x, y, z) ((x) ^ (y) ^ (z))
335 #define SET(a, b, c, d, k, s, Ti)\
336 t = a + H(b,c,d) + X[k] + Ti;\
337 a = ROTATE_LEFT(t, s) + b
360 #define I(x, y, z) ((y) ^ ((x) | ~(z)))
361 #define SET(a, b, c, d, k, s, Ti)\
362 t = a + I(b,c,d) + X[k] + Ti;\
363 a = ROTATE_LEFT(t, s) + b
395 pms->count[0] = pms->count[1] = 0;
396 pms->abcd[0] = 0x67452301;
397 pms->abcd[1] =
T_MASK ^ 0x10325476;
398 pms->abcd[2] =
T_MASK ^ 0x67452301;
399 pms->abcd[3] = 0x10325476;
407 int offset = (pms->count[0] >> 3) & 63;
414 pms->count[1] += nbytes >> 29;
415 pms->count[0] += nbits;
416 if (pms->count[0] < nbits)
421 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
423 memcpy(pms->buf + offset, p, copy);
424 if (offset + copy < 64)
432 for (; left >= 64; p += 64, left -= 64)
437 memcpy(pms->buf, p, left);
444 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
445 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
446 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
447 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
453 for (i = 0; i < 8; ++i)
454 data[i] = (
md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
456 md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
459 for (i = 0; i < 16; ++i)
460 digest[i] = (
md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
struct md5_state_s md5_state_t
static void md5_process(md5_state_t *pms, const md5_byte_t *data)
MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
#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)