summaryrefslogtreecommitdiff
path: root/usr/src/lib/pkcs11/pkcs11_softtoken/common
diff options
context:
space:
mode:
authorDina K Nimeh <Dina.Nimeh@Sun.COM>2009-06-09 07:24:43 -0700
committerDina K Nimeh <Dina.Nimeh@Sun.COM>2009-06-09 07:24:43 -0700
commit5cd3be5eff795b7ee05cb9d597d494c19ce22a05 (patch)
treeaee4775dc818bdd8c3b4914b43264e8a13d2a89f /usr/src/lib/pkcs11/pkcs11_softtoken/common
parent191c289b86668766245f78ec1f87557319bc46a1 (diff)
downloadillumos-joyent-5cd3be5eff795b7ee05cb9d597d494c19ce22a05.tar.gz
6837738 ssh and javaws dump core in libsoftcrypto when freeing memory under libumem
Diffstat (limited to 'usr/src/lib/pkcs11/pkcs11_softtoken/common')
-rw-r--r--usr/src/lib/pkcs11/pkcs11_softtoken/common/softAttributeUtil.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softAttributeUtil.c b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softAttributeUtil.c
index 1e86481fa4..d1829207d7 100644
--- a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softAttributeUtil.c
+++ b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softAttributeUtil.c
@@ -1573,7 +1573,33 @@ soft_build_public_key_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
if (isModulus && isPubExpo) {
/*
- * Copy big integer attribute value to the
+ * Derive modulus_bits attribute from modulus.
+ * Save modulus_bits integer value to the
+ * designated place in the public key object.
+ */
+ n.malloced = 0;
+#ifdef __sparcv9
+ if (big_init(&n, (int)CHARLEN2BIGNUMLEN(
+ modulus.big_value_len)) != BIG_OK) {
+#else /* !__sparcv9 */
+ if (big_init(&n, CHARLEN2BIGNUMLEN(
+ modulus.big_value_len)) != BIG_OK) {
+#endif /* __sparcv9 */
+ rv = CKR_HOST_MEMORY;
+ big_finish(&n);
+ goto fail_cleanup;
+ }
+ bytestring2bignum(&n, modulus.big_value,
+ modulus.big_value_len);
+
+ modulus_bits = big_bitlength(&n);
+ KEY_PUB_RSA_MOD_BITS(pbk) = modulus_bits;
+ big_finish(&n);
+
+ /*
+ * After modulus_bits has been computed,
+ * it is safe to move modulus and pubexpo
+ * big integer attribute value to the
* designated place in the public key object.
*/
copy_bigint_attr(&modulus,
@@ -1585,33 +1611,6 @@ soft_build_public_key_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
rv = CKR_TEMPLATE_INCOMPLETE;
goto fail_cleanup;
}
-
- /*
- * Derive modulus_bits attribute from modulus.
- * Copy big integer attribute value to the
- * designated place in the public key object.
- */
- n.malloced = 0;
-#ifdef __sparcv9
- if (big_init(&n,
- (int)CHARLEN2BIGNUMLEN(modulus.big_value_len))
- != BIG_OK) {
-#else /* !__sparcv9 */
- if (big_init(&n,
- CHARLEN2BIGNUMLEN(modulus.big_value_len))
- != BIG_OK) {
-#endif /* __sparcv9 */
- rv = CKR_HOST_MEMORY;
- big_finish(&n);
- goto fail_cleanup;
- }
- bytestring2bignum(&n, modulus.big_value,
- modulus.big_value_len);
-
- modulus_bits = big_bitlength(&n);
- KEY_PUB_RSA_MOD_BITS(pbk) = modulus_bits;
-
- big_finish(&n);
} else {
/* mode is SOFT_GEN_KEY */