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