282 m_state[0] = 0x67452301;
283 m_state[1] = 0xefcdab89;
284 m_state[2] = 0x98badcfe;
285 m_state[3] = 0x10325476;
290 static const uint8_t md5_padding[64] = {
291 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
292 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
293 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
298 memcpy(
final, m_counter,
sizeof(m_counter));
301 size_t index = (m_counter[0] >> 3) & 0x3f;
302 size_t remainder = index < 56 ? 56 - index : 120 - index;
303 hash(md5_padding, remainder);
309 memcpy(&m_value, m_state,
sizeof(
md5_t));
313 virtual void hash_block()
315 constexpr int S11 = 7;
316 constexpr int S12 = 12;
317 constexpr int S13 = 17;
318 constexpr int S14 = 22;
319 constexpr int S21 = 5;
320 constexpr int S22 = 9;
321 constexpr int S23 = 14;
322 constexpr int S24 = 20;
323 constexpr int S31 = 4;
324 constexpr int S32 = 11;
325 constexpr int S33 = 16;
326 constexpr int S34 = 23;
327 constexpr int S41 = 6;
328 constexpr int S42 = 10;
329 constexpr int S43 = 15;
330 constexpr int S44 = 21;
333 uint32_t a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3];
336 #define MD5_R1(a, b, c, d, i, s, ac) { (a) += (((b) & (c)) | ((~b) & (d))) + m_temp[(i)] + static_cast<uint32_t>(ac); (a) = rol((a), (s)); (a) += (b); }
337 #define MD5_R2(a, b, c, d, i, s, ac) { (a) += (((b) & (d)) | ((c) & (~d))) + m_temp[(i)] + static_cast<uint32_t>(ac); (a) = rol((a), (s)); (a) += (b); }
338 #define MD5_R3(a, b, c, d, i, s, ac) { (a) += ((b) ^ (c) ^ (d)) + m_temp[(i)] + static_cast<uint32_t>(ac); (a) = rol((a), (s)); (a) += (b); }
339 #define MD5_R4(a, b, c, d, i, s, ac) { (a) += ((c) ^ ((b) | (~d))) + m_temp[(i)] + static_cast<uint32_t>(ac); (a) = rol((a), (s)); (a) += (b); }
342 MD5_R1(a, b, c, d, 0, S11, 0xd76aa478);
343 MD5_R1(d, a, b, c, 1, S12, 0xe8c7b756);
344 MD5_R1(c, d, a, b, 2, S13, 0x242070db);
345 MD5_R1(b, c, d, a, 3, S14, 0xc1bdceee);
346 MD5_R1(a, b, c, d, 4, S11, 0xf57c0faf);
347 MD5_R1(d, a, b, c, 5, S12, 0x4787c62a);
348 MD5_R1(c, d, a, b, 6, S13, 0xa8304613);
349 MD5_R1(b, c, d, a, 7, S14, 0xfd469501);
350 MD5_R1(a, b, c, d, 8, S11, 0x698098d8);
351 MD5_R1(d, a, b, c, 9, S12, 0x8b44f7af);
352 MD5_R1(c, d, a, b, 10, S13, 0xffff5bb1);
353 MD5_R1(b, c, d, a, 11, S14, 0x895cd7be);
354 MD5_R1(a, b, c, d, 12, S11, 0x6b901122);
355 MD5_R1(d, a, b, c, 13, S12, 0xfd987193);
356 MD5_R1(c, d, a, b, 14, S13, 0xa679438e);
357 MD5_R1(b, c, d, a, 15, S14, 0x49b40821);
358 MD5_R2(a, b, c, d, 1, S21, 0xf61e2562);
359 MD5_R2(d, a, b, c, 6, S22, 0xc040b340);
360 MD5_R2(c, d, a, b, 11, S23, 0x265e5a51);
361 MD5_R2(b, c, d, a, 0, S24, 0xe9b6c7aa);
362 MD5_R2(a, b, c, d, 5, S21, 0xd62f105d);
363 MD5_R2(d, a, b, c, 10, S22, 0x2441453);
364 MD5_R2(c, d, a, b, 15, S23, 0xd8a1e681);
365 MD5_R2(b, c, d, a, 4, S24, 0xe7d3fbc8);
366 MD5_R2(a, b, c, d, 9, S21, 0x21e1cde6);
367 MD5_R2(d, a, b, c, 14, S22, 0xc33707d6);
368 MD5_R2(c, d, a, b, 3, S23, 0xf4d50d87);
369 MD5_R2(b, c, d, a, 8, S24, 0x455a14ed);
370 MD5_R2(a, b, c, d, 13, S21, 0xa9e3e905);
371 MD5_R2(d, a, b, c, 2, S22, 0xfcefa3f8);
372 MD5_R2(c, d, a, b, 7, S23, 0x676f02d9);
373 MD5_R2(b, c, d, a, 12, S24, 0x8d2a4c8a);
374 MD5_R3(a, b, c, d, 5, S31, 0xfffa3942);
375 MD5_R3(d, a, b, c, 8, S32, 0x8771f681);
376 MD5_R3(c, d, a, b, 11, S33, 0x6d9d6122);
377 MD5_R3(b, c, d, a, 14, S34, 0xfde5380c);
378 MD5_R3(a, b, c, d, 1, S31, 0xa4beea44);
379 MD5_R3(d, a, b, c, 4, S32, 0x4bdecfa9);
380 MD5_R3(c, d, a, b, 7, S33, 0xf6bb4b60);
381 MD5_R3(b, c, d, a, 10, S34, 0xbebfbc70);
382 MD5_R3(a, b, c, d, 13, S31, 0x289b7ec6);
383 MD5_R3(d, a, b, c, 0, S32, 0xeaa127fa);
384 MD5_R3(c, d, a, b, 3, S33, 0xd4ef3085);
385 MD5_R3(b, c, d, a, 6, S34, 0x4881d05);
386 MD5_R3(a, b, c, d, 9, S31, 0xd9d4d039);
387 MD5_R3(d, a, b, c, 12, S32, 0xe6db99e5);
388 MD5_R3(c, d, a, b, 15, S33, 0x1fa27cf8);
389 MD5_R3(b, c, d, a, 2, S34, 0xc4ac5665);
390 MD5_R4(a, b, c, d, 0, S41, 0xf4292244);
391 MD5_R4(d, a, b, c, 7, S42, 0x432aff97);
392 MD5_R4(c, d, a, b, 14, S43, 0xab9423a7);
393 MD5_R4(b, c, d, a, 5, S44, 0xfc93a039);
394 MD5_R4(a, b, c, d, 12, S41, 0x655b59c3);
395 MD5_R4(d, a, b, c, 3, S42, 0x8f0ccc92);
396 MD5_R4(c, d, a, b, 10, S43, 0xffeff47d);
397 MD5_R4(b, c, d, a, 1, S44, 0x85845dd1);
398 MD5_R4(a, b, c, d, 8, S41, 0x6fa87e4f);
399 MD5_R4(d, a, b, c, 15, S42, 0xfe2ce6e0);
400 MD5_R4(c, d, a, b, 6, S43, 0xa3014314);
401 MD5_R4(b, c, d, a, 13, S44, 0x4e0811a1);
402 MD5_R4(a, b, c, d, 4, S41, 0xf7537e82);
403 MD5_R4(d, a, b, c, 11, S42, 0xbd3af235);
404 MD5_R4(c, d, a, b, 2, S43, 0x2ad7d2bb);
405 MD5_R4(b, c, d, a, 9, S44, 0xeb86d391);
453 m_state[0] = 0x67452301;
454 m_state[1] = 0xEFCDAB89;
455 m_state[2] = 0x98BADCFE;
456 m_state[3] = 0x10325476;
457 m_state[4] = 0xC3D2E1F0;
464 for (
size_t i = 0; i < 8; i++)
465 final[i] =
static_cast<uint8_t
>((m_counter[((i >= 4) ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255);
468 while ((m_counter[0] & 504) != 448)
473 for (
size_t i = 0; i < 20; i++)
474 m_value.data8[i] =
static_cast<uint8_t
>((m_state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
478 virtual void hash_block()
481 uint32_t a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], e = m_state[4];
483#if BYTE_ORDER == BIG_ENDIAN
484 #define SHA1BLK0(i) (m_temp[i])
486 #define SHA1BLK0(i) (m_temp[i] = (rol(m_temp[i],24) & 0xFF00FF00) | (rol(m_temp[i],8) & 0x00FF00FF))
488 #define SHA1BLK(i) (m_temp[i&15] = rol(m_temp[(i+13)&15] ^ m_temp[(i+8)&15] ^ m_temp[(i+2)&15] ^ m_temp[i&15],1))
491 #define SHA1_R0(v, w, x, y, z, i) { (z) += (((w)&((x)^(y)))^(y))+SHA1BLK0((i))+0x5A827999+rol((v),5); (w)=rol((w),30); }
492 #define SHA1_R1(v, w, x, y, z, i) { (z) += (((w)&((x)^(y)))^(y))+SHA1BLK((i))+0x5A827999+rol((v),5); (w)=rol((w),30); }
493 #define SHA1_R2(v, w, x, y, z, i) { (z) += ((w)^(x)^(y))+SHA1BLK((i))+0x6ED9EBA1+rol((v),5); (w)=rol((w),30); }
494 #define SHA1_R3(v, w, x, y, z, i) { (z) += ((((w)|(x))&(y))|((w)&(x)))+SHA1BLK((i))+0x8F1BBCDC+rol((v),5); (w)=rol((w),30); }
495 #define SHA1_R4(v, w, x, y, z, i) { (z) += ((w)^(x)^(y))+SHA1BLK((i))+0xCA62C1D6+rol((v),5); (w)=rol((w),30); }
498 SHA1_R0(a, b, c, d, e, 0); SHA1_R0(e, a, b, c, d, 1); SHA1_R0(d, e, a, b, c, 2); SHA1_R0(c, d, e, a, b, 3);
499 SHA1_R0(b, c, d, e, a, 4); SHA1_R0(a, b, c, d, e, 5); SHA1_R0(e, a, b, c, d, 6); SHA1_R0(d, e, a, b, c, 7);
500 SHA1_R0(c, d, e, a, b, 8); SHA1_R0(b, c, d, e, a, 9); SHA1_R0(a, b, c, d, e, 10); SHA1_R0(e, a, b, c, d, 11);
501 SHA1_R0(d, e, a, b, c, 12); SHA1_R0(c, d, e, a, b, 13); SHA1_R0(b, c, d, e, a, 14); SHA1_R0(a, b, c, d, e, 15);
502 SHA1_R1(e, a, b, c, d, 16); SHA1_R1(d, e, a, b, c, 17); SHA1_R1(c, d, e, a, b, 18); SHA1_R1(b, c, d, e, a, 19);
503 SHA1_R2(a, b, c, d, e, 20); SHA1_R2(e, a, b, c, d, 21); SHA1_R2(d, e, a, b, c, 22); SHA1_R2(c, d, e, a, b, 23);
504 SHA1_R2(b, c, d, e, a, 24); SHA1_R2(a, b, c, d, e, 25); SHA1_R2(e, a, b, c, d, 26); SHA1_R2(d, e, a, b, c, 27);
505 SHA1_R2(c, d, e, a, b, 28); SHA1_R2(b, c, d, e, a, 29); SHA1_R2(a, b, c, d, e, 30); SHA1_R2(e, a, b, c, d, 31);
506 SHA1_R2(d, e, a, b, c, 32); SHA1_R2(c, d, e, a, b, 33); SHA1_R2(b, c, d, e, a, 34); SHA1_R2(a, b, c, d, e, 35);
507 SHA1_R2(e, a, b, c, d, 36); SHA1_R2(d, e, a, b, c, 37); SHA1_R2(c, d, e, a, b, 38); SHA1_R2(b, c, d, e, a, 39);
508 SHA1_R3(a, b, c, d, e, 40); SHA1_R3(e, a, b, c, d, 41); SHA1_R3(d, e, a, b, c, 42); SHA1_R3(c, d, e, a, b, 43);
509 SHA1_R3(b, c, d, e, a, 44); SHA1_R3(a, b, c, d, e, 45); SHA1_R3(e, a, b, c, d, 46); SHA1_R3(d, e, a, b, c, 47);
510 SHA1_R3(c, d, e, a, b, 48); SHA1_R3(b, c, d, e, a, 49); SHA1_R3(a, b, c, d, e, 50); SHA1_R3(e, a, b, c, d, 51);
511 SHA1_R3(d, e, a, b, c, 52); SHA1_R3(c, d, e, a, b, 53); SHA1_R3(b, c, d, e, a, 54); SHA1_R3(a, b, c, d, e, 55);
512 SHA1_R3(e, a, b, c, d, 56); SHA1_R3(d, e, a, b, c, 57); SHA1_R3(c, d, e, a, b, 58); SHA1_R3(b, c, d, e, a, 59);
513 SHA1_R4(a, b, c, d, e, 60); SHA1_R4(e, a, b, c, d, 61); SHA1_R4(d, e, a, b, c, 62); SHA1_R4(c, d, e, a, b, 63);
514 SHA1_R4(b, c, d, e, a, 64); SHA1_R4(a, b, c, d, e, 65); SHA1_R4(e, a, b, c, d, 66); SHA1_R4(d, e, a, b, c, 67);
515 SHA1_R4(c, d, e, a, b, 68); SHA1_R4(b, c, d, e, a, 69); SHA1_R4(a, b, c, d, e, 70); SHA1_R4(e, a, b, c, d, 71);
516 SHA1_R4(d, e, a, b, c, 72); SHA1_R4(c, d, e, a, b, 73); SHA1_R4(b, c, d, e, a, 74); SHA1_R4(a, b, c, d, e, 75);
517 SHA1_R4(e, a, b, c, d, 76); SHA1_R4(d, e, a, b, c, 77); SHA1_R4(c, d, e, a, b, 78); SHA1_R4(b, c, d, e, a, 79);