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