xref: /illumos-gate/usr/src/common/crypto/sha1/sha1.c (revision 9b9d39d2a32ff806d2431dbcc50968ef1e6d46b2)
1 /*
2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * The basic framework for this code came from the reference
8  * implementation for MD5.  That implementation is Copyright (C)
9  * 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.
10  *
11  * License to copy and use this software is granted provided that it
12  * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
13  * Algorithm" in all material mentioning or referencing this software
14  * or this function.
15  *
16  * License is also granted to make and use derivative works provided
17  * that such works are identified as "derived from the RSA Data
18  * Security, Inc. MD5 Message-Digest Algorithm" in all material
19  * mentioning or referencing the derived work.
20  *
21  * RSA Data Security, Inc. makes no representations concerning either
22  * the merchantability of this software or the suitability of this
23  * software for any particular purpose. It is provided "as is"
24  * without express or implied warranty of any kind.
25  *
26  * These notices must be retained in any copies of any part of this
27  * documentation and/or software.
28  *
29  * NOTE: Cleaned-up and optimized, version of SHA1, based on the FIPS 180-1
30  * standard, available at http://www.itl.nist.gov/fipspubs/fip180-1.htm
31  * Not as fast as one would like -- further optimizations are encouraged
32  * and appreciated.
33  */
34 
35 #if defined(_STANDALONE)
36 #include <sys/cdefs.h>
37 #include <stdint.h>
38 #define	_RESTRICT_KYWD	restrict
39 #else
40 #if !defined(_KERNEL) && !defined(_BOOT)
41 #include <stdint.h>
42 #include <strings.h>
43 #include <stdlib.h>
44 #include <errno.h>
45 #include <sys/systeminfo.h>
46 #endif  /* !_KERNEL && !_BOOT */
47 #endif	/* _STANDALONE */
48 
49 #include <sys/types.h>
50 #if !defined(_STANDALONE)
51 #include <sys/inttypes.h>
52 #endif
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/sysmacros.h>
56 #include <sys/sha1.h>
57 #include <sys/sha1_consts.h>
58 
59 #if defined(_STANDALONE)
60 #include <sys/endian.h>
61 #define	HAVE_HTONL
62 #if _BYTE_ORDER == _LITTLE_ENDIAN
63 #undef _BIG_ENDIAN
64 #else
65 #undef _LITTLE_ENDIAN
66 #endif
67 #else
68 #ifdef _LITTLE_ENDIAN
69 #include <sys/byteorder.h>
70 #define	HAVE_HTONL
71 #endif
72 #endif /* _STANDALONE */
73 
74 #ifdef	_BOOT
75 #define	bcopy(_s, _d, _l)	((void) memcpy((_d), (_s), (_l)))
76 #define	bzero(_m, _l)		((void) memset((_m), 0, (_l)))
77 #endif
78 
79 static void Encode(uint8_t *, const uint32_t *, size_t);
80 
81 #if	defined(__sparc)
82 
83 #define	SHA1_TRANSFORM(ctx, in) \
84 	SHA1Transform((ctx)->state[0], (ctx)->state[1], (ctx)->state[2], \
85 		(ctx)->state[3], (ctx)->state[4], (ctx), (in))
86 
87 static void SHA1Transform(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
88     SHA1_CTX *, const uint8_t [64]);
89 
90 #elif	defined(__amd64)
91 
92 #define	SHA1_TRANSFORM(ctx, in) sha1_block_data_order((ctx), (in), 1)
93 #define	SHA1_TRANSFORM_BLOCKS(ctx, in, num) sha1_block_data_order((ctx), \
94 		(in), (num))
95 
96 void sha1_block_data_order(SHA1_CTX *ctx, const void *inpp, size_t num_blocks);
97 
98 #else
99 
100 #define	SHA1_TRANSFORM(ctx, in) SHA1Transform((ctx), (in))
101 
102 static void SHA1Transform(SHA1_CTX *, const uint8_t [64]);
103 
104 #endif
105 
106 
107 static uint8_t PADDING[64] = { 0x80, /* all zeros */ };
108 
109 /*
110  * F, G, and H are the basic SHA1 functions.
111  */
112 #define	F(b, c, d)	(((b) & (c)) | ((~b) & (d)))
113 #define	G(b, c, d)	((b) ^ (c) ^ (d))
114 #define	H(b, c, d)	(((b) & (c)) | (((b)|(c)) & (d)))
115 
116 /*
117  * SHA1Init()
118  *
119  * purpose: initializes the sha1 context and begins and sha1 digest operation
120  *   input: SHA1_CTX *	: the context to initializes.
121  *  output: void
122  */
123 
124 void
125 SHA1Init(SHA1_CTX *ctx)
126 {
127 	ctx->count[0] = ctx->count[1] = 0;
128 
129 	/*
130 	 * load magic initialization constants. Tell lint
131 	 * that these constants are unsigned by using U.
132 	 */
133 
134 	ctx->state[0] = 0x67452301U;
135 	ctx->state[1] = 0xefcdab89U;
136 	ctx->state[2] = 0x98badcfeU;
137 	ctx->state[3] = 0x10325476U;
138 	ctx->state[4] = 0xc3d2e1f0U;
139 }
140 
141 #ifdef VIS_SHA1
142 #ifdef _KERNEL
143 
144 #include <sys/regset.h>
145 #include <sys/vis.h>
146 #include <sys/fpu/fpusystm.h>
147 
148 /* the alignment for block stores to save fp registers */
149 #define	VIS_ALIGN	(64)
150 
151 extern int sha1_savefp(kfpu_t *, int);
152 extern void sha1_restorefp(kfpu_t *);
153 
154 uint32_t	vis_sha1_svfp_threshold = 128;
155 
156 #endif /* _KERNEL */
157 
158 /*
159  * VIS SHA-1 consts.
160  */
161 static uint64_t VIS[] = {
162 	0x8000000080000000ULL,
163 	0x0002000200020002ULL,
164 	0x5a8279996ed9eba1ULL,
165 	0x8f1bbcdcca62c1d6ULL,
166 	0x012389ab456789abULL};
167 
168 extern void SHA1TransformVIS(uint64_t *, uint32_t *, uint32_t *, uint64_t *);
169 
170 
171 /*
172  * SHA1Update()
173  *
174  * purpose: continues an sha1 digest operation, using the message block
175  *          to update the context.
176  *   input: SHA1_CTX *	: the context to update
177  *          void *	: the message block
178  *          size_t    : the length of the message block in bytes
179  *  output: void
180  */
181 
182 void
183 SHA1Update(SHA1_CTX *ctx, const void *inptr, size_t input_len)
184 {
185 	size_t i, buf_index, buf_len;
186 	uint64_t X0[40], input64[8];
187 	const uint8_t *input = inptr;
188 	uint32_t il;
189 #ifdef _KERNEL
190 	int usevis = 0;
191 #else
192 	int usevis = 1;
193 #endif /* _KERNEL */
194 
195 	/* check for noop */
196 	if (input_len == 0)
197 		return;
198 
199 	/* compute number of bytes mod 64 */
200 	buf_index = (ctx->count[1] >> 3) & 0x3F;
201 
202 	/*
203 	 * Extract low 32 bits of input_len; when we adjust
204 	 * count[0] we must fold in the carry from the
205 	 * addition of the low bits along with the nonzero
206 	 * upper bits (if any) from input_len.
207 	 */
208 	il = input_len & UINT32_MAX;
209 	il = il << 3;
210 
211 	/* update number of bits */
212 	if ((ctx->count[1] += il) < il)
213 		ctx->count[0]++;
214 
215 	ctx->count[0] += (input_len >> 29);
216 
217 	buf_len = 64 - buf_index;
218 
219 	/* transform as many times as possible */
220 	i = 0;
221 	if (input_len >= buf_len) {
222 #ifdef _KERNEL
223 		kfpu_t *fpu;
224 		if (fpu_exists) {
225 			uint8_t fpua[sizeof (kfpu_t) + GSR_SIZE + VIS_ALIGN];
226 			size_t len = (input_len + buf_index) & ~0x3f;
227 			int svfp_ok;
228 
229 			fpu = (kfpu_t *)P2ROUNDUP((uintptr_t)fpua, 64);
230 			svfp_ok = ((len >= vis_sha1_svfp_threshold) ? 1 : 0);
231 			usevis = fpu_exists && sha1_savefp(fpu, svfp_ok);
232 		} else {
233 			usevis = 0;
234 		}
235 #endif /* _KERNEL */
236 
237 		/*
238 		 * general optimization:
239 		 *
240 		 * only do initial bcopy() and SHA1Transform() if
241 		 * buf_index != 0.  if buf_index == 0, we're just
242 		 * wasting our time doing the bcopy() since there
243 		 * wasn't any data left over from a previous call to
244 		 * SHA1Update().
245 		 */
246 
247 		if (buf_index) {
248 			bcopy(input, &ctx->buf_un.buf8[buf_index], buf_len);
249 			if (usevis) {
250 				SHA1TransformVIS(X0,
251 				    ctx->buf_un.buf32,
252 				    &ctx->state[0], VIS);
253 			} else {
254 				SHA1_TRANSFORM(ctx, ctx->buf_un.buf8);
255 			}
256 			i = buf_len;
257 		}
258 
259 		/*
260 		 * VIS SHA-1: uses the VIS 1.0 instructions to accelerate
261 		 * SHA-1 processing. This is achieved by "offloading" the
262 		 * computation of the message schedule (MS) to the VIS units.
263 		 * This allows the VIS computation of the message schedule
264 		 * to be performed in parallel with the standard integer
265 		 * processing of the remainder of the SHA-1 computation.
266 		 * performance by up to around 1.37X, compared to an optimized
267 		 * integer-only implementation.
268 		 *
269 		 * The VIS implementation of SHA1Transform has a different API
270 		 * to the standard integer version:
271 		 *
272 		 * void SHA1TransformVIS(
273 		 *	 uint64_t *, // Pointer to MS for ith block
274 		 *	 uint32_t *, // Pointer to ith block of message data
275 		 *	 uint32_t *, // Pointer to SHA state i.e ctx->state
276 		 *	 uint64_t *, // Pointer to various VIS constants
277 		 * )
278 		 *
279 		 * Note: the message data must by 4-byte aligned.
280 		 *
281 		 * Function requires VIS 1.0 support.
282 		 *
283 		 * Handling is provided to deal with arbitrary byte alingment
284 		 * of the input data but the performance gains are reduced
285 		 * for alignments other than 4-bytes.
286 		 */
287 		if (usevis) {
288 			if (!IS_P2ALIGNED(&input[i], sizeof (uint32_t))) {
289 				/*
290 				 * Main processing loop - input misaligned
291 				 */
292 				for (; i + 63 < input_len; i += 64) {
293 					bcopy(&input[i], input64, 64);
294 					SHA1TransformVIS(X0,
295 					    (uint32_t *)input64,
296 					    &ctx->state[0], VIS);
297 				}
298 			} else {
299 				/*
300 				 * Main processing loop - input 8-byte aligned
301 				 */
302 				for (; i + 63 < input_len; i += 64) {
303 					SHA1TransformVIS(X0,
304 					    /* LINTED E_BAD_PTR_CAST_ALIGN */
305 					    (uint32_t *)&input[i], /* CSTYLED */
306 					    &ctx->state[0], VIS);
307 				}
308 
309 			}
310 #ifdef _KERNEL
311 			sha1_restorefp(fpu);
312 #endif /* _KERNEL */
313 		} else {
314 			for (; i + 63 < input_len; i += 64) {
315 				SHA1_TRANSFORM(ctx, &input[i]);
316 			}
317 		}
318 
319 		/*
320 		 * general optimization:
321 		 *
322 		 * if i and input_len are the same, return now instead
323 		 * of calling bcopy(), since the bcopy() in this case
324 		 * will be an expensive nop.
325 		 */
326 
327 		if (input_len == i)
328 			return;
329 
330 		buf_index = 0;
331 	}
332 
333 	/* buffer remaining input */
334 	bcopy(&input[i], &ctx->buf_un.buf8[buf_index], input_len - i);
335 }
336 
337 #else /* VIS_SHA1 */
338 
339 void
340 SHA1Update(SHA1_CTX *ctx, const void *inptr, size_t input_len)
341 {
342 	size_t i, buf_index, buf_len;
343 	const uint8_t *input = inptr;
344 	uint32_t il;
345 #if defined(__amd64)
346 	size_t	block_count;
347 #endif	/* __amd64 */
348 
349 	/* check for noop */
350 	if (input_len == 0)
351 		return;
352 
353 	/* compute number of bytes mod 64 */
354 	buf_index = (ctx->count[1] >> 3) & 0x3F;
355 
356 	/*
357 	 * Extract low 32 bits of input_len; when we adjust
358 	 * count[0] we must fold in the carry from the
359 	 * addition of the low bits along with the nonzero
360 	 * upper bits (if any) from input_len.
361 	 */
362 	il = input_len & UINT32_MAX;
363 	il = il << 3;
364 
365 	/* update number of bits */
366 	if ((ctx->count[1] += il) < il)
367 		ctx->count[0]++;
368 
369 	ctx->count[0] += (input_len >> 29);
370 
371 	buf_len = 64 - buf_index;
372 
373 	/* transform as many times as possible */
374 	i = 0;
375 	if (input_len >= buf_len) {
376 
377 		/*
378 		 * general optimization:
379 		 *
380 		 * only do initial bcopy() and SHA1Transform() if
381 		 * buf_index != 0.  if buf_index == 0, we're just
382 		 * wasting our time doing the bcopy() since there
383 		 * wasn't any data left over from a previous call to
384 		 * SHA1Update().
385 		 */
386 
387 		if (buf_index) {
388 			bcopy(input, &ctx->buf_un.buf8[buf_index], buf_len);
389 			SHA1_TRANSFORM(ctx, ctx->buf_un.buf8);
390 			i = buf_len;
391 		}
392 
393 #if !defined(__amd64)
394 		for (; i + 63 < input_len; i += 64)
395 			SHA1_TRANSFORM(ctx, &input[i]);
396 #else
397 		block_count = (input_len - i) >> 6;
398 		if (block_count > 0) {
399 			SHA1_TRANSFORM_BLOCKS(ctx, &input[i], block_count);
400 			i += block_count << 6;
401 		}
402 #endif	/* !__amd64 */
403 
404 		/*
405 		 * general optimization:
406 		 *
407 		 * if i and input_len are the same, return now instead
408 		 * of calling bcopy(), since the bcopy() in this case
409 		 * will be an expensive nop.
410 		 */
411 
412 		if (input_len == i)
413 			return;
414 
415 		buf_index = 0;
416 	}
417 
418 	/* buffer remaining input */
419 	bcopy(&input[i], &ctx->buf_un.buf8[buf_index], input_len - i);
420 }
421 
422 #endif /* VIS_SHA1 */
423 
424 /*
425  * SHA1Final()
426  *
427  * purpose: ends an sha1 digest operation, finalizing the message digest and
428  *          zeroing the context.
429  *   input: uchar_t *	: A buffer to store the digest.
430  *			: The function actually uses void* because many
431  *			: callers pass things other than uchar_t here.
432  *          SHA1_CTX *  : the context to finalize, save, and zero
433  *  output: void
434  */
435 
436 void
437 SHA1Final(void *digest, SHA1_CTX *ctx)
438 {
439 	uint8_t		bitcount_be[sizeof (ctx->count)];
440 	uint32_t	index = (ctx->count[1] >> 3) & 0x3f;
441 
442 	/* store bit count, big endian */
443 	Encode(bitcount_be, ctx->count, sizeof (bitcount_be));
444 
445 	/* pad out to 56 mod 64 */
446 	SHA1Update(ctx, PADDING, ((index < 56) ? 56 : 120) - index);
447 
448 	/* append length (before padding) */
449 	SHA1Update(ctx, bitcount_be, sizeof (bitcount_be));
450 
451 	/* store state in digest */
452 	Encode(digest, ctx->state, sizeof (ctx->state));
453 
454 	/* zeroize sensitive information */
455 	bzero(ctx, sizeof (*ctx));
456 }
457 
458 
459 #if !defined(__amd64)
460 
461 /*
462  * ROTATE_LEFT rotates x left n bits.
463  */
464 
465 #if	defined(__GNUC__) && defined(_LP64)
466 static __inline__ uint64_t
467 ROTATE_LEFT(uint64_t value, uint32_t n)
468 {
469 	uint32_t t32;
470 
471 	t32 = (uint32_t)value;
472 	return ((t32 << n) | (t32 >> (32 - n)));
473 }
474 
475 #else
476 #define	ROTATE_LEFT(x, n)	\
477 	(((x) << (n)) | ((x) >> ((sizeof (x) * NBBY)-(n))))
478 #endif
479 
480 typedef uint32_t sha1word;
481 
482 /*
483  * sparc optimization:
484  *
485  * on the sparc, we can load big endian 32-bit data easily.  note that
486  * special care must be taken to ensure the address is 32-bit aligned.
487  * in the interest of speed, we don't check to make sure, since
488  * careful programming can guarantee this for us.
489  */
490 
491 #if	defined(_BIG_ENDIAN)
492 #define	LOAD_BIG_32(addr)	(*(uint32_t *)(addr))
493 
494 #elif	defined(HAVE_HTONL)
495 #define	LOAD_BIG_32(addr) htonl(*((uint32_t *)(addr)))
496 
497 #else
498 /* little endian -- will work on big endian, but slowly */
499 #define	LOAD_BIG_32(addr)	\
500 	(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
501 #endif	/* _BIG_ENDIAN */
502 
503 /*
504  * SHA1Transform()
505  */
506 #if	defined(W_ARRAY)
507 #define	W(n) w[n]
508 #else	/* !defined(W_ARRAY) */
509 #define	W(n) w_ ## n
510 #endif	/* !defined(W_ARRAY) */
511 
512 
513 #if	defined(__sparc)
514 
515 /*
516  * sparc register window optimization:
517  *
518  * `a', `b', `c', `d', and `e' are passed into SHA1Transform
519  * explicitly since it increases the number of registers available to
520  * the compiler.  under this scheme, these variables can be held in
521  * %i0 - %i4, which leaves more local and out registers available.
522  *
523  * purpose: sha1 transformation -- updates the digest based on `block'
524  *   input: uint32_t	: bytes  1 -  4 of the digest
525  *          uint32_t	: bytes  5 -  8 of the digest
526  *          uint32_t	: bytes  9 - 12 of the digest
527  *          uint32_t	: bytes 12 - 16 of the digest
528  *          uint32_t	: bytes 16 - 20 of the digest
529  *          SHA1_CTX *	: the context to update
530  *          uint8_t [64]: the block to use to update the digest
531  *  output: void
532  */
533 
534 void
535 SHA1Transform(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e,
536     SHA1_CTX *ctx, const uint8_t blk[64])
537 {
538 	/*
539 	 * sparc optimization:
540 	 *
541 	 * while it is somewhat counter-intuitive, on sparc, it is
542 	 * more efficient to place all the constants used in this
543 	 * function in an array and load the values out of the array
544 	 * than to manually load the constants.  this is because
545 	 * setting a register to a 32-bit value takes two ops in most
546 	 * cases: a `sethi' and an `or', but loading a 32-bit value
547 	 * from memory only takes one `ld' (or `lduw' on v9).  while
548 	 * this increases memory usage, the compiler can find enough
549 	 * other things to do while waiting to keep the pipeline does
550 	 * not stall.  additionally, it is likely that many of these
551 	 * constants are cached so that later accesses do not even go
552 	 * out to the bus.
553 	 *
554 	 * this array is declared `static' to keep the compiler from
555 	 * having to bcopy() this array onto the stack frame of
556 	 * SHA1Transform() each time it is called -- which is
557 	 * unacceptably expensive.
558 	 *
559 	 * the `const' is to ensure that callers are good citizens and
560 	 * do not try to munge the array.  since these routines are
561 	 * going to be called from inside multithreaded kernelland,
562 	 * this is a good safety check. -- `sha1_consts' will end up in
563 	 * .rodata.
564 	 *
565 	 * unfortunately, loading from an array in this manner hurts
566 	 * performance under Intel.  So, there is a macro,
567 	 * SHA1_CONST(), used in SHA1Transform(), that either expands to
568 	 * a reference to this array, or to the actual constant,
569 	 * depending on what platform this code is compiled for.
570 	 */
571 
572 	static const uint32_t sha1_consts[] = {
573 		SHA1_CONST_0, SHA1_CONST_1, SHA1_CONST_2, SHA1_CONST_3
574 	};
575 
576 	/*
577 	 * general optimization:
578 	 *
579 	 * use individual integers instead of using an array.  this is a
580 	 * win, although the amount it wins by seems to vary quite a bit.
581 	 */
582 
583 	uint32_t	w_0, w_1, w_2,  w_3,  w_4,  w_5,  w_6,  w_7;
584 	uint32_t	w_8, w_9, w_10, w_11, w_12, w_13, w_14, w_15;
585 
586 	/*
587 	 * sparc optimization:
588 	 *
589 	 * if `block' is already aligned on a 4-byte boundary, use
590 	 * LOAD_BIG_32() directly.  otherwise, bcopy() into a
591 	 * buffer that *is* aligned on a 4-byte boundary and then do
592 	 * the LOAD_BIG_32() on that buffer.  benchmarks have shown
593 	 * that using the bcopy() is better than loading the bytes
594 	 * individually and doing the endian-swap by hand.
595 	 *
596 	 * even though it's quite tempting to assign to do:
597 	 *
598 	 * blk = bcopy(ctx->buf_un.buf32, blk, sizeof (ctx->buf_un.buf32));
599 	 *
600 	 * and only have one set of LOAD_BIG_32()'s, the compiler
601 	 * *does not* like that, so please resist the urge.
602 	 */
603 
604 	if ((uintptr_t)blk & 0x3) {		/* not 4-byte aligned? */
605 		bcopy(blk, ctx->buf_un.buf32,  sizeof (ctx->buf_un.buf32));
606 		w_15 = LOAD_BIG_32(ctx->buf_un.buf32 + 15);
607 		w_14 = LOAD_BIG_32(ctx->buf_un.buf32 + 14);
608 		w_13 = LOAD_BIG_32(ctx->buf_un.buf32 + 13);
609 		w_12 = LOAD_BIG_32(ctx->buf_un.buf32 + 12);
610 		w_11 = LOAD_BIG_32(ctx->buf_un.buf32 + 11);
611 		w_10 = LOAD_BIG_32(ctx->buf_un.buf32 + 10);
612 		w_9  = LOAD_BIG_32(ctx->buf_un.buf32 +  9);
613 		w_8  = LOAD_BIG_32(ctx->buf_un.buf32 +  8);
614 		w_7  = LOAD_BIG_32(ctx->buf_un.buf32 +  7);
615 		w_6  = LOAD_BIG_32(ctx->buf_un.buf32 +  6);
616 		w_5  = LOAD_BIG_32(ctx->buf_un.buf32 +  5);
617 		w_4  = LOAD_BIG_32(ctx->buf_un.buf32 +  4);
618 		w_3  = LOAD_BIG_32(ctx->buf_un.buf32 +  3);
619 		w_2  = LOAD_BIG_32(ctx->buf_un.buf32 +  2);
620 		w_1  = LOAD_BIG_32(ctx->buf_un.buf32 +  1);
621 		w_0  = LOAD_BIG_32(ctx->buf_un.buf32 +  0);
622 	} else {
623 		/* LINTED E_BAD_PTR_CAST_ALIGN */
624 		w_15 = LOAD_BIG_32(blk + 60);
625 		/* LINTED E_BAD_PTR_CAST_ALIGN */
626 		w_14 = LOAD_BIG_32(blk + 56);
627 		/* LINTED E_BAD_PTR_CAST_ALIGN */
628 		w_13 = LOAD_BIG_32(blk + 52);
629 		/* LINTED E_BAD_PTR_CAST_ALIGN */
630 		w_12 = LOAD_BIG_32(blk + 48);
631 		/* LINTED E_BAD_PTR_CAST_ALIGN */
632 		w_11 = LOAD_BIG_32(blk + 44);
633 		/* LINTED E_BAD_PTR_CAST_ALIGN */
634 		w_10 = LOAD_BIG_32(blk + 40);
635 		/* LINTED E_BAD_PTR_CAST_ALIGN */
636 		w_9  = LOAD_BIG_32(blk + 36);
637 		/* LINTED E_BAD_PTR_CAST_ALIGN */
638 		w_8  = LOAD_BIG_32(blk + 32);
639 		/* LINTED E_BAD_PTR_CAST_ALIGN */
640 		w_7  = LOAD_BIG_32(blk + 28);
641 		/* LINTED E_BAD_PTR_CAST_ALIGN */
642 		w_6  = LOAD_BIG_32(blk + 24);
643 		/* LINTED E_BAD_PTR_CAST_ALIGN */
644 		w_5  = LOAD_BIG_32(blk + 20);
645 		/* LINTED E_BAD_PTR_CAST_ALIGN */
646 		w_4  = LOAD_BIG_32(blk + 16);
647 		/* LINTED E_BAD_PTR_CAST_ALIGN */
648 		w_3  = LOAD_BIG_32(blk + 12);
649 		/* LINTED E_BAD_PTR_CAST_ALIGN */
650 		w_2  = LOAD_BIG_32(blk +  8);
651 		/* LINTED E_BAD_PTR_CAST_ALIGN */
652 		w_1  = LOAD_BIG_32(blk +  4);
653 		/* LINTED E_BAD_PTR_CAST_ALIGN */
654 		w_0  = LOAD_BIG_32(blk +  0);
655 	}
656 #else	/* !defined(__sparc) */
657 
658 void /* CSTYLED */
659 SHA1Transform(SHA1_CTX *ctx, const uint8_t blk[64])
660 {
661 	/* CSTYLED */
662 	sha1word a = ctx->state[0];
663 	sha1word b = ctx->state[1];
664 	sha1word c = ctx->state[2];
665 	sha1word d = ctx->state[3];
666 	sha1word e = ctx->state[4];
667 
668 #if	defined(W_ARRAY)
669 	sha1word	w[16];
670 #else	/* !defined(W_ARRAY) */
671 	sha1word	w_0, w_1, w_2,  w_3,  w_4,  w_5,  w_6,  w_7;
672 	sha1word	w_8, w_9, w_10, w_11, w_12, w_13, w_14, w_15;
673 #endif	/* !defined(W_ARRAY) */
674 
675 	W(0)  = LOAD_BIG_32((void *)(blk +  0));
676 	W(1)  = LOAD_BIG_32((void *)(blk +  4));
677 	W(2)  = LOAD_BIG_32((void *)(blk +  8));
678 	W(3)  = LOAD_BIG_32((void *)(blk + 12));
679 	W(4)  = LOAD_BIG_32((void *)(blk + 16));
680 	W(5)  = LOAD_BIG_32((void *)(blk + 20));
681 	W(6)  = LOAD_BIG_32((void *)(blk + 24));
682 	W(7)  = LOAD_BIG_32((void *)(blk + 28));
683 	W(8)  = LOAD_BIG_32((void *)(blk + 32));
684 	W(9)  = LOAD_BIG_32((void *)(blk + 36));
685 	W(10) = LOAD_BIG_32((void *)(blk + 40));
686 	W(11) = LOAD_BIG_32((void *)(blk + 44));
687 	W(12) = LOAD_BIG_32((void *)(blk + 48));
688 	W(13) = LOAD_BIG_32((void *)(blk + 52));
689 	W(14) = LOAD_BIG_32((void *)(blk + 56));
690 	W(15) = LOAD_BIG_32((void *)(blk + 60));
691 
692 #endif	/* !defined(__sparc) */
693 
694 	/*
695 	 * general optimization:
696 	 *
697 	 * even though this approach is described in the standard as
698 	 * being slower algorithmically, it is 30-40% faster than the
699 	 * "faster" version under SPARC, because this version has more
700 	 * of the constraints specified at compile-time and uses fewer
701 	 * variables (and therefore has better register utilization)
702 	 * than its "speedier" brother.  (i've tried both, trust me)
703 	 *
704 	 * for either method given in the spec, there is an "assignment"
705 	 * phase where the following takes place:
706 	 *
707 	 *	tmp = (main_computation);
708 	 *	e = d; d = c; c = rotate_left(b, 30); b = a; a = tmp;
709 	 *
710 	 * we can make the algorithm go faster by not doing this work,
711 	 * but just pretending that `d' is now `e', etc. this works
712 	 * really well and obviates the need for a temporary variable.
713 	 * however, we still explicitly perform the rotate action,
714 	 * since it is cheaper on SPARC to do it once than to have to
715 	 * do it over and over again.
716 	 */
717 
718 	/* round 1 */
719 	e = ROTATE_LEFT(a, 5) + F(b, c, d) + e + W(0) + SHA1_CONST(0); /* 0 */
720 	b = ROTATE_LEFT(b, 30);
721 
722 	d = ROTATE_LEFT(e, 5) + F(a, b, c) + d + W(1) + SHA1_CONST(0); /* 1 */
723 	a = ROTATE_LEFT(a, 30);
724 
725 	c = ROTATE_LEFT(d, 5) + F(e, a, b) + c + W(2) + SHA1_CONST(0); /* 2 */
726 	e = ROTATE_LEFT(e, 30);
727 
728 	b = ROTATE_LEFT(c, 5) + F(d, e, a) + b + W(3) + SHA1_CONST(0); /* 3 */
729 	d = ROTATE_LEFT(d, 30);
730 
731 	a = ROTATE_LEFT(b, 5) + F(c, d, e) + a + W(4) + SHA1_CONST(0); /* 4 */
732 	c = ROTATE_LEFT(c, 30);
733 
734 	e = ROTATE_LEFT(a, 5) + F(b, c, d) + e + W(5) + SHA1_CONST(0); /* 5 */
735 	b = ROTATE_LEFT(b, 30);
736 
737 	d = ROTATE_LEFT(e, 5) + F(a, b, c) + d + W(6) + SHA1_CONST(0); /* 6 */
738 	a = ROTATE_LEFT(a, 30);
739 
740 	c = ROTATE_LEFT(d, 5) + F(e, a, b) + c + W(7) + SHA1_CONST(0); /* 7 */
741 	e = ROTATE_LEFT(e, 30);
742 
743 	b = ROTATE_LEFT(c, 5) + F(d, e, a) + b + W(8) + SHA1_CONST(0); /* 8 */
744 	d = ROTATE_LEFT(d, 30);
745 
746 	a = ROTATE_LEFT(b, 5) + F(c, d, e) + a + W(9) + SHA1_CONST(0); /* 9 */
747 	c = ROTATE_LEFT(c, 30);
748 
749 	e = ROTATE_LEFT(a, 5) + F(b, c, d) + e + W(10) + SHA1_CONST(0); /* 10 */
750 	b = ROTATE_LEFT(b, 30);
751 
752 	d = ROTATE_LEFT(e, 5) + F(a, b, c) + d + W(11) + SHA1_CONST(0); /* 11 */
753 	a = ROTATE_LEFT(a, 30);
754 
755 	c = ROTATE_LEFT(d, 5) + F(e, a, b) + c + W(12) + SHA1_CONST(0); /* 12 */
756 	e = ROTATE_LEFT(e, 30);
757 
758 	b = ROTATE_LEFT(c, 5) + F(d, e, a) + b + W(13) + SHA1_CONST(0); /* 13 */
759 	d = ROTATE_LEFT(d, 30);
760 
761 	a = ROTATE_LEFT(b, 5) + F(c, d, e) + a + W(14) + SHA1_CONST(0); /* 14 */
762 	c = ROTATE_LEFT(c, 30);
763 
764 	e = ROTATE_LEFT(a, 5) + F(b, c, d) + e + W(15) + SHA1_CONST(0); /* 15 */
765 	b = ROTATE_LEFT(b, 30);
766 
767 	W(0) = ROTATE_LEFT((W(13) ^ W(8) ^ W(2) ^ W(0)), 1);		/* 16 */
768 	d = ROTATE_LEFT(e, 5) + F(a, b, c) + d + W(0) + SHA1_CONST(0);
769 	a = ROTATE_LEFT(a, 30);
770 
771 	W(1) = ROTATE_LEFT((W(14) ^ W(9) ^ W(3) ^ W(1)), 1);		/* 17 */
772 	c = ROTATE_LEFT(d, 5) + F(e, a, b) + c + W(1) + SHA1_CONST(0);
773 	e = ROTATE_LEFT(e, 30);
774 
775 	W(2) = ROTATE_LEFT((W(15) ^ W(10) ^ W(4) ^ W(2)), 1);	/* 18 */
776 	b = ROTATE_LEFT(c, 5) + F(d, e, a) + b + W(2) + SHA1_CONST(0);
777 	d = ROTATE_LEFT(d, 30);
778 
779 	W(3) = ROTATE_LEFT((W(0) ^ W(11) ^ W(5) ^ W(3)), 1);		/* 19 */
780 	a = ROTATE_LEFT(b, 5) + F(c, d, e) + a + W(3) + SHA1_CONST(0);
781 	c = ROTATE_LEFT(c, 30);
782 
783 	/* round 2 */
784 	W(4) = ROTATE_LEFT((W(1) ^ W(12) ^ W(6) ^ W(4)), 1);		/* 20 */
785 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(4) + SHA1_CONST(1);
786 	b = ROTATE_LEFT(b, 30);
787 
788 	W(5) = ROTATE_LEFT((W(2) ^ W(13) ^ W(7) ^ W(5)), 1);		/* 21 */
789 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(5) + SHA1_CONST(1);
790 	a = ROTATE_LEFT(a, 30);
791 
792 	W(6) = ROTATE_LEFT((W(3) ^ W(14) ^ W(8) ^ W(6)), 1);		/* 22 */
793 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(6) + SHA1_CONST(1);
794 	e = ROTATE_LEFT(e, 30);
795 
796 	W(7) = ROTATE_LEFT((W(4) ^ W(15) ^ W(9) ^ W(7)), 1);		/* 23 */
797 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(7) + SHA1_CONST(1);
798 	d = ROTATE_LEFT(d, 30);
799 
800 	W(8) = ROTATE_LEFT((W(5) ^ W(0) ^ W(10) ^ W(8)), 1);		/* 24 */
801 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(8) + SHA1_CONST(1);
802 	c = ROTATE_LEFT(c, 30);
803 
804 	W(9) = ROTATE_LEFT((W(6) ^ W(1) ^ W(11) ^ W(9)), 1);		/* 25 */
805 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(9) + SHA1_CONST(1);
806 	b = ROTATE_LEFT(b, 30);
807 
808 	W(10) = ROTATE_LEFT((W(7) ^ W(2) ^ W(12) ^ W(10)), 1);	/* 26 */
809 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(10) + SHA1_CONST(1);
810 	a = ROTATE_LEFT(a, 30);
811 
812 	W(11) = ROTATE_LEFT((W(8) ^ W(3) ^ W(13) ^ W(11)), 1);	/* 27 */
813 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(11) + SHA1_CONST(1);
814 	e = ROTATE_LEFT(e, 30);
815 
816 	W(12) = ROTATE_LEFT((W(9) ^ W(4) ^ W(14) ^ W(12)), 1);	/* 28 */
817 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(12) + SHA1_CONST(1);
818 	d = ROTATE_LEFT(d, 30);
819 
820 	W(13) = ROTATE_LEFT((W(10) ^ W(5) ^ W(15) ^ W(13)), 1);	/* 29 */
821 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(13) + SHA1_CONST(1);
822 	c = ROTATE_LEFT(c, 30);
823 
824 	W(14) = ROTATE_LEFT((W(11) ^ W(6) ^ W(0) ^ W(14)), 1);	/* 30 */
825 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(14) + SHA1_CONST(1);
826 	b = ROTATE_LEFT(b, 30);
827 
828 	W(15) = ROTATE_LEFT((W(12) ^ W(7) ^ W(1) ^ W(15)), 1);	/* 31 */
829 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(15) + SHA1_CONST(1);
830 	a = ROTATE_LEFT(a, 30);
831 
832 	W(0) = ROTATE_LEFT((W(13) ^ W(8) ^ W(2) ^ W(0)), 1);		/* 32 */
833 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(0) + SHA1_CONST(1);
834 	e = ROTATE_LEFT(e, 30);
835 
836 	W(1) = ROTATE_LEFT((W(14) ^ W(9) ^ W(3) ^ W(1)), 1);		/* 33 */
837 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(1) + SHA1_CONST(1);
838 	d = ROTATE_LEFT(d, 30);
839 
840 	W(2) = ROTATE_LEFT((W(15) ^ W(10) ^ W(4) ^ W(2)), 1);	/* 34 */
841 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(2) + SHA1_CONST(1);
842 	c = ROTATE_LEFT(c, 30);
843 
844 	W(3) = ROTATE_LEFT((W(0) ^ W(11) ^ W(5) ^ W(3)), 1);		/* 35 */
845 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(3) + SHA1_CONST(1);
846 	b = ROTATE_LEFT(b, 30);
847 
848 	W(4) = ROTATE_LEFT((W(1) ^ W(12) ^ W(6) ^ W(4)), 1);		/* 36 */
849 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(4) + SHA1_CONST(1);
850 	a = ROTATE_LEFT(a, 30);
851 
852 	W(5) = ROTATE_LEFT((W(2) ^ W(13) ^ W(7) ^ W(5)), 1);		/* 37 */
853 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(5) + SHA1_CONST(1);
854 	e = ROTATE_LEFT(e, 30);
855 
856 	W(6) = ROTATE_LEFT((W(3) ^ W(14) ^ W(8) ^ W(6)), 1);		/* 38 */
857 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(6) + SHA1_CONST(1);
858 	d = ROTATE_LEFT(d, 30);
859 
860 	W(7) = ROTATE_LEFT((W(4) ^ W(15) ^ W(9) ^ W(7)), 1);		/* 39 */
861 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(7) + SHA1_CONST(1);
862 	c = ROTATE_LEFT(c, 30);
863 
864 	/* round 3 */
865 	W(8) = ROTATE_LEFT((W(5) ^ W(0) ^ W(10) ^ W(8)), 1);		/* 40 */
866 	e = ROTATE_LEFT(a, 5) + H(b, c, d) + e + W(8) + SHA1_CONST(2);
867 	b = ROTATE_LEFT(b, 30);
868 
869 	W(9) = ROTATE_LEFT((W(6) ^ W(1) ^ W(11) ^ W(9)), 1);		/* 41 */
870 	d = ROTATE_LEFT(e, 5) + H(a, b, c) + d + W(9) + SHA1_CONST(2);
871 	a = ROTATE_LEFT(a, 30);
872 
873 	W(10) = ROTATE_LEFT((W(7) ^ W(2) ^ W(12) ^ W(10)), 1);	/* 42 */
874 	c = ROTATE_LEFT(d, 5) + H(e, a, b) + c + W(10) + SHA1_CONST(2);
875 	e = ROTATE_LEFT(e, 30);
876 
877 	W(11) = ROTATE_LEFT((W(8) ^ W(3) ^ W(13) ^ W(11)), 1);	/* 43 */
878 	b = ROTATE_LEFT(c, 5) + H(d, e, a) + b + W(11) + SHA1_CONST(2);
879 	d = ROTATE_LEFT(d, 30);
880 
881 	W(12) = ROTATE_LEFT((W(9) ^ W(4) ^ W(14) ^ W(12)), 1);	/* 44 */
882 	a = ROTATE_LEFT(b, 5) + H(c, d, e) + a + W(12) + SHA1_CONST(2);
883 	c = ROTATE_LEFT(c, 30);
884 
885 	W(13) = ROTATE_LEFT((W(10) ^ W(5) ^ W(15) ^ W(13)), 1);	/* 45 */
886 	e = ROTATE_LEFT(a, 5) + H(b, c, d) + e + W(13) + SHA1_CONST(2);
887 	b = ROTATE_LEFT(b, 30);
888 
889 	W(14) = ROTATE_LEFT((W(11) ^ W(6) ^ W(0) ^ W(14)), 1);	/* 46 */
890 	d = ROTATE_LEFT(e, 5) + H(a, b, c) + d + W(14) + SHA1_CONST(2);
891 	a = ROTATE_LEFT(a, 30);
892 
893 	W(15) = ROTATE_LEFT((W(12) ^ W(7) ^ W(1) ^ W(15)), 1);	/* 47 */
894 	c = ROTATE_LEFT(d, 5) + H(e, a, b) + c + W(15) + SHA1_CONST(2);
895 	e = ROTATE_LEFT(e, 30);
896 
897 	W(0) = ROTATE_LEFT((W(13) ^ W(8) ^ W(2) ^ W(0)), 1);		/* 48 */
898 	b = ROTATE_LEFT(c, 5) + H(d, e, a) + b + W(0) + SHA1_CONST(2);
899 	d = ROTATE_LEFT(d, 30);
900 
901 	W(1) = ROTATE_LEFT((W(14) ^ W(9) ^ W(3) ^ W(1)), 1);		/* 49 */
902 	a = ROTATE_LEFT(b, 5) + H(c, d, e) + a + W(1) + SHA1_CONST(2);
903 	c = ROTATE_LEFT(c, 30);
904 
905 	W(2) = ROTATE_LEFT((W(15) ^ W(10) ^ W(4) ^ W(2)), 1);	/* 50 */
906 	e = ROTATE_LEFT(a, 5) + H(b, c, d) + e + W(2) + SHA1_CONST(2);
907 	b = ROTATE_LEFT(b, 30);
908 
909 	W(3) = ROTATE_LEFT((W(0) ^ W(11) ^ W(5) ^ W(3)), 1);		/* 51 */
910 	d = ROTATE_LEFT(e, 5) + H(a, b, c) + d + W(3) + SHA1_CONST(2);
911 	a = ROTATE_LEFT(a, 30);
912 
913 	W(4) = ROTATE_LEFT((W(1) ^ W(12) ^ W(6) ^ W(4)), 1);		/* 52 */
914 	c = ROTATE_LEFT(d, 5) + H(e, a, b) + c + W(4) + SHA1_CONST(2);
915 	e = ROTATE_LEFT(e, 30);
916 
917 	W(5) = ROTATE_LEFT((W(2) ^ W(13) ^ W(7) ^ W(5)), 1);		/* 53 */
918 	b = ROTATE_LEFT(c, 5) + H(d, e, a) + b + W(5) + SHA1_CONST(2);
919 	d = ROTATE_LEFT(d, 30);
920 
921 	W(6) = ROTATE_LEFT((W(3) ^ W(14) ^ W(8) ^ W(6)), 1);		/* 54 */
922 	a = ROTATE_LEFT(b, 5) + H(c, d, e) + a + W(6) + SHA1_CONST(2);
923 	c = ROTATE_LEFT(c, 30);
924 
925 	W(7) = ROTATE_LEFT((W(4) ^ W(15) ^ W(9) ^ W(7)), 1);		/* 55 */
926 	e = ROTATE_LEFT(a, 5) + H(b, c, d) + e + W(7) + SHA1_CONST(2);
927 	b = ROTATE_LEFT(b, 30);
928 
929 	W(8) = ROTATE_LEFT((W(5) ^ W(0) ^ W(10) ^ W(8)), 1);		/* 56 */
930 	d = ROTATE_LEFT(e, 5) + H(a, b, c) + d + W(8) + SHA1_CONST(2);
931 	a = ROTATE_LEFT(a, 30);
932 
933 	W(9) = ROTATE_LEFT((W(6) ^ W(1) ^ W(11) ^ W(9)), 1);		/* 57 */
934 	c = ROTATE_LEFT(d, 5) + H(e, a, b) + c + W(9) + SHA1_CONST(2);
935 	e = ROTATE_LEFT(e, 30);
936 
937 	W(10) = ROTATE_LEFT((W(7) ^ W(2) ^ W(12) ^ W(10)), 1);	/* 58 */
938 	b = ROTATE_LEFT(c, 5) + H(d, e, a) + b + W(10) + SHA1_CONST(2);
939 	d = ROTATE_LEFT(d, 30);
940 
941 	W(11) = ROTATE_LEFT((W(8) ^ W(3) ^ W(13) ^ W(11)), 1);	/* 59 */
942 	a = ROTATE_LEFT(b, 5) + H(c, d, e) + a + W(11) + SHA1_CONST(2);
943 	c = ROTATE_LEFT(c, 30);
944 
945 	/* round 4 */
946 	W(12) = ROTATE_LEFT((W(9) ^ W(4) ^ W(14) ^ W(12)), 1);	/* 60 */
947 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(12) + SHA1_CONST(3);
948 	b = ROTATE_LEFT(b, 30);
949 
950 	W(13) = ROTATE_LEFT((W(10) ^ W(5) ^ W(15) ^ W(13)), 1);	/* 61 */
951 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(13) + SHA1_CONST(3);
952 	a = ROTATE_LEFT(a, 30);
953 
954 	W(14) = ROTATE_LEFT((W(11) ^ W(6) ^ W(0) ^ W(14)), 1);	/* 62 */
955 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(14) + SHA1_CONST(3);
956 	e = ROTATE_LEFT(e, 30);
957 
958 	W(15) = ROTATE_LEFT((W(12) ^ W(7) ^ W(1) ^ W(15)), 1);	/* 63 */
959 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(15) + SHA1_CONST(3);
960 	d = ROTATE_LEFT(d, 30);
961 
962 	W(0) = ROTATE_LEFT((W(13) ^ W(8) ^ W(2) ^ W(0)), 1);		/* 64 */
963 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(0) + SHA1_CONST(3);
964 	c = ROTATE_LEFT(c, 30);
965 
966 	W(1) = ROTATE_LEFT((W(14) ^ W(9) ^ W(3) ^ W(1)), 1);		/* 65 */
967 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(1) + SHA1_CONST(3);
968 	b = ROTATE_LEFT(b, 30);
969 
970 	W(2) = ROTATE_LEFT((W(15) ^ W(10) ^ W(4) ^ W(2)), 1);	/* 66 */
971 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(2) + SHA1_CONST(3);
972 	a = ROTATE_LEFT(a, 30);
973 
974 	W(3) = ROTATE_LEFT((W(0) ^ W(11) ^ W(5) ^ W(3)), 1);		/* 67 */
975 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(3) + SHA1_CONST(3);
976 	e = ROTATE_LEFT(e, 30);
977 
978 	W(4) = ROTATE_LEFT((W(1) ^ W(12) ^ W(6) ^ W(4)), 1);		/* 68 */
979 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(4) + SHA1_CONST(3);
980 	d = ROTATE_LEFT(d, 30);
981 
982 	W(5) = ROTATE_LEFT((W(2) ^ W(13) ^ W(7) ^ W(5)), 1);		/* 69 */
983 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(5) + SHA1_CONST(3);
984 	c = ROTATE_LEFT(c, 30);
985 
986 	W(6) = ROTATE_LEFT((W(3) ^ W(14) ^ W(8) ^ W(6)), 1);		/* 70 */
987 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(6) + SHA1_CONST(3);
988 	b = ROTATE_LEFT(b, 30);
989 
990 	W(7) = ROTATE_LEFT((W(4) ^ W(15) ^ W(9) ^ W(7)), 1);		/* 71 */
991 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(7) + SHA1_CONST(3);
992 	a = ROTATE_LEFT(a, 30);
993 
994 	W(8) = ROTATE_LEFT((W(5) ^ W(0) ^ W(10) ^ W(8)), 1);		/* 72 */
995 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(8) + SHA1_CONST(3);
996 	e = ROTATE_LEFT(e, 30);
997 
998 	W(9) = ROTATE_LEFT((W(6) ^ W(1) ^ W(11) ^ W(9)), 1);		/* 73 */
999 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(9) + SHA1_CONST(3);
1000 	d = ROTATE_LEFT(d, 30);
1001 
1002 	W(10) = ROTATE_LEFT((W(7) ^ W(2) ^ W(12) ^ W(10)), 1);	/* 74 */
1003 	a = ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(10) + SHA1_CONST(3);
1004 	c = ROTATE_LEFT(c, 30);
1005 
1006 	W(11) = ROTATE_LEFT((W(8) ^ W(3) ^ W(13) ^ W(11)), 1);	/* 75 */
1007 	e = ROTATE_LEFT(a, 5) + G(b, c, d) + e + W(11) + SHA1_CONST(3);
1008 	b = ROTATE_LEFT(b, 30);
1009 
1010 	W(12) = ROTATE_LEFT((W(9) ^ W(4) ^ W(14) ^ W(12)), 1);	/* 76 */
1011 	d = ROTATE_LEFT(e, 5) + G(a, b, c) + d + W(12) + SHA1_CONST(3);
1012 	a = ROTATE_LEFT(a, 30);
1013 
1014 	W(13) = ROTATE_LEFT((W(10) ^ W(5) ^ W(15) ^ W(13)), 1);	/* 77 */
1015 	c = ROTATE_LEFT(d, 5) + G(e, a, b) + c + W(13) + SHA1_CONST(3);
1016 	e = ROTATE_LEFT(e, 30);
1017 
1018 	W(14) = ROTATE_LEFT((W(11) ^ W(6) ^ W(0) ^ W(14)), 1);	/* 78 */
1019 	b = ROTATE_LEFT(c, 5) + G(d, e, a) + b + W(14) + SHA1_CONST(3);
1020 	d = ROTATE_LEFT(d, 30);
1021 
1022 	W(15) = ROTATE_LEFT((W(12) ^ W(7) ^ W(1) ^ W(15)), 1);	/* 79 */
1023 
1024 	ctx->state[0] += ROTATE_LEFT(b, 5) + G(c, d, e) + a + W(15) +
1025 	    SHA1_CONST(3);
1026 	ctx->state[1] += b;
1027 	ctx->state[2] += ROTATE_LEFT(c, 30);
1028 	ctx->state[3] += d;
1029 	ctx->state[4] += e;
1030 
1031 	/* zeroize sensitive information */
1032 	W(0) = W(1) = W(2) = W(3) = W(4) = W(5) = W(6) = W(7) = W(8) = 0;
1033 	W(9) = W(10) = W(11) = W(12) = W(13) = W(14) = W(15) = 0;
1034 }
1035 #endif	/* !__amd64 */
1036 
1037 
1038 /*
1039  * Encode()
1040  *
1041  * purpose: to convert a list of numbers from little endian to big endian
1042  *   input: uint8_t *	: place to store the converted big endian numbers
1043  *	    uint32_t *	: place to get numbers to convert from
1044  *          size_t	: the length of the input in bytes
1045  *  output: void
1046  */
1047 
1048 static void
1049 Encode(uint8_t *_RESTRICT_KYWD output, const uint32_t *_RESTRICT_KYWD input,
1050     size_t len)
1051 {
1052 	size_t		i, j;
1053 
1054 #if	defined(__sparc)
1055 	if (IS_P2ALIGNED(output, sizeof (uint32_t))) {
1056 		for (i = 0, j = 0; j < len; i++, j += 4) {
1057 			/* LINTED E_BAD_PTR_CAST_ALIGN */
1058 			*((uint32_t *)(output + j)) = input[i];
1059 		}
1060 	} else {
1061 #endif	/* little endian -- will work on big endian, but slowly */
1062 		for (i = 0, j = 0; j < len; i++, j += 4) {
1063 			output[j]	= (input[i] >> 24) & 0xff;
1064 			output[j + 1]	= (input[i] >> 16) & 0xff;
1065 			output[j + 2]	= (input[i] >>  8) & 0xff;
1066 			output[j + 3]	= input[i] & 0xff;
1067 		}
1068 #if	defined(__sparc)
1069 	}
1070 #endif
1071 }
1072