25 #define ROTL(x,n,w) (((x)<<((n)&(w-1))) | ((x)>>(((-(n))&(w-1)))))
31 #define ROTL32(x,n) ROTL(x,n,32)
32 #define ROTL16(x,n) ROTL(x,n,16)
51 (*dst)[0] = (std::uint8_t)((src)& 0xff);
52 (*dst)[1] = (std::uint8_t)((src >> 8) & 0xff);
53 (*dst)[2] = (std::uint8_t)((src >> 16) & 0xff);
54 (*dst)[3] = (std::uint8_t)((src >> 24));
65 (*dst)[0] = (std::uint8_t)((src >> 24));
66 (*dst)[1] = (std::uint8_t)((src >> 16) & 0xff);
67 (*dst)[2] = (std::uint8_t)((src >> 8) & 0xff);
68 (*dst)[3] = (std::uint8_t)((src)& 0xff);
81 temp = ((std::uint32_t)src[0]);
82 temp |= ((std::uint32_t)src[1]) << 8;
83 temp |= ((std::uint32_t)src[2]) << 16;
84 temp |= ((std::uint32_t)src[3]) << 24;
100 (*hash)[0] = 0x67452301;
101 (*hash)[1] = 0xefcdab89;
102 (*hash)[2] = 0x98badcfe;
103 (*hash)[3] = 0x10325476;
104 (*hash)[4] = 0xc3d2e1f0;
111 std::uint32_t a, b, c, d, e, g;
113 for (i = 0; i < 64; i++)
115 tmp[i + 16] =
ROTL32(1, tmp[i] ^ tmp[i + 8] ^ tmp[i + 2] ^ tmp[i + 13]);
117 tmp[i + 16] =
ROTL32(tmp[i] ^ tmp[i + 8] ^ tmp[i + 2] ^ tmp[i + 13], 1);
125 for (i = 0; i < 20 * 1; i++)
127 g = tmp[i] +
ROTL32(a, 5) + e + ((b & c) | (~b & d)) + 0x5a827999;
135 for (; i < 20 * 2; i++)
137 g = (d ^ c ^ b) + e +
ROTL32(g, 5) + tmp[i] + 0x6ed9eba1;
145 for (; i < 20 * 3; i++)
147 g = tmp[i] +
ROTL32(g, 5) + e + ((c & b) | (d & c) | (d & b)) - 0x70e44324;
155 for (; i < 20 * 4; i++)
157 g = (d ^ c ^ b) + e +
ROTL32(g, 5) + tmp[i] - 0x359d3e2a;
179 static void hash_set_16(std::uint32_t * dst,
unsigned char const * src,
unsigned int count,
185 for (pos = 0, i = 0; i < 16; i++)
191 dst[i] |= ((std::uint32_t)src[pos]);
195 dst[i] |= ((std::uint32_t)src[pos]) << 24;
196 else if (pos == count)
197 dst[i] |= ((std::uint32_t)0x80000000);
203 dst[i] |= ((std::uint32_t)src[pos]) << 8;
207 dst[i] |= ((std::uint32_t)src[pos]) << 16;
208 else if (pos == count)
209 dst[i] |= ((std::uint32_t)0x800000);
215 dst[i] |= ((std::uint32_t)src[pos]) << 16;
219 dst[i] |= ((std::uint32_t)src[pos]) << 8;
220 else if (pos == count)
221 dst[i] |= ((std::uint32_t)0x8000);
227 dst[i] |= ((std::uint32_t)src[pos]) << 24;
231 dst[i] |= ((std::uint32_t)src[pos]);
232 else if (pos == count)
233 dst[i] |= ((std::uint32_t)0x80);
242 std::uint32_t tmp[64 + 16];
243 const unsigned char* data;
250 if (size > 0 && !datain)
257 data = (
const unsigned char*)datain;
276 std::uint32_t size_high = 0;
277 std::uint32_t size_low = 0;
278 unsigned int counter;
279 for (counter = 0; counter < size; counter++){
285 dst[14] |= ((size_high >> 24) & 0xff) << 24;
286 dst[14] |= ((size_high >> 16) & 0xff) << 16;
287 dst[14] |= ((size_high >> 8) & 0xff) << 8;
288 dst[14] |= ((size_high)& 0xff);
290 dst[15] |= ((size_low >> 24) & 0xff) << 24;
291 dst[15] |= ((size_low >> 16) & 0xff) << 16;
292 dst[15] |= ((size_low >> 8) & 0xff) << 8;
293 dst[15] |= ((size_low)& 0xff);
298 std::uint32_t tmp[64 + 16];
299 unsigned char const * data;
301 unsigned int orgSize;
307 if (size > 0 && !datain)
315 data = (
const unsigned char*)datain;
356 for (i = 0; i < 5; i++)
373 for (i = 0; i < 5; i++) {
374 if (h1[i] != h2[i]) {
385 static char temp[8 * 5 + 1];
393 for (i = 0; i < 5; i++)
394 std::sprintf(&temp[i * 8],
"%08x", hash[i]);
404 for (i = 0; i < 5; i++)
429 if (std::strlen(str) != 5 * 8)
434 for (i = 0; i < 5; i++)
435 if (std::sscanf(&str[i * 8],
"%8x", &(*hash)[i]) != 1)
456 for (i = 0; i < 5; i++)
474 for (i = 0; i < 5; i++)