--- old/usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ikeadm.c	Wed Aug 27 14:22:08 2008
+++ new/usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ikeadm.c	Wed Aug 27 14:22:07 2008
@@ -22,8 +22,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <unistd.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -376,19 +374,19 @@
 				{"rule",	IKE_SVC_GET_RULE},
 				{"preshared",	IKE_SVC_GET_PS},
 				{"defaults",	IKE_SVC_GET_DEFS},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"set", IKE_SVC_ERROR, {
 				{"debug",	IKE_SVC_SET_DBG},
 				{"priv",	IKE_SVC_SET_PRIV},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"add", IKE_SVC_ERROR, {
 				{"rule",	IKE_SVC_NEW_RULE},
 				{"preshared",	IKE_SVC_NEW_PS},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"del", IKE_SVC_ERROR, {
@@ -395,7 +393,7 @@
 				{"p1",		IKE_SVC_DEL_P1},
 				{"rule",	IKE_SVC_DEL_RULE},
 				{"preshared",	IKE_SVC_DEL_PS},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"dump", IKE_SVC_ERROR, {
@@ -402,24 +400,24 @@
 				{"p1",		IKE_SVC_DUMP_P1S},
 				{"rule",	IKE_SVC_DUMP_RULES},
 				{"preshared",	IKE_SVC_DUMP_PS},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"flush", IKE_SVC_ERROR, {
 				{"p1",		IKE_SVC_FLUSH_P1S},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"read", IKE_SVC_ERROR, {
 				{"rule",	IKE_SVC_READ_RULES},
 				{"preshared",	IKE_SVC_READ_PS},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"write", IKE_SVC_ERROR, {
 				{"rule",	IKE_SVC_WRITE_RULES},
 				{"preshared",	IKE_SVC_WRITE_PS},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"help", IKEADM_HELP_GENERAL, {
@@ -432,26 +430,26 @@
 				{"read",	IKEADM_HELP_READ},
 				{"write",	IKEADM_HELP_WRITE},
 				{"help",	IKEADM_HELP_HELP},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"exit", IKEADM_EXIT, {
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"quit", IKEADM_EXIT, {
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{"dbg", IKE_SVC_ERROR, {
 				{"rbdump",	IKE_SVC_DBG_RBDUMP},
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
 		},
 		{NULL,	IKE_SVC_ERROR, {
-				{NULL,		IKE_SVC_ERROR},
+				{NULL,		IKE_SVC_ERROR}
 			}
-		},
+		}
 	};
 	struct cmdtbl	*ct = table;
 	struct objtbl	*ot;
@@ -1138,17 +1136,6 @@
 	return (-1);
 }
 
-/* stolen from libdhcputil (dhcp_inittab.c) */
-static uint64_t
-ike_ntohll(uint64_t nll)
-{
-#ifdef	_LITTLE_ENDIAN
-	return ((uint64_t)ntohl(nll & 0xffffffff) << 32 | ntohl(nll >> 32));
-#else
-	return (nll);
-#endif
-}
-
 /*
  * Printing functions
  *
@@ -1158,11 +1145,10 @@
  * the ipsec_util.c functions actually print the string to the file named
  * in the second arg to the function (and are named dump_foo).
  *
- * The reason for this is that in the context of the ikeadm output, it
- * seemed like the localization of the text would be more straightforward
- * (and could more easily accomodate non-english grammar!) if more complete
- * phrases were being translated, rather than a bit of a phrase followed by
- * a call to dump_foo() followed by more of the phrase.
+ * Localization for ikeadm seems more straightforward when complete
+ * phrases are translated rather than: a part of a phrase, a call to
+ * dump_foo(), and more of the phrase.  It could also accommodate
+ * non-English grammar more easily.
  */
 
 static char *
@@ -1393,8 +1379,8 @@
 {
 	(void) printf(
 	    gettext("%s Cookies: Initiator 0x%llx  Responder 0x%llx\n"),
-	    prefix, ike_ntohll(hdrp->p1hdr_cookies.cky_i),
-	    ike_ntohll(hdrp->p1hdr_cookies.cky_r));
+	    prefix, ntohll(hdrp->p1hdr_cookies.cky_i),
+	    ntohll(hdrp->p1hdr_cookies.cky_r));
 	(void) printf(gettext("%s The local host is the %s.\n"), prefix,
 	    hdrp->p1hdr_isinit ? gettext("initiator") : gettext("responder"));
 	(void) printf(gettext("%s ISAKMP version %d.%d; %s exchange\n"), prefix,
--- old/usr/src/cmd/iscsi/iscsitgtd/t10_spc.h	Wed Aug 27 14:22:13 2008
+++ new/usr/src/cmd/iscsi/iscsitgtd/t10_spc.h	Wed Aug 27 14:22:12 2008
@@ -27,8 +27,6 @@
 #ifndef _T10_SPC_H
 #define	_T10_SPC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -46,6 +44,8 @@
 #define	FIXED_SENSE_ADDL_INFO_LEN 0xFFFFFFFF
 #define	INFORMATION_SENSE_DESCR sizeof (struct scsi_information_sense_descr)
 
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <sys/scsi/generic/inquiry.h>
 #include <sys/scsi/generic/mode.h>
 
@@ -84,15 +84,6 @@
 #define	SPC_SENSE_FM	0x02
 #define	SPC_SENSE_ILI	0x04
 
-#ifdef _BIG_ENDIAN
-#define	htonll(x)   (x)
-#define	ntohll(x)   (x)
-#else
-#define	htonll(x)   ((((unsigned long long)htonl(x & 0xffffffff)) << 32) + \
-		    htonl(x >> 32))
-#define	ntohll(x)   ((((unsigned long long)ntohl(x)) << 32) + ntohl(x >> 32))
-#endif
-
 /*
  * []------------------------------------------------------------------[]
  * | SPC-3, revision 21c -- ASC/ASCQ values				|
--- old/usr/src/common/crypto/aes/aes_impl.c	Wed Aug 27 14:22:18 2008
+++ new/usr/src/common/crypto/aes/aes_impl.c	Wed Aug 27 14:22:17 2008
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/ddi.h>
@@ -1490,10 +1488,7 @@
 
 #else	/* byte swap */
 	for (i = 0, j = 0; j < keysize; i++, j += 4) {
-		keyarr.ka32[i] = (((uint32_t)cipherKey[j] << 24) |
-		    ((uint32_t)cipherKey[j + 1] << 16) |
-		    ((uint32_t)cipherKey[j + 2] << 8) |
-		    (uint32_t)cipherKey[j + 3]);
+		keyarr.ka32[i] = htonl(*(uint32_t *)&cipherKey[j]);
 	}
 #endif
 
@@ -1530,15 +1525,10 @@
 		bcopy(pt, &buffer, AES_BLOCK_LEN);
 
 #else	/* byte swap */
-		buffer[0] = (((uint32_t)pt[0] << 24) | ((uint32_t)pt[1] << 16) |
-		    ((uint32_t)pt[2] << 8) | (uint32_t)pt[3]);
-		buffer[1] = (((uint32_t)pt[4] << 24) | ((uint32_t)pt[5] << 16) |
-		    ((uint32_t)pt[6] << 8) | (uint32_t)pt[7]);
-		buffer[2] = (((uint32_t)pt[8] << 24) | ((uint32_t)pt[9] << 16) |
-		    ((uint32_t)pt[10] << 8) | (uint32_t)pt[11]);
-		buffer[3] = (((uint32_t)pt[12] << 24) |
-		    ((uint32_t)pt[13] << 16) | ((uint32_t)pt[14] << 8) |
-		    (uint32_t)pt[15]);
+		buffer[0] = htonl(*(uint32_t *)&pt[0]);
+		buffer[1] = htonl(*(uint32_t *)&pt[4]);
+		buffer[2] = htonl(*(uint32_t *)&pt[8]);
+		buffer[3] = htonl(*(uint32_t *)&pt[12]);
 #endif
 
 		AES_ENCRYPT_IMPL(&ksch->encr_ks.ks32[0], ksch->nr,
@@ -1550,22 +1540,10 @@
 	}
 
 #else	/* byte swap */
-		ct[0] = buffer[0] >> 24;
-		ct[1] = buffer[0] >> 16;
-		ct[2] = buffer[0] >> 8;
-		ct[3] = (uint8_t)buffer[0];
-		ct[4] = buffer[1] >> 24;
-		ct[5] = buffer[1] >> 16;
-		ct[6] = buffer[1] >> 8;
-		ct[7] = (uint8_t)buffer[1];
-		ct[8] = buffer[2] >> 24;
-		ct[9] = buffer[2] >> 16;
-		ct[10] = buffer[2] >> 8;
-		ct[11] = (uint8_t)buffer[2];
-		ct[12] = buffer[3] >> 24;
-		ct[13] = buffer[3] >> 16;
-		ct[14] = buffer[3] >> 8;
-		ct[15] = (uint8_t)buffer[3];
+		*(uint32_t *)&ct[0] = htonl(buffer[0]);
+		*(uint32_t *)&ct[4] = htonl(buffer[1]);
+		*(uint32_t *)&ct[8] = htonl(buffer[2]);
+		*(uint32_t *)&ct[12] = htonl(buffer[3]);
 #endif
 /* EXPORT DELETE END */
 	return (CRYPTO_SUCCESS);
@@ -1600,18 +1578,10 @@
 		bcopy(ct, &buffer, AES_BLOCK_LEN);
 
 #else	/* byte swap */
-		buffer[0] = (((uint32_t)ct[0] << 24) | ((uint32_t)ct[1] << 16) |
-		    ((uint32_t)ct[2] << 8) | (uint32_t)ct[3]);
-
-		buffer[1] = (((uint32_t)ct[4] << 24) | ((uint32_t)ct[5] << 16) |
-		    ((uint32_t)ct[6] << 8) | (uint32_t)ct[7]);
-
-		buffer[2] = (((uint32_t)ct[8] << 24) | ((uint32_t)ct[9] << 16) |
-		    ((uint32_t)ct[10] << 8) | (uint32_t)ct[11]);
-
-		buffer[3] = (((uint32_t)ct[12] << 24) |
-		    ((uint32_t)ct[13] << 16) | ((uint32_t)ct[14] << 8) |
-		    (uint32_t)ct[15]);
+		buffer[0] = htonl(*(uint32_t *)&ct[0]);
+		buffer[1] = htonl(*(uint32_t *)&ct[4]);
+		buffer[2] = htonl(*(uint32_t *)&ct[8]);
+		buffer[3] = htonl(*(uint32_t *)&ct[12]);
 #endif
 
 		AES_DECRYPT_IMPL(&ksch->decr_ks.ks32[0], ksch->nr,
@@ -1623,22 +1593,10 @@
 	}
 
 #else	/* byte swap */
-		pt[0] = buffer[0] >> 24;
-		pt[1] = buffer[0] >> 16;
-		pt[2] = buffer[0] >> 8;
-		pt[3] = (uint8_t)buffer[0];
-		pt[4] = buffer[1] >> 24;
-		pt[5] = buffer[1] >> 16;
-		pt[6] = buffer[1] >> 8;
-		pt[7] = (uint8_t)buffer[1];
-		pt[8] = buffer[2] >> 24;
-		pt[9] = buffer[2] >> 16;
-		pt[10] = buffer[2] >> 8;
-		pt[11] = (uint8_t)buffer[2];
-		pt[12] = buffer[3] >> 24;
-		pt[13] = buffer[3] >> 16;
-		pt[14] = buffer[3] >> 8;
-		pt[15] = (uint8_t)buffer[3];
+	*(uint32_t *)&pt[0] = htonl(buffer[0]);
+	*(uint32_t *)&pt[4] = htonl(buffer[1]);
+	*(uint32_t *)&pt[8] = htonl(buffer[2]);
+	*(uint32_t *)&pt[12] = htonl(buffer[3]);
 #endif
 
 /* EXPORT DELETE END */
--- old/usr/src/common/crypto/aes/amd64/aesopt.h	Wed Aug 27 14:22:23 2008
+++ new/usr/src/common/crypto/aes/amd64/aesopt.h	Wed Aug 27 14:22:22 2008
@@ -54,7 +54,8 @@
  *    from brg_endian.h
  * 5. Undefined VIA_ACE_POSSIBLE and ASSUME_VIA_ACE_PRESENT
  * 6. Changed uint_8t and uint_32t to uint8_t and uint32_t
- * 7. cstyled and hdrchk code
+ * 7. Defined aes_sw32 as htonl() for byte swapping
+ * 8. Cstyled and hdrchk code
  *
  */
 
@@ -61,13 +62,12 @@
 #ifndef _AESOPT_H
 #define	_AESOPT_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
 
 #include <sys/types.h>
+#include <sys/byteorder.h>
 #include <aes_impl.h>
 
 /*  SUPPORT FEATURES */
@@ -521,17 +521,20 @@
 #define	DEC_UNROLL  NONE
 #endif
 
-#if defined(bswap32)
+#if (ALGORITHM_BYTE_ORDER == IS_LITTLE_ENDIAN)
+#define	aes_sw32	htonl
+#elif defined(bswap32)
 #define	aes_sw32	bswap32
 #elif defined(bswap_32)
 #define	aes_sw32	bswap_32
 #else
-#define	brot(x, n)   (((uint32_t)(x) <<  n) | ((uint32_t)(x) >> (32 - n)))
+#define	brot(x, n)  (((uint32_t)(x) << (n)) | ((uint32_t)(x) >> (32 - (n))))
 #define	aes_sw32(x) ((brot((x), 8) & 0x00ff00ff) | (brot((x), 24) & 0xff00ff00))
 #endif
 
+
 /*
- *  upr(x, n):  rotates bytes within words by n positions, moving bytes to
+ *	upr(x, n):  rotates bytes within words by n positions, moving bytes to
  *		higher index positions with wrap around into low positions
  *	ups(x, n):  moves bytes by n positions to higher index positions in
  *		words but without wrap around
--- old/usr/src/common/crypto/blowfish/blowfish_impl.c	Wed Aug 27 14:22:28 2008
+++ new/usr/src/common/crypto/blowfish/blowfish_impl.c	Wed Aug 27 14:22:27 2008
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Blowfish encryption/decryption and keyschedule code.
  */
@@ -50,9 +48,13 @@
 #include <strings.h>
 #include <stdlib.h>
 #define	BLOWFISH_ASSERT(x)
-
 #endif /* _KERNEL */
 
+#if defined(__i386) || defined(__amd64)
+#include <sys/byteorder.h>
+#define	UNALIGNED_POINTERS_PERMITTED
+#endif
+
 /* EXPORT DELETE START */
 
 /*
@@ -390,11 +392,16 @@
 		b32 = (uint32_t *)block;
 		left = b32[0];
 		right = b32[1];
-	} else {
+	} else
 #endif
+	{
 	/*
 	 * Read input block and place in left/right in big-endian order.
 	 */
+#ifdef UNALIGNED_POINTERS_PERMITTED
+	left = htonl(*(uint32_t *)&block[0]);
+	right = htonl(*(uint32_t *)&block[4]);
+#else
 	left = ((uint32_t)block[0] << 24)
 	    | ((uint32_t)block[1] << 16)
 	    | ((uint32_t)block[2] << 8)
@@ -403,9 +410,8 @@
 	    | ((uint32_t)block[5] << 16)
 	    | ((uint32_t)block[6] << 8)
 	    | (uint32_t)block[7];
-#ifdef _BIG_ENDIAN
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
-#endif
 
 	ROUND(left, right, 0);
 	ROUND(left, right, 1);
@@ -436,20 +442,24 @@
 		b32 = (uint32_t *)out_block;
 		b32[0] = left;
 		b32[1] = right;
-	} else {
+	} else
 #endif
-	/* Put the block back into the user's block with final swap */
-	out_block[0] = left >> 24;
-	out_block[1] = left >> 16;
-	out_block[2] = left >> 8;
-	out_block[3] = left;
-	out_block[4] = right >> 24;
-	out_block[5] = right >> 16;
-	out_block[6] = right >> 8;
-	out_block[7] = right;
-#ifdef _BIG_ENDIAN
+	{
+		/* Put the block back into the user's block with final swap */
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		*(uint32_t *)&out_block[0] = htonl(left);
+		*(uint32_t *)&out_block[4] = htonl(right);
+#else
+		out_block[0] = left >> 24;
+		out_block[1] = left >> 16;
+		out_block[2] = left >> 8;
+		out_block[3] = left;
+		out_block[4] = right >> 24;
+		out_block[5] = right >> 16;
+		out_block[6] = right >> 8;
+		out_block[7] = right;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
-#endif
 /* EXPORT DELETE END */
 	return (CRYPTO_SUCCESS);
 }
@@ -479,11 +489,16 @@
 		b32 = (uint32_t *)block;
 		left = b32[0];
 		right = b32[1];
-	} else {
+	} else
 #endif
+	{
 	/*
 	 * Read input block and place in left/right in big-endian order.
 	 */
+#ifdef UNALIGNED_POINTERS_PERMITTED
+	left = htonl(*(uint32_t *)&block[0]);
+	right = htonl(*(uint32_t *)&block[4]);
+#else
 	left = ((uint32_t)block[0] << 24)
 	    | ((uint32_t)block[1] << 16)
 	    | ((uint32_t)block[2] << 8)
@@ -492,9 +507,8 @@
 	    | ((uint32_t)block[5] << 16)
 	    | ((uint32_t)block[6] << 8)
 	    | (uint32_t)block[7];
-#ifdef _BIG_ENDIAN
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
-#endif
 
 	ROUND(left, right, 17);
 	ROUND(left, right, 16);
@@ -525,20 +539,24 @@
 		b32 = (uint32_t *)out_block;
 		b32[0] = left;
 		b32[1] = right;
-	} else {
+	} else
 #endif
+	{
 	/* Put the block back into the user's block with final swap */
-	out_block[0] = left >> 24;
-	out_block[1] = left >> 16;
-	out_block[2] = left >> 8;
-	out_block[3] = left;
-	out_block[4] = right >> 24;
-	out_block[5] = right >> 16;
-	out_block[6] = right >> 8;
-	out_block[7] = right;
-#ifdef _BIG_ENDIAN
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		*(uint32_t *)&out_block[0] = htonl(left);
+		*(uint32_t *)&out_block[4] = htonl(right);
+#else
+		out_block[0] = left >> 24;
+		out_block[1] = left >> 16;
+		out_block[2] = left >> 8;
+		out_block[3] = left;
+		out_block[4] = right >> 24;
+		out_block[5] = right >> 16;
+		out_block[6] = right >> 8;
+		out_block[7] = right;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
-#endif
 /* EXPORT DELETE END */
 	return (CRYPTO_SUCCESS);
 }
--- old/usr/src/common/crypto/des/des_impl.c	Wed Aug 27 14:22:33 2008
+++ new/usr/src/common/crypto/des/des_impl.c	Wed Aug 27 14:22:32 2008
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/ddi.h>
@@ -39,6 +37,11 @@
 #include <stdlib.h>
 #endif	/* !_KERNEL */
 
+#if defined(__i386) || defined(__amd64)
+#include <sys/byteorder.h>
+#define	UNALIGNED_POINTERS_PERMITTED
+#endif
+
 /* EXPORT DELETE START */
 
 typedef struct keysched_s {
@@ -518,23 +521,26 @@
 		if (decrypt == B_TRUE)
 			/* LINTED */
 			*(uint64_t *)out_block = des_crypt_impl(
-			    ksch->ksch_decrypt,
-			    /* LINTED */
+			    ksch->ksch_decrypt, /* LINTED */
 			    *(uint64_t *)block, 3);
 		else
 			/* LINTED */
 			*(uint64_t *)out_block = des_crypt_impl(
-			    ksch->ksch_encrypt,
-			    /* LINTED */
+			    ksch->ksch_encrypt, /* LINTED */
 			    *(uint64_t *)block, 3);
-	} else {
-#endif
+	} else
+#endif	/* _BIG_ENDIAN */
+	{
 		uint64_t tmp;
 
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		tmp = htonll(*(uint64_t *)&block[0]);
+#else
 		tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
 		    ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
 		    ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
 		    ((uint64_t)block[6] << 8) | (uint64_t)block[7]);
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
 		if (decrypt == B_TRUE)
 			tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 3);
@@ -541,6 +547,9 @@
 		else
 			tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 3);
 
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		*(uint64_t *)&out_block[0] = htonll(tmp);
+#else
 		out_block[0] = tmp >> 56;
 		out_block[1] = tmp >> 48;
 		out_block[2] = tmp >> 40;
@@ -549,9 +558,8 @@
 		out_block[5] = tmp >> 16;
 		out_block[6] = tmp >> 8;
 		out_block[7] = (uint8_t)tmp;
-#ifdef _BIG_ENDIAN
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
-#endif
 /* EXPORT DELETE END */
 	return (CRYPTO_SUCCESS);
 }
@@ -574,30 +582,37 @@
 		if (decrypt == B_TRUE)
 			/* LINTED */
 			*(uint64_t *)out_block = des_crypt_impl(
-			    ksch->ksch_decrypt,
-			    /* LINTED */
+			    ksch->ksch_decrypt, /* LINTED */
 			    *(uint64_t *)block, 1);
 		else
 			/* LINTED */
 			*(uint64_t *)out_block = des_crypt_impl(
-			    ksch->ksch_encrypt,
-			    /* LINTED */
+			    ksch->ksch_encrypt, /* LINTED */
 			    *(uint64_t *)block, 1);
 
-	} else {
-#endif
+	} else
+#endif	/* _BIG_ENDIAN */
+	{
 		uint64_t tmp;
 
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		tmp = htonll(*(uint64_t *)&block[0]);
+#else
 		tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
 		    ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
 		    ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
 		    ((uint64_t)block[6] << 8) | (uint64_t)block[7]);
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
+
 		if (decrypt == B_TRUE)
 			tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 1);
 		else
 			tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 1);
 
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		*(uint64_t *)&out_block[0] = htonll(tmp);
+#else
 		out_block[0] = tmp >> 56;
 		out_block[1] = tmp >> 48;
 		out_block[2] = tmp >> 40;
@@ -606,9 +621,8 @@
 		out_block[5] = tmp >> 16;
 		out_block[6] = tmp >> 8;
 		out_block[7] = (uint8_t)tmp;
-#ifdef _BIG_ENDIAN
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
-#endif
 /* EXPORT DELETE END */
 	return (CRYPTO_SUCCESS);
 }
@@ -650,7 +664,7 @@
 		0x1ffe1ffe0efe0efeULL,	0xfe1ffe1ffe0efe0eULL,
 		0x011f011f010e010eULL,	0x1f011f010e010e01ULL,
 		0xe0fee0fef1fef1feULL,	0xfee0fee0fef1fef1ULL,
-#endif
+#endif	/* _LITTLE_ENDIAN */
 
 		/* We'll save the other possibly-weak keys for the future. */
 	};
@@ -658,6 +672,9 @@
 	if (key == NULL)
 		return (B_FALSE);
 
+#ifdef UNALIGNED_POINTERS_PERMITTED
+	key_so_far = htonll(*(uint64_t *)&key[0]);
+#else
 	/*
 	 * The code below reverses the bytes on LITTLE_ENDIAN machines.
 	 * On BIG_ENDIAN, the same code copies without reversing
@@ -667,6 +684,7 @@
 	    ((uint64_t)key[2] << 40) | ((uint64_t)key[3] << 32) |
 	    ((uint64_t)key[4] << 24) | ((uint64_t)key[5] << 16) |
 	    ((uint64_t)key[6] << 8) | (uint64_t)key[7]);
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
 	/*
 	 * Fix parity.
@@ -680,6 +698,9 @@
 		}
 
 	if (corrected_key != NULL) {
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		*(uint64_t *)&corrected_key[0] = htonll(key_so_far);
+#else
 		/*
 		 * The code below reverses the bytes on LITTLE_ENDIAN machines.
 		 * On BIG_ENDIAN, the same code copies without reversing
@@ -693,6 +714,7 @@
 		corrected_key[5] = key_so_far >> 16;
 		corrected_key[6] = key_so_far >> 8;
 		corrected_key[7] = (uint8_t)key_so_far;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
 /* EXPORT DELETE END */
 	return (B_TRUE);
@@ -743,7 +765,7 @@
 	/*
 	 * Perform key equivalence checks, now that parity is properly set.
 	 * 1st and 2nd keys must be unique, the 3rd key can be the same as
-	 * the 1st key for the 2 key varient of 3DES.
+	 * the 1st key for the 2 key variant of 3DES.
 	 */
 	if (currentkey[0] == currentkey[1] || currentkey[1] == currentkey[2])
 		return (B_FALSE);
@@ -785,6 +807,9 @@
 	paritied_key = (uint8_t *)aligned_key;
 	while (strength > i) {
 		offset = 8 * i;
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		key_so_far = htonll(*(uint64_t *)&paritied_key[offset]);
+#else
 		key_so_far = (((uint64_t)paritied_key[offset + 0] << 56) |
 		    ((uint64_t)paritied_key[offset + 1] << 48) |
 		    ((uint64_t)paritied_key[offset + 2] << 40) |
@@ -793,9 +818,13 @@
 		    ((uint64_t)paritied_key[offset + 5] << 16) |
 		    ((uint64_t)paritied_key[offset + 6] << 8) |
 		    (uint64_t)paritied_key[offset + 7]);
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
 		fix_des_parity(&key_so_far);
 
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		*(uint64_t *)&paritied_key[offset] = htonll(key_so_far);
+#else
 		paritied_key[offset + 0] = key_so_far >> 56;
 		paritied_key[offset + 1] = key_so_far >> 48;
 		paritied_key[offset + 2] = key_so_far >> 40;
@@ -804,6 +833,7 @@
 		paritied_key[offset + 5] = key_so_far >> 16;
 		paritied_key[offset + 6] = key_so_far >> 8;
 		paritied_key[offset + 7] = (uint8_t)key_so_far;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
 		i++;
 	}
@@ -855,10 +885,13 @@
 			/* LINTED: pointer alignment */
 			key_uint64[i] = *((uint64_t *)&cipherKey[j]);
 		}
-	} else {
-#endif
+	} else
+#endif	/* _BIG_ENDIAN */
 	{
 		for (i = 0, j = 0; j < keysize; i++, j += 8) {
+#ifdef UNALIGNED_POINTERS_PERMITTED
+			key_uint64[i] = htonll(*(uint64_t *)&cipherKey[j]);
+#else
 			key_uint64[i] = (((uint64_t)cipherKey[j] << 56) |
 			    ((uint64_t)cipherKey[j + 1] << 48) |
 			    ((uint64_t)cipherKey[j + 2] << 40) |
@@ -867,11 +900,9 @@
 			    ((uint64_t)cipherKey[j + 5] << 16) |
 			    ((uint64_t)cipherKey[j + 6] << 8) |
 			    (uint64_t)cipherKey[j + 7]);
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 		}
 	}
-#ifdef _BIG_ENDIAN
-	}
-#endif
 
 	switch (strength) {
 	case DES:
@@ -951,7 +982,7 @@
 /*
  * Replace the LSB of each byte by the xor of the other
  * 7 bits.  The tricky thing is that the original contents of the LSBs
- * are nullifed by including them twice in the xor computation.
+ * are nullified by including them twice in the xor computation.
  */
 static void
 fix_des_parity(uint64_t *keyp)
@@ -988,11 +1019,11 @@
 	    IS_P2ALIGNED(data, sizeof (uint32_t))) {
 		/* LINTED: pointer alignment */
 		*(uint32_t *)&dst[0] ^=
-		/* LINTED: pointer alignment */
+		    /* LINTED: pointer alignment */
 		    *(uint32_t *)&data[0];
-		/* LINTED: pointer alignment */
+		    /* LINTED: pointer alignment */
 		*(uint32_t *)&dst[4] ^=
-		/* LINTED: pointer alignment */
+		    /* LINTED: pointer alignment */
 		    *(uint32_t *)&data[4];
 	} else {
 		DES_XOR_BLOCK(data, dst);
--- old/usr/src/common/crypto/md4/md4.c	Wed Aug 27 14:22:38 2008
+++ new/usr/src/common/crypto/md4/md4.c	Wed Aug 27 14:22:37 2008
@@ -1,10 +1,8 @@
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
  */
@@ -38,6 +36,10 @@
 #include <strings.h>
 #endif /* _KERNEL */
 
+#if defined(__i386) || defined(__amd64)
+#define	UNALIGNED_POINTERS_PERMITTED
+#endif
+
 #include <sys/md4.h>
 
 /*
@@ -262,18 +264,20 @@
  * a multiple of 4.
  */
 static void
-Encode(output, input, len)
-	unsigned char *output;
-	uint32_t *input;
-	unsigned int len;
+Encode(unsigned char *output, uint32_t *input, unsigned int len)
 {
 	unsigned int i, j;
 
 	for (i = 0, j = 0; j < len; i++, j += 4) {
+#if defined(_LITTLE_ENDIAN) && defined(UNALIGNED_POINTERS_PERMITTED)
+		*(uint32_t *)&output[j] = input[i];
+#else
+		/* endian-independent code */
 		output[j] = (unsigned char)(input[i] & 0xff);
 		output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
 		output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
 		output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+#endif	/* _LITTLE_ENDIAN && UNALIGNED_POINTERS_PERMITTED */
 	}
 }
 
@@ -282,16 +286,20 @@
  * a multiple of 4.
  */
 static void
-Decode(output, input, len)
-	uint32_t *output;
-	unsigned char *input;
-	unsigned int len;
+Decode(uint32_t *output, unsigned char *input, unsigned int len)
 {
 	unsigned int i, j;
 
-	for (i = 0, j = 0; j < len; i++, j += 4)
+	for (i = 0, j = 0; j < len; i++, j += 4) {
+#if defined(_LITTLE_ENDIAN) && defined(UNALIGNED_POINTERS_PERMITTED)
+		output[i] = *(uint32_t *)&input[j];
+#else
+		/* endian-independent code */
 		output[i] = ((uint32_t)input[j]) |
-			(((uint32_t)input[j+1]) << 8) |
-			(((uint32_t)input[j+2]) << 16) |
-			(((uint32_t)input[j+3]) << 24);
+		    (((uint32_t)input[j+1]) << 8) |
+		    (((uint32_t)input[j+2]) << 16) |
+		    (((uint32_t)input[j+3]) << 24);
+#endif	/* _LITTLE_ENDIAN && UNALIGNED_POINTERS_PERMITTED */
+	}
+
 }
--- old/usr/src/common/crypto/md5/md5_byteswap.h	Wed Aug 27 14:22:43 2008
+++ new/usr/src/common/crypto/md5/md5_byteswap.h	Wed Aug 27 14:22:42 2008
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -27,8 +27,6 @@
 #ifndef	_MD5_BYTESWAP_H
 #define	_MD5_BYTESWAP_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * definitions for inline functions for little-endian loads.
  *
@@ -40,8 +38,11 @@
  * same thing and must be changed together.
  */
 
+#include <sys/types.h>
 #if defined(__sparc)
 #include <v9/sys/asi.h>
+#elif defined(_LITTLE_ENDIAN)
+#include <sys/byteorder.h>
 #endif
 
 #ifdef	__cplusplus
@@ -95,25 +96,11 @@
 
 	__asm__(
 	    "lduwa	[%1] %2, %0\n\t"
-	: "=r" (value)
-	: "r" (addr), "i" (ASI_PL));
+	    : "=r" (value)
+	    : "r" (addr), "i" (ASI_PL));
 
 	return (value);
 }
-
-static __inline__ uint16_t
-load_little_16(uint16_t *addr)
-{
-	uint16_t value;
-
-	__asm__(
-	    "lduha	[%1] %2, %0\n\t"
-	: "=r" (value)
-	: "r" (addr), "i" (ASI_PL));
-
-	return (value);
-}
-
 #endif	/* !__lint && __GNUC__ */
 
 #if !defined(__GNUC__)
@@ -129,13 +116,14 @@
 }
 #endif	/* __lint */
 
-#else	/* !sun4u */
+#elif defined(_LITTLE_ENDIAN)
+#define	LOAD_LITTLE_32(addr)	htonl(addr)
 
+#else
 /* big endian -- will work on little endian, but slowly */
 /* Since we do byte operations, we don't have to check for alignment. */
 #define	LOAD_LITTLE_32(addr)	\
 	((addr)[0] | ((addr)[1] << 8) | ((addr)[2] << 16) | ((addr)[3] << 24))
-
 #endif	/* sun4u */
 
 #if defined(sun4v)
@@ -175,9 +163,9 @@
 set_little(uint8_t asi)
 {
 	__asm__ __volatile__(
-		"wr	%%g0, %0, %%asi\n\t"
-	: /* Nothing */
-	: "r" (asi));
+	    "wr	%%g0, %0, %%asi\n\t"
+	    : /* Nothing */
+	    : "r" (asi));
 }
 
 static __inline__ uint8_t
@@ -186,8 +174,8 @@
 	uint8_t asi;
 
 	__asm__ __volatile__(
-		"rd	%%asi, %0\n\t"
-	: "=r" (asi));
+	    "rd	%%asi, %0\n\t"
+	    : "=r" (asi));
 
 	return (asi);
 }
--- old/usr/src/common/crypto/modes/ccm.c	Wed Aug 27 14:22:48 2008
+++ new/usr/src/common/crypto/modes/ccm.c	Wed Aug 27 14:22:47 2008
@@ -36,6 +36,11 @@
 #include <sys/crypto/common.h>
 #include <sys/crypto/impl.h>
 
+#if defined(__i386) || defined(__amd64)
+#include <sys/byteorder.h>
+#define	UNALIGNED_POINTERS_PERMITTED
+#endif
+
 /*
  * Encrypt multiple blocks of data in CCM mode.  Decrypt for CCM mode
  * is done in another function.
@@ -59,9 +64,6 @@
 	size_t out_data_1_len;
 	uint64_t counter;
 	uint8_t *mac_buf;
-#ifdef _LITTLE_ENDIAN
-	uint8_t *p;
-#endif
 
 	if (length + ctx->ccm_remainder_len < block_size) {
 		/* accumulate bytes here and return */
@@ -114,29 +116,13 @@
 		 * Increment counter. Counter bits are confined
 		 * to the bottom 64 bits of the counter block.
 		 */
-		counter = ctx->ccm_cb[1] & ctx->ccm_counter_mask;
 #ifdef _LITTLE_ENDIAN
-		p = (uint8_t *)&counter;
-		counter = (((uint64_t)p[0] << 56) |
-		    ((uint64_t)p[1] << 48) |
-		    ((uint64_t)p[2] << 40) |
-		    ((uint64_t)p[3] << 32) |
-		    ((uint64_t)p[4] << 24) |
-		    ((uint64_t)p[5] << 16) |
-		    ((uint64_t)p[6] << 8) |
-		    (uint64_t)p[7]);
-#endif
+		counter = ntohll(ctx->ccm_cb[1] & ctx->ccm_counter_mask);
+		counter = htonll(counter + 1);
+#else
+		counter = ctx->ccm_cb[1] & ctx->ccm_counter_mask;
 		counter++;
-#ifdef _LITTLE_ENDIAN
-		counter = (((uint64_t)p[0] << 56) |
-		    ((uint64_t)p[1] << 48) |
-		    ((uint64_t)p[2] << 40) |
-		    ((uint64_t)p[3] << 32) |
-		    ((uint64_t)p[4] << 24) |
-		    ((uint64_t)p[5] << 16) |
-		    ((uint64_t)p[6] << 8) |
-		    (uint64_t)p[7]);
-#endif
+#endif	/* _LITTLE_ENDIAN */
 		counter &= ctx->ccm_counter_mask;
 		ctx->ccm_cb[1] =
 		    (ctx->ccm_cb[1] & ~(ctx->ccm_counter_mask)) | counter;
@@ -316,8 +302,7 @@
 					bcopy(ccm_mac_p, out_data_2,
 					    ctx->ccm_mac_len);
 				} else {
-					size_t len_not_used
-					    = out_data_1_len -
+					size_t len_not_used = out_data_1_len -
 					    ctx->ccm_remainder_len;
 					/*
 					 * part of mac in will be in
@@ -494,29 +479,13 @@
 		 * Increment counter.
 		 * Counter bits are confined to the bottom 64 bits
 		 */
-		counter = ctx->ccm_cb[1] & ctx->ccm_counter_mask;
 #ifdef _LITTLE_ENDIAN
-		p = (uint8_t *)&counter;
-		counter = (((uint64_t)p[0] << 56) |
-		    ((uint64_t)p[1] << 48) |
-		    ((uint64_t)p[2] << 40) |
-		    ((uint64_t)p[3] << 32) |
-		    ((uint64_t)p[4] << 24) |
-		    ((uint64_t)p[5] << 16) |
-		    ((uint64_t)p[6] << 8) |
-		    (uint64_t)p[7]);
-#endif
+		counter = ntohll(ctx->ccm_cb[1] & ctx->ccm_counter_mask);
+		counter = htonll(counter + 1);
+#else
+		counter = ctx->ccm_cb[1] & ctx->ccm_counter_mask;
 		counter++;
-#ifdef _LITTLE_ENDIAN
-		counter = (((uint64_t)p[0] << 56) |
-		    ((uint64_t)p[1] << 48) |
-		    ((uint64_t)p[2] << 40) |
-		    ((uint64_t)p[3] << 32) |
-		    ((uint64_t)p[4] << 24) |
-		    ((uint64_t)p[5] << 16) |
-		    ((uint64_t)p[6] << 8) |
-		    (uint64_t)p[7]);
-#endif
+#endif	/* _LITTLE_ENDIAN */
 		counter &= ctx->ccm_counter_mask;
 		ctx->ccm_cb[1] =
 		    (ctx->ccm_cb[1] & ~(ctx->ccm_counter_mask)) | counter;
@@ -704,9 +673,6 @@
 	int i, j, k;
 	uint64_t mask = 0;
 	uint8_t *cb;
-#ifdef _LITTLE_ENDIAN
-	uint8_t *p8;
-#endif	/* _LITTLE_ENDIAN */
 
 	q = (uint8_t)((15 - nonceSize) & 0xFF);
 	t = (uint8_t)((aes_ctx->ccm_mac_len) & 0xFF);
@@ -748,15 +714,7 @@
 	}
 
 #ifdef _LITTLE_ENDIAN
-	p8 = (uint8_t *)&mask;
-	mask = (((uint64_t)p8[0] << 56) |
-	    ((uint64_t)p8[1] << 48) |
-	    ((uint64_t)p8[2] << 40) |
-	    ((uint64_t)p8[3] << 32) |
-	    ((uint64_t)p8[4] << 24) |
-	    ((uint64_t)p8[5] << 16) |
-	    ((uint64_t)p8[6] << 8) |
-	    (uint64_t)p8[7]);
+	mask = htonll(mask);
 #endif
 	aes_ctx->ccm_counter_mask = mask;
 
@@ -777,6 +735,13 @@
 static void
 encode_adata_len(ulong_t auth_data_len, uint8_t *encoded, size_t *encoded_len)
 {
+#ifdef UNALIGNED_POINTERS_PERMITTED
+	uint32_t	*lencoded_ptr;
+#ifdef _LP64
+	uint64_t	*llencoded_ptr;
+#endif
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
+
 	if (auth_data_len < ((1ULL<<16) - (1ULL<<8))) {
 		/* 0 < a < (2^16-2^8) */
 		*encoded_len = 2;
@@ -789,10 +754,16 @@
 		*encoded_len = 6;
 		encoded[0] = 0xff;
 		encoded[1] = 0xfe;
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		lencoded_ptr = (uint32_t *)&encoded[2];
+		*lencoded_ptr = htonl(auth_data_len);
+#else
 		encoded[2] = (auth_data_len & 0xff000000) >> 24;
 		encoded[3] = (auth_data_len & 0xff0000) >> 16;
 		encoded[4] = (auth_data_len & 0xff00) >> 8;
 		encoded[5] = auth_data_len & 0xff;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
+
 #ifdef _LP64
 	} else {
 		/* 2^32 <= a < 2^64 */
@@ -799,6 +770,10 @@
 		*encoded_len = 10;
 		encoded[0] = 0xff;
 		encoded[1] = 0xff;
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		llencoded_ptr = (uint64_t *)&encoded[2];
+		*llencoded_ptr = htonl(auth_data_len);
+#else
 		encoded[2] = (auth_data_len & 0xff00000000000000) >> 56;
 		encoded[3] = (auth_data_len & 0xff000000000000) >> 48;
 		encoded[4] = (auth_data_len & 0xff0000000000) >> 40;
@@ -807,6 +782,7 @@
 		encoded[7] = (auth_data_len & 0xff0000) >> 16;
 		encoded[8] = (auth_data_len & 0xff00) >> 8;
 		encoded[9] = auth_data_len & 0xff;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 #endif	/* _LP64 */
 	}
 }
--- old/usr/src/common/crypto/modes/ctr.c	Wed Aug 27 14:22:53 2008
+++ new/usr/src/common/crypto/modes/ctr.c	Wed Aug 27 14:22:52 2008
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifndef _KERNEL
 #include <strings.h>
 #include <limits.h>
@@ -37,6 +35,10 @@
 #include <sys/crypto/common.h>
 #include <sys/crypto/impl.h>
 
+#ifdef _LITTLE_ENDIAN
+#include <sys/byteorder.h>
+#endif
+
 /*
  * Encrypt and decrypt multiple blocks of data in counter mode.
  */
@@ -101,29 +103,13 @@
 		 * Increment counter. Counter bits are confined
 		 * to the bottom 64 bits of the counter block.
 		 */
-		counter = ctx->ctr_cb[1] & ctx->ctr_counter_mask;
 #ifdef _LITTLE_ENDIAN
-		p = (uint8_t *)&counter;
-		counter = (((uint64_t)p[0] << 56) |
-		    ((uint64_t)p[1] << 48) |
-		    ((uint64_t)p[2] << 40) |
-		    ((uint64_t)p[3] << 32) |
-		    ((uint64_t)p[4] << 24) |
-		    ((uint64_t)p[5] << 16) |
-		    ((uint64_t)p[6] << 8) |
-		    (uint64_t)p[7]);
-#endif
+		counter = ntohll(ctx->ctr_cb[1] & ctx->ctr_counter_mask);
+		counter = htonll(counter + 1);
+#else
+		counter = ctx->ctr_cb[1] & ctx->ctr_counter_mask;
 		counter++;
-#ifdef _LITTLE_ENDIAN
-		counter = (((uint64_t)p[0] << 56) |
-		    ((uint64_t)p[1] << 48) |
-		    ((uint64_t)p[2] << 40) |
-		    ((uint64_t)p[3] << 32) |
-		    ((uint64_t)p[4] << 24) |
-		    ((uint64_t)p[5] << 16) |
-		    ((uint64_t)p[6] << 8) |
-		    (uint64_t)p[7]);
-#endif
+#endif	/* _LITTLE_ENDIAN */
 		counter &= ctx->ctr_counter_mask;
 		ctx->ctr_cb[1] =
 		    (ctx->ctr_cb[1] & ~(ctx->ctr_counter_mask)) | counter;
@@ -224,9 +210,6 @@
 void (*copy_block)(uint8_t *, uint8_t *))
 {
 	uint64_t mask = 0;
-#ifdef _LITTLE_ENDIAN
-	uint8_t *p8;
-#endif
 
 	if (count == 0 || count > 64) {
 		return (CRYPTO_MECHANISM_PARAM_INVALID);
@@ -233,16 +216,9 @@
 	}
 	while (count-- > 0)
 		mask |= (1ULL << count);
+
 #ifdef _LITTLE_ENDIAN
-	p8 = (uint8_t *)&mask;
-	mask = (((uint64_t)p8[0] << 56) |
-	    ((uint64_t)p8[1] << 48) |
-	    ((uint64_t)p8[2] << 40) |
-	    ((uint64_t)p8[3] << 32) |
-	    ((uint64_t)p8[4] << 24) |
-	    ((uint64_t)p8[5] << 16) |
-	    ((uint64_t)p8[6] << 8) |
-	    (uint64_t)p8[7]);
+	mask = htonll(mask);
 #endif
 	ctr_ctx->ctr_counter_mask = mask;
 	copy_block(cb, (uchar_t *)ctr_ctx->ctr_cb);
--- old/usr/src/common/crypto/sha1/sha1.c	Wed Aug 27 14:22:58 2008
+++ new/usr/src/common/crypto/sha1/sha1.c	Wed Aug 27 14:22:56 2008
@@ -3,8 +3,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * The basic framework for this code came from the reference
  * implementation for MD5.  That implementation is Copyright (C)
@@ -29,7 +27,7 @@
  * documentation and/or software.
  *
  * NOTE: Cleaned-up and optimized, version of SHA1, based on the FIPS 180-1
- * standard, available at http://www.itl.nist.gov/div897/pubs/fip180-1.htm
+ * standard, available at http://www.itl.nist.gov/fipspubs/fip180-1.htm
  * Not as fast as one would like -- further optimizations are encouraged
  * and appreciated.
  */
@@ -48,6 +46,11 @@
 #include <sys/systeminfo.h>
 #endif  /* !_KERNEL */
 
+#ifdef _LITTLE_ENDIAN
+#include <sys/byteorder.h>
+#define	HAVE_HTONL
+#endif
+
 static void Encode(uint8_t *, const uint32_t *, size_t);
 
 #if	defined(__sparc)
@@ -106,18 +109,7 @@
 
 #endif
 
-#if	defined(__GNUC__) && (defined(__i386) || defined(__amd64))
 
-#define	HAVE_BSWAP
-
-extern __inline__ uint32_t bswap(uint32_t value)
-{
-	__asm__("bswap %0" : "+r" (value));
-	return (value);
-}
-
-#endif
-
 /*
  * SHA1Init()
  *
@@ -296,8 +288,8 @@
 				 */
 				for (; i + 63 < input_len; i += 64) {
 					SHA1TransformVIS(X0,
-					/* LINTED E_BAD_PTR_CAST_ALIGN */
-					    (uint32_t *)&input[i],
+					    /* LINTED E_BAD_PTR_CAST_ALIGN */
+					    (uint32_t *)&input[i], /* CSTYLED */
 					    &ctx->state[0], VIS);
 				}
 
@@ -455,25 +447,17 @@
  */
 
 #if	defined(_BIG_ENDIAN)
-
 #define	LOAD_BIG_32(addr)	(*(uint32_t *)(addr))
 
-#else	/* !defined(_BIG_ENDIAN) */
+#elif	defined(HAVE_HTONL)
+#define	LOAD_BIG_32(addr) htonl(*((uint32_t *)(addr)))
 
-#if	defined(HAVE_BSWAP)
-
-#define	LOAD_BIG_32(addr) bswap(*((uint32_t *)(addr)))
-
-#else	/* !defined(HAVE_BSWAP) */
-
+#else
 /* little endian -- will work on big endian, but slowly */
 #define	LOAD_BIG_32(addr)	\
 	(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
+#endif	/* _BIG_ENDIAN */
 
-#endif	/* !defined(HAVE_BSWAP) */
-
-#endif	/* !defined(_BIG_ENDIAN) */
-
 /*
  * SHA1Transform()
  */
@@ -537,7 +521,7 @@
 	 * .rodata.
 	 *
 	 * unfortunately, loading from an array in this manner hurts
-	 * performance under intel.  so, there is a macro,
+	 * performance under Intel.  So, there is a macro,
 	 * SHA1_CONST(), used in SHA1Transform(), that either expands to
 	 * a reference to this array, or to the actual constant,
 	 * depending on what platform this code is compiled for.
@@ -544,7 +528,7 @@
 	 */
 
 	static const uint32_t sha1_consts[] = {
-		SHA1_CONST_0,	SHA1_CONST_1,	SHA1_CONST_2,	SHA1_CONST_3,
+		SHA1_CONST_0, SHA1_CONST_1, SHA1_CONST_2, SHA1_CONST_3
 	};
 
 	/*
@@ -629,9 +613,10 @@
 	}
 #else	/* !defined(__sparc) */
 
-void
+void /* CSTYLED */
 SHA1Transform(SHA1_CTX *ctx, const uint8_t blk[64])
 {
+	/* CSTYLED */
 	sha1word a = ctx->state[0];
 	sha1word b = ctx->state[1];
 	sha1word c = ctx->state[2];
--- old/usr/src/common/crypto/sha2/sha2.c	Wed Aug 27 14:23:02 2008
+++ new/usr/src/common/crypto/sha2/sha2.c	Wed Aug 27 14:23:01 2008
@@ -3,8 +3,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * The basic framework for this code came from the reference
  * implementation for MD5.  That implementation is Copyright (C)
@@ -29,7 +27,8 @@
  * documentation and/or software.
  *
  * NOTE: Cleaned-up and optimized, version of SHA2, based on the FIPS 180-2
- * standard, available at http://www.itl.nist.gov/div897/pubs/fip180-2.htm
+ * standard, available at
+ * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
  * Not as fast as one would like -- further optimizations are encouraged
  * and appreciated.
  */
@@ -60,6 +59,11 @@
 
 #endif	/* _KERNEL */
 
+#ifdef _LITTLE_ENDIAN
+#include <sys/byteorder.h>
+#define	HAVE_HTONL
+#endif
+
 static void Encode(uint8_t *, uint32_t *, size_t);
 static void Encode64(uint8_t *, uint64_t *, size_t);
 
@@ -121,28 +125,23 @@
  */
 
 #if	defined(_BIG_ENDIAN)
-
 #define	LOAD_BIG_32(addr)	(*(uint32_t *)(addr))
+#define	LOAD_BIG_64(addr)	(*(uint64_t *)(addr))
 
-#else	/* little endian -- will work on big endian, but slowly */
+#elif	defined(HAVE_HTONL)
+#define	LOAD_BIG_32(addr) htonl(*((uint32_t *)(addr)))
+#define	LOAD_BIG_64(addr) htonll(*((uint64_t *)(addr)))
 
+#else
+/* little endian -- will work on big endian, but slowly */
 #define	LOAD_BIG_32(addr)	\
 	(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
-#endif
-
-
-#if	defined(_BIG_ENDIAN)
-
-#define	LOAD_BIG_64(addr)	(*(uint64_t *)(addr))
-
-#else	/* little endian -- will work on big endian, but slowly */
-
 #define	LOAD_BIG_64(addr)	\
 	(((uint64_t)(addr)[0] << 56) | ((uint64_t)(addr)[1] << 48) |	\
 	    ((uint64_t)(addr)[2] << 40) | ((uint64_t)(addr)[3] << 32) |	\
 	    ((uint64_t)(addr)[4] << 24) | ((uint64_t)(addr)[5] << 16) |	\
 	    ((uint64_t)(addr)[6] << 8) | (uint64_t)(addr)[7])
-#endif
+#endif	/* _BIG_ENDIAN */
 
 
 #if	!defined(__amd64)
@@ -715,8 +714,8 @@
 		break;
 #ifdef _KERNEL
 	default:
-		cmn_err(CE_PANIC, "sha2_init: "
-		    "failed to find a supported algorithm: 0x%x",
+		cmn_err(CE_PANIC,
+		    "sha2_init: failed to find a supported algorithm: 0x%x",
 		    (uint32_t)mech);
 
 #endif /* _KERNEL */
--- old/usr/src/lib/libc/amd64/gen/byteorder.s	Wed Aug 27 14:23:07 2008
+++ new/usr/src/lib/libc/amd64/gen/byteorder.s	Wed Aug 27 14:23:06 2008
@@ -19,28 +19,46 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 	.file	"byteorder.s"
 
-#include "SYS.h"
+#include <sys/asm_linkage.h>
 
 	/*
-	 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs.
-	 * As such, they could be implemented as a single routine, using
-	 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so
+	 * NOTE: htonll/ntohll, htonl/ntohl, and htons/ntohs are identical
+	 * routines. As such, they could be implemented as a single routine,
+	 * using multiple ALTENTRY/SET_SIZE definitions. We don't do this so
 	 * that they will have unique addresses, allowing DTrace and
-	 * other debuggers to tell them apart. 
+	 * other debuggers to tell them apart.
 	 */
 
+/*
+ *	unsigned long long htonll( hll )
+ *	unsigned long long ntohll( hll )
+ *	unsigned long long hll;
+ *	reverses the byte order of 'uint64_t hll' on little endian machines
+ */
+	ENTRY(htonll)
+	movq	%rdi, %rax	/* %rax = hll */
+	bswapq	%rax		/* reverses the byte order of %rax */
+	ret			/* return (%rax) */
+	SET_SIZE(htonll)
 
+	ENTRY(ntohll)
+	movq	%rdi, %rax	/* %rax = hll */
+	bswapq	%rax		/* reverses the byte order of %rax */
+	ret			/* return (%rax) */
+	SET_SIZE(ntohll)
+
+
 /*
  *	unsigned long htonl( hl )
  *	unsigned long ntohl( hl )
- *	long hl;
- *	reverses the byte order of 'uint32_t hl'
+ *	unsigned long hl;
+ *	reverses the byte order of 'uint32_t hl' on little endian machines
  */
 	ENTRY(htonl)
 	movl	%edi, %eax	/* %eax = hl */
@@ -56,9 +74,8 @@
 
 /*
  *	unsigned short htons( hs )
- *	short hs;
- *
- *	reverses the byte order in hs.
+ *	unsigned short hs;
+ *	reverses the byte order of 'uint16_t hs' on little endian machines.
  */
 	ENTRY(htons)
 	movl	%edi, %eax	/* %eax = hs */
--- old/usr/src/lib/libc/i386/Makefile.com	Wed Aug 27 14:23:12 2008
+++ new/usr/src/lib/libc/i386/Makefile.com	Wed Aug 27 14:23:11 2008
@@ -22,8 +22,6 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
 
 LIB_PIC= libc_pic.a
 VERS=	.1
@@ -108,6 +106,7 @@
 	abs.o			\
 	alloca.o		\
 	byteorder.o		\
+	byteorder64.o		\
 	cuexit.o		\
 	ecvt.o			\
 	errlst.o		\
@@ -970,7 +969,7 @@
 $(DYNLIB) := PICS += $(ROOTFS_LIBDIR)/libc_i18n.a
 $(DYNLIB) := BUILD.SO = $(LD) -o $@ -G $(DYNFLAGS) $(PICS) $(ALTPICS) $(LDLIBS)
 
-MAPFILES =	../port/mapfile-vers ../i386/mapfile-vers 
+MAPFILES =	../port/mapfile-vers ../i386/mapfile-vers
 
 #
 # EXTN_CPPFLAGS and EXTN_CFLAGS set in enclosing Makefile
--- /dev/null	Wed Aug 27 14:23:18 2008
+++ new/usr/src/lib/libc/i386/gen/byteorder64.c	Wed Aug 27 14:23:16 2008
@@ -0,0 +1,50 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/isa_defs.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <inttypes.h>
+
+#if (defined(_BIG_ENDIAN) || defined(_LP64)) && !defined(__lint)
+
+#error	Use ISA-dependent byteorder64.c only on a 32-bit little-endian machine.
+
+#else
+
+uint64_t
+htonll(uint64_t in)
+{
+	return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32));
+}
+
+uint64_t
+ntohll(uint64_t in)
+{
+	return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32);
+}
+
+#endif	/* (_BIG_ENDIAN) || _LP64) && !__lint */
--- old/usr/src/lib/libc/port/mapfile-vers	Wed Aug 27 14:23:21 2008
+++ new/usr/src/lib/libc/port/mapfile-vers	Wed Aug 27 14:23:19 2008
@@ -22,8 +22,6 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
 
 #
 # All function names added to this or any other libc mapfile
@@ -81,6 +79,7 @@
 	getattrat;
 	getpagesizes2;
 	htonl;
+	htonll;
 	htons;
 	lio_listio;
 	mkdtemp;
@@ -99,6 +98,7 @@
 	mq_unlink;
 	nanosleep;
 	ntohl;
+	ntohll;
 	ntohs;
 	posix_fadvise;
 	posix_fallocate;
@@ -1042,7 +1042,7 @@
 	iconv_close;
 	iconv_open;
 	lfmt;
-	mutex_destroy = 		NODYNSORT;
+	mutex_destroy =			NODYNSORT;
 	mutex_init;
 	mutex_lock =			NODYNSORT;
 	mutex_trylock =			NODYNSORT;
--- old/usr/src/lib/libc/sparc/gen/byteorder.c	Wed Aug 27 14:23:25 2008
+++ new/usr/src/lib/libc/sparc/gen/byteorder.c	Wed Aug 27 14:23:24 2008
@@ -20,12 +20,10 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/isa_defs.h>
 #include <sys/types.h>
 
@@ -36,6 +34,25 @@
 
 #else	/* !_LITTLE_ENDIAN */
 
+/*
+ * htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
+ * These functions just return the input parameter, as the host
+ * byte order is the same as the network byte order (big endian).
+ * On little endian machines, these functions byte swap.
+ */
+
+uint64_t
+htonll(uint64_t in)
+{
+	return (in);
+}
+
+uint64_t
+ntohll(uint64_t in)
+{
+	return (in);
+}
+
 uint32_t
 htonl(uint32_t in)
 {
--- old/usr/src/lib/libc/sparcv9/gen/byteorder.c	Wed Aug 27 14:23:30 2008
+++ new/usr/src/lib/libc/sparcv9/gen/byteorder.c	Wed Aug 27 14:23:29 2008
@@ -20,12 +20,10 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/isa_defs.h>
 #include <sys/types.h>
 
@@ -36,6 +34,25 @@
 
 #else	/* !_LITTLE_ENDIAN */
 
+/*
+ * htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
+ * These functions just return the input parameter, as the host
+ * byte order is the same as the network byte order (big endian).
+ * On little endian machines, these functions byte swap.
+ */
+
+uint64_t
+htonll(uint64_t in)
+{
+	return (in);
+}
+
+uint64_t
+ntohll(uint64_t in)
+{
+	return (in);
+}
+
 uint32_t
 htonl(uint32_t in)
 {
--- old/usr/src/lib/libdhcputil/common/dhcp_inittab.c	Wed Aug 27 14:23:35 2008
+++ new/usr/src/lib/libdhcputil/common/dhcp_inittab.c	Wed Aug 27 14:23:34 2008
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <string.h>
 #include <stdlib.h>
@@ -47,8 +45,6 @@
 #include "dhcp_symbol.h"
 #include "dhcp_inittab.h"
 
-static uint64_t		dhcp_htonll(uint64_t);
-static uint64_t		dhcp_ntohll(uint64_t);
 static void		inittab_msg(const char *, ...);
 static uchar_t		category_to_code(const char *);
 static boolean_t	encode_number(uint8_t, uint8_t, boolean_t, uint8_t,
@@ -1478,7 +1474,7 @@
 		case 8:
 			(void) memcpy(&uint64, from, 8);
 			to += sprintf(to, is_signed ? "%lld" : "%llu",
-			    dhcp_ntohll(uint64));
+			    ntohll(uint64));
 			break;
 
 		default:
@@ -1574,7 +1570,7 @@
 			break;
 
 		case 8:
-			uint64 = dhcp_htonll(strtoull(from, &endptr, 0));
+			uint64 = htonll(strtoull(from, &endptr, 0));
 			if (errno != 0 || from == endptr) {
 				goto error;
 			}
@@ -1695,37 +1691,6 @@
 }
 
 /*
- * dhcp_htonll(): converts a 64-bit number from host to network byte order
- *
- *   input: uint64_t: the number to convert
- *  output: uint64_t: its value in network byte order
- */
-
-static uint64_t
-dhcp_htonll(uint64_t uint64_hbo)
-{
-	return (dhcp_ntohll(uint64_hbo));
-}
-
-/*
- * dhcp_ntohll(): converts a 64-bit number from network to host byte order
- *
- *   input: uint64_t: the number to convert
- *  output: uint64_t: its value in host byte order
- */
-
-static uint64_t
-dhcp_ntohll(uint64_t uint64_nbo)
-{
-#ifdef	_LITTLE_ENDIAN
-	return ((uint64_t)ntohl(uint64_nbo & 0xffffffff) << 32 |
-	    ntohl(uint64_nbo >> 32));
-#else
-	return (uint64_nbo);
-#endif
-}
-
-/*
  * our internal table of DHCP option values, used by inittab_verify()
  */
 static dhcp_symbol_t inittab_table[] =
@@ -1745,7 +1710,7 @@
 { DSYM_FIELD,		16,	"Yiaddr",	DSYM_IP,	1,	1 },
 { DSYM_FIELD,		20,	"BootSrvA",	DSYM_IP,	1,	1 },
 { DSYM_FIELD,		24,	"Giaddr",	DSYM_IP,	1,	1 },
-{ DSYM_FIELD,		28,	"Chaddr",	DSYM_OCTET, 	1,	16 },
+{ DSYM_FIELD,		28,	"Chaddr",	DSYM_OCTET,	1,	16 },
 { DSYM_FIELD,		44,	"BootSrvN",	DSYM_ASCII,	1,	64 },
 { DSYM_FIELD,		108,	"BootFile",	DSYM_ASCII,	1,	128 },
 { DSYM_FIELD,		236,	"Magic",	DSYM_OCTET,	1,	4 },
--- old/usr/src/stand/lib/xdr/byteorder.c	Wed Aug 27 14:23:40 2008
+++ new/usr/src/stand/lib/xdr/byteorder.c	Wed Aug 27 14:23:39 2008
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,16 +19,41 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 1991-2000, 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <netinet/in.h>
 
+/*
+ * htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
+ *
+ * On little endian machines these functions reverse the byte order of the
+ * input parameter and returns the result.  This is to convert the byte order
+ * from host byte order (little endian) to network byte order (big endian),
+ * or vice versa.
+ *
+ * On big endian machines these functions just return the input parameter,
+ * as the host byte order is the same as the network byte order (big endian).
+ */
+
+
 #ifdef	_LITTLE_ENDIAN
+uint64_t
+htonll(uint64_t in)
+{
+	return ((uint64_t)htonl((in >> 32) & 0xffffffff) |
+	    ((uint64_t)htonl(in & 0xffffffff) << 32));
+}
+
+uint64_t
+ntohll(uint64_t in)
+{
+	return ((uint64_t)ntohl((in >> 32) & 0xffffffff) |
+	    ((uint64_t)ntohl(in & 0xffffffff) << 32));
+}
+
 uint32_t
 htonl(uint32_t in)
 {
@@ -68,7 +92,18 @@
 #else	/* _LITTLE_ENDIAN */
 
 #if defined(lint)
+uint64_t
+htonll(uint64_t in)
+{
+	return (in);
+}
 
+uint64_t
+ntohll(uint64_t in)
+{
+	return (in);
+}
+
 uint32_t
 htonl(uint32_t in)
 {
--- old/usr/src/uts/common/crypto/io/dca_3des.c	Wed Aug 27 14:23:45 2008
+++ new/usr/src/uts/common/crypto/io/dca_3des.c	Wed Aug 27 14:23:43 2008
@@ -21,12 +21,10 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Deimos - cryptographic acceleration based upon Broadcom 582x.
  */
@@ -40,6 +38,11 @@
 #include <sys/crypto/spi.h>
 #include <sys/crypto/dca.h>
 
+#if defined(__i386) || defined(__amd64)
+#include <sys/byteorder.h>
+#define	UNALIGNED_POINTERS_PERMITTED
+#endif
+
 /*
  * 3DES implementation.
  */
@@ -74,9 +77,15 @@
 	 * If cd_miscdata non-null then this contains the IV.
 	 */
 	if (in->cd_miscdata != NULL) {
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		uint32_t	*p = (uint32_t *)in->cd_miscdata;
+		des_ctx->dr_ctx.iv[0] = htonl(p[0]);
+		des_ctx->dr_ctx.iv[1] = htonl(p[1]);
+#else
 		uchar_t	*p = (uchar_t *)in->cd_miscdata;
 		des_ctx->dr_ctx.iv[0] = p[0]<<24 | p[1]<<16 | p[2]<<8 | p[3];
 		des_ctx->dr_ctx.iv[1] = p[4]<<24 | p[5]<<16 | p[6]<<8 | p[7];
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
 
 	if (len > dca_length(out)) {
@@ -168,9 +177,15 @@
 	 * If cd_miscdata non-null then this contains the IV.
 	 */
 	if (in->cd_miscdata != NULL) {
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		uint32_t	*p = (uint32_t *)in->cd_miscdata;
+		des_ctx->dr_ctx.iv[0] = htonl(p[0]);
+		des_ctx->dr_ctx.iv[1] = htonl(p[1]);
+#else
 		uchar_t	*p = (uchar_t *)in->cd_miscdata;
 		des_ctx->dr_ctx.iv[0] = p[0]<<24 | p[1]<<16 | p[2]<<8 | p[3];
 		des_ctx->dr_ctx.iv[1] = p[4]<<24 | p[5]<<16 | p[6]<<8 | p[7];
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
 
 	if (len > dca_length(out)) {
@@ -392,7 +407,11 @@
 	 */
 	if (flags & DR_DECRYPT) {
 		uchar_t		ivstore[DESBLOCK];
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		uint32_t	*ivp = (uint32_t *)ivstore;
+#else
 		uchar_t		*ivp = ivstore;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
 		/* get last 8 bytes of ciphertext for IV of next op */
 		/*
@@ -420,10 +439,15 @@
 		}
 
 		/* store as a pair of native 32-bit values */
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		ctx->dr_ctx.iv[0] = htonl(ivp[0]);
+		ctx->dr_ctx.iv[1] = htonl(ivp[1]);
+#else
 		ctx->dr_ctx.iv[0] =
 		    ivp[0]<<24 | ivp[1]<<16 | ivp[2]<<8 | ivp[3];
 		ctx->dr_ctx.iv[1] =
 		    ivp[4]<<24 | ivp[5]<<16 | ivp[6]<<8 | ivp[7];
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
 
 	/* For now we force a pullup.  Add direct DMA later. */
@@ -550,20 +574,31 @@
 		 */
 		if (reqp->dr_flags & DR_ENCRYPT) {
 			uchar_t		ivstore[DESBLOCK];
+#ifdef UNALIGNED_POINTERS_PERMITTED
+			uint32_t	*iv = (uint32_t *)ivstore;
+#else
 			uchar_t		*iv = ivstore;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 
 			/* get last 8 bytes for IV of next op */
-			errno = dca_getbufbytes(out, off, DESBLOCK, iv);
+			errno = dca_getbufbytes(out, off, DESBLOCK,
+			    (uchar_t *)iv);
 			if (errno != CRYPTO_SUCCESS) {
 				DBG(NULL, DWARN,
 				    "dca_3desdone: dca_getbufbytes() failed");
 				goto errout;
 			}
+
 			/* store as a pair of native 32-bit values */
+#ifdef UNALIGNED_POINTERS_PERMITTED
+			ctx->dr_ctx.iv[0] = htonl(iv[0]);
+			ctx->dr_ctx.iv[1] = htonl(iv[1]);
+#else
 			ctx->dr_ctx.iv[0] =
 			    iv[0]<<24 | iv[1]<<16 | iv[2]<<8 | iv[3];
 			ctx->dr_ctx.iv[1] =
 			    iv[4]<<24 | iv[5]<<16 | iv[6]<<8 | iv[7];
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 		}
 
 		/*
@@ -623,7 +658,12 @@
 {
 	dca_request_t	*des_ctx;
 	dca_t		*dca = ctx->cc_provider;
+#ifdef UNALIGNED_POINTERS_PERMITTED
+	uint32_t	*param;
+	uint32_t	*value32;
+#else
 	uchar_t		*param;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	uchar_t		*value;
 	size_t		paramsz;
 	unsigned	len;
@@ -630,7 +670,12 @@
 	int		i, j;
 
 	paramsz = mechanism->cm_param_len;
+#ifdef UNALIGNED_POINTERS_PERMITTED
+	param = (uint32_t *)mechanism->cm_param;
+#else
 	param = (uchar_t *)mechanism->cm_param;
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
+
 	if ((paramsz != 0) && (paramsz != DES_IV_LEN)) {
 		DBG(NULL, DWARN,
 		    "dca_3desctxinit: parameter(IV) length not %d (%d)",
@@ -650,10 +695,15 @@
 	 */
 	if (param != NULL) {
 		ASSERT(paramsz == DES_IV_LEN);
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		des_ctx->dr_ctx.iv[0] = htonl(param[0]);
+		des_ctx->dr_ctx.iv[1] = htonl(param[1]);
+#else
 		des_ctx->dr_ctx.iv[0] = param[0]<<24 | param[1]<<16 |
 		    param[2]<<8 | param[3];
 		des_ctx->dr_ctx.iv[1] = param[4]<<24 | param[5]<<16 |
 		    param[6]<<8 | param[7];
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
 	}
 	des_ctx->dr_ctx.residlen = 0;
 	des_ctx->dr_ctx.activeresidlen = 0;
@@ -709,10 +759,18 @@
 			dca_3desctxfree(ctx);
 			return (CRYPTO_KEY_SIZE_RANGE);
 		}
+
+#ifdef UNALIGNED_POINTERS_PERMITTED
+		value32 = (uint32_t *)value;
+		des_ctx->dr_ctx.key[0] = htonl(value32[0]);
+		des_ctx->dr_ctx.key[1] = htonl(value32[1]);
+#else
 		des_ctx->dr_ctx.key[0] =
 		    value[0]<<24 | value[1]<<16 | value[2]<<8 | value[3];
 		des_ctx->dr_ctx.key[1] =
 		    value[4]<<24 | value[5]<<16 | value[6]<<8 | value[7];
+#endif	/* UNALIGNED_POINTERS_PERMITTED */
+
 		/* for single des just repeat des key */
 		des_ctx->dr_ctx.key[4] =
 		    des_ctx->dr_ctx.key[2] = des_ctx->dr_ctx.key[0];
--- old/usr/src/uts/common/sys/byteorder.h	Wed Aug 27 14:23:50 2008
+++ new/usr/src/uts/common/sys/byteorder.h	Wed Aug 27 14:23:48 2008
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -40,8 +40,6 @@
 #ifndef _SYS_BYTEORDER_H
 #define	_SYS_BYTEORDER_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/isa_defs.h>
 #include <sys/int_types.h>
 
@@ -61,8 +59,10 @@
 #if defined(_BIG_ENDIAN) && !defined(ntohl) && !defined(__lint)
 /* big-endian */
 #define	ntohl(x)	(x)
+#define	ntohll(x)	(x)
 #define	ntohs(x)	(x)
 #define	htonl(x)	(x)
+#define	htonll(x)	(x)
 #define	htons(x)	(x)
 
 #elif !defined(ntohl) /* little-endian */
@@ -80,14 +80,18 @@
 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5)
 extern	uint32_t htonl(uint32_t);
 extern	uint16_t htons(uint16_t);
-extern 	uint32_t ntohl(uint32_t);
+extern	uint32_t ntohl(uint32_t);
 extern	uint16_t ntohs(uint16_t);
 #else
 extern	in_addr_t htonl(in_addr_t);
 extern	in_port_t htons(in_port_t);
-extern 	in_addr_t ntohl(in_addr_t);
+extern	in_addr_t ntohl(in_addr_t);
 extern	in_port_t ntohs(in_port_t);
 #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5) */
+#if !(defined(_XPG4_2) || defined(_XPG5)) || defined(__EXTENSIONS__)
+extern	uint64_t htonll(uint64_t);
+extern	uint64_t ntohll(uint64_t);
+#endif	/* !(_XPG4_2||_XPG5) || __EXTENSIONS__ */
 #endif
 
 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
--- old/usr/src/uts/intel/amd64/ml/amd64.il	Wed Aug 27 14:23:55 2008
+++ new/usr/src/uts/intel/amd64/ml/amd64.il	Wed Aug 27 14:23:53 2008
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /
 / In-line functions for amd64 kernels.
 /
@@ -78,6 +76,16 @@
 / Networking byte order functions (too bad, Intel has the wrong byte order)
 /
 
+	.inline	htonll,4
+	movq	%rdi, %rax
+	bswapq	%rax
+	.end
+
+	.inline	ntohll,4
+	movq	%rdi, %rax
+	bswapq	%rax
+	.end
+
 	.inline	htonl,4
 	movl	%edi, %eax
 	bswap	%eax
--- old/usr/src/uts/intel/asm/byteorder.h	Wed Aug 27 14:24:00 2008
+++ new/usr/src/uts/intel/asm/byteorder.h	Wed Aug 27 14:23:58 2008
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -27,8 +26,6 @@
 #ifndef _ASM_BYTEORDER_H
 #define	_ASM_BYTEORDER_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 
 #ifdef	__cplusplus
@@ -37,19 +34,15 @@
 
 #if !defined(__lint) && defined(__GNUC__)
 
-#if defined(__i386) || defined(__amd64)
+/*
+ * htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
+ * These functions reverse the byte order of the input parameter and returns
+ * the result.  This is to convert the byte order from host byte order
+ * (little endian) to network byte order (big endian), or vice versa.
+ */
 
-extern __inline__ uint32_t htonl(uint32_t value)
-{
-	__asm__("bswap %0" : "+r" (value));
-	return (value);
-}
 
-extern __inline__ uint32_t ntohl(uint32_t value)
-{
-	__asm__("bswap %0" : "+r" (value));
-	return (value);
-}
+#if defined(__i386) || defined(__amd64)
 
 extern __inline__ uint16_t htons(uint16_t value)
 {
@@ -71,6 +64,44 @@
 	return (value);
 }
 
+extern __inline__ uint32_t htonl(uint32_t value)
+{
+	__asm__("bswap %0" : "+r" (value));
+	return (value);
+}
+
+extern __inline__ uint32_t ntohl(uint32_t value)
+{
+	__asm__("bswap %0" : "+r" (value));
+	return (value);
+}
+
+#if defined(__amd64)
+extern __inline__ uint64_t htonll(uint64_t value)
+{
+	__asm__("bswapq %0" : "+r" (value));
+	return (value);
+}
+
+extern __inline__ uint64_t ntohll(uint64_t value)
+{
+	__asm__("bswapq %0" : "+r" (value));
+	return (value);
+}
+
+#elif defined(__i386)
+/* Use the htonl() and ntohl() inline functions defined above */
+extern __inline__ uint64_t htonll(uint64_t value)
+{
+	return (htonl(value >> 32) | ((uint64_t)htonl(value) << 32));
+}
+
+extern __inline__ uint64_t ntohll(uint64_t value)
+{
+	return (ntohl(value >> 32) | (uint64_t)ntohl(value) << 32);
+}
+#endif	/* __amd64 */
+
 #endif	/* __i386 || __amd64 */
 
 #endif	/* !__lint && __GNUC__ */
--- old/usr/src/uts/intel/ia32/ml/i86_subr.s	Wed Aug 27 14:24:05 2008
+++ new/usr/src/uts/intel/ia32/ml/i86_subr.s	Wed Aug 27 14:24:03 2008
@@ -110,7 +110,7 @@
 	SET_SIZE(no_fault)
 
 #elif defined(__i386)
-			
+
 	ENTRY(on_fault)
 	movl	%gs:CPU_THREAD, %edx
 	movl	4(%esp), %eax			/* jumpbuf address */
@@ -905,7 +905,7 @@
 #if defined(__amd64)
 
 	ENTRY(_insque)
-	movq	(%rsi), %rax		/* predp->forw 			*/
+	movq	(%rsi), %rax		/* predp->forw			*/
 	movq	%rsi, CPTRSIZE(%rdi)	/* entryp->back = predp		*/
 	movq	%rax, (%rdi)		/* entryp->forw = predp->forw	*/
 	movq	%rdi, (%rsi)		/* predp->forw = entryp		*/
@@ -1080,7 +1080,7 @@
 #endif	/* __lint */
 
 	/*
-	 * Berkley 4.3 introduced symbolically named interrupt levels
+	 * Berkeley 4.3 introduced symbolically named interrupt levels
 	 * as a way deal with priority in a machine independent fashion.
 	 * Numbered priorities are machine specific, and should be
 	 * discouraged where possible.
@@ -1193,7 +1193,7 @@
 	SET_SIZE(spl0)
 
 
-	/* splx implentation */
+	/* splx implementation */
 	ENTRY(splx)
 	jmp	do_splx		/* redirect to common splx code */
 	SET_SIZE(splx)
@@ -1882,7 +1882,7 @@
 					/* rdx == table */
 					/* rcx == mask */
 	addq	%rsi, %rdi		/* end = &cp[size] */
-.scanloop:	
+.scanloop:
 	cmpq	%rdi, %rsi		/* while (cp < end */
 	jnb	.scandone
 	movzbq	(%rsi), %r8		/* %r8 = *cp */
@@ -1897,7 +1897,7 @@
 	SET_SIZE(scanc)
 
 #elif defined(__i386)
-	
+
 	ENTRY(scanc)
 	pushl	%edi
 	pushl	%esi
@@ -1923,7 +1923,7 @@
 	ret
 	SET_SIZE(scanc)
 
-#endif	/* __i386 */	
+#endif	/* __i386 */
 #endif	/* __lint */
 
 /*
@@ -2027,22 +2027,50 @@
 #endif	/* __i386 */
 #endif	/* __lint */
 
+/* htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
+ * These functions reverse the byte order of the input parameter and returns
+ * the result.  This is to convert the byte order from host byte order
+ * (little endian) to network byte order (big endian), or vice versa.
+ */
+
 #if defined(__lint)
 
-/* ARGSUSED */
+uint64_t
+htonll(uint64_t i)
+{ return (i); }
+
+uint64_t
+ntohll(uint64_t i)
+{ return (i); }
+
 uint32_t
 htonl(uint32_t i)
-{ return (0); }
+{ return (i); }
 
-/* ARGSUSED */
 uint32_t
 ntohl(uint32_t i)
-{ return (0); }
+{ return (i); }
 
+uint16_t
+htons(uint16_t i)
+{ return (i); }
+
+uint16_t
+ntohs(uint16_t i)
+{ return (i); }
+
 #else	/* __lint */
 
 #if defined(__amd64)
 
+	ENTRY(htonll)
+	ALTENTRY(ntohll)
+	movq	%rdi, %rax
+	bswapq	%rax
+	ret
+	SET_SIZE(ntohll)
+	SET_SIZE(htonll)
+
 	/* XX64 there must be shorter sequences for this */
 	ENTRY(htonl)
 	ALTENTRY(ntohl)
@@ -2052,36 +2080,6 @@
 	SET_SIZE(ntohl)
 	SET_SIZE(htonl)
 
-#elif defined(__i386)
-
-	ENTRY(htonl)
-	ALTENTRY(ntohl)
-	movl	4(%esp), %eax
-	bswap	%eax
-	ret
-	SET_SIZE(ntohl)
-	SET_SIZE(htonl)
-
-#endif	/* __i386 */
-#endif	/* __lint */
-
-#if defined(__lint)
-
-/* ARGSUSED */
-uint16_t
-htons(uint16_t i)
-{ return (0); }
-
-/* ARGSUSED */
-uint16_t
-ntohs(uint16_t i)
-{ return (0); }
-
-
-#else	/* __lint */
-
-#if defined(__amd64)
-
 	/* XX64 there must be better sequences for this */
 	ENTRY(htons)
 	ALTENTRY(ntohs)
@@ -2089,11 +2087,29 @@
 	bswap	%eax
 	shrl	$16, %eax
 	ret
-	SET_SIZE(ntohs)	
+	SET_SIZE(ntohs)
 	SET_SIZE(htons)
 
 #elif defined(__i386)
 
+	ENTRY(htonll)
+	ALTENTRY(ntohll)
+	movl	4(%esp), %edx
+	movl	8(%esp), %eax
+	bswap	%edx
+	bswap	%eax
+	ret
+	SET_SIZE(ntohll)
+	SET_SIZE(htonll)
+
+	ENTRY(htonl)
+	ALTENTRY(ntohl)
+	movl	4(%esp), %eax
+	bswap	%eax
+	ret
+	SET_SIZE(ntohl)
+	SET_SIZE(htonl)
+
 	ENTRY(htons)
 	ALTENTRY(ntohs)
 	movl	4(%esp), %eax
--- old/usr/src/uts/intel/ia32/ml/ia32.il	Wed Aug 27 14:24:10 2008
+++ new/usr/src/uts/intel/ia32/ml/ia32.il	Wed Aug 27 14:24:08 2008
@@ -20,12 +20,10 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /
 / Inline functions for i386 kernels.
 /	Shared between all x86 platform variants.
@@ -88,6 +86,20 @@
 /
 / Networking byte order functions (too bad, Intel has the wrong byte order)
 /
+	.inline	htonll,4
+	movl	(%esp), %edx
+	movl	4(%esp), %eax
+	bswap	%edx
+	bswap	%eax
+	.end
+
+	.inline	ntohll,4
+	movl	(%esp), %edx
+	movl	4(%esp), %eax
+	bswap	%edx
+	bswap	%eax
+	.end
+
 	.inline	htonl,4
 	movl	(%esp), %eax
 	bswap	%eax
