97 if ((lsb += count) < t)
107 ibuffer[count++] = 0x80;
109 ibuffer[count++] = 0;
113 ibuffer[count++] = 0x80;
115 ibuffer[count++] = 0;
117 memset(ibuffer, 0, 56);
121 ibuffer[57] = lsb >> 8;
122 ibuffer[58] = lsb >> 16;
123 ibuffer[59] = lsb >> 24;
125 ibuffer[61] = msb >> 8;
126 ibuffer[62] = msb >> 16;
127 ibuffer[63] = msb >> 24;
132 #if (LIBXCKS_BYTE_ORDER == LIBXCKS_LITTLE_ENDIAN)
133 #define X(a) do { *(uint32_t*)p = a ; p += 4; } while(0)
135 #define X(a) do { *p++ = a; *p++ = a >> 8; \
136 *p++ = a >> 16; *p++ = a >> 24; } while(0)
150 void MD5::update(
const uint8_t* buf,
size_t len)
164 for (; len && count < 64; len--)
165 ibuffer[count++] = *buf++;
173 uint8_t tmpBuf[
sizeof(uint32_t) * 16];
174 memcpy(tmpBuf, buf,
sizeof(uint32_t) * 16);
182 for(; len && count < 64; len--)
183 ibuffer[count++] = *buf++;
192 #define FF(b, c, d) (d ^ (b & (c ^ d)))
193 #define FG(b, c, d) FF (d, b, c)
194 #define FH(b, c, d) (b ^ c ^ d)
195 #define FI(b, c, d) (c ^ (b | ~d))
201 void MD5::transform(uint8_t* data)
203 uint32_t correct_words[16];
208 uint32_t* cwp = correct_words;
210 #if (LIBXCKS_BYTE_ORDER == LIBXCKS_BIG_ENDIAN)
214 for (i = 0, p1 = data, p2 = (uint8_t*)correct_words; i < 16; i++, p2 += 4)
223 memcpy(correct_words, data, 64);
233 #define OP(a, b, c, d, s, T) \
236 a += FF(b, c, d) + (*cwp++) + T; \
249 OP(A, B, C, D, 7, 0xd76aa478);
250 OP(D, A, B, C, 12, 0xe8c7b756);
251 OP(C, D, A, B, 17, 0x242070db);
252 OP(B, C, D, A, 22, 0xc1bdceee);
253 OP(A, B, C, D, 7, 0xf57c0faf);
254 OP(D, A, B, C, 12, 0x4787c62a);
255 OP(C, D, A, B, 17, 0xa8304613);
256 OP(B, C, D, A, 22, 0xfd469501);
257 OP(A, B, C, D, 7, 0x698098d8);
258 OP(D, A, B, C, 12, 0x8b44f7af);
259 OP(C, D, A, B, 17, 0xffff5bb1);
260 OP(B, C, D, A, 22, 0x895cd7be);
261 OP(A, B, C, D, 7, 0x6b901122);
262 OP(D, A, B, C, 12, 0xfd987193);
263 OP(C, D, A, B, 17, 0xa679438e);
264 OP(B, C, D, A, 22, 0x49b40821);
271 #define OP(f, a, b, c, d, k, s, T) \
274 a += f (b, c, d) + correct_words[k] + T; \
281 OP(
FG, A, B, C, D, 1, 5, 0xf61e2562);
282 OP(
FG, D, A, B, C, 6, 9, 0xc040b340);
283 OP(
FG, C, D, A, B, 11, 14, 0x265e5a51);
284 OP(
FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
285 OP(
FG, A, B, C, D, 5, 5, 0xd62f105d);
286 OP(
FG, D, A, B, C, 10, 9, 0x02441453);
287 OP(
FG, C, D, A, B, 15, 14, 0xd8a1e681);
288 OP(
FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
289 OP(
FG, A, B, C, D, 9, 5, 0x21e1cde6);
290 OP(
FG, D, A, B, C, 14, 9, 0xc33707d6);
291 OP(
FG, C, D, A, B, 3, 14, 0xf4d50d87);
292 OP(
FG, B, C, D, A, 8, 20, 0x455a14ed);
293 OP(
FG, A, B, C, D, 13, 5, 0xa9e3e905);
294 OP(
FG, D, A, B, C, 2, 9, 0xfcefa3f8);
295 OP(
FG, C, D, A, B, 7, 14, 0x676f02d9);
296 OP(
FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
299 OP(
FH, A, B, C, D, 5, 4, 0xfffa3942);
300 OP(
FH, D, A, B, C, 8, 11, 0x8771f681);
301 OP(
FH, C, D, A, B, 11, 16, 0x6d9d6122);
302 OP(
FH, B, C, D, A, 14, 23, 0xfde5380c);
303 OP(
FH, A, B, C, D, 1, 4, 0xa4beea44);
304 OP(
FH, D, A, B, C, 4, 11, 0x4bdecfa9);
305 OP(
FH, C, D, A, B, 7, 16, 0xf6bb4b60);
306 OP(
FH, B, C, D, A, 10, 23, 0xbebfbc70);
307 OP(
FH, A, B, C, D, 13, 4, 0x289b7ec6);
308 OP(
FH, D, A, B, C, 0, 11, 0xeaa127fa);
309 OP(
FH, C, D, A, B, 3, 16, 0xd4ef3085);
310 OP(
FH, B, C, D, A, 6, 23, 0x04881d05);
311 OP(
FH, A, B, C, D, 9, 4, 0xd9d4d039);
312 OP(
FH, D, A, B, C, 12, 11, 0xe6db99e5);
313 OP(
FH, C, D, A, B, 15, 16, 0x1fa27cf8);
314 OP(
FH, B, C, D, A, 2, 23, 0xc4ac5665);
317 OP(
FI, A, B, C, D, 0, 6, 0xf4292244);
318 OP(
FI, D, A, B, C, 7, 10, 0x432aff97);
319 OP(
FI, C, D, A, B, 14, 15, 0xab9423a7);
320 OP(
FI, B, C, D, A, 5, 21, 0xfc93a039);
321 OP(
FI, A, B, C, D, 12, 6, 0x655b59c3);
322 OP(
FI, D, A, B, C, 3, 10, 0x8f0ccc92);
323 OP(
FI, C, D, A, B, 10, 15, 0xffeff47d);
324 OP(
FI, B, C, D, A, 1, 21, 0x85845dd1);
325 OP(
FI, A, B, C, D, 8, 6, 0x6fa87e4f);
326 OP(
FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
327 OP(
FI, C, D, A, B, 6, 15, 0xa3014314);
328 OP(
FI, B, C, D, A, 13, 21, 0x4e0811a1);
329 OP(
FI, A, B, C, D, 4, 6, 0xf7537e82);
330 OP(
FI, D, A, B, C, 11, 10, 0xbd3af235);
331 OP(
FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
332 OP(
FI, B, C, D, A, 9, 21, 0xeb86d391);
347 uint8_t* MD5::getValue(uint8_t* buffer)
const
352 (
reinterpret_cast<uint32_t*
>(buffer))[0] = swapOnBE(md5.
A_);
353 (
reinterpret_cast<uint32_t*
>(buffer))[1] = swapOnBE(md5.
B_);
354 (
reinterpret_cast<uint32_t*
>(buffer))[2] = swapOnBE(md5.
C_);
355 (
reinterpret_cast<uint32_t*
>(buffer))[3] = swapOnBE(md5.
D_);
Computes the MD5 hash from a byte stream.
uint32_t B_
Second part of the state of computation.
uint32_t C_
Third part of the state of computation.
uint32_t A_
First part of the state of computation.
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
uint32_t D_
Fourth part of the state of computation.
#define FH(b, c, d)
Third fonction of the MD5 algorithm.
#define FG(b, c, d)
Second fonction of the MD5 algorithm.
#define OP(a, b, c, d, s, T)
First round.
#define FI(b, c, d)
Fourth fonction of the MD5 algorithm.
#define X(a)
Helper function for MD5's computing.