--- old/usr/src/common/bignum/README	Wed Feb 25 22:19:06 2009
+++ new/usr/src/common/bignum/README	Wed Feb 25 22:19:02 2009
@@ -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.
@@ -19,14 +18,14 @@
 #
 # CDDL HEADER END
 #
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
 
-A note on the file mont_mulf.c. It is used as a starting point
-for the following hand optimized assembly files.
+A note on the file mont_mulf.c.
 
+It is used as a starting point for the following hand optimized assembly files:
+
 - usr/src/common/bignum/sun4u/mont_mulf_v8plus.s
  This file is used in the 32-bit pkcs11_softtoken library.
 
@@ -33,7 +32,12 @@
 - usr/src/common/bignum/sun4u/mont_mulf_v9.s
  This file is used in the 64-bit pkcs11_softtoken library.
 
-- usr/src/uts/sun4u/rsa/mont_mulf.s
+- usr/src/common/bignum/sun4u/mont_mulf_kernel_v9.s
  This file is used in the kernel RSA module.
 
 We keep the .c file around for future reference.
+
+See file bignumimpl.c for information about these preprocessor symbols:
+	USE_FLOATING_POINT, PSR_MUL, HWCAP, UMUL64
+UMUL64 is set in bignum.h based on architecture.
+The other symbols are set in Makefiles, as appropriate.
--- old/usr/src/common/bignum/amd64/bignum_amd64.c	Wed Feb 25 22:19:19 2009
+++ new/usr/src/common/bignum/amd64/bignum_amd64.c	Wed Feb 25 22:19:15 2009
@@ -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,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains bignum implementation code that
  * is specific to AMD64, but which is still more appropriate
@@ -41,146 +38,18 @@
 #include "bignum.h"
 
 /*
- * The bignum interface deals only with arrays of 32-bit "digits".
- * The 64-bit bignum functions are internal implementation details.
- * If a bignum happens to be aligned on a 64-bit boundary
- * and its length is even, then the pure 64-bit implementation
- * can be used.
+ * The bignum interface deals with arrays of 64-bit "chunks" or "digits".
+ * Data should be aligned on 8-byte address boundaries for best performance.
  */
 
-#define	ISALIGNED64(p) (((uintptr_t)(p) & 7) == 0)
-#define	ISBIGNUM64(p, len) (ISALIGNED64(p) && (((len) & 1) == 0))
 
-#if defined(__lint)
-
-extern uint64_t *P64(uint32_t *addr);
-
-#else /* lint */
-
-#define	P64(addr) ((uint64_t *)addr)
-
-#endif /* lint */
-
-extern uint64_t big_mul_set_vec64(uint64_t *, uint64_t *, int, uint64_t);
-extern uint64_t big_mul_add_vec64(uint64_t *, uint64_t *, int, uint64_t);
-extern void big_mul_vec64(uint64_t *, uint64_t *, int, uint64_t *, int);
-extern void big_sqr_vec64(uint64_t *, uint64_t *, int);
-
-extern uint32_t big_mul_set_vec32(uint32_t *, uint32_t *, int, uint32_t);
-extern uint32_t big_mul_add_vec32(uint32_t *, uint32_t *, int, uint32_t);
-extern void big_mul_vec32(uint32_t *, uint32_t *, int, uint32_t *, int);
-extern void big_sqr_vec32(uint32_t *, uint32_t *, int);
-
-uint32_t big_mul_set_vec(uint32_t *, uint32_t *, int, uint32_t);
-uint32_t big_mul_add_vec(uint32_t *, uint32_t *, int, uint32_t);
-void big_mul_vec(uint32_t *, uint32_t *, int, uint32_t *, int);
-void big_sqr_vec(uint32_t *, uint32_t *, int);
-
-
 void
-big_mul_vec(uint32_t *r, uint32_t *a, int alen, uint32_t *b, int blen)
+big_mul_vec(BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int alen,
+    BIG_CHUNK_TYPE *b, int blen)
 {
-	if (!ISALIGNED64(r) || !ISBIGNUM64(a, alen) || !ISBIGNUM64(b, blen)) {
-		big_mul_vec32(r, a, alen, b, blen);
-		return;
-	}
+	int	i;
 
-	big_mul_vec64(P64(r), P64(a), alen / 2, P64(b), blen / 2);
-}
-
-void
-big_sqr_vec(uint32_t *r, uint32_t *a, int alen)
-{
-	if (!ISALIGNED64(r) || !ISBIGNUM64(a, alen)) {
-		big_mul_vec32(r, a, alen, a, alen);
-		return;
-	}
-	big_sqr_vec64(P64(r), P64(a), alen / 2);
-}
-
-/*
- * It is OK to cast the 64-bit carry to 32 bit.
- * There will be no loss, because although we are multiplying the vector, a,
- * by a uint64_t, its value cannot exceedthat of a uint32_t.
- */
-
-uint32_t
-big_mul_set_vec(uint32_t *r, uint32_t *a, int alen, uint32_t digit)
-{
-	if (!ISALIGNED64(r) || !ISBIGNUM64(a, alen))
-		return (big_mul_set_vec32(r, a, alen, digit));
-
-	return (big_mul_set_vec64(P64(r), P64(a), alen / 2, digit));
-}
-uint32_t
-big_mul_add_vec(uint32_t *r, uint32_t *a, int alen, uint32_t digit)
-{
-	if (!ISALIGNED64(r) || !ISBIGNUM64(a, alen))
-		return (big_mul_add_vec32(r, a, alen, digit));
-
-	return (big_mul_add_vec64(P64(r), P64(a), alen / 2, digit));
-}
-
-
-void
-big_mul_vec64(uint64_t *r, uint64_t *a, int alen, uint64_t *b, int blen)
-{
-	int i;
-
-	r[alen] = big_mul_set_vec64(r, a, alen, b[0]);
+	r[alen] = big_mul_set_vec(r, a, alen, b[0]);
 	for (i = 1; i < blen; ++i)
-		r[alen + i] = big_mul_add_vec64(r+i, a, alen, b[i]);
-}
-
-void
-big_mul_vec32(uint32_t *r, uint32_t *a, int alen, uint32_t *b, int blen)
-{
-	int i;
-
-	r[alen] = big_mul_set_vec32(r, a, alen, b[0]);
-	for (i = 1; i < blen; ++i)
-		r[alen + i] = big_mul_add_vec32(r+i, a, alen, b[i]);
-}
-
-void
-big_sqr_vec32(uint32_t *r, uint32_t *a, int alen)
-{
-	big_mul_vec32(r, a, alen, a, alen);
-}
-
-
-uint32_t
-big_mul_set_vec32(uint32_t *r, uint32_t *a, int alen, uint32_t digit)
-{
-	uint64_t p, d, cy;
-
-	d = (uint64_t)digit;
-	cy = 0;
-	while (alen != 0) {
-		p = (uint64_t)a[0] * d + cy;
-		r[0] = (uint32_t)p;
-		cy = p >> 32;
-		++r;
-		++a;
-		--alen;
-	}
-	return ((uint32_t)cy);
-}
-
-uint32_t
-big_mul_add_vec32(uint32_t *r, uint32_t *a, int alen, uint32_t digit)
-{
-	uint64_t p, d, cy;
-
-	d = (uint64_t)digit;
-	cy = 0;
-	while (alen != 0) {
-		p = r[0] + (uint64_t)a[0] * d + cy;
-		r[0] = (uint32_t)p;
-		cy = p >> 32;
-		++r;
-		++a;
-		--alen;
-	}
-	return ((uint32_t)cy);
+		r[alen + i] = big_mul_add_vec(r + i, a, alen, b[i]);
 }
--- old/usr/src/common/bignum/amd64/bignum_amd64_asm.s	Wed Feb 25 22:19:30 2009
+++ new/usr/src/common/bignum/amd64/bignum_amd64_asm.s	Wed Feb 25 22:19:27 2009
@@ -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,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/asm_linkage.h>
 
 #if defined(lint) || defined(__lint)
@@ -34,17 +31,17 @@
 
 /* ARGSUSED */
 uint64_t
-big_mul_set_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
+big_mul_set_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
 { return (0); }
 
 /* ARGSUSED */
 uint64_t
-big_mul_add_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
+big_mul_add_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
 { return (0); }
 
 /* ARGSUSED */
 void
-big_sqr_vec64(uint64_t *r, uint64_t *a, int len)
+big_sqr_vec(uint64_t *r, uint64_t *a, int len)
 {}
 
 #else	/* lint */
@@ -55,11 +52,8 @@
 /  the 64X64->128 bit  unsigned multiply instruction.
 /
 /  As defined in Sun's bignum library for pkcs11, bignums are
-/  composed of an array of 32-bit "digits" along with descriptive
-/  information.  The arrays of digits are only required to be
-/  aligned on 32-bit boundary.  This implementation works only
-/  when the two factors and the result happen to be 64 bit aligned
-/  and have an even number of digits.
+/  composed of an array of 64-bit "digits" or "chunks" along with
+/  descriptive information.
 /
 / ------------------------------------------------------------------------
 
@@ -68,9 +62,9 @@
 / r and a are 64 bit aligned.
 /
 / uint64_t
-/ big_mul_set_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
+/ big_mul_set_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
 /
-	ENTRY(big_mul_set_vec64)
+	ENTRY(big_mul_set_vec)
 	xorq	%rax, %rax		/ if (len == 0) return (0)
 	testq	%rdx, %rdx
 	jz	.L17
@@ -219,8 +213,9 @@
 .L17:
 	movq	%r9, %rax
 	ret
-	SET_SIZE(big_mul_set_vec64)
+	SET_SIZE(big_mul_set_vec)
 
+
 / ------------------------------------------------------------------------
 /
 /  Implementation of big_mul_add_vec which exploits
@@ -227,11 +222,8 @@
 /  the 64X64->128 bit  unsigned multiply instruction.
 /
 /  As defined in Sun's bignum library for pkcs11, bignums are
-/  composed of an array of 32-bit "digits" along with descriptive
-/  information.  The arrays of digits are only required to be
-/  aligned on 32-bit boundary.  This implementation works only
-/  when the two factors and the result happen to be 64 bit aligned
-/  and have an even number of digits.
+/  composed of an array of 64-bit "digits" or "chunks" along with
+/  descriptive information.
 /
 / ------------------------------------------------------------------------
 
@@ -240,9 +232,9 @@
 / r and a are 64 bit aligned.
 /
 / uint64_t
-/ big_mul_add_vec64(uint64_t *r, uint64_t *a, int len, uint64_t digit)
+/ big_mul_add_vec(uint64_t *r, uint64_t *a, int len, uint64_t digit)
 /
-	ENTRY(big_mul_add_vec64)
+	ENTRY(big_mul_add_vec)
 	xorq	%rax, %rax		/ if (len == 0) return (0)
 	testq	%rdx, %rdx
 	jz	.L27
@@ -436,13 +428,13 @@
 .L27:
 	movq	%r9, %rax
 	ret
-	SET_SIZE(big_mul_add_vec64)
+	SET_SIZE(big_mul_add_vec)
 
 
 / void
-/ big_sqr_vec64(uint64_t *r, uint64_t *a, int len)
+/ big_sqr_vec(uint64_t *r, uint64_t *a, int len)
 
-	ENTRY(big_sqr_vec64)
+	ENTRY(big_sqr_vec)
 	pushq	%rbx
 	pushq	%rbp
 	pushq	%r12
@@ -461,7 +453,7 @@
 	leaq	8(%r14), %rsi		/ arg2 = ta + 1
 	movq	%r15, %rdx		/ arg3 = tlen
 	movq	0(%r14), %rcx		/ arg4 = ta[0]
-	call	big_mul_set_vec64
+	call	big_mul_set_vec
 	movq	%rax, 0(%r13, %r15, 8)	/ tr[tlen] = cy
 .L31:
 	decq	%r15			/ --tlen
@@ -473,7 +465,7 @@
 	leaq	8(%r14), %rsi		/ arg2 = ta + 1
 	movq	%r15, %rdx		/ arg3 = tlen
 	movq	0(%r14), %rcx		/ arg4 = ta[0]
-	call	big_mul_add_vec64
+	call	big_mul_add_vec
 	movq	%rax, 0(%r13, %r15, 8)	/ tr[tlen] = cy
 	jmp	.L31
 
@@ -552,6 +544,6 @@
 
 	ret
 
-	SET_SIZE(big_sqr_vec64)
+	SET_SIZE(big_sqr_vec)
 
 #endif	/* lint */
--- old/usr/src/common/bignum/bignum.h	Wed Feb 25 22:19:40 2009
+++ new/usr/src/common/bignum/bignum.h	Wed Feb 25 22:19:38 2009
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -26,8 +26,6 @@
 #ifndef _BIGNUM_H
 #define	_BIGNUM_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -34,17 +32,18 @@
 
 #include <sys/types.h>
 
-#ifndef __sparcv9
-#define	BIGNUM_CHUNK_32
-#else
+#if defined(__sparcv9) || defined(__amd64) /* 64-bit chunk size */
 #ifndef UMUL64
-#define	UMUL64
+#define	UMUL64	/* 64-bit multiplication results are supported */
 #endif
+#else
+#define	BIGNUM_CHUNK_32
 #endif
 
 
 #define	BITSINBYTE	8
 
+/* Bignum "digits" (aka "chunks" or "words") are either 32- or 64-bits */
 #ifdef BIGNUM_CHUNK_32
 #define	BIG_CHUNK_SIZE		32
 #define	BIG_CHUNK_TYPE		uint32_t
@@ -53,6 +52,7 @@
 #define	BIG_CHUNK_ALLBITS	0xffffffff
 #define	BIG_CHUNK_LOWHALFBITS	0xffff
 #define	BIG_CHUNK_HALF_HIGHBIT	0x8000
+
 #else
 #define	BIG_CHUNK_SIZE		64
 #define	BIG_CHUNK_TYPE		uint64_t
@@ -65,7 +65,7 @@
 
 #define	BITLEN2BIGNUMLEN(x)	(((x) + BIG_CHUNK_SIZE - 1) / BIG_CHUNK_SIZE)
 #define	CHARLEN2BIGNUMLEN(x)	(((x) + sizeof (BIG_CHUNK_TYPE) - 1) / \
-				sizeof (BIG_CHUNK_TYPE))
+				    sizeof (BIG_CHUNK_TYPE))
 
 #define	BIGNUM_WORDSIZE	(BIG_CHUNK_SIZE / BITSINBYTE)  /* word size in bytes */
 #define	BIG_CHUNKS_FOR_160BITS	((160 + BIG_CHUNK_SIZE - 1) / BIG_CHUNK_SIZE)
@@ -78,10 +78,10 @@
  */
 typedef struct {
 	/* size and len in units of BIG_CHUNK_TYPE words  */
-	int size; /* size of memory allocated for value   */
-	int len;  /* number of words that hold valid data in value */
-	int sign; /* 1 for nonnegative, -1 for negative   */
-	int malloced; /* 1 if value was malloced 0 if not */
+	uint32_t	size;	/* size of memory allocated for value  */
+	uint32_t	len;	/* number of valid data words in value */
+	int		sign;	/* 1 for nonnegative, -1 for negative  */
+	int		malloced; /* 1 if value was malloced, 0 if not */
 	BIG_CHUNK_TYPE *value;
 } BIGNUM;
 
--- old/usr/src/common/bignum/bignumimpl.c	Wed Feb 25 22:19:52 2009
+++ new/usr/src/common/bignum/bignumimpl.c	Wed Feb 25 22:19:50 2009
@@ -19,16 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
-#define	big_div_pos_fast big_div_pos
-
-#include "bignum.h"
-
 /*
  * Configuration guide
  * -------------------
@@ -50,7 +44,7 @@
  *
  * HWCAP
  *   Meaning: Call multiply support functions through a function pointer.
- *   On x86, there are multiple implementations for differnt hardware
+ *   On x86, there are multiple implementations for different hardware
  *   capabilities, such as MMX, SSE2, etc.  Tests are made at run-time, when
  *   a function is first used.  So, the support functions are called through
  *   a function pointer.  There is no need for that on Sparc, because there
@@ -68,16 +62,33 @@
  */
 
 
+#include <sys/types.h>
+#include "bignum.h"
+
 #ifdef	_KERNEL
 #include <sys/ddi.h>
 #include <sys/mdesc.h>
 #include <sys/crypto/common.h>
 
-#include <sys/types.h>
 #include <sys/kmem.h>
 #include <sys/param.h>
 #include <sys/sunddi.h>
 
+#else
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#define	ASSERT	assert
+#endif	/* _KERNEL */
+
+#ifdef	_LP64 /* truncate 64-bit size_t to 32-bits */
+#define	UI32(ui)	((uint32_t)ui)
+#else /* size_t already 32-bits */
+#define	UI32(ui)	(ui)
+#endif
+
+
+#ifdef	_KERNEL
 #define	big_malloc(size)	kmem_alloc(size, KM_NOSLEEP)
 #define	big_free(ptr, size)	kmem_free(ptr, size)
 
@@ -95,11 +106,6 @@
 
 #else	/* _KERNEL */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#define	ASSERT	assert
-
 #ifndef MALLOC_DEBUG
 
 #define	big_malloc(size)	malloc(size)
@@ -126,6 +132,11 @@
 
 #define	big_realloc(x, y, z) realloc((x), (z))
 
+
+/*
+ * printbignum()
+ * Print a BIGNUM type to stdout.
+ */
 void
 printbignum(char *aname, BIGNUM *a)
 {
@@ -135,13 +146,13 @@
 	for (i = a->len - 1; i >= 0; i--) {
 #ifdef BIGNUM_CHUNK_32
 		(void) printf("%08x ", a->value[i]);
-		if ((i % 8 == 0) && (i != 0)) {
+		if (((i & (BITSINBYTE - 1)) == 0) && (i != 0)) {
 			(void) printf("\n");
 		}
 #else
 		(void) printf("%08x %08x ", (uint32_t)((a->value[i]) >> 32),
 		    (uint32_t)((a->value[i]) & 0xffffffff));
-		if ((i % 4 == 0) && (i != 0)) {
+		if (((i & 3) == 0) && (i != 0)) { /* end of this chunk */
 			(void) printf("\n");
 		}
 #endif
@@ -152,11 +163,27 @@
 #endif	/* _KERNEL */
 
 
-/* size in BIG_CHUNK_SIZE-bit words */
+/*
+ * big_init()
+ * Initialize and allocate memory for a BIGNUM type.
+ *
+ * big_init(number, size) is equivalent to big_init1(number, size, NULL, 0)
+ *
+ * Note: call big_finish() to free memory allocated by big_init().
+ *
+ * Input:
+ * number	Uninitialized memory for BIGNUM
+ * size		Minimum size, in BIG_CHUNK_SIZE-bit words, required for BIGNUM
+ *
+ * Output:
+ * number	Initialized BIGNUM
+ *
+ * Return BIG_OK on success or BIG_NO_MEM for an allocation error.
+ */
 BIG_ERR_CODE
 big_init(BIGNUM *number, int size)
 {
-	number->value = big_malloc(sizeof (BIG_CHUNK_TYPE) * size);
+	number->value = big_malloc(BIGNUM_WORDSIZE * size);
 	if (number->value == NULL) {
 		return (BIG_NO_MEM);
 	}
@@ -167,12 +194,32 @@
 	return (BIG_OK);
 }
 
-/* size in BIG_CHUNK_SIZE-bit words */
+
+/*
+ * big_init1()
+ * Initialize and, if needed, allocate memory for a BIGNUM type.
+ * Use the buffer passed, buf, if any, instad of allocating memory
+ * if it's at least "size" bytes.
+ *
+ * Note: call big_finish() to free memory allocated by big_init().
+ *
+ * Input:
+ * number	Uninitialized memory for BIGNUM
+ * size		Minimum size, in BIG_CHUNK_SIZE-bit words, required for BIGNUM
+ * buf		Buffer for storing a BIGNUM.
+ *		If NULL, big_init1() will allocate a buffer
+ * bufsize	Size, in BIG_CHUNK_SIZE_bit words, of buf
+ *
+ * Output:
+ * number	Initialized BIGNUM
+ *
+ * Return BIG_OK on success or BIG_NO_MEM for an allocation error.
+ */
 BIG_ERR_CODE
 big_init1(BIGNUM *number, int size, BIG_CHUNK_TYPE *buf, int bufsize)
 {
 	if ((buf == NULL) || (size > bufsize)) {
-		number->value = big_malloc(sizeof (BIG_CHUNK_TYPE) * size);
+		number->value = big_malloc(BIGNUM_WORDSIZE * size);
 		if (number->value == NULL) {
 			return (BIG_NO_MEM);
 		}
@@ -183,18 +230,22 @@
 		number->size = bufsize;
 		number->malloced = 0;
 	}
-		number->len = 0;
-		number->sign = 1;
+	number->len = 0;
+	number->sign = 1;
 
 	return (BIG_OK);
 }
 
+
+/*
+ * big_finish()
+ * Free memory, if any, allocated by big_init() or big_init1().
+ */
 void
 big_finish(BIGNUM *number)
 {
 	if (number->malloced == 1) {
-		big_free(number->value,
-		    sizeof (BIG_CHUNK_TYPE) * number->size);
+		big_free(number->value, BIGNUM_WORDSIZE * number->size);
 		number->malloced = 0;
 	}
 }
@@ -201,8 +252,8 @@
 
 
 /*
- *  bn->size should be at least
- * (len + sizeof (BIG_CHUNK_TYPE) - 1) / sizeof (BIG_CHUNK_TYPE) bytes
+ * bn->size should be at least
+ * (len + BIGNUM_WORDSIZE - 1) / BIGNUM_WORDSIZE bytes
  * converts from byte-big-endian format to bignum format (words in
  * little endian order, but bytes within the words big endian)
  */
@@ -209,40 +260,43 @@
 void
 bytestring2bignum(BIGNUM *bn, uchar_t *kn, size_t len)
 {
-	int		i, j, offs;
+	int		i, j;
+	uint32_t	offs;
+	const uint32_t	slen = UI32(len);
 	BIG_CHUNK_TYPE	word;
 	uchar_t		*knwordp;
 
-#ifdef	_LP64
-	offs = (uint32_t)len % sizeof (BIG_CHUNK_TYPE);
-	bn->len = (uint32_t)len / sizeof (BIG_CHUNK_TYPE);
+	if (slen == 0) {
+		bn->len = 1;
+		bn->value[0] = 0;
+		return;
+	}
 
-	for (i = 0; i < (uint32_t)len / sizeof (BIG_CHUNK_TYPE); i++) {
-#else	/* !_LP64 */
-	offs = len % sizeof (BIG_CHUNK_TYPE);
-	bn->len = len / sizeof (BIG_CHUNK_TYPE);
-	for (i = 0; i < len / sizeof (BIG_CHUNK_TYPE); i++) {
-#endif	/* _LP64 */
-		knwordp = &(kn[len - sizeof (BIG_CHUNK_TYPE) * (i + 1)]);
+	offs = slen % BIGNUM_WORDSIZE;
+	bn->len = slen / BIGNUM_WORDSIZE;
+
+	for (i = 0; i < slen / BIGNUM_WORDSIZE; i++) {
+		knwordp = &(kn[slen - BIGNUM_WORDSIZE * (i + 1)]);
 		word = knwordp[0];
-		for (j = 1; j < sizeof (BIG_CHUNK_TYPE); j++) {
-			word = (word << 8)+ knwordp[j];
+		for (j = 1; j < BIGNUM_WORDSIZE; j++) {
+			word = (word << BITSINBYTE) + knwordp[j];
 		}
 		bn->value[i] = word;
 	}
 	if (offs > 0) {
 		word = kn[0];
-		for (i = 1; i < offs; i++) word = (word << 8) + kn[i];
+		for (i = 1; i < offs; i++) word = (word << BITSINBYTE) + kn[i];
 		bn->value[bn->len++] = word;
 	}
-	while ((bn->len > 1) && (bn->value[bn->len-1] == 0)) {
+	while ((bn->len > 1) && (bn->value[bn->len - 1] == 0)) {
 		bn->len --;
 	}
 }
 
+
 /*
  * copies the least significant len bytes if
- * len < bn->len * sizeof (BIG_CHUNK_TYPE)
+ * len < bn->len * BIGNUM_WORDSIZE
  * converts from bignum format to byte-big-endian format.
  * bignum format is words of type  BIG_CHUNK_TYPE in little endian order.
  */
@@ -249,56 +303,38 @@
 void
 bignum2bytestring(uchar_t *kn, BIGNUM *bn, size_t len)
 {
-	int		i, j, offs;
+	int		i, j;
+	uint32_t	offs;
+	const uint32_t	slen = UI32(len);
 	BIG_CHUNK_TYPE	word;
 
-	if (len < sizeof (BIG_CHUNK_TYPE) * bn->len) {
-#ifdef	_LP64
-		for (i = 0; i < (uint32_t)len / sizeof (BIG_CHUNK_TYPE); i++) {
-#else	/* !_LP64 */
-		for (i = 0; i < len / sizeof (BIG_CHUNK_TYPE); i++) {
-#endif	/* _LP64 */
+	if (len < BIGNUM_WORDSIZE * bn->len) {
+		for (i = 0; i < slen / BIGNUM_WORDSIZE; i++) {
 			word = bn->value[i];
-			for (j = 0; j < sizeof (BIG_CHUNK_TYPE); j++) {
-				kn[len - sizeof (BIG_CHUNK_TYPE) * i - j - 1] =
+			for (j = 0; j < BIGNUM_WORDSIZE; j++) {
+				kn[slen - BIGNUM_WORDSIZE * i - j - 1] =
 				    word & 0xff;
-				word = word >> 8;
+				word = word >> BITSINBYTE;
 			}
 		}
-#ifdef	_LP64
-		offs = (uint32_t)len % sizeof (BIG_CHUNK_TYPE);
-#else	/* !_LP64 */
-		offs = len % sizeof (BIG_CHUNK_TYPE);
-#endif	/* _LP64 */
+		offs = slen % BIGNUM_WORDSIZE;
 		if (offs > 0) {
-			word = bn->value[len / sizeof (BIG_CHUNK_TYPE)];
-#ifdef	_LP64
-			for (i =  (uint32_t)len % sizeof (BIG_CHUNK_TYPE);
-			    i > 0; i --) {
-#else	/* !_LP64 */
-			for (i = len % sizeof (BIG_CHUNK_TYPE);
-			    i > 0; i --) {
-#endif	/* _LP64 */
+			word = bn->value[slen / BIGNUM_WORDSIZE];
+			for (i =  slen % BIGNUM_WORDSIZE; i > 0; i --) {
 				kn[i - 1] = word & 0xff;
-				word = word >> 8;
+				word = word >> BITSINBYTE;
 			}
 		}
 	} else {
 		for (i = 0; i < bn->len; i++) {
 			word = bn->value[i];
-			for (j = 0; j < sizeof (BIG_CHUNK_TYPE); j++) {
-				kn[len - sizeof (BIG_CHUNK_TYPE) * i - j - 1] =
+			for (j = 0; j < BIGNUM_WORDSIZE; j++) {
+				kn[slen - BIGNUM_WORDSIZE * i - j - 1] =
 				    word & 0xff;
-				word = word >> 8;
+				word = word >> BITSINBYTE;
 			}
 		}
-#ifdef	_LP64
-		for (i = 0;
-		    i < (uint32_t)len - sizeof (BIG_CHUNK_TYPE) * bn->len;
-		    i++) {
-#else	/* !_LP64 */
-		for (i = 0; i < len - sizeof (BIG_CHUNK_TYPE) * bn->len; i++) {
-#endif	/* _LP64 */
+		for (i = 0; i < slen - BIGNUM_WORDSIZE * bn->len; i++) {
 			kn[i] = 0;
 		}
 	}
@@ -315,7 +351,7 @@
 	while ((l > 0) && (a->value[l] == 0)) {
 		l--;
 	}
-	b = sizeof (BIG_CHUNK_TYPE) * BITSINBYTE;
+	b = BIG_CHUNK_SIZE;
 	c = a->value[l];
 	while ((b > 1) && ((c & BIG_CHUNK_HIGHBIT) == 0)) {
 		c = c << 1;
@@ -322,7 +358,7 @@
 		b--;
 	}
 
-	return (l * sizeof (BIG_CHUNK_TYPE) * BITSINBYTE + b);
+	return (l * BIG_CHUNK_SIZE + b);
 }
 
 
@@ -340,11 +376,11 @@
 	if (dest->size < len) {
 		if (dest->malloced == 1) {
 			newptr = (BIG_CHUNK_TYPE *)big_realloc(dest->value,
-			    sizeof (BIG_CHUNK_TYPE) * dest->size,
-			    sizeof (BIG_CHUNK_TYPE) * len);
+			    BIGNUM_WORDSIZE * dest->size,
+			    BIGNUM_WORDSIZE * len);
 		} else {
 			newptr = (BIG_CHUNK_TYPE *)
-			    big_malloc(sizeof (BIG_CHUNK_TYPE) * len);
+			    big_malloc(BIGNUM_WORDSIZE * len);
 			if (newptr != NULL) {
 				dest->malloced = 1;
 			}
@@ -375,10 +411,10 @@
 		return (BIG_OK);
 	if (number->malloced) {
 		number->value = big_realloc(number->value,
-		    sizeof (BIG_CHUNK_TYPE) * number->size,
-		    sizeof (BIG_CHUNK_TYPE) * size);
+		    BIGNUM_WORDSIZE * number->size,
+		    BIGNUM_WORDSIZE * size);
 	} else {
-		newptr = big_malloc(sizeof (BIG_CHUNK_TYPE) * size);
+		newptr = big_malloc(BIGNUM_WORDSIZE * size);
 		if (newptr != NULL) {
 			for (i = 0; i < number->size; i++) {
 				newptr[i] = number->value[i];
@@ -561,7 +597,7 @@
 			}
 		}
 	} else {
-		i = aa->len-1;
+		i = aa->len - 1;
 	}
 	for (; i >= 0; i--) {
 		if (aa->value[i] > bb->value[i]) {
@@ -795,8 +831,8 @@
 int
 big_cmp_abs_high(BIGNUM *aa, BIGNUM *bb)
 {
-	int lendiff;
-	BIGNUM aa1;
+	int		lendiff;
+	BIGNUM		aa1;
 
 	lendiff = aa->len - bb->len;
 	aa1.len = bb->len;
@@ -912,7 +948,7 @@
 	cy = aa->value[0] >> offs;
 	for (i = 1; i < aa->len; i++) {
 		ai = aa->value[i];
-		result->value[i-1] = (ai << (BIG_CHUNK_SIZE - offs)) | cy;
+		result->value[i - 1] = (ai << (BIG_CHUNK_SIZE - offs)) | cy;
 		cy = ai >> offs;
 	}
 	result->len = aa->len;
@@ -926,7 +962,7 @@
  * it is assumed that aa and bb are positive
  */
 BIG_ERR_CODE
-big_div_pos_fast(BIGNUM *result, BIGNUM *remainder, BIGNUM *aa, BIGNUM *bb)
+big_div_pos(BIGNUM *result, BIGNUM *remainder, BIGNUM *aa, BIGNUM *bb)
 {
 	BIG_ERR_CODE	err = BIG_OK;
 	int		i, alen, blen, tlen, rlen, offs;
@@ -1077,6 +1113,7 @@
 	return (err);
 }
 
+
 /*
  * If there is no processor-specific integer implementation of
  * the lower level multiply functions, then this code is provided
@@ -1106,7 +1143,7 @@
 
 #define	MUL_SET_VEC_ROUND_PREFETCH(R) \
 	p = pf * d; \
-	pf = (uint64_t)a[R+1]; \
+	pf = (uint64_t)a[R + 1]; \
 	t = p + cy; \
 	r[R] = (uint32_t)t; \
 	cy = t >> 32
@@ -1120,7 +1157,7 @@
 #define	MUL_ADD_VEC_ROUND_PREFETCH(R) \
 	t = (uint64_t)r[R]; \
 	p = pf * d; \
-	pf = (uint64_t)a[R+1]; \
+	pf = (uint64_t)a[R + 1]; \
 	t = p + t + cy; \
 	r[R] = (uint32_t)t; \
 	cy = t >> 32
@@ -1242,10 +1279,10 @@
 void
 big_sqr_vec(uint32_t *r, uint32_t *a, int len)
 {
-	uint32_t *tr, *ta;
-	int tlen, row, col;
-	uint64_t p, s, t, t2, cy;
-	uint32_t d;
+	uint32_t	*tr, *ta;
+	int		tlen, row, col;
+	uint64_t	p, s, t, t2, cy;
+	uint32_t	d;
 
 	tr = r + 1;
 	ta = a;
@@ -1276,13 +1313,13 @@
 		cy = (t >> 32) + (t2 >> 32);
 		if (row == len - 1)
 			break;
-		p = ((uint64_t)r[col+1] << 1) + cy;
-		r[col+1] = (uint32_t)p;
+		p = ((uint64_t)r[col + 1] << 1) + cy;
+		r[col + 1] = (uint32_t)p;
 		cy = p >> 32;
 		++row;
 		col += 2;
 	}
-	r[col+1] = (uint32_t)cy;
+	r[col + 1] = (uint32_t)cy;
 }
 
 #else /* BIG_CHUNK_SIZE == 64 */
@@ -1361,11 +1398,12 @@
 	ASSERT(r != a);
 	r[len] = big_mul_set_vec(r, a, len, a[0]);
 	for (i = 1; i < len; ++i)
-		r[len + i] = big_mul_add_vec(r+i, a, len, a[i]);
+		r[len + i] = big_mul_add_vec(r + i, a, len, a[i]);
 }
 
 #endif /* BIG_CHUNK_SIZE == 32/64 */
 
+
 #else /* ! UMUL64 */
 
 #if (BIG_CHUNK_SIZE != 32)
@@ -1432,7 +1470,7 @@
 	ASSERT(r != a);
 	r[len] = big_mul_set_vec(r, a, len, a[0]);
 	for (i = 1; i < len; ++i)
-		r[len + i] = big_mul_add_vec(r+i, a, len, a[i]);
+		r[len + i] = big_mul_add_vec(r + i, a, len, a[i]);
 }
 
 #endif /* UMUL64 */
@@ -1445,7 +1483,7 @@
 
 	r[alen] = big_mul_set_vec(r, a, alen, b[0]);
 	for (i = 1; i < blen; ++i)
-		r[alen + i] = big_mul_add_vec(r+i, a, alen, b[i]);
+		r[alen + i] = big_mul_add_vec(r + i, a, alen, b[i]);
 }
 
 
@@ -1492,6 +1530,7 @@
 	bb->len = blen;
 
 	rsize = alen + blen;
+	ASSERT(rsize > 0);
 	if (result->size < rsize) {
 		err = big_extend(result, rsize);
 		if (err != BIG_OK) {
@@ -1549,14 +1588,14 @@
 	} else {
 		tmp1.len = rsize;
 	}
-	if ((err = big_copy(result, &tmp1)) != BIG_OK) {
-		return (err);
-	}
+
+	err = big_copy(result, &tmp1);
+
 	result->sign = sign;
 
 	big_finish(&tmp1);
 
-	return (BIG_OK);
+	return (err);
 }
 
 
@@ -1619,9 +1658,11 @@
 			rr[i] = rr[i + nlen];
 		}
 	}
-	for (i = nlen - 1; (i >= 0) && (rr[i] == 0); i--)
+
+	/* Remove leading zeros, but keep at least 1 digit: */
+	for (i = nlen - 1; (i > 0) && (rr[i] == 0); i--)
 		;
-	ret->len = i+1;
+	ret->len = i + 1;
 
 	return (BIG_OK);
 }
@@ -1764,8 +1805,8 @@
 	BIGNUM		tmp1;
 	BIG_CHUNK_TYPE	tmp1value[BIGTMPSIZE];
 	int		i, j, k, l, m, p;
-	int		bit, bitind, bitcount, groupbits, apowerssize;
-	int		nbits;
+	uint32_t	bit, bitind, bitcount, groupbits, apowerssize;
+	uint32_t	nbits;
 	BIG_ERR_CODE	err;
 
 	nbits = big_numbits(e);
@@ -1783,10 +1824,11 @@
 		return (err);
 	}
 
-	/* set the malloced bit to help cleanup */
+	/* clear the malloced bit to help cleanup */
 	for (i = 0; i < apowerssize; i++) {
 		apowers[i].malloced = 0;
 	}
+
 	for (i = 0; i < apowerssize; i++) {
 		if ((err = big_init1(&(apowers[i]), n->len, NULL, 0)) !=
 		    BIG_OK) {
@@ -1803,7 +1845,7 @@
 
 	for (i = 1; i < apowerssize; i++) {
 		if ((err = big_mont_mul(&tmp1, ma,
-		    &(apowers[i-1]), n, n0)) != BIG_OK) {
+		    &(apowers[i - 1]), n, n0)) != BIG_OK) {
 			goto ret;
 		}
 		(void) big_copy(&apowers[i], &tmp1);
@@ -1912,12 +1954,13 @@
     BIGNUM *tmp, BIG_CHUNK_TYPE n0)
 {
 
-	int		i, j, k, l, m, p, bit, bitind, bitcount, nlen;
+	int		i, j, k, l, m, p;
+	uint32_t	bit, bitind, bitcount, nlen;
 	double		dn0;
 	double		*dn, *dt, *d16r, *d32r;
 	uint32_t	*nint, *prod;
 	double		*apowers[APOWERS_MAX_SIZE];
-	int		nbits, groupbits, apowerssize;
+	uint32_t	nbits, groupbits, apowerssize;
 	BIG_ERR_CODE	err = BIG_OK;
 
 #ifdef _KERNEL
@@ -2077,7 +2120,7 @@
 					}
 					conv_i32_to_d32(d32r, prod, nlen);
 					mont_mulf_noconv(prod, d32r,
-					    apowers[p >> (l+1)],
+					    apowers[p >> (l + 1)],
 					    dt, dn, nint, nlen, dn0);
 					for (m = 0; m < l; m++) {
 						conv_i32_to_d32_and_d16(d32r,
@@ -2183,8 +2226,9 @@
 		goto ret1;
 	}
 
-	/* set the malloced bit to help cleanup */
+	/* clear the malloced bit to help cleanup */
 	rr.malloced = 0;
+
 	if (n_rr == NULL) {
 		if ((err = big_init1(&rr, 2 * n->len + 1,
 		    rrvalue, arraysize(rrvalue))) != BIG_OK) {
@@ -2381,7 +2425,8 @@
 	BIG_CHUNK_TYPE	t2value[BIGTMPSIZE];
 	BIG_CHUNK_TYPE	t3value[BIGTMPSIZE];
 	BIG_CHUNK_TYPE	prodvalue[BIGTMPSIZE];
-	int		i, nbits, diff, nrootbits, highbits;
+	int		i, diff;
+	uint32_t	nbits, nrootbits, highbits;
 	BIG_ERR_CODE	err;
 
 	nbits = big_numbits(n);
@@ -2551,7 +2596,8 @@
 BIG_ERR_CODE
 big_Lucas(BIGNUM *Lkminus1, BIGNUM *Lk, BIGNUM *p, BIGNUM *k, BIGNUM *n)
 {
-	int		m, w, i;
+	int		i;
+	uint32_t	m, w;
 	BIG_CHUNK_TYPE	bit;
 	BIGNUM		ki, tmp, tmp2;
 	BIG_CHUNK_TYPE	kivalue[BIGTMPSIZE];
@@ -2569,7 +2615,7 @@
 	    kivalue, arraysize(kivalue))) != BIG_OK)
 		return (err);
 
-	if ((err = big_init1(&tmp, 2 * n->len +1,
+	if ((err = big_init1(&tmp, 2 * n->len + 1,
 	    tmpvalue, arraysize(tmpvalue))) != BIG_OK)
 		goto ret1;
 
@@ -2692,7 +2738,7 @@
 		goto ret4;
 	}
 
-	(void) big_sub_pos(&o, n, &big_One); 	/* cannot fail */
+	(void) big_sub_pos(&o, n, &big_One);	/* cannot fail */
 	(void) big_copy(&nminus1, &o);		/* cannot fail */
 	e = 0;
 	while ((o.value[0] & 1) == 0) {
@@ -2781,16 +2827,13 @@
 
 #define	SIEVESIZE 1000
 
-uint32_t smallprimes[] =
-{
-3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
-51, 53, 59, 61, 67, 71, 73, 79, 83, 89, 91, 97
-};
 
-
 BIG_ERR_CODE
 big_nextprime_pos_ext(BIGNUM *result, BIGNUM *n, big_modexp_ncp_info_t *info)
 {
+	static const uint32_t smallprimes[] = {
+	    3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
+	    51, 53, 59, 61, 67, 71, 73, 79, 83, 89, 91, 97 };
 	BIG_ERR_CODE	err;
 	int		sieve[SIEVESIZE];
 	int		i;
--- old/usr/src/common/bignum/mont_mulf.c	Wed Feb 25 22:20:03 2009
+++ new/usr/src/common/bignum/mont_mulf.c	Wed Feb 25 22:20:00 2009
@@ -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,14 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * If compiled without -DRF_INLINE_MACROS then needs -lm at link time
  * If compiled with -DRF_INLINE_MACROS then needs conv.il at compile time
- * (i.e. cc <compileer_flags> -DRF_INLINE_MACROS conv.il mont_mulf.c )
+ * (i.e. cc <compiler_flags> -DRF_INLINE_MACROS conv.il mont_mulf.c )
  */
 
 #include <sys/types.h>
@@ -94,10 +91,10 @@
 conv_d16_to_i32(uint32_t *i32, double *d16, int64_t *tmp, int ilen)
 {
 	int i;
-	int64_t t, t1,		/* using int64_t and not uint64_t */
-		a, b, c, d;	/* because more efficient code is */
+	int64_t t, t1,		/* Using int64_t and not uint64_t */
+	    a, b, c, d;		/* because more efficient code is */
 				/* generated this way, and there  */
-				/* is no overflow  */
+				/* is no overflow.  */
 	t1 = 0;
 	a = (int64_t)d16[0];
 	b = (int64_t)d16[1];
@@ -201,8 +198,7 @@
 #pragma pipeloop(0)
 	for (i = 0; i < len - 3; i += 4) {
 		i16_to_d16_and_d32x4(&TwoToMinus16, &TwoTo16, &Zero,
-					&(d16[2*i]), &(d32[i]),
-					(float *)(&(i32[i])));
+		    &(d16[2*i]), &(d32[i]), (float *)(&(i32[i])));
 	}
 	for (; i < len; i++) {
 		a = i32[i];
@@ -279,24 +275,24 @@
 			}
 
 			digit = mod(lower32(b, Zero) * dn0,
-				    TwoToMinus16, TwoTo16);
+			    TwoToMinus16, TwoTo16);
 		}
 	} else {
 		a = dt[0] = pdm1[0] * pdm2[0];
 
 		dt[65] = dt[64] = dt[63] = dt[62] = dt[61] = dt[60] =
-			dt[59] = dt[58] = dt[57] = dt[56] = dt[55] =
-			dt[54] = dt[53] = dt[52] = dt[51] = dt[50] =
-			dt[49] = dt[48] = dt[47] = dt[46] = dt[45] =
-			dt[44] = dt[43] = dt[42] = dt[41] = dt[40] =
-			dt[39] = dt[38] = dt[37] = dt[36] = dt[35] =
-			dt[34] = dt[33] = dt[32] = dt[31] = dt[30] =
-			dt[29] = dt[28] = dt[27] = dt[26] = dt[25] =
-			dt[24] = dt[23] = dt[22] = dt[21] = dt[20] =
-			dt[19] = dt[18] = dt[17] = dt[16] = dt[15] =
-			dt[14] = dt[13] = dt[12] = dt[11] = dt[10] =
-			dt[9] = dt[8] = dt[7] = dt[6] = dt[5] = dt[4] =
-			dt[3] = dt[2] = dt[1] = Zero;
+		    dt[59] = dt[58] = dt[57] = dt[56] = dt[55] =
+		    dt[54] = dt[53] = dt[52] = dt[51] = dt[50] =
+		    dt[49] = dt[48] = dt[47] = dt[46] = dt[45] =
+		    dt[44] = dt[43] = dt[42] = dt[41] = dt[40] =
+		    dt[39] = dt[38] = dt[37] = dt[36] = dt[35] =
+		    dt[34] = dt[33] = dt[32] = dt[31] = dt[30] =
+		    dt[29] = dt[28] = dt[27] = dt[26] = dt[25] =
+		    dt[24] = dt[23] = dt[22] = dt[21] = dt[20] =
+		    dt[19] = dt[18] = dt[17] = dt[16] = dt[15] =
+		    dt[14] = dt[13] = dt[12] = dt[11] = dt[10] =
+		    dt[9] = dt[8] = dt[7] = dt[6] = dt[5] = dt[4] =
+		    dt[3] = dt[2] = dt[1] = Zero;
 
 		pdn_0 = pdn[0];
 		pdm1_0 = pdm1[0];
@@ -326,9 +322,9 @@
 			pdtj[26] += pdm1[13] *m2j + pdn[13] * digit;
 			pdtj[28] += pdm1[14] *m2j + pdn[14] * digit;
 			pdtj[30] += pdm1[15] *m2j + pdn[15] * digit;
-			/* no need for cleenup, cannot overflow */
+			/* no need for cleanup, cannot overflow */
 			digit = mod(lower32(b, Zero) * dn0,
-				    TwoToMinus16, TwoTo16);
+			    TwoToMinus16, TwoTo16);
 		}
 	}
 
--- old/usr/src/lib/pkcs11/libsoftcrypto/amd64/Makefile	Wed Feb 25 22:20:15 2009
+++ new/usr/src/lib/pkcs11/libsoftcrypto/amd64/Makefile	Wed Feb 25 22:20:12 2009
@@ -19,7 +19,7 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # lib/pkcs11/libsoftcrypto/amd64/Makefile
@@ -38,13 +38,12 @@
 BIGNUM_PSM_SRC= $(BIGNUM_DIR)/$(MACH64)/bignum_amd64.c \
 		$(BIGNUM_DIR)/$(MACH64)/bignum_amd64_asm.s
 
-
 include ../Makefile.com
 include $(SRC)/lib/Makefile.lib.64
 
-BIGNUM_FLAGS += -DPSR_MUL
-LINTFLAGS64 += $(BIGNUM_FLAGS) $(AES_FLAGS)
-
+CFLAGS		+= -xO4 -xcrossfile
+BIGNUM_FLAGS	+= -DPSR_MUL
+LINTFLAGS64	+= $(BIGNUM_FLAGS) $(AES_FLAGS)
 CLEANFILES      += arcfour-x86_64.s
 
 LDLIBS  += -lc
@@ -52,11 +51,11 @@
 
 install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64)
 
-arcfour-x86_64.s: $(ARCFOUR_DIR)/amd64/arcfour-x86_64.pl
+arcfour-x86_64.s:	$(ARCFOUR_DIR)/amd64/arcfour-x86_64.pl
 	$(PERL) $? $@
 
 pics/%.o:	$(AES_DIR)/$(MACH64)/%.c
-	$(COMPILE.c) $(AES_FLAGS) -o $@ $< 
+	$(COMPILE.c) $(AES_FLAGS) -o $@ $<
 	$(POST_PROCESS_O)
 
 pics/%.o:	$(AES_DIR)/$(MACH64)/%.s
@@ -64,7 +63,7 @@
 	$(POST_PROCESS_O)
 
 pics/%.o:	$(BIGNUM_DIR)/$(MACH64)/%.c
-	$(COMPILE.c) $(BIGNUM_FLAGS) -o $@ $< 
+	$(COMPILE.c) $(BIGNUM_FLAGS) -o $@ $<
 	$(POST_PROCESS_O)
 
 pics/%.o:	$(BIGNUM_DIR)/$(MACH64)/%.s
@@ -71,7 +70,7 @@
 	$(COMPILE64.s) $(BIGNUM_FLAGS) -o $@ $<
 	$(POST_PROCESS_O)
 
-pics/%.o: arcfour-x86_64.s
+pics/%.o:	arcfour-x86_64.s
 	$(COMPILE64.s) $(ARCFOUR_FLAGS) -o $@ $<
 	$(POST_PROCESS_O)
 
--- old/usr/src/uts/intel/bignum/Makefile.64	Wed Feb 25 22:20:25 2009
+++ new/usr/src/uts/intel/bignum/Makefile.64	Wed Feb 25 22:20:22 2009
@@ -19,11 +19,9 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	Configuration and targets for bignum module
 #	specific to AMD 64-bit architecture, amd64.
 #
@@ -45,7 +43,7 @@
 # general-purpose registers is faster than any MMX or SSE2 implementation.
 
 BIGNUM_CFG = -DPSR_MUL
-
+CFLAGS	+= -xO4 -xcrossfile
 $(OBJS_DIR)/bignumimpl.o $(LINTS_DIR)/bignumimpl.ln := \
 	CPPFLAGS += $(BIGNUM_CFG)
 $(OBJS_DIR)/bignum_amd64.o $(LINTS_DIR)/bignum_amd64.ln := \
@@ -52,12 +50,13 @@
 	CPPFLAGS += $(BIGNUM_CFG)
 
 $(OBJS_DIR)/bignum_amd64.o: $(BIGNUMDIR)/amd64/bignum_amd64.c
-	$(COMPILE.c) -o $@ $(BIGNUMDIR)/amd64/bignum_amd64.c
+	$(COMPILE.c) -o $@ $(BIGNUM_CFG) $(BIGNUMDIR)/amd64/bignum_amd64.c
 	$(CTFCONVERT_O)
 	$(POST_PROCESS_O)
 
 $(OBJS_DIR)/bignum_amd64_asm.o: $(BIGNUMDIR)/amd64/bignum_amd64_asm.s
-	$(COMPILE.s) -P -o $@ $(BIGNUM_CFG) $(BIGNUMDIR)/amd64/bignum_amd64_asm.s
+	$(COMPILE.s) -P -o $@ $(BIGNUM_CFG) \
+		$(BIGNUMDIR)/amd64/bignum_amd64_asm.s
 	$(POST_PROCESS_O)
 
 $(LINTS_DIR)/bignum_amd64.ln: $(BIGNUMDIR)/amd64/bignum_amd64.c
