312 m_state[0] = 0x67452301;
313 m_state[1] = 0xefcdab89;
314 m_state[2] = 0x98badcfe;
315 m_state[3] = 0x10325476;
320 static const uint8_t md5_padding[64] = {
321 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
322 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
323 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
328 memcpy(
final, m_counter,
sizeof(m_counter));
331 size_t index = (m_counter[0] >> 3) & 0x3f;
332 size_t remainder = index < 56 ? 56 - index : 120 - index;
333 hash(md5_padding, remainder);
339 memcpy(&m_value, m_state,
sizeof(
md5_t));
343 virtual void hash_block()
345 constexpr int S11 = 7;
346 constexpr int S12 = 12;
347 constexpr int S13 = 17;
348 constexpr int S14 = 22;
349 constexpr int S21 = 5;
350 constexpr int S22 = 9;
351 constexpr int S23 = 14;
352 constexpr int S24 = 20;
353 constexpr int S31 = 4;
354 constexpr int S32 = 11;
355 constexpr int S33 = 16;
356 constexpr int S34 = 23;
357 constexpr int S41 = 6;
358 constexpr int S42 = 10;
359 constexpr int S43 = 15;
360 constexpr int S44 = 21;
363 uint32_t a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3];
366 #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); }
367 #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); }
368 #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); }
369 #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); }
372 MD5_R1(a, b, c, d, 0, S11, 0xd76aa478);
373 MD5_R1(d, a, b, c, 1, S12, 0xe8c7b756);
374 MD5_R1(c, d, a, b, 2, S13, 0x242070db);
375 MD5_R1(b, c, d, a, 3, S14, 0xc1bdceee);
376 MD5_R1(a, b, c, d, 4, S11, 0xf57c0faf);
377 MD5_R1(d, a, b, c, 5, S12, 0x4787c62a);
378 MD5_R1(c, d, a, b, 6, S13, 0xa8304613);
379 MD5_R1(b, c, d, a, 7, S14, 0xfd469501);
380 MD5_R1(a, b, c, d, 8, S11, 0x698098d8);
381 MD5_R1(d, a, b, c, 9, S12, 0x8b44f7af);
382 MD5_R1(c, d, a, b, 10, S13, 0xffff5bb1);
383 MD5_R1(b, c, d, a, 11, S14, 0x895cd7be);
384 MD5_R1(a, b, c, d, 12, S11, 0x6b901122);
385 MD5_R1(d, a, b, c, 13, S12, 0xfd987193);
386 MD5_R1(c, d, a, b, 14, S13, 0xa679438e);
387 MD5_R1(b, c, d, a, 15, S14, 0x49b40821);
388 MD5_R2(a, b, c, d, 1, S21, 0xf61e2562);
389 MD5_R2(d, a, b, c, 6, S22, 0xc040b340);
390 MD5_R2(c, d, a, b, 11, S23, 0x265e5a51);
391 MD5_R2(b, c, d, a, 0, S24, 0xe9b6c7aa);
392 MD5_R2(a, b, c, d, 5, S21, 0xd62f105d);
393 MD5_R2(d, a, b, c, 10, S22, 0x2441453);
394 MD5_R2(c, d, a, b, 15, S23, 0xd8a1e681);
395 MD5_R2(b, c, d, a, 4, S24, 0xe7d3fbc8);
396 MD5_R2(a, b, c, d, 9, S21, 0x21e1cde6);
397 MD5_R2(d, a, b, c, 14, S22, 0xc33707d6);
398 MD5_R2(c, d, a, b, 3, S23, 0xf4d50d87);
399 MD5_R2(b, c, d, a, 8, S24, 0x455a14ed);
400 MD5_R2(a, b, c, d, 13, S21, 0xa9e3e905);
401 MD5_R2(d, a, b, c, 2, S22, 0xfcefa3f8);
402 MD5_R2(c, d, a, b, 7, S23, 0x676f02d9);
403 MD5_R2(b, c, d, a, 12, S24, 0x8d2a4c8a);
404 MD5_R3(a, b, c, d, 5, S31, 0xfffa3942);
405 MD5_R3(d, a, b, c, 8, S32, 0x8771f681);
406 MD5_R3(c, d, a, b, 11, S33, 0x6d9d6122);
407 MD5_R3(b, c, d, a, 14, S34, 0xfde5380c);
408 MD5_R3(a, b, c, d, 1, S31, 0xa4beea44);
409 MD5_R3(d, a, b, c, 4, S32, 0x4bdecfa9);
410 MD5_R3(c, d, a, b, 7, S33, 0xf6bb4b60);
411 MD5_R3(b, c, d, a, 10, S34, 0xbebfbc70);
412 MD5_R3(a, b, c, d, 13, S31, 0x289b7ec6);
413 MD5_R3(d, a, b, c, 0, S32, 0xeaa127fa);
414 MD5_R3(c, d, a, b, 3, S33, 0xd4ef3085);
415 MD5_R3(b, c, d, a, 6, S34, 0x4881d05);
416 MD5_R3(a, b, c, d, 9, S31, 0xd9d4d039);
417 MD5_R3(d, a, b, c, 12, S32, 0xe6db99e5);
418 MD5_R3(c, d, a, b, 15, S33, 0x1fa27cf8);
419 MD5_R3(b, c, d, a, 2, S34, 0xc4ac5665);
420 MD5_R4(a, b, c, d, 0, S41, 0xf4292244);
421 MD5_R4(d, a, b, c, 7, S42, 0x432aff97);
422 MD5_R4(c, d, a, b, 14, S43, 0xab9423a7);
423 MD5_R4(b, c, d, a, 5, S44, 0xfc93a039);
424 MD5_R4(a, b, c, d, 12, S41, 0x655b59c3);
425 MD5_R4(d, a, b, c, 3, S42, 0x8f0ccc92);
426 MD5_R4(c, d, a, b, 10, S43, 0xffeff47d);
427 MD5_R4(b, c, d, a, 1, S44, 0x85845dd1);
428 MD5_R4(a, b, c, d, 8, S41, 0x6fa87e4f);
429 MD5_R4(d, a, b, c, 15, S42, 0xfe2ce6e0);
430 MD5_R4(c, d, a, b, 6, S43, 0xa3014314);
431 MD5_R4(b, c, d, a, 13, S44, 0x4e0811a1);
432 MD5_R4(a, b, c, d, 4, S41, 0xf7537e82);
433 MD5_R4(d, a, b, c, 11, S42, 0xbd3af235);
434 MD5_R4(c, d, a, b, 2, S43, 0x2ad7d2bb);
435 MD5_R4(b, c, d, a, 9, S44, 0xeb86d391);
515 m_state[0] = 0x67452301;
516 m_state[1] = 0xEFCDAB89;
517 m_state[2] = 0x98BADCFE;
518 m_state[3] = 0x10325476;
519 m_state[4] = 0xC3D2E1F0;
526 for (
size_t i = 0; i < 8; i++)
527 final[i] =
static_cast<uint8_t
>((m_counter[((i >= 4) ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255);
530 while ((m_counter[0] & 504) != 448)
535 for (
size_t i = 0; i < 20; i++)
536 m_value.data8[i] =
static_cast<uint8_t
>((m_state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
540 virtual void hash_block()
543 uint32_t a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], e = m_state[4];
545#if BYTE_ORDER == BIG_ENDIAN
546 #define SHA1BLK0(i) (m_temp[i])
548 #define SHA1BLK0(i) (m_temp[i] = (rol(m_temp[i],24) & 0xFF00FF00) | (rol(m_temp[i],8) & 0x00FF00FF))
550 #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))
553 #define SHA1_R0(v, w, x, y, z, i) { (z) += (((w)&((x)^(y)))^(y))+SHA1BLK0((i))+0x5A827999+rol((v),5); (w)=rol((w),30); }
554 #define SHA1_R1(v, w, x, y, z, i) { (z) += (((w)&((x)^(y)))^(y))+SHA1BLK((i))+0x5A827999+rol((v),5); (w)=rol((w),30); }
555 #define SHA1_R2(v, w, x, y, z, i) { (z) += ((w)^(x)^(y))+SHA1BLK((i))+0x6ED9EBA1+rol((v),5); (w)=rol((w),30); }
556 #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); }
557 #define SHA1_R4(v, w, x, y, z, i) { (z) += ((w)^(x)^(y))+SHA1BLK((i))+0xCA62C1D6+rol((v),5); (w)=rol((w),30); }
560 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);
561 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);
562 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);
563 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);
564 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);
565 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);
566 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);
567 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);
568 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);
569 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);
570 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);
571 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);
572 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);
573 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);
574 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);
575 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);
576 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);
577 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);
578 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);
579 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);