17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
590e0e8c4Sizick * Common Development and Distribution License (the "License").
690e0e8c4Sizick * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22d288ba74SAnthony Scarpino * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
24*33f5ff17SMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <stdlib.h>
287c478bd9Sstevel@tonic-gate #include <string.h>
297c478bd9Sstevel@tonic-gate #include <security/cryptoki.h>
3023c57df7Smcpowers #include <sys/crypto/common.h>
317c478bd9Sstevel@tonic-gate #include <arcfour.h>
327c478bd9Sstevel@tonic-gate #include <aes_impl.h>
33f66d273dSizick #include <blowfish_impl.h>
347c478bd9Sstevel@tonic-gate #include <bignum.h>
357c478bd9Sstevel@tonic-gate #include <des_impl.h>
367c478bd9Sstevel@tonic-gate #include <rsa_impl.h>
377c478bd9Sstevel@tonic-gate #include "softGlobal.h"
387c478bd9Sstevel@tonic-gate #include "softObject.h"
397c478bd9Sstevel@tonic-gate #include "softSession.h"
407c478bd9Sstevel@tonic-gate #include "softKeystore.h"
417c478bd9Sstevel@tonic-gate #include "softKeystoreUtil.h"
42f66d273dSizick #include "softCrypt.h"
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * This attribute table is used by the soft_lookup_attr()
477c478bd9Sstevel@tonic-gate * to validate the attributes.
487c478bd9Sstevel@tonic-gate */
497c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE attr_map[] = {
507c478bd9Sstevel@tonic-gate CKA_PRIVATE,
517c478bd9Sstevel@tonic-gate CKA_LABEL,
527c478bd9Sstevel@tonic-gate CKA_APPLICATION,
537c478bd9Sstevel@tonic-gate CKA_OBJECT_ID,
547c478bd9Sstevel@tonic-gate CKA_CERTIFICATE_TYPE,
557c478bd9Sstevel@tonic-gate CKA_ISSUER,
567c478bd9Sstevel@tonic-gate CKA_SERIAL_NUMBER,
577c478bd9Sstevel@tonic-gate CKA_AC_ISSUER,
587c478bd9Sstevel@tonic-gate CKA_OWNER,
597c478bd9Sstevel@tonic-gate CKA_ATTR_TYPES,
607c478bd9Sstevel@tonic-gate CKA_SUBJECT,
617c478bd9Sstevel@tonic-gate CKA_ID,
627c478bd9Sstevel@tonic-gate CKA_SENSITIVE,
637c478bd9Sstevel@tonic-gate CKA_START_DATE,
647c478bd9Sstevel@tonic-gate CKA_END_DATE,
657c478bd9Sstevel@tonic-gate CKA_MODULUS,
667c478bd9Sstevel@tonic-gate CKA_MODULUS_BITS,
677c478bd9Sstevel@tonic-gate CKA_PUBLIC_EXPONENT,
687c478bd9Sstevel@tonic-gate CKA_PRIVATE_EXPONENT,
697c478bd9Sstevel@tonic-gate CKA_PRIME_1,
707c478bd9Sstevel@tonic-gate CKA_PRIME_2,
717c478bd9Sstevel@tonic-gate CKA_EXPONENT_1,
727c478bd9Sstevel@tonic-gate CKA_EXPONENT_2,
737c478bd9Sstevel@tonic-gate CKA_COEFFICIENT,
747c478bd9Sstevel@tonic-gate CKA_PRIME,
757c478bd9Sstevel@tonic-gate CKA_SUBPRIME,
767c478bd9Sstevel@tonic-gate CKA_BASE,
777c478bd9Sstevel@tonic-gate CKA_EXTRACTABLE,
787c478bd9Sstevel@tonic-gate CKA_LOCAL,
797c478bd9Sstevel@tonic-gate CKA_NEVER_EXTRACTABLE,
807c478bd9Sstevel@tonic-gate CKA_ALWAYS_SENSITIVE,
817c478bd9Sstevel@tonic-gate CKA_MODIFIABLE,
827c478bd9Sstevel@tonic-gate CKA_ECDSA_PARAMS,
83034448feSmcpowers CKA_EC_PARAMS,
847c478bd9Sstevel@tonic-gate CKA_EC_POINT,
857c478bd9Sstevel@tonic-gate CKA_SECONDARY_AUTH,
867c478bd9Sstevel@tonic-gate CKA_AUTH_PIN_FLAGS,
877c478bd9Sstevel@tonic-gate CKA_HW_FEATURE_TYPE,
887c478bd9Sstevel@tonic-gate CKA_RESET_ON_INIT,
897c478bd9Sstevel@tonic-gate CKA_HAS_RESET
907c478bd9Sstevel@tonic-gate };
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate * attributes that exists only in public key objects
947c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two
957c478bd9Sstevel@tonic-gate * other object classes, but they are also listed
967c478bd9Sstevel@tonic-gate * because not all object have them.
977c478bd9Sstevel@tonic-gate */
987c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE PUB_KEY_ATTRS[] =
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate CKA_SUBJECT,
1017c478bd9Sstevel@tonic-gate CKA_ENCRYPT,
1027c478bd9Sstevel@tonic-gate CKA_WRAP,
1037c478bd9Sstevel@tonic-gate CKA_VERIFY,
1047c478bd9Sstevel@tonic-gate CKA_VERIFY_RECOVER,
1057c478bd9Sstevel@tonic-gate CKA_MODULUS,
1067c478bd9Sstevel@tonic-gate CKA_MODULUS_BITS,
1077c478bd9Sstevel@tonic-gate CKA_PUBLIC_EXPONENT,
1087c478bd9Sstevel@tonic-gate CKA_PRIME,
1097c478bd9Sstevel@tonic-gate CKA_SUBPRIME,
1107c478bd9Sstevel@tonic-gate CKA_BASE,
1117c478bd9Sstevel@tonic-gate CKA_TRUSTED,
1127c478bd9Sstevel@tonic-gate CKA_ECDSA_PARAMS,
1137c478bd9Sstevel@tonic-gate CKA_EC_PARAMS,
1147c478bd9Sstevel@tonic-gate CKA_EC_POINT
1157c478bd9Sstevel@tonic-gate };
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * attributes that exists only in private key objects
1197c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two
1207c478bd9Sstevel@tonic-gate * other object classes, but they are also listed
1217c478bd9Sstevel@tonic-gate * because not all object have them.
1227c478bd9Sstevel@tonic-gate */
1237c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE PRIV_KEY_ATTRS[] =
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate CKA_DECRYPT,
1267c478bd9Sstevel@tonic-gate CKA_UNWRAP,
1277c478bd9Sstevel@tonic-gate CKA_SIGN,
1287c478bd9Sstevel@tonic-gate CKA_SIGN_RECOVER,
1297c478bd9Sstevel@tonic-gate CKA_MODULUS,
1307c478bd9Sstevel@tonic-gate CKA_PUBLIC_EXPONENT,
1317c478bd9Sstevel@tonic-gate CKA_PRIVATE_EXPONENT,
1327c478bd9Sstevel@tonic-gate CKA_PRIME,
1337c478bd9Sstevel@tonic-gate CKA_SUBPRIME,
1347c478bd9Sstevel@tonic-gate CKA_BASE,
1357c478bd9Sstevel@tonic-gate CKA_PRIME_1,
1367c478bd9Sstevel@tonic-gate CKA_PRIME_2,
1377c478bd9Sstevel@tonic-gate CKA_EXPONENT_1,
1387c478bd9Sstevel@tonic-gate CKA_EXPONENT_2,
1397c478bd9Sstevel@tonic-gate CKA_COEFFICIENT,
1407c478bd9Sstevel@tonic-gate CKA_VALUE_BITS,
1417c478bd9Sstevel@tonic-gate CKA_SUBJECT,
1427c478bd9Sstevel@tonic-gate CKA_SENSITIVE,
1437c478bd9Sstevel@tonic-gate CKA_EXTRACTABLE,
1447c478bd9Sstevel@tonic-gate CKA_NEVER_EXTRACTABLE,
1457c478bd9Sstevel@tonic-gate CKA_ALWAYS_SENSITIVE,
1467c478bd9Sstevel@tonic-gate CKA_EC_PARAMS
1477c478bd9Sstevel@tonic-gate };
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate * attributes that exists only in secret key objects
1517c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two
1527c478bd9Sstevel@tonic-gate * other object classes, but they are also listed
1537c478bd9Sstevel@tonic-gate * because not all object have them.
1547c478bd9Sstevel@tonic-gate */
1557c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE SECRET_KEY_ATTRS[] =
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate CKA_VALUE_LEN,
1587c478bd9Sstevel@tonic-gate CKA_ENCRYPT,
1597c478bd9Sstevel@tonic-gate CKA_DECRYPT,
1607c478bd9Sstevel@tonic-gate CKA_WRAP,
1617c478bd9Sstevel@tonic-gate CKA_UNWRAP,
1627c478bd9Sstevel@tonic-gate CKA_SIGN,
1637c478bd9Sstevel@tonic-gate CKA_VERIFY,
1647c478bd9Sstevel@tonic-gate CKA_SENSITIVE,
1657c478bd9Sstevel@tonic-gate CKA_EXTRACTABLE,
1667c478bd9Sstevel@tonic-gate CKA_NEVER_EXTRACTABLE,
1677c478bd9Sstevel@tonic-gate CKA_ALWAYS_SENSITIVE
1687c478bd9Sstevel@tonic-gate };
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate * attributes that exists only in domain parameter objects
1727c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two
1737c478bd9Sstevel@tonic-gate * other object classes, but they are also listed
1747c478bd9Sstevel@tonic-gate * because not all object have them.
1757c478bd9Sstevel@tonic-gate */
1767c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE DOMAIN_ATTRS[] =
1777c478bd9Sstevel@tonic-gate {
1787c478bd9Sstevel@tonic-gate CKA_PRIME,
1797c478bd9Sstevel@tonic-gate CKA_SUBPRIME,
1807c478bd9Sstevel@tonic-gate CKA_BASE,
1817c478bd9Sstevel@tonic-gate CKA_PRIME_BITS,
1827c478bd9Sstevel@tonic-gate CKA_SUBPRIME_BITS,
1837c478bd9Sstevel@tonic-gate CKA_SUB_PRIME_BITS
1847c478bd9Sstevel@tonic-gate };
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate * attributes that exists only in hardware feature objects
1887c478bd9Sstevel@tonic-gate *
1897c478bd9Sstevel@tonic-gate */
1907c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE HARDWARE_ATTRS[] =
1917c478bd9Sstevel@tonic-gate {
1927c478bd9Sstevel@tonic-gate CKA_HW_FEATURE_TYPE,
1937c478bd9Sstevel@tonic-gate CKA_RESET_ON_INIT,
1947c478bd9Sstevel@tonic-gate CKA_HAS_RESET
1957c478bd9Sstevel@tonic-gate };
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate * attributes that exists only in certificate objects
1997c478bd9Sstevel@tonic-gate */
2007c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE CERT_ATTRS[] =
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate CKA_CERTIFICATE_TYPE,
2037c478bd9Sstevel@tonic-gate CKA_TRUSTED,
2047c478bd9Sstevel@tonic-gate CKA_SUBJECT,
2057c478bd9Sstevel@tonic-gate CKA_ID,
2067c478bd9Sstevel@tonic-gate CKA_ISSUER,
2077c478bd9Sstevel@tonic-gate CKA_AC_ISSUER,
2087c478bd9Sstevel@tonic-gate CKA_SERIAL_NUMBER,
2097c478bd9Sstevel@tonic-gate CKA_OWNER,
2107c478bd9Sstevel@tonic-gate CKA_ATTR_TYPES
2117c478bd9Sstevel@tonic-gate };
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate * Validate the attribute by using binary search algorithm.
2167c478bd9Sstevel@tonic-gate */
2177c478bd9Sstevel@tonic-gate CK_RV
soft_lookup_attr(CK_ATTRIBUTE_TYPE type)2187c478bd9Sstevel@tonic-gate soft_lookup_attr(CK_ATTRIBUTE_TYPE type)
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate size_t lower, middle, upper;
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate lower = 0;
2247c478bd9Sstevel@tonic-gate upper = (sizeof (attr_map) / sizeof (CK_ATTRIBUTE_TYPE)) - 1;
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate while (lower <= upper) {
2277c478bd9Sstevel@tonic-gate /* Always starts from middle. */
2287c478bd9Sstevel@tonic-gate middle = (lower + upper) / 2;
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate if (type > attr_map[middle]) {
2317c478bd9Sstevel@tonic-gate /* Adjust the lower bound to upper half. */
2327c478bd9Sstevel@tonic-gate lower = middle + 1;
2337c478bd9Sstevel@tonic-gate continue;
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate if (type == attr_map[middle]) {
2377c478bd9Sstevel@tonic-gate /* Found it. */
2387c478bd9Sstevel@tonic-gate return (CKR_OK);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate if (type < attr_map[middle]) {
2427c478bd9Sstevel@tonic-gate /* Adjust the upper bound to lower half. */
2437c478bd9Sstevel@tonic-gate upper = middle - 1;
2447c478bd9Sstevel@tonic-gate continue;
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate /* Failed to find the matching attribute from the attribute table. */
2497c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate /*
2547c478bd9Sstevel@tonic-gate * Validate the attribute by using the following search algorithm:
2557c478bd9Sstevel@tonic-gate *
2567c478bd9Sstevel@tonic-gate * 1) Search for the most frequently used attributes first.
2577c478bd9Sstevel@tonic-gate * 2) If not found, search for the usage-purpose attributes - these
2587c478bd9Sstevel@tonic-gate * attributes have dense set of values, therefore compiler will
2597c478bd9Sstevel@tonic-gate * optimize it with a branch table and branch to the appropriate
2607c478bd9Sstevel@tonic-gate * case.
2617c478bd9Sstevel@tonic-gate * 3) If still not found, use binary search for the rest of the
2627c478bd9Sstevel@tonic-gate * attributes in the attr_map[] table.
2637c478bd9Sstevel@tonic-gate */
2647c478bd9Sstevel@tonic-gate CK_RV
soft_validate_attr(CK_ATTRIBUTE_PTR template,CK_ULONG ulAttrNum,CK_OBJECT_CLASS * class)2657c478bd9Sstevel@tonic-gate soft_validate_attr(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
2667c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS *class)
2677c478bd9Sstevel@tonic-gate {
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate CK_ULONG i;
2707c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
2737c478bd9Sstevel@tonic-gate /* First tier search */
2747c478bd9Sstevel@tonic-gate switch (template[i].type) {
2757c478bd9Sstevel@tonic-gate case CKA_CLASS:
2767c478bd9Sstevel@tonic-gate *class = *((CK_OBJECT_CLASS*)template[i].pValue);
2777c478bd9Sstevel@tonic-gate break;
2787c478bd9Sstevel@tonic-gate case CKA_TOKEN:
2797c478bd9Sstevel@tonic-gate break;
2807c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
2817c478bd9Sstevel@tonic-gate break;
2827c478bd9Sstevel@tonic-gate case CKA_VALUE:
2837c478bd9Sstevel@tonic-gate break;
2847c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN:
2857c478bd9Sstevel@tonic-gate break;
2867c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS:
2877c478bd9Sstevel@tonic-gate break;
2887c478bd9Sstevel@tonic-gate default:
2897c478bd9Sstevel@tonic-gate /* Second tier search */
2907c478bd9Sstevel@tonic-gate switch (template[i].type) {
2917c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
2927c478bd9Sstevel@tonic-gate break;
2937c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
2947c478bd9Sstevel@tonic-gate break;
2957c478bd9Sstevel@tonic-gate case CKA_WRAP:
2967c478bd9Sstevel@tonic-gate break;
2977c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
2987c478bd9Sstevel@tonic-gate break;
2997c478bd9Sstevel@tonic-gate case CKA_SIGN:
3007c478bd9Sstevel@tonic-gate break;
3017c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER:
3027c478bd9Sstevel@tonic-gate break;
3037c478bd9Sstevel@tonic-gate case CKA_VERIFY:
3047c478bd9Sstevel@tonic-gate break;
3057c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER:
3067c478bd9Sstevel@tonic-gate break;
3077c478bd9Sstevel@tonic-gate case CKA_DERIVE:
3087c478bd9Sstevel@tonic-gate break;
3097c478bd9Sstevel@tonic-gate default:
3107c478bd9Sstevel@tonic-gate /* Third tier search */
3117c478bd9Sstevel@tonic-gate rv = soft_lookup_attr(template[i].type);
3127c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
3137c478bd9Sstevel@tonic-gate return (rv);
3147c478bd9Sstevel@tonic-gate break;
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate break;
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate return (rv);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate static void
cleanup_cert_attr(cert_attr_t * attr)3237c478bd9Sstevel@tonic-gate cleanup_cert_attr(cert_attr_t *attr)
3247c478bd9Sstevel@tonic-gate {
3257c478bd9Sstevel@tonic-gate if (attr) {
3267c478bd9Sstevel@tonic-gate if (attr->value) {
3277c478bd9Sstevel@tonic-gate (void) memset(attr->value, 0, attr->length);
3287c478bd9Sstevel@tonic-gate free(attr->value);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate attr->value = NULL;
3317c478bd9Sstevel@tonic-gate attr->length = 0;
3327c478bd9Sstevel@tonic-gate }
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate static CK_RV
copy_cert_attr(cert_attr_t * src_attr,cert_attr_t ** dest_attr)3367c478bd9Sstevel@tonic-gate copy_cert_attr(cert_attr_t *src_attr, cert_attr_t **dest_attr)
3377c478bd9Sstevel@tonic-gate {
3387c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate if (src_attr == NULL || dest_attr == NULL)
3417c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate if (src_attr->value == NULL)
3447c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /* free memory if its already allocated */
3477c478bd9Sstevel@tonic-gate if (*dest_attr != NULL) {
3487c478bd9Sstevel@tonic-gate if ((*dest_attr)->value != (CK_BYTE *)NULL)
3497c478bd9Sstevel@tonic-gate free((*dest_attr)->value);
3507c478bd9Sstevel@tonic-gate } else {
3517c478bd9Sstevel@tonic-gate *dest_attr = malloc(sizeof (cert_attr_t));
3527c478bd9Sstevel@tonic-gate if (*dest_attr == NULL)
3537c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate (*dest_attr)->value = NULL;
3577c478bd9Sstevel@tonic-gate (*dest_attr)->length = 0;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate if (src_attr->length) {
3607c478bd9Sstevel@tonic-gate (*dest_attr)->value = malloc(src_attr->length);
3617c478bd9Sstevel@tonic-gate if ((*dest_attr)->value == NULL) {
3627c478bd9Sstevel@tonic-gate free(*dest_attr);
3637c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate (void) memcpy((*dest_attr)->value, src_attr->value,
3677c478bd9Sstevel@tonic-gate src_attr->length);
3687c478bd9Sstevel@tonic-gate (*dest_attr)->length = src_attr->length;
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate return (rv);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate void
soft_cleanup_cert_object(soft_object_t * object_p)3757c478bd9Sstevel@tonic-gate soft_cleanup_cert_object(soft_object_t *object_p)
3767c478bd9Sstevel@tonic-gate {
3777c478bd9Sstevel@tonic-gate CK_CERTIFICATE_TYPE certtype = object_p->cert_type;
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate if (object_p->class != CKO_CERTIFICATE ||
3807c478bd9Sstevel@tonic-gate OBJ_CERT(object_p) == NULL)
3817c478bd9Sstevel@tonic-gate return;
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509) {
3847c478bd9Sstevel@tonic-gate if (X509_CERT_SUBJECT(object_p) != NULL) {
3857c478bd9Sstevel@tonic-gate cleanup_cert_attr(X509_CERT_SUBJECT(object_p));
3867c478bd9Sstevel@tonic-gate free(X509_CERT_SUBJECT(object_p));
3877c478bd9Sstevel@tonic-gate X509_CERT_SUBJECT(object_p) = NULL;
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate if (X509_CERT_VALUE(object_p) != NULL) {
3907c478bd9Sstevel@tonic-gate cleanup_cert_attr(X509_CERT_VALUE(object_p));
3917c478bd9Sstevel@tonic-gate free(X509_CERT_VALUE(object_p));
3927c478bd9Sstevel@tonic-gate X509_CERT_VALUE(object_p) = NULL;
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate free(OBJ_CERT(object_p));
3957c478bd9Sstevel@tonic-gate } else if (certtype == CKC_X_509_ATTR_CERT) {
3967c478bd9Sstevel@tonic-gate if (X509_ATTR_CERT_VALUE(object_p) != NULL) {
3977c478bd9Sstevel@tonic-gate cleanup_cert_attr(X509_ATTR_CERT_VALUE(object_p));
3987c478bd9Sstevel@tonic-gate free(X509_ATTR_CERT_VALUE(object_p));
3997c478bd9Sstevel@tonic-gate X509_ATTR_CERT_VALUE(object_p) = NULL;
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate if (X509_ATTR_CERT_OWNER(object_p) != NULL) {
4027c478bd9Sstevel@tonic-gate cleanup_cert_attr(X509_ATTR_CERT_OWNER(object_p));
4037c478bd9Sstevel@tonic-gate free(X509_ATTR_CERT_OWNER(object_p));
4047c478bd9Sstevel@tonic-gate X509_ATTR_CERT_OWNER(object_p) = NULL;
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate free(OBJ_CERT(object_p));
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate * Clean up and release all the storage in the extra attribute list
4127c478bd9Sstevel@tonic-gate * of an object.
4137c478bd9Sstevel@tonic-gate */
4147c478bd9Sstevel@tonic-gate void
soft_cleanup_extra_attr(soft_object_t * object_p)4157c478bd9Sstevel@tonic-gate soft_cleanup_extra_attr(soft_object_t *object_p)
4167c478bd9Sstevel@tonic-gate {
4177c478bd9Sstevel@tonic-gate
4187c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR extra_attr;
4197c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR tmp;
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate extra_attr = object_p->extra_attrlistp;
4227c478bd9Sstevel@tonic-gate while (extra_attr) {
4237c478bd9Sstevel@tonic-gate tmp = extra_attr->next;
4247c478bd9Sstevel@tonic-gate if (extra_attr->attr.pValue)
4257c478bd9Sstevel@tonic-gate /*
4267c478bd9Sstevel@tonic-gate * All extra attributes in the extra attribute
4277c478bd9Sstevel@tonic-gate * list have pValue points to the value of the
4287c478bd9Sstevel@tonic-gate * attribute (with simple byte array type).
4297c478bd9Sstevel@tonic-gate * Free the storage for the value of the attribute.
4307c478bd9Sstevel@tonic-gate */
4317c478bd9Sstevel@tonic-gate free(extra_attr->attr.pValue);
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate /* Free the storage for the attribute_info struct. */
4347c478bd9Sstevel@tonic-gate free(extra_attr);
4357c478bd9Sstevel@tonic-gate extra_attr = tmp;
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = NULL;
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate /*
4437c478bd9Sstevel@tonic-gate * Create the attribute_info struct to hold the object's attribute,
4447c478bd9Sstevel@tonic-gate * and add it to the extra attribute list of an object.
4457c478bd9Sstevel@tonic-gate */
4467c478bd9Sstevel@tonic-gate CK_RV
soft_add_extra_attr(CK_ATTRIBUTE_PTR template,soft_object_t * object_p)4477c478bd9Sstevel@tonic-gate soft_add_extra_attr(CK_ATTRIBUTE_PTR template, soft_object_t *object_p)
4487c478bd9Sstevel@tonic-gate {
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR attrp;
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate /* Allocate the storage for the attribute_info struct. */
4537c478bd9Sstevel@tonic-gate attrp = calloc(1, sizeof (attribute_info_t));
4547c478bd9Sstevel@tonic-gate if (attrp == NULL) {
4557c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate /* Set up attribute_info struct. */
4597c478bd9Sstevel@tonic-gate attrp->attr.type = template->type;
4607c478bd9Sstevel@tonic-gate attrp->attr.ulValueLen = template->ulValueLen;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate if ((template->pValue != NULL) &&
4637c478bd9Sstevel@tonic-gate (template->ulValueLen > 0)) {
4647c478bd9Sstevel@tonic-gate /* Allocate storage for the value of the attribute. */
4657c478bd9Sstevel@tonic-gate attrp->attr.pValue = malloc(template->ulValueLen);
4667c478bd9Sstevel@tonic-gate if (attrp->attr.pValue == NULL) {
4677c478bd9Sstevel@tonic-gate free(attrp);
4687c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate (void) memcpy(attrp->attr.pValue, template->pValue,
4727c478bd9Sstevel@tonic-gate template->ulValueLen);
4737c478bd9Sstevel@tonic-gate } else {
4747c478bd9Sstevel@tonic-gate attrp->attr.pValue = NULL;
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate /* Insert the new attribute in front of extra attribute list. */
4787c478bd9Sstevel@tonic-gate if (object_p->extra_attrlistp == NULL) {
4797c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp;
4807c478bd9Sstevel@tonic-gate attrp->next = NULL;
4817c478bd9Sstevel@tonic-gate } else {
4827c478bd9Sstevel@tonic-gate attrp->next = object_p->extra_attrlistp;
4837c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp;
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate return (CKR_OK);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate CK_RV
soft_copy_certificate(certificate_obj_t * oldcert,certificate_obj_t ** newcert,CK_CERTIFICATE_TYPE type)4907c478bd9Sstevel@tonic-gate soft_copy_certificate(certificate_obj_t *oldcert, certificate_obj_t **newcert,
4917c478bd9Sstevel@tonic-gate CK_CERTIFICATE_TYPE type)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
4947c478bd9Sstevel@tonic-gate certificate_obj_t *cert;
4957c478bd9Sstevel@tonic-gate x509_cert_t x509;
4967c478bd9Sstevel@tonic-gate x509_attr_cert_t x509_attr;
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate cert = calloc(1, sizeof (certificate_obj_t));
4997c478bd9Sstevel@tonic-gate if (cert == NULL) {
5007c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate if (type == CKC_X_509) {
5047c478bd9Sstevel@tonic-gate x509 = oldcert->cert_type_u.x509;
5057c478bd9Sstevel@tonic-gate if (x509.subject)
5067c478bd9Sstevel@tonic-gate if ((rv = copy_cert_attr(x509.subject,
5077c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509.subject)))
5087c478bd9Sstevel@tonic-gate return (rv);
5097c478bd9Sstevel@tonic-gate if (x509.value)
5107c478bd9Sstevel@tonic-gate if ((rv = copy_cert_attr(x509.value,
5117c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509.value)))
5127c478bd9Sstevel@tonic-gate return (rv);
5137c478bd9Sstevel@tonic-gate } else if (type == CKC_X_509_ATTR_CERT) {
5147c478bd9Sstevel@tonic-gate x509_attr = oldcert->cert_type_u.x509_attr;
5157c478bd9Sstevel@tonic-gate if (x509_attr.owner)
5167c478bd9Sstevel@tonic-gate if ((rv = copy_cert_attr(x509_attr.owner,
5177c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509_attr.owner)))
5187c478bd9Sstevel@tonic-gate return (rv);
5197c478bd9Sstevel@tonic-gate if (x509_attr.value)
5207c478bd9Sstevel@tonic-gate if ((rv = copy_cert_attr(x509_attr.value,
5217c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509_attr.value)))
5227c478bd9Sstevel@tonic-gate return (rv);
5237c478bd9Sstevel@tonic-gate } else {
5247c478bd9Sstevel@tonic-gate /* wrong certificate type */
5257c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate if (rv == CKR_OK)
5287c478bd9Sstevel@tonic-gate *newcert = cert;
5297c478bd9Sstevel@tonic-gate return (rv);
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /*
5337c478bd9Sstevel@tonic-gate * Copy the attribute_info struct from the old object to a new attribute_info
5347c478bd9Sstevel@tonic-gate * struct, and add that new struct to the extra attribute list of the new
5357c478bd9Sstevel@tonic-gate * object.
5367c478bd9Sstevel@tonic-gate */
5377c478bd9Sstevel@tonic-gate CK_RV
soft_copy_extra_attr(CK_ATTRIBUTE_INFO_PTR old_attrp,soft_object_t * object_p)5387c478bd9Sstevel@tonic-gate soft_copy_extra_attr(CK_ATTRIBUTE_INFO_PTR old_attrp, soft_object_t *object_p)
5397c478bd9Sstevel@tonic-gate {
5407c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR attrp;
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate /* Allocate attribute_info struct. */
5437c478bd9Sstevel@tonic-gate attrp = calloc(1, sizeof (attribute_info_t));
5447c478bd9Sstevel@tonic-gate if (attrp == NULL) {
5457c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate attrp->attr.type = old_attrp->attr.type;
5497c478bd9Sstevel@tonic-gate attrp->attr.ulValueLen = old_attrp->attr.ulValueLen;
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate if ((old_attrp->attr.pValue != NULL) &&
5527c478bd9Sstevel@tonic-gate (old_attrp->attr.ulValueLen > 0)) {
5537c478bd9Sstevel@tonic-gate attrp->attr.pValue = malloc(old_attrp->attr.ulValueLen);
5547c478bd9Sstevel@tonic-gate if (attrp->attr.pValue == NULL) {
5557c478bd9Sstevel@tonic-gate free(attrp);
5567c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
5577c478bd9Sstevel@tonic-gate }
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate (void) memcpy(attrp->attr.pValue, old_attrp->attr.pValue,
5607c478bd9Sstevel@tonic-gate old_attrp->attr.ulValueLen);
5617c478bd9Sstevel@tonic-gate } else {
5627c478bd9Sstevel@tonic-gate attrp->attr.pValue = NULL;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate /* Insert the new attribute in front of extra attribute list */
5667c478bd9Sstevel@tonic-gate if (object_p->extra_attrlistp == NULL) {
5677c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp;
5687c478bd9Sstevel@tonic-gate attrp->next = NULL;
5697c478bd9Sstevel@tonic-gate } else {
5707c478bd9Sstevel@tonic-gate attrp->next = object_p->extra_attrlistp;
5717c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp;
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate return (CKR_OK);
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate * Get the attribute triple from the extra attribute list in the object
5807c478bd9Sstevel@tonic-gate * (if the specified attribute type is found), and copy it to a template.
5817c478bd9Sstevel@tonic-gate * Note the type of the attribute to be copied is specified by the template,
5827c478bd9Sstevel@tonic-gate * and the storage is pre-allocated for the atrribute value in the template
5837c478bd9Sstevel@tonic-gate * for doing the copy.
5847c478bd9Sstevel@tonic-gate */
5857c478bd9Sstevel@tonic-gate CK_RV
get_extra_attr_from_object(soft_object_t * object_p,CK_ATTRIBUTE_PTR template)5867c478bd9Sstevel@tonic-gate get_extra_attr_from_object(soft_object_t *object_p, CK_ATTRIBUTE_PTR template)
5877c478bd9Sstevel@tonic-gate {
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR extra_attr;
5907c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE type = template->type;
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate extra_attr = object_p->extra_attrlistp;
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate while (extra_attr) {
5957c478bd9Sstevel@tonic-gate if (type == extra_attr->attr.type) {
5967c478bd9Sstevel@tonic-gate /* Found it. */
5977c478bd9Sstevel@tonic-gate break;
5987c478bd9Sstevel@tonic-gate } else {
5997c478bd9Sstevel@tonic-gate /* Does not match, try next one. */
6007c478bd9Sstevel@tonic-gate extra_attr = extra_attr->next;
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate if (extra_attr == NULL) {
6057c478bd9Sstevel@tonic-gate /* A valid but un-initialized attribute. */
6067c478bd9Sstevel@tonic-gate template->ulValueLen = 0;
6077c478bd9Sstevel@tonic-gate return (CKR_OK);
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate /*
6117c478bd9Sstevel@tonic-gate * We found the attribute in the extra attribute list.
6127c478bd9Sstevel@tonic-gate */
6137c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
6147c478bd9Sstevel@tonic-gate template->ulValueLen = extra_attr->attr.ulValueLen;
6157c478bd9Sstevel@tonic-gate return (CKR_OK);
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate if (template->ulValueLen >= extra_attr->attr.ulValueLen) {
6197c478bd9Sstevel@tonic-gate /*
6207c478bd9Sstevel@tonic-gate * The buffer provided by the application is large
6217c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute.
6227c478bd9Sstevel@tonic-gate */
6237c478bd9Sstevel@tonic-gate (void) memcpy(template->pValue, extra_attr->attr.pValue,
6247c478bd9Sstevel@tonic-gate extra_attr->attr.ulValueLen);
6257c478bd9Sstevel@tonic-gate template->ulValueLen = extra_attr->attr.ulValueLen;
6267c478bd9Sstevel@tonic-gate return (CKR_OK);
6277c478bd9Sstevel@tonic-gate } else {
6287c478bd9Sstevel@tonic-gate /*
6297c478bd9Sstevel@tonic-gate * The buffer provided by the application does
6307c478bd9Sstevel@tonic-gate * not have enough space to hold the value.
6317c478bd9Sstevel@tonic-gate */
6327c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
6337c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL);
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate * Modify the attribute triple in the extra attribute list of the object
6407c478bd9Sstevel@tonic-gate * if the specified attribute type is found. Otherwise, just add it to
6417c478bd9Sstevel@tonic-gate * list.
6427c478bd9Sstevel@tonic-gate */
6437c478bd9Sstevel@tonic-gate CK_RV
set_extra_attr_to_object(soft_object_t * object_p,CK_ATTRIBUTE_TYPE type,CK_ATTRIBUTE_PTR template)6447c478bd9Sstevel@tonic-gate set_extra_attr_to_object(soft_object_t *object_p, CK_ATTRIBUTE_TYPE type,
6457c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
6467c478bd9Sstevel@tonic-gate {
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR extra_attr;
6497c478bd9Sstevel@tonic-gate
6507c478bd9Sstevel@tonic-gate extra_attr = object_p->extra_attrlistp;
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate while (extra_attr) {
6537c478bd9Sstevel@tonic-gate if (type == extra_attr->attr.type) {
6547c478bd9Sstevel@tonic-gate /* Found it. */
6557c478bd9Sstevel@tonic-gate break;
6567c478bd9Sstevel@tonic-gate } else {
6577c478bd9Sstevel@tonic-gate /* Does not match, try next one. */
6587c478bd9Sstevel@tonic-gate extra_attr = extra_attr->next;
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate if (extra_attr == NULL) {
6637c478bd9Sstevel@tonic-gate /*
6647c478bd9Sstevel@tonic-gate * This attribute is a new one, go ahead adding it to
6657c478bd9Sstevel@tonic-gate * the extra attribute list.
6667c478bd9Sstevel@tonic-gate */
6677c478bd9Sstevel@tonic-gate return (soft_add_extra_attr(template, object_p));
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate /* We found the attribute in the extra attribute list. */
6717c478bd9Sstevel@tonic-gate if ((template->pValue != NULL) &&
6727c478bd9Sstevel@tonic-gate (template->ulValueLen > 0)) {
6737c478bd9Sstevel@tonic-gate if (template->ulValueLen > extra_attr->attr.ulValueLen) {
6747c478bd9Sstevel@tonic-gate /* The old buffer is too small to hold the new value. */
6757c478bd9Sstevel@tonic-gate if (extra_attr->attr.pValue != NULL)
6767c478bd9Sstevel@tonic-gate /* Free storage for the old attribute value. */
6777c478bd9Sstevel@tonic-gate free(extra_attr->attr.pValue);
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate /* Allocate storage for the new attribute value. */
6807c478bd9Sstevel@tonic-gate extra_attr->attr.pValue = malloc(template->ulValueLen);
6817c478bd9Sstevel@tonic-gate if (extra_attr->attr.pValue == NULL) {
6827c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate /* Replace the attribute with new value. */
6877c478bd9Sstevel@tonic-gate extra_attr->attr.ulValueLen = template->ulValueLen;
6887c478bd9Sstevel@tonic-gate (void) memcpy(extra_attr->attr.pValue, template->pValue,
6897c478bd9Sstevel@tonic-gate template->ulValueLen);
6907c478bd9Sstevel@tonic-gate } else {
6917c478bd9Sstevel@tonic-gate extra_attr->attr.pValue = NULL;
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate return (CKR_OK);
6957c478bd9Sstevel@tonic-gate }
6967c478bd9Sstevel@tonic-gate
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate /*
6997c478bd9Sstevel@tonic-gate * Copy the big integer attribute value from template to a biginteger_t struct.
7007c478bd9Sstevel@tonic-gate */
7017c478bd9Sstevel@tonic-gate CK_RV
get_bigint_attr_from_template(biginteger_t * big,CK_ATTRIBUTE_PTR template)7027c478bd9Sstevel@tonic-gate get_bigint_attr_from_template(biginteger_t *big, CK_ATTRIBUTE_PTR template)
7037c478bd9Sstevel@tonic-gate {
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate if ((template->pValue != NULL) &&
7067c478bd9Sstevel@tonic-gate (template->ulValueLen > 0)) {
7077c478bd9Sstevel@tonic-gate /* Allocate storage for the value of the attribute. */
7087c478bd9Sstevel@tonic-gate big->big_value = malloc(template->ulValueLen);
7097c478bd9Sstevel@tonic-gate if (big->big_value == NULL) {
7107c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate (void) memcpy(big->big_value, template->pValue,
7147c478bd9Sstevel@tonic-gate template->ulValueLen);
7157c478bd9Sstevel@tonic-gate big->big_value_len = template->ulValueLen;
7167c478bd9Sstevel@tonic-gate } else {
7177c478bd9Sstevel@tonic-gate big->big_value = NULL;
7187c478bd9Sstevel@tonic-gate big->big_value_len = 0;
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate return (CKR_OK);
7227c478bd9Sstevel@tonic-gate }
7237c478bd9Sstevel@tonic-gate
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate /*
7267c478bd9Sstevel@tonic-gate * Copy the big integer attribute value from a biginteger_t struct in the
7277c478bd9Sstevel@tonic-gate * object to a template.
7287c478bd9Sstevel@tonic-gate */
7297c478bd9Sstevel@tonic-gate CK_RV
get_bigint_attr_from_object(biginteger_t * big,CK_ATTRIBUTE_PTR template)7307c478bd9Sstevel@tonic-gate get_bigint_attr_from_object(biginteger_t *big, CK_ATTRIBUTE_PTR template)
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate
7337c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
7347c478bd9Sstevel@tonic-gate template->ulValueLen = big->big_value_len;
7357c478bd9Sstevel@tonic-gate return (CKR_OK);
7367c478bd9Sstevel@tonic-gate }
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate if (big->big_value == NULL) {
7397c478bd9Sstevel@tonic-gate template->ulValueLen = 0;
7407c478bd9Sstevel@tonic-gate return (CKR_OK);
7417c478bd9Sstevel@tonic-gate }
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate if (template->ulValueLen >= big->big_value_len) {
7447c478bd9Sstevel@tonic-gate /*
7457c478bd9Sstevel@tonic-gate * The buffer provided by the application is large
7467c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute.
7477c478bd9Sstevel@tonic-gate */
7487c478bd9Sstevel@tonic-gate (void) memcpy(template->pValue, big->big_value,
7497c478bd9Sstevel@tonic-gate big->big_value_len);
7507c478bd9Sstevel@tonic-gate template->ulValueLen = big->big_value_len;
7517c478bd9Sstevel@tonic-gate return (CKR_OK);
7527c478bd9Sstevel@tonic-gate } else {
7537c478bd9Sstevel@tonic-gate /*
7547c478bd9Sstevel@tonic-gate * The buffer provided by the application does
7557c478bd9Sstevel@tonic-gate * not have enough space to hold the value.
7567c478bd9Sstevel@tonic-gate */
7577c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
7587c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL);
7597c478bd9Sstevel@tonic-gate }
7607c478bd9Sstevel@tonic-gate }
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate /*
7647c478bd9Sstevel@tonic-gate * Copy the boolean data type attribute value from an object for the
7657c478bd9Sstevel@tonic-gate * specified attribute to the template.
7667c478bd9Sstevel@tonic-gate */
7677c478bd9Sstevel@tonic-gate CK_RV
get_bool_attr_from_object(soft_object_t * object_p,CK_ULONG bool_flag,CK_ATTRIBUTE_PTR template)7687c478bd9Sstevel@tonic-gate get_bool_attr_from_object(soft_object_t *object_p, CK_ULONG bool_flag,
7697c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
7707c478bd9Sstevel@tonic-gate {
7717c478bd9Sstevel@tonic-gate
7727c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
7737c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL);
7747c478bd9Sstevel@tonic-gate return (CKR_OK);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate if (template->ulValueLen >= sizeof (CK_BBOOL)) {
7787c478bd9Sstevel@tonic-gate /*
7797c478bd9Sstevel@tonic-gate * The buffer provided by the application is large
7807c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute.
7817c478bd9Sstevel@tonic-gate */
7827c478bd9Sstevel@tonic-gate if (object_p->bool_attr_mask & bool_flag) {
7837c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE;
7847c478bd9Sstevel@tonic-gate } else {
7857c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE;
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate
7887c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL);
7897c478bd9Sstevel@tonic-gate return (CKR_OK);
7907c478bd9Sstevel@tonic-gate } else {
7917c478bd9Sstevel@tonic-gate /*
7927c478bd9Sstevel@tonic-gate * The buffer provided by the application does
7937c478bd9Sstevel@tonic-gate * not have enough space to hold the value.
7947c478bd9Sstevel@tonic-gate */
7957c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
7967c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL);
7977c478bd9Sstevel@tonic-gate }
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate /*
8017c478bd9Sstevel@tonic-gate * Set the boolean data type attribute value in the object.
8027c478bd9Sstevel@tonic-gate */
8037c478bd9Sstevel@tonic-gate CK_RV
set_bool_attr_to_object(soft_object_t * object_p,CK_ULONG bool_flag,CK_ATTRIBUTE_PTR template)8047c478bd9Sstevel@tonic-gate set_bool_attr_to_object(soft_object_t *object_p, CK_ULONG bool_flag,
8057c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
8067c478bd9Sstevel@tonic-gate {
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template->pValue)
8097c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |= bool_flag;
8107c478bd9Sstevel@tonic-gate else
8117c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &= ~bool_flag;
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate return (CKR_OK);
8147c478bd9Sstevel@tonic-gate }
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate
8177c478bd9Sstevel@tonic-gate /*
8187c478bd9Sstevel@tonic-gate * Copy the CK_ULONG data type attribute value from an object to the
8197c478bd9Sstevel@tonic-gate * template.
8207c478bd9Sstevel@tonic-gate */
8217c478bd9Sstevel@tonic-gate CK_RV
get_ulong_attr_from_object(CK_ULONG value,CK_ATTRIBUTE_PTR template)8227c478bd9Sstevel@tonic-gate get_ulong_attr_from_object(CK_ULONG value, CK_ATTRIBUTE_PTR template)
8237c478bd9Sstevel@tonic-gate {
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
8267c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_ULONG);
8277c478bd9Sstevel@tonic-gate return (CKR_OK);
8287c478bd9Sstevel@tonic-gate }
8297c478bd9Sstevel@tonic-gate
8307c478bd9Sstevel@tonic-gate if (template->ulValueLen >= sizeof (CK_ULONG)) {
8317c478bd9Sstevel@tonic-gate /*
8327c478bd9Sstevel@tonic-gate * The buffer provided by the application is large
8337c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute.
8347c478bd9Sstevel@tonic-gate * It is also assumed to be correctly aligned.
8357c478bd9Sstevel@tonic-gate */
8367c478bd9Sstevel@tonic-gate *(CK_ULONG_PTR)template->pValue = value;
8377c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_ULONG);
8387c478bd9Sstevel@tonic-gate return (CKR_OK);
8397c478bd9Sstevel@tonic-gate } else {
8407c478bd9Sstevel@tonic-gate /*
8417c478bd9Sstevel@tonic-gate * The buffer provided by the application does
8427c478bd9Sstevel@tonic-gate * not have enough space to hold the value.
8437c478bd9Sstevel@tonic-gate */
8447c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
8457c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL);
8467c478bd9Sstevel@tonic-gate }
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate /*
8517c478bd9Sstevel@tonic-gate * Copy the CK_ULONG data type attribute value from a template to the
8527c478bd9Sstevel@tonic-gate * object.
8537c478bd9Sstevel@tonic-gate */
8547739299dSAnthony Scarpino static CK_RV
get_ulong_attr_from_template(CK_ULONG * value,CK_ATTRIBUTE_PTR template)8557c478bd9Sstevel@tonic-gate get_ulong_attr_from_template(CK_ULONG *value, CK_ATTRIBUTE_PTR template)
8567c478bd9Sstevel@tonic-gate {
8577c478bd9Sstevel@tonic-gate
8587739299dSAnthony Scarpino if (template->ulValueLen < sizeof (CK_ULONG))
8597739299dSAnthony Scarpino return (CKR_ATTRIBUTE_VALUE_INVALID);
8607739299dSAnthony Scarpino
8617c478bd9Sstevel@tonic-gate if (template->pValue != NULL) {
8627c478bd9Sstevel@tonic-gate *value = *(CK_ULONG_PTR)template->pValue;
8637c478bd9Sstevel@tonic-gate } else {
8647c478bd9Sstevel@tonic-gate *value = 0;
8657c478bd9Sstevel@tonic-gate }
8667739299dSAnthony Scarpino
8677739299dSAnthony Scarpino return (CKR_OK);
8687c478bd9Sstevel@tonic-gate }
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate /*
8717c478bd9Sstevel@tonic-gate * Copy the big integer attribute value from source's biginteger_t to
8727c478bd9Sstevel@tonic-gate * destination's biginteger_t.
8737c478bd9Sstevel@tonic-gate */
8747c478bd9Sstevel@tonic-gate void
copy_bigint_attr(biginteger_t * src,biginteger_t * dst)8757c478bd9Sstevel@tonic-gate copy_bigint_attr(biginteger_t *src, biginteger_t *dst)
8767c478bd9Sstevel@tonic-gate {
8777c478bd9Sstevel@tonic-gate
8787c478bd9Sstevel@tonic-gate if ((src->big_value != NULL) &&
8797c478bd9Sstevel@tonic-gate (src->big_value_len > 0)) {
8807c478bd9Sstevel@tonic-gate /*
8817c478bd9Sstevel@tonic-gate * To do the copy, just have dst's big_value points
8827c478bd9Sstevel@tonic-gate * to src's.
8837c478bd9Sstevel@tonic-gate */
8847c478bd9Sstevel@tonic-gate dst->big_value = src->big_value;
8857c478bd9Sstevel@tonic-gate dst->big_value_len = src->big_value_len;
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate /*
8887c478bd9Sstevel@tonic-gate * After the copy, nullify the src's big_value pointer.
8897c478bd9Sstevel@tonic-gate * It prevents any double freeing the value.
8907c478bd9Sstevel@tonic-gate */
8917c478bd9Sstevel@tonic-gate src->big_value = NULL;
8927c478bd9Sstevel@tonic-gate src->big_value_len = 0;
8937c478bd9Sstevel@tonic-gate } else {
8947c478bd9Sstevel@tonic-gate dst->big_value = NULL;
8957c478bd9Sstevel@tonic-gate dst->big_value_len = 0;
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate }
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate CK_RV
get_string_from_template(CK_ATTRIBUTE_PTR dest,CK_ATTRIBUTE_PTR src)9007c478bd9Sstevel@tonic-gate get_string_from_template(CK_ATTRIBUTE_PTR dest, CK_ATTRIBUTE_PTR src)
9017c478bd9Sstevel@tonic-gate {
9027c478bd9Sstevel@tonic-gate if ((src->pValue != NULL) &&
9037c478bd9Sstevel@tonic-gate (src->ulValueLen > 0)) {
9047c478bd9Sstevel@tonic-gate /* Allocate storage for the value of the attribute. */
9057c478bd9Sstevel@tonic-gate dest->pValue = malloc(src->ulValueLen);
9067c478bd9Sstevel@tonic-gate if (dest->pValue == NULL) {
9077c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate
9107c478bd9Sstevel@tonic-gate (void) memcpy(dest->pValue, src->pValue,
9117c478bd9Sstevel@tonic-gate src->ulValueLen);
9127c478bd9Sstevel@tonic-gate dest->ulValueLen = src->ulValueLen;
9137c478bd9Sstevel@tonic-gate dest->type = src->type;
9147c478bd9Sstevel@tonic-gate } else {
9157c478bd9Sstevel@tonic-gate dest->pValue = NULL;
9167c478bd9Sstevel@tonic-gate dest->ulValueLen = 0;
9177c478bd9Sstevel@tonic-gate dest->type = src->type;
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate return (CKR_OK);
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate }
9237c478bd9Sstevel@tonic-gate
9247c478bd9Sstevel@tonic-gate CK_RV
get_cert_attr_from_template(cert_attr_t ** dest,CK_ATTRIBUTE_PTR src)9257c478bd9Sstevel@tonic-gate get_cert_attr_from_template(cert_attr_t **dest, CK_ATTRIBUTE_PTR src)
9267c478bd9Sstevel@tonic-gate {
9277c478bd9Sstevel@tonic-gate if (src->pValue != NULL && src->ulValueLen > 0) {
9287c478bd9Sstevel@tonic-gate /*
9297c478bd9Sstevel@tonic-gate * If the attribute was already set, clear out the
9307c478bd9Sstevel@tonic-gate * existing value and release the memory.
9317c478bd9Sstevel@tonic-gate */
9327c478bd9Sstevel@tonic-gate if (*dest != NULL) {
9337c478bd9Sstevel@tonic-gate if ((*dest)->value != NULL) {
9347c478bd9Sstevel@tonic-gate (void) memset((*dest)->value, 0,
9357c478bd9Sstevel@tonic-gate (*dest)->length);
9367c478bd9Sstevel@tonic-gate free((*dest)->value);
9377c478bd9Sstevel@tonic-gate }
9387c478bd9Sstevel@tonic-gate } else {
9397c478bd9Sstevel@tonic-gate *dest = malloc(sizeof (cert_attr_t));
9407c478bd9Sstevel@tonic-gate if (*dest == NULL) {
9417c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
9427c478bd9Sstevel@tonic-gate }
9437c478bd9Sstevel@tonic-gate (void) memset(*dest, 0, sizeof (cert_attr_t));
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate (*dest)->value = malloc(src->ulValueLen);
9467c478bd9Sstevel@tonic-gate if ((*dest)->value == NULL) {
9477c478bd9Sstevel@tonic-gate free(*dest);
9487c478bd9Sstevel@tonic-gate *dest = NULL;
9497c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
9507c478bd9Sstevel@tonic-gate }
9517c478bd9Sstevel@tonic-gate (void) memcpy((*dest)->value, src->pValue, src->ulValueLen);
9527c478bd9Sstevel@tonic-gate (*dest)->length = src->ulValueLen;
9537c478bd9Sstevel@tonic-gate }
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate return (CKR_OK);
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate /*
9597c478bd9Sstevel@tonic-gate * Copy the certificate attribute information to the template.
9607c478bd9Sstevel@tonic-gate * If the template attribute is not big enough, set the ulValueLen=-1
9617c478bd9Sstevel@tonic-gate * and return CKR_BUFFER_TOO_SMALL.
9627c478bd9Sstevel@tonic-gate */
9637c478bd9Sstevel@tonic-gate static CK_RV
get_cert_attr_from_object(cert_attr_t * src,CK_ATTRIBUTE_PTR template)9647c478bd9Sstevel@tonic-gate get_cert_attr_from_object(cert_attr_t *src, CK_ATTRIBUTE_PTR template)
9657c478bd9Sstevel@tonic-gate {
9667c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
9677c478bd9Sstevel@tonic-gate template->ulValueLen = src->length;
9687c478bd9Sstevel@tonic-gate return (CKR_OK);
9697c478bd9Sstevel@tonic-gate } else if (template->ulValueLen >= src->length) {
9707c478bd9Sstevel@tonic-gate /*
9717c478bd9Sstevel@tonic-gate * The buffer provided by the application is large
9727c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute.
9737c478bd9Sstevel@tonic-gate */
9747c478bd9Sstevel@tonic-gate (void) memcpy(template->pValue, src->value, src->length);
9757c478bd9Sstevel@tonic-gate template->ulValueLen = src->length;
9767c478bd9Sstevel@tonic-gate return (CKR_OK);
9777c478bd9Sstevel@tonic-gate } else {
9787c478bd9Sstevel@tonic-gate /*
9797c478bd9Sstevel@tonic-gate * The buffer provided by the application does
9807c478bd9Sstevel@tonic-gate * not have enough space to hold the value.
9817c478bd9Sstevel@tonic-gate */
9827c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
9837c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL);
9847c478bd9Sstevel@tonic-gate }
9857c478bd9Sstevel@tonic-gate }
9867c478bd9Sstevel@tonic-gate
9877c478bd9Sstevel@tonic-gate void
string_attr_cleanup(CK_ATTRIBUTE_PTR template)9887c478bd9Sstevel@tonic-gate string_attr_cleanup(CK_ATTRIBUTE_PTR template)
9897c478bd9Sstevel@tonic-gate {
9907c478bd9Sstevel@tonic-gate
9917c478bd9Sstevel@tonic-gate if (template->pValue) {
9927c478bd9Sstevel@tonic-gate free(template->pValue);
9937c478bd9Sstevel@tonic-gate template->pValue = NULL;
9947c478bd9Sstevel@tonic-gate template->ulValueLen = 0;
9957c478bd9Sstevel@tonic-gate }
9967c478bd9Sstevel@tonic-gate }
9977c478bd9Sstevel@tonic-gate
9987c478bd9Sstevel@tonic-gate /*
9997c478bd9Sstevel@tonic-gate * Release the storage allocated for object attribute with big integer
10007c478bd9Sstevel@tonic-gate * value.
10017c478bd9Sstevel@tonic-gate */
10027c478bd9Sstevel@tonic-gate void
bigint_attr_cleanup(biginteger_t * big)10037c478bd9Sstevel@tonic-gate bigint_attr_cleanup(biginteger_t *big)
10047c478bd9Sstevel@tonic-gate {
10057c478bd9Sstevel@tonic-gate
10067c478bd9Sstevel@tonic-gate if (big == NULL)
10077c478bd9Sstevel@tonic-gate return;
10087c478bd9Sstevel@tonic-gate
10097c478bd9Sstevel@tonic-gate if (big->big_value) {
10107c478bd9Sstevel@tonic-gate (void) memset(big->big_value, 0, big->big_value_len);
10117c478bd9Sstevel@tonic-gate free(big->big_value);
10127c478bd9Sstevel@tonic-gate big->big_value = NULL;
10137c478bd9Sstevel@tonic-gate big->big_value_len = 0;
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate }
10167c478bd9Sstevel@tonic-gate
10177c478bd9Sstevel@tonic-gate
10187c478bd9Sstevel@tonic-gate /*
10197c478bd9Sstevel@tonic-gate * Clean up and release all the storage allocated to hold the big integer
10207c478bd9Sstevel@tonic-gate * attributes associated with the type (i.e. class) of the object. Also,
10217c478bd9Sstevel@tonic-gate * release the storage allocated to the type of the object.
10227c478bd9Sstevel@tonic-gate */
10237c478bd9Sstevel@tonic-gate void
soft_cleanup_object_bigint_attrs(soft_object_t * object_p)10247c478bd9Sstevel@tonic-gate soft_cleanup_object_bigint_attrs(soft_object_t *object_p)
10257c478bd9Sstevel@tonic-gate {
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = object_p->class;
10287c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
10297c478bd9Sstevel@tonic-gate
10307c478bd9Sstevel@tonic-gate
10317c478bd9Sstevel@tonic-gate switch (class) {
10327c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY:
10337c478bd9Sstevel@tonic-gate if (OBJ_PUB(object_p)) {
10347c478bd9Sstevel@tonic-gate switch (keytype) {
10357c478bd9Sstevel@tonic-gate case CKK_RSA:
10367c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_RSA_MOD(
10377c478bd9Sstevel@tonic-gate object_p));
10387c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_RSA_PUBEXPO(
10397c478bd9Sstevel@tonic-gate object_p));
10407c478bd9Sstevel@tonic-gate break;
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate case CKK_DSA:
10437c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_PRIME(
10447c478bd9Sstevel@tonic-gate object_p));
10457c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_SUBPRIME(
10467c478bd9Sstevel@tonic-gate object_p));
10477c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_BASE(
10487c478bd9Sstevel@tonic-gate object_p));
10497c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_VALUE(
10507c478bd9Sstevel@tonic-gate object_p));
10517c478bd9Sstevel@tonic-gate break;
10527c478bd9Sstevel@tonic-gate
10537c478bd9Sstevel@tonic-gate case CKK_DH:
10547c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH_PRIME(
10557c478bd9Sstevel@tonic-gate object_p));
10567c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH_BASE(
10577c478bd9Sstevel@tonic-gate object_p));
10587c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH_VALUE(
10597c478bd9Sstevel@tonic-gate object_p));
10607c478bd9Sstevel@tonic-gate break;
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
10637c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH942_PRIME(
10647c478bd9Sstevel@tonic-gate object_p));
10657c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH942_BASE(
10667c478bd9Sstevel@tonic-gate object_p));
10677c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH942_SUBPRIME(
10687c478bd9Sstevel@tonic-gate object_p));
10697c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DH942_VALUE(
10707c478bd9Sstevel@tonic-gate object_p));
10717c478bd9Sstevel@tonic-gate break;
1072034448feSmcpowers case CKK_EC:
1073034448feSmcpowers bigint_attr_cleanup(OBJ_PUB_EC_POINT(
1074034448feSmcpowers object_p));
1075034448feSmcpowers break;
10767c478bd9Sstevel@tonic-gate }
10777c478bd9Sstevel@tonic-gate
10787c478bd9Sstevel@tonic-gate /* Release Public Key Object struct */
10797c478bd9Sstevel@tonic-gate free(OBJ_PUB(object_p));
10807c478bd9Sstevel@tonic-gate OBJ_PUB(object_p) = NULL;
10817c478bd9Sstevel@tonic-gate }
10827c478bd9Sstevel@tonic-gate break;
10837c478bd9Sstevel@tonic-gate
10847c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY:
10857c478bd9Sstevel@tonic-gate if (OBJ_PRI(object_p)) {
10867c478bd9Sstevel@tonic-gate switch (keytype) {
10877c478bd9Sstevel@tonic-gate case CKK_RSA:
10887c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_MOD(
10897c478bd9Sstevel@tonic-gate object_p));
10907c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PUBEXPO(
10917c478bd9Sstevel@tonic-gate object_p));
10927c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PRIEXPO(
10937c478bd9Sstevel@tonic-gate object_p));
10947c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PRIME1(
10957c478bd9Sstevel@tonic-gate object_p));
10967c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PRIME2(
10977c478bd9Sstevel@tonic-gate object_p));
10987c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_EXPO1(
10997c478bd9Sstevel@tonic-gate object_p));
11007c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_EXPO2(
11017c478bd9Sstevel@tonic-gate object_p));
11027c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_COEF(
11037c478bd9Sstevel@tonic-gate object_p));
11047c478bd9Sstevel@tonic-gate break;
11057c478bd9Sstevel@tonic-gate
11067c478bd9Sstevel@tonic-gate case CKK_DSA:
11077c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_PRIME(
11087c478bd9Sstevel@tonic-gate object_p));
11097c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_SUBPRIME(
11107c478bd9Sstevel@tonic-gate object_p));
11117c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_BASE(
11127c478bd9Sstevel@tonic-gate object_p));
11137c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_VALUE(
11147c478bd9Sstevel@tonic-gate object_p));
11157c478bd9Sstevel@tonic-gate break;
11167c478bd9Sstevel@tonic-gate
11177c478bd9Sstevel@tonic-gate case CKK_DH:
11187c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH_PRIME(
11197c478bd9Sstevel@tonic-gate object_p));
11207c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH_BASE(
11217c478bd9Sstevel@tonic-gate object_p));
11227c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH_VALUE(
11237c478bd9Sstevel@tonic-gate object_p));
11247c478bd9Sstevel@tonic-gate break;
11257c478bd9Sstevel@tonic-gate
11267c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
11277c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH942_PRIME(
11287c478bd9Sstevel@tonic-gate object_p));
11297c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH942_BASE(
11307c478bd9Sstevel@tonic-gate object_p));
11317c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH942_SUBPRIME(
11327c478bd9Sstevel@tonic-gate object_p));
11337c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DH942_VALUE(
11347c478bd9Sstevel@tonic-gate object_p));
11357c478bd9Sstevel@tonic-gate break;
1136034448feSmcpowers
1137034448feSmcpowers case CKK_EC:
1138034448feSmcpowers bigint_attr_cleanup(OBJ_PRI_EC_VALUE(
1139034448feSmcpowers object_p));
1140034448feSmcpowers break;
11417c478bd9Sstevel@tonic-gate }
11427c478bd9Sstevel@tonic-gate
11437c478bd9Sstevel@tonic-gate /* Release Private Key Object struct. */
11447c478bd9Sstevel@tonic-gate free(OBJ_PRI(object_p));
11457c478bd9Sstevel@tonic-gate OBJ_PRI(object_p) = NULL;
11467c478bd9Sstevel@tonic-gate }
11477c478bd9Sstevel@tonic-gate break;
11487c478bd9Sstevel@tonic-gate
11497c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY:
11507c478bd9Sstevel@tonic-gate if (OBJ_SEC(object_p)) {
11517c478bd9Sstevel@tonic-gate /* cleanup key data area */
11527c478bd9Sstevel@tonic-gate if (OBJ_SEC_VALUE(object_p) != NULL &&
11537c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p) > 0) {
11547c478bd9Sstevel@tonic-gate (void) memset(OBJ_SEC_VALUE(object_p), 0,
11557c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p));
11567c478bd9Sstevel@tonic-gate free(OBJ_SEC_VALUE(object_p));
11577c478bd9Sstevel@tonic-gate }
11587c478bd9Sstevel@tonic-gate /* cleanup key schedule data area */
11597c478bd9Sstevel@tonic-gate if (OBJ_KEY_SCHED(object_p) != NULL &&
11607c478bd9Sstevel@tonic-gate OBJ_KEY_SCHED_LEN(object_p) > 0) {
11617c478bd9Sstevel@tonic-gate (void) memset(OBJ_KEY_SCHED(object_p), 0,
11627c478bd9Sstevel@tonic-gate OBJ_KEY_SCHED_LEN(object_p));
11637c478bd9Sstevel@tonic-gate free(OBJ_KEY_SCHED(object_p));
11647c478bd9Sstevel@tonic-gate }
11657c478bd9Sstevel@tonic-gate
11667c478bd9Sstevel@tonic-gate /* Release Secret Key Object struct. */
11677c478bd9Sstevel@tonic-gate free(OBJ_SEC(object_p));
11687c478bd9Sstevel@tonic-gate OBJ_SEC(object_p) = NULL;
11697c478bd9Sstevel@tonic-gate }
11707c478bd9Sstevel@tonic-gate break;
11717c478bd9Sstevel@tonic-gate
11727c478bd9Sstevel@tonic-gate case CKO_DOMAIN_PARAMETERS:
11737c478bd9Sstevel@tonic-gate if (OBJ_DOM(object_p)) {
11747c478bd9Sstevel@tonic-gate switch (keytype) {
11757c478bd9Sstevel@tonic-gate case CKK_DSA:
11767c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DSA_PRIME(
11777c478bd9Sstevel@tonic-gate object_p));
11787c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DSA_SUBPRIME(
11797c478bd9Sstevel@tonic-gate object_p));
11807c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DSA_BASE(
11817c478bd9Sstevel@tonic-gate object_p));
11827c478bd9Sstevel@tonic-gate break;
11837c478bd9Sstevel@tonic-gate
11847c478bd9Sstevel@tonic-gate case CKK_DH:
11857c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DH_PRIME(
11867c478bd9Sstevel@tonic-gate object_p));
11877c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DH_BASE(
11887c478bd9Sstevel@tonic-gate object_p));
11897c478bd9Sstevel@tonic-gate break;
11907c478bd9Sstevel@tonic-gate
11917c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
11927c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DH942_PRIME(
11937c478bd9Sstevel@tonic-gate object_p));
11947c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DH942_BASE(
11957c478bd9Sstevel@tonic-gate object_p));
11967c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_DOM_DH942_SUBPRIME(
11977c478bd9Sstevel@tonic-gate object_p));
11987c478bd9Sstevel@tonic-gate break;
11997c478bd9Sstevel@tonic-gate }
12007c478bd9Sstevel@tonic-gate
12017c478bd9Sstevel@tonic-gate /* Release Domain Parameters Object struct. */
12027c478bd9Sstevel@tonic-gate free(OBJ_DOM(object_p));
12037c478bd9Sstevel@tonic-gate OBJ_DOM(object_p) = NULL;
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate break;
12067c478bd9Sstevel@tonic-gate }
12077c478bd9Sstevel@tonic-gate }
12087c478bd9Sstevel@tonic-gate
12097c478bd9Sstevel@tonic-gate
12107c478bd9Sstevel@tonic-gate /*
12117c478bd9Sstevel@tonic-gate * Parse the common attributes. Return to caller with appropriate return
12127c478bd9Sstevel@tonic-gate * value to indicate if the supplied template specifies a valid attribute
12137c478bd9Sstevel@tonic-gate * with a valid value.
12147c478bd9Sstevel@tonic-gate */
12157c478bd9Sstevel@tonic-gate CK_RV
soft_parse_common_attrs(CK_ATTRIBUTE_PTR template,uchar_t * object_type)12167c478bd9Sstevel@tonic-gate soft_parse_common_attrs(CK_ATTRIBUTE_PTR template, uchar_t *object_type)
12177c478bd9Sstevel@tonic-gate {
12187c478bd9Sstevel@tonic-gate
12197c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
12207c478bd9Sstevel@tonic-gate
12217c478bd9Sstevel@tonic-gate switch (template->type) {
12227c478bd9Sstevel@tonic-gate case CKA_CLASS:
12237c478bd9Sstevel@tonic-gate break;
12247c478bd9Sstevel@tonic-gate
12257c478bd9Sstevel@tonic-gate /* default boolean attributes */
12267c478bd9Sstevel@tonic-gate case CKA_TOKEN:
12277c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_TRUE) {
122890e0e8c4Sizick if (!soft_keystore_status(KEYSTORE_INITIALIZED))
12297c478bd9Sstevel@tonic-gate return (CKR_DEVICE_REMOVED);
12307c478bd9Sstevel@tonic-gate *object_type |= TOKEN_OBJECT;
12317c478bd9Sstevel@tonic-gate }
12327c478bd9Sstevel@tonic-gate break;
12337c478bd9Sstevel@tonic-gate
12347c478bd9Sstevel@tonic-gate case CKA_PRIVATE:
12357c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_TRUE) {
12367c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&soft_giant_mutex);
12377c478bd9Sstevel@tonic-gate if (!soft_slot.authenticated) {
12387c478bd9Sstevel@tonic-gate /*
12397c478bd9Sstevel@tonic-gate * Check if this is the special case when
12407c478bd9Sstevel@tonic-gate * the PIN is never initialized in the keystore.
12417c478bd9Sstevel@tonic-gate * If true, we will let it pass here and let
12427c478bd9Sstevel@tonic-gate * it fail with CKR_PIN_EXPIRED later on.
12437c478bd9Sstevel@tonic-gate */
12447c478bd9Sstevel@tonic-gate if (!soft_slot.userpin_change_needed) {
12457c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(
12467c478bd9Sstevel@tonic-gate &soft_giant_mutex);
12477c478bd9Sstevel@tonic-gate return (CKR_USER_NOT_LOGGED_IN);
12487c478bd9Sstevel@tonic-gate }
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&soft_giant_mutex);
12517c478bd9Sstevel@tonic-gate *object_type |= PRIVATE_OBJECT;
12527c478bd9Sstevel@tonic-gate }
12537c478bd9Sstevel@tonic-gate break;
12547c478bd9Sstevel@tonic-gate
12557c478bd9Sstevel@tonic-gate case CKA_LABEL:
12567c478bd9Sstevel@tonic-gate break;
12577c478bd9Sstevel@tonic-gate
12587c478bd9Sstevel@tonic-gate default:
12597c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
12607c478bd9Sstevel@tonic-gate }
12617c478bd9Sstevel@tonic-gate
12627c478bd9Sstevel@tonic-gate return (rv);
12637c478bd9Sstevel@tonic-gate }
12647c478bd9Sstevel@tonic-gate
12657c478bd9Sstevel@tonic-gate
12667c478bd9Sstevel@tonic-gate /*
12677c478bd9Sstevel@tonic-gate * Build a Public Key Object.
12687c478bd9Sstevel@tonic-gate *
12697c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as
12707c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return
12717c478bd9Sstevel@tonic-gate * with appropriate return value.
12727c478bd9Sstevel@tonic-gate * - Set up attribute mask field in the object for the supplied common
12737c478bd9Sstevel@tonic-gate * attributes that have boolean type.
12747c478bd9Sstevel@tonic-gate * - Build the attribute_info struct to hold the value of each supplied
12757c478bd9Sstevel@tonic-gate * attribute that has byte array type. Link attribute_info structs
12767c478bd9Sstevel@tonic-gate * together to form the extra attribute list of the object.
12777c478bd9Sstevel@tonic-gate * - Allocate storage for the Public Key object.
12787c478bd9Sstevel@tonic-gate * - Build the Public Key object according to the key type. Allocate
12797c478bd9Sstevel@tonic-gate * storage to hold the big integer value for the supplied attributes
12807c478bd9Sstevel@tonic-gate * that are required for a certain key type.
12817c478bd9Sstevel@tonic-gate *
12827c478bd9Sstevel@tonic-gate */
12837c478bd9Sstevel@tonic-gate CK_RV
soft_build_public_key_object(CK_ATTRIBUTE_PTR template,CK_ULONG ulAttrNum,soft_object_t * new_object,CK_ULONG mode,CK_KEY_TYPE key_type)12847c478bd9Sstevel@tonic-gate soft_build_public_key_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
12857c478bd9Sstevel@tonic-gate soft_object_t *new_object, CK_ULONG mode, CK_KEY_TYPE key_type)
12867c478bd9Sstevel@tonic-gate {
12877c478bd9Sstevel@tonic-gate
12887c478bd9Sstevel@tonic-gate ulong_t i;
12897c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL;
12907c478bd9Sstevel@tonic-gate uint64_t attr_mask = PUBLIC_KEY_DEFAULT;
12917c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
12927c478bd9Sstevel@tonic-gate int isLabel = 0;
12937c478bd9Sstevel@tonic-gate /* Must set flags */
12947c478bd9Sstevel@tonic-gate int isModulus = 0;
12957c478bd9Sstevel@tonic-gate int isPubExpo = 0;
12967c478bd9Sstevel@tonic-gate int isPrime = 0;
12977c478bd9Sstevel@tonic-gate int isSubprime = 0;
12987c478bd9Sstevel@tonic-gate int isBase = 0;
12997c478bd9Sstevel@tonic-gate int isValue = 0;
1300034448feSmcpowers int isECParam = 0;
1301034448feSmcpowers int isECPoint = 0;
13027c478bd9Sstevel@tonic-gate /* Must not set flags */
13037c478bd9Sstevel@tonic-gate int isModulusBits = 0;
13047c478bd9Sstevel@tonic-gate CK_ULONG modulus_bits = 0;
13057c478bd9Sstevel@tonic-gate
13067c478bd9Sstevel@tonic-gate biginteger_t modulus;
13077c478bd9Sstevel@tonic-gate biginteger_t pubexpo;
1308f9fbec18Smcpowers biginteger_t prime;
1309f9fbec18Smcpowers biginteger_t subprime;
13107c478bd9Sstevel@tonic-gate biginteger_t base;
13117c478bd9Sstevel@tonic-gate biginteger_t value;
1312f9fbec18Smcpowers biginteger_t point;
13137c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp;
1314f9fbec18Smcpowers CK_ATTRIBUTE param_tmp;
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate public_key_obj_t *pbk;
13177c478bd9Sstevel@tonic-gate uchar_t object_type = 0;
13187c478bd9Sstevel@tonic-gate
131920d58091SDina K Nimeh CK_ATTRIBUTE defpubexpo = { CKA_PUBLIC_EXPONENT,
132020d58091SDina K Nimeh (CK_BYTE_PTR)DEFAULT_PUB_EXPO, DEFAULT_PUB_EXPO_Len };
132120d58091SDina K Nimeh
132220d58091SDina K Nimeh BIGNUM n;
132320d58091SDina K Nimeh
13247c478bd9Sstevel@tonic-gate /* prevent bigint_attr_cleanup from freeing invalid attr value */
13257c478bd9Sstevel@tonic-gate (void) memset(&modulus, 0x0, sizeof (biginteger_t));
13267c478bd9Sstevel@tonic-gate (void) memset(&pubexpo, 0x0, sizeof (biginteger_t));
13277c478bd9Sstevel@tonic-gate (void) memset(&prime, 0x0, sizeof (biginteger_t));
13287c478bd9Sstevel@tonic-gate (void) memset(&subprime, 0x0, sizeof (biginteger_t));
13297c478bd9Sstevel@tonic-gate (void) memset(&base, 0x0, sizeof (biginteger_t));
13307c478bd9Sstevel@tonic-gate (void) memset(&value, 0x0, sizeof (biginteger_t));
1331f9fbec18Smcpowers (void) memset(&point, 0x0, sizeof (biginteger_t));
13327c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL;
1333f9fbec18Smcpowers param_tmp.pValue = NULL;
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate /* Public Key Object Attributes */
13387c478bd9Sstevel@tonic-gate switch (template[i].type) {
13397c478bd9Sstevel@tonic-gate
13407c478bd9Sstevel@tonic-gate /* common key attributes */
13417c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
13427c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue);
13437c478bd9Sstevel@tonic-gate break;
13447c478bd9Sstevel@tonic-gate
13457c478bd9Sstevel@tonic-gate case CKA_ID:
13467c478bd9Sstevel@tonic-gate case CKA_START_DATE:
13477c478bd9Sstevel@tonic-gate case CKA_END_DATE:
13487c478bd9Sstevel@tonic-gate
13497c478bd9Sstevel@tonic-gate /* common public key attribute */
13507c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
13517c478bd9Sstevel@tonic-gate /*
13527c478bd9Sstevel@tonic-gate * Allocate storage to hold the attribute
13537c478bd9Sstevel@tonic-gate * value with byte array type, and add it to
13547c478bd9Sstevel@tonic-gate * the extra attribute list of the object.
13557c478bd9Sstevel@tonic-gate */
13567c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&template[i],
13577c478bd9Sstevel@tonic-gate new_object);
13587c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
13597c478bd9Sstevel@tonic-gate goto fail_cleanup;
13607c478bd9Sstevel@tonic-gate }
13617c478bd9Sstevel@tonic-gate break;
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate /*
13647c478bd9Sstevel@tonic-gate * The following key related attribute types must
13657c478bd9Sstevel@tonic-gate * not be specified by C_CreateObject, C_GenerateKey(Pair).
13667c478bd9Sstevel@tonic-gate */
13677c478bd9Sstevel@tonic-gate case CKA_LOCAL:
13687c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM:
13697c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
13707c478bd9Sstevel@tonic-gate goto fail_cleanup;
13717c478bd9Sstevel@tonic-gate
13727c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
13737c478bd9Sstevel@tonic-gate case CKA_DERIVE:
13747c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
13757c478bd9Sstevel@tonic-gate attr_mask |= DERIVE_BOOL_ON;
13767c478bd9Sstevel@tonic-gate break;
13777c478bd9Sstevel@tonic-gate
13787c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
13797c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
13807c478bd9Sstevel@tonic-gate attr_mask |= ENCRYPT_BOOL_ON;
13817c478bd9Sstevel@tonic-gate else
13827c478bd9Sstevel@tonic-gate attr_mask &= ~ENCRYPT_BOOL_ON;
13837c478bd9Sstevel@tonic-gate break;
13847c478bd9Sstevel@tonic-gate
13857c478bd9Sstevel@tonic-gate case CKA_VERIFY:
13867c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
13877c478bd9Sstevel@tonic-gate attr_mask |= VERIFY_BOOL_ON;
13887c478bd9Sstevel@tonic-gate else
13897c478bd9Sstevel@tonic-gate attr_mask &= ~VERIFY_BOOL_ON;
13907c478bd9Sstevel@tonic-gate break;
13917c478bd9Sstevel@tonic-gate
13927c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER:
13937c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
13947c478bd9Sstevel@tonic-gate attr_mask |= VERIFY_RECOVER_BOOL_ON;
13957c478bd9Sstevel@tonic-gate else
13967c478bd9Sstevel@tonic-gate attr_mask &= ~VERIFY_RECOVER_BOOL_ON;
13977c478bd9Sstevel@tonic-gate break;
13987c478bd9Sstevel@tonic-gate
13997c478bd9Sstevel@tonic-gate case CKA_WRAP:
14007c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
14017c478bd9Sstevel@tonic-gate attr_mask |= WRAP_BOOL_ON;
14027c478bd9Sstevel@tonic-gate else
14037c478bd9Sstevel@tonic-gate attr_mask &= ~WRAP_BOOL_ON;
14047c478bd9Sstevel@tonic-gate break;
14057c478bd9Sstevel@tonic-gate
14067c478bd9Sstevel@tonic-gate case CKA_TRUSTED:
14077c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
14087c478bd9Sstevel@tonic-gate attr_mask |= TRUSTED_BOOL_ON;
14097c478bd9Sstevel@tonic-gate break;
14107c478bd9Sstevel@tonic-gate
14117c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
14127c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template[i].pValue) == B_FALSE)
14137c478bd9Sstevel@tonic-gate attr_mask |= NOT_MODIFIABLE_BOOL_ON;
14147c478bd9Sstevel@tonic-gate break;
14157c478bd9Sstevel@tonic-gate
14167c478bd9Sstevel@tonic-gate /*
14177c478bd9Sstevel@tonic-gate * The following key related attribute types must
14187c478bd9Sstevel@tonic-gate * be specified according to the key type by
14197c478bd9Sstevel@tonic-gate * C_CreateObject.
14207c478bd9Sstevel@tonic-gate */
14217c478bd9Sstevel@tonic-gate case CKA_MODULUS:
14227c478bd9Sstevel@tonic-gate
14237c478bd9Sstevel@tonic-gate isModulus = 1;
14247c478bd9Sstevel@tonic-gate /*
14257c478bd9Sstevel@tonic-gate * Copyin big integer attribute from template
14267c478bd9Sstevel@tonic-gate * to a local variable.
14277c478bd9Sstevel@tonic-gate */
14287c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&modulus,
14297c478bd9Sstevel@tonic-gate &template[i]);
14307c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
14317c478bd9Sstevel@tonic-gate goto fail_cleanup;
14327c478bd9Sstevel@tonic-gate
14337c478bd9Sstevel@tonic-gate /*
14347c478bd9Sstevel@tonic-gate * Modulus length needs to be between min key length and
14357c478bd9Sstevel@tonic-gate * max key length.
14367c478bd9Sstevel@tonic-gate */
14377c478bd9Sstevel@tonic-gate if ((modulus.big_value_len <
14387c478bd9Sstevel@tonic-gate MIN_RSA_KEYLENGTH_IN_BYTES) ||
14397c478bd9Sstevel@tonic-gate (modulus.big_value_len >
14407c478bd9Sstevel@tonic-gate MAX_RSA_KEYLENGTH_IN_BYTES)) {
14417c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
14427c478bd9Sstevel@tonic-gate goto fail_cleanup;
14437c478bd9Sstevel@tonic-gate }
14447c478bd9Sstevel@tonic-gate break;
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
14477c478bd9Sstevel@tonic-gate isPubExpo = 1;
14487c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&pubexpo,
14497c478bd9Sstevel@tonic-gate &template[i]);
14507c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
14517c478bd9Sstevel@tonic-gate goto fail_cleanup;
14527c478bd9Sstevel@tonic-gate break;
14537c478bd9Sstevel@tonic-gate
14547c478bd9Sstevel@tonic-gate case CKA_PRIME:
14557c478bd9Sstevel@tonic-gate isPrime = 1;
14567c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime,
14577c478bd9Sstevel@tonic-gate &template[i]);
14587c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
14597c478bd9Sstevel@tonic-gate goto fail_cleanup;
14607c478bd9Sstevel@tonic-gate break;
14617c478bd9Sstevel@tonic-gate
14627c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
14637c478bd9Sstevel@tonic-gate isSubprime = 1;
14647c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&subprime,
14657c478bd9Sstevel@tonic-gate &template[i]);
14667c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
14677c478bd9Sstevel@tonic-gate goto fail_cleanup;
14687c478bd9Sstevel@tonic-gate break;
14697c478bd9Sstevel@tonic-gate
14707c478bd9Sstevel@tonic-gate case CKA_BASE:
14717c478bd9Sstevel@tonic-gate isBase = 1;
14727c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&base,
14737c478bd9Sstevel@tonic-gate &template[i]);
14747c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
14757c478bd9Sstevel@tonic-gate goto fail_cleanup;
14767c478bd9Sstevel@tonic-gate break;
14777c478bd9Sstevel@tonic-gate
14787c478bd9Sstevel@tonic-gate case CKA_VALUE:
14797c478bd9Sstevel@tonic-gate isValue = 1;
14807c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
14817c478bd9Sstevel@tonic-gate if ((template[i].ulValueLen == 0) ||
14827c478bd9Sstevel@tonic-gate (template[i].pValue == NULL)) {
14837c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
14847c478bd9Sstevel@tonic-gate goto fail_cleanup;
14857c478bd9Sstevel@tonic-gate }
14867c478bd9Sstevel@tonic-gate }
14877c478bd9Sstevel@tonic-gate
14887c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&value,
14897c478bd9Sstevel@tonic-gate &template[i]);
14907c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
14917c478bd9Sstevel@tonic-gate goto fail_cleanup;
14927c478bd9Sstevel@tonic-gate break;
14937c478bd9Sstevel@tonic-gate
14947c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS:
14957c478bd9Sstevel@tonic-gate isModulusBits = 1;
14967739299dSAnthony Scarpino rv = get_ulong_attr_from_template(&modulus_bits,
14977c478bd9Sstevel@tonic-gate &template[i]);
14987739299dSAnthony Scarpino if (rv != CKR_OK)
14997739299dSAnthony Scarpino goto fail_cleanup;
15007c478bd9Sstevel@tonic-gate break;
15017c478bd9Sstevel@tonic-gate
15027c478bd9Sstevel@tonic-gate case CKA_LABEL:
15037c478bd9Sstevel@tonic-gate isLabel = 1;
15047c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp,
15057c478bd9Sstevel@tonic-gate &template[i]);
15067c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
15077c478bd9Sstevel@tonic-gate goto fail_cleanup;
15087c478bd9Sstevel@tonic-gate break;
15097c478bd9Sstevel@tonic-gate
1510034448feSmcpowers case CKA_EC_PARAMS:
1511034448feSmcpowers isECParam = 1;
1512f9fbec18Smcpowers rv = get_string_from_template(¶m_tmp, &template[i]);
1513034448feSmcpowers if (rv != CKR_OK)
1514034448feSmcpowers goto fail_cleanup;
1515034448feSmcpowers break;
1516034448feSmcpowers
1517034448feSmcpowers case CKA_EC_POINT:
1518034448feSmcpowers isECPoint = 1;
1519f9fbec18Smcpowers rv = get_bigint_attr_from_template(&point,
1520034448feSmcpowers &template[i]);
1521034448feSmcpowers if (rv != CKR_OK)
1522034448feSmcpowers goto fail_cleanup;
1523034448feSmcpowers break;
1524034448feSmcpowers
15257c478bd9Sstevel@tonic-gate default:
15267c478bd9Sstevel@tonic-gate rv = soft_parse_common_attrs(&template[i],
15277c478bd9Sstevel@tonic-gate &object_type);
15287c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
15297c478bd9Sstevel@tonic-gate goto fail_cleanup;
15307c478bd9Sstevel@tonic-gate break;
15317c478bd9Sstevel@tonic-gate }
15327c478bd9Sstevel@tonic-gate } /* For */
15337c478bd9Sstevel@tonic-gate
15347c478bd9Sstevel@tonic-gate /* Allocate storage for Public Key Object. */
15357c478bd9Sstevel@tonic-gate pbk = calloc(1, sizeof (public_key_obj_t));
15367c478bd9Sstevel@tonic-gate if (pbk == NULL) {
15377c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY;
15387c478bd9Sstevel@tonic-gate goto fail_cleanup;
15397c478bd9Sstevel@tonic-gate }
15407c478bd9Sstevel@tonic-gate
15417c478bd9Sstevel@tonic-gate new_object->object_class_u.public_key = pbk;
15427c478bd9Sstevel@tonic-gate new_object->class = CKO_PUBLIC_KEY;
15437c478bd9Sstevel@tonic-gate
15447c478bd9Sstevel@tonic-gate if ((mode == SOFT_CREATE_OBJ) && (keytype == (CK_KEY_TYPE)~0UL)) {
15457c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
15467c478bd9Sstevel@tonic-gate goto fail_cleanup;
15477c478bd9Sstevel@tonic-gate }
15487c478bd9Sstevel@tonic-gate
15497c478bd9Sstevel@tonic-gate if ((mode == SOFT_GEN_KEY) && (keytype == (CK_KEY_TYPE)~0UL)) {
15507c478bd9Sstevel@tonic-gate keytype = key_type;
15517c478bd9Sstevel@tonic-gate }
15527c478bd9Sstevel@tonic-gate
15537c478bd9Sstevel@tonic-gate if ((mode == SOFT_GEN_KEY) && (keytype != key_type)) {
15547c478bd9Sstevel@tonic-gate /*
15557c478bd9Sstevel@tonic-gate * The key type specified in the template does not
15567c478bd9Sstevel@tonic-gate * match the implied key type based on the mechanism.
15577c478bd9Sstevel@tonic-gate */
15587c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
15597c478bd9Sstevel@tonic-gate goto fail_cleanup;
15607c478bd9Sstevel@tonic-gate }
15617c478bd9Sstevel@tonic-gate
15627c478bd9Sstevel@tonic-gate new_object->key_type = keytype;
15637c478bd9Sstevel@tonic-gate
15647c478bd9Sstevel@tonic-gate /* Supported key types of the Public Key Object */
15657c478bd9Sstevel@tonic-gate switch (keytype) {
15667c478bd9Sstevel@tonic-gate
15677c478bd9Sstevel@tonic-gate case CKK_RSA:
15687c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
15697c478bd9Sstevel@tonic-gate if (isModulusBits || isPrime || isSubprime ||
15707c478bd9Sstevel@tonic-gate isBase || isValue) {
15717c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
15727c478bd9Sstevel@tonic-gate goto fail_cleanup;
15737c478bd9Sstevel@tonic-gate }
15747c478bd9Sstevel@tonic-gate
15757c478bd9Sstevel@tonic-gate if (isModulus && isPubExpo) {
15767c478bd9Sstevel@tonic-gate /*
15775cd3be5eSDina K Nimeh * Derive modulus_bits attribute from modulus.
15785cd3be5eSDina K Nimeh * Save modulus_bits integer value to the
15795cd3be5eSDina K Nimeh * designated place in the public key object.
15805cd3be5eSDina K Nimeh */
15815cd3be5eSDina K Nimeh n.malloced = 0;
15825cd3be5eSDina K Nimeh #ifdef __sparcv9
15835cd3be5eSDina K Nimeh if (big_init(&n, (int)CHARLEN2BIGNUMLEN(
15845cd3be5eSDina K Nimeh modulus.big_value_len)) != BIG_OK) {
15855cd3be5eSDina K Nimeh #else /* !__sparcv9 */
15865cd3be5eSDina K Nimeh if (big_init(&n, CHARLEN2BIGNUMLEN(
15875cd3be5eSDina K Nimeh modulus.big_value_len)) != BIG_OK) {
15885cd3be5eSDina K Nimeh #endif /* __sparcv9 */
15895cd3be5eSDina K Nimeh rv = CKR_HOST_MEMORY;
15905cd3be5eSDina K Nimeh big_finish(&n);
15915cd3be5eSDina K Nimeh goto fail_cleanup;
15925cd3be5eSDina K Nimeh }
15935cd3be5eSDina K Nimeh bytestring2bignum(&n, modulus.big_value,
15945cd3be5eSDina K Nimeh modulus.big_value_len);
15955cd3be5eSDina K Nimeh
15965cd3be5eSDina K Nimeh modulus_bits = big_bitlength(&n);
15975cd3be5eSDina K Nimeh KEY_PUB_RSA_MOD_BITS(pbk) = modulus_bits;
15985cd3be5eSDina K Nimeh big_finish(&n);
15995cd3be5eSDina K Nimeh
16005cd3be5eSDina K Nimeh /*
16015cd3be5eSDina K Nimeh * After modulus_bits has been computed,
16025cd3be5eSDina K Nimeh * it is safe to move modulus and pubexpo
16035cd3be5eSDina K Nimeh * big integer attribute value to the
16047c478bd9Sstevel@tonic-gate * designated place in the public key object.
16057c478bd9Sstevel@tonic-gate */
16067c478bd9Sstevel@tonic-gate copy_bigint_attr(&modulus,
16077c478bd9Sstevel@tonic-gate KEY_PUB_RSA_MOD(pbk));
16087c478bd9Sstevel@tonic-gate
16097c478bd9Sstevel@tonic-gate copy_bigint_attr(&pubexpo,
16107c478bd9Sstevel@tonic-gate KEY_PUB_RSA_PUBEXPO(pbk));
16117c478bd9Sstevel@tonic-gate } else {
16127c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
16137c478bd9Sstevel@tonic-gate goto fail_cleanup;
16147c478bd9Sstevel@tonic-gate }
16157c478bd9Sstevel@tonic-gate } else {
161620d58091SDina K Nimeh /* mode is SOFT_GEN_KEY */
161720d58091SDina K Nimeh
16187c478bd9Sstevel@tonic-gate if (isModulus || isPrime || isSubprime ||
16197c478bd9Sstevel@tonic-gate isBase || isValue) {
16207c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
16217c478bd9Sstevel@tonic-gate goto fail_cleanup;
16227c478bd9Sstevel@tonic-gate }
16237c478bd9Sstevel@tonic-gate
162420d58091SDina K Nimeh
162520d58091SDina K Nimeh if (isModulusBits) {
16267c478bd9Sstevel@tonic-gate /*
16277c478bd9Sstevel@tonic-gate * Copy big integer attribute value to the
16287c478bd9Sstevel@tonic-gate * designated place in the public key object.
16297c478bd9Sstevel@tonic-gate */
16307c478bd9Sstevel@tonic-gate KEY_PUB_RSA_MOD_BITS(pbk) = modulus_bits;
16317c478bd9Sstevel@tonic-gate } else {
16327c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
16337c478bd9Sstevel@tonic-gate goto fail_cleanup;
16347c478bd9Sstevel@tonic-gate }
163520d58091SDina K Nimeh
163620d58091SDina K Nimeh /*
163720d58091SDina K Nimeh * Use PKCS#11 default 0x010001 for public exponent
163820d58091SDina K Nimeh * if not not specified in attribute template.
163920d58091SDina K Nimeh */
164020d58091SDina K Nimeh if (!isPubExpo) {
164120d58091SDina K Nimeh isPubExpo = 1;
164220d58091SDina K Nimeh rv = get_bigint_attr_from_template(&pubexpo,
164320d58091SDina K Nimeh &defpubexpo);
164420d58091SDina K Nimeh if (rv != CKR_OK)
164520d58091SDina K Nimeh goto fail_cleanup;
164620d58091SDina K Nimeh }
164720d58091SDina K Nimeh /*
164820d58091SDina K Nimeh * Copy big integer attribute value to the
164920d58091SDina K Nimeh * designated place in the public key object.
165020d58091SDina K Nimeh */
165120d58091SDina K Nimeh copy_bigint_attr(&pubexpo, KEY_PUB_RSA_PUBEXPO(pbk));
16527c478bd9Sstevel@tonic-gate }
16537c478bd9Sstevel@tonic-gate
16547c478bd9Sstevel@tonic-gate break;
16557c478bd9Sstevel@tonic-gate
16567c478bd9Sstevel@tonic-gate case CKK_DSA:
16577c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
16587c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo) {
16597c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
16607c478bd9Sstevel@tonic-gate goto fail_cleanup;
16617c478bd9Sstevel@tonic-gate }
16627c478bd9Sstevel@tonic-gate
16637c478bd9Sstevel@tonic-gate if (isPrime && isSubprime && isBase && isValue) {
16647c478bd9Sstevel@tonic-gate copy_bigint_attr(&value,
16657c478bd9Sstevel@tonic-gate KEY_PUB_DSA_VALUE(pbk));
16667c478bd9Sstevel@tonic-gate } else {
16677c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
16687c478bd9Sstevel@tonic-gate goto fail_cleanup;
16697c478bd9Sstevel@tonic-gate }
16707c478bd9Sstevel@tonic-gate } else {
16717c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo ||
16727c478bd9Sstevel@tonic-gate isValue) {
16737c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
16747c478bd9Sstevel@tonic-gate goto fail_cleanup;
16757c478bd9Sstevel@tonic-gate }
16767c478bd9Sstevel@tonic-gate
16777c478bd9Sstevel@tonic-gate if (!(isPrime && isSubprime && isBase)) {
16787c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
16797c478bd9Sstevel@tonic-gate goto fail_cleanup;
16807c478bd9Sstevel@tonic-gate }
16817c478bd9Sstevel@tonic-gate }
16827c478bd9Sstevel@tonic-gate
16837c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PUB_DSA_PRIME(pbk));
16847c478bd9Sstevel@tonic-gate
16857c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime, KEY_PUB_DSA_SUBPRIME(pbk));
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PUB_DSA_BASE(pbk));
16887c478bd9Sstevel@tonic-gate
16897c478bd9Sstevel@tonic-gate break;
16907c478bd9Sstevel@tonic-gate
16917c478bd9Sstevel@tonic-gate case CKK_DH:
16927c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
16937c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo ||
16947c478bd9Sstevel@tonic-gate isSubprime) {
16957c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
16967c478bd9Sstevel@tonic-gate goto fail_cleanup;
16977c478bd9Sstevel@tonic-gate }
16987c478bd9Sstevel@tonic-gate
16997c478bd9Sstevel@tonic-gate if (isPrime && isBase && isValue) {
17007c478bd9Sstevel@tonic-gate copy_bigint_attr(&value,
17017c478bd9Sstevel@tonic-gate KEY_PUB_DH_VALUE(pbk));
17027c478bd9Sstevel@tonic-gate } else {
17037c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
17047c478bd9Sstevel@tonic-gate goto fail_cleanup;
17057c478bd9Sstevel@tonic-gate }
17067c478bd9Sstevel@tonic-gate } else {
17077c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo ||
17087c478bd9Sstevel@tonic-gate isSubprime || isValue) {
17097c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
17107c478bd9Sstevel@tonic-gate goto fail_cleanup;
17117c478bd9Sstevel@tonic-gate }
17127c478bd9Sstevel@tonic-gate
17137c478bd9Sstevel@tonic-gate if (!(isPrime && isBase)) {
17147c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
17157c478bd9Sstevel@tonic-gate goto fail_cleanup;
17167c478bd9Sstevel@tonic-gate }
17177c478bd9Sstevel@tonic-gate }
17187c478bd9Sstevel@tonic-gate
17197c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PUB_DH_PRIME(pbk));
17207c478bd9Sstevel@tonic-gate
17217c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PUB_DH_BASE(pbk));
17227c478bd9Sstevel@tonic-gate
17237c478bd9Sstevel@tonic-gate break;
17247c478bd9Sstevel@tonic-gate
17257c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
17267c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
17277c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo) {
17287c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
17297c478bd9Sstevel@tonic-gate goto fail_cleanup;
17307c478bd9Sstevel@tonic-gate }
17317c478bd9Sstevel@tonic-gate
17327c478bd9Sstevel@tonic-gate if (isPrime && isSubprime && isBase && isValue) {
17337c478bd9Sstevel@tonic-gate copy_bigint_attr(&value,
17347c478bd9Sstevel@tonic-gate KEY_PUB_DH942_VALUE(pbk));
17357c478bd9Sstevel@tonic-gate } else {
17367c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
17377c478bd9Sstevel@tonic-gate goto fail_cleanup;
17387c478bd9Sstevel@tonic-gate }
17397c478bd9Sstevel@tonic-gate } else {
17407c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo ||
17417c478bd9Sstevel@tonic-gate isValue) {
17427c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
17437c478bd9Sstevel@tonic-gate goto fail_cleanup;
17447c478bd9Sstevel@tonic-gate }
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gate if (!(isPrime && isSubprime && isBase)) {
17477c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
17487c478bd9Sstevel@tonic-gate goto fail_cleanup;
17497c478bd9Sstevel@tonic-gate }
17507c478bd9Sstevel@tonic-gate }
17517c478bd9Sstevel@tonic-gate
17527c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PUB_DH942_PRIME(pbk));
17537c478bd9Sstevel@tonic-gate
17547c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PUB_DH942_BASE(pbk));
17557c478bd9Sstevel@tonic-gate
17567c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime, KEY_PUB_DH942_SUBPRIME(pbk));
17577c478bd9Sstevel@tonic-gate
17587c478bd9Sstevel@tonic-gate break;
17597c478bd9Sstevel@tonic-gate
1760034448feSmcpowers case CKK_EC:
1761f9fbec18Smcpowers if (mode == SOFT_CREATE_OBJ) {
1762f9fbec18Smcpowers if (isModulusBits || isModulus || isPubExpo ||
1763f9fbec18Smcpowers isPrime || isSubprime || isBase || isValue) {
1764034448feSmcpowers rv = CKR_TEMPLATE_INCONSISTENT;
1765034448feSmcpowers goto fail_cleanup;
1766034448feSmcpowers
1767f9fbec18Smcpowers } else if (!isECParam || !isECPoint) {
1768034448feSmcpowers rv = CKR_TEMPLATE_INCOMPLETE;
1769034448feSmcpowers goto fail_cleanup;
1770034448feSmcpowers }
1771f9fbec18Smcpowers } else {
1772f9fbec18Smcpowers if (isModulusBits || isModulus || isPubExpo ||
1773f9fbec18Smcpowers isPrime || isSubprime || isBase || isValue) {
1774f9fbec18Smcpowers rv = CKR_TEMPLATE_INCONSISTENT;
1775f9fbec18Smcpowers goto fail_cleanup;
1776034448feSmcpowers
1777f9fbec18Smcpowers } else if (!isECParam) {
1778f9fbec18Smcpowers rv = CKR_TEMPLATE_INCOMPLETE;
1779f9fbec18Smcpowers goto fail_cleanup;
1780f9fbec18Smcpowers }
1781f9fbec18Smcpowers }
1782f9fbec18Smcpowers
1783f9fbec18Smcpowers if (isECPoint) {
1784f9fbec18Smcpowers copy_bigint_attr(&point, KEY_PUB_EC_POINT(pbk));
1785f9fbec18Smcpowers }
1786f9fbec18Smcpowers rv = soft_add_extra_attr(¶m_tmp, new_object);
1787f9fbec18Smcpowers if (rv != CKR_OK)
1788f9fbec18Smcpowers goto fail_cleanup;
1789f9fbec18Smcpowers string_attr_cleanup(¶m_tmp);
1790034448feSmcpowers break;
1791034448feSmcpowers
17927c478bd9Sstevel@tonic-gate default:
17937c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
17947c478bd9Sstevel@tonic-gate goto fail_cleanup;
17957c478bd9Sstevel@tonic-gate }
17967c478bd9Sstevel@tonic-gate
17977c478bd9Sstevel@tonic-gate /* Set up object. */
17987c478bd9Sstevel@tonic-gate new_object->object_type = object_type;
17997c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask;
18007c478bd9Sstevel@tonic-gate if (isLabel) {
18017c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&string_tmp, new_object);
18027c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
18037c478bd9Sstevel@tonic-gate goto fail_cleanup;
18047c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
18057c478bd9Sstevel@tonic-gate }
18067c478bd9Sstevel@tonic-gate
18077c478bd9Sstevel@tonic-gate return (rv);
18087c478bd9Sstevel@tonic-gate
18097c478bd9Sstevel@tonic-gate fail_cleanup:
18107c478bd9Sstevel@tonic-gate /*
18117c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables.
18127c478bd9Sstevel@tonic-gate */
18137c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&modulus);
18147c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&pubexpo);
18157c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime);
18167c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&subprime);
18177c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&base);
18187c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&value);
1819f9fbec18Smcpowers bigint_attr_cleanup(&point);
18207c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
1821f9fbec18Smcpowers string_attr_cleanup(¶m_tmp);
18227c478bd9Sstevel@tonic-gate
18237c478bd9Sstevel@tonic-gate /*
18247c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself.
18257c478bd9Sstevel@tonic-gate */
18267c478bd9Sstevel@tonic-gate soft_cleanup_object(new_object);
18277c478bd9Sstevel@tonic-gate
18287c478bd9Sstevel@tonic-gate return (rv);
18297c478bd9Sstevel@tonic-gate }
18307c478bd9Sstevel@tonic-gate
18317c478bd9Sstevel@tonic-gate
18327c478bd9Sstevel@tonic-gate /*
18337c478bd9Sstevel@tonic-gate * Build a Private Key Object.
18347c478bd9Sstevel@tonic-gate *
18357c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as
18367c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return
18377c478bd9Sstevel@tonic-gate * with appropriate return value.
18387c478bd9Sstevel@tonic-gate * - Set up attribute mask field in the object for the supplied common
18397c478bd9Sstevel@tonic-gate * attributes that have boolean type.
18407c478bd9Sstevel@tonic-gate * - Build the attribute_info struct to hold the value of each supplied
18417c478bd9Sstevel@tonic-gate * attribute that has byte array type. Link attribute_info structs
18427c478bd9Sstevel@tonic-gate * together to form the extra attribute list of the object.
18437c478bd9Sstevel@tonic-gate * - Allocate storage for the Private Key object.
18447c478bd9Sstevel@tonic-gate * - Build the Private Key object according to the key type. Allocate
18457c478bd9Sstevel@tonic-gate * storage to hold the big integer value for the supplied attributes
18467c478bd9Sstevel@tonic-gate * that are required for a certain key type.
18477c478bd9Sstevel@tonic-gate *
18487c478bd9Sstevel@tonic-gate */
18497c478bd9Sstevel@tonic-gate CK_RV
18507c478bd9Sstevel@tonic-gate soft_build_private_key_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
18517c478bd9Sstevel@tonic-gate soft_object_t *new_object, CK_ULONG mode, CK_KEY_TYPE key_type)
18527c478bd9Sstevel@tonic-gate {
18537c478bd9Sstevel@tonic-gate ulong_t i;
18547c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL;
18557c478bd9Sstevel@tonic-gate uint64_t attr_mask = PRIVATE_KEY_DEFAULT;
18567c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
18577c478bd9Sstevel@tonic-gate int isLabel = 0;
1858034448feSmcpowers int isECParam = 0;
18597c478bd9Sstevel@tonic-gate /* Must set flags unless mode == SOFT_UNWRAP_KEY */
18607c478bd9Sstevel@tonic-gate int isModulus = 0;
18617c478bd9Sstevel@tonic-gate int isPriExpo = 0;
18627c478bd9Sstevel@tonic-gate int isPrime = 0;
18637c478bd9Sstevel@tonic-gate int isSubprime = 0;
18647c478bd9Sstevel@tonic-gate int isBase = 0;
18657c478bd9Sstevel@tonic-gate /* Must set flags if mode == SOFT_GEN_KEY */
18667c478bd9Sstevel@tonic-gate int isValue = 0;
18677c478bd9Sstevel@tonic-gate /* Must not set flags */
18687c478bd9Sstevel@tonic-gate int isValueBits = 0;
18697c478bd9Sstevel@tonic-gate CK_ULONG value_bits = 0;
18707c478bd9Sstevel@tonic-gate
18717c478bd9Sstevel@tonic-gate /* Private Key RSA optional */
18727c478bd9Sstevel@tonic-gate int isPubExpo = 0;
18737c478bd9Sstevel@tonic-gate int isPrime1 = 0;
18747c478bd9Sstevel@tonic-gate int isPrime2 = 0;
18757c478bd9Sstevel@tonic-gate int isExpo1 = 0;
18767c478bd9Sstevel@tonic-gate int isExpo2 = 0;
18777c478bd9Sstevel@tonic-gate int isCoef = 0;
18787c478bd9Sstevel@tonic-gate
18797c478bd9Sstevel@tonic-gate biginteger_t modulus;
18807c478bd9Sstevel@tonic-gate biginteger_t priexpo;
18817c478bd9Sstevel@tonic-gate biginteger_t prime;
18827c478bd9Sstevel@tonic-gate biginteger_t subprime;
18837c478bd9Sstevel@tonic-gate biginteger_t base;
18847c478bd9Sstevel@tonic-gate biginteger_t value;
18857c478bd9Sstevel@tonic-gate
18867c478bd9Sstevel@tonic-gate biginteger_t pubexpo;
18877c478bd9Sstevel@tonic-gate biginteger_t prime1;
18887c478bd9Sstevel@tonic-gate biginteger_t prime2;
18897c478bd9Sstevel@tonic-gate biginteger_t expo1;
18907c478bd9Sstevel@tonic-gate biginteger_t expo2;
18917c478bd9Sstevel@tonic-gate biginteger_t coef;
18927c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp;
1893f9fbec18Smcpowers CK_ATTRIBUTE param_tmp;
18947c478bd9Sstevel@tonic-gate BIGNUM x, q;
18957c478bd9Sstevel@tonic-gate
18967c478bd9Sstevel@tonic-gate private_key_obj_t *pvk;
18977c478bd9Sstevel@tonic-gate uchar_t object_type = 0;
18987c478bd9Sstevel@tonic-gate
18997c478bd9Sstevel@tonic-gate /* prevent bigint_attr_cleanup from freeing invalid attr value */
19007c478bd9Sstevel@tonic-gate (void) memset(&modulus, 0x0, sizeof (biginteger_t));
19017c478bd9Sstevel@tonic-gate (void) memset(&priexpo, 0x0, sizeof (biginteger_t));
19027c478bd9Sstevel@tonic-gate (void) memset(&prime, 0x0, sizeof (biginteger_t));
19037c478bd9Sstevel@tonic-gate (void) memset(&subprime, 0x0, sizeof (biginteger_t));
19047c478bd9Sstevel@tonic-gate (void) memset(&base, 0x0, sizeof (biginteger_t));
19057c478bd9Sstevel@tonic-gate (void) memset(&value, 0x0, sizeof (biginteger_t));
19067c478bd9Sstevel@tonic-gate (void) memset(&pubexpo, 0x0, sizeof (biginteger_t));
19077c478bd9Sstevel@tonic-gate (void) memset(&prime1, 0x0, sizeof (biginteger_t));
19087c478bd9Sstevel@tonic-gate (void) memset(&prime2, 0x0, sizeof (biginteger_t));
19097c478bd9Sstevel@tonic-gate (void) memset(&expo1, 0x0, sizeof (biginteger_t));
19107c478bd9Sstevel@tonic-gate (void) memset(&expo2, 0x0, sizeof (biginteger_t));
19117c478bd9Sstevel@tonic-gate (void) memset(&coef, 0x0, sizeof (biginteger_t));
19127c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL;
1913f9fbec18Smcpowers param_tmp.pValue = NULL;
19147c478bd9Sstevel@tonic-gate x.malloced = 0;
19157c478bd9Sstevel@tonic-gate q.malloced = 0;
19167c478bd9Sstevel@tonic-gate
19177c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
19187c478bd9Sstevel@tonic-gate
19197c478bd9Sstevel@tonic-gate /* Private Key Object Attributes */
19207c478bd9Sstevel@tonic-gate switch (template[i].type) {
19217c478bd9Sstevel@tonic-gate /* common key attributes */
19227c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
19237c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue);
19247c478bd9Sstevel@tonic-gate break;
19257c478bd9Sstevel@tonic-gate
19267c478bd9Sstevel@tonic-gate case CKA_ID:
19277c478bd9Sstevel@tonic-gate case CKA_START_DATE:
19287c478bd9Sstevel@tonic-gate case CKA_END_DATE:
19297c478bd9Sstevel@tonic-gate
19307c478bd9Sstevel@tonic-gate /* common private key attribute */
19317c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
19327c478bd9Sstevel@tonic-gate /*
19337c478bd9Sstevel@tonic-gate * Allocate storage to hold the attribute
19347c478bd9Sstevel@tonic-gate * value with byte array type, and add it to
19357c478bd9Sstevel@tonic-gate * the extra attribute list of the object.
19367c478bd9Sstevel@tonic-gate */
19377c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&template[i],
19387c478bd9Sstevel@tonic-gate new_object);
19397c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
19407c478bd9Sstevel@tonic-gate goto fail_cleanup;
19417c478bd9Sstevel@tonic-gate }
19427c478bd9Sstevel@tonic-gate break;
19437c478bd9Sstevel@tonic-gate
19447c478bd9Sstevel@tonic-gate /*
19457c478bd9Sstevel@tonic-gate * The following key related attribute types must
19467c478bd9Sstevel@tonic-gate * not be specified by C_CreateObject or C_GenerateKey(Pair).
19477c478bd9Sstevel@tonic-gate */
19487c478bd9Sstevel@tonic-gate case CKA_LOCAL:
19497c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM:
19507c478bd9Sstevel@tonic-gate case CKA_AUTH_PIN_FLAGS:
19517c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE:
19527c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE:
19537c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
19547c478bd9Sstevel@tonic-gate goto fail_cleanup;
19557c478bd9Sstevel@tonic-gate
19567c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
19577c478bd9Sstevel@tonic-gate case CKA_DERIVE:
19587c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
19597c478bd9Sstevel@tonic-gate attr_mask |= DERIVE_BOOL_ON;
19607c478bd9Sstevel@tonic-gate break;
19617c478bd9Sstevel@tonic-gate
19627c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
19637c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
19647c478bd9Sstevel@tonic-gate attr_mask |= SENSITIVE_BOOL_ON;
19657c478bd9Sstevel@tonic-gate break;
19667c478bd9Sstevel@tonic-gate
19677c478bd9Sstevel@tonic-gate case CKA_SECONDARY_AUTH:
19687c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) {
19697c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
19707c478bd9Sstevel@tonic-gate goto fail_cleanup;
19717c478bd9Sstevel@tonic-gate }
19727c478bd9Sstevel@tonic-gate break;
19737c478bd9Sstevel@tonic-gate
19747c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
19757c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
19767c478bd9Sstevel@tonic-gate attr_mask |= DECRYPT_BOOL_ON;
19777c478bd9Sstevel@tonic-gate else
19787c478bd9Sstevel@tonic-gate attr_mask &= ~DECRYPT_BOOL_ON;
19797c478bd9Sstevel@tonic-gate break;
19807c478bd9Sstevel@tonic-gate
19817c478bd9Sstevel@tonic-gate case CKA_SIGN:
19827c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
19837c478bd9Sstevel@tonic-gate attr_mask |= SIGN_BOOL_ON;
19847c478bd9Sstevel@tonic-gate else
19857c478bd9Sstevel@tonic-gate attr_mask &= ~SIGN_BOOL_ON;
19867c478bd9Sstevel@tonic-gate break;
19877c478bd9Sstevel@tonic-gate
19887c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER:
19897c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
19907c478bd9Sstevel@tonic-gate attr_mask |= SIGN_RECOVER_BOOL_ON;
19917c478bd9Sstevel@tonic-gate else
19927c478bd9Sstevel@tonic-gate attr_mask &= ~SIGN_RECOVER_BOOL_ON;
19937c478bd9Sstevel@tonic-gate break;
19947c478bd9Sstevel@tonic-gate
19957c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
19967c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
19977c478bd9Sstevel@tonic-gate attr_mask |= UNWRAP_BOOL_ON;
19987c478bd9Sstevel@tonic-gate else
19997c478bd9Sstevel@tonic-gate attr_mask &= ~UNWRAP_BOOL_ON;
20007c478bd9Sstevel@tonic-gate break;
20017c478bd9Sstevel@tonic-gate
20027c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
20037c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
20047c478bd9Sstevel@tonic-gate attr_mask |= EXTRACTABLE_BOOL_ON;
20057c478bd9Sstevel@tonic-gate else
20067c478bd9Sstevel@tonic-gate attr_mask &= ~EXTRACTABLE_BOOL_ON;
20077c478bd9Sstevel@tonic-gate break;
20087c478bd9Sstevel@tonic-gate
20097c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
20107c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template[i].pValue) == B_FALSE)
20117c478bd9Sstevel@tonic-gate attr_mask |= NOT_MODIFIABLE_BOOL_ON;
20127c478bd9Sstevel@tonic-gate break;
20137c478bd9Sstevel@tonic-gate
20147c478bd9Sstevel@tonic-gate /*
20157c478bd9Sstevel@tonic-gate * The following key related attribute types must
20167c478bd9Sstevel@tonic-gate * be specified according to the key type by
20177c478bd9Sstevel@tonic-gate * C_CreateObject.
20187c478bd9Sstevel@tonic-gate */
20197c478bd9Sstevel@tonic-gate case CKA_MODULUS:
20207c478bd9Sstevel@tonic-gate
20217c478bd9Sstevel@tonic-gate isModulus = 1;
20227c478bd9Sstevel@tonic-gate /*
20237c478bd9Sstevel@tonic-gate * Copyin big integer attribute from template
20247c478bd9Sstevel@tonic-gate * to a local variable.
20257c478bd9Sstevel@tonic-gate */
20267c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&modulus,
20277c478bd9Sstevel@tonic-gate &template[i]);
20287c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20297c478bd9Sstevel@tonic-gate goto fail_cleanup;
20307c478bd9Sstevel@tonic-gate
20317c478bd9Sstevel@tonic-gate /*
20327c478bd9Sstevel@tonic-gate * Modulus length needs to be between min key length and
20337c478bd9Sstevel@tonic-gate * max key length.
20347c478bd9Sstevel@tonic-gate */
20357c478bd9Sstevel@tonic-gate if ((modulus.big_value_len <
20367c478bd9Sstevel@tonic-gate MIN_RSA_KEYLENGTH_IN_BYTES) ||
20377c478bd9Sstevel@tonic-gate (modulus.big_value_len >
20387c478bd9Sstevel@tonic-gate MAX_RSA_KEYLENGTH_IN_BYTES)) {
20397c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
20407c478bd9Sstevel@tonic-gate goto fail_cleanup;
20417c478bd9Sstevel@tonic-gate }
20427c478bd9Sstevel@tonic-gate break;
20437c478bd9Sstevel@tonic-gate
20447c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
20457c478bd9Sstevel@tonic-gate
20467c478bd9Sstevel@tonic-gate isPubExpo = 1;
20477c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&pubexpo,
20487c478bd9Sstevel@tonic-gate &template[i]);
20497c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20507c478bd9Sstevel@tonic-gate goto fail_cleanup;
20517c478bd9Sstevel@tonic-gate break;
20527c478bd9Sstevel@tonic-gate
20537c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT:
20547c478bd9Sstevel@tonic-gate
20557c478bd9Sstevel@tonic-gate isPriExpo = 1;
20567c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&priexpo,
20577c478bd9Sstevel@tonic-gate &template[i]);
20587c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20597c478bd9Sstevel@tonic-gate goto fail_cleanup;
20607c478bd9Sstevel@tonic-gate break;
20617c478bd9Sstevel@tonic-gate
20627c478bd9Sstevel@tonic-gate case CKA_PRIME_1:
20637c478bd9Sstevel@tonic-gate isPrime1 = 1;
20647c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime1,
20657c478bd9Sstevel@tonic-gate &template[i]);
20667c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20677c478bd9Sstevel@tonic-gate goto fail_cleanup;
20687c478bd9Sstevel@tonic-gate break;
20697c478bd9Sstevel@tonic-gate
20707c478bd9Sstevel@tonic-gate case CKA_PRIME_2:
20717c478bd9Sstevel@tonic-gate isPrime2 = 1;
20727c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime2,
20737c478bd9Sstevel@tonic-gate &template[i]);
20747c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20757c478bd9Sstevel@tonic-gate goto fail_cleanup;
20767c478bd9Sstevel@tonic-gate break;
20777c478bd9Sstevel@tonic-gate
20787c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1:
20797c478bd9Sstevel@tonic-gate isExpo1 = 1;
20807c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&expo1,
20817c478bd9Sstevel@tonic-gate &template[i]);
20827c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20837c478bd9Sstevel@tonic-gate goto fail_cleanup;
20847c478bd9Sstevel@tonic-gate break;
20857c478bd9Sstevel@tonic-gate
20867c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2:
20877c478bd9Sstevel@tonic-gate isExpo2 = 1;
20887c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&expo2,
20897c478bd9Sstevel@tonic-gate &template[i]);
20907c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20917c478bd9Sstevel@tonic-gate goto fail_cleanup;
20927c478bd9Sstevel@tonic-gate break;
20937c478bd9Sstevel@tonic-gate
20947c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT:
20957c478bd9Sstevel@tonic-gate isCoef = 1;
20967c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&coef,
20977c478bd9Sstevel@tonic-gate &template[i]);
20987c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
20997c478bd9Sstevel@tonic-gate goto fail_cleanup;
21007c478bd9Sstevel@tonic-gate break;
21017c478bd9Sstevel@tonic-gate
21027c478bd9Sstevel@tonic-gate case CKA_PRIME:
21037c478bd9Sstevel@tonic-gate isPrime = 1;
21047c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime,
21057c478bd9Sstevel@tonic-gate &template[i]);
21067c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
21077c478bd9Sstevel@tonic-gate goto fail_cleanup;
21087c478bd9Sstevel@tonic-gate break;
21097c478bd9Sstevel@tonic-gate
21107c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
21117c478bd9Sstevel@tonic-gate isSubprime = 1;
21127c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&subprime,
21137c478bd9Sstevel@tonic-gate &template[i]);
21147c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
21157c478bd9Sstevel@tonic-gate goto fail_cleanup;
21167c478bd9Sstevel@tonic-gate break;
21177c478bd9Sstevel@tonic-gate
21187c478bd9Sstevel@tonic-gate case CKA_BASE:
21197c478bd9Sstevel@tonic-gate isBase = 1;
21207c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&base,
21217c478bd9Sstevel@tonic-gate &template[i]);
21227c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
21237c478bd9Sstevel@tonic-gate goto fail_cleanup;
21247c478bd9Sstevel@tonic-gate break;
21257c478bd9Sstevel@tonic-gate
21267c478bd9Sstevel@tonic-gate case CKA_VALUE:
21277c478bd9Sstevel@tonic-gate isValue = 1;
21287c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
21297c478bd9Sstevel@tonic-gate if ((template[i].ulValueLen == 0) ||
21307c478bd9Sstevel@tonic-gate (template[i].pValue == NULL)) {
21317c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
21327c478bd9Sstevel@tonic-gate goto fail_cleanup;
21337c478bd9Sstevel@tonic-gate }
21347c478bd9Sstevel@tonic-gate }
21357c478bd9Sstevel@tonic-gate
21367c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&value,
21377c478bd9Sstevel@tonic-gate &template[i]);
21387c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
21397c478bd9Sstevel@tonic-gate goto fail_cleanup;
21407c478bd9Sstevel@tonic-gate break;
21417c478bd9Sstevel@tonic-gate
21427c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS:
21437c478bd9Sstevel@tonic-gate isValueBits = 1;
21447739299dSAnthony Scarpino rv = get_ulong_attr_from_template(&value_bits,
21457c478bd9Sstevel@tonic-gate &template[i]);
21467739299dSAnthony Scarpino if (rv != CKR_OK)
21477739299dSAnthony Scarpino goto fail_cleanup;
21487c478bd9Sstevel@tonic-gate break;
21497c478bd9Sstevel@tonic-gate
21507c478bd9Sstevel@tonic-gate case CKA_LABEL:
21517c478bd9Sstevel@tonic-gate isLabel = 1;
21527c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp,
21537c478bd9Sstevel@tonic-gate &template[i]);
21547c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
21557c478bd9Sstevel@tonic-gate goto fail_cleanup;
21567c478bd9Sstevel@tonic-gate break;
21577c478bd9Sstevel@tonic-gate
2158034448feSmcpowers case CKA_EC_PARAMS:
2159034448feSmcpowers isECParam = 1;
2160f9fbec18Smcpowers rv = get_string_from_template(¶m_tmp,
2161034448feSmcpowers &template[i]);
2162034448feSmcpowers if (rv != CKR_OK)
2163034448feSmcpowers goto fail_cleanup;
2164034448feSmcpowers break;
2165034448feSmcpowers
21667c478bd9Sstevel@tonic-gate default:
21677c478bd9Sstevel@tonic-gate rv = soft_parse_common_attrs(&template[i],
21687c478bd9Sstevel@tonic-gate &object_type);
21697c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
21707c478bd9Sstevel@tonic-gate goto fail_cleanup;
21717c478bd9Sstevel@tonic-gate break;
21727c478bd9Sstevel@tonic-gate
21737c478bd9Sstevel@tonic-gate }
21747c478bd9Sstevel@tonic-gate } /* For */
21757c478bd9Sstevel@tonic-gate
21767c478bd9Sstevel@tonic-gate /* Allocate storage for Private Key Object. */
21777c478bd9Sstevel@tonic-gate pvk = calloc(1, sizeof (private_key_obj_t));
21787c478bd9Sstevel@tonic-gate if (pvk == NULL) {
21797c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY;
21807c478bd9Sstevel@tonic-gate goto fail_cleanup;
21817c478bd9Sstevel@tonic-gate }
21827c478bd9Sstevel@tonic-gate
21837c478bd9Sstevel@tonic-gate new_object->object_class_u.private_key = pvk;
21847c478bd9Sstevel@tonic-gate new_object->class = CKO_PRIVATE_KEY;
21857c478bd9Sstevel@tonic-gate
21867c478bd9Sstevel@tonic-gate if ((mode == SOFT_CREATE_OBJ) && (keytype == (CK_KEY_TYPE)~0UL)) {
21877c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
21887c478bd9Sstevel@tonic-gate goto fail_cleanup;
21897c478bd9Sstevel@tonic-gate }
21907c478bd9Sstevel@tonic-gate
21917c478bd9Sstevel@tonic-gate if (mode == SOFT_GEN_KEY) {
21927c478bd9Sstevel@tonic-gate /*
21937c478bd9Sstevel@tonic-gate * The key type is not specified in the application's
21947c478bd9Sstevel@tonic-gate * template, so we use the implied key type based on
21957c478bd9Sstevel@tonic-gate * the mechanism.
21967c478bd9Sstevel@tonic-gate */
21977c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
21987c478bd9Sstevel@tonic-gate keytype = key_type;
21997c478bd9Sstevel@tonic-gate }
22007c478bd9Sstevel@tonic-gate
22017c478bd9Sstevel@tonic-gate /* If still unspecified, template is incomplete */
22027c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
22037c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
22047c478bd9Sstevel@tonic-gate goto fail_cleanup;
22057c478bd9Sstevel@tonic-gate }
22067c478bd9Sstevel@tonic-gate
22077c478bd9Sstevel@tonic-gate /*
22087c478bd9Sstevel@tonic-gate * The key type specified in the template does not
22097c478bd9Sstevel@tonic-gate * match the implied key type based on the mechanism.
22107c478bd9Sstevel@tonic-gate */
22117c478bd9Sstevel@tonic-gate if (keytype != key_type) {
22127c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
22137c478bd9Sstevel@tonic-gate goto fail_cleanup;
22147c478bd9Sstevel@tonic-gate }
22157c478bd9Sstevel@tonic-gate }
22167c478bd9Sstevel@tonic-gate
22177c478bd9Sstevel@tonic-gate if (mode == SOFT_UNWRAP_KEY) {
22187c478bd9Sstevel@tonic-gate /*
22197c478bd9Sstevel@tonic-gate * Note that, for mode SOFT_UNWRAP_KEY, key type is not
22207c478bd9Sstevel@tonic-gate * implied by the mechanism (key_type), so if it is not
22217c478bd9Sstevel@tonic-gate * specified from the attribute template (keytype), it is
22227c478bd9Sstevel@tonic-gate * incomplete.
22237c478bd9Sstevel@tonic-gate */
22247c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
22257c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
22267c478bd9Sstevel@tonic-gate goto fail_cleanup;
22277c478bd9Sstevel@tonic-gate }
22287c478bd9Sstevel@tonic-gate }
22297c478bd9Sstevel@tonic-gate
22307c478bd9Sstevel@tonic-gate new_object->key_type = keytype;
22317c478bd9Sstevel@tonic-gate
22327c478bd9Sstevel@tonic-gate /* Supported key types of the Private Key Object */
22337c478bd9Sstevel@tonic-gate switch (keytype) {
22347c478bd9Sstevel@tonic-gate case CKK_RSA:
22357c478bd9Sstevel@tonic-gate if (isPrime || isSubprime || isBase || isValue ||
22367c478bd9Sstevel@tonic-gate isValueBits) {
22377c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
22387c478bd9Sstevel@tonic-gate goto fail_cleanup;
22397c478bd9Sstevel@tonic-gate }
22407c478bd9Sstevel@tonic-gate
22417c478bd9Sstevel@tonic-gate if (mode == SOFT_GEN_KEY || mode == SOFT_UNWRAP_KEY) {
22427c478bd9Sstevel@tonic-gate if (isModulus || isPubExpo || isPriExpo || isPrime1 ||
22437c478bd9Sstevel@tonic-gate isPrime2 || isExpo1 || isExpo2 || isCoef) {
22447c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
22457c478bd9Sstevel@tonic-gate goto fail_cleanup;
22467c478bd9Sstevel@tonic-gate } else
22477c478bd9Sstevel@tonic-gate break;
22487c478bd9Sstevel@tonic-gate }
22497c478bd9Sstevel@tonic-gate
22507c478bd9Sstevel@tonic-gate if (isModulus && isPriExpo) {
22517c478bd9Sstevel@tonic-gate /*
22527c478bd9Sstevel@tonic-gate * Copy big integer attribute value to the
22537c478bd9Sstevel@tonic-gate * designated place in the Private Key object.
22547c478bd9Sstevel@tonic-gate */
22557c478bd9Sstevel@tonic-gate copy_bigint_attr(&modulus, KEY_PRI_RSA_MOD(pvk));
22567c478bd9Sstevel@tonic-gate
22577c478bd9Sstevel@tonic-gate copy_bigint_attr(&priexpo, KEY_PRI_RSA_PRIEXPO(pvk));
22587c478bd9Sstevel@tonic-gate } else {
22597c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
22607c478bd9Sstevel@tonic-gate goto fail_cleanup;
22617c478bd9Sstevel@tonic-gate }
22627c478bd9Sstevel@tonic-gate
22637c478bd9Sstevel@tonic-gate /* The following attributes are optional. */
22647c478bd9Sstevel@tonic-gate if (isPubExpo) {
22657c478bd9Sstevel@tonic-gate copy_bigint_attr(&pubexpo, KEY_PRI_RSA_PUBEXPO(pvk));
22667c478bd9Sstevel@tonic-gate }
22677c478bd9Sstevel@tonic-gate
22687c478bd9Sstevel@tonic-gate if (isPrime1) {
22697c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime1, KEY_PRI_RSA_PRIME1(pvk));
22707c478bd9Sstevel@tonic-gate }
22717c478bd9Sstevel@tonic-gate
22727c478bd9Sstevel@tonic-gate if (isPrime2) {
22737c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime2, KEY_PRI_RSA_PRIME2(pvk));
22747c478bd9Sstevel@tonic-gate }
22757c478bd9Sstevel@tonic-gate
22767c478bd9Sstevel@tonic-gate if (isExpo1) {
22777c478bd9Sstevel@tonic-gate copy_bigint_attr(&expo1, KEY_PRI_RSA_EXPO1(pvk));
22787c478bd9Sstevel@tonic-gate }
22797c478bd9Sstevel@tonic-gate
22807c478bd9Sstevel@tonic-gate if (isExpo2) {
22817c478bd9Sstevel@tonic-gate copy_bigint_attr(&expo2, KEY_PRI_RSA_EXPO2(pvk));
22827c478bd9Sstevel@tonic-gate }
22837c478bd9Sstevel@tonic-gate
22847c478bd9Sstevel@tonic-gate if (isCoef) {
22857c478bd9Sstevel@tonic-gate copy_bigint_attr(&coef, KEY_PRI_RSA_COEF(pvk));
22867c478bd9Sstevel@tonic-gate }
22877c478bd9Sstevel@tonic-gate break;
22887c478bd9Sstevel@tonic-gate
22897c478bd9Sstevel@tonic-gate case CKK_DSA:
22907c478bd9Sstevel@tonic-gate if (isModulus || isPubExpo || isPriExpo || isPrime1 ||
22917c478bd9Sstevel@tonic-gate isPrime2 || isExpo1 || isExpo2 || isCoef ||
22927c478bd9Sstevel@tonic-gate isValueBits) {
22937c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
22947c478bd9Sstevel@tonic-gate goto fail_cleanup;
22957c478bd9Sstevel@tonic-gate }
22967c478bd9Sstevel@tonic-gate
22977c478bd9Sstevel@tonic-gate if (mode == SOFT_GEN_KEY || mode == SOFT_UNWRAP_KEY) {
22987c478bd9Sstevel@tonic-gate if (isPrime || isSubprime || isBase || isValue) {
22997c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
23007c478bd9Sstevel@tonic-gate goto fail_cleanup;
23017c478bd9Sstevel@tonic-gate } else
23027c478bd9Sstevel@tonic-gate break;
23037c478bd9Sstevel@tonic-gate }
23047c478bd9Sstevel@tonic-gate
23057c478bd9Sstevel@tonic-gate if (isPrime && isSubprime && isBase && isValue) {
23067c478bd9Sstevel@tonic-gate /*
23077c478bd9Sstevel@tonic-gate * The private value x must be less than subprime q.
2308b60f2a0bSfr41279 * Size for big_init is in BIG_CHUNK_TYPE words.
23097c478bd9Sstevel@tonic-gate */
23107c478bd9Sstevel@tonic-gate #ifdef __sparcv9
2311b60f2a0bSfr41279 if (big_init(&x,
2312b60f2a0bSfr41279 (int)CHARLEN2BIGNUMLEN(value.big_value_len))
2313b60f2a0bSfr41279 != BIG_OK) {
2314f9fbec18Smcpowers #else /* !__sparcv9 */
2315b60f2a0bSfr41279 if (big_init(&x,
2316b60f2a0bSfr41279 CHARLEN2BIGNUMLEN(value.big_value_len))
2317b60f2a0bSfr41279 != BIG_OK) {
2318f9fbec18Smcpowers #endif /* __sparcv9 */
23197c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY;
23207c478bd9Sstevel@tonic-gate goto fail_cleanup;
23217c478bd9Sstevel@tonic-gate }
23227c478bd9Sstevel@tonic-gate #ifdef __sparcv9
2323b60f2a0bSfr41279 if (big_init(&q,
2324b60f2a0bSfr41279 (int)CHARLEN2BIGNUMLEN(subprime.big_value_len))
2325b60f2a0bSfr41279 != BIG_OK) {
2326f9fbec18Smcpowers #else /* !__sparcv9 */
2327b60f2a0bSfr41279 if (big_init(&q,
2328b60f2a0bSfr41279 CHARLEN2BIGNUMLEN(subprime.big_value_len))
2329b60f2a0bSfr41279 != BIG_OK) {
2330f9fbec18Smcpowers #endif /* __sparcv9 */
23317c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY;
23327c478bd9Sstevel@tonic-gate goto fail_cleanup;
23337c478bd9Sstevel@tonic-gate }
23347c478bd9Sstevel@tonic-gate bytestring2bignum(&x, value.big_value,
23357c478bd9Sstevel@tonic-gate value.big_value_len);
23367c478bd9Sstevel@tonic-gate bytestring2bignum(&q, subprime.big_value,
23377c478bd9Sstevel@tonic-gate subprime.big_value_len);
23387c478bd9Sstevel@tonic-gate
23397c478bd9Sstevel@tonic-gate if (big_cmp_abs(&x, &q) > 0) {
23407c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
23417c478bd9Sstevel@tonic-gate goto fail_cleanup;
23427c478bd9Sstevel@tonic-gate }
23437c478bd9Sstevel@tonic-gate
23447c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PRI_DSA_PRIME(pvk));
23457c478bd9Sstevel@tonic-gate
23467c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime, KEY_PRI_DSA_SUBPRIME(pvk));
23477c478bd9Sstevel@tonic-gate
23487c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PRI_DSA_BASE(pvk));
23497c478bd9Sstevel@tonic-gate
23507c478bd9Sstevel@tonic-gate copy_bigint_attr(&value, KEY_PRI_DSA_VALUE(pvk));
23517c478bd9Sstevel@tonic-gate } else {
23527c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
23537c478bd9Sstevel@tonic-gate goto fail_cleanup;
23547c478bd9Sstevel@tonic-gate }
23557c478bd9Sstevel@tonic-gate break;
23567c478bd9Sstevel@tonic-gate
23577c478bd9Sstevel@tonic-gate case CKK_DH:
23587c478bd9Sstevel@tonic-gate if (isModulus || isPubExpo || isPriExpo || isPrime1 ||
23597c478bd9Sstevel@tonic-gate isPrime2 || isExpo1 || isExpo2 || isCoef ||
23607c478bd9Sstevel@tonic-gate isSubprime) {
23617c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
23627c478bd9Sstevel@tonic-gate goto fail_cleanup;
23637c478bd9Sstevel@tonic-gate }
23647c478bd9Sstevel@tonic-gate
23657c478bd9Sstevel@tonic-gate /* CKA_VALUE_BITS is for key gen but not unwrap */
23667c478bd9Sstevel@tonic-gate if (mode == SOFT_GEN_KEY)
23677c478bd9Sstevel@tonic-gate KEY_PRI_DH_VAL_BITS(pvk) = (isValueBits) ?
23687c478bd9Sstevel@tonic-gate value_bits : 0;
23697c478bd9Sstevel@tonic-gate else if (mode == SOFT_UNWRAP_KEY) {
23707c478bd9Sstevel@tonic-gate if (isValueBits) {
23717c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
23727c478bd9Sstevel@tonic-gate goto fail_cleanup;
23737c478bd9Sstevel@tonic-gate }
23747c478bd9Sstevel@tonic-gate }
23757c478bd9Sstevel@tonic-gate
23767c478bd9Sstevel@tonic-gate if (mode == SOFT_GEN_KEY || mode == SOFT_UNWRAP_KEY) {
23777c478bd9Sstevel@tonic-gate if (isPrime || isBase || isValue) {
23787c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
23797c478bd9Sstevel@tonic-gate goto fail_cleanup;
23807c478bd9Sstevel@tonic-gate } else
23817c478bd9Sstevel@tonic-gate break;
23827c478bd9Sstevel@tonic-gate }
23837c478bd9Sstevel@tonic-gate
23847c478bd9Sstevel@tonic-gate if (isValueBits) {
23857c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
23867c478bd9Sstevel@tonic-gate goto fail_cleanup;
23877c478bd9Sstevel@tonic-gate }
23887c478bd9Sstevel@tonic-gate
23897c478bd9Sstevel@tonic-gate if (isPrime && isBase && isValue) {
23907c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PRI_DH_PRIME(pvk));
23917c478bd9Sstevel@tonic-gate
23927c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PRI_DH_BASE(pvk));
23937c478bd9Sstevel@tonic-gate
23947c478bd9Sstevel@tonic-gate copy_bigint_attr(&value, KEY_PRI_DH_VALUE(pvk));
23957c478bd9Sstevel@tonic-gate } else {
23967c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
23977c478bd9Sstevel@tonic-gate goto fail_cleanup;
23987c478bd9Sstevel@tonic-gate }
23997c478bd9Sstevel@tonic-gate break;
24007c478bd9Sstevel@tonic-gate
24017c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
24027c478bd9Sstevel@tonic-gate if (isModulus || isPubExpo || isPriExpo || isPrime1 ||
24037c478bd9Sstevel@tonic-gate isPrime2 || isExpo1 || isExpo2 || isCoef ||
24047c478bd9Sstevel@tonic-gate isValueBits) {
24057c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
24067c478bd9Sstevel@tonic-gate goto fail_cleanup;
24077c478bd9Sstevel@tonic-gate }
24087c478bd9Sstevel@tonic-gate
24097c478bd9Sstevel@tonic-gate if (mode == SOFT_GEN_KEY || mode == SOFT_UNWRAP_KEY) {
24107c478bd9Sstevel@tonic-gate if (isPrime || isSubprime || isBase || isValue) {
24117c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
24127c478bd9Sstevel@tonic-gate goto fail_cleanup;
24137c478bd9Sstevel@tonic-gate } else
24147c478bd9Sstevel@tonic-gate break;
24157c478bd9Sstevel@tonic-gate }
24167c478bd9Sstevel@tonic-gate
24177c478bd9Sstevel@tonic-gate if (isPrime && isSubprime && isBase && isValue) {
24187c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PRI_DH942_PRIME(pvk));
24197c478bd9Sstevel@tonic-gate
24207c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PRI_DH942_BASE(pvk));
24217c478bd9Sstevel@tonic-gate
24227c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime,
24237c478bd9Sstevel@tonic-gate KEY_PRI_DH942_SUBPRIME(pvk));
24247c478bd9Sstevel@tonic-gate
24257c478bd9Sstevel@tonic-gate copy_bigint_attr(&value, KEY_PRI_DH942_VALUE(pvk));
24267c478bd9Sstevel@tonic-gate } else {
24277c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
24287c478bd9Sstevel@tonic-gate goto fail_cleanup;
24297c478bd9Sstevel@tonic-gate }
24307c478bd9Sstevel@tonic-gate break;
24317c478bd9Sstevel@tonic-gate
2432034448feSmcpowers case CKK_EC:
2433034448feSmcpowers if (isModulus || isPubExpo || isPrime ||
2434034448feSmcpowers isPrime1 || isPrime2 || isExpo1 || isExpo2 || isCoef ||
2435034448feSmcpowers isValueBits || isBase) {
2436034448feSmcpowers rv = CKR_TEMPLATE_INCONSISTENT;
2437034448feSmcpowers goto fail_cleanup;
2438034448feSmcpowers
2439f9fbec18Smcpowers } else if (isECParam) {
2440f9fbec18Smcpowers rv = soft_add_extra_attr(¶m_tmp, new_object);
2441f9fbec18Smcpowers if (rv != CKR_OK)
2442034448feSmcpowers goto fail_cleanup;
2443f9fbec18Smcpowers string_attr_cleanup(¶m_tmp);
2444034448feSmcpowers }
2445f9fbec18Smcpowers if (isValue) {
2446034448feSmcpowers copy_bigint_attr(&value, KEY_PRI_EC_VALUE(pvk));
2447f9fbec18Smcpowers }
2448034448feSmcpowers break;
2449034448feSmcpowers
24507c478bd9Sstevel@tonic-gate default:
24517c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
24527c478bd9Sstevel@tonic-gate goto fail_cleanup;
24537c478bd9Sstevel@tonic-gate }
24547c478bd9Sstevel@tonic-gate
24557c478bd9Sstevel@tonic-gate /* Set up object. */
24567c478bd9Sstevel@tonic-gate new_object->object_type = object_type;
24577c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask;
24587c478bd9Sstevel@tonic-gate if (isLabel) {
24597c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&string_tmp, new_object);
24607c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
24617c478bd9Sstevel@tonic-gate goto fail_cleanup;
24627c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
24637c478bd9Sstevel@tonic-gate }
24647c478bd9Sstevel@tonic-gate big_finish(&x);
24657c478bd9Sstevel@tonic-gate big_finish(&q);
24667c478bd9Sstevel@tonic-gate
24677c478bd9Sstevel@tonic-gate return (rv);
24687c478bd9Sstevel@tonic-gate
24697c478bd9Sstevel@tonic-gate fail_cleanup:
24707c478bd9Sstevel@tonic-gate /*
24717c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables.
24727c478bd9Sstevel@tonic-gate */
24737c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&modulus);
24747c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&priexpo);
24757c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime);
24767c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&subprime);
24777c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&base);
24787c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&value);
24797c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&pubexpo);
24807c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime1);
24817c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime2);
24827c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&expo1);
24837c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&expo2);
24847c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&coef);
24857c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
2486f9fbec18Smcpowers string_attr_cleanup(¶m_tmp);
24877c478bd9Sstevel@tonic-gate big_finish(&x);
24887c478bd9Sstevel@tonic-gate big_finish(&q);
24897c478bd9Sstevel@tonic-gate
24907c478bd9Sstevel@tonic-gate /*
24917c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself.
24927c478bd9Sstevel@tonic-gate */
24937c478bd9Sstevel@tonic-gate soft_cleanup_object(new_object);
24947c478bd9Sstevel@tonic-gate
24957c478bd9Sstevel@tonic-gate return (rv);
24967c478bd9Sstevel@tonic-gate }
24977c478bd9Sstevel@tonic-gate
24987c478bd9Sstevel@tonic-gate
24997c478bd9Sstevel@tonic-gate /*
25007c478bd9Sstevel@tonic-gate * Build a Secret Key Object.
25017c478bd9Sstevel@tonic-gate *
25027c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as
25037c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return
25047c478bd9Sstevel@tonic-gate * with appropriate return value.
25057c478bd9Sstevel@tonic-gate * - Set up attribute mask field in the object for the supplied common
25067c478bd9Sstevel@tonic-gate * attributes that have boolean type.
25077c478bd9Sstevel@tonic-gate * - Build the attribute_info struct to hold the value of each supplied
25087c478bd9Sstevel@tonic-gate * attribute that has byte array type. Link attribute_info structs
25097c478bd9Sstevel@tonic-gate * together to form the extra attribute list of the object.
25107c478bd9Sstevel@tonic-gate * - Allocate storage for the Secret Key object.
25117c478bd9Sstevel@tonic-gate * - Build the Secret Key object. Allocate storage to hold the big integer
25127c478bd9Sstevel@tonic-gate * value for the attribute CKA_VALUE that is required for all the key
25137c478bd9Sstevel@tonic-gate * types supported by secret key object.
25147c478bd9Sstevel@tonic-gate * This function is called internally with mode = SOFT_CREATE_OBJ_INT.
25157c478bd9Sstevel@tonic-gate *
25167c478bd9Sstevel@tonic-gate */
25177c478bd9Sstevel@tonic-gate CK_RV
25187c478bd9Sstevel@tonic-gate soft_build_secret_key_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
25197c478bd9Sstevel@tonic-gate soft_object_t *new_object, CK_ULONG mode, CK_ULONG key_len,
25207c478bd9Sstevel@tonic-gate CK_KEY_TYPE key_type)
25217c478bd9Sstevel@tonic-gate {
25227c478bd9Sstevel@tonic-gate
25237c478bd9Sstevel@tonic-gate ulong_t i;
25247c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL;
25257c478bd9Sstevel@tonic-gate uint64_t attr_mask = SECRET_KEY_DEFAULT;
25267c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
25277c478bd9Sstevel@tonic-gate int isLabel = 0;
25287c478bd9Sstevel@tonic-gate /* Must set flags if mode != SOFT_UNWRAP_KEY, else must not set */
25297c478bd9Sstevel@tonic-gate int isValue = 0;
25307c478bd9Sstevel@tonic-gate /* Must not set flags if mode != SOFT_UNWRAP_KEY, else optional */
25317c478bd9Sstevel@tonic-gate int isValueLen = 0;
25327c478bd9Sstevel@tonic-gate
25337c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp;
25347c478bd9Sstevel@tonic-gate
25357c478bd9Sstevel@tonic-gate secret_key_obj_t *sck;
25367c478bd9Sstevel@tonic-gate uchar_t object_type = 0;
25377c478bd9Sstevel@tonic-gate
25387c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL;
25397c478bd9Sstevel@tonic-gate
25407c478bd9Sstevel@tonic-gate /* Allocate storage for Secret Key Object. */
25417c478bd9Sstevel@tonic-gate sck = calloc(1, sizeof (secret_key_obj_t));
25427c478bd9Sstevel@tonic-gate if (sck == NULL) {
25437c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY;
25447c478bd9Sstevel@tonic-gate goto fail_cleanup;
25457c478bd9Sstevel@tonic-gate }
25467c478bd9Sstevel@tonic-gate
25477c478bd9Sstevel@tonic-gate new_object->object_class_u.secret_key = sck;
25487c478bd9Sstevel@tonic-gate new_object->class = CKO_SECRET_KEY;
25497c478bd9Sstevel@tonic-gate
25507c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
25517c478bd9Sstevel@tonic-gate
25527c478bd9Sstevel@tonic-gate /* Secret Key Object Attributes */
25537c478bd9Sstevel@tonic-gate switch (template[i].type) {
25547c478bd9Sstevel@tonic-gate
25557c478bd9Sstevel@tonic-gate /* common key attributes */
25567c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
25577c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue);
25587c478bd9Sstevel@tonic-gate break;
25597c478bd9Sstevel@tonic-gate
25607c478bd9Sstevel@tonic-gate case CKA_ID:
25617c478bd9Sstevel@tonic-gate case CKA_START_DATE:
25627c478bd9Sstevel@tonic-gate case CKA_END_DATE:
25637c478bd9Sstevel@tonic-gate /*
25647c478bd9Sstevel@tonic-gate * Allocate storage to hold the attribute
25657c478bd9Sstevel@tonic-gate * value with byte array type, and add it to
25667c478bd9Sstevel@tonic-gate * the extra attribute list of the object.
25677c478bd9Sstevel@tonic-gate */
25687c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&template[i],
25697c478bd9Sstevel@tonic-gate new_object);
25707c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
25717c478bd9Sstevel@tonic-gate goto fail_cleanup;
25727c478bd9Sstevel@tonic-gate }
25737c478bd9Sstevel@tonic-gate break;
25747c478bd9Sstevel@tonic-gate
25757c478bd9Sstevel@tonic-gate /*
25767c478bd9Sstevel@tonic-gate * The following key related attribute types must
25777c478bd9Sstevel@tonic-gate * not be specified by C_CreateObject and C_GenerateKey.
25787c478bd9Sstevel@tonic-gate */
25797c478bd9Sstevel@tonic-gate case CKA_LOCAL:
25807c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM:
25817c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE:
25827c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE:
25837c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
25847c478bd9Sstevel@tonic-gate goto fail_cleanup;
25857c478bd9Sstevel@tonic-gate
25867c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
25877c478bd9Sstevel@tonic-gate case CKA_DERIVE:
25887c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
25897c478bd9Sstevel@tonic-gate attr_mask |= DERIVE_BOOL_ON;
25907c478bd9Sstevel@tonic-gate break;
25917c478bd9Sstevel@tonic-gate
25927c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
25937c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
25947c478bd9Sstevel@tonic-gate attr_mask |= SENSITIVE_BOOL_ON;
25957c478bd9Sstevel@tonic-gate break;
25967c478bd9Sstevel@tonic-gate
25977c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
25987c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
25997c478bd9Sstevel@tonic-gate attr_mask |= ENCRYPT_BOOL_ON;
26007c478bd9Sstevel@tonic-gate else
26017c478bd9Sstevel@tonic-gate attr_mask &= ~ENCRYPT_BOOL_ON;
26027c478bd9Sstevel@tonic-gate break;
26037c478bd9Sstevel@tonic-gate
26047c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
26057c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
26067c478bd9Sstevel@tonic-gate attr_mask |= DECRYPT_BOOL_ON;
26077c478bd9Sstevel@tonic-gate else
26087c478bd9Sstevel@tonic-gate attr_mask &= ~DECRYPT_BOOL_ON;
26097c478bd9Sstevel@tonic-gate break;
26107c478bd9Sstevel@tonic-gate
26117c478bd9Sstevel@tonic-gate case CKA_SIGN:
26127c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
26137c478bd9Sstevel@tonic-gate attr_mask |= SIGN_BOOL_ON;
26147c478bd9Sstevel@tonic-gate else
26157c478bd9Sstevel@tonic-gate attr_mask &= ~SIGN_BOOL_ON;
26167c478bd9Sstevel@tonic-gate break;
26177c478bd9Sstevel@tonic-gate
26187c478bd9Sstevel@tonic-gate case CKA_VERIFY:
26197c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
26207c478bd9Sstevel@tonic-gate attr_mask |= VERIFY_BOOL_ON;
26217c478bd9Sstevel@tonic-gate else
26227c478bd9Sstevel@tonic-gate attr_mask &= ~VERIFY_BOOL_ON;
26237c478bd9Sstevel@tonic-gate break;
26247c478bd9Sstevel@tonic-gate
26257c478bd9Sstevel@tonic-gate case CKA_WRAP:
26267c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
26277c478bd9Sstevel@tonic-gate attr_mask |= WRAP_BOOL_ON;
26287c478bd9Sstevel@tonic-gate else
26297c478bd9Sstevel@tonic-gate attr_mask &= ~WRAP_BOOL_ON;
26307c478bd9Sstevel@tonic-gate break;
26317c478bd9Sstevel@tonic-gate
26327c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
26337c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
26347c478bd9Sstevel@tonic-gate attr_mask |= UNWRAP_BOOL_ON;
26357c478bd9Sstevel@tonic-gate else
26367c478bd9Sstevel@tonic-gate attr_mask &= ~UNWRAP_BOOL_ON;
26377c478bd9Sstevel@tonic-gate break;
26387c478bd9Sstevel@tonic-gate
26397c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
26407c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue)
26417c478bd9Sstevel@tonic-gate attr_mask |= EXTRACTABLE_BOOL_ON;
26427c478bd9Sstevel@tonic-gate else
26437c478bd9Sstevel@tonic-gate attr_mask &= ~EXTRACTABLE_BOOL_ON;
26447c478bd9Sstevel@tonic-gate break;
26457c478bd9Sstevel@tonic-gate
26467c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
26477c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template[i].pValue) == B_FALSE)
26487c478bd9Sstevel@tonic-gate attr_mask |= NOT_MODIFIABLE_BOOL_ON;
26497c478bd9Sstevel@tonic-gate break;
26507c478bd9Sstevel@tonic-gate
26517c478bd9Sstevel@tonic-gate case CKA_VALUE:
26527c478bd9Sstevel@tonic-gate isValue = 1;
26537c478bd9Sstevel@tonic-gate if (mode == SOFT_CREATE_OBJ) {
26547c478bd9Sstevel@tonic-gate if ((template[i].ulValueLen == 0) ||
26557c478bd9Sstevel@tonic-gate (template[i].pValue == NULL)) {
26567c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
26577c478bd9Sstevel@tonic-gate goto fail_cleanup;
26587c478bd9Sstevel@tonic-gate }
26597c478bd9Sstevel@tonic-gate }
26607c478bd9Sstevel@tonic-gate
26617c478bd9Sstevel@tonic-gate /*
26627c478bd9Sstevel@tonic-gate * Copyin attribute from template
26637c478bd9Sstevel@tonic-gate * to a local variable.
26647c478bd9Sstevel@tonic-gate */
26657c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template((biginteger_t *)sck,
26667c478bd9Sstevel@tonic-gate &template[i]);
26677c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
26687c478bd9Sstevel@tonic-gate goto fail_cleanup;
26697c478bd9Sstevel@tonic-gate break;
26707c478bd9Sstevel@tonic-gate
26717c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN:
26727c478bd9Sstevel@tonic-gate isValueLen = 1;
26737739299dSAnthony Scarpino rv = get_ulong_attr_from_template(&sck->sk_value_len,
26747c478bd9Sstevel@tonic-gate &template[i]);
26757739299dSAnthony Scarpino if (rv != CKR_OK)
26767739299dSAnthony Scarpino goto fail_cleanup;
26777c478bd9Sstevel@tonic-gate break;
26787c478bd9Sstevel@tonic-gate
26797c478bd9Sstevel@tonic-gate case CKA_LABEL:
26807c478bd9Sstevel@tonic-gate isLabel = 1;
26817c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp,
26827c478bd9Sstevel@tonic-gate &template[i]);
26837c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
26847c478bd9Sstevel@tonic-gate goto fail_cleanup;
26857c478bd9Sstevel@tonic-gate break;
26867c478bd9Sstevel@tonic-gate
26877c478bd9Sstevel@tonic-gate default:
26887c478bd9Sstevel@tonic-gate rv = soft_parse_common_attrs(&template[i],
26897c478bd9Sstevel@tonic-gate &object_type);
26907c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
26917c478bd9Sstevel@tonic-gate goto fail_cleanup;
26927c478bd9Sstevel@tonic-gate break;
26937c478bd9Sstevel@tonic-gate
26947c478bd9Sstevel@tonic-gate }
26957c478bd9Sstevel@tonic-gate } /* For */
26967c478bd9Sstevel@tonic-gate
26977c478bd9Sstevel@tonic-gate switch (mode) {
26987c478bd9Sstevel@tonic-gate case SOFT_CREATE_OBJ:
26997c478bd9Sstevel@tonic-gate case SOFT_CREATE_OBJ_INT:
27007c478bd9Sstevel@tonic-gate case SOFT_DERIVE_KEY_DH:
27017c478bd9Sstevel@tonic-gate /*
27027c478bd9Sstevel@tonic-gate * The key type must be specified in the application's
27037c478bd9Sstevel@tonic-gate * template. Otherwise, returns error.
27047c478bd9Sstevel@tonic-gate */
27057c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
27067c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
27077c478bd9Sstevel@tonic-gate goto fail_cleanup;
27087c478bd9Sstevel@tonic-gate }
27097c478bd9Sstevel@tonic-gate break;
27107c478bd9Sstevel@tonic-gate
27117c478bd9Sstevel@tonic-gate case SOFT_GEN_KEY:
27127c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
27137c478bd9Sstevel@tonic-gate /*
27147c478bd9Sstevel@tonic-gate * The key type is not specified in the application's
27157c478bd9Sstevel@tonic-gate * template, so we use the implied key type based on
27167c478bd9Sstevel@tonic-gate * the mechanism.
27177c478bd9Sstevel@tonic-gate */
27187c478bd9Sstevel@tonic-gate keytype = key_type;
27197c478bd9Sstevel@tonic-gate } else {
27207c478bd9Sstevel@tonic-gate if (keytype != key_type) {
27217c478bd9Sstevel@tonic-gate /*
27227c478bd9Sstevel@tonic-gate * The key type specified in the template
27237c478bd9Sstevel@tonic-gate * does not match the implied key type based
27247c478bd9Sstevel@tonic-gate * on the mechanism.
27257c478bd9Sstevel@tonic-gate */
27267c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
27277c478bd9Sstevel@tonic-gate goto fail_cleanup;
27287c478bd9Sstevel@tonic-gate }
27297c478bd9Sstevel@tonic-gate }
27307c478bd9Sstevel@tonic-gate
27317c478bd9Sstevel@tonic-gate /*
27327c478bd9Sstevel@tonic-gate * If a key_len is passed as a parameter, it has to
27337c478bd9Sstevel@tonic-gate * match the one found in the template.
27347c478bd9Sstevel@tonic-gate */
27357c478bd9Sstevel@tonic-gate if (key_len > 0) {
27367c478bd9Sstevel@tonic-gate if (isValueLen && sck->sk_value_len != key_len) {
27377c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
27387c478bd9Sstevel@tonic-gate goto fail_cleanup;
27397c478bd9Sstevel@tonic-gate }
27407c478bd9Sstevel@tonic-gate isValueLen = 1;
27417c478bd9Sstevel@tonic-gate sck->sk_value_len = key_len;
27427c478bd9Sstevel@tonic-gate }
27437c478bd9Sstevel@tonic-gate break;
27447c478bd9Sstevel@tonic-gate
27457c478bd9Sstevel@tonic-gate case SOFT_UNWRAP_KEY:
27467c478bd9Sstevel@tonic-gate /*
27477c478bd9Sstevel@tonic-gate * Note that, for mode SOFT_UNWRAP_KEY, key type is not
27487c478bd9Sstevel@tonic-gate * implied by the mechanism (key_type), so if it is not
27497c478bd9Sstevel@tonic-gate * specified from the attribute template (keytype), it is
27507c478bd9Sstevel@tonic-gate * incomplete.
27517c478bd9Sstevel@tonic-gate */
27527c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
27537c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
27547c478bd9Sstevel@tonic-gate goto fail_cleanup;
27557c478bd9Sstevel@tonic-gate }
27567c478bd9Sstevel@tonic-gate break;
27577c478bd9Sstevel@tonic-gate
27587c478bd9Sstevel@tonic-gate case SOFT_DERIVE_KEY_OTHER:
27597c478bd9Sstevel@tonic-gate /*
27607c478bd9Sstevel@tonic-gate * For CKM_MD5_KEY_DERIVATION & CKM_SHA1_KEY_DERIVATION, the
27617c478bd9Sstevel@tonic-gate * key type is optional.
27627c478bd9Sstevel@tonic-gate */
27637c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
27647c478bd9Sstevel@tonic-gate keytype = key_type;
27657c478bd9Sstevel@tonic-gate }
27667c478bd9Sstevel@tonic-gate break;
27677c478bd9Sstevel@tonic-gate }
27687c478bd9Sstevel@tonic-gate
27697c478bd9Sstevel@tonic-gate switch (mode) {
27707c478bd9Sstevel@tonic-gate case SOFT_CREATE_OBJ:
27717c478bd9Sstevel@tonic-gate case SOFT_CREATE_OBJ_INT:
27727c478bd9Sstevel@tonic-gate switch (keytype) {
27737c478bd9Sstevel@tonic-gate case CKK_RC4:
27747c478bd9Sstevel@tonic-gate if (!isValue) {
27757c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
27767c478bd9Sstevel@tonic-gate goto fail_cleanup;
27777c478bd9Sstevel@tonic-gate }
27787c478bd9Sstevel@tonic-gate if ((sck->sk_value_len < ARCFOUR_MIN_KEY_BYTES) ||
27797c478bd9Sstevel@tonic-gate (sck->sk_value_len > ARCFOUR_MAX_KEY_BYTES)) {
27807c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
27817c478bd9Sstevel@tonic-gate goto fail_cleanup;
27827c478bd9Sstevel@tonic-gate }
27837c478bd9Sstevel@tonic-gate break;
27847c478bd9Sstevel@tonic-gate
27857c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET:
27867c478bd9Sstevel@tonic-gate if (!isValue) {
27877c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
27887c478bd9Sstevel@tonic-gate goto fail_cleanup;
27897c478bd9Sstevel@tonic-gate }
27907c478bd9Sstevel@tonic-gate break;
27917c478bd9Sstevel@tonic-gate
27927c478bd9Sstevel@tonic-gate case CKK_AES:
27937c478bd9Sstevel@tonic-gate if (!isValue) {
27947c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
27957c478bd9Sstevel@tonic-gate goto fail_cleanup;
27967c478bd9Sstevel@tonic-gate }
27977c478bd9Sstevel@tonic-gate if ((sck->sk_value_len != AES_MIN_KEY_BYTES) &&
27987c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_192_KEY_BYTES) &&
27997c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_MAX_KEY_BYTES)) {
28007c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
28017c478bd9Sstevel@tonic-gate goto fail_cleanup;
28027c478bd9Sstevel@tonic-gate }
28037c478bd9Sstevel@tonic-gate break;
28047c478bd9Sstevel@tonic-gate
2805f66d273dSizick case CKK_BLOWFISH:
2806f66d273dSizick if (!isValue) {
2807f66d273dSizick rv = CKR_TEMPLATE_INCOMPLETE;
2808f66d273dSizick goto fail_cleanup;
2809f66d273dSizick }
2810f66d273dSizick if ((sck->sk_value_len < BLOWFISH_MINBYTES) ||
2811f66d273dSizick (sck->sk_value_len > BLOWFISH_MAXBYTES)) {
2812f66d273dSizick rv = CKR_ATTRIBUTE_VALUE_INVALID;
2813f66d273dSizick goto fail_cleanup;
2814f66d273dSizick }
2815f66d273dSizick
2816f66d273dSizick break;
2817f66d273dSizick
28187c478bd9Sstevel@tonic-gate case CKK_DES:
28197c478bd9Sstevel@tonic-gate if (!isValue) {
28207c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
28217c478bd9Sstevel@tonic-gate goto fail_cleanup;
28227c478bd9Sstevel@tonic-gate }
28237c478bd9Sstevel@tonic-gate if (sck->sk_value_len != DES_KEYSIZE) {
28247c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
28257c478bd9Sstevel@tonic-gate goto fail_cleanup;
28267c478bd9Sstevel@tonic-gate }
28277c478bd9Sstevel@tonic-gate break;
28287c478bd9Sstevel@tonic-gate
28297c478bd9Sstevel@tonic-gate case CKK_DES2:
28307c478bd9Sstevel@tonic-gate if (!isValue) {
28317c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
28327c478bd9Sstevel@tonic-gate goto fail_cleanup;
28337c478bd9Sstevel@tonic-gate }
28347c478bd9Sstevel@tonic-gate if (sck->sk_value_len != DES2_KEYSIZE) {
28357c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
28367c478bd9Sstevel@tonic-gate goto fail_cleanup;
28377c478bd9Sstevel@tonic-gate }
28387c478bd9Sstevel@tonic-gate break;
28397c478bd9Sstevel@tonic-gate
28407c478bd9Sstevel@tonic-gate case CKK_DES3:
28417c478bd9Sstevel@tonic-gate if (!isValue) {
28427c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
28437c478bd9Sstevel@tonic-gate goto fail_cleanup;
28447c478bd9Sstevel@tonic-gate }
28457c478bd9Sstevel@tonic-gate if (sck->sk_value_len != DES3_KEYSIZE) {
28467c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
28477c478bd9Sstevel@tonic-gate goto fail_cleanup;
28487c478bd9Sstevel@tonic-gate }
28497c478bd9Sstevel@tonic-gate break;
28507c478bd9Sstevel@tonic-gate
28517c478bd9Sstevel@tonic-gate default:
28527c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
28537c478bd9Sstevel@tonic-gate goto fail_cleanup;
28547c478bd9Sstevel@tonic-gate }
28557c478bd9Sstevel@tonic-gate
28567c478bd9Sstevel@tonic-gate if (isValueLen) {
28577c478bd9Sstevel@tonic-gate /*
28587c478bd9Sstevel@tonic-gate * Templates for internal object creation come from
28597c478bd9Sstevel@tonic-gate * applications calls to C_DeriveKey(), for which it
28607c478bd9Sstevel@tonic-gate * is OKey to pass a CKA_VALUE_LEN attribute, as
28617c478bd9Sstevel@tonic-gate * long as it does not conflict with the length of the
28627c478bd9Sstevel@tonic-gate * CKA_VALUE attribute.
28637c478bd9Sstevel@tonic-gate */
28647c478bd9Sstevel@tonic-gate if ((mode != SOFT_CREATE_OBJ_INT) ||
28657c478bd9Sstevel@tonic-gate ((key_len > 0) && sck->sk_value_len != key_len)) {
28667c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
28677c478bd9Sstevel@tonic-gate goto fail_cleanup;
28687c478bd9Sstevel@tonic-gate }
28697c478bd9Sstevel@tonic-gate }
28707c478bd9Sstevel@tonic-gate break;
28717c478bd9Sstevel@tonic-gate
28727c478bd9Sstevel@tonic-gate case SOFT_GEN_KEY:
28737c478bd9Sstevel@tonic-gate /* CKA_VALUE must not be specified */
28747c478bd9Sstevel@tonic-gate if (isValue) {
28757c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
28767c478bd9Sstevel@tonic-gate goto fail_cleanup;
28777c478bd9Sstevel@tonic-gate }
28787c478bd9Sstevel@tonic-gate
28797c478bd9Sstevel@tonic-gate switch (keytype) {
28807c478bd9Sstevel@tonic-gate /*
28817c478bd9Sstevel@tonic-gate * CKA_VALUE_LEN must be specified by C_GenerateKey
28827c478bd9Sstevel@tonic-gate * if mech is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET.
28837c478bd9Sstevel@tonic-gate */
28847c478bd9Sstevel@tonic-gate case CKK_RC4:
28857c478bd9Sstevel@tonic-gate if (!isValueLen) {
2886d288ba74SAnthony Scarpino rv = CKR_TEMPLATE_INCOMPLETE;
28877c478bd9Sstevel@tonic-gate goto fail_cleanup;
28887c478bd9Sstevel@tonic-gate }
2889d288ba74SAnthony Scarpino ;
28907c478bd9Sstevel@tonic-gate if ((sck->sk_value_len < ARCFOUR_MIN_KEY_BYTES) ||
28917c478bd9Sstevel@tonic-gate (sck->sk_value_len > ARCFOUR_MAX_KEY_BYTES)) {
28927c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
28937c478bd9Sstevel@tonic-gate goto fail_cleanup;
28947c478bd9Sstevel@tonic-gate }
28957c478bd9Sstevel@tonic-gate break;
28967c478bd9Sstevel@tonic-gate
28977c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET:
28987c478bd9Sstevel@tonic-gate /* arbitrary key length - no length checking */
28997c478bd9Sstevel@tonic-gate if (!isValueLen) {
2900d288ba74SAnthony Scarpino rv = CKR_TEMPLATE_INCOMPLETE;
29017c478bd9Sstevel@tonic-gate goto fail_cleanup;
29027c478bd9Sstevel@tonic-gate }
29037c478bd9Sstevel@tonic-gate break;
29047c478bd9Sstevel@tonic-gate
29057c478bd9Sstevel@tonic-gate case CKK_AES:
29067c478bd9Sstevel@tonic-gate if (!isValueLen) {
2907d288ba74SAnthony Scarpino rv = CKR_TEMPLATE_INCOMPLETE;
29087c478bd9Sstevel@tonic-gate goto fail_cleanup;
29097c478bd9Sstevel@tonic-gate }
29107c478bd9Sstevel@tonic-gate
29117c478bd9Sstevel@tonic-gate if ((sck->sk_value_len != AES_MIN_KEY_BYTES) &&
29127c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_192_KEY_BYTES) &&
29137c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_MAX_KEY_BYTES)) {
29147c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
29157c478bd9Sstevel@tonic-gate goto fail_cleanup;
29167c478bd9Sstevel@tonic-gate }
29177c478bd9Sstevel@tonic-gate
29187c478bd9Sstevel@tonic-gate break;
29197c478bd9Sstevel@tonic-gate
2920f66d273dSizick case CKK_BLOWFISH:
2921f66d273dSizick if (!isValueLen) {
2922d288ba74SAnthony Scarpino rv = CKR_TEMPLATE_INCOMPLETE;
2923f66d273dSizick goto fail_cleanup;
2924f66d273dSizick }
2925f66d273dSizick if ((sck->sk_value_len < BLOWFISH_MINBYTES) ||
2926f66d273dSizick (sck->sk_value_len > BLOWFISH_MAXBYTES)) {
2927f66d273dSizick rv = CKR_ATTRIBUTE_VALUE_INVALID;
2928f66d273dSizick goto fail_cleanup;
2929f66d273dSizick }
2930f66d273dSizick
2931f66d273dSizick break;
2932f66d273dSizick
29337c478bd9Sstevel@tonic-gate case CKK_DES:
29347c478bd9Sstevel@tonic-gate case CKK_DES2:
29357c478bd9Sstevel@tonic-gate case CKK_DES3:
29367c478bd9Sstevel@tonic-gate /* CKA_VALUE_LEN attribute does not apply to DES<n> */
29377c478bd9Sstevel@tonic-gate if (isValueLen) {
29387c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
29397c478bd9Sstevel@tonic-gate goto fail_cleanup;
29407c478bd9Sstevel@tonic-gate }
29417c478bd9Sstevel@tonic-gate break;
29427c478bd9Sstevel@tonic-gate
29437c478bd9Sstevel@tonic-gate default:
29447c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
29457c478bd9Sstevel@tonic-gate goto fail_cleanup;
29467c478bd9Sstevel@tonic-gate }
29477c478bd9Sstevel@tonic-gate break;
29487c478bd9Sstevel@tonic-gate
29497c478bd9Sstevel@tonic-gate case SOFT_UNWRAP_KEY:
29507c478bd9Sstevel@tonic-gate /*
29517c478bd9Sstevel@tonic-gate * According to v2.11 of PKCS#11 spec, neither CKA_VALUE nor
29527c478bd9Sstevel@tonic-gate * CKA_VALUE_LEN can be be specified; however v2.20 has this
29537c478bd9Sstevel@tonic-gate * restriction removed, perhaps because it makes it hard to
29547c478bd9Sstevel@tonic-gate * determine variable-length key sizes. This case statement
29557c478bd9Sstevel@tonic-gate * complied with v2.20.
29567c478bd9Sstevel@tonic-gate */
29577c478bd9Sstevel@tonic-gate if (isValue) {
29587c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
29597c478bd9Sstevel@tonic-gate goto fail_cleanup;
29607c478bd9Sstevel@tonic-gate }
29617c478bd9Sstevel@tonic-gate
29627c478bd9Sstevel@tonic-gate switch (keytype) {
29637c478bd9Sstevel@tonic-gate /*
29647c478bd9Sstevel@tonic-gate * CKA_VALUE_LEN is optional
29657c478bd9Sstevel@tonic-gate * if key is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET
29667c478bd9Sstevel@tonic-gate * and the unwrapping mech is *_CBC_PAD.
29677c478bd9Sstevel@tonic-gate *
29687c478bd9Sstevel@tonic-gate * CKA_VALUE_LEN is required
29697c478bd9Sstevel@tonic-gate * if key is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET
29707c478bd9Sstevel@tonic-gate * and the unwrapping mech is *_ECB or *_CBC.
29717c478bd9Sstevel@tonic-gate *
29727c478bd9Sstevel@tonic-gate * since mech is not known at this point, CKA_VALUE_LEN is
29737c478bd9Sstevel@tonic-gate * treated as optional and the caller needs to enforce it.
29747c478bd9Sstevel@tonic-gate */
29757c478bd9Sstevel@tonic-gate case CKK_RC4:
29767c478bd9Sstevel@tonic-gate if (isValueLen) {
29777c478bd9Sstevel@tonic-gate if ((sck->sk_value_len <
29787c478bd9Sstevel@tonic-gate ARCFOUR_MIN_KEY_BYTES) ||
29797c478bd9Sstevel@tonic-gate (sck->sk_value_len >
29807c478bd9Sstevel@tonic-gate ARCFOUR_MAX_KEY_BYTES)) {
29817c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
29827c478bd9Sstevel@tonic-gate goto fail_cleanup;
29837c478bd9Sstevel@tonic-gate }
29847c478bd9Sstevel@tonic-gate }
29857c478bd9Sstevel@tonic-gate break;
29867c478bd9Sstevel@tonic-gate
29877c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET:
29887c478bd9Sstevel@tonic-gate /* arbitrary key length - no length checking */
29897c478bd9Sstevel@tonic-gate break;
29907c478bd9Sstevel@tonic-gate
29917c478bd9Sstevel@tonic-gate case CKK_AES:
29927c478bd9Sstevel@tonic-gate if (isValueLen) {
29937c478bd9Sstevel@tonic-gate if ((sck->sk_value_len != AES_MIN_KEY_BYTES) &&
29947c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_192_KEY_BYTES) &&
29957c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_MAX_KEY_BYTES)) {
29967c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
29977c478bd9Sstevel@tonic-gate goto fail_cleanup;
29987c478bd9Sstevel@tonic-gate }
29997c478bd9Sstevel@tonic-gate }
30007c478bd9Sstevel@tonic-gate break;
30017c478bd9Sstevel@tonic-gate
3002f66d273dSizick case CKK_BLOWFISH:
3003f66d273dSizick if (isValueLen &&
3004f66d273dSizick ((sck->sk_value_len < BLOWFISH_MINBYTES) ||
3005f66d273dSizick (sck->sk_value_len > BLOWFISH_MAXBYTES))) {
3006f66d273dSizick rv = CKR_ATTRIBUTE_VALUE_INVALID;
3007f66d273dSizick goto fail_cleanup;
3008f66d273dSizick }
3009f66d273dSizick break;
3010f66d273dSizick
30117c478bd9Sstevel@tonic-gate case CKK_DES:
30127c478bd9Sstevel@tonic-gate case CKK_DES2:
30137c478bd9Sstevel@tonic-gate case CKK_DES3:
30147c478bd9Sstevel@tonic-gate /* CKA_VALUE_LEN attribute does not apply to DES<n> */
30157c478bd9Sstevel@tonic-gate if (isValueLen) {
30167c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
30177c478bd9Sstevel@tonic-gate goto fail_cleanup;
30187c478bd9Sstevel@tonic-gate }
30197c478bd9Sstevel@tonic-gate break;
30207c478bd9Sstevel@tonic-gate
30217c478bd9Sstevel@tonic-gate default:
30227c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
30237c478bd9Sstevel@tonic-gate goto fail_cleanup;
30247c478bd9Sstevel@tonic-gate }
30257c478bd9Sstevel@tonic-gate break;
30267c478bd9Sstevel@tonic-gate
30277c478bd9Sstevel@tonic-gate case SOFT_DERIVE_KEY_DH:
30287c478bd9Sstevel@tonic-gate /* CKA_VALUE must not be specified */
30297c478bd9Sstevel@tonic-gate if (isValue) {
30307c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
30317c478bd9Sstevel@tonic-gate goto fail_cleanup;
30327c478bd9Sstevel@tonic-gate }
30337c478bd9Sstevel@tonic-gate
30347c478bd9Sstevel@tonic-gate switch (keytype) {
30357c478bd9Sstevel@tonic-gate /*
30367c478bd9Sstevel@tonic-gate * CKA_VALUE_LEN is optional
30377c478bd9Sstevel@tonic-gate * if mech is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET.
30387c478bd9Sstevel@tonic-gate */
30397c478bd9Sstevel@tonic-gate case CKK_RC4:
30407c478bd9Sstevel@tonic-gate if (isValueLen) {
30417c478bd9Sstevel@tonic-gate if ((sck->sk_value_len <
30427c478bd9Sstevel@tonic-gate ARCFOUR_MIN_KEY_BYTES) ||
30437c478bd9Sstevel@tonic-gate (sck->sk_value_len >
30447c478bd9Sstevel@tonic-gate ARCFOUR_MAX_KEY_BYTES)) {
30457c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
30467c478bd9Sstevel@tonic-gate goto fail_cleanup;
30477c478bd9Sstevel@tonic-gate }
30487c478bd9Sstevel@tonic-gate }
30497c478bd9Sstevel@tonic-gate break;
30507c478bd9Sstevel@tonic-gate
30517c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET:
30527c478bd9Sstevel@tonic-gate /* arbitrary key length - no length checking */
30537c478bd9Sstevel@tonic-gate break;
30547c478bd9Sstevel@tonic-gate
30557c478bd9Sstevel@tonic-gate case CKK_AES:
30567c478bd9Sstevel@tonic-gate if (isValueLen) {
30577c478bd9Sstevel@tonic-gate if ((sck->sk_value_len != AES_MIN_KEY_BYTES) &&
30587c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_192_KEY_BYTES) &&
30597c478bd9Sstevel@tonic-gate (sck->sk_value_len != AES_MAX_KEY_BYTES)) {
30607c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
30617c478bd9Sstevel@tonic-gate goto fail_cleanup;
30627c478bd9Sstevel@tonic-gate }
30637c478bd9Sstevel@tonic-gate }
30647c478bd9Sstevel@tonic-gate
30657c478bd9Sstevel@tonic-gate break;
30667c478bd9Sstevel@tonic-gate
3067f66d273dSizick case CKK_BLOWFISH:
3068f66d273dSizick if (isValueLen &&
3069f66d273dSizick ((sck->sk_value_len < BLOWFISH_MINBYTES) ||
3070f66d273dSizick (sck->sk_value_len > BLOWFISH_MAXBYTES))) {
3071f66d273dSizick rv = CKR_ATTRIBUTE_VALUE_INVALID;
3072f66d273dSizick goto fail_cleanup;
3073f66d273dSizick }
3074f66d273dSizick break;
3075f66d273dSizick
30767c478bd9Sstevel@tonic-gate case CKK_DES:
30777c478bd9Sstevel@tonic-gate case CKK_DES2:
30787c478bd9Sstevel@tonic-gate case CKK_DES3:
30797c478bd9Sstevel@tonic-gate /* CKA_VALUE_LEN attribute does not apply to DES<n> */
30807c478bd9Sstevel@tonic-gate if (isValueLen) {
30817c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
30827c478bd9Sstevel@tonic-gate goto fail_cleanup;
30837c478bd9Sstevel@tonic-gate }
30847c478bd9Sstevel@tonic-gate break;
30857c478bd9Sstevel@tonic-gate
30867c478bd9Sstevel@tonic-gate default:
30877c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
30887c478bd9Sstevel@tonic-gate goto fail_cleanup;
30897c478bd9Sstevel@tonic-gate }
30907c478bd9Sstevel@tonic-gate break;
30917c478bd9Sstevel@tonic-gate
30927c478bd9Sstevel@tonic-gate case SOFT_DERIVE_KEY_OTHER:
30937c478bd9Sstevel@tonic-gate /* CKA_VALUE must not be specified */
30947c478bd9Sstevel@tonic-gate if (isValue) {
30957c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
30967c478bd9Sstevel@tonic-gate goto fail_cleanup;
30977c478bd9Sstevel@tonic-gate }
30987c478bd9Sstevel@tonic-gate
30997c478bd9Sstevel@tonic-gate switch (keytype) {
31007c478bd9Sstevel@tonic-gate /*
31017c478bd9Sstevel@tonic-gate * CKA_VALUE_LEN is an optional attribute for
31027c478bd9Sstevel@tonic-gate * CKM_SHA1_KEY_DERIVATION and CKM_MD5_KEY_DERIVATION
31037c478bd9Sstevel@tonic-gate * if mech is CKK_RC4, CKK_AES, CKK_GENERIC_SECRET.
31047c478bd9Sstevel@tonic-gate */
31057c478bd9Sstevel@tonic-gate case CKK_RC4:
31067c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET:
31077c478bd9Sstevel@tonic-gate case CKK_AES:
3108f66d273dSizick case CKK_BLOWFISH:
31097c478bd9Sstevel@tonic-gate /*
31107c478bd9Sstevel@tonic-gate * No need to check key length value here, it will be
31117c478bd9Sstevel@tonic-gate * validated later in soft_key_derive_check_length().
31127c478bd9Sstevel@tonic-gate */
31137c478bd9Sstevel@tonic-gate break;
31147c478bd9Sstevel@tonic-gate
31157c478bd9Sstevel@tonic-gate case CKK_DES:
31167c478bd9Sstevel@tonic-gate case CKK_DES2:
31177c478bd9Sstevel@tonic-gate case CKK_DES3:
31187c478bd9Sstevel@tonic-gate /* CKA_VALUE_LEN attribute does not apply to DES<n> */
31197c478bd9Sstevel@tonic-gate if (isValueLen) {
31207c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
31217c478bd9Sstevel@tonic-gate goto fail_cleanup;
31227c478bd9Sstevel@tonic-gate }
31237c478bd9Sstevel@tonic-gate break;
31247c478bd9Sstevel@tonic-gate
31257c478bd9Sstevel@tonic-gate default:
31267c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
31277c478bd9Sstevel@tonic-gate goto fail_cleanup;
31287c478bd9Sstevel@tonic-gate }
31297c478bd9Sstevel@tonic-gate break;
31307c478bd9Sstevel@tonic-gate }
31317c478bd9Sstevel@tonic-gate
31327c478bd9Sstevel@tonic-gate /* Set up object. */
31337c478bd9Sstevel@tonic-gate new_object->key_type = keytype;
31347c478bd9Sstevel@tonic-gate new_object->object_type = object_type;
31357c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask;
31367c478bd9Sstevel@tonic-gate if (isLabel) {
31377c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&string_tmp, new_object);
31387c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
31397c478bd9Sstevel@tonic-gate goto fail_cleanup;
31407c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
31417c478bd9Sstevel@tonic-gate }
31427c478bd9Sstevel@tonic-gate return (rv);
31437c478bd9Sstevel@tonic-gate
31447c478bd9Sstevel@tonic-gate fail_cleanup:
31457c478bd9Sstevel@tonic-gate /*
31467c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables.
31477c478bd9Sstevel@tonic-gate */
31487c478bd9Sstevel@tonic-gate bigint_attr_cleanup((biginteger_t *)sck);
31497c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
31507c478bd9Sstevel@tonic-gate
31517c478bd9Sstevel@tonic-gate /*
31527c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself.
31537c478bd9Sstevel@tonic-gate */
31547c478bd9Sstevel@tonic-gate soft_cleanup_object(new_object);
31557c478bd9Sstevel@tonic-gate
31567c478bd9Sstevel@tonic-gate return (rv);
31577c478bd9Sstevel@tonic-gate }
31587c478bd9Sstevel@tonic-gate
31597c478bd9Sstevel@tonic-gate
31607c478bd9Sstevel@tonic-gate /*
31617c478bd9Sstevel@tonic-gate * Build a Domain Parameter Object.
31627c478bd9Sstevel@tonic-gate *
31637c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as
31647c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return
31657c478bd9Sstevel@tonic-gate * with appropriate return value.
31667c478bd9Sstevel@tonic-gate * - Allocate storage for the Domain Parameter object.
31677c478bd9Sstevel@tonic-gate * - Build the Domain Parameter object according to the key type. Allocate
31687c478bd9Sstevel@tonic-gate * storage to hold the big integer value for the supplied attributes
31697c478bd9Sstevel@tonic-gate * that are required for a certain key type.
31707c478bd9Sstevel@tonic-gate *
31717c478bd9Sstevel@tonic-gate */
31727c478bd9Sstevel@tonic-gate CK_RV
31737c478bd9Sstevel@tonic-gate soft_build_domain_parameters_object(CK_ATTRIBUTE_PTR template,
31747c478bd9Sstevel@tonic-gate CK_ULONG ulAttrNum, soft_object_t *new_object)
31757c478bd9Sstevel@tonic-gate {
31767c478bd9Sstevel@tonic-gate
31777c478bd9Sstevel@tonic-gate ulong_t i;
31787c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL;
31797c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
31807c478bd9Sstevel@tonic-gate int isLabel = 0;
31817c478bd9Sstevel@tonic-gate /* Must set flags */
31827c478bd9Sstevel@tonic-gate int isPrime = 0;
31837c478bd9Sstevel@tonic-gate int isSubprime = 0;
31847c478bd9Sstevel@tonic-gate int isBase = 0;
31857c478bd9Sstevel@tonic-gate /* Must not set flags */
31867c478bd9Sstevel@tonic-gate int isPrimeBits = 0;
31877c478bd9Sstevel@tonic-gate int isSubPrimeBits = 0;
31887c478bd9Sstevel@tonic-gate
31897c478bd9Sstevel@tonic-gate biginteger_t prime;
31907c478bd9Sstevel@tonic-gate biginteger_t subprime;
31917c478bd9Sstevel@tonic-gate biginteger_t base;
31927c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp;
31937c478bd9Sstevel@tonic-gate
31947c478bd9Sstevel@tonic-gate domain_obj_t *dom;
31957c478bd9Sstevel@tonic-gate uchar_t object_type = 0;
31967c478bd9Sstevel@tonic-gate
31977c478bd9Sstevel@tonic-gate /* prevent bigint_attr_cleanup from freeing invalid attr value */
31987c478bd9Sstevel@tonic-gate (void) memset(&prime, 0x0, sizeof (biginteger_t));
31997c478bd9Sstevel@tonic-gate (void) memset(&subprime, 0x0, sizeof (biginteger_t));
32007c478bd9Sstevel@tonic-gate (void) memset(&base, 0x0, sizeof (biginteger_t));
32017c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL;
32027c478bd9Sstevel@tonic-gate
32037c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
32047c478bd9Sstevel@tonic-gate
32057c478bd9Sstevel@tonic-gate /* Domain Parameters Object Attributes */
32067c478bd9Sstevel@tonic-gate switch (template[i].type) {
32077c478bd9Sstevel@tonic-gate
32087c478bd9Sstevel@tonic-gate /* common domain parameter attribute */
32097c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
32107c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue);
32117c478bd9Sstevel@tonic-gate break;
32127c478bd9Sstevel@tonic-gate
32137c478bd9Sstevel@tonic-gate /*
32147c478bd9Sstevel@tonic-gate * The following common domain parameter attribute
32157c478bd9Sstevel@tonic-gate * must not be specified by C_CreateObject.
32167c478bd9Sstevel@tonic-gate */
32177c478bd9Sstevel@tonic-gate case CKA_LOCAL:
32187c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
32197c478bd9Sstevel@tonic-gate goto fail_cleanup;
32207c478bd9Sstevel@tonic-gate
32217c478bd9Sstevel@tonic-gate /*
32227c478bd9Sstevel@tonic-gate * The following domain parameter attributes must be
32237c478bd9Sstevel@tonic-gate * specified according to the key type by
32247c478bd9Sstevel@tonic-gate * C_CreateObject.
32257c478bd9Sstevel@tonic-gate */
32267c478bd9Sstevel@tonic-gate case CKA_PRIME:
32277c478bd9Sstevel@tonic-gate isPrime = 1;
32287c478bd9Sstevel@tonic-gate /*
32297c478bd9Sstevel@tonic-gate * Copyin big integer attribute from template
32307c478bd9Sstevel@tonic-gate * to a local variable.
32317c478bd9Sstevel@tonic-gate */
32327c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime,
32337c478bd9Sstevel@tonic-gate &template[i]);
32347c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
32357c478bd9Sstevel@tonic-gate goto fail_cleanup;
32367c478bd9Sstevel@tonic-gate break;
32377c478bd9Sstevel@tonic-gate
32387c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
32397c478bd9Sstevel@tonic-gate isSubprime = 1;
32407c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&subprime,
32417c478bd9Sstevel@tonic-gate &template[i]);
32427c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
32437c478bd9Sstevel@tonic-gate goto fail_cleanup;
32447c478bd9Sstevel@tonic-gate break;
32457c478bd9Sstevel@tonic-gate
32467c478bd9Sstevel@tonic-gate case CKA_BASE:
32477c478bd9Sstevel@tonic-gate isBase = 1;
32487c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&base,
32497c478bd9Sstevel@tonic-gate &template[i]);
32507c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
32517c478bd9Sstevel@tonic-gate goto fail_cleanup;
32527c478bd9Sstevel@tonic-gate break;
32537c478bd9Sstevel@tonic-gate
32547c478bd9Sstevel@tonic-gate case CKA_PRIME_BITS:
32557c478bd9Sstevel@tonic-gate isPrimeBits = 1;
32567c478bd9Sstevel@tonic-gate break;
32577c478bd9Sstevel@tonic-gate
32587c478bd9Sstevel@tonic-gate case CKA_SUB_PRIME_BITS:
32597c478bd9Sstevel@tonic-gate isSubPrimeBits = 1;
32607c478bd9Sstevel@tonic-gate break;
32617c478bd9Sstevel@tonic-gate
32627c478bd9Sstevel@tonic-gate case CKA_LABEL:
32637c478bd9Sstevel@tonic-gate isLabel = 1;
32647c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp,
32657c478bd9Sstevel@tonic-gate &template[i]);
32667c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
32677c478bd9Sstevel@tonic-gate goto fail_cleanup;
32687c478bd9Sstevel@tonic-gate break;
32697c478bd9Sstevel@tonic-gate
32707c478bd9Sstevel@tonic-gate default:
32717c478bd9Sstevel@tonic-gate rv = soft_parse_common_attrs(&template[i],
32727c478bd9Sstevel@tonic-gate &object_type);
32737c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
32747c478bd9Sstevel@tonic-gate goto fail_cleanup;
32757c478bd9Sstevel@tonic-gate break;
32767c478bd9Sstevel@tonic-gate
32777c478bd9Sstevel@tonic-gate }
32787c478bd9Sstevel@tonic-gate } /* For */
32797c478bd9Sstevel@tonic-gate
32807c478bd9Sstevel@tonic-gate /* Allocate storage for Domain Parameters Object. */
32817c478bd9Sstevel@tonic-gate dom = calloc(1, sizeof (domain_obj_t));
32827c478bd9Sstevel@tonic-gate if (dom == NULL) {
32837c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY;
32847c478bd9Sstevel@tonic-gate goto fail_cleanup;
32857c478bd9Sstevel@tonic-gate }
32867c478bd9Sstevel@tonic-gate
32877c478bd9Sstevel@tonic-gate new_object->object_class_u.domain = dom;
32887c478bd9Sstevel@tonic-gate new_object->class = CKO_DOMAIN_PARAMETERS;
32897c478bd9Sstevel@tonic-gate
32907c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) {
32917c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
32927c478bd9Sstevel@tonic-gate goto fail_cleanup;
32937c478bd9Sstevel@tonic-gate }
32947c478bd9Sstevel@tonic-gate
32957c478bd9Sstevel@tonic-gate new_object->key_type = keytype;
32967c478bd9Sstevel@tonic-gate
32977c478bd9Sstevel@tonic-gate /* Supported key types of the Domain Parameters Object */
32987c478bd9Sstevel@tonic-gate switch (keytype) {
32997c478bd9Sstevel@tonic-gate case CKK_DSA:
33007c478bd9Sstevel@tonic-gate if (isPrimeBits || isSubPrimeBits) {
33017c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
33027c478bd9Sstevel@tonic-gate goto fail_cleanup;
33037c478bd9Sstevel@tonic-gate }
33047c478bd9Sstevel@tonic-gate
33057c478bd9Sstevel@tonic-gate if (isPrime && isSubprime && isBase) {
33067c478bd9Sstevel@tonic-gate /*
33077c478bd9Sstevel@tonic-gate * Copy big integer attribute value to the
33087c478bd9Sstevel@tonic-gate * designated place in the domain parameter
33097c478bd9Sstevel@tonic-gate * object.
33107c478bd9Sstevel@tonic-gate */
33117c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_DOM_DSA_PRIME(dom));
33127c478bd9Sstevel@tonic-gate
33137c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime, KEY_DOM_DSA_SUBPRIME(dom));
33147c478bd9Sstevel@tonic-gate
33157c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_DOM_DSA_BASE(dom));
33167c478bd9Sstevel@tonic-gate } else {
33177c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
33187c478bd9Sstevel@tonic-gate goto fail_cleanup;
33197c478bd9Sstevel@tonic-gate }
33207c478bd9Sstevel@tonic-gate break;
33217c478bd9Sstevel@tonic-gate
33227c478bd9Sstevel@tonic-gate case CKK_DH:
33237c478bd9Sstevel@tonic-gate if (isPrimeBits || isSubprime || isSubPrimeBits) {
33247c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
33257c478bd9Sstevel@tonic-gate goto fail_cleanup;
33267c478bd9Sstevel@tonic-gate }
33277c478bd9Sstevel@tonic-gate
33287c478bd9Sstevel@tonic-gate if (isPrime && isBase) {
33297c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_DOM_DH_PRIME(dom));
33307c478bd9Sstevel@tonic-gate
33317c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_DOM_DH_BASE(dom));
33327c478bd9Sstevel@tonic-gate } else {
33337c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
33347c478bd9Sstevel@tonic-gate goto fail_cleanup;
33357c478bd9Sstevel@tonic-gate }
33367c478bd9Sstevel@tonic-gate break;
33377c478bd9Sstevel@tonic-gate
33387c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
33397c478bd9Sstevel@tonic-gate if (isPrimeBits || isSubPrimeBits) {
33407c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
33417c478bd9Sstevel@tonic-gate goto fail_cleanup;
33427c478bd9Sstevel@tonic-gate }
33437c478bd9Sstevel@tonic-gate
33447c478bd9Sstevel@tonic-gate if (isPrime && isSubprime && isBase) {
33457c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_DOM_DH942_PRIME(dom));
33467c478bd9Sstevel@tonic-gate
33477c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_DOM_DH942_BASE(dom));
33487c478bd9Sstevel@tonic-gate
33497c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime,
33507c478bd9Sstevel@tonic-gate KEY_DOM_DH942_SUBPRIME(dom));
33517c478bd9Sstevel@tonic-gate } else {
33527c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
33537c478bd9Sstevel@tonic-gate goto fail_cleanup;
33547c478bd9Sstevel@tonic-gate }
33557c478bd9Sstevel@tonic-gate break;
33567c478bd9Sstevel@tonic-gate
33577c478bd9Sstevel@tonic-gate default:
33587c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
33597c478bd9Sstevel@tonic-gate goto fail_cleanup;
33607c478bd9Sstevel@tonic-gate }
33617c478bd9Sstevel@tonic-gate
33627c478bd9Sstevel@tonic-gate new_object->object_type = object_type;
33637c478bd9Sstevel@tonic-gate
33647c478bd9Sstevel@tonic-gate if (isLabel) {
33657c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&string_tmp, new_object);
33667c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
33677c478bd9Sstevel@tonic-gate goto fail_cleanup;
33687c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
33697c478bd9Sstevel@tonic-gate }
33707c478bd9Sstevel@tonic-gate
33717c478bd9Sstevel@tonic-gate return (rv);
33727c478bd9Sstevel@tonic-gate
33737c478bd9Sstevel@tonic-gate fail_cleanup:
33747c478bd9Sstevel@tonic-gate /*
33757c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables.
33767c478bd9Sstevel@tonic-gate */
33777c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime);
33787c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&subprime);
33797c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&base);
33807c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
33817c478bd9Sstevel@tonic-gate
33827c478bd9Sstevel@tonic-gate /*
33837c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself.
33847c478bd9Sstevel@tonic-gate */
33857c478bd9Sstevel@tonic-gate soft_cleanup_object(new_object);
33867c478bd9Sstevel@tonic-gate
33877c478bd9Sstevel@tonic-gate return (rv);
33887c478bd9Sstevel@tonic-gate }
33897c478bd9Sstevel@tonic-gate
33907c478bd9Sstevel@tonic-gate /*
33917c478bd9Sstevel@tonic-gate * Build a Certificate Object
33927c478bd9Sstevel@tonic-gate *
33937c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as
33947c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return
33957c478bd9Sstevel@tonic-gate * with appropriate return value.
33967c478bd9Sstevel@tonic-gate * - Allocate storage for the Certificate object
33977c478bd9Sstevel@tonic-gate */
33987c478bd9Sstevel@tonic-gate static CK_RV
33997c478bd9Sstevel@tonic-gate soft_build_certificate_object(CK_ATTRIBUTE_PTR template,
34007c478bd9Sstevel@tonic-gate CK_ULONG ulAttrNum, soft_object_t *new_object,
34017c478bd9Sstevel@tonic-gate CK_CERTIFICATE_TYPE cert_type)
34027c478bd9Sstevel@tonic-gate {
34037c478bd9Sstevel@tonic-gate uint64_t attr_mask = 0;
34047c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
34057c478bd9Sstevel@tonic-gate CK_ULONG i;
34067c478bd9Sstevel@tonic-gate int owner_set = 0;
34077c478bd9Sstevel@tonic-gate int value_set = 0;
34087c478bd9Sstevel@tonic-gate int subject_set = 0;
34097c478bd9Sstevel@tonic-gate certificate_obj_t *cert;
34107c478bd9Sstevel@tonic-gate /* certificate type defaults to the value given as a parameter */
34117c478bd9Sstevel@tonic-gate CK_CERTIFICATE_TYPE certtype = cert_type;
34127c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp;
34137c478bd9Sstevel@tonic-gate int isLabel = 0;
34147c478bd9Sstevel@tonic-gate uchar_t object_type = 0;
34157c478bd9Sstevel@tonic-gate
34167c478bd9Sstevel@tonic-gate /*
34177c478bd9Sstevel@tonic-gate * Look for the certificate type attribute and do some
34187c478bd9Sstevel@tonic-gate * sanity checking before creating the structures.
34197c478bd9Sstevel@tonic-gate */
34207c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
34217c478bd9Sstevel@tonic-gate /* Certificate Object Attributes */
34227c478bd9Sstevel@tonic-gate switch (template[i].type) {
34237c478bd9Sstevel@tonic-gate case CKA_CERTIFICATE_TYPE:
34247c478bd9Sstevel@tonic-gate certtype =
34257c478bd9Sstevel@tonic-gate *((CK_CERTIFICATE_TYPE*)template[i].pValue);
34267c478bd9Sstevel@tonic-gate break;
34277c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
34287c478bd9Sstevel@tonic-gate subject_set = 1;
34297c478bd9Sstevel@tonic-gate break;
34307c478bd9Sstevel@tonic-gate case CKA_OWNER:
34317c478bd9Sstevel@tonic-gate owner_set = 1;
34327c478bd9Sstevel@tonic-gate break;
34337c478bd9Sstevel@tonic-gate case CKA_VALUE:
34347c478bd9Sstevel@tonic-gate value_set = 1;
34357c478bd9Sstevel@tonic-gate break;
34367c478bd9Sstevel@tonic-gate }
34377c478bd9Sstevel@tonic-gate }
34387c478bd9Sstevel@tonic-gate
34397c478bd9Sstevel@tonic-gate /* The certificate type MUST be specified */
34407c478bd9Sstevel@tonic-gate if (certtype != CKC_X_509 && certtype != CKC_X_509_ATTR_CERT)
34417c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCOMPLETE);
34427c478bd9Sstevel@tonic-gate
34437c478bd9Sstevel@tonic-gate /*
34447c478bd9Sstevel@tonic-gate * For X.509 certs, the CKA_SUBJECT and CKA_VALUE
34457c478bd9Sstevel@tonic-gate * must be present at creation time.
34467c478bd9Sstevel@tonic-gate */
34477c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509 &&
34487c478bd9Sstevel@tonic-gate (!subject_set || !value_set))
34497c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCOMPLETE);
34507c478bd9Sstevel@tonic-gate
34517c478bd9Sstevel@tonic-gate /*
34527c478bd9Sstevel@tonic-gate * For X.509 Attribute certs, the CKA_OWNER and CKA_VALUE
34537c478bd9Sstevel@tonic-gate * must be present at creation time.
34547c478bd9Sstevel@tonic-gate */
34557c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509_ATTR_CERT &&
34567c478bd9Sstevel@tonic-gate (!owner_set || !value_set))
34577c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCOMPLETE);
34587c478bd9Sstevel@tonic-gate
34597c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL;
34607c478bd9Sstevel@tonic-gate cert = calloc(1, sizeof (certificate_obj_t));
34617c478bd9Sstevel@tonic-gate if (cert == NULL) {
34627c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
34637c478bd9Sstevel@tonic-gate }
34647c478bd9Sstevel@tonic-gate cert->certificate_type = certtype;
34657c478bd9Sstevel@tonic-gate
34667c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) {
34677c478bd9Sstevel@tonic-gate /* Certificate Object Attributes */
34687c478bd9Sstevel@tonic-gate switch (certtype) {
34697c478bd9Sstevel@tonic-gate case CKC_X_509:
34707c478bd9Sstevel@tonic-gate switch (template[i].type) {
34717c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
34727c478bd9Sstevel@tonic-gate rv = get_cert_attr_from_template(
34737c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509.subject,
34747c478bd9Sstevel@tonic-gate &template[i]);
34757c478bd9Sstevel@tonic-gate break;
34767c478bd9Sstevel@tonic-gate case CKA_VALUE:
34777c478bd9Sstevel@tonic-gate rv = get_cert_attr_from_template(
34787c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509.value,
34797c478bd9Sstevel@tonic-gate &template[i]);
34807c478bd9Sstevel@tonic-gate break;
34817c478bd9Sstevel@tonic-gate case CKA_LABEL:
34827c478bd9Sstevel@tonic-gate isLabel = 1;
34837c478bd9Sstevel@tonic-gate rv = get_string_from_template(
34847c478bd9Sstevel@tonic-gate &string_tmp,
34857c478bd9Sstevel@tonic-gate &template[i]);
34867c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
34877c478bd9Sstevel@tonic-gate goto fail_cleanup;
34887c478bd9Sstevel@tonic-gate break;
34897c478bd9Sstevel@tonic-gate case CKA_ID:
34907c478bd9Sstevel@tonic-gate case CKA_ISSUER:
34917c478bd9Sstevel@tonic-gate case CKA_SERIAL_NUMBER:
34927c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&template[i],
34937c478bd9Sstevel@tonic-gate new_object);
34947c478bd9Sstevel@tonic-gate break;
34957c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
34967c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template[i].pValue) ==
34977c478bd9Sstevel@tonic-gate B_FALSE)
34987c478bd9Sstevel@tonic-gate attr_mask |=
34997c478bd9Sstevel@tonic-gate NOT_MODIFIABLE_BOOL_ON;
35007c478bd9Sstevel@tonic-gate break;
35017c478bd9Sstevel@tonic-gate case CKA_CERTIFICATE_TYPE:
35027c478bd9Sstevel@tonic-gate break;
35037c478bd9Sstevel@tonic-gate default:
3504f9fbec18Smcpowers rv = soft_parse_common_attrs(
3505f9fbec18Smcpowers &template[i], &object_type);
35067c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
35077c478bd9Sstevel@tonic-gate goto fail_cleanup;
35087c478bd9Sstevel@tonic-gate }
35097c478bd9Sstevel@tonic-gate break;
35107c478bd9Sstevel@tonic-gate case CKC_X_509_ATTR_CERT:
35117c478bd9Sstevel@tonic-gate switch (template[i].type) {
35127c478bd9Sstevel@tonic-gate case CKA_OWNER:
35137c478bd9Sstevel@tonic-gate rv = get_cert_attr_from_template(
35147c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509_attr.owner,
35157c478bd9Sstevel@tonic-gate &template[i]);
35167c478bd9Sstevel@tonic-gate break;
35177c478bd9Sstevel@tonic-gate case CKA_VALUE:
35187c478bd9Sstevel@tonic-gate rv = get_cert_attr_from_template(
35197c478bd9Sstevel@tonic-gate &cert->cert_type_u.x509_attr.value,
35207c478bd9Sstevel@tonic-gate &template[i]);
35217c478bd9Sstevel@tonic-gate break;
35227c478bd9Sstevel@tonic-gate case CKA_LABEL:
35237c478bd9Sstevel@tonic-gate isLabel = 1;
35247c478bd9Sstevel@tonic-gate rv = get_string_from_template(
35257c478bd9Sstevel@tonic-gate &string_tmp, &template[i]);
35267c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
35277c478bd9Sstevel@tonic-gate goto fail_cleanup;
35287c478bd9Sstevel@tonic-gate break;
35297c478bd9Sstevel@tonic-gate case CKA_SERIAL_NUMBER:
35307c478bd9Sstevel@tonic-gate case CKA_AC_ISSUER:
35317c478bd9Sstevel@tonic-gate case CKA_ATTR_TYPES:
35327c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&template[i],
35337c478bd9Sstevel@tonic-gate new_object);
35347c478bd9Sstevel@tonic-gate break;
35357c478bd9Sstevel@tonic-gate
35367c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
35377c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template[i].pValue) ==
35387c478bd9Sstevel@tonic-gate B_FALSE)
35397c478bd9Sstevel@tonic-gate attr_mask |=
35407c478bd9Sstevel@tonic-gate NOT_MODIFIABLE_BOOL_ON;
35417c478bd9Sstevel@tonic-gate break;
35427c478bd9Sstevel@tonic-gate case CKA_CERTIFICATE_TYPE:
35437c478bd9Sstevel@tonic-gate break;
35447c478bd9Sstevel@tonic-gate default:
3545f9fbec18Smcpowers rv = soft_parse_common_attrs(
3546f9fbec18Smcpowers &template[i], &object_type);
35477c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
35487c478bd9Sstevel@tonic-gate goto fail_cleanup;
35497c478bd9Sstevel@tonic-gate break;
35507c478bd9Sstevel@tonic-gate }
35517c478bd9Sstevel@tonic-gate break;
35527c478bd9Sstevel@tonic-gate default:
35537c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE;
35547c478bd9Sstevel@tonic-gate break;
35557c478bd9Sstevel@tonic-gate }
35567c478bd9Sstevel@tonic-gate }
35577c478bd9Sstevel@tonic-gate
35587c478bd9Sstevel@tonic-gate if (rv == CKR_OK) {
35597c478bd9Sstevel@tonic-gate new_object->object_class_u.certificate = cert;
35607c478bd9Sstevel@tonic-gate new_object->class = CKO_CERTIFICATE;
35617c478bd9Sstevel@tonic-gate new_object->object_type = object_type;
35627c478bd9Sstevel@tonic-gate new_object->cert_type = certtype;
35637c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask;
35647c478bd9Sstevel@tonic-gate if (isLabel) {
35657c478bd9Sstevel@tonic-gate rv = soft_add_extra_attr(&string_tmp, new_object);
35667c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
35677c478bd9Sstevel@tonic-gate goto fail_cleanup;
35687c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp);
35697c478bd9Sstevel@tonic-gate }
35707c478bd9Sstevel@tonic-gate }
35717c478bd9Sstevel@tonic-gate
35727c478bd9Sstevel@tonic-gate fail_cleanup:
35737c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
35747c478bd9Sstevel@tonic-gate soft_cleanup_cert_object(new_object);
35757c478bd9Sstevel@tonic-gate }
35767c478bd9Sstevel@tonic-gate return (rv);
35777c478bd9Sstevel@tonic-gate }
35787c478bd9Sstevel@tonic-gate
35797c478bd9Sstevel@tonic-gate
35807c478bd9Sstevel@tonic-gate /*
35817c478bd9Sstevel@tonic-gate * Validate the attribute types in the object's template. Then,
35827c478bd9Sstevel@tonic-gate * call the appropriate build function according to the class of
35837c478bd9Sstevel@tonic-gate * the object specified in the template.
35847c478bd9Sstevel@tonic-gate *
35857c478bd9Sstevel@tonic-gate * Note: The following classes of objects are supported:
35867c478bd9Sstevel@tonic-gate * - CKO_PUBLIC_KEY
35877c478bd9Sstevel@tonic-gate * - CKO_PRIVATE_KEY
35887c478bd9Sstevel@tonic-gate * - CKO_SECRET_KEY
35897c478bd9Sstevel@tonic-gate * - CKO_DOMAIN_PARAMETERS
35907c478bd9Sstevel@tonic-gate * - CKO_CERTIFICATE
35917c478bd9Sstevel@tonic-gate *
35927c478bd9Sstevel@tonic-gate */
35937c478bd9Sstevel@tonic-gate CK_RV
35947c478bd9Sstevel@tonic-gate soft_build_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
35957c478bd9Sstevel@tonic-gate soft_object_t *new_object)
35967c478bd9Sstevel@tonic-gate {
35977c478bd9Sstevel@tonic-gate
35987c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = (CK_OBJECT_CLASS)~0UL;
35997c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
36007c478bd9Sstevel@tonic-gate
36017c478bd9Sstevel@tonic-gate if (template == NULL) {
36027c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD);
36037c478bd9Sstevel@tonic-gate }
36047c478bd9Sstevel@tonic-gate
36057c478bd9Sstevel@tonic-gate /* Validate the attribute type in the template. */
36067c478bd9Sstevel@tonic-gate rv = soft_validate_attr(template, ulAttrNum, &class);
36077c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
36087c478bd9Sstevel@tonic-gate return (rv);
36097c478bd9Sstevel@tonic-gate /*
36107c478bd9Sstevel@tonic-gate * CKA_CLASS is a mandatory attribute for C_CreateObject
36117c478bd9Sstevel@tonic-gate */
36127c478bd9Sstevel@tonic-gate if (class == (CK_OBJECT_CLASS)~0UL)
36137c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCOMPLETE);
36147c478bd9Sstevel@tonic-gate
36157c478bd9Sstevel@tonic-gate /*
36167c478bd9Sstevel@tonic-gate * Call the appropriate function based on the supported class
36177c478bd9Sstevel@tonic-gate * of the object.
36187c478bd9Sstevel@tonic-gate */
36197c478bd9Sstevel@tonic-gate switch (class) {
36207c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY:
36217c478bd9Sstevel@tonic-gate rv = soft_build_public_key_object(template, ulAttrNum,
36227c478bd9Sstevel@tonic-gate new_object, SOFT_CREATE_OBJ, (CK_KEY_TYPE)~0UL);
36237c478bd9Sstevel@tonic-gate break;
36247c478bd9Sstevel@tonic-gate
36257c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY:
36267c478bd9Sstevel@tonic-gate rv = soft_build_private_key_object(template, ulAttrNum,
36277c478bd9Sstevel@tonic-gate new_object, SOFT_CREATE_OBJ, (CK_KEY_TYPE)~0UL);
36287c478bd9Sstevel@tonic-gate break;
36297c478bd9Sstevel@tonic-gate
36307c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY:
36317c478bd9Sstevel@tonic-gate rv = soft_build_secret_key_object(template, ulAttrNum,
36327c478bd9Sstevel@tonic-gate new_object, SOFT_CREATE_OBJ, 0, (CK_KEY_TYPE)~0UL);
36337c478bd9Sstevel@tonic-gate break;
36347c478bd9Sstevel@tonic-gate
36357c478bd9Sstevel@tonic-gate case CKO_DOMAIN_PARAMETERS:
36367c478bd9Sstevel@tonic-gate rv = soft_build_domain_parameters_object(template, ulAttrNum,
36377c478bd9Sstevel@tonic-gate new_object);
36387c478bd9Sstevel@tonic-gate break;
36397c478bd9Sstevel@tonic-gate
36407c478bd9Sstevel@tonic-gate case CKO_CERTIFICATE:
36417c478bd9Sstevel@tonic-gate rv = soft_build_certificate_object(template, ulAttrNum,
36427c478bd9Sstevel@tonic-gate new_object, (CK_CERTIFICATE_TYPE)~0UL);
36437c478bd9Sstevel@tonic-gate break;
36447c478bd9Sstevel@tonic-gate
36457c478bd9Sstevel@tonic-gate case CKO_DATA:
36467c478bd9Sstevel@tonic-gate case CKO_HW_FEATURE:
36477c478bd9Sstevel@tonic-gate case CKO_VENDOR_DEFINED:
36487c478bd9Sstevel@tonic-gate default:
36497c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
36507c478bd9Sstevel@tonic-gate }
36517c478bd9Sstevel@tonic-gate
36527c478bd9Sstevel@tonic-gate return (rv);
36537c478bd9Sstevel@tonic-gate }
36547c478bd9Sstevel@tonic-gate
36557c478bd9Sstevel@tonic-gate /*
36567c478bd9Sstevel@tonic-gate * Validate the attribute types in the object's template. Then,
36577c478bd9Sstevel@tonic-gate * call the appropriate build function according to the class of
36587c478bd9Sstevel@tonic-gate * the object specified in the template.
36597c478bd9Sstevel@tonic-gate *
36607c478bd9Sstevel@tonic-gate */
36617c478bd9Sstevel@tonic-gate CK_RV
36627c478bd9Sstevel@tonic-gate soft_build_key(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum,
36637c478bd9Sstevel@tonic-gate soft_object_t *new_object, CK_OBJECT_CLASS class, CK_KEY_TYPE key_type,
36647c478bd9Sstevel@tonic-gate CK_ULONG key_len, CK_ULONG mode)
36657c478bd9Sstevel@tonic-gate {
36667c478bd9Sstevel@tonic-gate
36677c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
36687c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS temp_class = (CK_OBJECT_CLASS)~0UL;
36697c478bd9Sstevel@tonic-gate
36707c478bd9Sstevel@tonic-gate /* Validate the attribute type in the template. */
36717c478bd9Sstevel@tonic-gate if ((template != NULL) && (ulAttrNum != 0)) {
36727c478bd9Sstevel@tonic-gate rv = soft_validate_attr(template, ulAttrNum, &temp_class);
36737c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
36747c478bd9Sstevel@tonic-gate return (rv);
36757c478bd9Sstevel@tonic-gate }
36767c478bd9Sstevel@tonic-gate
36777c478bd9Sstevel@tonic-gate /*
36787c478bd9Sstevel@tonic-gate * If either the class from the parameter list ("class") or
36797c478bd9Sstevel@tonic-gate * the class from the template ("temp_class") is not specified,
36807c478bd9Sstevel@tonic-gate * try to use the other one.
36817c478bd9Sstevel@tonic-gate */
36827c478bd9Sstevel@tonic-gate if (temp_class == (CK_OBJECT_CLASS)~0UL) {
36837c478bd9Sstevel@tonic-gate temp_class = class;
36847c478bd9Sstevel@tonic-gate } else if (class == (CK_OBJECT_CLASS)~0UL) {
36857c478bd9Sstevel@tonic-gate class = temp_class;
36867c478bd9Sstevel@tonic-gate }
36877c478bd9Sstevel@tonic-gate
36887c478bd9Sstevel@tonic-gate /* If object class is still not specified, template is incomplete. */
36897c478bd9Sstevel@tonic-gate if (class == (CK_OBJECT_CLASS)~0UL)
36907c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCOMPLETE);
36917c478bd9Sstevel@tonic-gate
36927c478bd9Sstevel@tonic-gate /* Class should match if specified in both parameters and template. */
36937c478bd9Sstevel@tonic-gate if (class != temp_class)
36947c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCONSISTENT);
36957c478bd9Sstevel@tonic-gate
36967c478bd9Sstevel@tonic-gate /*
36977c478bd9Sstevel@tonic-gate * Call the appropriate function based on the supported class
36987c478bd9Sstevel@tonic-gate * of the object.
36997c478bd9Sstevel@tonic-gate */
37007c478bd9Sstevel@tonic-gate switch (class) {
37017c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY:
37027c478bd9Sstevel@tonic-gate
37037c478bd9Sstevel@tonic-gate /* Unwrapping public keys is not supported. */
37047c478bd9Sstevel@tonic-gate if (mode == SOFT_UNWRAP_KEY) {
37057c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
37067c478bd9Sstevel@tonic-gate break;
37077c478bd9Sstevel@tonic-gate }
37087c478bd9Sstevel@tonic-gate
37097c478bd9Sstevel@tonic-gate rv = soft_build_public_key_object(template, ulAttrNum,
37107c478bd9Sstevel@tonic-gate new_object, mode, key_type);
37117c478bd9Sstevel@tonic-gate break;
37127c478bd9Sstevel@tonic-gate
37137c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY:
37147c478bd9Sstevel@tonic-gate
37157c478bd9Sstevel@tonic-gate rv = soft_build_private_key_object(template, ulAttrNum,
37167c478bd9Sstevel@tonic-gate new_object, mode, key_type);
37177c478bd9Sstevel@tonic-gate break;
37187c478bd9Sstevel@tonic-gate
37197c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY:
37207c478bd9Sstevel@tonic-gate
37217c478bd9Sstevel@tonic-gate rv = soft_build_secret_key_object(template, ulAttrNum,
37227c478bd9Sstevel@tonic-gate new_object, mode, key_len, key_type);
37237c478bd9Sstevel@tonic-gate break;
37247c478bd9Sstevel@tonic-gate
37257c478bd9Sstevel@tonic-gate case CKO_DOMAIN_PARAMETERS:
37267c478bd9Sstevel@tonic-gate
37277c478bd9Sstevel@tonic-gate /* Unwrapping domain parameters is not supported. */
37287c478bd9Sstevel@tonic-gate if (mode == SOFT_UNWRAP_KEY) {
37297c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID;
37307c478bd9Sstevel@tonic-gate break;
37317c478bd9Sstevel@tonic-gate }
37327c478bd9Sstevel@tonic-gate
37337c478bd9Sstevel@tonic-gate rv = soft_build_domain_parameters_object(template, ulAttrNum,
37347c478bd9Sstevel@tonic-gate new_object);
37357c478bd9Sstevel@tonic-gate break;
37367c478bd9Sstevel@tonic-gate
37377c478bd9Sstevel@tonic-gate case CKO_DATA:
37387c478bd9Sstevel@tonic-gate case CKO_CERTIFICATE:
37397c478bd9Sstevel@tonic-gate case CKO_HW_FEATURE:
37407c478bd9Sstevel@tonic-gate case CKO_VENDOR_DEFINED:
37417c478bd9Sstevel@tonic-gate default:
37427c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
37437c478bd9Sstevel@tonic-gate }
37447c478bd9Sstevel@tonic-gate
37457c478bd9Sstevel@tonic-gate return (rv);
37467c478bd9Sstevel@tonic-gate }
37477c478bd9Sstevel@tonic-gate
37487c478bd9Sstevel@tonic-gate
37497c478bd9Sstevel@tonic-gate /*
37507c478bd9Sstevel@tonic-gate * Get the value of a requested attribute that is common to all supported
37517c478bd9Sstevel@tonic-gate * classes (i.e. public key, private key, secret key, domain parameters,
37527c478bd9Sstevel@tonic-gate * and certificate classes).
37537c478bd9Sstevel@tonic-gate */
37547c478bd9Sstevel@tonic-gate CK_RV
37557c478bd9Sstevel@tonic-gate soft_get_common_attrs(soft_object_t *object_p, CK_ATTRIBUTE_PTR template,
37567c478bd9Sstevel@tonic-gate uchar_t object_type)
37577c478bd9Sstevel@tonic-gate {
37587c478bd9Sstevel@tonic-gate
37597c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
37607c478bd9Sstevel@tonic-gate
37617c478bd9Sstevel@tonic-gate switch (template->type) {
37627c478bd9Sstevel@tonic-gate
37637c478bd9Sstevel@tonic-gate case CKA_CLASS:
37647c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(object_p->class,
37657c478bd9Sstevel@tonic-gate template));
37667c478bd9Sstevel@tonic-gate
37677c478bd9Sstevel@tonic-gate /* default boolean attributes */
37687c478bd9Sstevel@tonic-gate case CKA_TOKEN:
37697c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL);
37707c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
37717c478bd9Sstevel@tonic-gate return (CKR_OK);
37727c478bd9Sstevel@tonic-gate }
37737c478bd9Sstevel@tonic-gate if (object_type & TOKEN_OBJECT)
37747c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE;
37757c478bd9Sstevel@tonic-gate else
37767c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE;
37777c478bd9Sstevel@tonic-gate break;
37787c478bd9Sstevel@tonic-gate
37797c478bd9Sstevel@tonic-gate case CKA_PRIVATE:
37807c478bd9Sstevel@tonic-gate
37817c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL);
37827c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
37837c478bd9Sstevel@tonic-gate return (CKR_OK);
37847c478bd9Sstevel@tonic-gate }
37857c478bd9Sstevel@tonic-gate if (object_type & PRIVATE_OBJECT)
37867c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE;
37877c478bd9Sstevel@tonic-gate else
37887c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE;
37897c478bd9Sstevel@tonic-gate break;
37907c478bd9Sstevel@tonic-gate
37917c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
37927c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL);
37937c478bd9Sstevel@tonic-gate if (template->pValue == NULL) {
37947c478bd9Sstevel@tonic-gate return (CKR_OK);
37957c478bd9Sstevel@tonic-gate }
37967c478bd9Sstevel@tonic-gate if ((object_p->bool_attr_mask) & NOT_MODIFIABLE_BOOL_ON)
37977c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE;
37987c478bd9Sstevel@tonic-gate else
37997c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE;
38007c478bd9Sstevel@tonic-gate break;
38017c478bd9Sstevel@tonic-gate
38027c478bd9Sstevel@tonic-gate case CKA_LABEL:
38037c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p,
38047c478bd9Sstevel@tonic-gate template));
38057c478bd9Sstevel@tonic-gate
38067c478bd9Sstevel@tonic-gate default:
38077c478bd9Sstevel@tonic-gate /*
38087c478bd9Sstevel@tonic-gate * The specified attribute for the object is invalid.
38097c478bd9Sstevel@tonic-gate * (the object does not possess such an attribute.)
38107c478bd9Sstevel@tonic-gate */
38117c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
38127c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
38137c478bd9Sstevel@tonic-gate }
38147c478bd9Sstevel@tonic-gate
38157c478bd9Sstevel@tonic-gate return (rv);
38167c478bd9Sstevel@tonic-gate }
38177c478bd9Sstevel@tonic-gate
38187c478bd9Sstevel@tonic-gate /*
38197c478bd9Sstevel@tonic-gate * Get the value of a requested attribute that is common to all key objects
38207c478bd9Sstevel@tonic-gate * (i.e. public key, private key and secret key).
38217c478bd9Sstevel@tonic-gate */
38227c478bd9Sstevel@tonic-gate CK_RV
38237c478bd9Sstevel@tonic-gate soft_get_common_key_attrs(soft_object_t *object_p, CK_ATTRIBUTE_PTR template)
38247c478bd9Sstevel@tonic-gate {
38257c478bd9Sstevel@tonic-gate
38267c478bd9Sstevel@tonic-gate switch (template->type) {
38277c478bd9Sstevel@tonic-gate
38287c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
38297c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(object_p->key_type,
38307c478bd9Sstevel@tonic-gate template));
38317c478bd9Sstevel@tonic-gate
38327c478bd9Sstevel@tonic-gate case CKA_ID:
38337c478bd9Sstevel@tonic-gate case CKA_START_DATE:
38347c478bd9Sstevel@tonic-gate case CKA_END_DATE:
38357c478bd9Sstevel@tonic-gate /*
38367c478bd9Sstevel@tonic-gate * The above extra attributes have byte array type.
38377c478bd9Sstevel@tonic-gate */
38387c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p,
38397c478bd9Sstevel@tonic-gate template));
38407c478bd9Sstevel@tonic-gate
38417c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
38427c478bd9Sstevel@tonic-gate case CKA_LOCAL:
38437c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
38447c478bd9Sstevel@tonic-gate LOCAL_BOOL_ON, template));
38457c478bd9Sstevel@tonic-gate
38467c478bd9Sstevel@tonic-gate case CKA_DERIVE:
38477c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
38487c478bd9Sstevel@tonic-gate DERIVE_BOOL_ON, template));
38497c478bd9Sstevel@tonic-gate
38507c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM:
38517c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(object_p->mechanism,
38527c478bd9Sstevel@tonic-gate template));
38537c478bd9Sstevel@tonic-gate
38547c478bd9Sstevel@tonic-gate default:
38557c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
38567c478bd9Sstevel@tonic-gate }
38577c478bd9Sstevel@tonic-gate }
38587c478bd9Sstevel@tonic-gate
38597c478bd9Sstevel@tonic-gate /*
38607c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Public Key Object.
38617c478bd9Sstevel@tonic-gate *
38627c478bd9Sstevel@tonic-gate * Rule: All the attributes in the public key object can be revealed.
38637c478bd9Sstevel@tonic-gate */
38647c478bd9Sstevel@tonic-gate CK_RV
38657c478bd9Sstevel@tonic-gate soft_get_public_key_attribute(soft_object_t *object_p,
38667c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
38677c478bd9Sstevel@tonic-gate {
38687c478bd9Sstevel@tonic-gate
38697c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
38707c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
38717c478bd9Sstevel@tonic-gate
38727c478bd9Sstevel@tonic-gate switch (template->type) {
38737c478bd9Sstevel@tonic-gate
38747c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
3875f9fbec18Smcpowers case CKA_EC_PARAMS:
38767c478bd9Sstevel@tonic-gate /*
38777c478bd9Sstevel@tonic-gate * The above extra attributes have byte array type.
38787c478bd9Sstevel@tonic-gate */
38797c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p,
38807c478bd9Sstevel@tonic-gate template));
38817c478bd9Sstevel@tonic-gate
38827c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
38837c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
38847c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
38857c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template));
38867c478bd9Sstevel@tonic-gate
38877c478bd9Sstevel@tonic-gate case CKA_VERIFY:
38887c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
38897c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template));
38907c478bd9Sstevel@tonic-gate
38917c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER:
38927c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
38937c478bd9Sstevel@tonic-gate VERIFY_RECOVER_BOOL_ON, template));
38947c478bd9Sstevel@tonic-gate
38957c478bd9Sstevel@tonic-gate case CKA_WRAP:
38967c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
38977c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template));
38987c478bd9Sstevel@tonic-gate
38997c478bd9Sstevel@tonic-gate case CKA_TRUSTED:
39007c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
39017c478bd9Sstevel@tonic-gate TRUSTED_BOOL_ON, template));
39027c478bd9Sstevel@tonic-gate
39037c478bd9Sstevel@tonic-gate case CKA_MODULUS:
39047c478bd9Sstevel@tonic-gate /*
39057c478bd9Sstevel@tonic-gate * This attribute is valid only for RSA public key
39067c478bd9Sstevel@tonic-gate * object.
39077c478bd9Sstevel@tonic-gate */
39087c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
39097c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39107c478bd9Sstevel@tonic-gate OBJ_PUB_RSA_MOD(object_p), template));
39117c478bd9Sstevel@tonic-gate } else {
39127c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
39137c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
39147c478bd9Sstevel@tonic-gate }
39157c478bd9Sstevel@tonic-gate
39167c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
39177c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
39187c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39197c478bd9Sstevel@tonic-gate OBJ_PUB_RSA_PUBEXPO(object_p), template));
39207c478bd9Sstevel@tonic-gate } else {
39217c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
39227c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
39237c478bd9Sstevel@tonic-gate }
39247c478bd9Sstevel@tonic-gate
39257c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS:
39267c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
39277c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
39287c478bd9Sstevel@tonic-gate OBJ_PUB_RSA_MOD_BITS(object_p), template));
39297c478bd9Sstevel@tonic-gate } else {
39307c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
39317c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
39327c478bd9Sstevel@tonic-gate }
39337c478bd9Sstevel@tonic-gate
39347c478bd9Sstevel@tonic-gate case CKA_PRIME:
39357c478bd9Sstevel@tonic-gate switch (keytype) {
39367c478bd9Sstevel@tonic-gate case CKK_DSA:
39377c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39387c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_PRIME(object_p), template));
39397c478bd9Sstevel@tonic-gate
39407c478bd9Sstevel@tonic-gate case CKK_DH:
39417c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39427c478bd9Sstevel@tonic-gate OBJ_PUB_DH_PRIME(object_p), template));
39437c478bd9Sstevel@tonic-gate
39447c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
39457c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39467c478bd9Sstevel@tonic-gate OBJ_PUB_DH942_PRIME(object_p), template));
39477c478bd9Sstevel@tonic-gate
39487c478bd9Sstevel@tonic-gate default:
39497c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
39507c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
39517c478bd9Sstevel@tonic-gate }
39527c478bd9Sstevel@tonic-gate
39537c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
39547c478bd9Sstevel@tonic-gate switch (keytype) {
39557c478bd9Sstevel@tonic-gate case CKK_DSA:
39567c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39577c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_SUBPRIME(object_p), template));
39587c478bd9Sstevel@tonic-gate
39597c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
39607c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39617c478bd9Sstevel@tonic-gate OBJ_PUB_DH942_SUBPRIME(object_p), template));
39627c478bd9Sstevel@tonic-gate
39637c478bd9Sstevel@tonic-gate default:
39647c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
39657c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
39667c478bd9Sstevel@tonic-gate }
39677c478bd9Sstevel@tonic-gate
39687c478bd9Sstevel@tonic-gate case CKA_BASE:
39697c478bd9Sstevel@tonic-gate switch (keytype) {
39707c478bd9Sstevel@tonic-gate case CKK_DSA:
39717c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39727c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_BASE(object_p), template));
39737c478bd9Sstevel@tonic-gate
39747c478bd9Sstevel@tonic-gate case CKK_DH:
39757c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39767c478bd9Sstevel@tonic-gate OBJ_PUB_DH_BASE(object_p), template));
39777c478bd9Sstevel@tonic-gate
39787c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
39797c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39807c478bd9Sstevel@tonic-gate OBJ_PUB_DH942_BASE(object_p), template));
39817c478bd9Sstevel@tonic-gate
39827c478bd9Sstevel@tonic-gate default:
39837c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
39847c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
39857c478bd9Sstevel@tonic-gate }
39867c478bd9Sstevel@tonic-gate
3987034448feSmcpowers case CKA_EC_POINT:
3988f9fbec18Smcpowers return (get_bigint_attr_from_object(
3989f9fbec18Smcpowers OBJ_PUB_EC_POINT(object_p), template));
3990034448feSmcpowers
39917c478bd9Sstevel@tonic-gate case CKA_VALUE:
39927c478bd9Sstevel@tonic-gate switch (keytype) {
39937c478bd9Sstevel@tonic-gate case CKK_DSA:
39947c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39957c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_VALUE(object_p), template));
39967c478bd9Sstevel@tonic-gate
39977c478bd9Sstevel@tonic-gate case CKK_DH:
39987c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
39997c478bd9Sstevel@tonic-gate OBJ_PUB_DH_VALUE(object_p), template));
40007c478bd9Sstevel@tonic-gate
40017c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
40027c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
40037c478bd9Sstevel@tonic-gate OBJ_PUB_DH942_VALUE(object_p), template));
40047c478bd9Sstevel@tonic-gate
40057c478bd9Sstevel@tonic-gate default:
40067c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
40077c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
40087c478bd9Sstevel@tonic-gate }
40097c478bd9Sstevel@tonic-gate
40107c478bd9Sstevel@tonic-gate default:
40117c478bd9Sstevel@tonic-gate /*
40127c478bd9Sstevel@tonic-gate * First, get the value of the request attribute defined
40137c478bd9Sstevel@tonic-gate * in the list of common key attributes. If the request
40147c478bd9Sstevel@tonic-gate * attribute is not found in that list, then get the
40157c478bd9Sstevel@tonic-gate * attribute from the list of common attributes.
40167c478bd9Sstevel@tonic-gate */
40177c478bd9Sstevel@tonic-gate rv = soft_get_common_key_attrs(object_p, template);
40187c478bd9Sstevel@tonic-gate if (rv == CKR_ATTRIBUTE_TYPE_INVALID) {
40197c478bd9Sstevel@tonic-gate rv = soft_get_common_attrs(object_p, template,
40207c478bd9Sstevel@tonic-gate object_p->object_type);
40217c478bd9Sstevel@tonic-gate }
40227c478bd9Sstevel@tonic-gate break;
40237c478bd9Sstevel@tonic-gate }
40247c478bd9Sstevel@tonic-gate
40257c478bd9Sstevel@tonic-gate return (rv);
40267c478bd9Sstevel@tonic-gate }
40277c478bd9Sstevel@tonic-gate
40287c478bd9Sstevel@tonic-gate
40297c478bd9Sstevel@tonic-gate /*
40307c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Private Key Object.
40317c478bd9Sstevel@tonic-gate *
40327c478bd9Sstevel@tonic-gate * Rule: All the attributes in the private key object can be revealed
40337c478bd9Sstevel@tonic-gate * except those marked with footnote number "7" when the object
40347c478bd9Sstevel@tonic-gate * has its CKA_SENSITIVE attribute set to TRUE or its
40357c478bd9Sstevel@tonic-gate * CKA_EXTRACTABLE attribute set to FALSE (p.88 in PKCS11 spec.).
40367c478bd9Sstevel@tonic-gate */
40377c478bd9Sstevel@tonic-gate CK_RV
40387c478bd9Sstevel@tonic-gate soft_get_private_key_attribute(soft_object_t *object_p,
40397c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
40407c478bd9Sstevel@tonic-gate {
40417c478bd9Sstevel@tonic-gate
40427c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
40437c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
40447c478bd9Sstevel@tonic-gate
40457c478bd9Sstevel@tonic-gate
40467c478bd9Sstevel@tonic-gate /*
40477c478bd9Sstevel@tonic-gate * If the following specified attributes for the private key
40487c478bd9Sstevel@tonic-gate * object cannot be revealed because the object is sensitive
40497c478bd9Sstevel@tonic-gate * or unextractable, then the ulValueLen is set to -1.
40507c478bd9Sstevel@tonic-gate */
40517c478bd9Sstevel@tonic-gate if ((object_p->bool_attr_mask & SENSITIVE_BOOL_ON) ||
40527c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) {
40537c478bd9Sstevel@tonic-gate
40547c478bd9Sstevel@tonic-gate switch (template->type) {
40557c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT:
40567c478bd9Sstevel@tonic-gate case CKA_PRIME_1:
40577c478bd9Sstevel@tonic-gate case CKA_PRIME_2:
40587c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1:
40597c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2:
40607c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT:
40617c478bd9Sstevel@tonic-gate case CKA_VALUE:
40627c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
40637c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_SENSITIVE);
40647c478bd9Sstevel@tonic-gate }
40657c478bd9Sstevel@tonic-gate }
40667c478bd9Sstevel@tonic-gate
40677c478bd9Sstevel@tonic-gate switch (template->type) {
40687c478bd9Sstevel@tonic-gate
40697c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
4070f9fbec18Smcpowers case CKA_EC_PARAMS:
40717c478bd9Sstevel@tonic-gate /*
40727c478bd9Sstevel@tonic-gate * The above extra attributes have byte array type.
40737c478bd9Sstevel@tonic-gate */
40747c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p,
40757c478bd9Sstevel@tonic-gate template));
40767c478bd9Sstevel@tonic-gate
40777c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
40787c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
40797c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
40807c478bd9Sstevel@tonic-gate SENSITIVE_BOOL_ON, template));
40817c478bd9Sstevel@tonic-gate
40827c478bd9Sstevel@tonic-gate case CKA_SECONDARY_AUTH:
40837c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
40847c478bd9Sstevel@tonic-gate SECONDARY_AUTH_BOOL_ON, template));
40857c478bd9Sstevel@tonic-gate
40867c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
40877c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
40887c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template));
40897c478bd9Sstevel@tonic-gate
40907c478bd9Sstevel@tonic-gate case CKA_SIGN:
40917c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
40927c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template));
40937c478bd9Sstevel@tonic-gate
40947c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER:
40957c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
40967c478bd9Sstevel@tonic-gate SIGN_RECOVER_BOOL_ON, template));
40977c478bd9Sstevel@tonic-gate
40987c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
40997c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
41007c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template));
41017c478bd9Sstevel@tonic-gate
41027c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
41037c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
41047c478bd9Sstevel@tonic-gate EXTRACTABLE_BOOL_ON, template));
41057c478bd9Sstevel@tonic-gate
41067c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE:
41077c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
41087c478bd9Sstevel@tonic-gate ALWAYS_SENSITIVE_BOOL_ON, template));
41097c478bd9Sstevel@tonic-gate
41107c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE:
41117c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
41127c478bd9Sstevel@tonic-gate NEVER_EXTRACTABLE_BOOL_ON, template));
41137c478bd9Sstevel@tonic-gate
41147c478bd9Sstevel@tonic-gate case CKA_MODULUS:
41157c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41167c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41177c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_MOD(object_p), template));
41187c478bd9Sstevel@tonic-gate } else {
41197c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41207c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41217c478bd9Sstevel@tonic-gate break;
41227c478bd9Sstevel@tonic-gate }
41237c478bd9Sstevel@tonic-gate
41247c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
41257c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41267c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41277c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PUBEXPO(object_p), template));
41287c478bd9Sstevel@tonic-gate } else {
41297c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41307c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41317c478bd9Sstevel@tonic-gate break;
41327c478bd9Sstevel@tonic-gate }
41337c478bd9Sstevel@tonic-gate
41347c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT:
41357c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41367c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41377c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PRIEXPO(object_p), template));
41387c478bd9Sstevel@tonic-gate } else {
41397c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41407c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41417c478bd9Sstevel@tonic-gate break;
41427c478bd9Sstevel@tonic-gate }
41437c478bd9Sstevel@tonic-gate
41447c478bd9Sstevel@tonic-gate case CKA_PRIME_1:
41457c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41467c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41477c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PRIME1(object_p), template));
41487c478bd9Sstevel@tonic-gate } else {
41497c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41507c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41517c478bd9Sstevel@tonic-gate break;
41527c478bd9Sstevel@tonic-gate }
41537c478bd9Sstevel@tonic-gate
41547c478bd9Sstevel@tonic-gate case CKA_PRIME_2:
41557c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41567c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41577c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PRIME2(object_p), template));
41587c478bd9Sstevel@tonic-gate } else {
41597c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41607c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41617c478bd9Sstevel@tonic-gate break;
41627c478bd9Sstevel@tonic-gate }
41637c478bd9Sstevel@tonic-gate
41647c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1:
41657c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41667c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41677c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_EXPO1(object_p), template));
41687c478bd9Sstevel@tonic-gate } else {
41697c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41707c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41717c478bd9Sstevel@tonic-gate break;
41727c478bd9Sstevel@tonic-gate }
41737c478bd9Sstevel@tonic-gate
41747c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2:
41757c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41767c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41777c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_EXPO2(object_p), template));
41787c478bd9Sstevel@tonic-gate } else {
41797c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41807c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41817c478bd9Sstevel@tonic-gate break;
41827c478bd9Sstevel@tonic-gate }
41837c478bd9Sstevel@tonic-gate
41847c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT:
41857c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
41867c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
41877c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_COEF(object_p), template));
41887c478bd9Sstevel@tonic-gate } else {
41897c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
41907c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
41917c478bd9Sstevel@tonic-gate break;
41927c478bd9Sstevel@tonic-gate }
41937c478bd9Sstevel@tonic-gate
41947c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS:
41957c478bd9Sstevel@tonic-gate if (keytype == CKK_DH) {
41967c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
41977c478bd9Sstevel@tonic-gate OBJ_PRI_DH_VAL_BITS(object_p), template));
41987c478bd9Sstevel@tonic-gate } else {
41997c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
42007c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
42017c478bd9Sstevel@tonic-gate break;
42027c478bd9Sstevel@tonic-gate }
42037c478bd9Sstevel@tonic-gate
42047c478bd9Sstevel@tonic-gate case CKA_PRIME:
42057c478bd9Sstevel@tonic-gate switch (keytype) {
42067c478bd9Sstevel@tonic-gate case CKK_DSA:
42077c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42087c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_PRIME(object_p), template));
42097c478bd9Sstevel@tonic-gate
42107c478bd9Sstevel@tonic-gate case CKK_DH:
42117c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42127c478bd9Sstevel@tonic-gate OBJ_PRI_DH_PRIME(object_p), template));
42137c478bd9Sstevel@tonic-gate
42147c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
42157c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42167c478bd9Sstevel@tonic-gate OBJ_PRI_DH942_PRIME(object_p), template));
42177c478bd9Sstevel@tonic-gate
42187c478bd9Sstevel@tonic-gate default:
42197c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
42207c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
42217c478bd9Sstevel@tonic-gate }
42227c478bd9Sstevel@tonic-gate
42237c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
42247c478bd9Sstevel@tonic-gate switch (keytype) {
42257c478bd9Sstevel@tonic-gate case CKK_DSA:
42267c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42277c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_SUBPRIME(object_p), template));
42287c478bd9Sstevel@tonic-gate
42297c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
42307c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42317c478bd9Sstevel@tonic-gate OBJ_PRI_DH942_SUBPRIME(object_p), template));
42327c478bd9Sstevel@tonic-gate
42337c478bd9Sstevel@tonic-gate default:
42347c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
42357c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
42367c478bd9Sstevel@tonic-gate }
42377c478bd9Sstevel@tonic-gate
42387c478bd9Sstevel@tonic-gate case CKA_BASE:
42397c478bd9Sstevel@tonic-gate switch (keytype) {
42407c478bd9Sstevel@tonic-gate case CKK_DSA:
42417c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42427c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_BASE(object_p), template));
42437c478bd9Sstevel@tonic-gate
42447c478bd9Sstevel@tonic-gate case CKK_DH:
42457c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42467c478bd9Sstevel@tonic-gate OBJ_PRI_DH_BASE(object_p), template));
42477c478bd9Sstevel@tonic-gate
42487c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
42497c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42507c478bd9Sstevel@tonic-gate OBJ_PRI_DH942_BASE(object_p), template));
42517c478bd9Sstevel@tonic-gate
42527c478bd9Sstevel@tonic-gate default:
42537c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
42547c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
42557c478bd9Sstevel@tonic-gate }
42567c478bd9Sstevel@tonic-gate
42577c478bd9Sstevel@tonic-gate case CKA_VALUE:
42587c478bd9Sstevel@tonic-gate switch (keytype) {
42597c478bd9Sstevel@tonic-gate case CKK_DSA:
42607c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42617c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_VALUE(object_p), template));
42627c478bd9Sstevel@tonic-gate
42637c478bd9Sstevel@tonic-gate case CKK_DH:
42647c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42657c478bd9Sstevel@tonic-gate OBJ_PRI_DH_VALUE(object_p), template));
42667c478bd9Sstevel@tonic-gate
42677c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
42687c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
42697c478bd9Sstevel@tonic-gate OBJ_PRI_DH942_VALUE(object_p), template));
42707c478bd9Sstevel@tonic-gate
4271034448feSmcpowers case CKK_EC:
4272034448feSmcpowers return (get_bigint_attr_from_object(
4273034448feSmcpowers OBJ_PRI_EC_VALUE(object_p), template));
4274034448feSmcpowers
42757c478bd9Sstevel@tonic-gate default:
42767c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
42777c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
42787c478bd9Sstevel@tonic-gate }
42797c478bd9Sstevel@tonic-gate
42807c478bd9Sstevel@tonic-gate default:
42817c478bd9Sstevel@tonic-gate /*
42827c478bd9Sstevel@tonic-gate * First, get the value of the request attribute defined
42837c478bd9Sstevel@tonic-gate * in the list of common key attributes. If the request
42847c478bd9Sstevel@tonic-gate * attribute is not found in that list, then get the
42857c478bd9Sstevel@tonic-gate * attribute from the list of common attributes.
42867c478bd9Sstevel@tonic-gate */
42877c478bd9Sstevel@tonic-gate rv = soft_get_common_key_attrs(object_p, template);
42887c478bd9Sstevel@tonic-gate if (rv == CKR_ATTRIBUTE_TYPE_INVALID) {
42897c478bd9Sstevel@tonic-gate rv = soft_get_common_attrs(object_p, template,
42907c478bd9Sstevel@tonic-gate object_p->object_type);
42917c478bd9Sstevel@tonic-gate }
42927c478bd9Sstevel@tonic-gate break;
42937c478bd9Sstevel@tonic-gate }
42947c478bd9Sstevel@tonic-gate
42957c478bd9Sstevel@tonic-gate return (rv);
42967c478bd9Sstevel@tonic-gate }
42977c478bd9Sstevel@tonic-gate
42987c478bd9Sstevel@tonic-gate
42997c478bd9Sstevel@tonic-gate /*
43007c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Secret Key Object.
43017c478bd9Sstevel@tonic-gate *
43027c478bd9Sstevel@tonic-gate * Rule: All the attributes in the secret key object can be revealed
43037c478bd9Sstevel@tonic-gate * except those marked with footnote number "7" when the object
43047c478bd9Sstevel@tonic-gate * has its CKA_SENSITIVE attribute set to TRUE or its
43057c478bd9Sstevel@tonic-gate * CKA_EXTRACTABLE attribute set to FALSE (p.88 in PKCS11 spec.).
43067c478bd9Sstevel@tonic-gate */
43077c478bd9Sstevel@tonic-gate CK_RV
43087c478bd9Sstevel@tonic-gate soft_get_secret_key_attribute(soft_object_t *object_p,
43097c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
43107c478bd9Sstevel@tonic-gate {
43117c478bd9Sstevel@tonic-gate
43127c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
43137c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
43147c478bd9Sstevel@tonic-gate
43157c478bd9Sstevel@tonic-gate switch (template->type) {
43167c478bd9Sstevel@tonic-gate
43177c478bd9Sstevel@tonic-gate /* Key related boolean attributes */
43187c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
43197c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43207c478bd9Sstevel@tonic-gate SENSITIVE_BOOL_ON, template));
43217c478bd9Sstevel@tonic-gate
43227c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
43237c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43247c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template));
43257c478bd9Sstevel@tonic-gate
43267c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
43277c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43287c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template));
43297c478bd9Sstevel@tonic-gate
43307c478bd9Sstevel@tonic-gate case CKA_SIGN:
43317c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43327c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template));
43337c478bd9Sstevel@tonic-gate
43347c478bd9Sstevel@tonic-gate case CKA_VERIFY:
43357c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43367c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template));
43377c478bd9Sstevel@tonic-gate
43387c478bd9Sstevel@tonic-gate case CKA_WRAP:
43397c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43407c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template));
43417c478bd9Sstevel@tonic-gate
43427c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
43437c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43447c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template));
43457c478bd9Sstevel@tonic-gate
43467c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
43477c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43487c478bd9Sstevel@tonic-gate EXTRACTABLE_BOOL_ON, template));
43497c478bd9Sstevel@tonic-gate
43507c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE:
43517c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43527c478bd9Sstevel@tonic-gate ALWAYS_SENSITIVE_BOOL_ON, template));
43537c478bd9Sstevel@tonic-gate
43547c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE:
43557c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
43567c478bd9Sstevel@tonic-gate NEVER_EXTRACTABLE_BOOL_ON, template));
43577c478bd9Sstevel@tonic-gate
43587c478bd9Sstevel@tonic-gate case CKA_VALUE:
43597c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN:
43607c478bd9Sstevel@tonic-gate /*
43617c478bd9Sstevel@tonic-gate * If the specified attribute for the secret key object
43627c478bd9Sstevel@tonic-gate * cannot be revealed because the object is sensitive
43637c478bd9Sstevel@tonic-gate * or unextractable, then the ulValueLen is set to -1.
43647c478bd9Sstevel@tonic-gate */
43657c478bd9Sstevel@tonic-gate if ((object_p->bool_attr_mask & SENSITIVE_BOOL_ON) ||
43667c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) {
43677c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
43687c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_SENSITIVE);
43697c478bd9Sstevel@tonic-gate }
43707c478bd9Sstevel@tonic-gate
43717c478bd9Sstevel@tonic-gate switch (keytype) {
43727c478bd9Sstevel@tonic-gate case CKK_RC4:
43737c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET:
43747c478bd9Sstevel@tonic-gate case CKK_RC5:
43757c478bd9Sstevel@tonic-gate case CKK_DES:
43767c478bd9Sstevel@tonic-gate case CKK_DES2:
43777c478bd9Sstevel@tonic-gate case CKK_DES3:
43787c478bd9Sstevel@tonic-gate case CKK_CDMF:
43797c478bd9Sstevel@tonic-gate case CKK_AES:
4380f66d273dSizick case CKK_BLOWFISH:
43817c478bd9Sstevel@tonic-gate if (template->type == CKA_VALUE_LEN) {
43827c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
43837c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p),
43847c478bd9Sstevel@tonic-gate template));
43857c478bd9Sstevel@tonic-gate } else {
43867c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
43877c478bd9Sstevel@tonic-gate (biginteger_t *)OBJ_SEC(object_p),
43887c478bd9Sstevel@tonic-gate template));
43897c478bd9Sstevel@tonic-gate }
43907c478bd9Sstevel@tonic-gate default:
43917c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
43927c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID;
43937c478bd9Sstevel@tonic-gate break;
43947c478bd9Sstevel@tonic-gate }
43957c478bd9Sstevel@tonic-gate break;
43967c478bd9Sstevel@tonic-gate
43977c478bd9Sstevel@tonic-gate default:
43987c478bd9Sstevel@tonic-gate /*
43997c478bd9Sstevel@tonic-gate * First, get the value of the request attribute defined
44007c478bd9Sstevel@tonic-gate * in the list of common key attributes. If the request
44017c478bd9Sstevel@tonic-gate * attribute is not found in that list, then get the
44027c478bd9Sstevel@tonic-gate * attribute from the list of common attributes.
44037c478bd9Sstevel@tonic-gate */
44047c478bd9Sstevel@tonic-gate rv = soft_get_common_key_attrs(object_p, template);
44057c478bd9Sstevel@tonic-gate if (rv == CKR_ATTRIBUTE_TYPE_INVALID) {
44067c478bd9Sstevel@tonic-gate rv = soft_get_common_attrs(object_p, template,
44077c478bd9Sstevel@tonic-gate object_p->object_type);
44087c478bd9Sstevel@tonic-gate }
44097c478bd9Sstevel@tonic-gate break;
44107c478bd9Sstevel@tonic-gate }
44117c478bd9Sstevel@tonic-gate
44127c478bd9Sstevel@tonic-gate return (rv);
44137c478bd9Sstevel@tonic-gate }
44147c478bd9Sstevel@tonic-gate
44157c478bd9Sstevel@tonic-gate
44167c478bd9Sstevel@tonic-gate /*
44177c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Domain Parameters Object.
44187c478bd9Sstevel@tonic-gate *
44197c478bd9Sstevel@tonic-gate * Rule: All the attributes in the domain parameters object can be revealed.
44207c478bd9Sstevel@tonic-gate */
44217c478bd9Sstevel@tonic-gate CK_RV
44227c478bd9Sstevel@tonic-gate soft_get_domain_parameters_attribute(soft_object_t *object_p,
44237c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
44247c478bd9Sstevel@tonic-gate {
44257c478bd9Sstevel@tonic-gate
44267c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
44277c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
44287c478bd9Sstevel@tonic-gate
44297c478bd9Sstevel@tonic-gate switch (template->type) {
44307c478bd9Sstevel@tonic-gate
44317c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
44327c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(keytype,
44337c478bd9Sstevel@tonic-gate template));
44347c478bd9Sstevel@tonic-gate
44357c478bd9Sstevel@tonic-gate case CKA_LOCAL:
44367c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
44377c478bd9Sstevel@tonic-gate LOCAL_BOOL_ON, template));
44387c478bd9Sstevel@tonic-gate
44397c478bd9Sstevel@tonic-gate case CKA_PRIME:
44407c478bd9Sstevel@tonic-gate switch (keytype) {
44417c478bd9Sstevel@tonic-gate case CKK_DSA:
44427c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44437c478bd9Sstevel@tonic-gate OBJ_DOM_DSA_PRIME(object_p), template));
44447c478bd9Sstevel@tonic-gate
44457c478bd9Sstevel@tonic-gate case CKK_DH:
44467c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44477c478bd9Sstevel@tonic-gate OBJ_DOM_DH_PRIME(object_p), template));
44487c478bd9Sstevel@tonic-gate
44497c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
44507c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44517c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_PRIME(object_p), template));
44527c478bd9Sstevel@tonic-gate
44537c478bd9Sstevel@tonic-gate default:
44547c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
44557c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
44567c478bd9Sstevel@tonic-gate }
44577c478bd9Sstevel@tonic-gate
44587c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
44597c478bd9Sstevel@tonic-gate switch (keytype) {
44607c478bd9Sstevel@tonic-gate case CKK_DSA:
44617c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44627c478bd9Sstevel@tonic-gate OBJ_DOM_DSA_SUBPRIME(object_p), template));
44637c478bd9Sstevel@tonic-gate
44647c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
44657c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44667c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_SUBPRIME(object_p), template));
44677c478bd9Sstevel@tonic-gate
44687c478bd9Sstevel@tonic-gate default:
44697c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
44707c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
44717c478bd9Sstevel@tonic-gate }
44727c478bd9Sstevel@tonic-gate
44737c478bd9Sstevel@tonic-gate case CKA_BASE:
44747c478bd9Sstevel@tonic-gate switch (keytype) {
44757c478bd9Sstevel@tonic-gate case CKK_DSA:
44767c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44777c478bd9Sstevel@tonic-gate OBJ_DOM_DSA_BASE(object_p), template));
44787c478bd9Sstevel@tonic-gate
44797c478bd9Sstevel@tonic-gate case CKK_DH:
44807c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44817c478bd9Sstevel@tonic-gate OBJ_DOM_DH_BASE(object_p), template));
44827c478bd9Sstevel@tonic-gate
44837c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
44847c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object(
44857c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_BASE(object_p), template));
44867c478bd9Sstevel@tonic-gate
44877c478bd9Sstevel@tonic-gate default:
44887c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
44897c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
44907c478bd9Sstevel@tonic-gate }
44917c478bd9Sstevel@tonic-gate
44927c478bd9Sstevel@tonic-gate case CKA_PRIME_BITS:
44937c478bd9Sstevel@tonic-gate switch (keytype) {
44947c478bd9Sstevel@tonic-gate case CKK_DSA:
44957c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
44967c478bd9Sstevel@tonic-gate OBJ_DOM_DSA_PRIME_BITS(object_p), template));
44977c478bd9Sstevel@tonic-gate
44987c478bd9Sstevel@tonic-gate case CKK_DH:
44997c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
45007c478bd9Sstevel@tonic-gate OBJ_DOM_DH_PRIME_BITS(object_p), template));
45017c478bd9Sstevel@tonic-gate
45027c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
45037c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
45047c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_PRIME_BITS(object_p), template));
45057c478bd9Sstevel@tonic-gate
45067c478bd9Sstevel@tonic-gate default:
45077c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
45087c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
45097c478bd9Sstevel@tonic-gate }
45107c478bd9Sstevel@tonic-gate
45117c478bd9Sstevel@tonic-gate case CKA_SUB_PRIME_BITS:
45127c478bd9Sstevel@tonic-gate switch (keytype) {
45137c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
45147c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(
45157c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_SUBPRIME_BITS(object_p), template));
45167c478bd9Sstevel@tonic-gate
45177c478bd9Sstevel@tonic-gate default:
45187c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
45197c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
45207c478bd9Sstevel@tonic-gate }
45217c478bd9Sstevel@tonic-gate
45227c478bd9Sstevel@tonic-gate default:
45237c478bd9Sstevel@tonic-gate /*
45247c478bd9Sstevel@tonic-gate * Get the value of a common attribute.
45257c478bd9Sstevel@tonic-gate */
45267c478bd9Sstevel@tonic-gate rv = soft_get_common_attrs(object_p, template,
45277c478bd9Sstevel@tonic-gate object_p->object_type);
45287c478bd9Sstevel@tonic-gate break;
45297c478bd9Sstevel@tonic-gate }
45307c478bd9Sstevel@tonic-gate
45317c478bd9Sstevel@tonic-gate return (rv);
45327c478bd9Sstevel@tonic-gate }
45337c478bd9Sstevel@tonic-gate
45347c478bd9Sstevel@tonic-gate /*
45357c478bd9Sstevel@tonic-gate * Get certificate attributes from an object.
45367c478bd9Sstevel@tonic-gate * return CKR_ATTRIBUTE_TYPE_INVALID if the requested type
45377c478bd9Sstevel@tonic-gate * does not exist in the certificate.
45387c478bd9Sstevel@tonic-gate */
45397c478bd9Sstevel@tonic-gate CK_RV
45407c478bd9Sstevel@tonic-gate soft_get_certificate_attribute(soft_object_t *object_p,
45417c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template)
45427c478bd9Sstevel@tonic-gate {
45437c478bd9Sstevel@tonic-gate CK_CERTIFICATE_TYPE certtype = object_p->cert_type;
45447c478bd9Sstevel@tonic-gate cert_attr_t src;
45457c478bd9Sstevel@tonic-gate
45467c478bd9Sstevel@tonic-gate switch (template->type) {
45477c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
45487c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509) {
45497c478bd9Sstevel@tonic-gate return (get_cert_attr_from_object(
45507c478bd9Sstevel@tonic-gate X509_CERT_SUBJECT(object_p), template));
45517c478bd9Sstevel@tonic-gate }
45527c478bd9Sstevel@tonic-gate break;
45537c478bd9Sstevel@tonic-gate case CKA_VALUE:
45547c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509) {
45557c478bd9Sstevel@tonic-gate return (get_cert_attr_from_object(
45567c478bd9Sstevel@tonic-gate X509_CERT_VALUE(object_p), template));
45577c478bd9Sstevel@tonic-gate } else if (certtype == CKC_X_509_ATTR_CERT) {
45587c478bd9Sstevel@tonic-gate return (get_cert_attr_from_object(
4559f9fbec18Smcpowers X509_ATTR_CERT_VALUE(object_p), template));
45607c478bd9Sstevel@tonic-gate }
45617c478bd9Sstevel@tonic-gate break;
45627c478bd9Sstevel@tonic-gate case CKA_OWNER:
45637c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509_ATTR_CERT) {
45647c478bd9Sstevel@tonic-gate return (get_cert_attr_from_object(
4565f9fbec18Smcpowers X509_ATTR_CERT_OWNER(object_p), template));
45667c478bd9Sstevel@tonic-gate }
45677c478bd9Sstevel@tonic-gate break;
45687c478bd9Sstevel@tonic-gate case CKA_CERTIFICATE_TYPE:
45697c478bd9Sstevel@tonic-gate src.value = (CK_BYTE *)&certtype;
45707c478bd9Sstevel@tonic-gate src.length = sizeof (certtype);
45717c478bd9Sstevel@tonic-gate return (get_cert_attr_from_object(&src, template));
45727c478bd9Sstevel@tonic-gate case CKA_TRUSTED:
45737c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p,
45747c478bd9Sstevel@tonic-gate TRUSTED_BOOL_ON, template));
45757c478bd9Sstevel@tonic-gate case CKA_ID:
45767c478bd9Sstevel@tonic-gate case CKA_ISSUER:
45777c478bd9Sstevel@tonic-gate case CKA_SERIAL_NUMBER:
45787c478bd9Sstevel@tonic-gate case CKA_AC_ISSUER:
45797c478bd9Sstevel@tonic-gate case CKA_ATTR_TYPES:
45807c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p,
45817c478bd9Sstevel@tonic-gate template));
45827c478bd9Sstevel@tonic-gate default:
45837c478bd9Sstevel@tonic-gate return (soft_get_common_attrs(object_p, template,
45847c478bd9Sstevel@tonic-gate object_p->object_type));
45857c478bd9Sstevel@tonic-gate }
45867c478bd9Sstevel@tonic-gate
45877c478bd9Sstevel@tonic-gate /*
45887c478bd9Sstevel@tonic-gate * If we got this far, then the combination of certificate type
45897c478bd9Sstevel@tonic-gate * and requested attribute is invalid.
45907c478bd9Sstevel@tonic-gate */
45917c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
45927c478bd9Sstevel@tonic-gate }
45937c478bd9Sstevel@tonic-gate
45947c478bd9Sstevel@tonic-gate CK_RV
45957c478bd9Sstevel@tonic-gate soft_set_certificate_attribute(soft_object_t *object_p,
45967c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy)
45977c478bd9Sstevel@tonic-gate {
45987c478bd9Sstevel@tonic-gate CK_CERTIFICATE_TYPE certtype = object_p->cert_type;
45997c478bd9Sstevel@tonic-gate
46007c478bd9Sstevel@tonic-gate switch (template->type) {
46017c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
46027c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509) {
46037c478bd9Sstevel@tonic-gate /* SUBJECT attr cannot be modified. */
46047c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
46057c478bd9Sstevel@tonic-gate }
46067c478bd9Sstevel@tonic-gate break;
46077c478bd9Sstevel@tonic-gate case CKA_OWNER:
46087c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509_ATTR_CERT) {
46097c478bd9Sstevel@tonic-gate /* OWNER attr cannot be modified. */
46107c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
46117c478bd9Sstevel@tonic-gate }
46127c478bd9Sstevel@tonic-gate break;
46137c478bd9Sstevel@tonic-gate case CKA_VALUE:
46147c478bd9Sstevel@tonic-gate /* VALUE attr cannot be modified. */
46157c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
46167c478bd9Sstevel@tonic-gate case CKA_ID:
46177c478bd9Sstevel@tonic-gate case CKA_ISSUER:
46187c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509) {
46197c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
46207c478bd9Sstevel@tonic-gate template->type, template));
46217c478bd9Sstevel@tonic-gate }
46227c478bd9Sstevel@tonic-gate break;
46237c478bd9Sstevel@tonic-gate case CKA_AC_ISSUER:
46247c478bd9Sstevel@tonic-gate case CKA_ATTR_TYPES:
46257c478bd9Sstevel@tonic-gate if (certtype == CKC_X_509_ATTR_CERT) {
46267c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
46277c478bd9Sstevel@tonic-gate template->type, template));
46287c478bd9Sstevel@tonic-gate }
46297c478bd9Sstevel@tonic-gate break;
46307c478bd9Sstevel@tonic-gate case CKA_SERIAL_NUMBER:
46317c478bd9Sstevel@tonic-gate case CKA_LABEL:
46327c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
46337c478bd9Sstevel@tonic-gate template->type, template));
46347c478bd9Sstevel@tonic-gate default:
46357c478bd9Sstevel@tonic-gate return (soft_set_common_storage_attribute(
46367c478bd9Sstevel@tonic-gate object_p, template, copy));
46377c478bd9Sstevel@tonic-gate }
46387c478bd9Sstevel@tonic-gate
46397c478bd9Sstevel@tonic-gate /*
46407c478bd9Sstevel@tonic-gate * If we got this far, then the combination of certificate type
46417c478bd9Sstevel@tonic-gate * and requested attribute is invalid.
46427c478bd9Sstevel@tonic-gate */
46437c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
46447c478bd9Sstevel@tonic-gate }
46457c478bd9Sstevel@tonic-gate
46467c478bd9Sstevel@tonic-gate /*
46477c478bd9Sstevel@tonic-gate * Call the appropriate get attribute function according to the class
46487c478bd9Sstevel@tonic-gate * of object.
46497c478bd9Sstevel@tonic-gate *
46507c478bd9Sstevel@tonic-gate * The caller of this function holds the lock on the object.
46517c478bd9Sstevel@tonic-gate */
46527c478bd9Sstevel@tonic-gate CK_RV
46537c478bd9Sstevel@tonic-gate soft_get_attribute(soft_object_t *object_p, CK_ATTRIBUTE_PTR template)
46547c478bd9Sstevel@tonic-gate {
46557c478bd9Sstevel@tonic-gate
46567c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
46577c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = object_p->class;
46587c478bd9Sstevel@tonic-gate
46597c478bd9Sstevel@tonic-gate switch (class) {
46607c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY:
46617c478bd9Sstevel@tonic-gate rv = soft_get_public_key_attribute(object_p, template);
46627c478bd9Sstevel@tonic-gate break;
46637c478bd9Sstevel@tonic-gate
46647c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY:
46657c478bd9Sstevel@tonic-gate rv = soft_get_private_key_attribute(object_p, template);
46667c478bd9Sstevel@tonic-gate break;
46677c478bd9Sstevel@tonic-gate
46687c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY:
46697c478bd9Sstevel@tonic-gate rv = soft_get_secret_key_attribute(object_p, template);
46707c478bd9Sstevel@tonic-gate break;
46717c478bd9Sstevel@tonic-gate
46727c478bd9Sstevel@tonic-gate case CKO_DOMAIN_PARAMETERS:
46737c478bd9Sstevel@tonic-gate rv = soft_get_domain_parameters_attribute(object_p, template);
46747c478bd9Sstevel@tonic-gate break;
46757c478bd9Sstevel@tonic-gate
46767c478bd9Sstevel@tonic-gate case CKO_CERTIFICATE:
46777c478bd9Sstevel@tonic-gate rv = soft_get_certificate_attribute(object_p, template);
46787c478bd9Sstevel@tonic-gate break;
46797c478bd9Sstevel@tonic-gate
46807c478bd9Sstevel@tonic-gate default:
46817c478bd9Sstevel@tonic-gate /*
46827c478bd9Sstevel@tonic-gate * If the specified attribute for the object is invalid
46837c478bd9Sstevel@tonic-gate * (the object does not possess such as attribute), then
46847c478bd9Sstevel@tonic-gate * the ulValueLen is modified to hold the value -1.
46857c478bd9Sstevel@tonic-gate */
46867c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1;
46877c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
46887c478bd9Sstevel@tonic-gate }
46897c478bd9Sstevel@tonic-gate
46907c478bd9Sstevel@tonic-gate return (rv);
46917c478bd9Sstevel@tonic-gate
46927c478bd9Sstevel@tonic-gate }
46937c478bd9Sstevel@tonic-gate
46947c478bd9Sstevel@tonic-gate CK_RV
46957c478bd9Sstevel@tonic-gate soft_set_common_storage_attribute(soft_object_t *object_p,
46967c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy)
46977c478bd9Sstevel@tonic-gate {
46987c478bd9Sstevel@tonic-gate
46997c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
47007c478bd9Sstevel@tonic-gate
47017c478bd9Sstevel@tonic-gate switch (template->type) {
47027c478bd9Sstevel@tonic-gate
47037c478bd9Sstevel@tonic-gate case CKA_TOKEN:
47047c478bd9Sstevel@tonic-gate if (copy) {
47057c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_TRUE) {
470690e0e8c4Sizick if (!soft_keystore_status(KEYSTORE_INITIALIZED))
47077c478bd9Sstevel@tonic-gate return (CKR_DEVICE_REMOVED);
47087c478bd9Sstevel@tonic-gate object_p->object_type |= TOKEN_OBJECT;
47097c478bd9Sstevel@tonic-gate }
47107c478bd9Sstevel@tonic-gate } else {
47117c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_READ_ONLY;
47127c478bd9Sstevel@tonic-gate }
47137c478bd9Sstevel@tonic-gate
47147c478bd9Sstevel@tonic-gate break;
47157c478bd9Sstevel@tonic-gate
47167c478bd9Sstevel@tonic-gate case CKA_PRIVATE:
47177c478bd9Sstevel@tonic-gate if (copy) {
47187c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_TRUE) {
47197c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&soft_giant_mutex);
47207c478bd9Sstevel@tonic-gate if (!soft_slot.authenticated) {
47217c478bd9Sstevel@tonic-gate /*
47227c478bd9Sstevel@tonic-gate * Check if this is the special case
47237c478bd9Sstevel@tonic-gate * when the PIN is never initialized
47247c478bd9Sstevel@tonic-gate * in the keystore. If true, we will
47257c478bd9Sstevel@tonic-gate * let it pass here and let it fail
47267c478bd9Sstevel@tonic-gate * with CKR_PIN_EXPIRED later on.
47277c478bd9Sstevel@tonic-gate */
47287c478bd9Sstevel@tonic-gate if (!soft_slot.userpin_change_needed) {
47297c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(
47307c478bd9Sstevel@tonic-gate &soft_giant_mutex);
47317c478bd9Sstevel@tonic-gate return (CKR_USER_NOT_LOGGED_IN);
47327c478bd9Sstevel@tonic-gate }
47337c478bd9Sstevel@tonic-gate }
47347c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&soft_giant_mutex);
47357c478bd9Sstevel@tonic-gate object_p->object_type |= PRIVATE_OBJECT;
47367c478bd9Sstevel@tonic-gate }
47377c478bd9Sstevel@tonic-gate } else {
47387c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_READ_ONLY;
47397c478bd9Sstevel@tonic-gate }
47407c478bd9Sstevel@tonic-gate break;
47417c478bd9Sstevel@tonic-gate
47427c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
47437c478bd9Sstevel@tonic-gate if (copy) {
47447c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == TRUE)
47457c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &=
47467c478bd9Sstevel@tonic-gate ~NOT_MODIFIABLE_BOOL_ON;
47477c478bd9Sstevel@tonic-gate else
47487c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |=
47497c478bd9Sstevel@tonic-gate NOT_MODIFIABLE_BOOL_ON;
47507c478bd9Sstevel@tonic-gate } else {
47517c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_READ_ONLY;
47527c478bd9Sstevel@tonic-gate }
47537c478bd9Sstevel@tonic-gate break;
47547c478bd9Sstevel@tonic-gate
47557c478bd9Sstevel@tonic-gate case CKA_CLASS:
47567c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_READ_ONLY;
47577c478bd9Sstevel@tonic-gate break;
47587c478bd9Sstevel@tonic-gate
47597c478bd9Sstevel@tonic-gate default:
47607c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
47617c478bd9Sstevel@tonic-gate }
47627c478bd9Sstevel@tonic-gate
47637c478bd9Sstevel@tonic-gate return (rv);
47647c478bd9Sstevel@tonic-gate }
47657c478bd9Sstevel@tonic-gate
47667c478bd9Sstevel@tonic-gate /*
47677c478bd9Sstevel@tonic-gate * Set the value of an attribute that is common to all key objects
47687c478bd9Sstevel@tonic-gate * (i.e. public key, private key and secret key).
47697c478bd9Sstevel@tonic-gate */
47707c478bd9Sstevel@tonic-gate CK_RV
47717c478bd9Sstevel@tonic-gate soft_set_common_key_attribute(soft_object_t *object_p,
47727c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy)
47737c478bd9Sstevel@tonic-gate {
47747c478bd9Sstevel@tonic-gate
47757c478bd9Sstevel@tonic-gate switch (template->type) {
47767c478bd9Sstevel@tonic-gate
47777c478bd9Sstevel@tonic-gate case CKA_LABEL:
47787c478bd9Sstevel@tonic-gate /*
47797c478bd9Sstevel@tonic-gate * Only the LABEL can be modified in the common storage
47807c478bd9Sstevel@tonic-gate * object attributes after the object is created.
47817c478bd9Sstevel@tonic-gate */
47827c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
47837c478bd9Sstevel@tonic-gate CKA_LABEL, template));
47847c478bd9Sstevel@tonic-gate
47857c478bd9Sstevel@tonic-gate case CKA_ID:
47867c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
47877c478bd9Sstevel@tonic-gate CKA_ID, template));
47887c478bd9Sstevel@tonic-gate
47897c478bd9Sstevel@tonic-gate case CKA_START_DATE:
47907c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
47917c478bd9Sstevel@tonic-gate CKA_START_DATE, template));
47927c478bd9Sstevel@tonic-gate
47937c478bd9Sstevel@tonic-gate case CKA_END_DATE:
47947c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
47957c478bd9Sstevel@tonic-gate CKA_END_DATE, template));
47967c478bd9Sstevel@tonic-gate
47977c478bd9Sstevel@tonic-gate case CKA_DERIVE:
47987c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
47997c478bd9Sstevel@tonic-gate DERIVE_BOOL_ON, template));
48007c478bd9Sstevel@tonic-gate
48017c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
48027c478bd9Sstevel@tonic-gate case CKA_LOCAL:
48037c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM:
48047c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
48057c478bd9Sstevel@tonic-gate
48067c478bd9Sstevel@tonic-gate default:
48077c478bd9Sstevel@tonic-gate return (soft_set_common_storage_attribute(object_p,
48087c478bd9Sstevel@tonic-gate template, copy));
48097c478bd9Sstevel@tonic-gate
48107c478bd9Sstevel@tonic-gate }
48117c478bd9Sstevel@tonic-gate
48127c478bd9Sstevel@tonic-gate }
48137c478bd9Sstevel@tonic-gate
48147c478bd9Sstevel@tonic-gate
48157c478bd9Sstevel@tonic-gate /*
48167c478bd9Sstevel@tonic-gate * Set the value of an attribute of a Public Key Object.
48177c478bd9Sstevel@tonic-gate *
48187c478bd9Sstevel@tonic-gate * Rule: The attributes marked with footnote number "8" in the PKCS11
48197c478bd9Sstevel@tonic-gate * spec may be modified (p.88 in PKCS11 spec.).
48207c478bd9Sstevel@tonic-gate */
48217c478bd9Sstevel@tonic-gate CK_RV
48227c478bd9Sstevel@tonic-gate soft_set_public_key_attribute(soft_object_t *object_p,
48237c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy)
48247c478bd9Sstevel@tonic-gate {
48257c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
48267c478bd9Sstevel@tonic-gate
48277c478bd9Sstevel@tonic-gate switch (template->type) {
48287c478bd9Sstevel@tonic-gate
48297c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
48307c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
48317c478bd9Sstevel@tonic-gate CKA_SUBJECT, template));
48327c478bd9Sstevel@tonic-gate
48337c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
48347c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
48357c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template));
48367c478bd9Sstevel@tonic-gate
48377c478bd9Sstevel@tonic-gate case CKA_VERIFY:
48387c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
48397c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template));
48407c478bd9Sstevel@tonic-gate
48417c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER:
48427c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
48437c478bd9Sstevel@tonic-gate VERIFY_RECOVER_BOOL_ON, template));
48447c478bd9Sstevel@tonic-gate
48457c478bd9Sstevel@tonic-gate case CKA_WRAP:
48467c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
48477c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template));
48487c478bd9Sstevel@tonic-gate
48497c478bd9Sstevel@tonic-gate case CKA_MODULUS:
48507c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS:
48517c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
48527c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA)
48537c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
48547c478bd9Sstevel@tonic-gate break;
48557c478bd9Sstevel@tonic-gate
48567c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
48577c478bd9Sstevel@tonic-gate if ((keytype == CKK_DSA) ||
48587c478bd9Sstevel@tonic-gate (keytype == CKK_X9_42_DH))
48597c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
48607c478bd9Sstevel@tonic-gate break;
48617c478bd9Sstevel@tonic-gate
48627c478bd9Sstevel@tonic-gate case CKA_PRIME:
48637c478bd9Sstevel@tonic-gate case CKA_BASE:
48647c478bd9Sstevel@tonic-gate case CKA_VALUE:
48657c478bd9Sstevel@tonic-gate if ((keytype == CKK_DSA) ||
48667c478bd9Sstevel@tonic-gate (keytype == CKK_DH) ||
48677c478bd9Sstevel@tonic-gate (keytype == CKK_X9_42_DH))
48687c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
48697c478bd9Sstevel@tonic-gate break;
48707c478bd9Sstevel@tonic-gate
48717c478bd9Sstevel@tonic-gate default:
48727c478bd9Sstevel@tonic-gate /*
48737c478bd9Sstevel@tonic-gate * Set the value of a common key attribute.
48747c478bd9Sstevel@tonic-gate */
48757c478bd9Sstevel@tonic-gate return (soft_set_common_key_attribute(object_p,
48767c478bd9Sstevel@tonic-gate template, copy));
48777c478bd9Sstevel@tonic-gate
48787c478bd9Sstevel@tonic-gate }
48797c478bd9Sstevel@tonic-gate /*
48807c478bd9Sstevel@tonic-gate * If we got this far, then the combination of key type
48817c478bd9Sstevel@tonic-gate * and requested attribute is invalid.
48827c478bd9Sstevel@tonic-gate */
48837c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
48847c478bd9Sstevel@tonic-gate }
48857c478bd9Sstevel@tonic-gate
48867c478bd9Sstevel@tonic-gate
48877c478bd9Sstevel@tonic-gate /*
48887c478bd9Sstevel@tonic-gate * Set the value of an attribute of a Private Key Object.
48897c478bd9Sstevel@tonic-gate *
48907c478bd9Sstevel@tonic-gate * Rule: The attributes marked with footnote number "8" in the PKCS11
48917c478bd9Sstevel@tonic-gate * spec may be modified (p.88 in PKCS11 spec.).
48927c478bd9Sstevel@tonic-gate */
48937c478bd9Sstevel@tonic-gate CK_RV
48947c478bd9Sstevel@tonic-gate soft_set_private_key_attribute(soft_object_t *object_p,
48957c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy)
48967c478bd9Sstevel@tonic-gate {
48977c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
48987c478bd9Sstevel@tonic-gate
48997c478bd9Sstevel@tonic-gate switch (template->type) {
49007c478bd9Sstevel@tonic-gate
49017c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
49027c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
49037c478bd9Sstevel@tonic-gate CKA_SUBJECT, template));
49047c478bd9Sstevel@tonic-gate
49057c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
49067c478bd9Sstevel@tonic-gate /*
49077c478bd9Sstevel@tonic-gate * Cannot set SENSITIVE to FALSE if it is already ON.
49087c478bd9Sstevel@tonic-gate */
49097c478bd9Sstevel@tonic-gate if (((*(CK_BBOOL *)template->pValue) == B_FALSE) &&
49107c478bd9Sstevel@tonic-gate (object_p->bool_attr_mask & SENSITIVE_BOOL_ON)) {
49117c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
49127c478bd9Sstevel@tonic-gate }
49137c478bd9Sstevel@tonic-gate
49147c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template->pValue)
49157c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |= SENSITIVE_BOOL_ON;
49167c478bd9Sstevel@tonic-gate return (CKR_OK);
49177c478bd9Sstevel@tonic-gate
49187c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
49197c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
49207c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template));
49217c478bd9Sstevel@tonic-gate
49227c478bd9Sstevel@tonic-gate case CKA_SIGN:
49237c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
49247c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template));
49257c478bd9Sstevel@tonic-gate
49267c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER:
49277c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
49287c478bd9Sstevel@tonic-gate SIGN_RECOVER_BOOL_ON, template));
49297c478bd9Sstevel@tonic-gate
49307c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
49317c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
49327c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template));
49337c478bd9Sstevel@tonic-gate
49347c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
49357c478bd9Sstevel@tonic-gate /*
49367c478bd9Sstevel@tonic-gate * Cannot set EXTRACTABLE to TRUE if it is already OFF.
49377c478bd9Sstevel@tonic-gate */
49387c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) &&
49397c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) {
49407c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
49417c478bd9Sstevel@tonic-gate }
49427c478bd9Sstevel@tonic-gate
49437c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_FALSE)
49447c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &= ~EXTRACTABLE_BOOL_ON;
49457c478bd9Sstevel@tonic-gate return (CKR_OK);
49467c478bd9Sstevel@tonic-gate
49477c478bd9Sstevel@tonic-gate case CKA_MODULUS:
49487c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
49497c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT:
49507c478bd9Sstevel@tonic-gate case CKA_PRIME_1:
49517c478bd9Sstevel@tonic-gate case CKA_PRIME_2:
49527c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1:
49537c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2:
49547c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT:
49557c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) {
49567c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
49577c478bd9Sstevel@tonic-gate }
49587c478bd9Sstevel@tonic-gate break;
49597c478bd9Sstevel@tonic-gate
49607c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
49617c478bd9Sstevel@tonic-gate if ((keytype == CKK_DSA) ||
49627c478bd9Sstevel@tonic-gate (keytype == CKK_X9_42_DH))
49637c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
49647c478bd9Sstevel@tonic-gate break;
49657c478bd9Sstevel@tonic-gate
49667c478bd9Sstevel@tonic-gate case CKA_PRIME:
49677c478bd9Sstevel@tonic-gate case CKA_BASE:
49687c478bd9Sstevel@tonic-gate case CKA_VALUE:
49697c478bd9Sstevel@tonic-gate if ((keytype == CKK_DSA) ||
49707c478bd9Sstevel@tonic-gate (keytype == CKK_DH) ||
49717c478bd9Sstevel@tonic-gate (keytype == CKK_X9_42_DH))
49727c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
49737c478bd9Sstevel@tonic-gate break;
49747c478bd9Sstevel@tonic-gate
49757c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS:
49767c478bd9Sstevel@tonic-gate if (keytype == CKK_DH)
49777c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
49787c478bd9Sstevel@tonic-gate break;
49797c478bd9Sstevel@tonic-gate
49807c478bd9Sstevel@tonic-gate default:
49817c478bd9Sstevel@tonic-gate /*
49827c478bd9Sstevel@tonic-gate * Set the value of a common key attribute.
49837c478bd9Sstevel@tonic-gate */
49847c478bd9Sstevel@tonic-gate return (soft_set_common_key_attribute(object_p,
49857c478bd9Sstevel@tonic-gate template, copy));
49867c478bd9Sstevel@tonic-gate }
49877c478bd9Sstevel@tonic-gate
49887c478bd9Sstevel@tonic-gate /*
49897c478bd9Sstevel@tonic-gate * If we got this far, then the combination of key type
49907c478bd9Sstevel@tonic-gate * and requested attribute is invalid.
49917c478bd9Sstevel@tonic-gate */
49927c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
49937c478bd9Sstevel@tonic-gate }
49947c478bd9Sstevel@tonic-gate
49957c478bd9Sstevel@tonic-gate /*
49967c478bd9Sstevel@tonic-gate * Set the value of an attribute of a Secret Key Object.
49977c478bd9Sstevel@tonic-gate *
49987c478bd9Sstevel@tonic-gate * Rule: The attributes marked with footnote number "8" in the PKCS11
49997c478bd9Sstevel@tonic-gate * spec may be modified (p.88 in PKCS11 spec.).
50007c478bd9Sstevel@tonic-gate */
50017c478bd9Sstevel@tonic-gate CK_RV
50027c478bd9Sstevel@tonic-gate soft_set_secret_key_attribute(soft_object_t *object_p,
50037c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy)
50047c478bd9Sstevel@tonic-gate {
50057c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type;
50067c478bd9Sstevel@tonic-gate
50077c478bd9Sstevel@tonic-gate switch (template->type) {
50087c478bd9Sstevel@tonic-gate
50097c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
50107c478bd9Sstevel@tonic-gate /*
50117c478bd9Sstevel@tonic-gate * Cannot set SENSITIVE to FALSE if it is already ON.
50127c478bd9Sstevel@tonic-gate */
50137c478bd9Sstevel@tonic-gate if (((*(CK_BBOOL *)template->pValue) == B_FALSE) &&
50147c478bd9Sstevel@tonic-gate (object_p->bool_attr_mask & SENSITIVE_BOOL_ON)) {
50157c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
50167c478bd9Sstevel@tonic-gate }
50177c478bd9Sstevel@tonic-gate
50187c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template->pValue)
50197c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |= SENSITIVE_BOOL_ON;
50207c478bd9Sstevel@tonic-gate return (CKR_OK);
50217c478bd9Sstevel@tonic-gate
50227c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
50237c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
50247c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template));
50257c478bd9Sstevel@tonic-gate
50267c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
50277c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
50287c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template));
50297c478bd9Sstevel@tonic-gate
50307c478bd9Sstevel@tonic-gate case CKA_SIGN:
50317c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
50327c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template));
50337c478bd9Sstevel@tonic-gate
50347c478bd9Sstevel@tonic-gate case CKA_VERIFY:
50357c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
50367c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template));
50377c478bd9Sstevel@tonic-gate
50387c478bd9Sstevel@tonic-gate case CKA_WRAP:
50397c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
50407c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template));
50417c478bd9Sstevel@tonic-gate
50427c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
50437c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p,
50447c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template));
50457c478bd9Sstevel@tonic-gate
50467c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
50477c478bd9Sstevel@tonic-gate /*
50487c478bd9Sstevel@tonic-gate * Cannot set EXTRACTABLE to TRUE if it is already OFF.
50497c478bd9Sstevel@tonic-gate */
50507c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) &&
50517c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) {
50527c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
50537c478bd9Sstevel@tonic-gate }
50547c478bd9Sstevel@tonic-gate
50557c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_FALSE)
50567c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &= ~EXTRACTABLE_BOOL_ON;
50577c478bd9Sstevel@tonic-gate return (CKR_OK);
50587c478bd9Sstevel@tonic-gate
50597c478bd9Sstevel@tonic-gate case CKA_VALUE:
50607c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
50617c478bd9Sstevel@tonic-gate
50627c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN:
50637c478bd9Sstevel@tonic-gate if ((keytype == CKK_RC4) ||
50647c478bd9Sstevel@tonic-gate (keytype == CKK_GENERIC_SECRET) ||
5065f66d273dSizick (keytype == CKK_AES) ||
5066f66d273dSizick (keytype == CKK_BLOWFISH))
50677c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY);
50687c478bd9Sstevel@tonic-gate break;
50697c478bd9Sstevel@tonic-gate
50707c478bd9Sstevel@tonic-gate default:
50717c478bd9Sstevel@tonic-gate /*
50727c478bd9Sstevel@tonic-gate * Set the value of a common key attribute.
50737c478bd9Sstevel@tonic-gate */
50747c478bd9Sstevel@tonic-gate return (soft_set_common_key_attribute(object_p,
50757c478bd9Sstevel@tonic-gate template, copy));
50767c478bd9Sstevel@tonic-gate
50777c478bd9Sstevel@tonic-gate }
50787c478bd9Sstevel@tonic-gate /*
50797c478bd9Sstevel@tonic-gate * If we got this far, then the combination of key type
50807c478bd9Sstevel@tonic-gate * and requested attribute is invalid.
50817c478bd9Sstevel@tonic-gate */
50827c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID);
50837c478bd9Sstevel@tonic-gate }
50847c478bd9Sstevel@tonic-gate
50857c478bd9Sstevel@tonic-gate
50867c478bd9Sstevel@tonic-gate /*
50877c478bd9Sstevel@tonic-gate * Call the appropriate set attribute function according to the class
50887c478bd9Sstevel@tonic-gate * of object.
50897c478bd9Sstevel@tonic-gate *
50907c478bd9Sstevel@tonic-gate * The caller of this function does not hold the lock on the original
50917c478bd9Sstevel@tonic-gate * object, since this function is setting the attribute on the new object
50927c478bd9Sstevel@tonic-gate * that is being modified.
50937c478bd9Sstevel@tonic-gate *
50947c478bd9Sstevel@tonic-gate * Argument copy: TRUE when called by C_CopyObject,
50957c478bd9Sstevel@tonic-gate * FALSE when called by C_SetAttributeValue.
50967c478bd9Sstevel@tonic-gate */
50977c478bd9Sstevel@tonic-gate CK_RV
50987c478bd9Sstevel@tonic-gate soft_set_attribute(soft_object_t *object_p, CK_ATTRIBUTE_PTR template,
50997c478bd9Sstevel@tonic-gate boolean_t copy)
51007c478bd9Sstevel@tonic-gate {
51017c478bd9Sstevel@tonic-gate
51027c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
51037c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = object_p->class;
51047c478bd9Sstevel@tonic-gate
51057c478bd9Sstevel@tonic-gate switch (class) {
51067c478bd9Sstevel@tonic-gate
51077c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY:
51087c478bd9Sstevel@tonic-gate rv = soft_set_public_key_attribute(object_p, template, copy);
51097c478bd9Sstevel@tonic-gate break;
51107c478bd9Sstevel@tonic-gate
51117c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY:
51127c478bd9Sstevel@tonic-gate rv = soft_set_private_key_attribute(object_p, template, copy);
51137c478bd9Sstevel@tonic-gate break;
51147c478bd9Sstevel@tonic-gate
51157c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY:
51167c478bd9Sstevel@tonic-gate rv = soft_set_secret_key_attribute(object_p, template, copy);
51177c478bd9Sstevel@tonic-gate break;
51187c478bd9Sstevel@tonic-gate
51197c478bd9Sstevel@tonic-gate case CKO_DOMAIN_PARAMETERS:
51207c478bd9Sstevel@tonic-gate switch (template->type) {
51217c478bd9Sstevel@tonic-gate case CKA_LABEL:
51227c478bd9Sstevel@tonic-gate /*
51237c478bd9Sstevel@tonic-gate * Only the LABEL can be modified in the common
51247c478bd9Sstevel@tonic-gate * storage object attributes after the object is
51257c478bd9Sstevel@tonic-gate * created.
51267c478bd9Sstevel@tonic-gate */
51277c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p,
51287c478bd9Sstevel@tonic-gate CKA_LABEL, template));
51297c478bd9Sstevel@tonic-gate default:
51307c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCONSISTENT);
51317c478bd9Sstevel@tonic-gate }
51327c478bd9Sstevel@tonic-gate case CKO_CERTIFICATE:
51337c478bd9Sstevel@tonic-gate rv = soft_set_certificate_attribute(object_p, template, copy);
51347c478bd9Sstevel@tonic-gate break;
51357c478bd9Sstevel@tonic-gate
51367c478bd9Sstevel@tonic-gate default:
51377c478bd9Sstevel@tonic-gate /*
51387c478bd9Sstevel@tonic-gate * If the template specifies a value of an attribute
51397c478bd9Sstevel@tonic-gate * which is incompatible with other existing attributes
51407c478bd9Sstevel@tonic-gate * of the object, then fails with return code
51417c478bd9Sstevel@tonic-gate * CKR_TEMPLATE_INCONSISTENT.
51427c478bd9Sstevel@tonic-gate */
51437c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT;
51447c478bd9Sstevel@tonic-gate break;
51457c478bd9Sstevel@tonic-gate }
51467c478bd9Sstevel@tonic-gate
51477c478bd9Sstevel@tonic-gate return (rv);
51487c478bd9Sstevel@tonic-gate }
51497c478bd9Sstevel@tonic-gate
51507c478bd9Sstevel@tonic-gate CK_RV
5151c64d15a5Smcpowers soft_get_public_value(soft_object_t *key, CK_ATTRIBUTE_TYPE type,
51527c478bd9Sstevel@tonic-gate uchar_t *value, uint32_t *value_len)
51537c478bd9Sstevel@tonic-gate {
51547c478bd9Sstevel@tonic-gate uint32_t len = 0;
51557c478bd9Sstevel@tonic-gate switch (type) {
51567c478bd9Sstevel@tonic-gate
51577c478bd9Sstevel@tonic-gate /* The following attributes belong to RSA */
51587c478bd9Sstevel@tonic-gate case CKA_MODULUS:
51597c478bd9Sstevel@tonic-gate #ifdef __sparcv9
51607c478bd9Sstevel@tonic-gate len =
51617c478bd9Sstevel@tonic-gate /* LINTED */
51627c478bd9Sstevel@tonic-gate (uint32_t)
51637c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_RSA_MOD(key))->big_value_len;
51647c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
51657c478bd9Sstevel@tonic-gate len =
51667c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_RSA_MOD(key))->big_value_len;
51677c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
51687c478bd9Sstevel@tonic-gate
51697c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
51707c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
51717c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
51727c478bd9Sstevel@tonic-gate }
51737c478bd9Sstevel@tonic-gate *value_len = len;
51747c478bd9Sstevel@tonic-gate
51757c478bd9Sstevel@tonic-gate (void) memcpy(value,
51767c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_RSA_MOD(key))->big_value,
51777c478bd9Sstevel@tonic-gate *value_len);
51787c478bd9Sstevel@tonic-gate
51797c478bd9Sstevel@tonic-gate break;
51807c478bd9Sstevel@tonic-gate
51817c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
51827c478bd9Sstevel@tonic-gate #ifdef __sparcv9
51837c478bd9Sstevel@tonic-gate len =
51847c478bd9Sstevel@tonic-gate /* LINTED */
51857c478bd9Sstevel@tonic-gate (uint32_t)
51867c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_RSA_PUBEXPO(key))->big_value_len;
51877c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
51887c478bd9Sstevel@tonic-gate len =
51897c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_RSA_PUBEXPO(key))->big_value_len;
51907c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
51917c478bd9Sstevel@tonic-gate
51927c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
51937c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
51947c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
51957c478bd9Sstevel@tonic-gate }
51967c478bd9Sstevel@tonic-gate *value_len = len;
51977c478bd9Sstevel@tonic-gate
51987c478bd9Sstevel@tonic-gate (void) memcpy(value,
51997c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_RSA_PUBEXPO(key))->big_value,
52007c478bd9Sstevel@tonic-gate *value_len);
52017c478bd9Sstevel@tonic-gate
52027c478bd9Sstevel@tonic-gate break;
52037c478bd9Sstevel@tonic-gate
52047c478bd9Sstevel@tonic-gate /* The following attributes belong to DSA and DH */
52057c478bd9Sstevel@tonic-gate case CKA_PRIME:
52067c478bd9Sstevel@tonic-gate
52077c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
52087c478bd9Sstevel@tonic-gate #ifdef __sparcv9
52097c478bd9Sstevel@tonic-gate len =
52107c478bd9Sstevel@tonic-gate /* LINTED */
52117c478bd9Sstevel@tonic-gate (uint32_t)
52127c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_PRIME(key))->
52137c478bd9Sstevel@tonic-gate big_value_len;
52147c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
52157c478bd9Sstevel@tonic-gate len =
52167c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_PRIME(key))->
52177c478bd9Sstevel@tonic-gate big_value_len;
52187c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
52197c478bd9Sstevel@tonic-gate else
52207c478bd9Sstevel@tonic-gate #ifdef __sparcv9
52217c478bd9Sstevel@tonic-gate len =
52227c478bd9Sstevel@tonic-gate /* LINTED */
52237c478bd9Sstevel@tonic-gate (uint32_t)
52247c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_PRIME(key))->
52257c478bd9Sstevel@tonic-gate big_value_len;
52267c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
52277c478bd9Sstevel@tonic-gate len =
52287c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_PRIME(key))->
52297c478bd9Sstevel@tonic-gate big_value_len;
52307c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
52317c478bd9Sstevel@tonic-gate
52327c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
52337c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
52347c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
52357c478bd9Sstevel@tonic-gate }
52367c478bd9Sstevel@tonic-gate *value_len = len;
52377c478bd9Sstevel@tonic-gate
52387c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
52397c478bd9Sstevel@tonic-gate (void) memcpy(value,
52407c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_PRIME(key))->big_value,
52417c478bd9Sstevel@tonic-gate *value_len);
52427c478bd9Sstevel@tonic-gate else
52437c478bd9Sstevel@tonic-gate (void) memcpy(value,
52447c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_PRIME(key))->big_value,
52457c478bd9Sstevel@tonic-gate *value_len);
52467c478bd9Sstevel@tonic-gate
52477c478bd9Sstevel@tonic-gate break;
52487c478bd9Sstevel@tonic-gate
52497c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
52507c478bd9Sstevel@tonic-gate #ifdef __sparcv9
52517c478bd9Sstevel@tonic-gate len =
52527c478bd9Sstevel@tonic-gate /* LINTED */
52537c478bd9Sstevel@tonic-gate (uint32_t)
52547c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_SUBPRIME(key))->big_value_len;
52557c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
52567c478bd9Sstevel@tonic-gate len =
52577c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_SUBPRIME(key))->big_value_len;
52587c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
52597c478bd9Sstevel@tonic-gate
52607c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
52617c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
52627c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
52637c478bd9Sstevel@tonic-gate }
52647c478bd9Sstevel@tonic-gate *value_len = len;
52657c478bd9Sstevel@tonic-gate
52667c478bd9Sstevel@tonic-gate (void) memcpy(value,
52677c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_SUBPRIME(key))->big_value,
52687c478bd9Sstevel@tonic-gate *value_len);
52697c478bd9Sstevel@tonic-gate
52707c478bd9Sstevel@tonic-gate break;
52717c478bd9Sstevel@tonic-gate
52727c478bd9Sstevel@tonic-gate case CKA_BASE:
52737c478bd9Sstevel@tonic-gate
52747c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
52757c478bd9Sstevel@tonic-gate #ifdef __sparcv9
52767c478bd9Sstevel@tonic-gate len =
52777c478bd9Sstevel@tonic-gate /* LINTED */
52787c478bd9Sstevel@tonic-gate (uint32_t)
52797c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_BASE(key))->
52807c478bd9Sstevel@tonic-gate big_value_len;
52817c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
52827c478bd9Sstevel@tonic-gate len =
52837c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_BASE(key))->
52847c478bd9Sstevel@tonic-gate big_value_len;
52857c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
52867c478bd9Sstevel@tonic-gate else
52877c478bd9Sstevel@tonic-gate #ifdef __sparcv9
52887c478bd9Sstevel@tonic-gate len =
52897c478bd9Sstevel@tonic-gate /* LINTED */
52907c478bd9Sstevel@tonic-gate (uint32_t)
52917c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_BASE(key))->
52927c478bd9Sstevel@tonic-gate big_value_len;
52937c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
52947c478bd9Sstevel@tonic-gate len =
52957c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_BASE(key))->
52967c478bd9Sstevel@tonic-gate big_value_len;
52977c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
52987c478bd9Sstevel@tonic-gate
52997c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
53007c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
53017c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
53027c478bd9Sstevel@tonic-gate }
53037c478bd9Sstevel@tonic-gate *value_len = len;
53047c478bd9Sstevel@tonic-gate
53057c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
53067c478bd9Sstevel@tonic-gate (void) memcpy(value,
53077c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_BASE(key))->big_value,
53087c478bd9Sstevel@tonic-gate *value_len);
53097c478bd9Sstevel@tonic-gate else
53107c478bd9Sstevel@tonic-gate (void) memcpy(value,
53117c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_BASE(key))->big_value,
53127c478bd9Sstevel@tonic-gate *value_len);
53137c478bd9Sstevel@tonic-gate break;
53147c478bd9Sstevel@tonic-gate
53157c478bd9Sstevel@tonic-gate case CKA_VALUE:
53167c478bd9Sstevel@tonic-gate
53177c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
53187c478bd9Sstevel@tonic-gate #ifdef __sparcv9
53197c478bd9Sstevel@tonic-gate len =
53207c478bd9Sstevel@tonic-gate /* LINTED */
53217c478bd9Sstevel@tonic-gate (uint32_t)
53227c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_VALUE(key))->
53237c478bd9Sstevel@tonic-gate big_value_len;
53247c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
53257c478bd9Sstevel@tonic-gate len =
53267c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_VALUE(key))->
53277c478bd9Sstevel@tonic-gate big_value_len;
53287c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
53297c478bd9Sstevel@tonic-gate else
53307c478bd9Sstevel@tonic-gate #ifdef __sparcv9
53317c478bd9Sstevel@tonic-gate len =
53327c478bd9Sstevel@tonic-gate /* LINTED */
53337c478bd9Sstevel@tonic-gate (uint32_t)
53347c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_VALUE(key))->
53357c478bd9Sstevel@tonic-gate big_value_len;
53367c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
53377c478bd9Sstevel@tonic-gate len =
53387c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_VALUE(key))->
53397c478bd9Sstevel@tonic-gate big_value_len;
53407c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
53417c478bd9Sstevel@tonic-gate
53427c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
53437c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
53447c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
53457c478bd9Sstevel@tonic-gate }
53467c478bd9Sstevel@tonic-gate *value_len = len;
53477c478bd9Sstevel@tonic-gate
53487c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
53497c478bd9Sstevel@tonic-gate (void) memcpy(value,
53507c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DSA_VALUE(key))->big_value,
53517c478bd9Sstevel@tonic-gate *value_len);
53527c478bd9Sstevel@tonic-gate else
53537c478bd9Sstevel@tonic-gate (void) memcpy(value,
53547c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PUB_DH_VALUE(key))->big_value,
53557c478bd9Sstevel@tonic-gate *value_len);
53567c478bd9Sstevel@tonic-gate
53577c478bd9Sstevel@tonic-gate break;
53587c478bd9Sstevel@tonic-gate }
53597c478bd9Sstevel@tonic-gate
53607c478bd9Sstevel@tonic-gate return (CKR_OK);
53617c478bd9Sstevel@tonic-gate }
53627c478bd9Sstevel@tonic-gate
53637c478bd9Sstevel@tonic-gate
53647c478bd9Sstevel@tonic-gate CK_RV
5365c64d15a5Smcpowers soft_get_private_value(soft_object_t *key, CK_ATTRIBUTE_TYPE type,
53667c478bd9Sstevel@tonic-gate uchar_t *value, uint32_t *value_len)
53677c478bd9Sstevel@tonic-gate {
53687c478bd9Sstevel@tonic-gate
53697c478bd9Sstevel@tonic-gate uint32_t len = 0;
53707c478bd9Sstevel@tonic-gate
53717c478bd9Sstevel@tonic-gate switch (type) {
53727c478bd9Sstevel@tonic-gate
53737c478bd9Sstevel@tonic-gate /* The following attributes belong to RSA */
53747c478bd9Sstevel@tonic-gate case CKA_MODULUS:
53757c478bd9Sstevel@tonic-gate #ifdef __sparcv9
53767c478bd9Sstevel@tonic-gate len =
53777c478bd9Sstevel@tonic-gate /* LINTED */
53787c478bd9Sstevel@tonic-gate (uint32_t)
53797c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_MOD(key))->big_value_len;
53807c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
53817c478bd9Sstevel@tonic-gate len =
53827c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_MOD(key))->big_value_len;
53837c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
53847c478bd9Sstevel@tonic-gate
53857c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
53867c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
53877c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
53887c478bd9Sstevel@tonic-gate }
53897c478bd9Sstevel@tonic-gate *value_len = len;
53907c478bd9Sstevel@tonic-gate
53917c478bd9Sstevel@tonic-gate (void) memcpy(value,
53927c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_MOD(key))->big_value,
53937c478bd9Sstevel@tonic-gate *value_len);
53947c478bd9Sstevel@tonic-gate
53957c478bd9Sstevel@tonic-gate break;
53967c478bd9Sstevel@tonic-gate
53977c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT:
53987c478bd9Sstevel@tonic-gate #ifdef __sparcv9
53997c478bd9Sstevel@tonic-gate len =
54007c478bd9Sstevel@tonic-gate /* LINTED */
54017c478bd9Sstevel@tonic-gate (uint32_t)
54027c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIEXPO(key))->big_value_len;
54037c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
54047c478bd9Sstevel@tonic-gate len =
54057c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIEXPO(key))->big_value_len;
54067c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
54077c478bd9Sstevel@tonic-gate
54087c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
54097c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
54107c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
54117c478bd9Sstevel@tonic-gate }
54127c478bd9Sstevel@tonic-gate *value_len = len;
54137c478bd9Sstevel@tonic-gate
54147c478bd9Sstevel@tonic-gate (void) memcpy(value,
54157c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIEXPO(key))->big_value,
54167c478bd9Sstevel@tonic-gate *value_len);
54177c478bd9Sstevel@tonic-gate
54187c478bd9Sstevel@tonic-gate break;
54197c478bd9Sstevel@tonic-gate
54207c478bd9Sstevel@tonic-gate case CKA_PRIME_1:
54217c478bd9Sstevel@tonic-gate #ifdef __sparcv9
54227c478bd9Sstevel@tonic-gate len =
54237c478bd9Sstevel@tonic-gate /* LINTED */
54247c478bd9Sstevel@tonic-gate (uint32_t)
54257c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIME1(key))->big_value_len;
54267c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
54277c478bd9Sstevel@tonic-gate len =
54287c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIME1(key))->big_value_len;
54297c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
54307c478bd9Sstevel@tonic-gate
54317c478bd9Sstevel@tonic-gate if (len > *value_len) {
54327c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
54337c478bd9Sstevel@tonic-gate }
54347c478bd9Sstevel@tonic-gate *value_len = len;
54357c478bd9Sstevel@tonic-gate
54367c478bd9Sstevel@tonic-gate if (*value_len == 0) {
54377c478bd9Sstevel@tonic-gate return (CKR_OK);
54387c478bd9Sstevel@tonic-gate }
54397c478bd9Sstevel@tonic-gate
54407c478bd9Sstevel@tonic-gate (void) memcpy(value,
54417c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIME1(key))->big_value,
54427c478bd9Sstevel@tonic-gate *value_len);
54437c478bd9Sstevel@tonic-gate
54447c478bd9Sstevel@tonic-gate break;
54457c478bd9Sstevel@tonic-gate
54467c478bd9Sstevel@tonic-gate case CKA_PRIME_2:
54477c478bd9Sstevel@tonic-gate #ifdef __sparcv9
54487c478bd9Sstevel@tonic-gate len =
54497c478bd9Sstevel@tonic-gate /* LINTED */
54507c478bd9Sstevel@tonic-gate (uint32_t)
54517c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIME2(key))->big_value_len;
54527c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
54537c478bd9Sstevel@tonic-gate len =
54547c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIME2(key))->big_value_len;
54557c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
54567c478bd9Sstevel@tonic-gate
54577c478bd9Sstevel@tonic-gate if (len > *value_len) {
54587c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
54597c478bd9Sstevel@tonic-gate }
54607c478bd9Sstevel@tonic-gate *value_len = len;
54617c478bd9Sstevel@tonic-gate
54627c478bd9Sstevel@tonic-gate if (*value_len == 0) {
54637c478bd9Sstevel@tonic-gate return (CKR_OK);
54647c478bd9Sstevel@tonic-gate }
54657c478bd9Sstevel@tonic-gate
54667c478bd9Sstevel@tonic-gate (void) memcpy(value,
54677c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_PRIME2(key))->big_value,
54687c478bd9Sstevel@tonic-gate *value_len);
54697c478bd9Sstevel@tonic-gate
54707c478bd9Sstevel@tonic-gate break;
54717c478bd9Sstevel@tonic-gate
54727c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1:
54737c478bd9Sstevel@tonic-gate #ifdef __sparcv9
54747c478bd9Sstevel@tonic-gate len =
54757c478bd9Sstevel@tonic-gate /* LINTED */
54767c478bd9Sstevel@tonic-gate (uint32_t)
54777c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_EXPO1(key))->big_value_len;
54787c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
54797c478bd9Sstevel@tonic-gate len =
54807c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_EXPO1(key))->big_value_len;
54817c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
54827c478bd9Sstevel@tonic-gate
54837c478bd9Sstevel@tonic-gate if (len > *value_len) {
54847c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
54857c478bd9Sstevel@tonic-gate }
54867c478bd9Sstevel@tonic-gate *value_len = len;
54877c478bd9Sstevel@tonic-gate
54887c478bd9Sstevel@tonic-gate if (*value_len == 0) {
54897c478bd9Sstevel@tonic-gate return (CKR_OK);
54907c478bd9Sstevel@tonic-gate }
54917c478bd9Sstevel@tonic-gate
54927c478bd9Sstevel@tonic-gate (void) memcpy(value,
54937c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_EXPO1(key))->big_value,
54947c478bd9Sstevel@tonic-gate *value_len);
54957c478bd9Sstevel@tonic-gate
54967c478bd9Sstevel@tonic-gate break;
54977c478bd9Sstevel@tonic-gate
54987c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2:
54997c478bd9Sstevel@tonic-gate #ifdef __sparcv9
55007c478bd9Sstevel@tonic-gate len =
55017c478bd9Sstevel@tonic-gate /* LINTED */
55027c478bd9Sstevel@tonic-gate (uint32_t)
55037c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_EXPO2(key))->big_value_len;
55047c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
55057c478bd9Sstevel@tonic-gate len =
55067c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_EXPO2(key))->big_value_len;
55077c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
55087c478bd9Sstevel@tonic-gate
55097c478bd9Sstevel@tonic-gate if (len > *value_len) {
55107c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
55117c478bd9Sstevel@tonic-gate }
55127c478bd9Sstevel@tonic-gate *value_len = len;
55137c478bd9Sstevel@tonic-gate
55147c478bd9Sstevel@tonic-gate if (*value_len == 0) {
55157c478bd9Sstevel@tonic-gate return (CKR_OK);
55167c478bd9Sstevel@tonic-gate }
55177c478bd9Sstevel@tonic-gate
55187c478bd9Sstevel@tonic-gate (void) memcpy(value,
55197c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_EXPO2(key))->big_value,
55207c478bd9Sstevel@tonic-gate *value_len);
55217c478bd9Sstevel@tonic-gate
55227c478bd9Sstevel@tonic-gate break;
55237c478bd9Sstevel@tonic-gate
55247c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT:
55257c478bd9Sstevel@tonic-gate #ifdef __sparcv9
55267c478bd9Sstevel@tonic-gate len =
55277c478bd9Sstevel@tonic-gate /* LINTED */
55287c478bd9Sstevel@tonic-gate (uint32_t)
55297c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_COEF(key))->big_value_len;
55307c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
55317c478bd9Sstevel@tonic-gate len =
55327c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_COEF(key))->big_value_len;
55337c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
55347c478bd9Sstevel@tonic-gate
55357c478bd9Sstevel@tonic-gate if (len > *value_len) {
55367c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
55377c478bd9Sstevel@tonic-gate }
55387c478bd9Sstevel@tonic-gate *value_len = len;
55397c478bd9Sstevel@tonic-gate
55407c478bd9Sstevel@tonic-gate if (*value_len == 0) {
55417c478bd9Sstevel@tonic-gate return (CKR_OK);
55427c478bd9Sstevel@tonic-gate }
55437c478bd9Sstevel@tonic-gate
55447c478bd9Sstevel@tonic-gate (void) memcpy(value,
55457c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_RSA_COEF(key))->big_value,
55467c478bd9Sstevel@tonic-gate *value_len);
55477c478bd9Sstevel@tonic-gate
55487c478bd9Sstevel@tonic-gate break;
55497c478bd9Sstevel@tonic-gate
55507c478bd9Sstevel@tonic-gate /* The following attributes belong to DSA and DH */
55517c478bd9Sstevel@tonic-gate case CKA_PRIME:
55527c478bd9Sstevel@tonic-gate
55537c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
55547c478bd9Sstevel@tonic-gate #ifdef __sparcv9
55557c478bd9Sstevel@tonic-gate len =
55567c478bd9Sstevel@tonic-gate /* LINTED */
55577c478bd9Sstevel@tonic-gate (uint32_t)
55587c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_PRIME(key))->
55597c478bd9Sstevel@tonic-gate big_value_len;
55607c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
55617c478bd9Sstevel@tonic-gate len =
55627c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_PRIME(key))->
55637c478bd9Sstevel@tonic-gate big_value_len;
55647c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
55657c478bd9Sstevel@tonic-gate else
55667c478bd9Sstevel@tonic-gate #ifdef __sparcv9
55677c478bd9Sstevel@tonic-gate len =
55687c478bd9Sstevel@tonic-gate /* LINTED */
55697c478bd9Sstevel@tonic-gate (uint32_t)
55707c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_PRIME(key))->
55717c478bd9Sstevel@tonic-gate big_value_len;
55727c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
55737c478bd9Sstevel@tonic-gate len =
55747c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_PRIME(key))->
55757c478bd9Sstevel@tonic-gate big_value_len;
55767c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
55777c478bd9Sstevel@tonic-gate
55787c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
55797c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
55807c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
55817c478bd9Sstevel@tonic-gate }
55827c478bd9Sstevel@tonic-gate *value_len = len;
55837c478bd9Sstevel@tonic-gate
55847c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
55857c478bd9Sstevel@tonic-gate (void) memcpy(value,
55867c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_PRIME(key))->big_value,
55877c478bd9Sstevel@tonic-gate *value_len);
55887c478bd9Sstevel@tonic-gate else
55897c478bd9Sstevel@tonic-gate (void) memcpy(value,
55907c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_PRIME(key))->big_value,
55917c478bd9Sstevel@tonic-gate *value_len);
55927c478bd9Sstevel@tonic-gate
55937c478bd9Sstevel@tonic-gate break;
55947c478bd9Sstevel@tonic-gate
55957c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
55967c478bd9Sstevel@tonic-gate #ifdef __sparcv9
55977c478bd9Sstevel@tonic-gate len =
55987c478bd9Sstevel@tonic-gate /* LINTED */
55997c478bd9Sstevel@tonic-gate (uint32_t)
56007c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_SUBPRIME(key))->big_value_len;
56017c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
56027c478bd9Sstevel@tonic-gate len =
56037c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_SUBPRIME(key))->big_value_len;
56047c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
56057c478bd9Sstevel@tonic-gate
56067c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
56077c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
56087c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
56097c478bd9Sstevel@tonic-gate }
56107c478bd9Sstevel@tonic-gate *value_len = len;
56117c478bd9Sstevel@tonic-gate
56127c478bd9Sstevel@tonic-gate (void) memcpy(value,
56137c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_SUBPRIME(key))->big_value,
56147c478bd9Sstevel@tonic-gate *value_len);
56157c478bd9Sstevel@tonic-gate
56167c478bd9Sstevel@tonic-gate break;
56177c478bd9Sstevel@tonic-gate
56187c478bd9Sstevel@tonic-gate case CKA_BASE:
56197c478bd9Sstevel@tonic-gate
56207c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
56217c478bd9Sstevel@tonic-gate #ifdef __sparcv9
56227c478bd9Sstevel@tonic-gate len =
56237c478bd9Sstevel@tonic-gate /* LINTED */
56247c478bd9Sstevel@tonic-gate (uint32_t)
56257c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_BASE(key))->
56267c478bd9Sstevel@tonic-gate big_value_len;
56277c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
56287c478bd9Sstevel@tonic-gate len =
56297c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_BASE(key))->
56307c478bd9Sstevel@tonic-gate big_value_len;
56317c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
56327c478bd9Sstevel@tonic-gate else
56337c478bd9Sstevel@tonic-gate #ifdef __sparcv9
56347c478bd9Sstevel@tonic-gate len =
56357c478bd9Sstevel@tonic-gate /* LINTED */
56367c478bd9Sstevel@tonic-gate (uint32_t)
56377c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_BASE(key))->
56387c478bd9Sstevel@tonic-gate big_value_len;
56397c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
56407c478bd9Sstevel@tonic-gate len =
56417c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_BASE(key))->
56427c478bd9Sstevel@tonic-gate big_value_len;
56437c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
56447c478bd9Sstevel@tonic-gate
56457c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
56467c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
56477c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
56487c478bd9Sstevel@tonic-gate }
56497c478bd9Sstevel@tonic-gate *value_len = len;
56507c478bd9Sstevel@tonic-gate
56517c478bd9Sstevel@tonic-gate if (key->key_type == CKK_DSA)
56527c478bd9Sstevel@tonic-gate (void) memcpy(value,
56537c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_BASE(key))->big_value,
56547c478bd9Sstevel@tonic-gate *value_len);
56557c478bd9Sstevel@tonic-gate else
56567c478bd9Sstevel@tonic-gate (void) memcpy(value,
56577c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_BASE(key))->big_value,
56587c478bd9Sstevel@tonic-gate *value_len);
56597c478bd9Sstevel@tonic-gate break;
56607c478bd9Sstevel@tonic-gate
56617c478bd9Sstevel@tonic-gate case CKA_VALUE:
56627c478bd9Sstevel@tonic-gate
5663c64d15a5Smcpowers if (key->key_type == CKK_DSA) {
56647c478bd9Sstevel@tonic-gate #ifdef __sparcv9
56657c478bd9Sstevel@tonic-gate len =
56667c478bd9Sstevel@tonic-gate /* LINTED */
56677c478bd9Sstevel@tonic-gate (uint32_t)
56687c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_VALUE(key))->
56697c478bd9Sstevel@tonic-gate big_value_len;
56707c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
56717c478bd9Sstevel@tonic-gate len =
56727c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_VALUE(key))->
56737c478bd9Sstevel@tonic-gate big_value_len;
56747c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
5675c64d15a5Smcpowers } else if (key->key_type == CKK_DH) {
56767c478bd9Sstevel@tonic-gate #ifdef __sparcv9
56777c478bd9Sstevel@tonic-gate len =
56787c478bd9Sstevel@tonic-gate /* LINTED */
56797c478bd9Sstevel@tonic-gate (uint32_t)
56807c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_VALUE(key))->
56817c478bd9Sstevel@tonic-gate big_value_len;
56827c478bd9Sstevel@tonic-gate #else /* !__sparcv9 */
56837c478bd9Sstevel@tonic-gate len =
56847c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_VALUE(key))->
56857c478bd9Sstevel@tonic-gate big_value_len;
56867c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
5687c64d15a5Smcpowers } else {
5688c64d15a5Smcpowers #ifdef __sparcv9
5689c64d15a5Smcpowers len =
5690c64d15a5Smcpowers /* LINTED */
5691c64d15a5Smcpowers (uint32_t)
5692c64d15a5Smcpowers ((biginteger_t *)OBJ_PRI_EC_VALUE(key))->
5693c64d15a5Smcpowers big_value_len;
5694c64d15a5Smcpowers #else /* !__sparcv9 */
5695c64d15a5Smcpowers len =
5696c64d15a5Smcpowers ((biginteger_t *)OBJ_PRI_EC_VALUE(key))->
5697c64d15a5Smcpowers big_value_len;
5698c64d15a5Smcpowers #endif /* __sparcv9 */
5699c64d15a5Smcpowers }
57007c478bd9Sstevel@tonic-gate
57017c478bd9Sstevel@tonic-gate /* This attribute MUST BE set */
57027c478bd9Sstevel@tonic-gate if (len == 0 || len > *value_len) {
57037c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID);
57047c478bd9Sstevel@tonic-gate }
57057c478bd9Sstevel@tonic-gate *value_len = len;
57067c478bd9Sstevel@tonic-gate
5707c64d15a5Smcpowers if (key->key_type == CKK_DSA) {
57087c478bd9Sstevel@tonic-gate (void) memcpy(value,
57097c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DSA_VALUE(key))->big_value,
57107c478bd9Sstevel@tonic-gate *value_len);
5711c64d15a5Smcpowers } else if (key->key_type == CKK_DH) {
57127c478bd9Sstevel@tonic-gate (void) memcpy(value,
57137c478bd9Sstevel@tonic-gate ((biginteger_t *)OBJ_PRI_DH_VALUE(key))->big_value,
57147c478bd9Sstevel@tonic-gate *value_len);
5715c64d15a5Smcpowers } else {
5716c64d15a5Smcpowers (void) memcpy(value,
5717c64d15a5Smcpowers ((biginteger_t *)OBJ_PRI_EC_VALUE(key))->big_value,
5718c64d15a5Smcpowers *value_len);
5719c64d15a5Smcpowers }
57207c478bd9Sstevel@tonic-gate
57217c478bd9Sstevel@tonic-gate break;
57227c478bd9Sstevel@tonic-gate }
57237c478bd9Sstevel@tonic-gate
57247c478bd9Sstevel@tonic-gate return (CKR_OK);
57257c478bd9Sstevel@tonic-gate
57267c478bd9Sstevel@tonic-gate }
57277c478bd9Sstevel@tonic-gate
57287c478bd9Sstevel@tonic-gate static CK_RV
57297c478bd9Sstevel@tonic-gate copy_bigint(biginteger_t *new_bigint, biginteger_t *old_bigint)
57307c478bd9Sstevel@tonic-gate {
57317c478bd9Sstevel@tonic-gate new_bigint->big_value =
57327c478bd9Sstevel@tonic-gate malloc((sizeof (CK_BYTE) * new_bigint->big_value_len));
57337c478bd9Sstevel@tonic-gate
57347c478bd9Sstevel@tonic-gate if (new_bigint->big_value == NULL) {
57357c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
57367c478bd9Sstevel@tonic-gate }
57377c478bd9Sstevel@tonic-gate
57387c478bd9Sstevel@tonic-gate (void) memcpy(new_bigint->big_value, old_bigint->big_value,
57397c478bd9Sstevel@tonic-gate (sizeof (CK_BYTE) * new_bigint->big_value_len));
57407c478bd9Sstevel@tonic-gate
57417c478bd9Sstevel@tonic-gate return (CKR_OK);
57427c478bd9Sstevel@tonic-gate }
57437c478bd9Sstevel@tonic-gate
57447c478bd9Sstevel@tonic-gate static void
57457c478bd9Sstevel@tonic-gate free_public_key_attr(public_key_obj_t *pbk, CK_KEY_TYPE key_type)
57467c478bd9Sstevel@tonic-gate {
57477c478bd9Sstevel@tonic-gate if (pbk == NULL) {
57487c478bd9Sstevel@tonic-gate return;
57497c478bd9Sstevel@tonic-gate }
57507c478bd9Sstevel@tonic-gate
57517c478bd9Sstevel@tonic-gate switch (key_type) {
57527c478bd9Sstevel@tonic-gate case CKK_RSA:
57537c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_RSA_MOD(pbk));
57547c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_RSA_PUBEXPO(pbk));
57557c478bd9Sstevel@tonic-gate break;
57567c478bd9Sstevel@tonic-gate case CKK_DSA:
57577c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_PRIME(pbk));
57587c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_SUBPRIME(pbk));
57597c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_BASE(pbk));
57607c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_VALUE(pbk));
57617c478bd9Sstevel@tonic-gate break;
57627c478bd9Sstevel@tonic-gate case CKK_DH:
57637c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH_PRIME(pbk));
57647c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH_BASE(pbk));
57657c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH_VALUE(pbk));
57667c478bd9Sstevel@tonic-gate break;
5767f9fbec18Smcpowers case CKK_EC:
5768f9fbec18Smcpowers bigint_attr_cleanup(KEY_PUB_EC_POINT(pbk));
5769f9fbec18Smcpowers break;
57707c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
57717c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH942_PRIME(pbk));
57727c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH942_SUBPRIME(pbk));
57737c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH942_BASE(pbk));
57747c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DH942_VALUE(pbk));
57757c478bd9Sstevel@tonic-gate break;
57767c478bd9Sstevel@tonic-gate default:
57777c478bd9Sstevel@tonic-gate break;
57787c478bd9Sstevel@tonic-gate }
57797c478bd9Sstevel@tonic-gate free(pbk);
57807c478bd9Sstevel@tonic-gate }
57817c478bd9Sstevel@tonic-gate
57827c478bd9Sstevel@tonic-gate CK_RV
57837c478bd9Sstevel@tonic-gate soft_copy_public_key_attr(public_key_obj_t *old_pub_key_obj_p,
57847c478bd9Sstevel@tonic-gate public_key_obj_t **new_pub_key_obj_p, CK_KEY_TYPE key_type)
57857c478bd9Sstevel@tonic-gate {
57867c478bd9Sstevel@tonic-gate
57877c478bd9Sstevel@tonic-gate public_key_obj_t *pbk;
57887c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
57897c478bd9Sstevel@tonic-gate
57907c478bd9Sstevel@tonic-gate pbk = calloc(1, sizeof (public_key_obj_t));
57917c478bd9Sstevel@tonic-gate if (pbk == NULL) {
57927c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
57937c478bd9Sstevel@tonic-gate }
57947c478bd9Sstevel@tonic-gate
57957c478bd9Sstevel@tonic-gate switch (key_type) {
57967c478bd9Sstevel@tonic-gate case CKK_RSA:
57977c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PUB_RSA(pbk),
57987c478bd9Sstevel@tonic-gate KEY_PUB_RSA(old_pub_key_obj_p),
57997c478bd9Sstevel@tonic-gate sizeof (rsa_pub_key_t));
58007c478bd9Sstevel@tonic-gate /* copy modulus */
58017c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_RSA_MOD(pbk),
58027c478bd9Sstevel@tonic-gate KEY_PUB_RSA_MOD(old_pub_key_obj_p));
58037c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58047c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58057c478bd9Sstevel@tonic-gate return (rv);
58067c478bd9Sstevel@tonic-gate }
58077c478bd9Sstevel@tonic-gate /* copy public exponent */
58087c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_RSA_PUBEXPO(pbk),
58097c478bd9Sstevel@tonic-gate KEY_PUB_RSA_PUBEXPO(old_pub_key_obj_p));
58107c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58117c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58127c478bd9Sstevel@tonic-gate return (rv);
58137c478bd9Sstevel@tonic-gate }
58147c478bd9Sstevel@tonic-gate break;
58157c478bd9Sstevel@tonic-gate case CKK_DSA:
58167c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PUB_DSA(pbk),
58177c478bd9Sstevel@tonic-gate KEY_PUB_DSA(old_pub_key_obj_p),
58187c478bd9Sstevel@tonic-gate sizeof (dsa_pub_key_t));
58197c478bd9Sstevel@tonic-gate
58207c478bd9Sstevel@tonic-gate /* copy prime */
58217c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_PRIME(pbk),
58227c478bd9Sstevel@tonic-gate KEY_PUB_DSA_PRIME(old_pub_key_obj_p));
58237c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58247c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58257c478bd9Sstevel@tonic-gate return (rv);
58267c478bd9Sstevel@tonic-gate }
58277c478bd9Sstevel@tonic-gate
58287c478bd9Sstevel@tonic-gate /* copy subprime */
58297c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_SUBPRIME(pbk),
58307c478bd9Sstevel@tonic-gate KEY_PUB_DSA_SUBPRIME(old_pub_key_obj_p));
58317c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58327c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58337c478bd9Sstevel@tonic-gate return (rv);
58347c478bd9Sstevel@tonic-gate }
58357c478bd9Sstevel@tonic-gate
58367c478bd9Sstevel@tonic-gate /* copy base */
58377c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_BASE(pbk),
58387c478bd9Sstevel@tonic-gate KEY_PUB_DSA_BASE(old_pub_key_obj_p));
58397c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58407c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58417c478bd9Sstevel@tonic-gate return (rv);
58427c478bd9Sstevel@tonic-gate }
58437c478bd9Sstevel@tonic-gate
58447c478bd9Sstevel@tonic-gate /* copy value */
58457c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_VALUE(pbk),
58467c478bd9Sstevel@tonic-gate KEY_PUB_DSA_VALUE(old_pub_key_obj_p));
58477c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58487c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58497c478bd9Sstevel@tonic-gate return (rv);
58507c478bd9Sstevel@tonic-gate }
58517c478bd9Sstevel@tonic-gate break;
58527c478bd9Sstevel@tonic-gate case CKK_DH:
58537c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PUB_DH(pbk),
58547c478bd9Sstevel@tonic-gate KEY_PUB_DH(old_pub_key_obj_p),
58557c478bd9Sstevel@tonic-gate sizeof (dh_pub_key_t));
58567c478bd9Sstevel@tonic-gate
58577c478bd9Sstevel@tonic-gate /* copy prime */
58587c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH_PRIME(pbk),
58597c478bd9Sstevel@tonic-gate KEY_PUB_DH_PRIME(old_pub_key_obj_p));
58607c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58617c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58627c478bd9Sstevel@tonic-gate return (rv);
58637c478bd9Sstevel@tonic-gate }
58647c478bd9Sstevel@tonic-gate
58657c478bd9Sstevel@tonic-gate /* copy base */
58667c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH_BASE(pbk),
58677c478bd9Sstevel@tonic-gate KEY_PUB_DH_BASE(old_pub_key_obj_p));
58687c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58697c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58707c478bd9Sstevel@tonic-gate return (rv);
58717c478bd9Sstevel@tonic-gate }
58727c478bd9Sstevel@tonic-gate
58737c478bd9Sstevel@tonic-gate /* copy value */
58747c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH_VALUE(pbk),
58757c478bd9Sstevel@tonic-gate KEY_PUB_DH_VALUE(old_pub_key_obj_p));
58767c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
58777c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
58787c478bd9Sstevel@tonic-gate return (rv);
58797c478bd9Sstevel@tonic-gate }
58807c478bd9Sstevel@tonic-gate break;
5881f9fbec18Smcpowers case CKK_EC:
5882f9fbec18Smcpowers (void) memcpy(KEY_PUB_EC(pbk),
5883f9fbec18Smcpowers KEY_PUB_EC(old_pub_key_obj_p),
5884f9fbec18Smcpowers sizeof (ec_pub_key_t));
5885f9fbec18Smcpowers
5886f9fbec18Smcpowers /* copy point */
5887f9fbec18Smcpowers rv = copy_bigint(KEY_PUB_EC_POINT(pbk),
5888f9fbec18Smcpowers KEY_PUB_EC_POINT(old_pub_key_obj_p));
5889f9fbec18Smcpowers if (rv != CKR_OK) {
5890f9fbec18Smcpowers free_public_key_attr(pbk, key_type);
5891f9fbec18Smcpowers return (rv);
5892f9fbec18Smcpowers }
5893f9fbec18Smcpowers break;
58947c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
58957c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PUB_DH942(pbk),
58967c478bd9Sstevel@tonic-gate KEY_PUB_DH942(old_pub_key_obj_p),
58977c478bd9Sstevel@tonic-gate sizeof (dh942_pub_key_t));
58987c478bd9Sstevel@tonic-gate
58997c478bd9Sstevel@tonic-gate /* copy prime */
59007c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH942_PRIME(pbk),
59017c478bd9Sstevel@tonic-gate KEY_PUB_DH942_PRIME(old_pub_key_obj_p));
59027c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
59037c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
59047c478bd9Sstevel@tonic-gate return (rv);
59057c478bd9Sstevel@tonic-gate }
59067c478bd9Sstevel@tonic-gate
59077c478bd9Sstevel@tonic-gate /* copy subprime */
59087c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH942_SUBPRIME(pbk),
59097c478bd9Sstevel@tonic-gate KEY_PUB_DH942_SUBPRIME(old_pub_key_obj_p));
59107c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
59117c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
59127c478bd9Sstevel@tonic-gate return (rv);
59137c478bd9Sstevel@tonic-gate }
59147c478bd9Sstevel@tonic-gate
59157c478bd9Sstevel@tonic-gate /* copy base */
59167c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH942_BASE(pbk),
59177c478bd9Sstevel@tonic-gate KEY_PUB_DH942_BASE(old_pub_key_obj_p));
59187c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
59197c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
59207c478bd9Sstevel@tonic-gate return (rv);
59217c478bd9Sstevel@tonic-gate }
59227c478bd9Sstevel@tonic-gate
59237c478bd9Sstevel@tonic-gate /* copy value */
59247c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DH942_VALUE(pbk),
59257c478bd9Sstevel@tonic-gate KEY_PUB_DH942_VALUE(old_pub_key_obj_p));
59267c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
59277c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type);
59287c478bd9Sstevel@tonic-gate return (rv);
59297c478bd9Sstevel@tonic-gate }
59307c478bd9Sstevel@tonic-gate break;
59317c478bd9Sstevel@tonic-gate default:
59327c478bd9Sstevel@tonic-gate break;
59337c478bd9Sstevel@tonic-gate }
59347c478bd9Sstevel@tonic-gate *new_pub_key_obj_p = pbk;
59357c478bd9Sstevel@tonic-gate return (rv);
59367c478bd9Sstevel@tonic-gate }
59377c478bd9Sstevel@tonic-gate
59387c478bd9Sstevel@tonic-gate static void
59397c478bd9Sstevel@tonic-gate free_private_key_attr(private_key_obj_t *pbk, CK_KEY_TYPE key_type)
59407c478bd9Sstevel@tonic-gate {
59417c478bd9Sstevel@tonic-gate if (pbk == NULL) {
59427c478bd9Sstevel@tonic-gate return;
59437c478bd9Sstevel@tonic-gate }
59447c478bd9Sstevel@tonic-gate
59457c478bd9Sstevel@tonic-gate switch (key_type) {
59467c478bd9Sstevel@tonic-gate case CKK_RSA:
59477c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_MOD(pbk));
59487c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PUBEXPO(pbk));
59497c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PRIEXPO(pbk));
59507c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PRIME1(pbk));
59517c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PRIME2(pbk));
59527c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_EXPO1(pbk));
59537c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_EXPO2(pbk));
59547c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_COEF(pbk));
59557c478bd9Sstevel@tonic-gate break;
59567c478bd9Sstevel@tonic-gate case CKK_DSA:
59577c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_PRIME(pbk));
59587c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_SUBPRIME(pbk));
59597c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_BASE(pbk));
59607c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_VALUE(pbk));
59617c478bd9Sstevel@tonic-gate break;
59627c478bd9Sstevel@tonic-gate case CKK_DH:
59637c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH_PRIME(pbk));
59647c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH_BASE(pbk));
59657c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH_VALUE(pbk));
59667c478bd9Sstevel@tonic-gate break;
5967f9fbec18Smcpowers case CKK_EC:
5968f9fbec18Smcpowers bigint_attr_cleanup(KEY_PRI_EC_VALUE(pbk));
5969f9fbec18Smcpowers break;
59707c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
59717c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH942_PRIME(pbk));
59727c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH942_SUBPRIME(pbk));
59737c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH942_BASE(pbk));
59747c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DH942_VALUE(pbk));
59757c478bd9Sstevel@tonic-gate break;
59767c478bd9Sstevel@tonic-gate default:
59777c478bd9Sstevel@tonic-gate break;
59787c478bd9Sstevel@tonic-gate }
59797c478bd9Sstevel@tonic-gate free(pbk);
59807c478bd9Sstevel@tonic-gate }
59817c478bd9Sstevel@tonic-gate
59827c478bd9Sstevel@tonic-gate CK_RV
59837c478bd9Sstevel@tonic-gate soft_copy_private_key_attr(private_key_obj_t *old_pri_key_obj_p,
59847c478bd9Sstevel@tonic-gate private_key_obj_t **new_pri_key_obj_p, CK_KEY_TYPE key_type)
59857c478bd9Sstevel@tonic-gate {
59867c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
59877c478bd9Sstevel@tonic-gate private_key_obj_t *pbk;
59887c478bd9Sstevel@tonic-gate
59897c478bd9Sstevel@tonic-gate pbk = calloc(1, sizeof (private_key_obj_t));
59907c478bd9Sstevel@tonic-gate if (pbk == NULL) {
59917c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
59927c478bd9Sstevel@tonic-gate }
59937c478bd9Sstevel@tonic-gate
59947c478bd9Sstevel@tonic-gate switch (key_type) {
59957c478bd9Sstevel@tonic-gate case CKK_RSA:
59967c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PRI_RSA(pbk),
59977c478bd9Sstevel@tonic-gate KEY_PRI_RSA(old_pri_key_obj_p),
59987c478bd9Sstevel@tonic-gate sizeof (rsa_pri_key_t));
59997c478bd9Sstevel@tonic-gate /* copy modulus */
60007c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_MOD(pbk),
60017c478bd9Sstevel@tonic-gate KEY_PRI_RSA_MOD(old_pri_key_obj_p));
60027c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60037c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60047c478bd9Sstevel@tonic-gate return (rv);
60057c478bd9Sstevel@tonic-gate }
60067c478bd9Sstevel@tonic-gate /* copy public exponent */
60077c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PUBEXPO(pbk),
60087c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PUBEXPO(old_pri_key_obj_p));
60097c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60107c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60117c478bd9Sstevel@tonic-gate return (rv);
60127c478bd9Sstevel@tonic-gate }
60137c478bd9Sstevel@tonic-gate /* copy private exponent */
60147c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PRIEXPO(pbk),
60157c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PRIEXPO(old_pri_key_obj_p));
60167c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60177c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60187c478bd9Sstevel@tonic-gate return (rv);
60197c478bd9Sstevel@tonic-gate }
60207c478bd9Sstevel@tonic-gate /* copy prime_1 */
60217c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PRIME1(pbk),
60227c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PRIME1(old_pri_key_obj_p));
60237c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60247c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60257c478bd9Sstevel@tonic-gate return (rv);
60267c478bd9Sstevel@tonic-gate }
60277c478bd9Sstevel@tonic-gate /* copy prime_2 */
60287c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PRIME2(pbk),
60297c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PRIME2(old_pri_key_obj_p));
60307c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60317c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60327c478bd9Sstevel@tonic-gate return (rv);
60337c478bd9Sstevel@tonic-gate }
60347c478bd9Sstevel@tonic-gate /* copy exponent_1 */
60357c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_EXPO1(pbk),
60367c478bd9Sstevel@tonic-gate KEY_PRI_RSA_EXPO1(old_pri_key_obj_p));
60377c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60387c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60397c478bd9Sstevel@tonic-gate return (rv);
60407c478bd9Sstevel@tonic-gate }
60417c478bd9Sstevel@tonic-gate /* copy exponent_2 */
60427c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_EXPO2(pbk),
60437c478bd9Sstevel@tonic-gate KEY_PRI_RSA_EXPO2(old_pri_key_obj_p));
60447c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60457c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60467c478bd9Sstevel@tonic-gate return (rv);
60477c478bd9Sstevel@tonic-gate }
60487c478bd9Sstevel@tonic-gate /* copy coefficient */
60497c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_COEF(pbk),
60507c478bd9Sstevel@tonic-gate KEY_PRI_RSA_COEF(old_pri_key_obj_p));
60517c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60527c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60537c478bd9Sstevel@tonic-gate return (rv);
60547c478bd9Sstevel@tonic-gate }
60557c478bd9Sstevel@tonic-gate break;
60567c478bd9Sstevel@tonic-gate case CKK_DSA:
60577c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PRI_DSA(pbk),
60587c478bd9Sstevel@tonic-gate KEY_PRI_DSA(old_pri_key_obj_p),
60597c478bd9Sstevel@tonic-gate sizeof (dsa_pri_key_t));
60607c478bd9Sstevel@tonic-gate
60617c478bd9Sstevel@tonic-gate /* copy prime */
60627c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_PRIME(pbk),
60637c478bd9Sstevel@tonic-gate KEY_PRI_DSA_PRIME(old_pri_key_obj_p));
60647c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60657c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60667c478bd9Sstevel@tonic-gate return (rv);
60677c478bd9Sstevel@tonic-gate }
60687c478bd9Sstevel@tonic-gate
60697c478bd9Sstevel@tonic-gate /* copy subprime */
60707c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_SUBPRIME(pbk),
60717c478bd9Sstevel@tonic-gate KEY_PRI_DSA_SUBPRIME(old_pri_key_obj_p));
60727c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60737c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60747c478bd9Sstevel@tonic-gate return (rv);
60757c478bd9Sstevel@tonic-gate }
60767c478bd9Sstevel@tonic-gate
60777c478bd9Sstevel@tonic-gate /* copy base */
60787c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_BASE(pbk),
60797c478bd9Sstevel@tonic-gate KEY_PRI_DSA_BASE(old_pri_key_obj_p));
60807c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60817c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60827c478bd9Sstevel@tonic-gate return (rv);
60837c478bd9Sstevel@tonic-gate }
60847c478bd9Sstevel@tonic-gate
60857c478bd9Sstevel@tonic-gate /* copy value */
60867c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_VALUE(pbk),
60877c478bd9Sstevel@tonic-gate KEY_PRI_DSA_VALUE(old_pri_key_obj_p));
60887c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
60897c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
60907c478bd9Sstevel@tonic-gate return (rv);
60917c478bd9Sstevel@tonic-gate }
60927c478bd9Sstevel@tonic-gate break;
60937c478bd9Sstevel@tonic-gate case CKK_DH:
60947c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PRI_DH(pbk),
60957c478bd9Sstevel@tonic-gate KEY_PRI_DH(old_pri_key_obj_p),
60967c478bd9Sstevel@tonic-gate sizeof (dh_pri_key_t));
60977c478bd9Sstevel@tonic-gate
60987c478bd9Sstevel@tonic-gate /* copy prime */
60997c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH_PRIME(pbk),
61007c478bd9Sstevel@tonic-gate KEY_PRI_DH_PRIME(old_pri_key_obj_p));
61017c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61027c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61037c478bd9Sstevel@tonic-gate return (rv);
61047c478bd9Sstevel@tonic-gate }
61057c478bd9Sstevel@tonic-gate
61067c478bd9Sstevel@tonic-gate /* copy base */
61077c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH_BASE(pbk),
61087c478bd9Sstevel@tonic-gate KEY_PRI_DH_BASE(old_pri_key_obj_p));
61097c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61107c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61117c478bd9Sstevel@tonic-gate return (rv);
61127c478bd9Sstevel@tonic-gate }
61137c478bd9Sstevel@tonic-gate
61147c478bd9Sstevel@tonic-gate /* copy value */
61157c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH_VALUE(pbk),
61167c478bd9Sstevel@tonic-gate KEY_PRI_DH_VALUE(old_pri_key_obj_p));
61177c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61187c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61197c478bd9Sstevel@tonic-gate return (rv);
61207c478bd9Sstevel@tonic-gate }
61217c478bd9Sstevel@tonic-gate break;
6122f9fbec18Smcpowers case CKK_EC:
6123f9fbec18Smcpowers (void) memcpy(KEY_PRI_EC(pbk),
6124f9fbec18Smcpowers KEY_PRI_EC(old_pri_key_obj_p),
6125f9fbec18Smcpowers sizeof (ec_pri_key_t));
6126f9fbec18Smcpowers
6127f9fbec18Smcpowers /* copy value */
6128f9fbec18Smcpowers rv = copy_bigint(KEY_PRI_EC_VALUE(pbk),
6129f9fbec18Smcpowers KEY_PRI_EC_VALUE(old_pri_key_obj_p));
6130f9fbec18Smcpowers if (rv != CKR_OK) {
6131f9fbec18Smcpowers free_private_key_attr(pbk, key_type);
6132f9fbec18Smcpowers return (rv);
6133f9fbec18Smcpowers }
6134f9fbec18Smcpowers break;
61357c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
61367c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PRI_DH942(pbk),
61377c478bd9Sstevel@tonic-gate KEY_PRI_DH942(old_pri_key_obj_p),
61387c478bd9Sstevel@tonic-gate sizeof (dh942_pri_key_t));
61397c478bd9Sstevel@tonic-gate
61407c478bd9Sstevel@tonic-gate /* copy prime */
61417c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH942_PRIME(pbk),
61427c478bd9Sstevel@tonic-gate KEY_PRI_DH942_PRIME(old_pri_key_obj_p));
61437c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61447c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61457c478bd9Sstevel@tonic-gate return (rv);
61467c478bd9Sstevel@tonic-gate }
61477c478bd9Sstevel@tonic-gate
61487c478bd9Sstevel@tonic-gate /* copy subprime */
61497c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH942_SUBPRIME(pbk),
61507c478bd9Sstevel@tonic-gate KEY_PRI_DH942_SUBPRIME(old_pri_key_obj_p));
61517c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61527c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61537c478bd9Sstevel@tonic-gate return (rv);
61547c478bd9Sstevel@tonic-gate }
61557c478bd9Sstevel@tonic-gate
61567c478bd9Sstevel@tonic-gate /* copy base */
61577c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH942_BASE(pbk),
61587c478bd9Sstevel@tonic-gate KEY_PRI_DH942_BASE(old_pri_key_obj_p));
61597c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61607c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61617c478bd9Sstevel@tonic-gate return (rv);
61627c478bd9Sstevel@tonic-gate }
61637c478bd9Sstevel@tonic-gate
61647c478bd9Sstevel@tonic-gate /* copy value */
61657c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DH942_VALUE(pbk),
61667c478bd9Sstevel@tonic-gate KEY_PRI_DH942_VALUE(old_pri_key_obj_p));
61677c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
61687c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type);
61697c478bd9Sstevel@tonic-gate return (rv);
61707c478bd9Sstevel@tonic-gate }
61717c478bd9Sstevel@tonic-gate break;
61727c478bd9Sstevel@tonic-gate default:
61737c478bd9Sstevel@tonic-gate break;
61747c478bd9Sstevel@tonic-gate }
61757c478bd9Sstevel@tonic-gate *new_pri_key_obj_p = pbk;
61767c478bd9Sstevel@tonic-gate return (rv);
61777c478bd9Sstevel@tonic-gate }
61787c478bd9Sstevel@tonic-gate
61797c478bd9Sstevel@tonic-gate static void
61807c478bd9Sstevel@tonic-gate free_domain_attr(domain_obj_t *domain, CK_KEY_TYPE key_type)
61817c478bd9Sstevel@tonic-gate {
61827c478bd9Sstevel@tonic-gate if (domain == NULL) {
61837c478bd9Sstevel@tonic-gate return;
61847c478bd9Sstevel@tonic-gate }
61857c478bd9Sstevel@tonic-gate
61867c478bd9Sstevel@tonic-gate switch (key_type) {
61877c478bd9Sstevel@tonic-gate case CKK_DSA:
61887c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DSA_PRIME(domain));
61897c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DSA_SUBPRIME(domain));
61907c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DSA_BASE(domain));
61917c478bd9Sstevel@tonic-gate break;
61927c478bd9Sstevel@tonic-gate case CKK_DH:
61937c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DH_PRIME(domain));
61947c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DH_BASE(domain));
61957c478bd9Sstevel@tonic-gate break;
61967c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
61977c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DH942_PRIME(domain));
61987c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DH942_SUBPRIME(domain));
61997c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_DOM_DH942_BASE(domain));
62007c478bd9Sstevel@tonic-gate break;
62017c478bd9Sstevel@tonic-gate default:
62027c478bd9Sstevel@tonic-gate break;
62037c478bd9Sstevel@tonic-gate }
62047c478bd9Sstevel@tonic-gate free(domain);
62057c478bd9Sstevel@tonic-gate }
62067c478bd9Sstevel@tonic-gate
62077c478bd9Sstevel@tonic-gate CK_RV
62087c478bd9Sstevel@tonic-gate soft_copy_domain_attr(domain_obj_t *old_domain_obj_p,
62097c478bd9Sstevel@tonic-gate domain_obj_t **new_domain_obj_p, CK_KEY_TYPE key_type)
62107c478bd9Sstevel@tonic-gate {
62117c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK;
62127c478bd9Sstevel@tonic-gate domain_obj_t *domain;
62137c478bd9Sstevel@tonic-gate
62147c478bd9Sstevel@tonic-gate domain = calloc(1, sizeof (domain_obj_t));
62157c478bd9Sstevel@tonic-gate if (domain == NULL) {
62167c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
62177c478bd9Sstevel@tonic-gate }
62187c478bd9Sstevel@tonic-gate
62197c478bd9Sstevel@tonic-gate switch (key_type) {
62207c478bd9Sstevel@tonic-gate case CKK_DSA:
62217c478bd9Sstevel@tonic-gate (void) memcpy(KEY_DOM_DSA(domain),
62227c478bd9Sstevel@tonic-gate KEY_DOM_DSA(old_domain_obj_p),
62237c478bd9Sstevel@tonic-gate sizeof (dsa_dom_key_t));
62247c478bd9Sstevel@tonic-gate
62257c478bd9Sstevel@tonic-gate /* copy prime */
62267c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DSA_PRIME(domain),
62277c478bd9Sstevel@tonic-gate KEY_DOM_DSA_PRIME(old_domain_obj_p));
62287c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62297c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62307c478bd9Sstevel@tonic-gate return (rv);
62317c478bd9Sstevel@tonic-gate }
62327c478bd9Sstevel@tonic-gate
62337c478bd9Sstevel@tonic-gate /* copy subprime */
62347c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DSA_SUBPRIME(domain),
62357c478bd9Sstevel@tonic-gate KEY_DOM_DSA_SUBPRIME(old_domain_obj_p));
62367c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62377c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62387c478bd9Sstevel@tonic-gate return (rv);
62397c478bd9Sstevel@tonic-gate }
62407c478bd9Sstevel@tonic-gate
62417c478bd9Sstevel@tonic-gate /* copy base */
62427c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DSA_BASE(domain),
62437c478bd9Sstevel@tonic-gate KEY_DOM_DSA_BASE(old_domain_obj_p));
62447c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62457c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62467c478bd9Sstevel@tonic-gate return (rv);
62477c478bd9Sstevel@tonic-gate }
62487c478bd9Sstevel@tonic-gate
62497c478bd9Sstevel@tonic-gate break;
62507c478bd9Sstevel@tonic-gate case CKK_DH:
62517c478bd9Sstevel@tonic-gate (void) memcpy(KEY_DOM_DH(domain),
62527c478bd9Sstevel@tonic-gate KEY_DOM_DH(old_domain_obj_p),
62537c478bd9Sstevel@tonic-gate sizeof (dh_dom_key_t));
62547c478bd9Sstevel@tonic-gate
62557c478bd9Sstevel@tonic-gate /* copy prime */
62567c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DH_PRIME(domain),
62577c478bd9Sstevel@tonic-gate KEY_DOM_DH_PRIME(old_domain_obj_p));
62587c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62597c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62607c478bd9Sstevel@tonic-gate return (rv);
62617c478bd9Sstevel@tonic-gate }
62627c478bd9Sstevel@tonic-gate
62637c478bd9Sstevel@tonic-gate /* copy base */
62647c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DH_BASE(domain),
62657c478bd9Sstevel@tonic-gate KEY_DOM_DH_BASE(old_domain_obj_p));
62667c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62677c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62687c478bd9Sstevel@tonic-gate return (rv);
62697c478bd9Sstevel@tonic-gate }
62707c478bd9Sstevel@tonic-gate
62717c478bd9Sstevel@tonic-gate break;
62727c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
62737c478bd9Sstevel@tonic-gate (void) memcpy(KEY_DOM_DH942(domain),
62747c478bd9Sstevel@tonic-gate KEY_DOM_DH942(old_domain_obj_p),
62757c478bd9Sstevel@tonic-gate sizeof (dh942_dom_key_t));
62767c478bd9Sstevel@tonic-gate
62777c478bd9Sstevel@tonic-gate /* copy prime */
62787c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DH942_PRIME(domain),
62797c478bd9Sstevel@tonic-gate KEY_DOM_DH942_PRIME(old_domain_obj_p));
62807c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62817c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62827c478bd9Sstevel@tonic-gate return (rv);
62837c478bd9Sstevel@tonic-gate }
62847c478bd9Sstevel@tonic-gate
62857c478bd9Sstevel@tonic-gate /* copy subprime */
62867c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DH942_SUBPRIME(domain),
62877c478bd9Sstevel@tonic-gate KEY_DOM_DH942_SUBPRIME(old_domain_obj_p));
62887c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62897c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62907c478bd9Sstevel@tonic-gate return (rv);
62917c478bd9Sstevel@tonic-gate }
62927c478bd9Sstevel@tonic-gate
62937c478bd9Sstevel@tonic-gate /* copy base */
62947c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_DOM_DH942_BASE(domain),
62957c478bd9Sstevel@tonic-gate KEY_DOM_DH942_BASE(old_domain_obj_p));
62967c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
62977c478bd9Sstevel@tonic-gate free_domain_attr(domain, key_type);
62987c478bd9Sstevel@tonic-gate return (rv);
62997c478bd9Sstevel@tonic-gate }
63007c478bd9Sstevel@tonic-gate
63017c478bd9Sstevel@tonic-gate break;
63027c478bd9Sstevel@tonic-gate default:
63037c478bd9Sstevel@tonic-gate break;
63047c478bd9Sstevel@tonic-gate }
63057c478bd9Sstevel@tonic-gate *new_domain_obj_p = domain;
63067c478bd9Sstevel@tonic-gate return (rv);
63077c478bd9Sstevel@tonic-gate }
63087c478bd9Sstevel@tonic-gate
63097c478bd9Sstevel@tonic-gate CK_RV
63107c478bd9Sstevel@tonic-gate soft_copy_secret_key_attr(secret_key_obj_t *old_secret_key_obj_p,
63117c478bd9Sstevel@tonic-gate secret_key_obj_t **new_secret_key_obj_p)
63127c478bd9Sstevel@tonic-gate {
63137c478bd9Sstevel@tonic-gate secret_key_obj_t *sk;
63147c478bd9Sstevel@tonic-gate
63157c478bd9Sstevel@tonic-gate sk = malloc(sizeof (secret_key_obj_t));
63167c478bd9Sstevel@tonic-gate if (sk == NULL) {
63177c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
63187c478bd9Sstevel@tonic-gate }
63197c478bd9Sstevel@tonic-gate (void) memcpy(sk, old_secret_key_obj_p, sizeof (secret_key_obj_t));
63207c478bd9Sstevel@tonic-gate
63217c478bd9Sstevel@tonic-gate /* copy the secret key value */
63227c478bd9Sstevel@tonic-gate sk->sk_value = malloc((sizeof (CK_BYTE) * sk->sk_value_len));
63237c478bd9Sstevel@tonic-gate if (sk->sk_value == NULL) {
63247c478bd9Sstevel@tonic-gate free(sk);
63257c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
63267c478bd9Sstevel@tonic-gate }
63277c478bd9Sstevel@tonic-gate (void) memcpy(sk->sk_value, old_secret_key_obj_p->sk_value,
63287c478bd9Sstevel@tonic-gate (sizeof (CK_BYTE) * sk->sk_value_len));
63297c478bd9Sstevel@tonic-gate
63307c478bd9Sstevel@tonic-gate /*
63317c478bd9Sstevel@tonic-gate * Copy the pre-expanded key schedule.
63327c478bd9Sstevel@tonic-gate */
63337c478bd9Sstevel@tonic-gate if (old_secret_key_obj_p->key_sched != NULL &&
63347c478bd9Sstevel@tonic-gate old_secret_key_obj_p->keysched_len > 0) {
63357c478bd9Sstevel@tonic-gate sk->key_sched = malloc(old_secret_key_obj_p->keysched_len);
63367c478bd9Sstevel@tonic-gate if (sk->key_sched == NULL) {
63377c478bd9Sstevel@tonic-gate free(sk);
63387c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
63397c478bd9Sstevel@tonic-gate }
63407c478bd9Sstevel@tonic-gate sk->keysched_len = old_secret_key_obj_p->keysched_len;
63417c478bd9Sstevel@tonic-gate (void) memcpy(sk->key_sched, old_secret_key_obj_p->key_sched,
63427c478bd9Sstevel@tonic-gate sk->keysched_len);
63437c478bd9Sstevel@tonic-gate }
63447c478bd9Sstevel@tonic-gate
63457c478bd9Sstevel@tonic-gate *new_secret_key_obj_p = sk;
63467c478bd9Sstevel@tonic-gate
63477c478bd9Sstevel@tonic-gate return (CKR_OK);
63487c478bd9Sstevel@tonic-gate }
63497c478bd9Sstevel@tonic-gate
63507c478bd9Sstevel@tonic-gate /*
63517c478bd9Sstevel@tonic-gate * If CKA_CLASS not given, guess CKA_CLASS using
63527c478bd9Sstevel@tonic-gate * attributes on template .
63537c478bd9Sstevel@tonic-gate *
63547c478bd9Sstevel@tonic-gate * Some attributes are specific to an object class. If one or more
63557c478bd9Sstevel@tonic-gate * of these attributes are in the template, make a list of classes
63567c478bd9Sstevel@tonic-gate * that can have these attributes. This would speed up the search later,
63577c478bd9Sstevel@tonic-gate * because we can immediately skip an object if the class of that
6358c2e31228SViswanathan Kannappan * object can not possibly contain one of the attributes.
63597c478bd9Sstevel@tonic-gate *
63607c478bd9Sstevel@tonic-gate */
63617c478bd9Sstevel@tonic-gate void
63627c478bd9Sstevel@tonic-gate soft_process_find_attr(CK_OBJECT_CLASS *pclasses,
63637c478bd9Sstevel@tonic-gate CK_ULONG *num_result_pclasses, CK_ATTRIBUTE_PTR pTemplate,
63647c478bd9Sstevel@tonic-gate CK_ULONG ulCount)
63657c478bd9Sstevel@tonic-gate {
63667c478bd9Sstevel@tonic-gate ulong_t i;
63677c478bd9Sstevel@tonic-gate int j;
63687c478bd9Sstevel@tonic-gate boolean_t pub_found = B_FALSE,
63697c478bd9Sstevel@tonic-gate priv_found = B_FALSE,
63707c478bd9Sstevel@tonic-gate secret_found = B_FALSE,
63717c478bd9Sstevel@tonic-gate domain_found = B_FALSE,
63727c478bd9Sstevel@tonic-gate hardware_found = B_FALSE,
63737c478bd9Sstevel@tonic-gate cert_found = B_FALSE;
63747c478bd9Sstevel@tonic-gate int num_pub_key_attrs, num_priv_key_attrs,
63757c478bd9Sstevel@tonic-gate num_secret_key_attrs, num_domain_attrs,
63767c478bd9Sstevel@tonic-gate num_hardware_attrs, num_cert_attrs;
63777c478bd9Sstevel@tonic-gate int num_pclasses = 0;
63787c478bd9Sstevel@tonic-gate
63797c478bd9Sstevel@tonic-gate for (i = 0; i < ulCount; i++) {
63807c478bd9Sstevel@tonic-gate if (pTemplate[i].type == CKA_CLASS) {
63817c478bd9Sstevel@tonic-gate /*
63827c478bd9Sstevel@tonic-gate * don't need to guess the class, it is specified.
63837c478bd9Sstevel@tonic-gate * Just record the class, and return.
63847c478bd9Sstevel@tonic-gate */
63857c478bd9Sstevel@tonic-gate pclasses[0] =
63867c478bd9Sstevel@tonic-gate (*((CK_OBJECT_CLASS *)pTemplate[i].pValue));
63877c478bd9Sstevel@tonic-gate *num_result_pclasses = 1;
63887c478bd9Sstevel@tonic-gate return;
63897c478bd9Sstevel@tonic-gate }
63907c478bd9Sstevel@tonic-gate }
63917c478bd9Sstevel@tonic-gate
63927c478bd9Sstevel@tonic-gate num_pub_key_attrs =
63937c478bd9Sstevel@tonic-gate sizeof (PUB_KEY_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE);
63947c478bd9Sstevel@tonic-gate num_priv_key_attrs =
63957c478bd9Sstevel@tonic-gate sizeof (PRIV_KEY_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE);
63967c478bd9Sstevel@tonic-gate num_secret_key_attrs =
63977c478bd9Sstevel@tonic-gate sizeof (SECRET_KEY_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE);
63987c478bd9Sstevel@tonic-gate num_domain_attrs =
63997c478bd9Sstevel@tonic-gate sizeof (DOMAIN_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE);
64007c478bd9Sstevel@tonic-gate num_hardware_attrs =
64017c478bd9Sstevel@tonic-gate sizeof (HARDWARE_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE);
64027c478bd9Sstevel@tonic-gate num_cert_attrs =
64037c478bd9Sstevel@tonic-gate sizeof (CERT_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE);
64047c478bd9Sstevel@tonic-gate
64057c478bd9Sstevel@tonic-gate /*
64067c478bd9Sstevel@tonic-gate * Get the list of objects class that might contain
64077c478bd9Sstevel@tonic-gate * some attributes.
64087c478bd9Sstevel@tonic-gate */
64097c478bd9Sstevel@tonic-gate for (i = 0; i < ulCount; i++) {
64107c478bd9Sstevel@tonic-gate /*
64117c478bd9Sstevel@tonic-gate * only check if this attribute can belong to public key object
64127c478bd9Sstevel@tonic-gate * class if public key object isn't already in the list
64137c478bd9Sstevel@tonic-gate */
64147c478bd9Sstevel@tonic-gate if (!pub_found) {
64157c478bd9Sstevel@tonic-gate for (j = 0; j < num_pub_key_attrs; j++) {
64167c478bd9Sstevel@tonic-gate if (pTemplate[i].type == PUB_KEY_ATTRS[j]) {
64177c478bd9Sstevel@tonic-gate pub_found = B_TRUE;
64187c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] =
64197c478bd9Sstevel@tonic-gate CKO_PUBLIC_KEY;
64207c478bd9Sstevel@tonic-gate break;
64217c478bd9Sstevel@tonic-gate }
64227c478bd9Sstevel@tonic-gate }
64237c478bd9Sstevel@tonic-gate }
64247c478bd9Sstevel@tonic-gate
64257c478bd9Sstevel@tonic-gate if (!priv_found) {
64267c478bd9Sstevel@tonic-gate for (j = 0; j < num_priv_key_attrs; j++) {
64277c478bd9Sstevel@tonic-gate if (pTemplate[i].type == PRIV_KEY_ATTRS[j]) {
64287c478bd9Sstevel@tonic-gate priv_found = B_TRUE;
64297c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] =
64307c478bd9Sstevel@tonic-gate CKO_PRIVATE_KEY;
64317c478bd9Sstevel@tonic-gate break;
64327c478bd9Sstevel@tonic-gate }
64337c478bd9Sstevel@tonic-gate }
64347c478bd9Sstevel@tonic-gate }
64357c478bd9Sstevel@tonic-gate
64367c478bd9Sstevel@tonic-gate if (!secret_found) {
64377c478bd9Sstevel@tonic-gate for (j = 0; j < num_secret_key_attrs; j++) {
64387c478bd9Sstevel@tonic-gate if (pTemplate[i].type == SECRET_KEY_ATTRS[j]) {
64397c478bd9Sstevel@tonic-gate secret_found = B_TRUE;
64407c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] =
64417c478bd9Sstevel@tonic-gate CKO_SECRET_KEY;
64427c478bd9Sstevel@tonic-gate break;
64437c478bd9Sstevel@tonic-gate }
64447c478bd9Sstevel@tonic-gate }
64457c478bd9Sstevel@tonic-gate }
64467c478bd9Sstevel@tonic-gate
64477c478bd9Sstevel@tonic-gate if (!domain_found) {
64487c478bd9Sstevel@tonic-gate for (j = 0; j < num_domain_attrs; j++) {
64497c478bd9Sstevel@tonic-gate if (pTemplate[i].type == DOMAIN_ATTRS[j]) {
64507c478bd9Sstevel@tonic-gate domain_found = B_TRUE;
64517c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] =
64527c478bd9Sstevel@tonic-gate CKO_DOMAIN_PARAMETERS;
64537c478bd9Sstevel@tonic-gate break;
64547c478bd9Sstevel@tonic-gate }
64557c478bd9Sstevel@tonic-gate }
64567c478bd9Sstevel@tonic-gate }
64577c478bd9Sstevel@tonic-gate
64587c478bd9Sstevel@tonic-gate if (!hardware_found) {
64597c478bd9Sstevel@tonic-gate for (j = 0; j < num_hardware_attrs; j++) {
64607c478bd9Sstevel@tonic-gate if (pTemplate[i].type == HARDWARE_ATTRS[j]) {
64617c478bd9Sstevel@tonic-gate hardware_found = B_TRUE;
64627c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] =
64637c478bd9Sstevel@tonic-gate CKO_HW_FEATURE;
64647c478bd9Sstevel@tonic-gate break;
64657c478bd9Sstevel@tonic-gate }
64667c478bd9Sstevel@tonic-gate }
64677c478bd9Sstevel@tonic-gate }
64687c478bd9Sstevel@tonic-gate
64697c478bd9Sstevel@tonic-gate if (!cert_found) {
64707c478bd9Sstevel@tonic-gate for (j = 0; j < num_cert_attrs; j++) {
64717c478bd9Sstevel@tonic-gate if (pTemplate[i].type == CERT_ATTRS[j]) {
64727c478bd9Sstevel@tonic-gate cert_found = B_TRUE;
64737c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] =
64747c478bd9Sstevel@tonic-gate CKO_CERTIFICATE;
64757c478bd9Sstevel@tonic-gate break;
64767c478bd9Sstevel@tonic-gate }
64777c478bd9Sstevel@tonic-gate }
64787c478bd9Sstevel@tonic-gate }
64797c478bd9Sstevel@tonic-gate }
64807c478bd9Sstevel@tonic-gate *num_result_pclasses = num_pclasses;
64817c478bd9Sstevel@tonic-gate }
64827c478bd9Sstevel@tonic-gate
64837c478bd9Sstevel@tonic-gate boolean_t
64847c478bd9Sstevel@tonic-gate soft_find_match_attrs(soft_object_t *obj, CK_OBJECT_CLASS *pclasses,
64857c478bd9Sstevel@tonic-gate CK_ULONG num_pclasses, CK_ATTRIBUTE *template, CK_ULONG num_attr)
64867c478bd9Sstevel@tonic-gate {
64877c478bd9Sstevel@tonic-gate ulong_t i;
64887c478bd9Sstevel@tonic-gate CK_ATTRIBUTE *tmpl_attr, *obj_attr;
64897c478bd9Sstevel@tonic-gate cert_attr_t *cert_attr;
64907c478bd9Sstevel@tonic-gate uint64_t attr_mask;
64917c478bd9Sstevel@tonic-gate biginteger_t *bigint;
64927c478bd9Sstevel@tonic-gate boolean_t compare_attr, compare_bigint, compare_boolean;
64937c478bd9Sstevel@tonic-gate boolean_t compare_cert_val, compare_cert_type;
64947c478bd9Sstevel@tonic-gate
64957c478bd9Sstevel@tonic-gate /*
64967c478bd9Sstevel@tonic-gate * Check if the class of this object match with any
6497c2e31228SViswanathan Kannappan * of object classes that can possibly contain the
64987c478bd9Sstevel@tonic-gate * requested attributes.
64997c478bd9Sstevel@tonic-gate */
65007c478bd9Sstevel@tonic-gate if (num_pclasses > 0) {
65017c478bd9Sstevel@tonic-gate for (i = 0; i < num_pclasses; i++) {
65027c478bd9Sstevel@tonic-gate if (obj->class == pclasses[i]) {
65037c478bd9Sstevel@tonic-gate break;
65047c478bd9Sstevel@tonic-gate }
65057c478bd9Sstevel@tonic-gate }
65067c478bd9Sstevel@tonic-gate if (i == num_pclasses) {
65077c478bd9Sstevel@tonic-gate /*
6508c2e31228SViswanathan Kannappan * this object can't possibly contain one or
65097c478bd9Sstevel@tonic-gate * more attributes, don't need to check this object
65107c478bd9Sstevel@tonic-gate */
65117c478bd9Sstevel@tonic-gate return (B_FALSE);
65127c478bd9Sstevel@tonic-gate }
65137c478bd9Sstevel@tonic-gate }
65147c478bd9Sstevel@tonic-gate
65157c478bd9Sstevel@tonic-gate /* need to examine everything */
65167c478bd9Sstevel@tonic-gate for (i = 0; i < num_attr; i++) {
65177c478bd9Sstevel@tonic-gate tmpl_attr = &(template[i]);
65187c478bd9Sstevel@tonic-gate compare_attr = B_FALSE;
65197c478bd9Sstevel@tonic-gate compare_bigint = B_FALSE;
65207c478bd9Sstevel@tonic-gate compare_boolean = B_FALSE;
65217c478bd9Sstevel@tonic-gate compare_cert_val = B_FALSE;
65227c478bd9Sstevel@tonic-gate compare_cert_type = B_FALSE;
65237c478bd9Sstevel@tonic-gate switch (tmpl_attr->type) {
65247c478bd9Sstevel@tonic-gate /* First, check the most common attributes */
65257c478bd9Sstevel@tonic-gate case CKA_CLASS:
65267c478bd9Sstevel@tonic-gate if (*((CK_OBJECT_CLASS *)tmpl_attr->pValue) !=
65277c478bd9Sstevel@tonic-gate obj->class) {
65287c478bd9Sstevel@tonic-gate return (B_FALSE);
65297c478bd9Sstevel@tonic-gate }
65307c478bd9Sstevel@tonic-gate break;
65317c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE:
65327c478bd9Sstevel@tonic-gate if (*((CK_KEY_TYPE *)tmpl_attr->pValue) !=
65337c478bd9Sstevel@tonic-gate obj->key_type) {
65347c478bd9Sstevel@tonic-gate return (B_FALSE);
65357c478bd9Sstevel@tonic-gate }
65367c478bd9Sstevel@tonic-gate break;
65377c478bd9Sstevel@tonic-gate case CKA_ENCRYPT:
65387c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & ENCRYPT_BOOL_ON;
65397c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65407c478bd9Sstevel@tonic-gate break;
65417c478bd9Sstevel@tonic-gate case CKA_DECRYPT:
65427c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & DECRYPT_BOOL_ON;
65437c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65447c478bd9Sstevel@tonic-gate break;
65457c478bd9Sstevel@tonic-gate case CKA_WRAP:
65467c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & WRAP_BOOL_ON;
65477c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65487c478bd9Sstevel@tonic-gate break;
65497c478bd9Sstevel@tonic-gate case CKA_UNWRAP:
65507c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & UNWRAP_BOOL_ON;
65517c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65527c478bd9Sstevel@tonic-gate break;
65537c478bd9Sstevel@tonic-gate case CKA_SIGN:
65547c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & SIGN_BOOL_ON;
65557c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65567c478bd9Sstevel@tonic-gate break;
65577c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER:
65587c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
65597c478bd9Sstevel@tonic-gate SIGN_RECOVER_BOOL_ON;
65607c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65617c478bd9Sstevel@tonic-gate break;
65627c478bd9Sstevel@tonic-gate case CKA_VERIFY:
65637c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & VERIFY_BOOL_ON;
65647c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65657c478bd9Sstevel@tonic-gate break;
65667c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER:
65677c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
65687c478bd9Sstevel@tonic-gate VERIFY_RECOVER_BOOL_ON;
65697c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65707c478bd9Sstevel@tonic-gate break;
65717c478bd9Sstevel@tonic-gate case CKA_DERIVE:
65727c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & DERIVE_BOOL_ON;
65737c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65747c478bd9Sstevel@tonic-gate break;
65757c478bd9Sstevel@tonic-gate case CKA_LOCAL:
65767c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & LOCAL_BOOL_ON;
65777c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65787c478bd9Sstevel@tonic-gate break;
65797c478bd9Sstevel@tonic-gate case CKA_SENSITIVE:
65807c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & SENSITIVE_BOOL_ON;
65817c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65827c478bd9Sstevel@tonic-gate break;
65837c478bd9Sstevel@tonic-gate case CKA_SECONDARY_AUTH:
65847c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
65857c478bd9Sstevel@tonic-gate SECONDARY_AUTH_BOOL_ON;
65867c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65877c478bd9Sstevel@tonic-gate break;
65887c478bd9Sstevel@tonic-gate case CKA_TRUSTED:
65897c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & TRUSTED_BOOL_ON;
65907c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65917c478bd9Sstevel@tonic-gate break;
65927c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE:
65937c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
65947c478bd9Sstevel@tonic-gate EXTRACTABLE_BOOL_ON;
65957c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
65967c478bd9Sstevel@tonic-gate break;
65977c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE:
65987c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
65997c478bd9Sstevel@tonic-gate ALWAYS_SENSITIVE_BOOL_ON;
66007c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
66017c478bd9Sstevel@tonic-gate break;
66027c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE:
66037c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
66047c478bd9Sstevel@tonic-gate NEVER_EXTRACTABLE_BOOL_ON;
66057c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
66067c478bd9Sstevel@tonic-gate break;
66077c478bd9Sstevel@tonic-gate case CKA_TOKEN:
66087c478bd9Sstevel@tonic-gate attr_mask = (obj->object_type) & TOKEN_OBJECT;
66097c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
66107c478bd9Sstevel@tonic-gate break;
66117c478bd9Sstevel@tonic-gate case CKA_PRIVATE:
66127c478bd9Sstevel@tonic-gate attr_mask = (obj->object_type) & PRIVATE_OBJECT;
66137c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE;
66147c478bd9Sstevel@tonic-gate break;
66157c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE:
66167c478bd9Sstevel@tonic-gate {
66177c478bd9Sstevel@tonic-gate CK_BBOOL bval;
66187c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) &
66197c478bd9Sstevel@tonic-gate NOT_MODIFIABLE_BOOL_ON;
66207c478bd9Sstevel@tonic-gate
66217c478bd9Sstevel@tonic-gate if (attr_mask) {
66227c478bd9Sstevel@tonic-gate bval = FALSE;
66237c478bd9Sstevel@tonic-gate } else {
66247c478bd9Sstevel@tonic-gate bval = TRUE;
66257c478bd9Sstevel@tonic-gate }
66267c478bd9Sstevel@tonic-gate if (bval != *((CK_BBOOL *)tmpl_attr->pValue)) {
66277c478bd9Sstevel@tonic-gate return (B_FALSE);
66287c478bd9Sstevel@tonic-gate }
66297c478bd9Sstevel@tonic-gate break;
66307c478bd9Sstevel@tonic-gate }
66317c478bd9Sstevel@tonic-gate case CKA_OWNER:
66327c478bd9Sstevel@tonic-gate /*
66337c478bd9Sstevel@tonic-gate * For X.509 attribute certificate object, get its
66347c478bd9Sstevel@tonic-gate * CKA_OWNER attribute from the x509_attr_cert_t struct.
66357c478bd9Sstevel@tonic-gate */
66367c478bd9Sstevel@tonic-gate if ((obj->class == CKO_CERTIFICATE) &&
66377c478bd9Sstevel@tonic-gate (obj->cert_type == CKC_X_509_ATTR_CERT)) {
66387c478bd9Sstevel@tonic-gate cert_attr = X509_ATTR_CERT_OWNER(obj);
66397c478bd9Sstevel@tonic-gate compare_cert_val = B_TRUE;
66407c478bd9Sstevel@tonic-gate }
66417c478bd9Sstevel@tonic-gate break;
66427c478bd9Sstevel@tonic-gate case CKA_SUBJECT:
66437c478bd9Sstevel@tonic-gate /*
66447c478bd9Sstevel@tonic-gate * For X.509 certificate object, get its CKA_SUBJECT
66457c478bd9Sstevel@tonic-gate * attribute from the x509_cert_t struct (not from
66467c478bd9Sstevel@tonic-gate * the extra_attrlistp).
66477c478bd9Sstevel@tonic-gate */
66487c478bd9Sstevel@tonic-gate if ((obj->class == CKO_CERTIFICATE) &&
66497c478bd9Sstevel@tonic-gate (obj->cert_type == CKC_X_509)) {
66507c478bd9Sstevel@tonic-gate cert_attr = X509_CERT_SUBJECT(obj);
66517c478bd9Sstevel@tonic-gate compare_cert_val = B_TRUE;
66527c478bd9Sstevel@tonic-gate break;
66537c478bd9Sstevel@tonic-gate }
66547c478bd9Sstevel@tonic-gate /*FALLTHRU*/
66557c478bd9Sstevel@tonic-gate case CKA_ID:
66567c478bd9Sstevel@tonic-gate case CKA_START_DATE:
66577c478bd9Sstevel@tonic-gate case CKA_END_DATE:
66587c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM:
66597c478bd9Sstevel@tonic-gate case CKA_LABEL:
66607c478bd9Sstevel@tonic-gate case CKA_ISSUER:
66617c478bd9Sstevel@tonic-gate case CKA_SERIAL_NUMBER:
66627c478bd9Sstevel@tonic-gate case CKA_AC_ISSUER:
66637c478bd9Sstevel@tonic-gate case CKA_ATTR_TYPES:
66647c478bd9Sstevel@tonic-gate /* find these attributes from extra_attrlistp */
66657c478bd9Sstevel@tonic-gate obj_attr = get_extra_attr(tmpl_attr->type, obj);
66667c478bd9Sstevel@tonic-gate compare_attr = B_TRUE;
66677c478bd9Sstevel@tonic-gate break;
66687c478bd9Sstevel@tonic-gate case CKA_CERTIFICATE_TYPE:
66697c478bd9Sstevel@tonic-gate compare_cert_type = B_TRUE;
66707c478bd9Sstevel@tonic-gate break;
66717c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN:
66727c478bd9Sstevel@tonic-gate /* only secret key has this attribute */
66737c478bd9Sstevel@tonic-gate if (obj->class == CKO_SECRET_KEY) {
66747c478bd9Sstevel@tonic-gate if (*((CK_ULONG *)tmpl_attr->pValue) !=
66757c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(obj)) {
66767c478bd9Sstevel@tonic-gate return (B_FALSE);
66777c478bd9Sstevel@tonic-gate }
66787c478bd9Sstevel@tonic-gate } else {
66797c478bd9Sstevel@tonic-gate return (B_FALSE);
66807c478bd9Sstevel@tonic-gate }
66817c478bd9Sstevel@tonic-gate break;
66827c478bd9Sstevel@tonic-gate case CKA_VALUE:
66837c478bd9Sstevel@tonic-gate switch (obj->class) {
66847c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY:
66857c478bd9Sstevel@tonic-gate /*
66867c478bd9Sstevel@tonic-gate * secret_key_obj_t is the same as
66877c478bd9Sstevel@tonic-gate * biginteger_t
66887c478bd9Sstevel@tonic-gate */
66897c478bd9Sstevel@tonic-gate bigint = (biginteger_t *)OBJ_SEC(obj);
66907c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
66917c478bd9Sstevel@tonic-gate break;
66927c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY:
66937c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_DSA) {
66947c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_VALUE(obj);
66957c478bd9Sstevel@tonic-gate } else if (obj->key_type == CKK_DH) {
66967c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH_VALUE(obj);
66977c478bd9Sstevel@tonic-gate } else if (obj->key_type == CKK_X9_42_DH) {
66987c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH942_VALUE(obj);
66997c478bd9Sstevel@tonic-gate } else {
67007c478bd9Sstevel@tonic-gate return (B_FALSE);
67017c478bd9Sstevel@tonic-gate }
67027c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67037c478bd9Sstevel@tonic-gate break;
67047c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY:
67057c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_DSA) {
67067c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_VALUE(obj);
67077c478bd9Sstevel@tonic-gate } else if (obj->key_type == CKK_DH) {
67087c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH_VALUE(obj);
67097c478bd9Sstevel@tonic-gate } else if (obj->key_type == CKK_X9_42_DH) {
67107c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH942_VALUE(obj);
67117c478bd9Sstevel@tonic-gate } else {
67127c478bd9Sstevel@tonic-gate return (B_FALSE);
67137c478bd9Sstevel@tonic-gate }
67147c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67157c478bd9Sstevel@tonic-gate break;
67167c478bd9Sstevel@tonic-gate case CKO_CERTIFICATE:
67177c478bd9Sstevel@tonic-gate if (obj->cert_type == CKC_X_509) {
67187c478bd9Sstevel@tonic-gate cert_attr = X509_CERT_VALUE(obj);
67197c478bd9Sstevel@tonic-gate } else if (obj->cert_type ==
67207c478bd9Sstevel@tonic-gate CKC_X_509_ATTR_CERT) {
67217c478bd9Sstevel@tonic-gate cert_attr = X509_ATTR_CERT_VALUE(obj);
67227c478bd9Sstevel@tonic-gate }
67237c478bd9Sstevel@tonic-gate compare_cert_val = B_TRUE;
67247c478bd9Sstevel@tonic-gate break;
67257c478bd9Sstevel@tonic-gate default:
67267c478bd9Sstevel@tonic-gate return (B_FALSE);
67277c478bd9Sstevel@tonic-gate }
67287c478bd9Sstevel@tonic-gate break;
67297c478bd9Sstevel@tonic-gate case CKA_MODULUS:
67307c478bd9Sstevel@tonic-gate /* only RSA public and private key have this attr */
67317c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_RSA) {
67327c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) {
67337c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_RSA_MOD(obj);
67347c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) {
67357c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_MOD(obj);
67367c478bd9Sstevel@tonic-gate } else {
67377c478bd9Sstevel@tonic-gate return (B_FALSE);
67387c478bd9Sstevel@tonic-gate }
67397c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67407c478bd9Sstevel@tonic-gate } else {
67417c478bd9Sstevel@tonic-gate return (B_FALSE);
67427c478bd9Sstevel@tonic-gate }
67437c478bd9Sstevel@tonic-gate break;
67447c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS:
67457c478bd9Sstevel@tonic-gate /* only RSA public key has this attribute */
67467c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
67477c478bd9Sstevel@tonic-gate (obj->class == CKO_PUBLIC_KEY)) {
67487c478bd9Sstevel@tonic-gate CK_ULONG mod_bits = OBJ_PUB_RSA_MOD_BITS(obj);
67497c478bd9Sstevel@tonic-gate if (mod_bits !=
67507c478bd9Sstevel@tonic-gate *((CK_ULONG *)tmpl_attr->pValue)) {
67517c478bd9Sstevel@tonic-gate return (B_FALSE);
67527c478bd9Sstevel@tonic-gate }
67537c478bd9Sstevel@tonic-gate } else {
67547c478bd9Sstevel@tonic-gate return (B_FALSE);
67557c478bd9Sstevel@tonic-gate }
67567c478bd9Sstevel@tonic-gate break;
67577c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT:
67587c478bd9Sstevel@tonic-gate /* only RSA public and private key have this attr */
67597c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_RSA) {
67607c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) {
67617c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_RSA_PUBEXPO(obj);
67627c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) {
67637c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PUBEXPO(obj);
67647c478bd9Sstevel@tonic-gate } else {
67657c478bd9Sstevel@tonic-gate return (B_FALSE);
67667c478bd9Sstevel@tonic-gate }
67677c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67687c478bd9Sstevel@tonic-gate } else {
67697c478bd9Sstevel@tonic-gate return (B_FALSE);
67707c478bd9Sstevel@tonic-gate }
67717c478bd9Sstevel@tonic-gate break;
67727c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT:
67737c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */
67747c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
67757c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
67767c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PRIEXPO(obj);
67777c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67787c478bd9Sstevel@tonic-gate } else {
67797c478bd9Sstevel@tonic-gate return (B_FALSE);
67807c478bd9Sstevel@tonic-gate }
67817c478bd9Sstevel@tonic-gate break;
67827c478bd9Sstevel@tonic-gate case CKA_PRIME_1:
67837c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */
67847c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
67857c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
67867c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PRIME1(obj);
67877c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67887c478bd9Sstevel@tonic-gate } else {
67897c478bd9Sstevel@tonic-gate return (B_FALSE);
67907c478bd9Sstevel@tonic-gate }
67917c478bd9Sstevel@tonic-gate break;
67927c478bd9Sstevel@tonic-gate case CKA_PRIME_2:
67937c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */
67947c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
67957c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
67967c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PRIME2(obj);
67977c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
67987c478bd9Sstevel@tonic-gate } else {
67997c478bd9Sstevel@tonic-gate return (B_FALSE);
68007c478bd9Sstevel@tonic-gate }
68017c478bd9Sstevel@tonic-gate break;
68027c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1:
68037c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */
68047c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
68057c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
68067c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_EXPO1(obj);
68077c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
68087c478bd9Sstevel@tonic-gate } else {
68097c478bd9Sstevel@tonic-gate return (B_FALSE);
68107c478bd9Sstevel@tonic-gate }
68117c478bd9Sstevel@tonic-gate break;
68127c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2:
68137c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */
68147c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
68157c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
68167c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_EXPO2(obj);
68177c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
68187c478bd9Sstevel@tonic-gate } else {
68197c478bd9Sstevel@tonic-gate return (B_FALSE);
68207c478bd9Sstevel@tonic-gate }
68217c478bd9Sstevel@tonic-gate break;
68227c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT:
68237c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */
68247c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) &&
68257c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
68267c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_COEF(obj);
68277c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
68287c478bd9Sstevel@tonic-gate } else {
68297c478bd9Sstevel@tonic-gate return (B_FALSE);
68307c478bd9Sstevel@tonic-gate }
68317c478bd9Sstevel@tonic-gate break;
68327c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS:
68337c478bd9Sstevel@tonic-gate /* only Diffie-Hellman private key has this attr */
68347c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_DH) &&
68357c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) {
68367c478bd9Sstevel@tonic-gate CK_ULONG val_bits = OBJ_PRI_DH_VAL_BITS(obj);
68377c478bd9Sstevel@tonic-gate if (val_bits !=
68387c478bd9Sstevel@tonic-gate *((CK_ULONG *)tmpl_attr->pValue)) {
68397c478bd9Sstevel@tonic-gate return (B_FALSE);
68407c478bd9Sstevel@tonic-gate }
68417c478bd9Sstevel@tonic-gate } else {
68427c478bd9Sstevel@tonic-gate return (B_FALSE);
68437c478bd9Sstevel@tonic-gate }
68447c478bd9Sstevel@tonic-gate break;
68457c478bd9Sstevel@tonic-gate case CKA_PRIME:
68467c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) {
68477c478bd9Sstevel@tonic-gate switch (obj->key_type) {
68487c478bd9Sstevel@tonic-gate case CKK_DSA:
68497c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_PRIME(obj);
68507c478bd9Sstevel@tonic-gate break;
68517c478bd9Sstevel@tonic-gate case CKK_DH:
68527c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH_PRIME(obj);
68537c478bd9Sstevel@tonic-gate break;
68547c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
68557c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH942_PRIME(obj);
68567c478bd9Sstevel@tonic-gate break;
68577c478bd9Sstevel@tonic-gate default:
68587c478bd9Sstevel@tonic-gate return (B_FALSE);
68597c478bd9Sstevel@tonic-gate }
68607c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) {
68617c478bd9Sstevel@tonic-gate switch (obj->key_type) {
68627c478bd9Sstevel@tonic-gate case CKK_DSA:
68637c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_PRIME(obj);
68647c478bd9Sstevel@tonic-gate break;
68657c478bd9Sstevel@tonic-gate case CKK_DH:
68667c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH_PRIME(obj);
68677c478bd9Sstevel@tonic-gate break;
68687c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
68697c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH942_PRIME(obj);
68707c478bd9Sstevel@tonic-gate break;
68717c478bd9Sstevel@tonic-gate default:
68727c478bd9Sstevel@tonic-gate return (B_FALSE);
68737c478bd9Sstevel@tonic-gate }
68747c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_DOMAIN_PARAMETERS) {
68757c478bd9Sstevel@tonic-gate switch (obj->key_type) {
68767c478bd9Sstevel@tonic-gate case CKK_DSA:
68777c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DSA_PRIME(obj);
68787c478bd9Sstevel@tonic-gate break;
68797c478bd9Sstevel@tonic-gate case CKK_DH:
68807c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DH_PRIME(obj);
68817c478bd9Sstevel@tonic-gate break;
68827c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
68837c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DH942_PRIME(obj);
68847c478bd9Sstevel@tonic-gate break;
68857c478bd9Sstevel@tonic-gate default:
68867c478bd9Sstevel@tonic-gate return (B_FALSE);
68877c478bd9Sstevel@tonic-gate }
68887c478bd9Sstevel@tonic-gate } else {
68897c478bd9Sstevel@tonic-gate return (B_FALSE);
68907c478bd9Sstevel@tonic-gate }
68917c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
68927c478bd9Sstevel@tonic-gate break;
68937c478bd9Sstevel@tonic-gate case CKA_SUBPRIME:
68947c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) {
68957c478bd9Sstevel@tonic-gate switch (obj->key_type) {
68967c478bd9Sstevel@tonic-gate case CKK_DSA:
68977c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_SUBPRIME(obj);
68987c478bd9Sstevel@tonic-gate break;
68997c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
69007c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH942_SUBPRIME(obj);
69017c478bd9Sstevel@tonic-gate break;
69027c478bd9Sstevel@tonic-gate default:
69037c478bd9Sstevel@tonic-gate return (B_FALSE);
69047c478bd9Sstevel@tonic-gate }
69057c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) {
69067c478bd9Sstevel@tonic-gate switch (obj->key_type) {
69077c478bd9Sstevel@tonic-gate case CKK_DSA:
69087c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_SUBPRIME(obj);
69097c478bd9Sstevel@tonic-gate break;
69107c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
69117c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH942_SUBPRIME(obj);
69127c478bd9Sstevel@tonic-gate break;
69137c478bd9Sstevel@tonic-gate default:
69147c478bd9Sstevel@tonic-gate return (B_FALSE);
69157c478bd9Sstevel@tonic-gate }
69167c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_DOMAIN_PARAMETERS) {
69177c478bd9Sstevel@tonic-gate switch (obj->key_type) {
69187c478bd9Sstevel@tonic-gate case CKK_DSA:
69197c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DSA_SUBPRIME(obj);
69207c478bd9Sstevel@tonic-gate break;
69217c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
69227c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DH942_SUBPRIME(obj);
69237c478bd9Sstevel@tonic-gate break;
69247c478bd9Sstevel@tonic-gate default:
69257c478bd9Sstevel@tonic-gate return (B_FALSE);
69267c478bd9Sstevel@tonic-gate }
69277c478bd9Sstevel@tonic-gate } else {
69287c478bd9Sstevel@tonic-gate return (B_FALSE);
69297c478bd9Sstevel@tonic-gate }
69307c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
69317c478bd9Sstevel@tonic-gate break;
69327c478bd9Sstevel@tonic-gate case CKA_BASE:
69337c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) {
69347c478bd9Sstevel@tonic-gate switch (obj->key_type) {
69357c478bd9Sstevel@tonic-gate case CKK_DSA:
69367c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_BASE(obj);
69377c478bd9Sstevel@tonic-gate break;
69387c478bd9Sstevel@tonic-gate case CKK_DH:
69397c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH_BASE(obj);
69407c478bd9Sstevel@tonic-gate break;
69417c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
69427c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DH942_BASE(obj);
69437c478bd9Sstevel@tonic-gate break;
69447c478bd9Sstevel@tonic-gate default:
69457c478bd9Sstevel@tonic-gate return (B_FALSE);
69467c478bd9Sstevel@tonic-gate }
69477c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) {
69487c478bd9Sstevel@tonic-gate switch (obj->key_type) {
69497c478bd9Sstevel@tonic-gate case CKK_DSA:
69507c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_BASE(obj);
69517c478bd9Sstevel@tonic-gate break;
69527c478bd9Sstevel@tonic-gate case CKK_DH:
69537c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH_BASE(obj);
69547c478bd9Sstevel@tonic-gate break;
69557c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
69567c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DH942_BASE(obj);
69577c478bd9Sstevel@tonic-gate break;
69587c478bd9Sstevel@tonic-gate default:
69597c478bd9Sstevel@tonic-gate return (B_FALSE);
69607c478bd9Sstevel@tonic-gate }
69617c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_DOMAIN_PARAMETERS) {
69627c478bd9Sstevel@tonic-gate switch (obj->key_type) {
69637c478bd9Sstevel@tonic-gate case CKK_DSA:
69647c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DSA_BASE(obj);
69657c478bd9Sstevel@tonic-gate break;
69667c478bd9Sstevel@tonic-gate case CKK_DH:
69677c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DH_BASE(obj);
69687c478bd9Sstevel@tonic-gate break;
69697c478bd9Sstevel@tonic-gate case CKK_X9_42_DH:
69707c478bd9Sstevel@tonic-gate bigint = OBJ_DOM_DH942_BASE(obj);
69717c478bd9Sstevel@tonic-gate break;
69727c478bd9Sstevel@tonic-gate default:
69737c478bd9Sstevel@tonic-gate return (B_FALSE);
69747c478bd9Sstevel@tonic-gate }
69757c478bd9Sstevel@tonic-gate } else {
69767c478bd9Sstevel@tonic-gate return (B_FALSE);
69777c478bd9Sstevel@tonic-gate }
69787c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE;
69797c478bd9Sstevel@tonic-gate break;
69807c478bd9Sstevel@tonic-gate case CKA_PRIME_BITS:
69817c478bd9Sstevel@tonic-gate if (obj->class == CKO_DOMAIN_PARAMETERS) {
69827c478bd9Sstevel@tonic-gate CK_ULONG prime_bits;
69837c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_DSA) {
69847c478bd9Sstevel@tonic-gate prime_bits =
69857c478bd9Sstevel@tonic-gate OBJ_DOM_DSA_PRIME_BITS(obj);
69867c478bd9Sstevel@tonic-gate } else if (obj->key_type == CKK_DH) {
69877c478bd9Sstevel@tonic-gate prime_bits =
69887c478bd9Sstevel@tonic-gate OBJ_DOM_DH_PRIME_BITS(obj);
69897c478bd9Sstevel@tonic-gate } else if (obj->key_type == CKK_X9_42_DH) {
69907c478bd9Sstevel@tonic-gate prime_bits =
69917c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_PRIME_BITS(obj);
69927c478bd9Sstevel@tonic-gate } else {
69937c478bd9Sstevel@tonic-gate return (B_FALSE);
69947c478bd9Sstevel@tonic-gate }
69957c478bd9Sstevel@tonic-gate if (prime_bits !=
69967c478bd9Sstevel@tonic-gate *((CK_ULONG *)tmpl_attr->pValue)) {
69977c478bd9Sstevel@tonic-gate return (B_FALSE);
69987c478bd9Sstevel@tonic-gate }
69997c478bd9Sstevel@tonic-gate } else {
70007c478bd9Sstevel@tonic-gate return (B_FALSE);
70017c478bd9Sstevel@tonic-gate }
70027c478bd9Sstevel@tonic-gate break;
70037c478bd9Sstevel@tonic-gate case CKA_SUBPRIME_BITS:
70047c478bd9Sstevel@tonic-gate if ((obj->class == CKO_DOMAIN_PARAMETERS) &&
70057c478bd9Sstevel@tonic-gate (obj->key_type == CKK_X9_42_DH)) {
70067c478bd9Sstevel@tonic-gate CK_ULONG subprime_bits =
70077c478bd9Sstevel@tonic-gate OBJ_DOM_DH942_SUBPRIME_BITS(obj);
70087c478bd9Sstevel@tonic-gate if (subprime_bits !=
70097c478bd9Sstevel@tonic-gate *((CK_ULONG *)tmpl_attr->pValue)) {
70107c478bd9Sstevel@tonic-gate return (B_FALSE);
70117c478bd9Sstevel@tonic-gate }
70127c478bd9Sstevel@tonic-gate } else {
70137c478bd9Sstevel@tonic-gate return (B_FALSE);
70147c478bd9Sstevel@tonic-gate }
70157c478bd9Sstevel@tonic-gate break;
70167c478bd9Sstevel@tonic-gate default:
70177c478bd9Sstevel@tonic-gate /*
70187c478bd9Sstevel@tonic-gate * any other attributes are currently not supported.
70197c478bd9Sstevel@tonic-gate * so, it's not possible for them to be in the
70207c478bd9Sstevel@tonic-gate * object
70217c478bd9Sstevel@tonic-gate */
70227c478bd9Sstevel@tonic-gate return (B_FALSE);
70237c478bd9Sstevel@tonic-gate }
70247c478bd9Sstevel@tonic-gate if (compare_boolean) {
70257c478bd9Sstevel@tonic-gate CK_BBOOL bval;
70267c478bd9Sstevel@tonic-gate
70277c478bd9Sstevel@tonic-gate if (attr_mask) {
70287c478bd9Sstevel@tonic-gate bval = TRUE;
70297c478bd9Sstevel@tonic-gate } else {
70307c478bd9Sstevel@tonic-gate bval = FALSE;
70317c478bd9Sstevel@tonic-gate }
70327c478bd9Sstevel@tonic-gate if (bval != *((CK_BBOOL *)tmpl_attr->pValue)) {
70337c478bd9Sstevel@tonic-gate return (B_FALSE);
70347c478bd9Sstevel@tonic-gate }
70357c478bd9Sstevel@tonic-gate } else if (compare_bigint) {
70367c478bd9Sstevel@tonic-gate if (bigint == NULL) {
70377c478bd9Sstevel@tonic-gate return (B_FALSE);
70387c478bd9Sstevel@tonic-gate }
70397c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen != bigint->big_value_len) {
70407c478bd9Sstevel@tonic-gate return (B_FALSE);
70417c478bd9Sstevel@tonic-gate }
70427c478bd9Sstevel@tonic-gate if (memcmp(tmpl_attr->pValue, bigint->big_value,
70437c478bd9Sstevel@tonic-gate tmpl_attr->ulValueLen) != 0) {
70447c478bd9Sstevel@tonic-gate return (B_FALSE);
70457c478bd9Sstevel@tonic-gate }
70467c478bd9Sstevel@tonic-gate } else if (compare_attr) {
70477c478bd9Sstevel@tonic-gate if (obj_attr == NULL) {
70487c478bd9Sstevel@tonic-gate /*
70497c478bd9Sstevel@tonic-gate * The attribute type is valid, and its value
70507c478bd9Sstevel@tonic-gate * has not been initialized in the object. In
70517c478bd9Sstevel@tonic-gate * this case, it only matches the template's
70527c478bd9Sstevel@tonic-gate * attribute if the template's value length
70537c478bd9Sstevel@tonic-gate * is 0.
70547c478bd9Sstevel@tonic-gate */
70557c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen != 0)
70567c478bd9Sstevel@tonic-gate return (B_FALSE);
70577c478bd9Sstevel@tonic-gate } else {
70587c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen !=
70597c478bd9Sstevel@tonic-gate obj_attr->ulValueLen) {
70607c478bd9Sstevel@tonic-gate return (B_FALSE);
70617c478bd9Sstevel@tonic-gate }
70627c478bd9Sstevel@tonic-gate if (memcmp(tmpl_attr->pValue, obj_attr->pValue,
70637c478bd9Sstevel@tonic-gate tmpl_attr->ulValueLen) != 0) {
70647c478bd9Sstevel@tonic-gate return (B_FALSE);
70657c478bd9Sstevel@tonic-gate }
70667c478bd9Sstevel@tonic-gate }
70677c478bd9Sstevel@tonic-gate } else if (compare_cert_val) {
70687c478bd9Sstevel@tonic-gate if (cert_attr == NULL) {
70697c478bd9Sstevel@tonic-gate /* specific attribute not found */
70707c478bd9Sstevel@tonic-gate return (B_FALSE);
70717c478bd9Sstevel@tonic-gate }
70727c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen != cert_attr->length) {
70737c478bd9Sstevel@tonic-gate return (B_FALSE);
70747c478bd9Sstevel@tonic-gate }
70757c478bd9Sstevel@tonic-gate if (memcmp(tmpl_attr->pValue, cert_attr->value,
70767c478bd9Sstevel@tonic-gate tmpl_attr->ulValueLen) != 0) {
70777c478bd9Sstevel@tonic-gate return (B_FALSE);
70787c478bd9Sstevel@tonic-gate }
70797c478bd9Sstevel@tonic-gate } else if (compare_cert_type) {
70807c478bd9Sstevel@tonic-gate if (memcmp(tmpl_attr->pValue, &(obj->cert_type),
70817c478bd9Sstevel@tonic-gate tmpl_attr->ulValueLen) != 0) {
70827c478bd9Sstevel@tonic-gate return (B_FALSE);
70837c478bd9Sstevel@tonic-gate }
70847c478bd9Sstevel@tonic-gate }
70857c478bd9Sstevel@tonic-gate }
70867c478bd9Sstevel@tonic-gate return (B_TRUE);
70877c478bd9Sstevel@tonic-gate }
70887c478bd9Sstevel@tonic-gate
70897c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR
70907c478bd9Sstevel@tonic-gate get_extra_attr(CK_ATTRIBUTE_TYPE type, soft_object_t *obj)
70917c478bd9Sstevel@tonic-gate {
70927c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR tmp;
70937c478bd9Sstevel@tonic-gate
70947c478bd9Sstevel@tonic-gate tmp = obj->extra_attrlistp;
70957c478bd9Sstevel@tonic-gate while (tmp != NULL) {
70967c478bd9Sstevel@tonic-gate if (tmp->attr.type == type) {
70977c478bd9Sstevel@tonic-gate return (&(tmp->attr));
70987c478bd9Sstevel@tonic-gate }
70997c478bd9Sstevel@tonic-gate tmp = tmp->next;
71007c478bd9Sstevel@tonic-gate }
71017c478bd9Sstevel@tonic-gate /* if get there, the specified attribute is not found */
71027c478bd9Sstevel@tonic-gate return (NULL);
71037c478bd9Sstevel@tonic-gate }
7104