12e0724c7Sespie /* md5.c - Functions to compute MD5 message digest of files or memory blocks
22e0724c7Sespie according to the definition of MD5 in RFC 1321 from April 1992.
32e0724c7Sespie Copyright (C) 1995, 1996 Free Software Foundation, Inc.
42e0724c7Sespie
52e0724c7Sespie NOTE: This source is derived from an old version taken from the GNU C
62e0724c7Sespie Library (glibc).
72e0724c7Sespie
82e0724c7Sespie This program is free software; you can redistribute it and/or modify it
92e0724c7Sespie under the terms of the GNU General Public License as published by the
102e0724c7Sespie Free Software Foundation; either version 2, or (at your option) any
112e0724c7Sespie later version.
122e0724c7Sespie
132e0724c7Sespie This program is distributed in the hope that it will be useful,
142e0724c7Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
152e0724c7Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
162e0724c7Sespie GNU General Public License for more details.
172e0724c7Sespie
182e0724c7Sespie You should have received a copy of the GNU General Public License
192e0724c7Sespie along with this program; if not, write to the Free Software Foundation,
20*20fce977Smiod Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
212e0724c7Sespie
222e0724c7Sespie /* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */
232e0724c7Sespie
242e0724c7Sespie #ifdef HAVE_CONFIG_H
252e0724c7Sespie # include <config.h>
262e0724c7Sespie #endif
272e0724c7Sespie
282e0724c7Sespie #include <sys/types.h>
292e0724c7Sespie
302e0724c7Sespie #if STDC_HEADERS || defined _LIBC
312e0724c7Sespie # include <stdlib.h>
322e0724c7Sespie # include <string.h>
332e0724c7Sespie #else
342e0724c7Sespie # ifndef HAVE_MEMCPY
352e0724c7Sespie # define memcpy(d, s, n) bcopy ((s), (d), (n))
362e0724c7Sespie # endif
372e0724c7Sespie #endif
382e0724c7Sespie
392e0724c7Sespie #include "ansidecl.h"
402e0724c7Sespie #include "md5.h"
412e0724c7Sespie
422e0724c7Sespie #ifdef _LIBC
432e0724c7Sespie # include <endian.h>
442e0724c7Sespie # if __BYTE_ORDER == __BIG_ENDIAN
452e0724c7Sespie # define WORDS_BIGENDIAN 1
462e0724c7Sespie # endif
472e0724c7Sespie #endif
482e0724c7Sespie
492e0724c7Sespie #ifdef WORDS_BIGENDIAN
502e0724c7Sespie # define SWAP(n) \
512e0724c7Sespie (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
522e0724c7Sespie #else
532e0724c7Sespie # define SWAP(n) (n)
542e0724c7Sespie #endif
552e0724c7Sespie
562e0724c7Sespie
572e0724c7Sespie /* This array contains the bytes used to pad the buffer to the next
582e0724c7Sespie 64-byte boundary. (RFC 1321, 3.1: Step 1) */
592e0724c7Sespie static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
602e0724c7Sespie
612e0724c7Sespie
622e0724c7Sespie /* Initialize structure containing state of computation.
632e0724c7Sespie (RFC 1321, 3.3: Step 3) */
642e0724c7Sespie void
md5_init_ctx(struct md5_ctx * ctx)65*20fce977Smiod md5_init_ctx (struct md5_ctx *ctx)
662e0724c7Sespie {
679588ddcfSespie ctx->A = (md5_uint32) 0x67452301;
689588ddcfSespie ctx->B = (md5_uint32) 0xefcdab89;
699588ddcfSespie ctx->C = (md5_uint32) 0x98badcfe;
709588ddcfSespie ctx->D = (md5_uint32) 0x10325476;
712e0724c7Sespie
722e0724c7Sespie ctx->total[0] = ctx->total[1] = 0;
732e0724c7Sespie ctx->buflen = 0;
742e0724c7Sespie }
752e0724c7Sespie
762e0724c7Sespie /* Put result from CTX in first 16 bytes following RESBUF. The result
772e0724c7Sespie must be in little endian byte order.
782e0724c7Sespie
792e0724c7Sespie IMPORTANT: On some systems it is required that RESBUF is correctly
802e0724c7Sespie aligned for a 32 bits value. */
812e0724c7Sespie void *
md5_read_ctx(const struct md5_ctx * ctx,void * resbuf)82*20fce977Smiod md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
832e0724c7Sespie {
842e0724c7Sespie ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
852e0724c7Sespie ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
862e0724c7Sespie ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
872e0724c7Sespie ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
882e0724c7Sespie
892e0724c7Sespie return resbuf;
902e0724c7Sespie }
912e0724c7Sespie
922e0724c7Sespie /* Process the remaining bytes in the internal buffer and the usual
932e0724c7Sespie prolog according to the standard and write the result to RESBUF.
942e0724c7Sespie
952e0724c7Sespie IMPORTANT: On some systems it is required that RESBUF is correctly
962e0724c7Sespie aligned for a 32 bits value. */
972e0724c7Sespie void *
md5_finish_ctx(struct md5_ctx * ctx,void * resbuf)98*20fce977Smiod md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
992e0724c7Sespie {
1002e0724c7Sespie /* Take yet unprocessed bytes into account. */
1012e0724c7Sespie md5_uint32 bytes = ctx->buflen;
1022e0724c7Sespie size_t pad;
1032e0724c7Sespie
1042e0724c7Sespie /* Now count remaining bytes. */
1052e0724c7Sespie ctx->total[0] += bytes;
1062e0724c7Sespie if (ctx->total[0] < bytes)
1072e0724c7Sespie ++ctx->total[1];
1082e0724c7Sespie
1092e0724c7Sespie pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
1102e0724c7Sespie memcpy (&ctx->buffer[bytes], fillbuf, pad);
1112e0724c7Sespie
1122e0724c7Sespie /* Put the 64-bit file length in *bits* at the end of the buffer. */
1132e0724c7Sespie *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
1142e0724c7Sespie *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
1152e0724c7Sespie (ctx->total[0] >> 29));
1162e0724c7Sespie
1172e0724c7Sespie /* Process last bytes. */
1182e0724c7Sespie md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
1192e0724c7Sespie
1202e0724c7Sespie return md5_read_ctx (ctx, resbuf);
1212e0724c7Sespie }
1222e0724c7Sespie
1232e0724c7Sespie /* Compute MD5 message digest for bytes read from STREAM. The
1242e0724c7Sespie resulting message digest number will be written into the 16 bytes
1252e0724c7Sespie beginning at RESBLOCK. */
1262e0724c7Sespie int
md5_stream(FILE * stream,void * resblock)127*20fce977Smiod md5_stream (FILE *stream, void *resblock)
1282e0724c7Sespie {
1292e0724c7Sespie /* Important: BLOCKSIZE must be a multiple of 64. */
1302e0724c7Sespie #define BLOCKSIZE 4096
1312e0724c7Sespie struct md5_ctx ctx;
1322e0724c7Sespie char buffer[BLOCKSIZE + 72];
1332e0724c7Sespie size_t sum;
1342e0724c7Sespie
1352e0724c7Sespie /* Initialize the computation context. */
1362e0724c7Sespie md5_init_ctx (&ctx);
1372e0724c7Sespie
1382e0724c7Sespie /* Iterate over full file contents. */
1392e0724c7Sespie while (1)
1402e0724c7Sespie {
1412e0724c7Sespie /* We read the file in blocks of BLOCKSIZE bytes. One call of the
1422e0724c7Sespie computation function processes the whole buffer so that with the
1432e0724c7Sespie next round of the loop another block can be read. */
1442e0724c7Sespie size_t n;
1452e0724c7Sespie sum = 0;
1462e0724c7Sespie
1472e0724c7Sespie /* Read block. Take care for partial reads. */
1482e0724c7Sespie do
1492e0724c7Sespie {
1502e0724c7Sespie n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
1512e0724c7Sespie
1522e0724c7Sespie sum += n;
1532e0724c7Sespie }
1542e0724c7Sespie while (sum < BLOCKSIZE && n != 0);
1552e0724c7Sespie if (n == 0 && ferror (stream))
1562e0724c7Sespie return 1;
1572e0724c7Sespie
1582e0724c7Sespie /* If end of file is reached, end the loop. */
1592e0724c7Sespie if (n == 0)
1602e0724c7Sespie break;
1612e0724c7Sespie
1622e0724c7Sespie /* Process buffer with BLOCKSIZE bytes. Note that
1632e0724c7Sespie BLOCKSIZE % 64 == 0
1642e0724c7Sespie */
1652e0724c7Sespie md5_process_block (buffer, BLOCKSIZE, &ctx);
1662e0724c7Sespie }
1672e0724c7Sespie
1682e0724c7Sespie /* Add the last bytes if necessary. */
1692e0724c7Sespie if (sum > 0)
1702e0724c7Sespie md5_process_bytes (buffer, sum, &ctx);
1712e0724c7Sespie
1722e0724c7Sespie /* Construct result in desired memory. */
1732e0724c7Sespie md5_finish_ctx (&ctx, resblock);
1742e0724c7Sespie return 0;
1752e0724c7Sespie }
1762e0724c7Sespie
1772e0724c7Sespie /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
1782e0724c7Sespie result is always in little endian byte order, so that a byte-wise
1792e0724c7Sespie output yields to the wanted ASCII representation of the message
1802e0724c7Sespie digest. */
1812e0724c7Sespie void *
md5_buffer(const char * buffer,size_t len,void * resblock)182*20fce977Smiod md5_buffer (const char *buffer, size_t len, void *resblock)
1832e0724c7Sespie {
1842e0724c7Sespie struct md5_ctx ctx;
1852e0724c7Sespie
1862e0724c7Sespie /* Initialize the computation context. */
1872e0724c7Sespie md5_init_ctx (&ctx);
1882e0724c7Sespie
1892e0724c7Sespie /* Process whole buffer but last len % 64 bytes. */
1902e0724c7Sespie md5_process_bytes (buffer, len, &ctx);
1912e0724c7Sespie
1922e0724c7Sespie /* Put result in desired memory area. */
1932e0724c7Sespie return md5_finish_ctx (&ctx, resblock);
1942e0724c7Sespie }
1952e0724c7Sespie
1962e0724c7Sespie
1972e0724c7Sespie void
md5_process_bytes(const void * buffer,size_t len,struct md5_ctx * ctx)198*20fce977Smiod md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
1992e0724c7Sespie {
2002e0724c7Sespie /* When we already have some bits in our internal buffer concatenate
2012e0724c7Sespie both inputs first. */
2022e0724c7Sespie if (ctx->buflen != 0)
2032e0724c7Sespie {
2042e0724c7Sespie size_t left_over = ctx->buflen;
2052e0724c7Sespie size_t add = 128 - left_over > len ? len : 128 - left_over;
2062e0724c7Sespie
2072e0724c7Sespie memcpy (&ctx->buffer[left_over], buffer, add);
2082e0724c7Sespie ctx->buflen += add;
2092e0724c7Sespie
2102e0724c7Sespie if (left_over + add > 64)
2112e0724c7Sespie {
2122e0724c7Sespie md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx);
2132e0724c7Sespie /* The regions in the following copy operation cannot overlap. */
2142e0724c7Sespie memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
2152e0724c7Sespie (left_over + add) & 63);
2162e0724c7Sespie ctx->buflen = (left_over + add) & 63;
2172e0724c7Sespie }
2182e0724c7Sespie
2199588ddcfSespie buffer = (const void *) ((const char *) buffer + add);
2202e0724c7Sespie len -= add;
2212e0724c7Sespie }
2222e0724c7Sespie
2232e0724c7Sespie /* Process available complete blocks. */
2242e0724c7Sespie if (len > 64)
2252e0724c7Sespie {
226*20fce977Smiod #if !_STRING_ARCH_unaligned
227*20fce977Smiod /* To check alignment gcc has an appropriate operator. Other
228*20fce977Smiod compilers don't. */
229*20fce977Smiod # if __GNUC__ >= 2
230*20fce977Smiod # define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0)
231*20fce977Smiod # else
232*20fce977Smiod # define UNALIGNED_P(p) (((md5_uintptr) p) % sizeof (md5_uint32) != 0)
233*20fce977Smiod # endif
234*20fce977Smiod if (UNALIGNED_P (buffer))
235*20fce977Smiod while (len > 64)
236*20fce977Smiod {
237*20fce977Smiod md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
238*20fce977Smiod buffer = (const char *) buffer + 64;
239*20fce977Smiod len -= 64;
240*20fce977Smiod }
241*20fce977Smiod else
242*20fce977Smiod #endif
2432e0724c7Sespie md5_process_block (buffer, len & ~63, ctx);
2449588ddcfSespie buffer = (const void *) ((const char *) buffer + (len & ~63));
2452e0724c7Sespie len &= 63;
2462e0724c7Sespie }
2472e0724c7Sespie
2482e0724c7Sespie /* Move remaining bytes in internal buffer. */
2492e0724c7Sespie if (len > 0)
2502e0724c7Sespie {
2512e0724c7Sespie memcpy (ctx->buffer, buffer, len);
2522e0724c7Sespie ctx->buflen = len;
2532e0724c7Sespie }
2542e0724c7Sespie }
2552e0724c7Sespie
2562e0724c7Sespie
2572e0724c7Sespie /* These are the four functions used in the four steps of the MD5 algorithm
2582e0724c7Sespie and defined in the RFC 1321. The first function is a little bit optimized
2592e0724c7Sespie (as found in Colin Plumbs public domain implementation). */
2602e0724c7Sespie /* #define FF(b, c, d) ((b & c) | (~b & d)) */
2612e0724c7Sespie #define FF(b, c, d) (d ^ (b & (c ^ d)))
2622e0724c7Sespie #define FG(b, c, d) FF (d, b, c)
2632e0724c7Sespie #define FH(b, c, d) (b ^ c ^ d)
2642e0724c7Sespie #define FI(b, c, d) (c ^ (b | ~d))
2652e0724c7Sespie
2662e0724c7Sespie /* Process LEN bytes of BUFFER, accumulating context into CTX.
2672e0724c7Sespie It is assumed that LEN % 64 == 0. */
2682e0724c7Sespie
2692e0724c7Sespie void
md5_process_block(const void * buffer,size_t len,struct md5_ctx * ctx)270*20fce977Smiod md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
2712e0724c7Sespie {
2722e0724c7Sespie md5_uint32 correct_words[16];
2739588ddcfSespie const md5_uint32 *words = (const md5_uint32 *) buffer;
2742e0724c7Sespie size_t nwords = len / sizeof (md5_uint32);
2752e0724c7Sespie const md5_uint32 *endp = words + nwords;
2762e0724c7Sespie md5_uint32 A = ctx->A;
2772e0724c7Sespie md5_uint32 B = ctx->B;
2782e0724c7Sespie md5_uint32 C = ctx->C;
2792e0724c7Sespie md5_uint32 D = ctx->D;
2802e0724c7Sespie
2812e0724c7Sespie /* First increment the byte count. RFC 1321 specifies the possible
2822e0724c7Sespie length of the file up to 2^64 bits. Here we only compute the
2832e0724c7Sespie number of bytes. Do a double word increment. */
2842e0724c7Sespie ctx->total[0] += len;
2852e0724c7Sespie if (ctx->total[0] < len)
2862e0724c7Sespie ++ctx->total[1];
2872e0724c7Sespie
2882e0724c7Sespie /* Process all bytes in the buffer with 64 bytes in each round of
2892e0724c7Sespie the loop. */
2902e0724c7Sespie while (words < endp)
2912e0724c7Sespie {
2922e0724c7Sespie md5_uint32 *cwp = correct_words;
2932e0724c7Sespie md5_uint32 A_save = A;
2942e0724c7Sespie md5_uint32 B_save = B;
2952e0724c7Sespie md5_uint32 C_save = C;
2962e0724c7Sespie md5_uint32 D_save = D;
2972e0724c7Sespie
2982e0724c7Sespie /* First round: using the given function, the context and a constant
2992e0724c7Sespie the next context is computed. Because the algorithms processing
3002e0724c7Sespie unit is a 32-bit word and it is determined to work on words in
3012e0724c7Sespie little endian byte order we perhaps have to change the byte order
3022e0724c7Sespie before the computation. To reduce the work for the next steps
3032e0724c7Sespie we store the swapped words in the array CORRECT_WORDS. */
3042e0724c7Sespie
3052e0724c7Sespie #define OP(a, b, c, d, s, T) \
3062e0724c7Sespie do \
3072e0724c7Sespie { \
3082e0724c7Sespie a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \
3092e0724c7Sespie ++words; \
3102e0724c7Sespie CYCLIC (a, s); \
3112e0724c7Sespie a += b; \
3122e0724c7Sespie } \
3132e0724c7Sespie while (0)
3142e0724c7Sespie
3152e0724c7Sespie /* It is unfortunate that C does not provide an operator for
3162e0724c7Sespie cyclic rotation. Hope the C compiler is smart enough. */
3172e0724c7Sespie #define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
3182e0724c7Sespie
3192e0724c7Sespie /* Before we start, one word to the strange constants.
3202e0724c7Sespie They are defined in RFC 1321 as
3212e0724c7Sespie
3222e0724c7Sespie T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
3232e0724c7Sespie */
3242e0724c7Sespie
3252e0724c7Sespie /* Round 1. */
3269588ddcfSespie OP (A, B, C, D, 7, (md5_uint32) 0xd76aa478);
3279588ddcfSespie OP (D, A, B, C, 12, (md5_uint32) 0xe8c7b756);
3289588ddcfSespie OP (C, D, A, B, 17, (md5_uint32) 0x242070db);
3299588ddcfSespie OP (B, C, D, A, 22, (md5_uint32) 0xc1bdceee);
3309588ddcfSespie OP (A, B, C, D, 7, (md5_uint32) 0xf57c0faf);
3319588ddcfSespie OP (D, A, B, C, 12, (md5_uint32) 0x4787c62a);
3329588ddcfSespie OP (C, D, A, B, 17, (md5_uint32) 0xa8304613);
3339588ddcfSespie OP (B, C, D, A, 22, (md5_uint32) 0xfd469501);
3349588ddcfSespie OP (A, B, C, D, 7, (md5_uint32) 0x698098d8);
3359588ddcfSespie OP (D, A, B, C, 12, (md5_uint32) 0x8b44f7af);
3369588ddcfSespie OP (C, D, A, B, 17, (md5_uint32) 0xffff5bb1);
3379588ddcfSespie OP (B, C, D, A, 22, (md5_uint32) 0x895cd7be);
3389588ddcfSespie OP (A, B, C, D, 7, (md5_uint32) 0x6b901122);
3399588ddcfSespie OP (D, A, B, C, 12, (md5_uint32) 0xfd987193);
3409588ddcfSespie OP (C, D, A, B, 17, (md5_uint32) 0xa679438e);
3419588ddcfSespie OP (B, C, D, A, 22, (md5_uint32) 0x49b40821);
3422e0724c7Sespie
3432e0724c7Sespie /* For the second to fourth round we have the possibly swapped words
3442e0724c7Sespie in CORRECT_WORDS. Redefine the macro to take an additional first
3452e0724c7Sespie argument specifying the function to use. */
3462e0724c7Sespie #undef OP
3479588ddcfSespie #define OP(a, b, c, d, k, s, T) \
3482e0724c7Sespie do \
3492e0724c7Sespie { \
3509588ddcfSespie a += FX (b, c, d) + correct_words[k] + T; \
3512e0724c7Sespie CYCLIC (a, s); \
3522e0724c7Sespie a += b; \
3532e0724c7Sespie } \
3542e0724c7Sespie while (0)
3552e0724c7Sespie
3569588ddcfSespie #define FX(b, c, d) FG (b, c, d)
3579588ddcfSespie
3582e0724c7Sespie /* Round 2. */
3599588ddcfSespie OP (A, B, C, D, 1, 5, (md5_uint32) 0xf61e2562);
3609588ddcfSespie OP (D, A, B, C, 6, 9, (md5_uint32) 0xc040b340);
3619588ddcfSespie OP (C, D, A, B, 11, 14, (md5_uint32) 0x265e5a51);
3629588ddcfSespie OP (B, C, D, A, 0, 20, (md5_uint32) 0xe9b6c7aa);
3639588ddcfSespie OP (A, B, C, D, 5, 5, (md5_uint32) 0xd62f105d);
3649588ddcfSespie OP (D, A, B, C, 10, 9, (md5_uint32) 0x02441453);
3659588ddcfSespie OP (C, D, A, B, 15, 14, (md5_uint32) 0xd8a1e681);
3669588ddcfSespie OP (B, C, D, A, 4, 20, (md5_uint32) 0xe7d3fbc8);
3679588ddcfSespie OP (A, B, C, D, 9, 5, (md5_uint32) 0x21e1cde6);
3689588ddcfSespie OP (D, A, B, C, 14, 9, (md5_uint32) 0xc33707d6);
3699588ddcfSespie OP (C, D, A, B, 3, 14, (md5_uint32) 0xf4d50d87);
3709588ddcfSespie OP (B, C, D, A, 8, 20, (md5_uint32) 0x455a14ed);
3719588ddcfSespie OP (A, B, C, D, 13, 5, (md5_uint32) 0xa9e3e905);
3729588ddcfSespie OP (D, A, B, C, 2, 9, (md5_uint32) 0xfcefa3f8);
3739588ddcfSespie OP (C, D, A, B, 7, 14, (md5_uint32) 0x676f02d9);
3749588ddcfSespie OP (B, C, D, A, 12, 20, (md5_uint32) 0x8d2a4c8a);
3759588ddcfSespie
3769588ddcfSespie #undef FX
3779588ddcfSespie #define FX(b, c, d) FH (b, c, d)
3782e0724c7Sespie
3792e0724c7Sespie /* Round 3. */
3809588ddcfSespie OP (A, B, C, D, 5, 4, (md5_uint32) 0xfffa3942);
3819588ddcfSespie OP (D, A, B, C, 8, 11, (md5_uint32) 0x8771f681);
3829588ddcfSespie OP (C, D, A, B, 11, 16, (md5_uint32) 0x6d9d6122);
3839588ddcfSespie OP (B, C, D, A, 14, 23, (md5_uint32) 0xfde5380c);
3849588ddcfSespie OP (A, B, C, D, 1, 4, (md5_uint32) 0xa4beea44);
3859588ddcfSespie OP (D, A, B, C, 4, 11, (md5_uint32) 0x4bdecfa9);
3869588ddcfSespie OP (C, D, A, B, 7, 16, (md5_uint32) 0xf6bb4b60);
3879588ddcfSespie OP (B, C, D, A, 10, 23, (md5_uint32) 0xbebfbc70);
3889588ddcfSespie OP (A, B, C, D, 13, 4, (md5_uint32) 0x289b7ec6);
3899588ddcfSespie OP (D, A, B, C, 0, 11, (md5_uint32) 0xeaa127fa);
3909588ddcfSespie OP (C, D, A, B, 3, 16, (md5_uint32) 0xd4ef3085);
3919588ddcfSespie OP (B, C, D, A, 6, 23, (md5_uint32) 0x04881d05);
3929588ddcfSespie OP (A, B, C, D, 9, 4, (md5_uint32) 0xd9d4d039);
3939588ddcfSespie OP (D, A, B, C, 12, 11, (md5_uint32) 0xe6db99e5);
3949588ddcfSespie OP (C, D, A, B, 15, 16, (md5_uint32) 0x1fa27cf8);
3959588ddcfSespie OP (B, C, D, A, 2, 23, (md5_uint32) 0xc4ac5665);
3969588ddcfSespie
3979588ddcfSespie #undef FX
3989588ddcfSespie #define FX(b, c, d) FI (b, c, d)
3992e0724c7Sespie
4002e0724c7Sespie /* Round 4. */
4019588ddcfSespie OP (A, B, C, D, 0, 6, (md5_uint32) 0xf4292244);
4029588ddcfSespie OP (D, A, B, C, 7, 10, (md5_uint32) 0x432aff97);
4039588ddcfSespie OP (C, D, A, B, 14, 15, (md5_uint32) 0xab9423a7);
4049588ddcfSespie OP (B, C, D, A, 5, 21, (md5_uint32) 0xfc93a039);
4059588ddcfSespie OP (A, B, C, D, 12, 6, (md5_uint32) 0x655b59c3);
4069588ddcfSespie OP (D, A, B, C, 3, 10, (md5_uint32) 0x8f0ccc92);
4079588ddcfSespie OP (C, D, A, B, 10, 15, (md5_uint32) 0xffeff47d);
4089588ddcfSespie OP (B, C, D, A, 1, 21, (md5_uint32) 0x85845dd1);
4099588ddcfSespie OP (A, B, C, D, 8, 6, (md5_uint32) 0x6fa87e4f);
4109588ddcfSespie OP (D, A, B, C, 15, 10, (md5_uint32) 0xfe2ce6e0);
4119588ddcfSespie OP (C, D, A, B, 6, 15, (md5_uint32) 0xa3014314);
4129588ddcfSespie OP (B, C, D, A, 13, 21, (md5_uint32) 0x4e0811a1);
4139588ddcfSespie OP (A, B, C, D, 4, 6, (md5_uint32) 0xf7537e82);
4149588ddcfSespie OP (D, A, B, C, 11, 10, (md5_uint32) 0xbd3af235);
4159588ddcfSespie OP (C, D, A, B, 2, 15, (md5_uint32) 0x2ad7d2bb);
4169588ddcfSespie OP (B, C, D, A, 9, 21, (md5_uint32) 0xeb86d391);
4172e0724c7Sespie
4182e0724c7Sespie /* Add the starting values of the context. */
4192e0724c7Sespie A += A_save;
4202e0724c7Sespie B += B_save;
4212e0724c7Sespie C += C_save;
4222e0724c7Sespie D += D_save;
4232e0724c7Sespie }
4242e0724c7Sespie
4252e0724c7Sespie /* Put checksum in context given as argument. */
4262e0724c7Sespie ctx->A = A;
4272e0724c7Sespie ctx->B = B;
4282e0724c7Sespie ctx->C = C;
4292e0724c7Sespie ctx->D = D;
4302e0724c7Sespie }
431