xref: /netbsd-src/external/gpl3/gdb/dist/libiberty/md5.c (revision 5173eb0a33e5d83890ba976253e703be4c92557c)
198b9484cSchristos /* md5.c - Functions to compute MD5 message digest of files or memory blocks
298b9484cSchristos    according to the definition of MD5 in RFC 1321 from April 1992.
3*5173eb0aSchristos    Copyright (C) 1995-2024 Free Software Foundation, Inc.
498b9484cSchristos 
598b9484cSchristos    NOTE: This source is derived from an old version taken from the GNU C
698b9484cSchristos    Library (glibc).
798b9484cSchristos 
898b9484cSchristos    This program is free software; you can redistribute it and/or modify it
998b9484cSchristos    under the terms of the GNU General Public License as published by the
1098b9484cSchristos    Free Software Foundation; either version 2, or (at your option) any
1198b9484cSchristos    later version.
1298b9484cSchristos 
1398b9484cSchristos    This program is distributed in the hope that it will be useful,
1498b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1598b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1698b9484cSchristos    GNU General Public License for more details.
1798b9484cSchristos 
1898b9484cSchristos    You should have received a copy of the GNU General Public License
1998b9484cSchristos    along with this program; if not, write to the Free Software Foundation,
2098b9484cSchristos    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2198b9484cSchristos 
2298b9484cSchristos /* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.  */
2398b9484cSchristos 
2498b9484cSchristos #ifdef HAVE_CONFIG_H
2598b9484cSchristos # include <config.h>
2698b9484cSchristos #endif
2798b9484cSchristos 
2898b9484cSchristos #include <sys/types.h>
2998b9484cSchristos 
3098b9484cSchristos #if STDC_HEADERS || defined _LIBC
3198b9484cSchristos # include <stdlib.h>
3298b9484cSchristos # include <string.h>
3398b9484cSchristos #else
3498b9484cSchristos # ifndef HAVE_MEMCPY
3598b9484cSchristos #  define memcpy(d, s, n) bcopy ((s), (d), (n))
3698b9484cSchristos # endif
3798b9484cSchristos #endif
3898b9484cSchristos 
3998b9484cSchristos #include "ansidecl.h"
4098b9484cSchristos #include "md5.h"
4198b9484cSchristos 
4298b9484cSchristos #ifdef _LIBC
4398b9484cSchristos # include <endian.h>
4498b9484cSchristos # if __BYTE_ORDER == __BIG_ENDIAN
4598b9484cSchristos #  define WORDS_BIGENDIAN 1
4698b9484cSchristos # endif
4798b9484cSchristos #endif
4898b9484cSchristos 
4998b9484cSchristos #ifdef WORDS_BIGENDIAN
5098b9484cSchristos # define SWAP(n)							\
5198b9484cSchristos     (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
5298b9484cSchristos #else
5398b9484cSchristos # define SWAP(n) (n)
5498b9484cSchristos #endif
5598b9484cSchristos 
5698b9484cSchristos 
5798b9484cSchristos /* This array contains the bytes used to pad the buffer to the next
5898b9484cSchristos    64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
5998b9484cSchristos static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
6098b9484cSchristos 
6198b9484cSchristos 
6298b9484cSchristos /* Initialize structure containing state of computation.
6398b9484cSchristos    (RFC 1321, 3.3: Step 3)  */
6498b9484cSchristos void
6598b9484cSchristos md5_init_ctx (struct md5_ctx *ctx)
6698b9484cSchristos {
6798b9484cSchristos   ctx->A = (md5_uint32) 0x67452301;
6898b9484cSchristos   ctx->B = (md5_uint32) 0xefcdab89;
6998b9484cSchristos   ctx->C = (md5_uint32) 0x98badcfe;
7098b9484cSchristos   ctx->D = (md5_uint32) 0x10325476;
7198b9484cSchristos 
7298b9484cSchristos   ctx->total[0] = ctx->total[1] = 0;
7398b9484cSchristos   ctx->buflen = 0;
7498b9484cSchristos }
7598b9484cSchristos 
7698b9484cSchristos /* Put result from CTX in first 16 bytes following RESBUF.  The result
7798b9484cSchristos    must be in little endian byte order.
7898b9484cSchristos 
79a2e2270fSchristos    IMPORTANT: RESBUF may not be aligned as strongly as MD5_UNIT32 so we
80a2e2270fSchristos    put things in a local (aligned) buffer first, then memcpy into RESBUF.  */
8198b9484cSchristos void *
8298b9484cSchristos md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
8398b9484cSchristos {
84a2e2270fSchristos   md5_uint32 buffer[4];
85a2e2270fSchristos 
86a2e2270fSchristos   buffer[0] = SWAP (ctx->A);
87a2e2270fSchristos   buffer[1] = SWAP (ctx->B);
88a2e2270fSchristos   buffer[2] = SWAP (ctx->C);
89a2e2270fSchristos   buffer[3] = SWAP (ctx->D);
90a2e2270fSchristos 
91a2e2270fSchristos   memcpy (resbuf, buffer, 16);
9298b9484cSchristos 
9398b9484cSchristos   return resbuf;
9498b9484cSchristos }
9598b9484cSchristos 
9698b9484cSchristos /* Process the remaining bytes in the internal buffer and the usual
9798b9484cSchristos    prolog according to the standard and write the result to RESBUF.
9898b9484cSchristos 
9998b9484cSchristos    IMPORTANT: On some systems it is required that RESBUF is correctly
10098b9484cSchristos    aligned for a 32 bits value.  */
10198b9484cSchristos void *
10298b9484cSchristos md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
10398b9484cSchristos {
10498b9484cSchristos   /* Take yet unprocessed bytes into account.  */
10598b9484cSchristos   md5_uint32 bytes = ctx->buflen;
106a2e2270fSchristos   md5_uint32 swap_bytes;
10798b9484cSchristos   size_t pad;
10898b9484cSchristos 
10998b9484cSchristos   /* Now count remaining bytes.  */
11098b9484cSchristos   ctx->total[0] += bytes;
11198b9484cSchristos   if (ctx->total[0] < bytes)
11298b9484cSchristos     ++ctx->total[1];
11398b9484cSchristos 
11498b9484cSchristos   pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
11598b9484cSchristos   memcpy (&ctx->buffer[bytes], fillbuf, pad);
11698b9484cSchristos 
117a2e2270fSchristos   /* Put the 64-bit file length in *bits* at the end of the buffer.
118a2e2270fSchristos      Use memcpy to avoid aliasing problems.  On most systems, this
119a2e2270fSchristos      will be optimized away to the same code.  */
120a2e2270fSchristos   swap_bytes = SWAP (ctx->total[0] << 3);
121a2e2270fSchristos   memcpy (&ctx->buffer[bytes + pad], &swap_bytes, sizeof (swap_bytes));
122a2e2270fSchristos   swap_bytes = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
123a2e2270fSchristos   memcpy (&ctx->buffer[bytes + pad + 4], &swap_bytes, sizeof (swap_bytes));
12498b9484cSchristos 
12598b9484cSchristos   /* Process last bytes.  */
12698b9484cSchristos   md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
12798b9484cSchristos 
12898b9484cSchristos   return md5_read_ctx (ctx, resbuf);
12998b9484cSchristos }
13098b9484cSchristos 
13198b9484cSchristos /* Compute MD5 message digest for bytes read from STREAM.  The
13298b9484cSchristos    resulting message digest number will be written into the 16 bytes
13398b9484cSchristos    beginning at RESBLOCK.  */
13498b9484cSchristos int
13598b9484cSchristos md5_stream (FILE *stream, void *resblock)
13698b9484cSchristos {
13798b9484cSchristos   /* Important: BLOCKSIZE must be a multiple of 64.  */
13898b9484cSchristos #define BLOCKSIZE 4096
13998b9484cSchristos   struct md5_ctx ctx;
14098b9484cSchristos   char buffer[BLOCKSIZE + 72];
14198b9484cSchristos   size_t sum;
14298b9484cSchristos 
14398b9484cSchristos   /* Initialize the computation context.  */
14498b9484cSchristos   md5_init_ctx (&ctx);
14598b9484cSchristos 
14698b9484cSchristos   /* Iterate over full file contents.  */
14798b9484cSchristos   while (1)
14898b9484cSchristos     {
14998b9484cSchristos       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
15098b9484cSchristos 	 computation function processes the whole buffer so that with the
15198b9484cSchristos 	 next round of the loop another block can be read.  */
15298b9484cSchristos       size_t n;
15398b9484cSchristos       sum = 0;
15498b9484cSchristos 
15598b9484cSchristos       /* Read block.  Take care for partial reads.  */
15698b9484cSchristos       do
15798b9484cSchristos 	{
15898b9484cSchristos 	  n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
15998b9484cSchristos 
16098b9484cSchristos 	  sum += n;
16198b9484cSchristos 	}
16298b9484cSchristos       while (sum < BLOCKSIZE && n != 0);
16398b9484cSchristos       if (n == 0 && ferror (stream))
16498b9484cSchristos         return 1;
16598b9484cSchristos 
16698b9484cSchristos       /* If end of file is reached, end the loop.  */
16798b9484cSchristos       if (n == 0)
16898b9484cSchristos 	break;
16998b9484cSchristos 
17098b9484cSchristos       /* Process buffer with BLOCKSIZE bytes.  Note that
17198b9484cSchristos 			BLOCKSIZE % 64 == 0
17298b9484cSchristos        */
17398b9484cSchristos       md5_process_block (buffer, BLOCKSIZE, &ctx);
17498b9484cSchristos     }
17598b9484cSchristos 
17698b9484cSchristos   /* Add the last bytes if necessary.  */
17798b9484cSchristos   if (sum > 0)
17898b9484cSchristos     md5_process_bytes (buffer, sum, &ctx);
17998b9484cSchristos 
18098b9484cSchristos   /* Construct result in desired memory.  */
18198b9484cSchristos   md5_finish_ctx (&ctx, resblock);
18298b9484cSchristos   return 0;
18398b9484cSchristos }
18498b9484cSchristos 
18598b9484cSchristos /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
18698b9484cSchristos    result is always in little endian byte order, so that a byte-wise
18798b9484cSchristos    output yields to the wanted ASCII representation of the message
18898b9484cSchristos    digest.  */
18998b9484cSchristos void *
19098b9484cSchristos md5_buffer (const char *buffer, size_t len, void *resblock)
19198b9484cSchristos {
19298b9484cSchristos   struct md5_ctx ctx;
19398b9484cSchristos 
19498b9484cSchristos   /* Initialize the computation context.  */
19598b9484cSchristos   md5_init_ctx (&ctx);
19698b9484cSchristos 
19798b9484cSchristos   /* Process whole buffer but last len % 64 bytes.  */
19898b9484cSchristos   md5_process_bytes (buffer, len, &ctx);
19998b9484cSchristos 
20098b9484cSchristos   /* Put result in desired memory area.  */
20198b9484cSchristos   return md5_finish_ctx (&ctx, resblock);
20298b9484cSchristos }
20398b9484cSchristos 
20498b9484cSchristos 
20598b9484cSchristos void
20698b9484cSchristos md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
20798b9484cSchristos {
20898b9484cSchristos   /* When we already have some bits in our internal buffer concatenate
20998b9484cSchristos      both inputs first.  */
21098b9484cSchristos   if (ctx->buflen != 0)
21198b9484cSchristos     {
21298b9484cSchristos       size_t left_over = ctx->buflen;
21398b9484cSchristos       size_t add = 128 - left_over > len ? len : 128 - left_over;
21498b9484cSchristos 
21598b9484cSchristos       memcpy (&ctx->buffer[left_over], buffer, add);
21698b9484cSchristos       ctx->buflen += add;
21798b9484cSchristos 
21898b9484cSchristos       if (left_over + add > 64)
21998b9484cSchristos 	{
22098b9484cSchristos 	  md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx);
22198b9484cSchristos 	  /* The regions in the following copy operation cannot overlap.  */
22298b9484cSchristos 	  memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
22398b9484cSchristos 		  (left_over + add) & 63);
22498b9484cSchristos 	  ctx->buflen = (left_over + add) & 63;
22598b9484cSchristos 	}
22698b9484cSchristos 
22798b9484cSchristos       buffer = (const void *) ((const char *) buffer + add);
22898b9484cSchristos       len -= add;
22998b9484cSchristos     }
23098b9484cSchristos 
23198b9484cSchristos   /* Process available complete blocks.  */
23298b9484cSchristos   if (len > 64)
23398b9484cSchristos     {
2344559860eSchristos #if !_STRING_ARCH_unaligned || defined UBSAN_BOOTSTRAP
23598b9484cSchristos /* To check alignment gcc has an appropriate operator.  Other
23698b9484cSchristos    compilers don't.  */
23798b9484cSchristos # if __GNUC__ >= 2
23898b9484cSchristos #  define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0)
23998b9484cSchristos # else
24098b9484cSchristos #  define UNALIGNED_P(p) (((md5_uintptr) p) % sizeof (md5_uint32) != 0)
24198b9484cSchristos # endif
24298b9484cSchristos       if (UNALIGNED_P (buffer))
24398b9484cSchristos         while (len > 64)
24498b9484cSchristos           {
24598b9484cSchristos 	    memcpy (ctx->buffer, buffer, 64);
24698b9484cSchristos             md5_process_block (ctx->buffer, 64, ctx);
24798b9484cSchristos             buffer = (const char *) buffer + 64;
24898b9484cSchristos             len -= 64;
24998b9484cSchristos           }
25098b9484cSchristos       else
25198b9484cSchristos #endif
252a2e2270fSchristos 	{
25398b9484cSchristos 	  md5_process_block (buffer, len & ~63, ctx);
25498b9484cSchristos 	  buffer = (const void *) ((const char *) buffer + (len & ~63));
25598b9484cSchristos 	  len &= 63;
25698b9484cSchristos 	}
257a2e2270fSchristos     }
25898b9484cSchristos 
25998b9484cSchristos   /* Move remaining bytes in internal buffer.  */
26098b9484cSchristos   if (len > 0)
26198b9484cSchristos     {
26298b9484cSchristos       memcpy (ctx->buffer, buffer, len);
26398b9484cSchristos       ctx->buflen = len;
26498b9484cSchristos     }
26598b9484cSchristos }
26698b9484cSchristos 
26798b9484cSchristos 
26898b9484cSchristos /* These are the four functions used in the four steps of the MD5 algorithm
26998b9484cSchristos    and defined in the RFC 1321.  The first function is a little bit optimized
27098b9484cSchristos    (as found in Colin Plumbs public domain implementation).  */
27198b9484cSchristos /* #define FF(b, c, d) ((b & c) | (~b & d)) */
27298b9484cSchristos #define FF(b, c, d) (d ^ (b & (c ^ d)))
27398b9484cSchristos #define FG(b, c, d) FF (d, b, c)
27498b9484cSchristos #define FH(b, c, d) (b ^ c ^ d)
27598b9484cSchristos #define FI(b, c, d) (c ^ (b | ~d))
27698b9484cSchristos 
27798b9484cSchristos /* Process LEN bytes of BUFFER, accumulating context into CTX.
27898b9484cSchristos    It is assumed that LEN % 64 == 0.  */
27998b9484cSchristos 
28098b9484cSchristos void
28198b9484cSchristos md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
28298b9484cSchristos {
28398b9484cSchristos   md5_uint32 correct_words[16];
28498b9484cSchristos   const md5_uint32 *words = (const md5_uint32 *) buffer;
28598b9484cSchristos   size_t nwords = len / sizeof (md5_uint32);
28698b9484cSchristos   const md5_uint32 *endp = words + nwords;
28798b9484cSchristos   md5_uint32 A = ctx->A;
28898b9484cSchristos   md5_uint32 B = ctx->B;
28998b9484cSchristos   md5_uint32 C = ctx->C;
29098b9484cSchristos   md5_uint32 D = ctx->D;
29198b9484cSchristos 
29298b9484cSchristos   /* First increment the byte count.  RFC 1321 specifies the possible
29398b9484cSchristos      length of the file up to 2^64 bits.  Here we only compute the
29498b9484cSchristos      number of bytes.  Do a double word increment.  */
29598b9484cSchristos   ctx->total[0] += len;
296a2e2270fSchristos   ctx->total[1] += ((len >> 31) >> 1) + (ctx->total[0] < len);
29798b9484cSchristos 
29898b9484cSchristos   /* Process all bytes in the buffer with 64 bytes in each round of
29998b9484cSchristos      the loop.  */
30098b9484cSchristos   while (words < endp)
30198b9484cSchristos     {
30298b9484cSchristos       md5_uint32 *cwp = correct_words;
30398b9484cSchristos       md5_uint32 A_save = A;
30498b9484cSchristos       md5_uint32 B_save = B;
30598b9484cSchristos       md5_uint32 C_save = C;
30698b9484cSchristos       md5_uint32 D_save = D;
30798b9484cSchristos 
30898b9484cSchristos       /* First round: using the given function, the context and a constant
30998b9484cSchristos 	 the next context is computed.  Because the algorithms processing
31098b9484cSchristos 	 unit is a 32-bit word and it is determined to work on words in
31198b9484cSchristos 	 little endian byte order we perhaps have to change the byte order
31298b9484cSchristos 	 before the computation.  To reduce the work for the next steps
31398b9484cSchristos 	 we store the swapped words in the array CORRECT_WORDS.  */
31498b9484cSchristos 
31598b9484cSchristos #define OP(a, b, c, d, s, T)						\
31698b9484cSchristos       do								\
31798b9484cSchristos         {								\
31898b9484cSchristos 	  a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T;		\
31998b9484cSchristos 	  ++words;							\
32098b9484cSchristos 	  CYCLIC (a, s);						\
32198b9484cSchristos 	  a += b;							\
32298b9484cSchristos         }								\
32398b9484cSchristos       while (0)
32498b9484cSchristos 
32598b9484cSchristos       /* It is unfortunate that C does not provide an operator for
32698b9484cSchristos 	 cyclic rotation.  Hope the C compiler is smart enough.  */
32798b9484cSchristos #define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
32898b9484cSchristos 
32998b9484cSchristos       /* Before we start, one word to the strange constants.
33098b9484cSchristos 	 They are defined in RFC 1321 as
33198b9484cSchristos 
33298b9484cSchristos 	 T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
33398b9484cSchristos        */
33498b9484cSchristos 
33598b9484cSchristos       /* Round 1.  */
33698b9484cSchristos       OP (A, B, C, D,  7, (md5_uint32) 0xd76aa478);
33798b9484cSchristos       OP (D, A, B, C, 12, (md5_uint32) 0xe8c7b756);
33898b9484cSchristos       OP (C, D, A, B, 17, (md5_uint32) 0x242070db);
33998b9484cSchristos       OP (B, C, D, A, 22, (md5_uint32) 0xc1bdceee);
34098b9484cSchristos       OP (A, B, C, D,  7, (md5_uint32) 0xf57c0faf);
34198b9484cSchristos       OP (D, A, B, C, 12, (md5_uint32) 0x4787c62a);
34298b9484cSchristos       OP (C, D, A, B, 17, (md5_uint32) 0xa8304613);
34398b9484cSchristos       OP (B, C, D, A, 22, (md5_uint32) 0xfd469501);
34498b9484cSchristos       OP (A, B, C, D,  7, (md5_uint32) 0x698098d8);
34598b9484cSchristos       OP (D, A, B, C, 12, (md5_uint32) 0x8b44f7af);
34698b9484cSchristos       OP (C, D, A, B, 17, (md5_uint32) 0xffff5bb1);
34798b9484cSchristos       OP (B, C, D, A, 22, (md5_uint32) 0x895cd7be);
34898b9484cSchristos       OP (A, B, C, D,  7, (md5_uint32) 0x6b901122);
34998b9484cSchristos       OP (D, A, B, C, 12, (md5_uint32) 0xfd987193);
35098b9484cSchristos       OP (C, D, A, B, 17, (md5_uint32) 0xa679438e);
35198b9484cSchristos       OP (B, C, D, A, 22, (md5_uint32) 0x49b40821);
35298b9484cSchristos 
35398b9484cSchristos       /* For the second to fourth round we have the possibly swapped words
35498b9484cSchristos 	 in CORRECT_WORDS.  Redefine the macro to take an additional first
35598b9484cSchristos 	 argument specifying the function to use.  */
35698b9484cSchristos #undef OP
35798b9484cSchristos #define OP(a, b, c, d, k, s, T)						\
35898b9484cSchristos       do 								\
35998b9484cSchristos 	{								\
36098b9484cSchristos 	  a += FX (b, c, d) + correct_words[k] + T;			\
36198b9484cSchristos 	  CYCLIC (a, s);						\
36298b9484cSchristos 	  a += b;							\
36398b9484cSchristos 	}								\
36498b9484cSchristos       while (0)
36598b9484cSchristos 
36698b9484cSchristos #define FX(b, c, d) FG (b, c, d)
36798b9484cSchristos 
36898b9484cSchristos       /* Round 2.  */
36998b9484cSchristos       OP (A, B, C, D,  1,  5, (md5_uint32) 0xf61e2562);
37098b9484cSchristos       OP (D, A, B, C,  6,  9, (md5_uint32) 0xc040b340);
37198b9484cSchristos       OP (C, D, A, B, 11, 14, (md5_uint32) 0x265e5a51);
37298b9484cSchristos       OP (B, C, D, A,  0, 20, (md5_uint32) 0xe9b6c7aa);
37398b9484cSchristos       OP (A, B, C, D,  5,  5, (md5_uint32) 0xd62f105d);
37498b9484cSchristos       OP (D, A, B, C, 10,  9, (md5_uint32) 0x02441453);
37598b9484cSchristos       OP (C, D, A, B, 15, 14, (md5_uint32) 0xd8a1e681);
37698b9484cSchristos       OP (B, C, D, A,  4, 20, (md5_uint32) 0xe7d3fbc8);
37798b9484cSchristos       OP (A, B, C, D,  9,  5, (md5_uint32) 0x21e1cde6);
37898b9484cSchristos       OP (D, A, B, C, 14,  9, (md5_uint32) 0xc33707d6);
37998b9484cSchristos       OP (C, D, A, B,  3, 14, (md5_uint32) 0xf4d50d87);
38098b9484cSchristos       OP (B, C, D, A,  8, 20, (md5_uint32) 0x455a14ed);
38198b9484cSchristos       OP (A, B, C, D, 13,  5, (md5_uint32) 0xa9e3e905);
38298b9484cSchristos       OP (D, A, B, C,  2,  9, (md5_uint32) 0xfcefa3f8);
38398b9484cSchristos       OP (C, D, A, B,  7, 14, (md5_uint32) 0x676f02d9);
38498b9484cSchristos       OP (B, C, D, A, 12, 20, (md5_uint32) 0x8d2a4c8a);
38598b9484cSchristos 
38698b9484cSchristos #undef FX
38798b9484cSchristos #define FX(b, c, d) FH (b, c, d)
38898b9484cSchristos 
38998b9484cSchristos       /* Round 3.  */
39098b9484cSchristos       OP (A, B, C, D,  5,  4, (md5_uint32) 0xfffa3942);
39198b9484cSchristos       OP (D, A, B, C,  8, 11, (md5_uint32) 0x8771f681);
39298b9484cSchristos       OP (C, D, A, B, 11, 16, (md5_uint32) 0x6d9d6122);
39398b9484cSchristos       OP (B, C, D, A, 14, 23, (md5_uint32) 0xfde5380c);
39498b9484cSchristos       OP (A, B, C, D,  1,  4, (md5_uint32) 0xa4beea44);
39598b9484cSchristos       OP (D, A, B, C,  4, 11, (md5_uint32) 0x4bdecfa9);
39698b9484cSchristos       OP (C, D, A, B,  7, 16, (md5_uint32) 0xf6bb4b60);
39798b9484cSchristos       OP (B, C, D, A, 10, 23, (md5_uint32) 0xbebfbc70);
39898b9484cSchristos       OP (A, B, C, D, 13,  4, (md5_uint32) 0x289b7ec6);
39998b9484cSchristos       OP (D, A, B, C,  0, 11, (md5_uint32) 0xeaa127fa);
40098b9484cSchristos       OP (C, D, A, B,  3, 16, (md5_uint32) 0xd4ef3085);
40198b9484cSchristos       OP (B, C, D, A,  6, 23, (md5_uint32) 0x04881d05);
40298b9484cSchristos       OP (A, B, C, D,  9,  4, (md5_uint32) 0xd9d4d039);
40398b9484cSchristos       OP (D, A, B, C, 12, 11, (md5_uint32) 0xe6db99e5);
40498b9484cSchristos       OP (C, D, A, B, 15, 16, (md5_uint32) 0x1fa27cf8);
40598b9484cSchristos       OP (B, C, D, A,  2, 23, (md5_uint32) 0xc4ac5665);
40698b9484cSchristos 
40798b9484cSchristos #undef FX
40898b9484cSchristos #define FX(b, c, d) FI (b, c, d)
40998b9484cSchristos 
41098b9484cSchristos       /* Round 4.  */
41198b9484cSchristos       OP (A, B, C, D,  0,  6, (md5_uint32) 0xf4292244);
41298b9484cSchristos       OP (D, A, B, C,  7, 10, (md5_uint32) 0x432aff97);
41398b9484cSchristos       OP (C, D, A, B, 14, 15, (md5_uint32) 0xab9423a7);
41498b9484cSchristos       OP (B, C, D, A,  5, 21, (md5_uint32) 0xfc93a039);
41598b9484cSchristos       OP (A, B, C, D, 12,  6, (md5_uint32) 0x655b59c3);
41698b9484cSchristos       OP (D, A, B, C,  3, 10, (md5_uint32) 0x8f0ccc92);
41798b9484cSchristos       OP (C, D, A, B, 10, 15, (md5_uint32) 0xffeff47d);
41898b9484cSchristos       OP (B, C, D, A,  1, 21, (md5_uint32) 0x85845dd1);
41998b9484cSchristos       OP (A, B, C, D,  8,  6, (md5_uint32) 0x6fa87e4f);
42098b9484cSchristos       OP (D, A, B, C, 15, 10, (md5_uint32) 0xfe2ce6e0);
42198b9484cSchristos       OP (C, D, A, B,  6, 15, (md5_uint32) 0xa3014314);
42298b9484cSchristos       OP (B, C, D, A, 13, 21, (md5_uint32) 0x4e0811a1);
42398b9484cSchristos       OP (A, B, C, D,  4,  6, (md5_uint32) 0xf7537e82);
42498b9484cSchristos       OP (D, A, B, C, 11, 10, (md5_uint32) 0xbd3af235);
42598b9484cSchristos       OP (C, D, A, B,  2, 15, (md5_uint32) 0x2ad7d2bb);
42698b9484cSchristos       OP (B, C, D, A,  9, 21, (md5_uint32) 0xeb86d391);
42798b9484cSchristos 
42898b9484cSchristos       /* Add the starting values of the context.  */
42998b9484cSchristos       A += A_save;
43098b9484cSchristos       B += B_save;
43198b9484cSchristos       C += C_save;
43298b9484cSchristos       D += D_save;
43398b9484cSchristos     }
43498b9484cSchristos 
43598b9484cSchristos   /* Put checksum in context given as argument.  */
43698b9484cSchristos   ctx->A = A;
43798b9484cSchristos   ctx->B = B;
43898b9484cSchristos   ctx->C = C;
43998b9484cSchristos   ctx->D = D;
44098b9484cSchristos }
441