--- /dev/null	Mon Mar 24 15:31:29 2008
+++ new/deleted_files/usr/src/common/crypto/arcfour/amd64/arcfour_crypt_amd64.s	Mon Mar 24 15:31:28 2008
@@ -0,0 +1,165 @@
+#if !defined(lint) && !defined(__lint)
+/  ARCFOUR implementation optimized for AMD64.
+/
+/  Author: Marc Bevand <bevand_m (at) epita.fr>
+/  Licence: I hereby disclaim the copyright on this code and place it
+/  in the public domain.
+/
+/  The code has been designed to be easily integrated into openssl:
+/  the exported RC4() function can replace the actual implementations
+/  openssl already contains. Please note that when linking with openssl,
+/  it requires that sizeof(RC4_INT) == 8. So openssl must be compiled
+/  with -DRC4_INT='unsigned long'.
+/
+/  The throughput achieved by this code is about 320 MBytes/sec, on
+/  a 1.8 GHz AMD Opteron (rev C0) processor.
+
+
+/ ***** BEGIN LICENSE BLOCK *****
+/ Version: MPL 1.1/GPL 2.0/LGPL 2.1
+/
+/ The contents of this file are subject to the Mozilla Public License Version
+/ 1.1 (the "License"); you may not use this file except in compliance with
+/ the License. You may obtain a copy of the License at
+/ http://www.mozilla.org/MPL/
+/
+/ Software distributed under the License is distributed on an "AS IS" basis,
+/ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+/ for the specific language governing rights and limitations under the
+/ License.
+/
+/ The Original Code is "Marc Bevand's fast AMD64 ARCFOUR source"
+/
+/ The Initial Developer of the Original Code is
+/ Marc Bevand <bevand_m@epita.fr> .
+/ Portions created by the Initial Developer are
+/ Copyright (C) 2004 the Initial Developer. All Rights Reserved.
+/
+/ Contributor(s):
+/
+/ Alternatively, the contents of this file may be used under the terms of
+/ either the GNU General Public License Version 2 or later (the "GPL"), or
+/ the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+/ in which case the provisions of the GPL or the LGPL are applicable instead
+/ of those above. If you wish to allow use of your version of this file only
+/ under the terms of either the GPL or the LGPL, and not to allow others to
+/ use your version of this file under the terms of the MPL, indicate your
+/ decision by deleting the provisions above and replace them with the notice
+/ and other provisions required by the GPL or the LGPL. If you do not delete
+/ the provisions above, a recipient may use your version of this file under
+/ the terms of any one of the MPL, the GPL or the LGPL.
+/
+/ ***** END LICENSE BLOCK *****
+
+	.ident	"@(#)arcfour_crypt_amd64.s	1.1	08/01/02 SMI"
+
+/
+/ void arcfour_crypt(ARCFour_key *key, uchar_t *in,
+/		uchar_t *out, size_t len);
+/
+/ The following is Marc Bevand's RC4 implementation optimized for
+/ AMD64.  It has been lifted intact, except for minor interface
+/ changes to get along with Solaris crypto common code (the parameter
+/ order and the key struct element order are both different).
+/ This function works for both aligned and unaligned data ('in' and 'out').
+/ The key and key elements must be aligned.
+/
+/ Register Usage
+/ rax		data[x]
+/ rbx		ARG(len)
+/ rcx		key->i (aka x)
+/ rdx		key->j (aka y)
+/ rsi		ARG(in)
+/ rdi		ARG(out)
+/ rbp		key->arr (aka data or d)
+/ rsp		stack
+/ r8		8 bytes of rc4 stream
+/ r9		temp
+/ r10-r15 	unused
+/
+
+#include <sys/asm_linkage.h>
+
+
+	ENTRY_NP(arcfour_crypt)
+	/* EXPORT DELETE START */
+					/ load parameters
+	push	%rbp
+	push	%rbx
+	mov	%rdi,		%rbp	/ rbp = ARG(key)
+					/ rsi = ARG(in)
+	mov	%rdx,		%rdi	/ rdi = ARG(out)
+	mov	%rcx,		%rbx	/ rbx = ARG(len)
+
+					/ load key indices and key
+	mov	2048(%rbp),	%rcx	/ rcx x = key->i
+	mov	2056(%rbp),	%rdx	/ rdx y = key->j
+					/ rbp d = key->arr
+	inc	%rcx			/ x++
+	and	$255,		%rcx	/ x &= 0xff
+	lea	-8(%rbx,%rsi),	%rbx	/ rbx = in+len-8
+	mov	%rbx,		%r9	/ tmp = in+len-8
+	mov	(%rbp,%rcx,8),	%rax	/ tx = d[x]
+	cmp	%rsi,		%rbx	/ cmp in with in+len-8
+	jl	.Lend			/ jump if (in+len-8 < in)
+
+.Lstart:
+	add	$8,		%rsi		/ increment in
+	add	$8,		%rdi		/ increment out
+
+	/ generate the next 8 bytes of the rc4 stream into %r8
+	mov	$8,		%r11		/ byte counter
+1:	add	%al,		%dl		/ y += tx
+	mov	(%rbp,%rdx,8),	%ebx		/ ty = d[y]
+	mov	%ebx,		(%rbp,%rcx,8)	/ d[x] = ty
+	add	%al,		%bl		/ val = ty + tx
+	mov	%eax,		(%rbp,%rdx,8)	/ d[y] = tx
+	inc	%cl				/ x++		(NEXT ROUND)
+	mov	(%rbp,%rcx,8),	%eax		/ tx = d[x]	(NEXT ROUND)
+	movb	(%rbp,%rbx,8),	%r8b		/ val = d[val]
+	dec	%r11b
+	ror	$8,		%r8		/ (ror does not change ZF)
+	jnz	1b
+
+	/ xor 8 bytes
+	xor	-8(%rsi),	%r8
+	cmp	%r9,		%rsi		/ cmp in+len-8 with in
+	mov	%r8,		-8(%rdi)
+	jle	.Lstart				/ jump if (in <= in+len-8)
+
+.Lend:
+	add	$8,		%r9		/ tmp = in+len
+
+	/ handle the last bytes, one by one
+1:	cmp	%rsi,		%r9		/ cmp in with in+len
+	jle	.Lfinished			/ jump if (in+len <= in)
+	add	%al,		%dl		/ y += tx
+	mov	(%rbp,%rdx,8),	%ebx		/ ty = d[y]
+	mov	%ebx,		(%rbp,%rcx,8)	/ d[x] = ty
+	add	%al,		%bl		/ val = ty + tx
+	mov	%eax,		(%rbp,%rdx,8)	/ d[y] = tx
+	inc	%cl				/ x++		(NEXT ROUND)
+	mov	(%rbp,%rcx,8),	%eax		/ tx = d[x]	(NEXT ROUND)
+	movb	(%rbp,%rbx,8),	%r8b		/ val = d[val]
+	xor	(%rsi),		%r8b		/ xor 1 byte
+	movb	%r8b,		(%rdi)
+	inc	%rsi				/ in++
+	inc	%rdi				/ out++
+	jmp	1b
+
+.Lfinished:					/ save key indices i & j
+	dec	%rcx				/ x--
+	movb	%dl,		2056(%rbp)	/ key->j = y
+	movb	%cl,		2048(%rbp)	/ key->i = x
+	pop	%rbx
+	pop	%rbp
+
+	/* EXPORT DELETE END */
+
+	ret
+	SET_SIZE(arcfour_crypt)
+
+#else
+	/* LINTED */
+	/* Nothing to be linted in this file--it's pure assembly source. */
+#endif /* !lint && !__lint */
--- old/usr/src/cmd/cmd-crypto/digest/Makefile	Mon Mar 24 15:31:30 2008
+++ new/usr/src/cmd/cmd-crypto/digest/Makefile	Mon Mar 24 15:31:30 2008
@@ -19,39 +19,45 @@
 # 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.
 #
-# ident	"@(#)Makefile	1.5	07/02/02 SMI"
+# ident	"@(#)Makefile	1.6	08/03/20 SMI"
 #
 
-PROG = digest
+PROG= digest
+ROOTLINK= $(ROOTBIN)/mac
+DCFILE= $(PROG).dc
 
-OBJS = digest.o
+include ../../Makefile.cmd
 
-SRCS = $(OBJS:.o=.c)
+SUBDIRS= $(MACH)
+$(BUILD64)SUBDIRS += $(MACH64)
 
-include ../../Makefile.cmd 
+all	:=	TARGET = all
+install	:=	TARGET = install
+clean	:=	TARGET = clean
+clobber	:=	TARGET = clobber
+lint	:=	TARGET = lint
 
-CFLAGS += $(CCVERBOSE) -D_FILE_OFFSET_BITS=64
-
-LDLIBS += -lkmf -lpkcs11 -lcryptoutil
-
 .KEEP_STATE:
 
-all:    $(PROG)
+all clean clobber lint:    $(SUBDIRS)
 
-$(PROG): $(OBJS)
-	$(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(DYNFLAGS)
-	$(POST_PROCESS)
+install:	$(SUBDIRS)
+	-$(RM) $(ROOTPROG) $(ROOTLINK)
+	-$(LN) $(ISAEXEC) $(ROOTPROG)
+	-$(LN) $(ISAEXEC) $(ROOTLINK)
 
-install: all $(ROOTPROG)
-	$(RM) $(ROOTBIN)/mac
-	$(LN) $(ROOTPROG) $(ROOTBIN)/mac
+$(SUBDIRS):	FRC
+	@cd $@; pwd; $(MAKE) $(TARGET)
 
-clean:
-	$(RM) -f $(OBJS) $(PROG)
+$(DCFILE):
+	$(RM) messages.po
+	$(XGETTEXT) $(XGETFLAGS) -t $(PROG).c
+	$(SED) -e '/^domain/d' messages.po > $@
+	$(RM) messages.po
 
-lint:   lint_SRCS
+FRC:
 
 include ../../Makefile.targ
--- /dev/null	Mon Mar 24 15:31:35 2008
+++ new/usr/src/cmd/cmd-crypto/digest/Makefile.com	Mon Mar 24 15:31:35 2008
@@ -0,0 +1,70 @@
+#
+# 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.
+#
+# ident	"@(#)Makefile.com	1.1	08/03/20 SMI"
+#
+
+PROG = digest
+
+ROOTLINK32= $(ROOTBIN32)/mac
+ROOTLINK64= $(ROOTBIN64)/mac
+
+OBJS = digest.o
+
+SRCS = $(OBJS:%.o=../%.c)
+
+include ../../../Makefile.cmd
+
+CFLAGS += $(CCVERBOSE)
+CFLAGS64 += $(CCVERBOSE)
+CPPFLAGS +=-D_FILE_OFFSET_BITS=64
+
+LDLIBS += -lkmf -lpkcs11 -lcryptoutil
+
+.KEEP_STATE:
+
+all:	$(PROG)
+
+lint: lint_SRCS
+
+include ../../../Makefile.targ
+
+%.o:	../%.c
+	$(COMPILE.c) $<
+
+$(PROG): $(OBJS)
+	$(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(DYNFLAGS)
+	$(POST_PROCESS)
+
+$(ROOTLINK32): $(ROOTPROG32)
+	$(RM) $@
+	$(LN) $(ROOTPROG32) $@
+
+$(ROOTLINK64): $(ROOTPROG64)
+	$(RM) $@
+	$(LN) $(ROOTPROG64) $@
+
+clean:
+	$(RM) $(PROG) $(OBJS)
+
--- /dev/null	Mon Mar 24 15:31:36 2008
+++ new/usr/src/cmd/cmd-crypto/digest/amd64/Makefile	Mon Mar 24 15:31:36 2008
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+# ident	"@(#)Makefile	1.1	08/03/20 SMI"
+#
+
+include ../Makefile.com
+include ../../../Makefile.cmd.64
+
+install: all $(ROOTPROG64) $(ROOTLINK64)
--- old/usr/src/cmd/cmd-crypto/digest/digest.c	Mon Mar 24 15:31:38 2008
+++ new/usr/src/cmd/cmd-crypto/digest/digest.c	Mon Mar 24 15:31:38 2008
@@ -19,11 +19,11 @@
  * 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	"@(#)digest.c	1.11	07/10/04 SMI"
+#pragma ident	"@(#)digest.c	1.12	08/03/20 SMI"
 
 /*
  * digest.c
@@ -371,7 +371,7 @@
 	CK_ULONG resultlen;
 	CK_BYTE_PTR	pkeydata = NULL;
 	CK_OBJECT_HANDLE key = (CK_OBJECT_HANDLE) 0;
-	int keylen = 0;		/* key length */
+	size_t keylen = 0;		/* key length */
 	char *resultstr = NULL;	/* result in hex string */
 	int resultstrlen;	/* result string length */
 	int i;
@@ -417,16 +417,16 @@
 				}
 
 				status = pkcs11_get_pass(token_label,
-				    (char **)&pkeydata, (size_t *)&keylen,
+				    (char **)&pkeydata, &keylen,
 				    0, B_FALSE);
 			} else if (keyfile != NULL) {
 				/* get the key file */
 				status = pkcs11_read_data(keyfile,
-				    (void **)&pkeydata, (size_t *)&keylen);
+				    (void **)&pkeydata, &keylen);
 			} else {
 				/* get the key from input */
 				status = pkcs11_get_pass(NULL,
-				    (char **)&pkeydata, (size_t *)&keylen,
+				    (char **)&pkeydata, &keylen,
 				    0, B_FALSE);
 			}
 
--- /dev/null	Mon Mar 24 15:31:42 2008
+++ new/usr/src/cmd/cmd-crypto/digest/i386/Makefile	Mon Mar 24 15:31:42 2008
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+# ident	"@(#)Makefile	1.1	08/03/20 SMI"
+#
+
+include ../Makefile.com
+
+install: all $(ROOTPROG32) $(ROOTLINK32)
--- /dev/null	Mon Mar 24 15:31:44 2008
+++ new/usr/src/cmd/cmd-crypto/digest/sparc/Makefile	Mon Mar 24 15:31:44 2008
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+# ident	"@(#)Makefile	1.1	08/03/20 SMI"
+#
+
+include ../Makefile.com
+
+install: all $(ROOTPROG32) $(ROOTLINK32)
--- /dev/null	Mon Mar 24 15:31:46 2008
+++ new/usr/src/cmd/cmd-crypto/digest/sparcv9/Makefile	Mon Mar 24 15:31:46 2008
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+# ident	"@(#)Makefile	1.1	08/03/20 SMI"
+#
+
+include ../Makefile.com
+include ../../../Makefile.cmd.64
+
+install: all $(ROOTPROG64) $(ROOTLINK64)
--- /dev/null	Mon Mar 24 15:31:48 2008
+++ new/usr/src/common/crypto/arcfour/amd64/THIRDPARTYLICENSE	Mon Mar 24 15:31:48 2008
@@ -0,0 +1,36 @@
+Copyright (c) 2006, CRYPTOGAMS by <appro@openssl.org>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+      *	Redistributions of source code must retain copyright notices,
+	this list of conditions and the following disclaimer.
+
+      *	Redistributions in binary form must reproduce the above
+	copyright notice, this list of conditions and the following
+	disclaimer in the documentation and/or other materials
+	provided with the distribution.
+
+      *	Neither the name of the CRYPTOGAMS nor the names of its
+	copyright holder and contributors may be used to endorse or
+	promote products derived from this software without specific
+	prior written permission.
+
+ALTERNATIVELY, provided that this notice is retained in full, this
+product may be distributed under the terms of the GNU General Public
+License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+those given above.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--- /dev/null	Mon Mar 24 15:31:50 2008
+++ new/usr/src/common/crypto/arcfour/amd64/THIRDPARTYLICENSE.descrip	Mon Mar 24 15:31:50 2008
@@ -0,0 +1,1 @@
+PORTIONS OF ARCFOUR FUNCTIONALITY
--- /dev/null	Mon Mar 24 15:31:51 2008
+++ new/usr/src/common/crypto/arcfour/amd64/arcfour-x86_64.pl	Mon Mar 24 15:31:51 2008
@@ -0,0 +1,407 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. The module is, however, dual licensed under OpenSSL and
+# CRYPTOGAMS licenses depending on where you obtain it. For further
+# details see http://www.openssl.org/~appro/cryptogams/.
+# ====================================================================
+#
+# 2.22x RC4 tune-up:-) It should be noted though that my hand [as in
+# "hand-coded assembler"] doesn't stand for the whole improvement
+# coefficient. It turned out that eliminating RC4_CHAR from config
+# line results in ~40% improvement (yes, even for C implementation).
+# Presumably it has everything to do with AMD cache architecture and
+# RAW or whatever penalties. Once again! The module *requires* config
+# line *without* RC4_CHAR! As for coding "secret," I bet on partial
+# register arithmetics. For example instead of 'inc %r8; and $255,%r8'
+# I simply 'inc %r8b'. Even though optimization manual discourages
+# to operate on partial registers, it turned out to be the best bet.
+# At least for AMD... How IA32E would perform remains to be seen...
+
+# As was shown by Marc Bevand reordering of couple of load operations
+# results in even higher performance gain of 3.3x:-) At least on
+# Opteron... For reference, 1x in this case is RC4_CHAR C-code
+# compiled with gcc 3.3.2, which performs at ~54MBps per 1GHz clock.
+# Latter means that if you want to *estimate* what to expect from
+# *your* Opteron, then multiply 54 by 3.3 and clock frequency in GHz.
+
+# Intel P4 EM64T core was found to run the AMD64 code really slow...
+# The only way to achieve comparable performance on P4 was to keep
+# RC4_CHAR. Kind of ironic, huh? As it's apparently impossible to
+# compose blended code, which would perform even within 30% marginal
+# on either AMD and Intel platforms, I implement both cases. See
+# rc4_skey.c for further details...
+
+# P4 EM64T core appears to be "allergic" to 64-bit inc/dec. Replacing 
+# those with add/sub results in 50% performance improvement of folded
+# loop...
+
+# As was shown by Zou Nanhai loop unrolling can improve Intel EM64T
+# performance by >30% [unlike P4 32-bit case that is]. But this is
+# provided that loads are reordered even more aggressively! Both code
+# pathes, AMD64 and EM64T, reorder loads in essentially same manner
+# as my IA-64 implementation. On Opteron this resulted in modest 5%
+# improvement [I had to test it], while final Intel P4 performance
+# achieves respectful 432MBps on 2.8GHz processor now. For reference.
+# If executed on Xeon, current RC4_CHAR code-path is 2.7x faster than
+# RC4_INT code-path. While if executed on Opteron, it's only 25%
+# slower than the RC4_INT one [meaning that if CPU µ-arch detection
+# is not implemented, then this final RC4_CHAR code-path should be
+# preferred, as it provides better *all-round* performance].
+
+# Intel Core2 was observed to perform poorly on both code paths:-( It
+# apparently suffers from some kind of partial register stall, which
+# occurs in 64-bit mode only [as virtually identical 32-bit loop was
+# observed to outperform 64-bit one by almost 50%]. Adding two movzb to
+# cloop1 boosts its performance by 80%! This loop appears to be optimal
+# fit for Core2 and therefore the code was modified to skip cloop8 on
+# this CPU.
+
+#
+# OpenSolaris OS modifications
+#
+# Sun elects to use this software under the BSD license.
+#
+# This source originates from OpenSSL file rc4-x86_64.pl at
+# ftp://ftp.openssl.org/snapshot/openssl-0.9.8-stable-SNAP-20080131.tar.gz
+# (presumably for future OpenSSL release 0.9.8h), with these changes:
+#
+# 1. Added some comments, "use strict", and declared all variables.
+#
+# 2. Added OpenSolaris ENTRY_NP/SET_SIZE macros from
+# /usr/include/sys/asm_linkage.h, .ident keywords, and lint(1B) guards.
+#
+# 3. Changed function name from RC4() to arcfour_crypt() and RC4_set_key()
+# to arcfour_key_init(), and changed the parameter order for both to that
+# used by OpenSolaris.
+#
+# 4. The current method of using cpuid feature bits 20 (NX) or 28 (HTT) from
+# function OPENSSL_ia32_cpuid() to distinguish Intel/AMD does not work for
+# some newer AMD64 processors, as these bits are set on both Intel EM64T
+# processors and newer AMD64 processors.  I replaced this with code to use CPUID
+# instruction subfunction EAX=0 to determine if we're running on "GenuineIntel"
+# or not. The result decides whether to use a
+#	* 1-byte key array (label .LRC4_CHAR, optimal on Intel EM64T) or a
+#	* 4-byte key array (Labels .Lloop1 and .Lloop8, optimal on AMD64).
+#
+# 5. Removed x86_64-xlate.pl script (not needed for as(1) or gas(1) assemblers).
+#
+# 6. Removed Lcloop8 code (slower than Lcloop1 on EM64T and not used on AMD64).
+#
+
+use strict;
+my ($code, $dat, $inp, $out, $len, $idx, $ido, $i, @XX, @TX, $YY, $TY);
+my $output = shift;
+open STDOUT,">$output";
+
+#
+# Parameters
+#
+
+# OpenSSL:
+# void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
+#	unsigned char *outdata);
+#$dat="%rdi";	    # arg1
+#$len="%rsi";	    # arg2
+#$inp="%rdx";	    # arg3
+#$out="%rcx";	    # arg4
+
+# OpenSolaris:
+# void arcfour_crypt(ARCFour_key *key, uchar_t *in, uchar_t *out, size_t len);
+$dat="%rdi";	    # arg1
+$inp="%rsi";	    # arg2
+$out="%rdx";	    # arg3
+$len="%rcx";	    # arg4
+
+#
+# Register variables
+#
+# $XX[0] is key->i (aka key->x), $XX[1] is a temporary.
+# $TX[0] and $TX[1] are temporaries.
+# $YY is key->j (aka key->y).
+# $TY is a temporary.
+#
+@XX=("%r8","%r10");
+@TX=("%r9","%r11");
+$YY="%r12";
+$TY="%r13";
+
+$code=<<___;
+#if !defined(lint) && !defined(__lint)
+
+	.ident	"@(#)arcfour-x86_64.pl	1.1	08/03/20 SMI"
+
+#include <sys/asm_linkage.h>
+
+
+ENTRY_NP(arcfour_crypt)
+	/* EXPORT DELETE START */
+
+	or	$len,$len # If (len == 0) return
+	jne	.Lentry
+	ret
+.Lentry:
+	push	%r12
+	push	%r13
+
+	/ Set $dat to beginning of array, key->arr[0]
+	add	\$8,$dat
+	/ Get key->j
+	movl	-8($dat),$XX[0]#d
+	/ Get key->i
+	movl	-4($dat),$YY#d
+
+	/
+	/ Use a 1-byte data array, on Intel P4 EM64T,
+	/ which is more efficient there,
+	/ or a 4-byte data array (for AMD AMD64).
+	/
+
+	/ If RC4_CHAR flag set (Intel EM64T), then use 1-byte array
+	cmpl	\$-1,256($dat)
+	je	.LRC4_CHAR
+	/ otherwise use 4-byte integer array (AMD64)
+	inc	$XX[0]#b
+	movl	($dat,$XX[0],4),$TX[0]#d
+	test	\$-8,$len
+	jz	.Lloop1
+	jmp	.Lloop8
+
+.align	16
+.Lloop8:
+	/
+	/ This code is for use with a 4-byte integer data array, which is
+	/ more efficient on AMD64 Athlon and Opteron-class processors.
+	/
+___
+for ($i=0;$i<8;$i++) {
+$code.=<<___;
+	add	$TX[0]#b,$YY#b
+	mov	$XX[0],$XX[1]
+	movl	($dat,$YY,4),$TY#d
+	ror	\$8,%rax			# ror is redundant when $i=0
+	inc	$XX[1]#b
+	movl	($dat,$XX[1],4),$TX[1]#d
+	cmp	$XX[1],$YY
+	movl	$TX[0]#d,($dat,$YY,4)
+	cmove	$TX[0],$TX[1]
+	movl	$TY#d,($dat,$XX[0],4)
+	add	$TX[0]#b,$TY#b
+	movb	($dat,$TY,4),%al
+___
+push(@TX,shift(@TX)); push(@XX,shift(@XX));	# "rotate" registers
+}
+$code.=<<___;
+	ror	\$8,%rax
+	sub	\$8,$len
+
+	xor	($inp),%rax
+	add	\$8,$inp
+	mov	%rax,($out)
+	add	\$8,$out
+
+	test	\$-8,$len
+	jnz	.Lloop8
+	cmp	\$0,$len
+	jne	.Lloop1
+___
+$code.=<<___;
+.Lexit:
+	/
+	/ Cleanup and exit code
+	/
+	/ --i to undo ++i done at entry
+	sub	\$1,$XX[0]#b
+	/ set key->i
+	movl	$XX[0]#d,-8($dat)
+	/ set key->j
+	movl	$YY#d,-4($dat)
+
+	pop	%r13
+	pop	%r12
+	ret
+.align	16
+.Lloop1:
+	add	$TX[0]#b,$YY#b
+	movl	($dat,$YY,4),$TY#d
+	movl	$TX[0]#d,($dat,$YY,4)
+	movl	$TY#d,($dat,$XX[0],4)
+	add	$TY#b,$TX[0]#b
+	inc	$XX[0]#b
+	movl	($dat,$TX[0],4),$TY#d
+	movl	($dat,$XX[0],4),$TX[0]#d
+	xorb	($inp),$TY#b
+	inc	$inp
+	movb	$TY#b,($out)
+	inc	$out
+	dec	$len
+	jnz	.Lloop1
+	jmp	.Lexit
+
+
+.align	16
+.LRC4_CHAR:
+	/
+	/ This code is for use with a 1-byte integer data array, which is
+	/ more efficient on Intel P4 EM64T-class processors.
+	/
+	add	\$1,$XX[0]#b
+	movzb	($dat,$XX[0]),$TX[0]#d
+	jmp	.Lcloop1
+
+.align	16
+.Lcloop1:
+	add	$TX[0]#b,$YY#b
+	movzb	($dat,$YY),$TY#d
+	movb	$TX[0]#b,($dat,$YY)
+	movb	$TY#b,($dat,$XX[0])
+	add	$TX[0]#b,$TY#b
+	add	\$1,$XX[0]#b
+	/ Intel Optimization (preload $TY and $XX[0]):
+	movzb	$TY#b,$TY#d
+	movzb	$XX[0]#b,$XX[0]#d
+	movzb	($dat,$TY),$TY#d
+	movzb	($dat,$XX[0]),$TX[0]#d
+	xorb	($inp),$TY#b
+	lea	1($inp),$inp
+	movb	$TY#b,($out)
+	lea	1($out),$out
+	sub	\$1,$len
+	jnz	.Lcloop1
+	jmp	.Lexit
+
+	/* EXPORT DELETE END */
+	ret
+SET_SIZE(arcfour_crypt)
+___
+
+
+#
+# Parameters
+#
+
+# OpenSSL:
+# void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
+#$dat="%rdi";	    # arg1
+#$len="%rsi";	    # arg2
+#$inp="%rdx";	    # arg3
+
+# OpenSolaris:
+# void arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen);
+$dat="%rdi";	    # arg1
+$inp="%rsi";	    # arg2
+$len="%rdx";	    # arg3
+
+# Temporaries
+$idx="%r8";
+$ido="%r9";
+
+$code.=<<___;
+	/ int arcfour_crypt_on_intel(void);
+.extern	arcfour_crypt_on_intel
+
+ENTRY_NP(arcfour_key_init)
+	/* EXPORT DELETE START */
+
+	/ Find out if we're running on Intel or something else (e.g., AMD64).
+	/ This sets %eax to 1 for Intel, otherwise 0.
+	push	%rdi		/ Save arg1
+	push	%rsi		/ Save arg2
+	push	%rdx		/ Save arg3
+	call	arcfour_crypt_on_intel
+	pop	%rdx		/ Restore arg3
+	pop	%rsi		/ Restore arg2
+	pop	%rdi		/ Restore arg1
+
+	/ Set $dat to beginning of array, key->arr[0]
+	lea	8($dat),$dat
+	lea	($inp,$len),$inp
+	neg	$len
+	mov	$len,%rcx
+	/ Zeroed below, as %eax contains a flag from arcfour_crypt_on_intel():
+	/xor	%eax,%eax
+	xor	$ido,$ido
+	xor	%r10,%r10
+	xor	%r11,%r11
+
+	/
+	/ Use a 1-byte data array, on Intel P4 EM64T,
+	/ which is more efficient there,
+	/ or a 4-byte data array (for AMD AMD64).
+	/
+	cmp	\$1,%eax	/ Test if Intel
+	mov	\$0,%eax	/ Zero eax without modifying flags
+	je	.Lc1stloop	/ If Intel then use a 1-byte array,
+	jmp	.Lw1stloop	/ otherwise use a 4-byte array.
+
+.align	16
+.Lw1stloop:
+	/ AMD64 (4-byte array)
+	mov	%eax,($dat,%rax,4)
+	add	\$1,%al
+	jnc	.Lw1stloop
+
+	xor	$ido,$ido
+	xor	$idx,$idx
+.align	16
+.Lw2ndloop:
+	mov	($dat,$ido,4),%r10d
+	add	($inp,$len,1),$idx#b
+	add	%r10b,$idx#b
+	add	\$1,$len
+	mov	($dat,$idx,4),%r11d
+	cmovz	%rcx,$len
+	mov	%r10d,($dat,$idx,4)
+	mov	%r11d,($dat,$ido,4)
+	add	\$1,$ido#b
+	jnc	.Lw2ndloop
+	jmp	.Lexit_key
+
+.align	16
+.Lc1stloop:
+	/ Intel EM64T (1-byte array)
+	mov	%al,($dat,%rax)
+	add	\$1,%al
+	jnc	.Lc1stloop
+
+	xor	$ido,$ido
+	xor	$idx,$idx
+.align	16
+.Lc2ndloop:
+	mov	($dat,$ido),%r10b
+	add	($inp,$len),$idx#b
+	add	%r10b,$idx#b
+	add	\$1,$len
+	mov	($dat,$idx),%r11b
+	jnz	.Lcnowrap
+	mov	%rcx,$len
+.Lcnowrap:
+	mov	%r10b,($dat,$idx)
+	mov	%r11b,($dat,$ido)
+	add	\$1,$ido#b
+	jnc	.Lc2ndloop
+	movl	\$-1,256($dat)
+
+.align	16
+.Lexit_key:
+	xor	%eax,%eax
+	mov	%eax,-8($dat)
+	mov	%eax,-4($dat)
+
+	/* EXPORT DELETE END */
+	ret
+SET_SIZE(arcfour_key_init)
+.asciz	"RC4 for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
+
+#else
+	/* LINTED */
+	/* Nothing to be linted in this file--it's pure assembly source. */
+#endif /* !lint && !__lint */
+___
+
+$code =~ s/#([bwd])/$1/gm;
+
+print $code;
+
+close STDOUT;
--- old/usr/src/common/crypto/arcfour/arcfour.h	Mon Mar 24 15:31:53 2008
+++ new/usr/src/common/crypto/arcfour/arcfour.h	Mon Mar 24 15:31:53 2008
@@ -19,7 +19,7 @@
  * 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.
  */
 
@@ -26,7 +26,7 @@
 #ifndef _ARCFOUR_H
 #define	_ARCFOUR_H
 
-#pragma ident	"@(#)arcfour.h	1.6	07/03/29 SMI"
+#pragma ident	"@(#)arcfour.h	1.7	08/03/20 SMI"
 
 #ifdef __cplusplus
 extern "C" {
@@ -50,6 +50,9 @@
 void arcfour_crypt_aligned(ARCFour_key *key, size_t len, uchar_t *in,
     uchar_t *out);
 #endif	/* sun4u */
+#ifdef	__amd64
+int arcfour_crypt_on_intel(void);
+#endif	/* _amd64 */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/common/crypto/arcfour/arcfour_crypt.c	Mon Mar 24 15:31:58 2008
+++ new/usr/src/common/crypto/arcfour/arcfour_crypt.c	Mon Mar 24 15:31:57 2008
@@ -23,18 +23,21 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"@(#)arcfour_crypt.c	1.6	08/01/02 SMI"
+#pragma ident	"@(#)arcfour_crypt.c	1.7	08/03/20 SMI"
 
 #include "arcfour.h"
 
 #if defined(__amd64)
-/*
- * Use hand-tuned, processor-specific assembly version of arcfour_crypt()
- * for 64-bit x86:
- */
-#define	USE_PSR_VERSION_OF_ARCFOUR_CRYPT
-#endif /* __amd64 */
+#ifdef _KERNEL
+#include <sys/x86_archext.h>
+#include <sys/cpuvar.h>
 
+#else
+#include <sys/auxv.h>
+#endif	/* _KERNEL */
+#endif	/* __amd64 */
+
+#if !defined(__amd64)
 /* Initialize the key stream 'key' using the key value */
 void
 arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen)
@@ -45,12 +48,13 @@
 	uchar_t tmp;
 	int i, j;
 
+	/* Normalize key length to 256 */
 	for (i = j = 0; i < 256; i++, j++) {
 		if (j == keyvallen)
 			j = 0;
-
 		ext_keyval[i] = keyval[j];
 	}
+
 	for (i = 0; i < 256; i++)
 		key->arr[i] = (uchar_t)i;
 
@@ -68,7 +72,6 @@
 }
 
 
-#if !defined(USE_PSR_VERSION_OF_ARCFOUR_CRYPT)
 /*
  * Encipher 'in' using 'key'.
  * in and out can point to the same location
@@ -138,4 +141,21 @@
 
 /* EXPORT DELETE END */
 }
-#endif	/* !USE_PSR_VERSION_OF_ARCFOUR_CRYPT */
+
+#else
+
+/*
+ * Return 1 if executing on Intel, otherwise 0 (e.g., AMD64).
+ */
+int
+arcfour_crypt_on_intel(void)
+{
+#ifdef _KERNEL
+	return (cpuid_getvendor(CPU) == X86_VENDOR_Intel);
+#else
+	uint_t	ui;
+	(void) getisax(&ui, 1);
+	return ((ui & AV_386_AMD_MMX) == 0);
+#endif	/* _KERNEL */
+}
+#endif	/* !__amd64 */
--- old/usr/src/common/crypto/sha1/amd64/sha1-x86_64.pl	Mon Mar 24 15:32:02 2008
+++ new/usr/src/common/crypto/sha1/amd64/sha1-x86_64.pl	Mon Mar 24 15:32:02 2008
@@ -176,7 +176,6 @@
 my $func=shift;
 $code.=<<___;
 ENTRY_NP($func)
-	/* EXPORT DELETE START */
 	push	%rbx
 	push	%rbp
 	push	%r12
@@ -203,7 +202,6 @@
 	pop	%r12
 	pop	%rbp
 	pop	%rbx
-        /* EXPORT DELETE END */
 	ret
 SET_SIZE($func)
 ___
@@ -320,7 +318,7 @@
 
 $code=<<___;
 #if !defined(lint) && !defined(__lint)
-	.ident	"@(#)sha1-x86_64.pl	1.1	08/03/02 SMI"
+	.ident	"@(#)sha1-x86_64.pl	1.2	08/03/20 SMI"
 #include <sys/asm_linkage.h>
 ___
 
--- /dev/null	Mon Mar 24 15:32:06 2008
+++ new/usr/src/common/crypto/sha2/amd64/THIRDPARTYLICENSE	Mon Mar 24 15:32:06 2008
@@ -0,0 +1,36 @@
+Copyright (c) 2006, CRYPTOGAMS by <appro@openssl.org>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+      *	Redistributions of source code must retain copyright notices,
+	this list of conditions and the following disclaimer.
+
+      *	Redistributions in binary form must reproduce the above
+	copyright notice, this list of conditions and the following
+	disclaimer in the documentation and/or other materials
+	provided with the distribution.
+
+      *	Neither the name of the CRYPTOGAMS nor the names of its
+	copyright holder and contributors may be used to endorse or
+	promote products derived from this software without specific
+	prior written permission.
+
+ALTERNATIVELY, provided that this notice is retained in full, this
+product may be distributed under the terms of the GNU General Public
+License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+those given above.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--- /dev/null	Mon Mar 24 15:32:08 2008
+++ new/usr/src/common/crypto/sha2/amd64/THIRDPARTYLICENSE.descrip	Mon Mar 24 15:32:08 2008
@@ -0,0 +1,1 @@
+PORTIONS OF SHA2 FUNCTIONALITY
--- /dev/null	Mon Mar 24 15:32:09 2008
+++ new/usr/src/common/crypto/sha2/amd64/sha512-x86_64.pl	Mon Mar 24 15:32:09 2008
@@ -0,0 +1,396 @@
+#!/usr/bin/env perl
+#
+# ====================================================================
+# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# project. Rights for redistribution and usage in source and binary
+# forms are granted according to the OpenSSL license.
+# ====================================================================
+#
+# sha256/512_block procedure for x86_64.
+#
+# 40% improvement over compiler-generated code on Opteron. On EM64T
+# sha256 was observed to run >80% faster and sha512 - >40%. No magical
+# tricks, just straight implementation... I really wonder why gcc
+# [being armed with inline assembler] fails to generate as fast code.
+# The only thing which is cool about this module is that it's very
+# same instruction sequence used for both SHA-256 and SHA-512. In
+# former case the instructions operate on 32-bit operands, while in
+# latter - on 64-bit ones. All I had to do is to get one flavor right,
+# the other one passed the test right away:-)
+#
+# sha256_block runs in ~1005 cycles on Opteron, which gives you
+# asymptotic performance of 64*1000/1005=63.7MBps times CPU clock
+# frequency in GHz. sha512_block runs in ~1275 cycles, which results
+# in 128*1000/1275=100MBps per GHz. Is there room for improvement?
+# Well, if you compare it to IA-64 implementation, which maintains
+# X[16] in register bank[!], tends to 4 instructions per CPU clock
+# cycle and runs in 1003 cycles, 1275 is very good result for 3-way
+# issue Opteron pipeline and X[16] maintained in memory. So that *if*
+# there is a way to improve it, *then* the only way would be to try to
+# offload X[16] updates to SSE unit, but that would require "deeper"
+# loop unroll, which in turn would naturally cause size blow-up, not
+# to mention increased complexity! And once again, only *if* it's
+# actually possible to noticeably improve overall ILP, instruction
+# level parallelism, on a given CPU implementation in this case.
+#
+# Special note on Intel EM64T. While Opteron CPU exhibits perfect
+# perfromance ratio of 1.5 between 64- and 32-bit flavors [see above],
+# [currently available] EM64T CPUs apparently are far from it. On the
+# contrary, 64-bit version, sha512_block, is ~30% *slower* than 32-bit
+# sha256_block:-( This is presumably because 64-bit shifts/rotates
+# apparently are not atomic instructions, but implemented in microcode.
+
+#
+# OpenSolaris OS modifications
+#
+# Sun elects to use this software under the BSD license.
+#
+# This source originates from OpenSSL file sha512-x86_64.pl at
+# ftp://ftp.openssl.org/snapshot/openssl-0.9.8-stable-SNAP-20080131.tar.gz
+# (presumably for future OpenSSL release 0.9.8h), with these changes:
+#
+# 1. Added perl "use strict" and declared variables.
+#
+# 2. Added OpenSolaris ENTRY_NP/SET_SIZE macros from
+# /usr/include/sys/asm_linkage.h, .ident keywords, and lint(1B) guards.
+#
+# 3. Removed x86_64-xlate.pl script (not needed for as(1) or gas(1)
+# assemblers).  Replaced the .picmeup macro with assembler code.
+#
+# 4. Added 8 to $ctx, as OpenSolaris OS has an extra 4-byte field, "algotype",
+# at the beginning of SHA2_CTX (the next field is 8-byte aligned).
+#
+
+use strict;
+my ($code, $func, $TABLE, $SZ, @Sigma0, @Sigma1, @sigma0, @sigma1, $rounds,
+	@ROT, $A, $B, $C, $D, $E, $F, $G, $H, $T1, $a0, $a1, $a2, $i,
+	$ctx, $round, $inp, $Tbl, $_ctx, $_inp, $_end, $_rsp, $framesz);
+my $output = shift;
+open STDOUT,">$output";
+
+#
+# OpenSSL library:
+# void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num);
+# void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num);
+#
+# OpenSolaris OS:
+# void SHA512TransformBlocks(SHA2_CTX *ctx, const void *in, size_t num);
+# void SHA256TransformBlocks(SHA2_CTX *ctx, const void *in, size_t num);
+# Note: the OpenSolaris SHA2 structure has an extra 8 byte field at the
+# beginning (over OpenSSL's SHA512 or SHA256 structure).
+#
+
+if ($output =~ /512/) {
+	$func="SHA512TransformBlocks";
+	$TABLE="K512";
+	$SZ=8;
+	@ROT=($A,$B,$C,$D,$E,$F,$G,$H)=("%rax","%rbx","%rcx","%rdx",
+					"%r8", "%r9", "%r10","%r11");
+	($T1,$a0,$a1,$a2)=("%r12","%r13","%r14","%r15");
+	@Sigma0=(28,34,39);
+	@Sigma1=(14,18,41);
+	@sigma0=(1,  8, 7);
+	@sigma1=(19,61, 6);
+	$rounds=80;
+} else {
+	$func="SHA256TransformBlocks";
+	$TABLE="K256";
+	$SZ=4;
+	@ROT=($A,$B,$C,$D,$E,$F,$G,$H)=("%eax","%ebx","%ecx","%edx",
+					"%r8d","%r9d","%r10d","%r11d");
+	($T1,$a0,$a1,$a2)=("%r12d","%r13d","%r14d","%r15d");
+	@Sigma0=( 2,13,22);
+	@Sigma1=( 6,11,25);
+	@sigma0=( 7,18, 3);
+	@sigma1=(17,19,10);
+	$rounds=64;
+}
+
+$ctx="%rdi";	# 1st arg
+$round="%rdi";	# zaps $ctx
+$inp="%rsi";	# 2nd arg
+$Tbl="%rbp";
+
+$_ctx="16*$SZ+0*8(%rsp)";
+$_inp="16*$SZ+1*8(%rsp)";
+$_end="16*$SZ+2*8(%rsp)";
+$_rsp="16*$SZ+3*8(%rsp)";
+$framesz="16*$SZ+4*8";
+
+
+sub ROUND_00_15()
+{ my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
+
+$code.=<<___;
+	mov	$e,$a0
+	mov	$e,$a1
+	mov	$f,$a2
+
+	ror	\$$Sigma1[0],$a0
+	ror	\$$Sigma1[1],$a1
+	xor	$g,$a2			# f^g
+
+	xor	$a1,$a0
+	ror	\$`$Sigma1[2]-$Sigma1[1]`,$a1
+	and	$e,$a2			# (f^g)&e
+	mov	$T1,`$SZ*($i&0xf)`(%rsp)
+
+	xor	$a1,$a0			# Sigma1(e)
+	xor	$g,$a2			# Ch(e,f,g)=((f^g)&e)^g
+	add	$h,$T1			# T1+=h
+
+	mov	$a,$h
+	add	$a0,$T1			# T1+=Sigma1(e)
+
+	add	$a2,$T1			# T1+=Ch(e,f,g)
+	mov	$a,$a0
+	mov	$a,$a1
+
+	ror	\$$Sigma0[0],$h
+	ror	\$$Sigma0[1],$a0
+	mov	$a,$a2
+	add	($Tbl,$round,$SZ),$T1	# T1+=K[round]
+
+	xor	$a0,$h
+	ror	\$`$Sigma0[2]-$Sigma0[1]`,$a0
+	or	$c,$a1			# a|c
+
+	xor	$a0,$h			# h=Sigma0(a)
+	and	$c,$a2			# a&c
+	add	$T1,$d			# d+=T1
+
+	and	$b,$a1			# (a|c)&b
+	add	$T1,$h			# h+=T1
+
+	or	$a2,$a1			# Maj(a,b,c)=((a|c)&b)|(a&c)
+	lea	1($round),$round	# round++
+
+	add	$a1,$h			# h+=Maj(a,b,c)
+___
+}
+
+sub ROUND_16_XX()
+{ my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
+
+$code.=<<___;
+	mov	`$SZ*(($i+1)&0xf)`(%rsp),$a0
+	mov	`$SZ*(($i+14)&0xf)`(%rsp),$T1
+
+	mov	$a0,$a2
+
+	shr	\$$sigma0[2],$a0
+	ror	\$$sigma0[0],$a2
+
+	xor	$a2,$a0
+	ror	\$`$sigma0[1]-$sigma0[0]`,$a2
+
+	xor	$a2,$a0			# sigma0(X[(i+1)&0xf])
+	mov	$T1,$a1
+
+	shr	\$$sigma1[2],$T1
+	ror	\$$sigma1[0],$a1
+
+	xor	$a1,$T1
+	ror	\$`$sigma1[1]-$sigma1[0]`,$a1
+
+	xor	$a1,$T1			# sigma1(X[(i+14)&0xf])
+
+	add	$a0,$T1
+
+	add	`$SZ*(($i+9)&0xf)`(%rsp),$T1
+
+	add	`$SZ*($i&0xf)`(%rsp),$T1
+___
+	&ROUND_00_15(@_);
+}
+
+#
+# Execution begins here
+#
+
+$code=<<___;
+#if !defined(lint) && !defined(__lint)
+	.ident	"@(#)sha512-x86_64.pl	1.1	08/03/20 SMI"
+#include <sys/asm_linkage.h>
+
+ENTRY_NP($func)
+	push	%rbx
+	push	%rbp
+	push	%r12
+	push	%r13
+	push	%r14
+	push	%r15
+	mov	%rsp,%rbp		# copy %rsp
+	shl	\$4,%rdx		# num*16
+	sub	\$$framesz,%rsp
+	lea	($inp,%rdx,$SZ),%rdx	# inp+num*16*$SZ
+	and	\$-64,%rsp		# align stack frame
+	add	\$8,$ctx		# Skip OpenSolaris field, "algotype"
+	mov	$ctx,$_ctx		# save ctx, 1st arg
+	mov	$inp,$_inp		# save inp, 2nd arg
+	mov	%rdx,$_end		# save end pointer, "3rd" arg
+	mov	%rbp,$_rsp		# save copy of %rsp
+
+	/.picmeup $Tbl
+	/ The .picmeup pseudo-directive, from perlasm/x86_64_xlate.pl, puts
+	/ the address of the "next" instruction into the target register
+	/ ($Tbl).  This generates these 2 instructions:
+	lea	.Llea(%rip),$Tbl
+	/nop	/ .picmeup generates a nop for mod 8 alignment--not needed here
+
+.Llea:
+	lea	$TABLE-.($Tbl),$Tbl
+
+	mov	$SZ*0($ctx),$A
+	mov	$SZ*1($ctx),$B
+	mov	$SZ*2($ctx),$C
+	mov	$SZ*3($ctx),$D
+	mov	$SZ*4($ctx),$E
+	mov	$SZ*5($ctx),$F
+	mov	$SZ*6($ctx),$G
+	mov	$SZ*7($ctx),$H
+	jmp	.Lloop
+
+.align	16
+.Lloop:
+	xor	$round,$round
+___
+	for($i=0;$i<16;$i++) {
+		$code.="	mov	$SZ*$i($inp),$T1\n";
+		$code.="	bswap	$T1\n";
+		&ROUND_00_15($i,@ROT);
+		unshift(@ROT,pop(@ROT));
+	}
+$code.=<<___;
+	jmp	.Lrounds_16_xx
+.align	16
+.Lrounds_16_xx:
+___
+	for(;$i<32;$i++) {
+		&ROUND_16_XX($i,@ROT);
+		unshift(@ROT,pop(@ROT));
+	}
+
+$code.=<<___;
+	cmp	\$$rounds,$round
+	jb	.Lrounds_16_xx
+
+	mov	$_ctx,$ctx
+	lea	16*$SZ($inp),$inp
+
+	add	$SZ*0($ctx),$A
+	add	$SZ*1($ctx),$B
+	add	$SZ*2($ctx),$C
+	add	$SZ*3($ctx),$D
+	add	$SZ*4($ctx),$E
+	add	$SZ*5($ctx),$F
+	add	$SZ*6($ctx),$G
+	add	$SZ*7($ctx),$H
+
+	cmp	$_end,$inp
+
+	mov	$A,$SZ*0($ctx)
+	mov	$B,$SZ*1($ctx)
+	mov	$C,$SZ*2($ctx)
+	mov	$D,$SZ*3($ctx)
+	mov	$E,$SZ*4($ctx)
+	mov	$F,$SZ*5($ctx)
+	mov	$G,$SZ*6($ctx)
+	mov	$H,$SZ*7($ctx)
+	jb	.Lloop
+
+	mov	$_rsp,%rsp
+	pop	%r15
+	pop	%r14
+	pop	%r13
+	pop	%r12
+	pop	%rbp
+	pop	%rbx
+
+	ret
+SET_SIZE($func)
+
+___
+
+if ($SZ==4) {
+# SHA256
+$code.=<<___;
+.align	64
+.type	$TABLE,\@object
+$TABLE:
+	.long	0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
+	.long	0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
+	.long	0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
+	.long	0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
+	.long	0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
+	.long	0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
+	.long	0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
+	.long	0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
+	.long	0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
+	.long	0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
+	.long	0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
+	.long	0xd192e819,0xd6990624,0xf40e3585,0x106aa070
+	.long	0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
+	.long	0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
+	.long	0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
+	.long	0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
+___
+} else {
+# SHA512
+$code.=<<___;
+.align	64
+.type	$TABLE,\@object
+$TABLE:
+	.quad	0x428a2f98d728ae22,0x7137449123ef65cd
+	.quad	0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc
+	.quad	0x3956c25bf348b538,0x59f111f1b605d019
+	.quad	0x923f82a4af194f9b,0xab1c5ed5da6d8118
+	.quad	0xd807aa98a3030242,0x12835b0145706fbe
+	.quad	0x243185be4ee4b28c,0x550c7dc3d5ffb4e2
+	.quad	0x72be5d74f27b896f,0x80deb1fe3b1696b1
+	.quad	0x9bdc06a725c71235,0xc19bf174cf692694
+	.quad	0xe49b69c19ef14ad2,0xefbe4786384f25e3
+	.quad	0x0fc19dc68b8cd5b5,0x240ca1cc77ac9c65
+	.quad	0x2de92c6f592b0275,0x4a7484aa6ea6e483
+	.quad	0x5cb0a9dcbd41fbd4,0x76f988da831153b5
+	.quad	0x983e5152ee66dfab,0xa831c66d2db43210
+	.quad	0xb00327c898fb213f,0xbf597fc7beef0ee4
+	.quad	0xc6e00bf33da88fc2,0xd5a79147930aa725
+	.quad	0x06ca6351e003826f,0x142929670a0e6e70
+	.quad	0x27b70a8546d22ffc,0x2e1b21385c26c926
+	.quad	0x4d2c6dfc5ac42aed,0x53380d139d95b3df
+	.quad	0x650a73548baf63de,0x766a0abb3c77b2a8
+	.quad	0x81c2c92e47edaee6,0x92722c851482353b
+	.quad	0xa2bfe8a14cf10364,0xa81a664bbc423001
+	.quad	0xc24b8b70d0f89791,0xc76c51a30654be30
+	.quad	0xd192e819d6ef5218,0xd69906245565a910
+	.quad	0xf40e35855771202a,0x106aa07032bbd1b8
+	.quad	0x19a4c116b8d2d0c8,0x1e376c085141ab53
+	.quad	0x2748774cdf8eeb99,0x34b0bcb5e19b48a8
+	.quad	0x391c0cb3c5c95a63,0x4ed8aa4ae3418acb
+	.quad	0x5b9cca4f7763e373,0x682e6ff3d6b2b8a3
+	.quad	0x748f82ee5defb2fc,0x78a5636f43172f60
+	.quad	0x84c87814a1f0ab72,0x8cc702081a6439ec
+	.quad	0x90befffa23631e28,0xa4506cebde82bde9
+	.quad	0xbef9a3f7b2c67915,0xc67178f2e372532b
+	.quad	0xca273eceea26619c,0xd186b8c721c0c207
+	.quad	0xeada7dd6cde0eb1e,0xf57d4f7fee6ed178
+	.quad	0x06f067aa72176fba,0x0a637dc5a2c898a6
+	.quad	0x113f9804bef90dae,0x1b710b35131c471b
+	.quad	0x28db77f523047d84,0x32caab7b40c72493
+	.quad	0x3c9ebe0a15c9bebc,0x431d67c49c100d4c
+	.quad	0x4cc5d4becb3e42b6,0x597f299cfc657e2a
+	.quad	0x5fcb6fab3ad6faec,0x6c44198c4a475817
+___
+}
+$code.=<<___;
+
+#else
+	/* LINTED */
+	/* Nothing to be linted in this file--it's pure assembly source. */
+#endif /* !lint && !__lint */
+___
+
+$code =~ s/\`([^\`]*)\`/eval $1/gem;
+print $code;
+close STDOUT;
--- old/usr/src/common/crypto/sha2/sha2.c	Mon Mar 24 15:32:11 2008
+++ new/usr/src/common/crypto/sha2/sha2.c	Mon Mar 24 15:32:11 2008
@@ -1,11 +1,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	"@(#)sha2.c	1.7	07/04/10 SMI"
+#pragma ident	"@(#)sha2.c	1.8	08/03/20 SMI"
 
-
 /*
  * The basic framework for this code came from the reference
  * implementation for MD5.  That implementation is Copyright (C)
@@ -43,8 +42,10 @@
 #include <sys/sha2.h>
 #include <sys/sha2_consts.h>
 
-#ifndef _KERNEL
+#ifdef _KERNEL
+#include <sys/cmn_err.h>
 
+#else
 #include <strings.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -57,16 +58,22 @@
 #pragma weak SHA384Final = SHA2Final
 #pragma weak SHA512Final = SHA2Final
 
-#endif	/* !_KERNEL */
+#endif	/* _KERNEL */
 
-#ifdef _KERNEL
-#include <sys/cmn_err.h>
-#endif /* _KERNEL */
-
 static void Encode(uint8_t *, uint32_t *, size_t);
 static void Encode64(uint8_t *, uint64_t *, size_t);
+
+#if	defined(__amd64)
+#define	SHA512Transform(ctx, in) SHA512TransformBlocks((ctx), (in), 1)
+#define	SHA256Transform(ctx, in) SHA256TransformBlocks((ctx), (in), 1)
+
+void SHA512TransformBlocks(SHA2_CTX *ctx, const void *in, size_t num);
+void SHA256TransformBlocks(SHA2_CTX *ctx, const void *in, size_t num);
+
+#else
 static void SHA256Transform(SHA2_CTX *, const uint8_t *);
 static void SHA512Transform(SHA2_CTX *, const uint8_t *);
+#endif	/* __amd64 */
 
 static uint8_t PADDING[128] = { 0x80, /* all zeros */ };
 
@@ -135,16 +142,15 @@
 	    ((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
 
 
+#if	!defined(__amd64)
 /* SHA256 Transform */
 
 static void
 SHA256Transform(SHA2_CTX *ctx, const uint8_t *blk)
 {
-
 	uint32_t a = ctx->state.s32[0];
 	uint32_t b = ctx->state.s32[1];
 	uint32_t c = ctx->state.s32[2];
@@ -183,7 +189,7 @@
 		SHA256_CONST_60, SHA256_CONST_61, SHA256_CONST_62,
 		SHA256_CONST_63
 	};
-#endif
+#endif	/* __sparc */
 
 	if ((uintptr_t)blk & 0x3) {		/* not 4-byte aligned? */
 		bcopy(blk, ctx->buf_un.buf32,  sizeof (ctx->buf_un.buf32));
@@ -398,7 +404,7 @@
 		SHA512_CONST_75, SHA512_CONST_76, SHA512_CONST_77,
 		SHA512_CONST_78, SHA512_CONST_79
 	};
-#endif
+#endif	/* __sparc */
 
 
 	if ((uintptr_t)blk & 0x7) {		/* not 8-byte aligned? */
@@ -597,6 +603,7 @@
 	ctx->state.s64[7] += h;
 
 }
+#endif	/* !__amd64 */
 
 
 /*
@@ -749,7 +756,7 @@
  *          to update the context.
  *   input: SHA2_CTX *	: the context to update
  *          void *	: the message block
- *          size_t    : the length of the message block in bytes
+ *          size_t      : the length of the message block, in bytes
  *  output: void
  */
 
@@ -756,14 +763,19 @@
 void
 SHA2Update(SHA2_CTX *ctx, const void *inptr, size_t input_len)
 {
-	uint32_t i, buf_index, buf_len, buf_limit;
-	const uint8_t *input = inptr;
+	uint32_t	i, buf_index, buf_len, buf_limit;
+	const uint8_t	*input = inptr;
+	uint32_t	algotype = ctx->algotype;
+#if defined(__amd64)
+	uint32_t	block_count;
+#endif	/* !__amd64 */
 
+
 	/* check for noop */
 	if (input_len == 0)
 		return;
 
-	if (ctx->algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) {
+	if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) {
 		buf_limit = 64;
 
 		/* compute number of bytes mod 64 */
@@ -805,7 +817,7 @@
 		 */
 		if (buf_index) {
 			bcopy(input, &ctx->buf_un.buf8[buf_index], buf_len);
-			if (ctx->algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE)
+			if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE)
 				SHA256Transform(ctx, ctx->buf_un.buf8);
 			else
 				SHA512Transform(ctx, ctx->buf_un.buf8);
@@ -813,20 +825,41 @@
 			i = buf_len;
 		}
 
-
-		for (; i + buf_limit - 1 < input_len; i += buf_limit) {
-			if (ctx->algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE)
+#if !defined(__amd64)
+		if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) {
+			for (; i + buf_limit - 1 < input_len; i += buf_limit) {
 				SHA256Transform(ctx, &input[i]);
-			else
+			}
+		} else {
+			for (; i + buf_limit - 1 < input_len; i += buf_limit) {
 				SHA512Transform(ctx, &input[i]);
+			}
 		}
 
+#else
+		if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) {
+			block_count = (input_len - i) >> 6;
+			if (block_count > 0) {
+				SHA256TransformBlocks(ctx, &input[i],
+				    block_count);
+				i += block_count << 6;
+			}
+		} else {
+			block_count = (input_len - i) >> 7;
+			if (block_count > 0) {
+				SHA512TransformBlocks(ctx, &input[i],
+				    block_count);
+				i += block_count << 7;
+			}
+		}
+#endif	/* !__amd64 */
+
 		/*
 		 * general optimization:
 		 *
 		 * if i and input_len are the same, return now instead
 		 * of calling bcopy(), since the bcopy() in this case
-		 * will be an expensive nop.
+		 * will be an expensive noop.
 		 */
 
 		if (input_len == i)
@@ -845,7 +878,7 @@
  *
  * purpose: ends an sha2 digest operation, finalizing the message digest and
  *          zeroing the context.
- *   input: uchar_t *	: a buffer to store the digest in
+ *   input: uchar_t *	: a buffer to store the digest
  *			: The function actually uses void* because many
  *			: callers pass things other than uchar_t here.
  *          SHA2_CTX *  : the context to finalize, save, and zero
@@ -858,9 +891,9 @@
 	uint8_t		bitcount_be[sizeof (ctx->count.c32)];
 	uint8_t		bitcount_be64[sizeof (ctx->count.c64)];
 	uint32_t	index;
+	uint32_t	algotype = ctx->algotype;
 
-
-	if (ctx->algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) {
+	if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) {
 		index  = (ctx->count.c32[1] >> 3) & 0x3f;
 		Encode(bitcount_be, ctx->count.c32, sizeof (bitcount_be));
 		SHA2Update(ctx, PADDING, ((index < 56) ? 56 : 120) - index);
@@ -873,7 +906,7 @@
 		    sizeof (bitcount_be64));
 		SHA2Update(ctx, PADDING, ((index < 112) ? 112 : 240) - index);
 		SHA2Update(ctx, bitcount_be64, sizeof (bitcount_be64));
-		if (ctx->algotype <= SHA384_HMAC_GEN_MECH_INFO_TYPE) {
+		if (algotype <= SHA384_HMAC_GEN_MECH_INFO_TYPE) {
 			ctx->state.s64[6] = ctx->state.s64[7] = 0;
 			Encode64(digest, ctx->state.s64,
 			    sizeof (uint64_t) * 6);
--- old/usr/src/lib/libmd/Makefile.com	Mon Mar 24 15:32:16 2008
+++ new/usr/src/lib/libmd/Makefile.com	Mon Mar 24 15:32:16 2008
@@ -22,7 +22,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)Makefile.com	1.4	08/03/02 SMI"
+# ident	"@(#)Makefile.com	1.5	08/03/20 SMI"
 #
 
 # $LIBRARY is set in lower makefiles so we can have platform and
@@ -31,7 +31,8 @@
 #LIBRARY= libmd.a
 VERS= .1
 
-OBJECTS= md4.o md5.o $(MD5_PSR_OBJECTS) sha1.o $(SHA1_PSR_OBJECTS) sha2.o
+OBJECTS= md4.o md5.o $(MD5_PSR_OBJECTS) sha1.o $(SHA1_PSR_OBJECTS) \
+		sha2.o $(SHA2_PSR_OBJECTS)
 
 # Use $(SRC) to include makefiles rather than ../../ because the
 # platform subdirs are one level deeper so it would be ../../../ for them
--- old/usr/src/lib/libmd/amd64/Makefile	Mon Mar 24 15:32:20 2008
+++ new/usr/src/lib/libmd/amd64/Makefile	Mon Mar 24 15:32:20 2008
@@ -22,7 +22,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)Makefile	1.3	08/03/02 SMI"
+# ident	"@(#)Makefile	1.4	08/03/20 SMI"
 #
 
 LIBRARY= libmd.a
@@ -29,11 +29,12 @@
 
 MD5_PSR_OBJECTS = md5_amd64.o
 SHA1_PSR_OBJECTS = sha1-x86_64.o
+SHA2_PSR_OBJECTS = sha512-x86_64.o sha256-x86_64.o
 
 include ../Makefile.com
 include $(SRC)/lib/Makefile.lib.64
 
-CLEANFILES += md5_amd64.s sha1-x86_64.s
+CLEANFILES += md5_amd64.s sha1-x86_64.s sha512-x86_64.s sha256-x86_64.s
 
 # This prevents <sys/asm_linkage.h> from including C source:
 AS_CPPFLAGS += -D_ASM
@@ -40,16 +41,18 @@
 
 install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64)
 
-pics/md5_amd64.o: md5_amd64.s
+pics/%.o: %.s
 	$(COMPILE.s) -o $@ ${@F:.o=.s}
 	$(POST_PROCESS_O)
 
-pics/sha1-x86_64.o: sha1-x86_64.s
-	$(COMPILE.s) -o $@ ${@F:.o=.s}
-	$(POST_PROCESS_O)
-
 md5_amd64.s: $(COMDIR)/md5/amd64/md5_amd64.pl
 	$(PERL) $? $@
 
 sha1-x86_64.s: $(COMDIR)/sha1/amd64/sha1-x86_64.pl
+	$(PERL) $? $@
+
+sha512-x86_64.s: $(COMDIR)/sha2/amd64/sha512-x86_64.pl
+	$(PERL) $? $@
+
+sha256-x86_64.s: $(COMDIR)/sha2/amd64/sha512-x86_64.pl
 	$(PERL) $? $@
--- old/usr/src/lib/pkcs11/pkcs11_softtoken/Makefile.com	Mon Mar 24 15:32:24 2008
+++ new/usr/src/lib/pkcs11/pkcs11_softtoken/Makefile.com	Mon Mar 24 15:32:24 2008
@@ -22,7 +22,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)Makefile.com	1.5	08/02/26 SMI"
+# ident	"@(#)Makefile.com	1.6	08/03/20 SMI"
 #
 # lib/pkcs11/pkcs11_softtoken/Makefile.com
 #
@@ -95,8 +95,6 @@
 ECC_OBJECTS = $(ECC_COBJECTS) $(ECC_PSR_OBJECTS)
 MPI_OBJECTS = $(MPI_COBJECTS) $(MPI_PSR_OBJECTS)
 RSA_OBJECTS = $(RSA_COBJECTS) $(RSA_PSR_OBJECTS)
-SHA1_OBJECTS = $(SHA1_COBJECTS) $(SHA1_PSR_OBJECTS)
-SHA2_OBJECTS = $(SHA2_COBJECTS) $(SHA2_PSR_OBJECTS)
 BIGNUM_OBJECTS = $(BIGNUM_COBJECTS) $(BIGNUM_PSR_OBJECTS)
 
 BER_OBJECTS = bprint.o decode.o encode.o io.o
@@ -132,8 +130,6 @@
 	$(DES_OBJECTS)		\
 	$(MPI_OBJECTS)		\
 	$(RSA_OBJECTS)		\
-	$(SHA1_OBJECTS)		\
-	$(SHA2_OBJECTS)		\
 	$(BIGNUM_OBJECTS)	\
 	$(BER_OBJECTS)		\
 	$(ECC_OBJECTS)
@@ -163,8 +159,6 @@
 	$(DES_COBJECTS:%.o=$(DESDIR)/%.c) \
 	$(MPI_COBJECTS:%.o=$(MPIDIR)/%.c) \
 	$(RSA_COBJECTS:%.o=$(RSADIR)/%.c) \
-	$(SHA1_COBJECTS:%.o=$(SHA1DIR)/%.c) \
-	$(SHA2_COBJECTS:%.o=$(SHA2DIR)/%.c) \
 	$(BIGNUM_COBJECTS:%.o=$(BIGNUMDIR)/%.c) \
 	$(BIGNUM_PSR_SRCS) \
 	$(ECC_COBJECTS:%.o=$(ECCDIR)/%.c)
@@ -191,8 +185,6 @@
 	$(ARCFOUR_COBJECTS:%.o=$(ARCFOURDIR)/%.c) \
 	$(DES_COBJECTS:%.o=$(DESDIR)/%.c) \
 	$(RSA_COBJECTS:%.o=$(RSADIR)/%.c) \
-	$(SHA1_COBJECTS:%.o=$(SHA1DIR)/%.c) \
-	$(SHA2_COBJECTS:%.o=$(SHA2DIR)/%.c) \
 	$(BIGNUM_COBJECTS:%.o=$(BIGNUMDIR)/%.c) \
 	$(BIGNUM_PSR_SRCS)
 
@@ -230,14 +222,6 @@
 pics/%.o:	$(RSADIR)/%.c
 	$(COMPILE.c) -o $@ $<
 	$(POST_PROCESS_O)
-
-pics/%.o:	$(SHA1DIR)/%.c
-	$(COMPILE.c) -o $@ $<
-	$(POST_PROCESS_O)
-
-pics/%.o:	$(SHA2DIR)/%.c
-	$(COMPILE.c) -o $@ $<
-	$(POST_PROCESS_O)
 
 pics/%.o:	$(BIGNUMDIR)/%.c
 	$(COMPILE.c) -o $@ $(BIGNUM_CFG) $<
--- old/usr/src/lib/pkcs11/pkcs11_softtoken/amd64/Makefile	Mon Mar 24 15:32:29 2008
+++ new/usr/src/lib/pkcs11/pkcs11_softtoken/amd64/Makefile	Mon Mar 24 15:32:28 2008
@@ -22,15 +22,14 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)Makefile	1.4	08/02/26 SMI"
+# ident	"@(#)Makefile	1.5	08/03/20 SMI"
 #
 # lib/pkcs11/pkcs11_softtoken/amd64/Makefile
 
 AES_PSR_OBJECTS =
-ARCFOUR_PSR_OBJECTS =  arcfour_crypt_amd64.o
+ARCFOUR_PSR_OBJECTS =  arcfour-x86_64.o
 DES_PSR_OBJECTS =
 RSA_PSR_OBJECTS =
-SHA1_PSR_OBJECTS =
 BIGNUM_PSR_OBJECTS = bignum_amd64.o bignum_amd64_asm.o
 BIGNUM_PSR_PICS = $(BIGNUM_PSR_OBJECTS:%=pics/%)
 BIGNUM_CFG = -DPSR_MUL
@@ -43,6 +42,11 @@
 include ../Makefile.com
 include ../../../Makefile.lib.64
 
+#
+# Overrides
+#
+CLEANFILES	+= arcfour-x86_64.s
+
 install: all $(ROOTLIBS64) $(ROOTLINKS64)
 
 $(BIGNUM_PSR_PICS) := CFLAGS += $(C_BIGPICFLAGS) $(BIGNUM_CFG)
@@ -49,11 +53,13 @@
 
 LINTFLAGS64 += $(BIGNUM_CFG)
 
-pics/arcfour_crypt_amd64.o: $(ARCFOURDIR)/amd64/arcfour_crypt_amd64.s
-	$(COMPILE.s) -o $@ $(AS_BIGPICFLAGS) \
-		$(ARCFOURDIR)/amd64/arcfour_crypt_amd64.s
+pics/arcfour-x86_64.o: arcfour-x86_64.s
+	$(COMPILE.s) -o $@ $(AS_BIGPICFLAGS) ${@F:.o=.s}
 	$(POST_PROCESS_O)
 
+arcfour-x86_64.s: $(ARCFOURDIR)/amd64/arcfour-x86_64.pl
+	$(PERL) $? $@
+
 pics/%.o: $(BIGNUMDIR)/$(MACH64)/%.c
 	$(COMPILE.c) -o $@ $(C_BIGPICFLAGS) $(BIGNUM_CFG) $<
 	$(POST_PROCESS_O)
--- old/usr/src/lib/pkcs11/pkcs11_softtoken/i386/Makefile	Mon Mar 24 15:32:33 2008
+++ new/usr/src/lib/pkcs11/pkcs11_softtoken/i386/Makefile	Mon Mar 24 15:32:33 2008
@@ -22,7 +22,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)Makefile	1.5	08/02/26 SMI"
+# ident	"@(#)Makefile	1.6	08/03/20 SMI"
 #
 # lib/pkcs11/pkcs11_softtoken/i386/Makefile
 
@@ -30,7 +30,6 @@
 ARCFOUR_PSR_OBJECTS =
 DES_PSR_OBJECTS =
 RSA_PSR_OBJECTS =
-SHA1_PSR_OBJECTS =
 BIGNUM_PSR_OBJECTS = bignum_i386.o bignum_i386_asm.o
 BIGNUM_CFG = -DPSR_MUL -DHWCAP
 BIGNUM_PSR_SRCS = \
--- old/usr/src/pkgdefs/SUNWcsu/prototype_com	Mon Mar 24 15:32:37 2008
+++ new/usr/src/pkgdefs/SUNWcsu/prototype_com	Mon Mar 24 15:32:37 2008
@@ -22,7 +22,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)prototype_com	1.568	08/02/21 SMI"
+# ident	"@(#)prototype_com	1.569	08/03/20 SMI"
 #
 # This required package information file contains a list of package contents.
 # The 'pkgmk' command uses this file to identify the contents of a package
@@ -98,7 +98,7 @@
 f none usr/bin/devfree 555 root bin
 f none usr/bin/devreserv 555 root bin
 s none usr/bin/df=../sbin/df
-f none usr/bin/digest 555 root bin
+l none usr/bin/digest=../../usr/lib/isaexec
 f none usr/bin/dirname 555 root bin
 l none usr/bin/dispgid=../../usr/bin/ckgid
 l none usr/bin/dispuid=../../usr/bin/ckuid
@@ -177,7 +177,7 @@
 f none usr/bin/logins 750 root bin
 f none usr/bin/ls 555 root bin
 l none usr/bin/m68k=../../usr/bin/i286
-l none usr/bin/mac=../../usr/bin/digest
+l none usr/bin/mac=../../usr/lib/isaexec
 f none usr/bin/mach 555 root bin
 f none usr/bin/mail 2511 root mail
 f none usr/bin/mailx 2511 root mail
@@ -971,7 +971,7 @@
 f none usr/share/lib/terminfo/a/at386 644 root bin
 f none usr/share/lib/terminfo/a/at386-m 644 root bin
 d none usr/share/lib/terminfo/s 755 root bin
-f none usr/share/lib/terminfo/s/screen 644 root bin 
+f none usr/share/lib/terminfo/s/screen 644 root bin
 f none usr/share/lib/terminfo/s/screen-w 644 root bin
 f none usr/share/lib/terminfo/s/sun 644 root bin
 f none usr/share/lib/terminfo/s/sun-1 644 root bin
--- old/usr/src/pkgdefs/SUNWcsu/prototype_i386	Mon Mar 24 15:32:42 2008
+++ new/usr/src/pkgdefs/SUNWcsu/prototype_i386	Mon Mar 24 15:32:41 2008
@@ -19,10 +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.
 #
-# ident	"@(#)prototype_i386	1.91	07/09/18 SMI"
+# ident	"@(#)prototype_i386	1.92	08/03/20 SMI"
 #
 # This required package information file contains a list of package contents.
 # The 'pkgmk' command uses this file to identify the contents of a package
@@ -50,9 +50,11 @@
 f none usr/bin/i86/amt 555 root bin
 f none usr/bin/diskscan 555 root bin
 d none usr/bin/i86 755 root bin
+f none usr/bin/i86/digest 555 root bin
 f none usr/bin/i86/ksh93 555 root bin
 f none usr/bin/i86/newtask 4555 root sys
 f none usr/bin/i86/nohup 555 root bin
+l none usr/bin/i86/mac=digest
 f none usr/bin/i86/prctl 555 root bin
 f none usr/bin/i86/prstat 555 root bin
 f none usr/bin/i86/ps 555 root bin
@@ -105,8 +107,10 @@
 d none usr/bin/amd64 755 root bin
 f none usr/bin/amd64/amt 555 root bin
 f none usr/bin/amd64/crle 555 root bin
+f none usr/bin/amd64/digest 555 root bin
 f none usr/bin/amd64/ksh93 555 root bin
 f none usr/bin/amd64/ls 555 root bin
+l none usr/bin/amd64/mac=digest
 f none usr/bin/amd64/moe 555 root bin
 f none usr/bin/amd64/newtask 4555 root sys
 f none usr/bin/amd64/nohup 555 root bin
--- old/usr/src/pkgdefs/SUNWcsu/prototype_sparc	Mon Mar 24 15:32:46 2008
+++ new/usr/src/pkgdefs/SUNWcsu/prototype_sparc	Mon Mar 24 15:32:46 2008
@@ -19,10 +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.
 #
-# ident	"@(#)prototype_sparc	1.132	07/11/29 SMI"
+# ident	"@(#)prototype_sparc	1.133	08/03/20 SMI"
 #
 # This required package information file contains a list of package contents.
 # The 'pkgmk' command uses this file to identify the contents of a package
@@ -50,11 +50,15 @@
 f none usr/bin/sparcv7/ksh93 555 root bin
 l none usr/bin/sparcv7/rksh93=ksh93
 f none usr/bin/sparcv7/savecore 555 root bin
+f none usr/bin/sparcv7/digest 555 root bin
+l none usr/bin/sparcv7/mac=digest
 d none usr/bin/sparcv9 755 root bin
 f none usr/bin/sparcv9/amt 555 root bin
 f none usr/bin/sparcv9/crle 555 root bin
+f none usr/bin/sparcv9/digest 555 root bin
 f none usr/bin/sparcv9/ksh93 555 root bin
 f none usr/bin/sparcv9/ls 555 root bin
+l none usr/bin/sparcv9/mac=digest
 f none usr/bin/sparcv9/moe 555 root bin
 f none usr/bin/sparcv9/newtask 4555 root sys
 f none usr/bin/sparcv9/nohup 555 root bin
--- old/usr/src/tools/opensolaris/license-list	Mon Mar 24 15:32:50 2008
+++ new/usr/src/tools/opensolaris/license-list	Mon Mar 24 15:32:50 2008
@@ -65,7 +65,9 @@
 usr/src/cmd/which/THIRDPARTYLICENSE
 usr/src/cmd/xntpd/THIRDPARTYLICENSE
 usr/src/cmd/xstr/THIRDPARTYLICENSE
+usr/src/common/crypto/arcfour/amd64/THIRDPARTYLICENSE
 usr/src/common/crypto/sha1/amd64/THIRDPARTYLICENSE
+usr/src/common/crypto/sha2/amd64/THIRDPARTYLICENSE
 usr/src/common/openssl/LICENSE
 usr/src/grub/grub-0.95/COPYING
 usr/src/lib/gss_mechs/mech_krb5/THIRDPARTYLICENSE
--- old/usr/src/uts/common/sys/crypto/common.h	Mon Mar 24 15:32:55 2008
+++ new/usr/src/uts/common/sys/crypto/common.h	Mon Mar 24 15:32:54 2008
@@ -26,7 +26,7 @@
 #ifndef _SYS_CRYPTO_COMMON_H
 #define	_SYS_CRYPTO_COMMON_H
 
-#pragma ident	"@(#)common.h	1.26	08/01/04 SMI"
+#pragma ident	"@(#)common.h	1.27	08/03/20 SMI"
 
 /*
  * Header file for the common data structures of the cryptographic framework
@@ -187,15 +187,14 @@
 #define	SUN_CKM_ECDSA			"CKM_ECDSA"
 
 /* Shared operation context format for CKM_RC4 */
+typedef struct {
 #if defined(__amd64)
-typedef uint64_t arcfour_key_int_t;
+	uint32_t i, j;
+	uint32_t arr[256];
 #else
-typedef uchar_t arcfour_key_int_t;
+	uchar_t arr[256];
+	uchar_t i, j;
 #endif /* __amd64 */
-
-typedef struct {
-	arcfour_key_int_t arr[256];
-	arcfour_key_int_t i, j;
 	uint64_t pad;		/* For 64-bit alignment */
 } arcfour_state_t;
 
--- old/usr/src/uts/common/sys/sha2.h	Mon Mar 24 15:32:59 2008
+++ new/usr/src/uts/common/sys/sha2.h	Mon Mar 24 15:32:59 2008
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -26,7 +26,7 @@
 #ifndef _SYS_SHA2_H
 #define	_SYS_SHA2_H
 
-#pragma ident	"@(#)sha2.h	1.4	06/03/28 SMI"
+#pragma ident	"@(#)sha2.h	1.5	08/03/20 SMI"
 
 #include <sys/types.h>		/* for uint_* */
 
@@ -59,7 +59,7 @@
  * The contents of this structure are a private interface between the
  * Init/Update/Final calls of the functions defined below.
  * Callers must never attempt to read or write any of the fields
- * in this strucutre directly.
+ * in this structure directly.
  */
 typedef struct 	{
 	uint32_t algotype;		/* Algorithm Type */
--- old/usr/src/uts/intel/arcfour/Makefile	Mon Mar 24 15:33:03 2008
+++ new/usr/src/uts/intel/arcfour/Makefile	Mon Mar 24 15:33:03 2008
@@ -22,7 +22,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"@(#)Makefile	1.7	08/01/02 SMI"
+# ident	"@(#)Makefile	1.8	08/03/20 SMI"
 #
 #	This makefile drives the production of the ARCFOUR KEF provider.
 #
@@ -41,7 +41,7 @@
 MODULE		= arcfour
 LINTS		= $(ARCFOURPROV_OBJS:%.o=$(LINTS_DIR)/%.ln)
 ARCFOURPROV_OBJS_32 =
-ARCFOURPROV_OBJS_64 = arcfour_crypt_amd64.o
+ARCFOURPROV_OBJS_64 = arcfour-x86_64.o
 ARCFOURPROV_OBJS += $(ARCFOURPROV_OBJS_$(CLASS))
 OBJECTS		= $(ARCFOURPROV_OBJS:%=$(OBJS_DIR)/%)
 ROOTMODULE	= $(ROOT_CRYPTO_DIR)/$(MODULE)
@@ -65,6 +65,7 @@
 # Overrides
 #
 CPPFLAGS	+= -I$(COM_DIR)
+CLEANFILES	+= arcfour-x86_64.s
 
 #
 # For now, disable these lint checks; maintainers should endeavor
@@ -99,10 +100,12 @@
 #
 include $(UTSBASE)/intel/Makefile.targ
 
-$(OBJS_DIR)/arcfour_crypt_amd64.o: $(COM_DIR)/amd64/arcfour_crypt_amd64.s
-	$(COMPILE.s) -o $@ $(COM_DIR)/amd64/arcfour_crypt_amd64.s
+$(OBJS_DIR)/arcfour-x86_64.o: arcfour-x86_64.s
+	$(COMPILE.s) -o $@ ${@F:.o=.s}
 	$(POST_PROCESS_O)
 
-$(OBJS_DIR)/arcfour_crypt_amd64.ln: $(COM_DIR)/amd64/arcfour_crypt_amd64.s
-	@($(LHEAD) $(LINT.c) $(COM_DIR)/amd64/arcfour_crypt_amd64.s $(LTAIL))
+$(OBJS_DIR)/arcfour-x86_64.ln: arcfour-x86_64.s
+	@($(LHEAD) $(LINT.s) ${@F:.ln=.s} $(LTAIL))
 
+arcfour-x86_64.s: $(COM_DIR)/amd64/arcfour-x86_64.pl
+	$(PERL) $? $@
--- old/usr/src/uts/intel/sha2/Makefile	Mon Mar 24 15:33:07 2008
+++ new/usr/src/uts/intel/sha2/Makefile	Mon Mar 24 15:33:07 2008
@@ -19,10 +19,10 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"@(#)Makefile	1.3	06/11/02 SMI"
+#ident	"@(#)Makefile	1.4	08/03/20 SMI"
 #
 #	This makefile drives the production of the sha2 crypto kernel module.
 #
@@ -33,13 +33,17 @@
 #	Path to the base of the uts directory tree (usually /usr/src/uts).
 #
 UTSBASE	= ../..
+COMDIR	= $(COMMONBASE)/crypto/sha2
 
 #
 #	Define the module and object file sets.
 #
 MODULE		= sha2
-OBJECTS		= $(SHA2_OBJS:%=$(OBJS_DIR)/%)
 LINTS		= $(SHA2_OBJS:%.o=$(LINTS_DIR)/%.ln)
+SHA2_OBJS_32    =
+SHA2_OBJS_64    = sha512-x86_64.o sha256-x86_64.o
+SHA2_OBJS       += $(SHA2_OBJS_$(CLASS))
+OBJECTS		= $(SHA2_OBJS:%=$(OBJS_DIR)/%)
 ROOTMODULE	= $(ROOT_CRYPTO_DIR)/$(MODULE)
 ROOTLINK	= $(ROOT_MISC_DIR)/$(MODULE)
 
@@ -51,8 +55,8 @@
 #
 #	Override defaults
 #
+CLEANFILES += sha512-x86_64.s sha256-x86_64.s
 
-
 #
 #	Define targets
 #
@@ -98,3 +102,16 @@
 #	Include common targets.
 #
 include $(UTSBASE)/intel/Makefile.targ
+
+$(OBJS_DIR)/%.o: %.s
+	$(COMPILE.s) -o $@ ${@F:.o=.s}
+	$(POST_PROCESS_O)
+
+$(OBJS_DIR)/%.ln: %.s
+	@($(LHEAD) $(LINT.c) ${@F:.ln=.s} $(LTAIL))
+
+sha512-x86_64.s: $(COMDIR)/amd64/sha512-x86_64.pl
+	$(PERL) $? $@
+
+sha256-x86_64.s: $(COMDIR)/amd64/sha512-x86_64.pl
+	$(PERL) $? $@
