xref: /dflybsd-src/contrib/gcc-4.7/libiberty/sha1.c (revision 81fc95a5293ee307c688a350a3feb4734aaddbb4)
1e4b17023SJohn Marino /* sha1.c - Functions to compute SHA1 message digest of files or
2e4b17023SJohn Marino    memory blocks according to the NIST specification FIPS-180-1.
3e4b17023SJohn Marino 
4e4b17023SJohn Marino    Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2008 Free Software
5e4b17023SJohn Marino    Foundation, Inc.
6e4b17023SJohn Marino 
7e4b17023SJohn Marino    This program is free software; you can redistribute it and/or modify it
8e4b17023SJohn Marino    under the terms of the GNU General Public License as published by the
9e4b17023SJohn Marino    Free Software Foundation; either version 2, or (at your option) any
10e4b17023SJohn Marino    later version.
11e4b17023SJohn Marino 
12e4b17023SJohn Marino    This program is distributed in the hope that it will be useful,
13e4b17023SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
14e4b17023SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e4b17023SJohn Marino    GNU General Public License for more details.
16e4b17023SJohn Marino 
17e4b17023SJohn Marino    You should have received a copy of the GNU General Public License
18e4b17023SJohn Marino    along with this program; if not, write to the Free Software Foundation,
19e4b17023SJohn Marino    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
20e4b17023SJohn Marino 
21e4b17023SJohn Marino /* Written by Scott G. Miller
22e4b17023SJohn Marino    Credits:
23e4b17023SJohn Marino       Robert Klep <robert@ilse.nl>  -- Expansion function fix
24e4b17023SJohn Marino */
25e4b17023SJohn Marino 
26e4b17023SJohn Marino #include <config.h>
27e4b17023SJohn Marino 
28e4b17023SJohn Marino #include "sha1.h"
29e4b17023SJohn Marino 
30e4b17023SJohn Marino #include <stddef.h>
31e4b17023SJohn Marino #include <string.h>
32e4b17023SJohn Marino 
33e4b17023SJohn Marino #if USE_UNLOCKED_IO
34e4b17023SJohn Marino # include "unlocked-io.h"
35e4b17023SJohn Marino #endif
36e4b17023SJohn Marino 
37e4b17023SJohn Marino #ifdef WORDS_BIGENDIAN
38e4b17023SJohn Marino # define SWAP(n) (n)
39e4b17023SJohn Marino #else
40e4b17023SJohn Marino # define SWAP(n) \
41e4b17023SJohn Marino     (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
42e4b17023SJohn Marino #endif
43e4b17023SJohn Marino 
44e4b17023SJohn Marino #define BLOCKSIZE 4096
45e4b17023SJohn Marino #if BLOCKSIZE % 64 != 0
46e4b17023SJohn Marino # error "invalid BLOCKSIZE"
47e4b17023SJohn Marino #endif
48e4b17023SJohn Marino 
49e4b17023SJohn Marino /* This array contains the bytes used to pad the buffer to the next
50e4b17023SJohn Marino    64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
51e4b17023SJohn Marino static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
52e4b17023SJohn Marino 
53e4b17023SJohn Marino 
54e4b17023SJohn Marino /* Take a pointer to a 160 bit block of data (five 32 bit ints) and
55e4b17023SJohn Marino    initialize it to the start constants of the SHA1 algorithm.  This
56e4b17023SJohn Marino    must be called before using hash in the call to sha1_hash.  */
57e4b17023SJohn Marino void
sha1_init_ctx(struct sha1_ctx * ctx)58e4b17023SJohn Marino sha1_init_ctx (struct sha1_ctx *ctx)
59e4b17023SJohn Marino {
60e4b17023SJohn Marino   ctx->A = 0x67452301;
61e4b17023SJohn Marino   ctx->B = 0xefcdab89;
62e4b17023SJohn Marino   ctx->C = 0x98badcfe;
63e4b17023SJohn Marino   ctx->D = 0x10325476;
64e4b17023SJohn Marino   ctx->E = 0xc3d2e1f0;
65e4b17023SJohn Marino 
66e4b17023SJohn Marino   ctx->total[0] = ctx->total[1] = 0;
67e4b17023SJohn Marino   ctx->buflen = 0;
68e4b17023SJohn Marino }
69e4b17023SJohn Marino 
70e4b17023SJohn Marino /* Put result from CTX in first 20 bytes following RESBUF.  The result
71e4b17023SJohn Marino    must be in little endian byte order.
72e4b17023SJohn Marino 
73e4b17023SJohn Marino    IMPORTANT: On some systems it is required that RESBUF is correctly
74e4b17023SJohn Marino    aligned for a 32-bit value.  */
75e4b17023SJohn Marino void *
sha1_read_ctx(const struct sha1_ctx * ctx,void * resbuf)76e4b17023SJohn Marino sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
77e4b17023SJohn Marino {
78e4b17023SJohn Marino   ((sha1_uint32 *) resbuf)[0] = SWAP (ctx->A);
79e4b17023SJohn Marino   ((sha1_uint32 *) resbuf)[1] = SWAP (ctx->B);
80e4b17023SJohn Marino   ((sha1_uint32 *) resbuf)[2] = SWAP (ctx->C);
81e4b17023SJohn Marino   ((sha1_uint32 *) resbuf)[3] = SWAP (ctx->D);
82e4b17023SJohn Marino   ((sha1_uint32 *) resbuf)[4] = SWAP (ctx->E);
83e4b17023SJohn Marino 
84e4b17023SJohn Marino   return resbuf;
85e4b17023SJohn Marino }
86e4b17023SJohn Marino 
87e4b17023SJohn Marino /* Process the remaining bytes in the internal buffer and the usual
88e4b17023SJohn Marino    prolog according to the standard and write the result to RESBUF.
89e4b17023SJohn Marino 
90e4b17023SJohn Marino    IMPORTANT: On some systems it is required that RESBUF is correctly
91e4b17023SJohn Marino    aligned for a 32-bit value.  */
92e4b17023SJohn Marino void *
sha1_finish_ctx(struct sha1_ctx * ctx,void * resbuf)93e4b17023SJohn Marino sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
94e4b17023SJohn Marino {
95e4b17023SJohn Marino   /* Take yet unprocessed bytes into account.  */
96e4b17023SJohn Marino   sha1_uint32 bytes = ctx->buflen;
97e4b17023SJohn Marino   size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
98e4b17023SJohn Marino 
99e4b17023SJohn Marino   /* Now count remaining bytes.  */
100e4b17023SJohn Marino   ctx->total[0] += bytes;
101e4b17023SJohn Marino   if (ctx->total[0] < bytes)
102e4b17023SJohn Marino     ++ctx->total[1];
103e4b17023SJohn Marino 
104e4b17023SJohn Marino   /* Put the 64-bit file length in *bits* at the end of the buffer.  */
105e4b17023SJohn Marino   ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
106e4b17023SJohn Marino   ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);
107e4b17023SJohn Marino 
108e4b17023SJohn Marino   memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
109e4b17023SJohn Marino 
110e4b17023SJohn Marino   /* Process last bytes.  */
111e4b17023SJohn Marino   sha1_process_block (ctx->buffer, size * 4, ctx);
112e4b17023SJohn Marino 
113e4b17023SJohn Marino   return sha1_read_ctx (ctx, resbuf);
114e4b17023SJohn Marino }
115e4b17023SJohn Marino 
116e4b17023SJohn Marino /* Compute SHA1 message digest for bytes read from STREAM.  The
117e4b17023SJohn Marino    resulting message digest number will be written into the 16 bytes
118e4b17023SJohn Marino    beginning at RESBLOCK.  */
119e4b17023SJohn Marino int
sha1_stream(FILE * stream,void * resblock)120e4b17023SJohn Marino sha1_stream (FILE *stream, void *resblock)
121e4b17023SJohn Marino {
122e4b17023SJohn Marino   struct sha1_ctx ctx;
123e4b17023SJohn Marino   char buffer[BLOCKSIZE + 72];
124e4b17023SJohn Marino   size_t sum;
125e4b17023SJohn Marino 
126e4b17023SJohn Marino   /* Initialize the computation context.  */
127e4b17023SJohn Marino   sha1_init_ctx (&ctx);
128e4b17023SJohn Marino 
129e4b17023SJohn Marino   /* Iterate over full file contents.  */
130e4b17023SJohn Marino   while (1)
131e4b17023SJohn Marino     {
132e4b17023SJohn Marino       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
133e4b17023SJohn Marino 	 computation function processes the whole buffer so that with the
134e4b17023SJohn Marino 	 next round of the loop another block can be read.  */
135e4b17023SJohn Marino       size_t n;
136e4b17023SJohn Marino       sum = 0;
137e4b17023SJohn Marino 
138e4b17023SJohn Marino       /* Read block.  Take care for partial reads.  */
139e4b17023SJohn Marino       while (1)
140e4b17023SJohn Marino 	{
141e4b17023SJohn Marino 	  n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
142e4b17023SJohn Marino 
143e4b17023SJohn Marino 	  sum += n;
144e4b17023SJohn Marino 
145e4b17023SJohn Marino 	  if (sum == BLOCKSIZE)
146e4b17023SJohn Marino 	    break;
147e4b17023SJohn Marino 
148e4b17023SJohn Marino 	  if (n == 0)
149e4b17023SJohn Marino 	    {
150e4b17023SJohn Marino 	      /* Check for the error flag IFF N == 0, so that we don't
151e4b17023SJohn Marino 		 exit the loop after a partial read due to e.g., EAGAIN
152e4b17023SJohn Marino 		 or EWOULDBLOCK.  */
153e4b17023SJohn Marino 	      if (ferror (stream))
154e4b17023SJohn Marino 		return 1;
155e4b17023SJohn Marino 	      goto process_partial_block;
156e4b17023SJohn Marino 	    }
157e4b17023SJohn Marino 
158e4b17023SJohn Marino 	  /* We've read at least one byte, so ignore errors.  But always
159e4b17023SJohn Marino 	     check for EOF, since feof may be true even though N > 0.
160e4b17023SJohn Marino 	     Otherwise, we could end up calling fread after EOF.  */
161e4b17023SJohn Marino 	  if (feof (stream))
162e4b17023SJohn Marino 	    goto process_partial_block;
163e4b17023SJohn Marino 	}
164e4b17023SJohn Marino 
165e4b17023SJohn Marino       /* Process buffer with BLOCKSIZE bytes.  Note that
166e4b17023SJohn Marino 			BLOCKSIZE % 64 == 0
167e4b17023SJohn Marino        */
168e4b17023SJohn Marino       sha1_process_block (buffer, BLOCKSIZE, &ctx);
169e4b17023SJohn Marino     }
170e4b17023SJohn Marino 
171e4b17023SJohn Marino  process_partial_block:;
172e4b17023SJohn Marino 
173e4b17023SJohn Marino   /* Process any remaining bytes.  */
174e4b17023SJohn Marino   if (sum > 0)
175e4b17023SJohn Marino     sha1_process_bytes (buffer, sum, &ctx);
176e4b17023SJohn Marino 
177e4b17023SJohn Marino   /* Construct result in desired memory.  */
178e4b17023SJohn Marino   sha1_finish_ctx (&ctx, resblock);
179e4b17023SJohn Marino   return 0;
180e4b17023SJohn Marino }
181e4b17023SJohn Marino 
182e4b17023SJohn Marino /* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
183e4b17023SJohn Marino    result is always in little endian byte order, so that a byte-wise
184e4b17023SJohn Marino    output yields to the wanted ASCII representation of the message
185e4b17023SJohn Marino    digest.  */
186e4b17023SJohn Marino void *
sha1_buffer(const char * buffer,size_t len,void * resblock)187e4b17023SJohn Marino sha1_buffer (const char *buffer, size_t len, void *resblock)
188e4b17023SJohn Marino {
189e4b17023SJohn Marino   struct sha1_ctx ctx;
190e4b17023SJohn Marino 
191e4b17023SJohn Marino   /* Initialize the computation context.  */
192e4b17023SJohn Marino   sha1_init_ctx (&ctx);
193e4b17023SJohn Marino 
194e4b17023SJohn Marino   /* Process whole buffer but last len % 64 bytes.  */
195e4b17023SJohn Marino   sha1_process_bytes (buffer, len, &ctx);
196e4b17023SJohn Marino 
197e4b17023SJohn Marino   /* Put result in desired memory area.  */
198e4b17023SJohn Marino   return sha1_finish_ctx (&ctx, resblock);
199e4b17023SJohn Marino }
200e4b17023SJohn Marino 
201e4b17023SJohn Marino void
sha1_process_bytes(const void * buffer,size_t len,struct sha1_ctx * ctx)202e4b17023SJohn Marino sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
203e4b17023SJohn Marino {
204e4b17023SJohn Marino   /* When we already have some bits in our internal buffer concatenate
205e4b17023SJohn Marino      both inputs first.  */
206e4b17023SJohn Marino   if (ctx->buflen != 0)
207e4b17023SJohn Marino     {
208e4b17023SJohn Marino       size_t left_over = ctx->buflen;
209e4b17023SJohn Marino       size_t add = 128 - left_over > len ? len : 128 - left_over;
210e4b17023SJohn Marino 
211e4b17023SJohn Marino       memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
212e4b17023SJohn Marino       ctx->buflen += add;
213e4b17023SJohn Marino 
214e4b17023SJohn Marino       if (ctx->buflen > 64)
215e4b17023SJohn Marino 	{
216e4b17023SJohn Marino 	  sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
217e4b17023SJohn Marino 
218e4b17023SJohn Marino 	  ctx->buflen &= 63;
219e4b17023SJohn Marino 	  /* The regions in the following copy operation cannot overlap.  */
220e4b17023SJohn Marino 	  memcpy (ctx->buffer,
221e4b17023SJohn Marino 		  &((char *) ctx->buffer)[(left_over + add) & ~63],
222e4b17023SJohn Marino 		  ctx->buflen);
223e4b17023SJohn Marino 	}
224e4b17023SJohn Marino 
225e4b17023SJohn Marino       buffer = (const char *) buffer + add;
226e4b17023SJohn Marino       len -= add;
227e4b17023SJohn Marino     }
228e4b17023SJohn Marino 
229e4b17023SJohn Marino   /* Process available complete blocks.  */
230e4b17023SJohn Marino   if (len >= 64)
231e4b17023SJohn Marino     {
232e4b17023SJohn Marino #if !_STRING_ARCH_unaligned
233e4b17023SJohn Marino # define alignof(type) offsetof (struct { char c; type x; }, x)
234e4b17023SJohn Marino # define UNALIGNED_P(p) (((size_t) p) % alignof (sha1_uint32) != 0)
235e4b17023SJohn Marino       if (UNALIGNED_P (buffer))
236e4b17023SJohn Marino 	while (len > 64)
237e4b17023SJohn Marino 	  {
238e4b17023SJohn Marino 	    sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
239e4b17023SJohn Marino 	    buffer = (const char *) buffer + 64;
240e4b17023SJohn Marino 	    len -= 64;
241e4b17023SJohn Marino 	  }
242e4b17023SJohn Marino       else
243e4b17023SJohn Marino #endif
244e4b17023SJohn Marino 	{
245e4b17023SJohn Marino 	  sha1_process_block (buffer, len & ~63, ctx);
246e4b17023SJohn Marino 	  buffer = (const char *) buffer + (len & ~63);
247e4b17023SJohn Marino 	  len &= 63;
248e4b17023SJohn Marino 	}
249e4b17023SJohn Marino     }
250e4b17023SJohn Marino 
251e4b17023SJohn Marino   /* Move remaining bytes in internal buffer.  */
252e4b17023SJohn Marino   if (len > 0)
253e4b17023SJohn Marino     {
254e4b17023SJohn Marino       size_t left_over = ctx->buflen;
255e4b17023SJohn Marino 
256e4b17023SJohn Marino       memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
257e4b17023SJohn Marino       left_over += len;
258e4b17023SJohn Marino       if (left_over >= 64)
259e4b17023SJohn Marino 	{
260e4b17023SJohn Marino 	  sha1_process_block (ctx->buffer, 64, ctx);
261e4b17023SJohn Marino 	  left_over -= 64;
262e4b17023SJohn Marino 	  memcpy (ctx->buffer, &ctx->buffer[16], left_over);
263e4b17023SJohn Marino 	}
264e4b17023SJohn Marino       ctx->buflen = left_over;
265e4b17023SJohn Marino     }
266e4b17023SJohn Marino }
267e4b17023SJohn Marino 
268e4b17023SJohn Marino /* --- Code below is the primary difference between md5.c and sha1.c --- */
269e4b17023SJohn Marino 
270e4b17023SJohn Marino /* SHA1 round constants */
271e4b17023SJohn Marino #define K1 0x5a827999
272e4b17023SJohn Marino #define K2 0x6ed9eba1
273e4b17023SJohn Marino #define K3 0x8f1bbcdc
274e4b17023SJohn Marino #define K4 0xca62c1d6
275e4b17023SJohn Marino 
276e4b17023SJohn Marino /* Round functions.  Note that F2 is the same as F4.  */
277e4b17023SJohn Marino #define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
278e4b17023SJohn Marino #define F2(B,C,D) (B ^ C ^ D)
279e4b17023SJohn Marino #define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
280e4b17023SJohn Marino #define F4(B,C,D) (B ^ C ^ D)
281e4b17023SJohn Marino 
282e4b17023SJohn Marino /* Process LEN bytes of BUFFER, accumulating context into CTX.
283e4b17023SJohn Marino    It is assumed that LEN % 64 == 0.
284e4b17023SJohn Marino    Most of this code comes from GnuPG's cipher/sha1.c.  */
285e4b17023SJohn Marino 
286e4b17023SJohn Marino void
sha1_process_block(const void * buffer,size_t len,struct sha1_ctx * ctx)287e4b17023SJohn Marino sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
288e4b17023SJohn Marino {
289e4b17023SJohn Marino   const sha1_uint32 *words = (const sha1_uint32*) buffer;
290e4b17023SJohn Marino   size_t nwords = len / sizeof (sha1_uint32);
291e4b17023SJohn Marino   const sha1_uint32 *endp = words + nwords;
292e4b17023SJohn Marino   sha1_uint32 x[16];
293e4b17023SJohn Marino   sha1_uint32 a = ctx->A;
294e4b17023SJohn Marino   sha1_uint32 b = ctx->B;
295e4b17023SJohn Marino   sha1_uint32 c = ctx->C;
296e4b17023SJohn Marino   sha1_uint32 d = ctx->D;
297e4b17023SJohn Marino   sha1_uint32 e = ctx->E;
298e4b17023SJohn Marino 
299e4b17023SJohn Marino   /* First increment the byte count.  RFC 1321 specifies the possible
300e4b17023SJohn Marino      length of the file up to 2^64 bits.  Here we only compute the
301e4b17023SJohn Marino      number of bytes.  Do a double word increment.  */
302e4b17023SJohn Marino   ctx->total[0] += len;
303*5ce9237cSJohn Marino   ctx->total[1] += ((len >> 31) >> 1) + (ctx->total[0] < len);
304e4b17023SJohn Marino 
305e4b17023SJohn Marino #define rol(x, n) (((x) << (n)) | ((sha1_uint32) (x) >> (32 - (n))))
306e4b17023SJohn Marino 
307e4b17023SJohn Marino #define M(I) ( tm =   x[I&0x0f] ^ x[(I-14)&0x0f] \
308e4b17023SJohn Marino 		    ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
309e4b17023SJohn Marino 	       , (x[I&0x0f] = rol(tm, 1)) )
310e4b17023SJohn Marino 
311e4b17023SJohn Marino #define R(A,B,C,D,E,F,K,M)  do { E += rol( A, 5 )     \
312e4b17023SJohn Marino 				      + F( B, C, D )  \
313e4b17023SJohn Marino 				      + K	      \
314e4b17023SJohn Marino 				      + M;	      \
315e4b17023SJohn Marino 				 B = rol( B, 30 );    \
316e4b17023SJohn Marino 			       } while(0)
317e4b17023SJohn Marino 
318e4b17023SJohn Marino   while (words < endp)
319e4b17023SJohn Marino     {
320e4b17023SJohn Marino       sha1_uint32 tm;
321e4b17023SJohn Marino       int t;
322e4b17023SJohn Marino       for (t = 0; t < 16; t++)
323e4b17023SJohn Marino 	{
324e4b17023SJohn Marino 	  x[t] = SWAP (*words);
325e4b17023SJohn Marino 	  words++;
326e4b17023SJohn Marino 	}
327e4b17023SJohn Marino 
328e4b17023SJohn Marino       R( a, b, c, d, e, F1, K1, x[ 0] );
329e4b17023SJohn Marino       R( e, a, b, c, d, F1, K1, x[ 1] );
330e4b17023SJohn Marino       R( d, e, a, b, c, F1, K1, x[ 2] );
331e4b17023SJohn Marino       R( c, d, e, a, b, F1, K1, x[ 3] );
332e4b17023SJohn Marino       R( b, c, d, e, a, F1, K1, x[ 4] );
333e4b17023SJohn Marino       R( a, b, c, d, e, F1, K1, x[ 5] );
334e4b17023SJohn Marino       R( e, a, b, c, d, F1, K1, x[ 6] );
335e4b17023SJohn Marino       R( d, e, a, b, c, F1, K1, x[ 7] );
336e4b17023SJohn Marino       R( c, d, e, a, b, F1, K1, x[ 8] );
337e4b17023SJohn Marino       R( b, c, d, e, a, F1, K1, x[ 9] );
338e4b17023SJohn Marino       R( a, b, c, d, e, F1, K1, x[10] );
339e4b17023SJohn Marino       R( e, a, b, c, d, F1, K1, x[11] );
340e4b17023SJohn Marino       R( d, e, a, b, c, F1, K1, x[12] );
341e4b17023SJohn Marino       R( c, d, e, a, b, F1, K1, x[13] );
342e4b17023SJohn Marino       R( b, c, d, e, a, F1, K1, x[14] );
343e4b17023SJohn Marino       R( a, b, c, d, e, F1, K1, x[15] );
344e4b17023SJohn Marino       R( e, a, b, c, d, F1, K1, M(16) );
345e4b17023SJohn Marino       R( d, e, a, b, c, F1, K1, M(17) );
346e4b17023SJohn Marino       R( c, d, e, a, b, F1, K1, M(18) );
347e4b17023SJohn Marino       R( b, c, d, e, a, F1, K1, M(19) );
348e4b17023SJohn Marino       R( a, b, c, d, e, F2, K2, M(20) );
349e4b17023SJohn Marino       R( e, a, b, c, d, F2, K2, M(21) );
350e4b17023SJohn Marino       R( d, e, a, b, c, F2, K2, M(22) );
351e4b17023SJohn Marino       R( c, d, e, a, b, F2, K2, M(23) );
352e4b17023SJohn Marino       R( b, c, d, e, a, F2, K2, M(24) );
353e4b17023SJohn Marino       R( a, b, c, d, e, F2, K2, M(25) );
354e4b17023SJohn Marino       R( e, a, b, c, d, F2, K2, M(26) );
355e4b17023SJohn Marino       R( d, e, a, b, c, F2, K2, M(27) );
356e4b17023SJohn Marino       R( c, d, e, a, b, F2, K2, M(28) );
357e4b17023SJohn Marino       R( b, c, d, e, a, F2, K2, M(29) );
358e4b17023SJohn Marino       R( a, b, c, d, e, F2, K2, M(30) );
359e4b17023SJohn Marino       R( e, a, b, c, d, F2, K2, M(31) );
360e4b17023SJohn Marino       R( d, e, a, b, c, F2, K2, M(32) );
361e4b17023SJohn Marino       R( c, d, e, a, b, F2, K2, M(33) );
362e4b17023SJohn Marino       R( b, c, d, e, a, F2, K2, M(34) );
363e4b17023SJohn Marino       R( a, b, c, d, e, F2, K2, M(35) );
364e4b17023SJohn Marino       R( e, a, b, c, d, F2, K2, M(36) );
365e4b17023SJohn Marino       R( d, e, a, b, c, F2, K2, M(37) );
366e4b17023SJohn Marino       R( c, d, e, a, b, F2, K2, M(38) );
367e4b17023SJohn Marino       R( b, c, d, e, a, F2, K2, M(39) );
368e4b17023SJohn Marino       R( a, b, c, d, e, F3, K3, M(40) );
369e4b17023SJohn Marino       R( e, a, b, c, d, F3, K3, M(41) );
370e4b17023SJohn Marino       R( d, e, a, b, c, F3, K3, M(42) );
371e4b17023SJohn Marino       R( c, d, e, a, b, F3, K3, M(43) );
372e4b17023SJohn Marino       R( b, c, d, e, a, F3, K3, M(44) );
373e4b17023SJohn Marino       R( a, b, c, d, e, F3, K3, M(45) );
374e4b17023SJohn Marino       R( e, a, b, c, d, F3, K3, M(46) );
375e4b17023SJohn Marino       R( d, e, a, b, c, F3, K3, M(47) );
376e4b17023SJohn Marino       R( c, d, e, a, b, F3, K3, M(48) );
377e4b17023SJohn Marino       R( b, c, d, e, a, F3, K3, M(49) );
378e4b17023SJohn Marino       R( a, b, c, d, e, F3, K3, M(50) );
379e4b17023SJohn Marino       R( e, a, b, c, d, F3, K3, M(51) );
380e4b17023SJohn Marino       R( d, e, a, b, c, F3, K3, M(52) );
381e4b17023SJohn Marino       R( c, d, e, a, b, F3, K3, M(53) );
382e4b17023SJohn Marino       R( b, c, d, e, a, F3, K3, M(54) );
383e4b17023SJohn Marino       R( a, b, c, d, e, F3, K3, M(55) );
384e4b17023SJohn Marino       R( e, a, b, c, d, F3, K3, M(56) );
385e4b17023SJohn Marino       R( d, e, a, b, c, F3, K3, M(57) );
386e4b17023SJohn Marino       R( c, d, e, a, b, F3, K3, M(58) );
387e4b17023SJohn Marino       R( b, c, d, e, a, F3, K3, M(59) );
388e4b17023SJohn Marino       R( a, b, c, d, e, F4, K4, M(60) );
389e4b17023SJohn Marino       R( e, a, b, c, d, F4, K4, M(61) );
390e4b17023SJohn Marino       R( d, e, a, b, c, F4, K4, M(62) );
391e4b17023SJohn Marino       R( c, d, e, a, b, F4, K4, M(63) );
392e4b17023SJohn Marino       R( b, c, d, e, a, F4, K4, M(64) );
393e4b17023SJohn Marino       R( a, b, c, d, e, F4, K4, M(65) );
394e4b17023SJohn Marino       R( e, a, b, c, d, F4, K4, M(66) );
395e4b17023SJohn Marino       R( d, e, a, b, c, F4, K4, M(67) );
396e4b17023SJohn Marino       R( c, d, e, a, b, F4, K4, M(68) );
397e4b17023SJohn Marino       R( b, c, d, e, a, F4, K4, M(69) );
398e4b17023SJohn Marino       R( a, b, c, d, e, F4, K4, M(70) );
399e4b17023SJohn Marino       R( e, a, b, c, d, F4, K4, M(71) );
400e4b17023SJohn Marino       R( d, e, a, b, c, F4, K4, M(72) );
401e4b17023SJohn Marino       R( c, d, e, a, b, F4, K4, M(73) );
402e4b17023SJohn Marino       R( b, c, d, e, a, F4, K4, M(74) );
403e4b17023SJohn Marino       R( a, b, c, d, e, F4, K4, M(75) );
404e4b17023SJohn Marino       R( e, a, b, c, d, F4, K4, M(76) );
405e4b17023SJohn Marino       R( d, e, a, b, c, F4, K4, M(77) );
406e4b17023SJohn Marino       R( c, d, e, a, b, F4, K4, M(78) );
407e4b17023SJohn Marino       R( b, c, d, e, a, F4, K4, M(79) );
408e4b17023SJohn Marino 
409e4b17023SJohn Marino       a = ctx->A += a;
410e4b17023SJohn Marino       b = ctx->B += b;
411e4b17023SJohn Marino       c = ctx->C += c;
412e4b17023SJohn Marino       d = ctx->D += d;
413e4b17023SJohn Marino       e = ctx->E += e;
414e4b17023SJohn Marino     }
415e4b17023SJohn Marino }
416