MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / Md5Hex

Function Md5Hex

apps/tools/Tools/commands/PboCommand.cpp:44–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44std::string Md5Hex(const void* data, size_t size)
45{
46 static constexpr std::array<uint32_t, 64> shifts = {7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
47 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
48 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
49 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21};
50
51 static constexpr std::array<uint32_t, 64> constants = {
52 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
53 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
54 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
55 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
56 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
57 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
58 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
59 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391};
60
61 const auto* input = static_cast<const uint8_t*>(data);
62 std::vector<uint8_t> message(input, input + size);
63 const uint64_t bitLength = static_cast<uint64_t>(size) * 8U;
64
65 message.push_back(0x80);
66 while ((message.size() % 64) != 56)
67 message.push_back(0);
68
69 for (int i = 0; i < 8; ++i)
70 message.push_back(static_cast<uint8_t>((bitLength >> (8 * i)) & 0xffU));
71
72 uint32_t a0 = 0x67452301;
73 uint32_t b0 = 0xefcdab89;
74 uint32_t c0 = 0x98badcfe;
75 uint32_t d0 = 0x10325476;
76
77 for (size_t offset = 0; offset < message.size(); offset += 64)
78 {
79 uint32_t words[16];
80 for (int i = 0; i < 16; ++i)
81 {
82 const size_t j = offset + static_cast<size_t>(i) * 4;
83 words[i] = static_cast<uint32_t>(message[j]) | (static_cast<uint32_t>(message[j + 1]) << 8) |
84 (static_cast<uint32_t>(message[j + 2]) << 16) | (static_cast<uint32_t>(message[j + 3]) << 24);
85 }
86
87 uint32_t a = a0;
88 uint32_t b = b0;
89 uint32_t c = c0;
90 uint32_t d = d0;
91
92 for (uint32_t i = 0; i < 64; ++i)
93 {
94 uint32_t f = 0;
95 uint32_t g = 0;
96 if (i < 16)
97 {
98 f = (b & c) | (~b & d);
99 g = i;
100 }
101 else if (i < 32)

Callers 1

ListMethod · 0.85

Calls 5

RotateLeftFunction · 0.85
sizeMethod · 0.80
strMethod · 0.80
GetDataMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected