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 5034448feSmcpowers * Common Development and Distribution License (the "License"). 6034448feSmcpowers * 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 /* 2223c57df7Smcpowers * Copyright 2008 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 <aes_impl.h> 32f66d273dSizick #include <blowfish_impl.h> 337c478bd9Sstevel@tonic-gate #include <arcfour.h> 347c478bd9Sstevel@tonic-gate #include <des_impl.h> 357c478bd9Sstevel@tonic-gate #include "kernelGlobal.h" 367c478bd9Sstevel@tonic-gate #include "kernelObject.h" 377c478bd9Sstevel@tonic-gate #include "kernelSession.h" 387c478bd9Sstevel@tonic-gate #include "kernelSlot.h" 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * This attribute table is used by the kernel_lookup_attr() 437c478bd9Sstevel@tonic-gate * to validate the attributes. 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE attr_map[] = { 467c478bd9Sstevel@tonic-gate CKA_PRIVATE, 477c478bd9Sstevel@tonic-gate CKA_LABEL, 487c478bd9Sstevel@tonic-gate CKA_APPLICATION, 497c478bd9Sstevel@tonic-gate CKA_OBJECT_ID, 507c478bd9Sstevel@tonic-gate CKA_CERTIFICATE_TYPE, 517c478bd9Sstevel@tonic-gate CKA_ISSUER, 527c478bd9Sstevel@tonic-gate CKA_SERIAL_NUMBER, 537c478bd9Sstevel@tonic-gate CKA_AC_ISSUER, 547c478bd9Sstevel@tonic-gate CKA_OWNER, 557c478bd9Sstevel@tonic-gate CKA_ATTR_TYPES, 567c478bd9Sstevel@tonic-gate CKA_SUBJECT, 577c478bd9Sstevel@tonic-gate CKA_ID, 587c478bd9Sstevel@tonic-gate CKA_SENSITIVE, 597c478bd9Sstevel@tonic-gate CKA_START_DATE, 607c478bd9Sstevel@tonic-gate CKA_END_DATE, 617c478bd9Sstevel@tonic-gate CKA_MODULUS, 627c478bd9Sstevel@tonic-gate CKA_MODULUS_BITS, 637c478bd9Sstevel@tonic-gate CKA_PUBLIC_EXPONENT, 647c478bd9Sstevel@tonic-gate CKA_PRIVATE_EXPONENT, 657c478bd9Sstevel@tonic-gate CKA_PRIME_1, 667c478bd9Sstevel@tonic-gate CKA_PRIME_2, 677c478bd9Sstevel@tonic-gate CKA_EXPONENT_1, 687c478bd9Sstevel@tonic-gate CKA_EXPONENT_2, 697c478bd9Sstevel@tonic-gate CKA_COEFFICIENT, 707c478bd9Sstevel@tonic-gate CKA_PRIME, 717c478bd9Sstevel@tonic-gate CKA_SUBPRIME, 727c478bd9Sstevel@tonic-gate CKA_BASE, 737c478bd9Sstevel@tonic-gate CKA_EXTRACTABLE, 747c478bd9Sstevel@tonic-gate CKA_LOCAL, 757c478bd9Sstevel@tonic-gate CKA_NEVER_EXTRACTABLE, 767c478bd9Sstevel@tonic-gate CKA_ALWAYS_SENSITIVE, 777c478bd9Sstevel@tonic-gate CKA_MODIFIABLE, 787c478bd9Sstevel@tonic-gate CKA_ECDSA_PARAMS, 797c478bd9Sstevel@tonic-gate CKA_EC_POINT, 807c478bd9Sstevel@tonic-gate CKA_SECONDARY_AUTH, 817c478bd9Sstevel@tonic-gate CKA_AUTH_PIN_FLAGS, 827c478bd9Sstevel@tonic-gate CKA_HW_FEATURE_TYPE, 837c478bd9Sstevel@tonic-gate CKA_RESET_ON_INIT, 847c478bd9Sstevel@tonic-gate CKA_HAS_RESET 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * attributes that exists only in public key objects 897c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two 907c478bd9Sstevel@tonic-gate * other object classes, but they are also listed 917c478bd9Sstevel@tonic-gate * because not all object have them. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE PUB_KEY_ATTRS[] = 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate CKA_SUBJECT, 967c478bd9Sstevel@tonic-gate CKA_ENCRYPT, 977c478bd9Sstevel@tonic-gate CKA_WRAP, 987c478bd9Sstevel@tonic-gate CKA_VERIFY, 997c478bd9Sstevel@tonic-gate CKA_VERIFY_RECOVER, 1007c478bd9Sstevel@tonic-gate CKA_MODULUS, 1017c478bd9Sstevel@tonic-gate CKA_MODULUS_BITS, 1027c478bd9Sstevel@tonic-gate CKA_PUBLIC_EXPONENT, 1037c478bd9Sstevel@tonic-gate CKA_PRIME, 1047c478bd9Sstevel@tonic-gate CKA_SUBPRIME, 1057c478bd9Sstevel@tonic-gate CKA_BASE, 1067c478bd9Sstevel@tonic-gate CKA_TRUSTED, 1077c478bd9Sstevel@tonic-gate CKA_ECDSA_PARAMS, 1087c478bd9Sstevel@tonic-gate CKA_EC_PARAMS, 1097c478bd9Sstevel@tonic-gate CKA_EC_POINT 1107c478bd9Sstevel@tonic-gate }; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * attributes that exists only in private key objects 1147c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two 1157c478bd9Sstevel@tonic-gate * other object classes, but they are also listed 1167c478bd9Sstevel@tonic-gate * because not all object have them. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE PRIV_KEY_ATTRS[] = 1197c478bd9Sstevel@tonic-gate { 1207c478bd9Sstevel@tonic-gate CKA_DECRYPT, 1217c478bd9Sstevel@tonic-gate CKA_UNWRAP, 1227c478bd9Sstevel@tonic-gate CKA_SIGN, 1237c478bd9Sstevel@tonic-gate CKA_SIGN_RECOVER, 1247c478bd9Sstevel@tonic-gate CKA_MODULUS, 1257c478bd9Sstevel@tonic-gate CKA_PUBLIC_EXPONENT, 1267c478bd9Sstevel@tonic-gate CKA_PRIVATE_EXPONENT, 1277c478bd9Sstevel@tonic-gate CKA_PRIME, 1287c478bd9Sstevel@tonic-gate CKA_SUBPRIME, 1297c478bd9Sstevel@tonic-gate CKA_BASE, 1307c478bd9Sstevel@tonic-gate CKA_PRIME_1, 1317c478bd9Sstevel@tonic-gate CKA_PRIME_2, 1327c478bd9Sstevel@tonic-gate CKA_EXPONENT_1, 1337c478bd9Sstevel@tonic-gate CKA_EXPONENT_2, 1347c478bd9Sstevel@tonic-gate CKA_COEFFICIENT, 1357c478bd9Sstevel@tonic-gate CKA_VALUE_BITS, 1367c478bd9Sstevel@tonic-gate CKA_SUBJECT, 1377c478bd9Sstevel@tonic-gate CKA_SENSITIVE, 1387c478bd9Sstevel@tonic-gate CKA_EXTRACTABLE, 1397c478bd9Sstevel@tonic-gate CKA_NEVER_EXTRACTABLE, 1407c478bd9Sstevel@tonic-gate CKA_ALWAYS_SENSITIVE, 1417c478bd9Sstevel@tonic-gate CKA_ECDSA_PARAMS, 1427c478bd9Sstevel@tonic-gate CKA_EC_PARAMS 1437c478bd9Sstevel@tonic-gate }; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * attributes that exists only in secret key objects 1477c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two 1487c478bd9Sstevel@tonic-gate * other object classes, but they are also listed 1497c478bd9Sstevel@tonic-gate * because not all object have them. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE SECRET_KEY_ATTRS[] = 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate CKA_VALUE_LEN, 1547c478bd9Sstevel@tonic-gate CKA_ENCRYPT, 1557c478bd9Sstevel@tonic-gate CKA_DECRYPT, 1567c478bd9Sstevel@tonic-gate CKA_WRAP, 1577c478bd9Sstevel@tonic-gate CKA_UNWRAP, 1587c478bd9Sstevel@tonic-gate CKA_SIGN, 1597c478bd9Sstevel@tonic-gate CKA_VERIFY, 1607c478bd9Sstevel@tonic-gate CKA_SENSITIVE, 1617c478bd9Sstevel@tonic-gate CKA_EXTRACTABLE, 1627c478bd9Sstevel@tonic-gate CKA_NEVER_EXTRACTABLE, 1637c478bd9Sstevel@tonic-gate CKA_ALWAYS_SENSITIVE 1647c478bd9Sstevel@tonic-gate }; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * attributes that exists only in domain parameter objects 1687c478bd9Sstevel@tonic-gate * Note: some attributes may also exist in one or two 1697c478bd9Sstevel@tonic-gate * other object classes, but they are also listed 1707c478bd9Sstevel@tonic-gate * because not all object have them. 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE DOMAIN_ATTRS[] = 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate CKA_PRIME, 1757c478bd9Sstevel@tonic-gate CKA_SUBPRIME, 1767c478bd9Sstevel@tonic-gate CKA_BASE, 1777c478bd9Sstevel@tonic-gate CKA_PRIME_BITS, 1787c478bd9Sstevel@tonic-gate CKA_SUBPRIME_BITS, 1797c478bd9Sstevel@tonic-gate CKA_SUB_PRIME_BITS 1807c478bd9Sstevel@tonic-gate }; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate /* 1837c478bd9Sstevel@tonic-gate * attributes that exists only in hardware feature objects 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE HARDWARE_ATTRS[] = 1867c478bd9Sstevel@tonic-gate { 1877c478bd9Sstevel@tonic-gate CKA_HW_FEATURE_TYPE, 1887c478bd9Sstevel@tonic-gate CKA_RESET_ON_INIT, 1897c478bd9Sstevel@tonic-gate CKA_HAS_RESET 1907c478bd9Sstevel@tonic-gate }; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * attributes that exists only in certificate objects 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE CERT_ATTRS[] = 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate CKA_CERTIFICATE_TYPE, 1987c478bd9Sstevel@tonic-gate CKA_SUBJECT, 1997c478bd9Sstevel@tonic-gate CKA_ID, 2007c478bd9Sstevel@tonic-gate CKA_ISSUER, 2017c478bd9Sstevel@tonic-gate CKA_AC_ISSUER, 2027c478bd9Sstevel@tonic-gate CKA_SERIAL_NUMBER, 2037c478bd9Sstevel@tonic-gate CKA_OWNER, 2047c478bd9Sstevel@tonic-gate CKA_ATTR_TYPES 2057c478bd9Sstevel@tonic-gate }; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * Validate the attribute by using binary search algorithm. 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate CK_RV 2127c478bd9Sstevel@tonic-gate kernel_lookup_attr(CK_ATTRIBUTE_TYPE type) 2137c478bd9Sstevel@tonic-gate { 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate size_t lower, middle, upper; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate lower = 0; 2187c478bd9Sstevel@tonic-gate upper = (sizeof (attr_map) / sizeof (CK_ATTRIBUTE_TYPE)) - 1; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate while (lower <= upper) { 2217c478bd9Sstevel@tonic-gate /* Always starts from middle. */ 2227c478bd9Sstevel@tonic-gate middle = (lower + upper) / 2; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate if (type > attr_map[middle]) { 2257c478bd9Sstevel@tonic-gate /* Adjust the lower bound to upper half. */ 2267c478bd9Sstevel@tonic-gate lower = middle + 1; 2277c478bd9Sstevel@tonic-gate continue; 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate if (type == attr_map[middle]) { 2317c478bd9Sstevel@tonic-gate /* Found it. */ 2327c478bd9Sstevel@tonic-gate return (CKR_OK); 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate if (type < attr_map[middle]) { 2367c478bd9Sstevel@tonic-gate /* Adjust the upper bound to lower half. */ 2377c478bd9Sstevel@tonic-gate upper = middle - 1; 2387c478bd9Sstevel@tonic-gate continue; 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* Failed to find the matching attribute from the attribute table. */ 2437c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * Validate the attribute by using the following search algorithm: 2497c478bd9Sstevel@tonic-gate * 2507c478bd9Sstevel@tonic-gate * 1) Search for the most frequently used attributes first. 2517c478bd9Sstevel@tonic-gate * 2) If not found, search for the usage-purpose attributes - these 2527c478bd9Sstevel@tonic-gate * attributes have dense set of values, therefore compiler will 2537c478bd9Sstevel@tonic-gate * optimize it with a branch table and branch to the appropriate 2547c478bd9Sstevel@tonic-gate * case. 2557c478bd9Sstevel@tonic-gate * 3) If still not found, use binary search for the rest of the 2567c478bd9Sstevel@tonic-gate * attributes in the attr_map[] table. 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate CK_RV 2597c478bd9Sstevel@tonic-gate kernel_validate_attr(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum, 2607c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS *class) 2617c478bd9Sstevel@tonic-gate { 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate CK_ULONG i; 2647c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) { 2677c478bd9Sstevel@tonic-gate /* First tier search */ 2687c478bd9Sstevel@tonic-gate switch (template[i].type) { 2697c478bd9Sstevel@tonic-gate case CKA_CLASS: 2707c478bd9Sstevel@tonic-gate *class = *((CK_OBJECT_CLASS*)template[i].pValue); 2717c478bd9Sstevel@tonic-gate break; 2727c478bd9Sstevel@tonic-gate case CKA_TOKEN: 2737c478bd9Sstevel@tonic-gate break; 2747c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 2757c478bd9Sstevel@tonic-gate break; 2767c478bd9Sstevel@tonic-gate case CKA_VALUE: 2777c478bd9Sstevel@tonic-gate break; 2787c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN: 2797c478bd9Sstevel@tonic-gate break; 2807c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS: 2817c478bd9Sstevel@tonic-gate break; 2827c478bd9Sstevel@tonic-gate default: 2837c478bd9Sstevel@tonic-gate /* Second tier search */ 2847c478bd9Sstevel@tonic-gate switch (template[i].type) { 2857c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 2867c478bd9Sstevel@tonic-gate break; 2877c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 2887c478bd9Sstevel@tonic-gate break; 2897c478bd9Sstevel@tonic-gate case CKA_WRAP: 2907c478bd9Sstevel@tonic-gate break; 2917c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 2927c478bd9Sstevel@tonic-gate break; 2937c478bd9Sstevel@tonic-gate case CKA_SIGN: 2947c478bd9Sstevel@tonic-gate break; 2957c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER: 2967c478bd9Sstevel@tonic-gate break; 2977c478bd9Sstevel@tonic-gate case CKA_VERIFY: 2987c478bd9Sstevel@tonic-gate break; 2997c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER: 3007c478bd9Sstevel@tonic-gate break; 3017c478bd9Sstevel@tonic-gate case CKA_DERIVE: 3027c478bd9Sstevel@tonic-gate break; 3037c478bd9Sstevel@tonic-gate default: 3047c478bd9Sstevel@tonic-gate /* Third tier search */ 3057c478bd9Sstevel@tonic-gate rv = kernel_lookup_attr(template[i].type); 3067c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 3077c478bd9Sstevel@tonic-gate return (rv); 3087c478bd9Sstevel@tonic-gate break; 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate break; 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate return (rv); 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate /* 3187c478bd9Sstevel@tonic-gate * Clean up and release all the storage in the extra attribute list 3197c478bd9Sstevel@tonic-gate * of an object. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate void 3227c478bd9Sstevel@tonic-gate kernel_cleanup_extra_attr(kernel_object_t *object_p) 3237c478bd9Sstevel@tonic-gate { 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR extra_attr; 3267c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR tmp; 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate extra_attr = object_p->extra_attrlistp; 3297c478bd9Sstevel@tonic-gate while (extra_attr) { 3307c478bd9Sstevel@tonic-gate tmp = extra_attr->next; 3317c478bd9Sstevel@tonic-gate if (extra_attr->attr.pValue) 3327c478bd9Sstevel@tonic-gate /* 3337c478bd9Sstevel@tonic-gate * All extra attributes in the extra attribute 3347c478bd9Sstevel@tonic-gate * list have pValue points to the value of the 3357c478bd9Sstevel@tonic-gate * attribute (with simple byte array type). 3367c478bd9Sstevel@tonic-gate * Free the storage for the value of the attribute. 3377c478bd9Sstevel@tonic-gate */ 3387c478bd9Sstevel@tonic-gate free(extra_attr->attr.pValue); 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* Free the storage for the attribute_info struct. */ 3417c478bd9Sstevel@tonic-gate free(extra_attr); 3427c478bd9Sstevel@tonic-gate extra_attr = tmp; 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = NULL; 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate /* 3507c478bd9Sstevel@tonic-gate * Create the attribute_info struct to hold the object's attribute, 3517c478bd9Sstevel@tonic-gate * and add it to the extra attribute list of an object. 3527c478bd9Sstevel@tonic-gate */ 3537c478bd9Sstevel@tonic-gate CK_RV 3547c478bd9Sstevel@tonic-gate kernel_add_extra_attr(CK_ATTRIBUTE_PTR template, kernel_object_t *object_p) 3557c478bd9Sstevel@tonic-gate { 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR attrp; 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate /* Allocate the storage for the attribute_info struct. */ 3607c478bd9Sstevel@tonic-gate attrp = calloc(1, sizeof (attribute_info_t)); 3617c478bd9Sstevel@tonic-gate if (attrp == NULL) { 3627c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* Set up attribute_info struct. */ 3667c478bd9Sstevel@tonic-gate attrp->attr.type = template->type; 3677c478bd9Sstevel@tonic-gate attrp->attr.ulValueLen = template->ulValueLen; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate if ((template->pValue != NULL) && 3707c478bd9Sstevel@tonic-gate (template->ulValueLen > 0)) { 3717c478bd9Sstevel@tonic-gate /* Allocate storage for the value of the attribute. */ 3727c478bd9Sstevel@tonic-gate attrp->attr.pValue = malloc(template->ulValueLen); 3737c478bd9Sstevel@tonic-gate if (attrp->attr.pValue == NULL) { 3747c478bd9Sstevel@tonic-gate free(attrp); 3757c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate (void) memcpy(attrp->attr.pValue, template->pValue, 3797c478bd9Sstevel@tonic-gate template->ulValueLen); 3807c478bd9Sstevel@tonic-gate } else { 3817c478bd9Sstevel@tonic-gate attrp->attr.pValue = NULL; 3827c478bd9Sstevel@tonic-gate } 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate /* Insert the new attribute in front of extra attribute list. */ 3857c478bd9Sstevel@tonic-gate if (object_p->extra_attrlistp == NULL) { 3867c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp; 3877c478bd9Sstevel@tonic-gate attrp->next = NULL; 3887c478bd9Sstevel@tonic-gate } else { 3897c478bd9Sstevel@tonic-gate attrp->next = object_p->extra_attrlistp; 3907c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp; 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate return (CKR_OK); 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * Copy the attribute_info struct from the old object to a new attribute_info 3997c478bd9Sstevel@tonic-gate * struct, and add that new struct to the extra attribute list of the new 4007c478bd9Sstevel@tonic-gate * object. 4017c478bd9Sstevel@tonic-gate */ 4027c478bd9Sstevel@tonic-gate CK_RV 4037c478bd9Sstevel@tonic-gate kernel_copy_extra_attr(CK_ATTRIBUTE_INFO_PTR old_attrp, 4047c478bd9Sstevel@tonic-gate kernel_object_t *object_p) 4057c478bd9Sstevel@tonic-gate { 4067c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR attrp; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate /* Allocate attribute_info struct. */ 4097c478bd9Sstevel@tonic-gate attrp = calloc(1, sizeof (attribute_info_t)); 4107c478bd9Sstevel@tonic-gate if (attrp == NULL) { 4117c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate attrp->attr.type = old_attrp->attr.type; 4157c478bd9Sstevel@tonic-gate attrp->attr.ulValueLen = old_attrp->attr.ulValueLen; 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate if ((old_attrp->attr.pValue != NULL) && 4187c478bd9Sstevel@tonic-gate (old_attrp->attr.ulValueLen > 0)) { 4197c478bd9Sstevel@tonic-gate attrp->attr.pValue = malloc(old_attrp->attr.ulValueLen); 4207c478bd9Sstevel@tonic-gate if (attrp->attr.pValue == NULL) { 4217c478bd9Sstevel@tonic-gate free(attrp); 4227c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate (void) memcpy(attrp->attr.pValue, old_attrp->attr.pValue, 4267c478bd9Sstevel@tonic-gate old_attrp->attr.ulValueLen); 4277c478bd9Sstevel@tonic-gate } else { 4287c478bd9Sstevel@tonic-gate attrp->attr.pValue = NULL; 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate /* Insert the new attribute in front of extra attribute list */ 4327c478bd9Sstevel@tonic-gate if (object_p->extra_attrlistp == NULL) { 4337c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp; 4347c478bd9Sstevel@tonic-gate attrp->next = NULL; 4357c478bd9Sstevel@tonic-gate } else { 4367c478bd9Sstevel@tonic-gate attrp->next = object_p->extra_attrlistp; 4377c478bd9Sstevel@tonic-gate object_p->extra_attrlistp = attrp; 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate return (CKR_OK); 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate /* 4457c478bd9Sstevel@tonic-gate * Get the attribute triple from the extra attribute list in the object 4467c478bd9Sstevel@tonic-gate * (if the specified attribute type is found), and copy it to a template. 4477c478bd9Sstevel@tonic-gate * Note the type of the attribute to be copied is specified by the template, 4487c478bd9Sstevel@tonic-gate * and the storage is pre-allocated for the atrribute value in the template 4497c478bd9Sstevel@tonic-gate * for doing the copy. 4507c478bd9Sstevel@tonic-gate */ 4517c478bd9Sstevel@tonic-gate CK_RV 4527c478bd9Sstevel@tonic-gate get_extra_attr_from_object(kernel_object_t *object_p, CK_ATTRIBUTE_PTR template) 4537c478bd9Sstevel@tonic-gate { 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR extra_attr; 4567c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_TYPE type = template->type; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate extra_attr = object_p->extra_attrlistp; 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate while (extra_attr) { 4617c478bd9Sstevel@tonic-gate if (type == extra_attr->attr.type) { 4627c478bd9Sstevel@tonic-gate /* Found it. */ 4637c478bd9Sstevel@tonic-gate break; 4647c478bd9Sstevel@tonic-gate } else { 4657c478bd9Sstevel@tonic-gate /* Does not match, try next one. */ 4667c478bd9Sstevel@tonic-gate extra_attr = extra_attr->next; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate if (extra_attr == NULL) { 4717c478bd9Sstevel@tonic-gate /* A valid but un-initialized attribute. */ 4727c478bd9Sstevel@tonic-gate template->ulValueLen = 0; 4737c478bd9Sstevel@tonic-gate return (CKR_OK); 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate /* 4777c478bd9Sstevel@tonic-gate * We found the attribute in the extra attribute list. 4787c478bd9Sstevel@tonic-gate */ 4797c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 4807c478bd9Sstevel@tonic-gate template->ulValueLen = extra_attr->attr.ulValueLen; 4817c478bd9Sstevel@tonic-gate return (CKR_OK); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate if (template->ulValueLen >= extra_attr->attr.ulValueLen) { 4857c478bd9Sstevel@tonic-gate /* 4867c478bd9Sstevel@tonic-gate * The buffer provided by the application is large 4877c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute. 4887c478bd9Sstevel@tonic-gate */ 4897c478bd9Sstevel@tonic-gate (void) memcpy(template->pValue, extra_attr->attr.pValue, 4907c478bd9Sstevel@tonic-gate extra_attr->attr.ulValueLen); 4917c478bd9Sstevel@tonic-gate template->ulValueLen = extra_attr->attr.ulValueLen; 4927c478bd9Sstevel@tonic-gate return (CKR_OK); 4937c478bd9Sstevel@tonic-gate } else { 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * The buffer provided by the application does 4967c478bd9Sstevel@tonic-gate * not have enough space to hold the value. 4977c478bd9Sstevel@tonic-gate */ 4987c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 4997c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate } 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate /* 5057c478bd9Sstevel@tonic-gate * Modify the attribute triple in the extra attribute list of the object 5067c478bd9Sstevel@tonic-gate * if the specified attribute type is found. Otherwise, just add it to 5077c478bd9Sstevel@tonic-gate * list. 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate CK_RV 5107c478bd9Sstevel@tonic-gate set_extra_attr_to_object(kernel_object_t *object_p, CK_ATTRIBUTE_TYPE type, 5117c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 5127c478bd9Sstevel@tonic-gate { 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR extra_attr; 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate extra_attr = object_p->extra_attrlistp; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate while (extra_attr) { 5197c478bd9Sstevel@tonic-gate if (type == extra_attr->attr.type) { 5207c478bd9Sstevel@tonic-gate /* Found it. */ 5217c478bd9Sstevel@tonic-gate break; 5227c478bd9Sstevel@tonic-gate } else { 5237c478bd9Sstevel@tonic-gate /* Does not match, try next one. */ 5247c478bd9Sstevel@tonic-gate extra_attr = extra_attr->next; 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate if (extra_attr == NULL) { 5297c478bd9Sstevel@tonic-gate /* 5307c478bd9Sstevel@tonic-gate * This attribute is a new one, go ahead adding it to 5317c478bd9Sstevel@tonic-gate * the extra attribute list. 5327c478bd9Sstevel@tonic-gate */ 5337c478bd9Sstevel@tonic-gate return (kernel_add_extra_attr(template, object_p)); 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate /* We found the attribute in the extra attribute list. */ 5377c478bd9Sstevel@tonic-gate if ((template->pValue != NULL) && 5387c478bd9Sstevel@tonic-gate (template->ulValueLen > 0)) { 5397c478bd9Sstevel@tonic-gate if (template->ulValueLen > extra_attr->attr.ulValueLen) { 5407c478bd9Sstevel@tonic-gate /* The old buffer is too small to hold the new value. */ 5417c478bd9Sstevel@tonic-gate if (extra_attr->attr.pValue != NULL) 5427c478bd9Sstevel@tonic-gate /* Free storage for the old attribute value. */ 5437c478bd9Sstevel@tonic-gate free(extra_attr->attr.pValue); 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate /* Allocate storage for the new attribute value. */ 5467c478bd9Sstevel@tonic-gate extra_attr->attr.pValue = malloc(template->ulValueLen); 5477c478bd9Sstevel@tonic-gate if (extra_attr->attr.pValue == NULL) { 5487c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate /* Replace the attribute with new value. */ 5537c478bd9Sstevel@tonic-gate extra_attr->attr.ulValueLen = template->ulValueLen; 5547c478bd9Sstevel@tonic-gate (void) memcpy(extra_attr->attr.pValue, template->pValue, 5557c478bd9Sstevel@tonic-gate template->ulValueLen); 5567c478bd9Sstevel@tonic-gate } else { 5577c478bd9Sstevel@tonic-gate extra_attr->attr.pValue = NULL; 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate return (CKR_OK); 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate /* 5657c478bd9Sstevel@tonic-gate * Copy the big integer attribute value from template to a biginteger_t struct. 5667c478bd9Sstevel@tonic-gate */ 5677c478bd9Sstevel@tonic-gate CK_RV 5687c478bd9Sstevel@tonic-gate get_bigint_attr_from_template(biginteger_t *big, CK_ATTRIBUTE_PTR template) 5697c478bd9Sstevel@tonic-gate { 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate if ((template->pValue != NULL) && 5727c478bd9Sstevel@tonic-gate (template->ulValueLen > 0)) { 5737c478bd9Sstevel@tonic-gate /* Allocate storage for the value of the attribute. */ 5747c478bd9Sstevel@tonic-gate big->big_value = malloc(template->ulValueLen); 5757c478bd9Sstevel@tonic-gate if (big->big_value == NULL) { 5767c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate (void) memcpy(big->big_value, template->pValue, 5807c478bd9Sstevel@tonic-gate template->ulValueLen); 5817c478bd9Sstevel@tonic-gate big->big_value_len = template->ulValueLen; 5827c478bd9Sstevel@tonic-gate } else { 5837c478bd9Sstevel@tonic-gate big->big_value = NULL; 5847c478bd9Sstevel@tonic-gate big->big_value_len = 0; 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate return (CKR_OK); 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate /* 5927c478bd9Sstevel@tonic-gate * Copy the big integer attribute value from a biginteger_t struct in the 5937c478bd9Sstevel@tonic-gate * object to a template. 5947c478bd9Sstevel@tonic-gate */ 5957c478bd9Sstevel@tonic-gate CK_RV 5967c478bd9Sstevel@tonic-gate get_bigint_attr_from_object(biginteger_t *big, CK_ATTRIBUTE_PTR template) 5977c478bd9Sstevel@tonic-gate { 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 6007c478bd9Sstevel@tonic-gate template->ulValueLen = big->big_value_len; 6017c478bd9Sstevel@tonic-gate return (CKR_OK); 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate if (big->big_value == NULL) { 6057c478bd9Sstevel@tonic-gate template->ulValueLen = 0; 6067c478bd9Sstevel@tonic-gate return (CKR_OK); 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate if (template->ulValueLen >= big->big_value_len) { 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * The buffer provided by the application is large 6127c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute. 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate (void) memcpy(template->pValue, big->big_value, 6157c478bd9Sstevel@tonic-gate big->big_value_len); 6167c478bd9Sstevel@tonic-gate template->ulValueLen = big->big_value_len; 6177c478bd9Sstevel@tonic-gate return (CKR_OK); 6187c478bd9Sstevel@tonic-gate } else { 6197c478bd9Sstevel@tonic-gate /* 6207c478bd9Sstevel@tonic-gate * The buffer provided by the application does 6217c478bd9Sstevel@tonic-gate * not have enough space to hold the value. 6227c478bd9Sstevel@tonic-gate */ 6237c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 6247c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL); 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate /* 6307c478bd9Sstevel@tonic-gate * Copy the boolean data type attribute value from an object for the 6317c478bd9Sstevel@tonic-gate * specified attribute to the template. 6327c478bd9Sstevel@tonic-gate */ 6337c478bd9Sstevel@tonic-gate CK_RV 6347c478bd9Sstevel@tonic-gate get_bool_attr_from_object(kernel_object_t *object_p, CK_ULONG bool_flag, 6357c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 6367c478bd9Sstevel@tonic-gate { 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 6397c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL); 6407c478bd9Sstevel@tonic-gate return (CKR_OK); 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate if (template->ulValueLen >= sizeof (CK_BBOOL)) { 6447c478bd9Sstevel@tonic-gate /* 6457c478bd9Sstevel@tonic-gate * The buffer provided by the application is large 6467c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute. 6477c478bd9Sstevel@tonic-gate */ 6487c478bd9Sstevel@tonic-gate if (object_p->bool_attr_mask & bool_flag) { 6497c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE; 6507c478bd9Sstevel@tonic-gate } else { 6517c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE; 6527c478bd9Sstevel@tonic-gate } 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL); 6557c478bd9Sstevel@tonic-gate return (CKR_OK); 6567c478bd9Sstevel@tonic-gate } else { 6577c478bd9Sstevel@tonic-gate /* 6587c478bd9Sstevel@tonic-gate * The buffer provided by the application does 6597c478bd9Sstevel@tonic-gate * not have enough space to hold the value. 6607c478bd9Sstevel@tonic-gate */ 6617c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 6627c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL); 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate /* 6677c478bd9Sstevel@tonic-gate * Set the boolean data type attribute value in the object. 6687c478bd9Sstevel@tonic-gate */ 6697c478bd9Sstevel@tonic-gate CK_RV 6707c478bd9Sstevel@tonic-gate set_bool_attr_to_object(kernel_object_t *object_p, CK_ULONG bool_flag, 6717c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 6727c478bd9Sstevel@tonic-gate { 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template->pValue) 6757c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |= bool_flag; 6767c478bd9Sstevel@tonic-gate else 6777c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &= ~bool_flag; 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate return (CKR_OK); 6807c478bd9Sstevel@tonic-gate } 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate /* 6847c478bd9Sstevel@tonic-gate * Copy the CK_ULONG data type attribute value from an object to the 6857c478bd9Sstevel@tonic-gate * template. 6867c478bd9Sstevel@tonic-gate */ 6877c478bd9Sstevel@tonic-gate CK_RV 6887c478bd9Sstevel@tonic-gate get_ulong_attr_from_object(CK_ULONG value, CK_ATTRIBUTE_PTR template) 6897c478bd9Sstevel@tonic-gate { 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 6927c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_ULONG); 6937c478bd9Sstevel@tonic-gate return (CKR_OK); 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if (template->ulValueLen >= sizeof (CK_ULONG)) { 6977c478bd9Sstevel@tonic-gate /* 6987c478bd9Sstevel@tonic-gate * The buffer provided by the application is large 6997c478bd9Sstevel@tonic-gate * enough to hold the value of the attribute. 7007c478bd9Sstevel@tonic-gate */ 7017c478bd9Sstevel@tonic-gate *(CK_ULONG_PTR)template->pValue = value; 7027c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_ULONG); 7037c478bd9Sstevel@tonic-gate return (CKR_OK); 7047c478bd9Sstevel@tonic-gate } else { 7057c478bd9Sstevel@tonic-gate /* 7067c478bd9Sstevel@tonic-gate * The buffer provided by the application does 7077c478bd9Sstevel@tonic-gate * not have enough space to hold the value. 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 7107c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL); 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate /* 7167c478bd9Sstevel@tonic-gate * Copy the CK_ULONG data type attribute value from a template to the 7177c478bd9Sstevel@tonic-gate * object. 7187c478bd9Sstevel@tonic-gate */ 7197c478bd9Sstevel@tonic-gate void 7207c478bd9Sstevel@tonic-gate get_ulong_attr_from_template(CK_ULONG *value, CK_ATTRIBUTE_PTR template) 7217c478bd9Sstevel@tonic-gate { 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate if (template->pValue != NULL) { 7247c478bd9Sstevel@tonic-gate *value = *(CK_ULONG_PTR)template->pValue; 7257c478bd9Sstevel@tonic-gate } else { 7267c478bd9Sstevel@tonic-gate *value = 0; 7277c478bd9Sstevel@tonic-gate } 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* 7327c478bd9Sstevel@tonic-gate * Copy the big integer attribute value from source's biginteger_t to 7337c478bd9Sstevel@tonic-gate * destination's biginteger_t. 7347c478bd9Sstevel@tonic-gate */ 7357c478bd9Sstevel@tonic-gate void 7367c478bd9Sstevel@tonic-gate copy_bigint_attr(biginteger_t *src, biginteger_t *dst) 7377c478bd9Sstevel@tonic-gate { 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate if ((src->big_value != NULL) && 7407c478bd9Sstevel@tonic-gate (src->big_value_len > 0)) { 7417c478bd9Sstevel@tonic-gate /* 7427c478bd9Sstevel@tonic-gate * To do the copy, just have dst's big_value points 7437c478bd9Sstevel@tonic-gate * to src's. 7447c478bd9Sstevel@tonic-gate */ 7457c478bd9Sstevel@tonic-gate dst->big_value = src->big_value; 7467c478bd9Sstevel@tonic-gate dst->big_value_len = src->big_value_len; 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate /* 7497c478bd9Sstevel@tonic-gate * After the copy, nullify the src's big_value pointer. 7507c478bd9Sstevel@tonic-gate * It prevents any double freeing the value. 7517c478bd9Sstevel@tonic-gate */ 7527c478bd9Sstevel@tonic-gate src->big_value = NULL; 7537c478bd9Sstevel@tonic-gate src->big_value_len = 0; 7547c478bd9Sstevel@tonic-gate } else { 7557c478bd9Sstevel@tonic-gate dst->big_value = NULL; 7567c478bd9Sstevel@tonic-gate dst->big_value_len = 0; 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate CK_RV 7637c478bd9Sstevel@tonic-gate get_string_from_template(CK_ATTRIBUTE_PTR dest, CK_ATTRIBUTE_PTR src) 7647c478bd9Sstevel@tonic-gate { 7657c478bd9Sstevel@tonic-gate if ((src->pValue != NULL) && 7667c478bd9Sstevel@tonic-gate (src->ulValueLen > 0)) { 7677c478bd9Sstevel@tonic-gate /* Allocate storage for the value of the attribute. */ 7687c478bd9Sstevel@tonic-gate dest->pValue = malloc(src->ulValueLen); 7697c478bd9Sstevel@tonic-gate if (dest->pValue == NULL) { 7707c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 7717c478bd9Sstevel@tonic-gate } 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate (void) memcpy(dest->pValue, src->pValue, 7747c478bd9Sstevel@tonic-gate src->ulValueLen); 7757c478bd9Sstevel@tonic-gate dest->ulValueLen = src->ulValueLen; 7767c478bd9Sstevel@tonic-gate dest->type = src->type; 7777c478bd9Sstevel@tonic-gate } else { 7787c478bd9Sstevel@tonic-gate dest->pValue = NULL; 7797c478bd9Sstevel@tonic-gate dest->ulValueLen = 0; 7807c478bd9Sstevel@tonic-gate dest->type = src->type; 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate return (CKR_OK); 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate void 7887c478bd9Sstevel@tonic-gate string_attr_cleanup(CK_ATTRIBUTE_PTR template) 7897c478bd9Sstevel@tonic-gate { 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate if (template->pValue) { 7927c478bd9Sstevel@tonic-gate free(template->pValue); 7937c478bd9Sstevel@tonic-gate template->pValue = NULL; 7947c478bd9Sstevel@tonic-gate template->ulValueLen = 0; 7957c478bd9Sstevel@tonic-gate } 7967c478bd9Sstevel@tonic-gate } 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate /* 7997c478bd9Sstevel@tonic-gate * Release the storage allocated for object attribute with big integer 8007c478bd9Sstevel@tonic-gate * value. 8017c478bd9Sstevel@tonic-gate */ 8027c478bd9Sstevel@tonic-gate void 8037c478bd9Sstevel@tonic-gate bigint_attr_cleanup(biginteger_t *big) 8047c478bd9Sstevel@tonic-gate { 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate if (big == NULL) 8077c478bd9Sstevel@tonic-gate return; 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate if (big->big_value) { 8107c478bd9Sstevel@tonic-gate (void) memset(big->big_value, 0, big->big_value_len); 8117c478bd9Sstevel@tonic-gate free(big->big_value); 8127c478bd9Sstevel@tonic-gate big->big_value = NULL; 8137c478bd9Sstevel@tonic-gate big->big_value_len = 0; 8147c478bd9Sstevel@tonic-gate } 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate /* 8197c478bd9Sstevel@tonic-gate * Clean up and release all the storage allocated to hold the big integer 8207c478bd9Sstevel@tonic-gate * attributes associated with the type (i.e. class) of the object. Also, 8217c478bd9Sstevel@tonic-gate * release the storage allocated to the type of the object. 8227c478bd9Sstevel@tonic-gate */ 8237c478bd9Sstevel@tonic-gate void 8247c478bd9Sstevel@tonic-gate kernel_cleanup_object_bigint_attrs(kernel_object_t *object_p) 8257c478bd9Sstevel@tonic-gate { 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = object_p->class; 8287c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate 8317c478bd9Sstevel@tonic-gate switch (class) { 8327c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY: 8337c478bd9Sstevel@tonic-gate if (OBJ_PUB(object_p)) { 8347c478bd9Sstevel@tonic-gate switch (keytype) { 8357c478bd9Sstevel@tonic-gate case CKK_RSA: 8367c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_RSA_MOD( 8377c478bd9Sstevel@tonic-gate object_p)); 8387c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_RSA_PUBEXPO( 8397c478bd9Sstevel@tonic-gate object_p)); 8407c478bd9Sstevel@tonic-gate break; 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate case CKK_DSA: 8437c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_PRIME( 8447c478bd9Sstevel@tonic-gate object_p)); 8457c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_SUBPRIME( 8467c478bd9Sstevel@tonic-gate object_p)); 8477c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_BASE( 8487c478bd9Sstevel@tonic-gate object_p)); 8497c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PUB_DSA_VALUE( 8507c478bd9Sstevel@tonic-gate object_p)); 8517c478bd9Sstevel@tonic-gate break; 852034448feSmcpowers 853034448feSmcpowers case CKK_DH: 854034448feSmcpowers bigint_attr_cleanup(OBJ_PUB_DH_PRIME(object_p)); 855034448feSmcpowers bigint_attr_cleanup(OBJ_PUB_DH_BASE(object_p)); 856034448feSmcpowers bigint_attr_cleanup(OBJ_PUB_DH_VALUE(object_p)); 857034448feSmcpowers break; 858034448feSmcpowers 859034448feSmcpowers case CKK_EC: 860034448feSmcpowers bigint_attr_cleanup(OBJ_PUB_EC_POINT(object_p)); 861034448feSmcpowers break; 8627c478bd9Sstevel@tonic-gate } 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate /* Release Public Key Object struct */ 8657c478bd9Sstevel@tonic-gate free(OBJ_PUB(object_p)); 8667c478bd9Sstevel@tonic-gate OBJ_PUB(object_p) = NULL; 8677c478bd9Sstevel@tonic-gate } 8687c478bd9Sstevel@tonic-gate break; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY: 8717c478bd9Sstevel@tonic-gate if (OBJ_PRI(object_p)) { 8727c478bd9Sstevel@tonic-gate switch (keytype) { 8737c478bd9Sstevel@tonic-gate case CKK_RSA: 8747c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_MOD( 8757c478bd9Sstevel@tonic-gate object_p)); 8767c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PUBEXPO( 8777c478bd9Sstevel@tonic-gate object_p)); 8787c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PRIEXPO( 8797c478bd9Sstevel@tonic-gate object_p)); 8807c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PRIME1( 8817c478bd9Sstevel@tonic-gate object_p)); 8827c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_PRIME2( 8837c478bd9Sstevel@tonic-gate object_p)); 8847c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_EXPO1( 8857c478bd9Sstevel@tonic-gate object_p)); 8867c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_EXPO2( 8877c478bd9Sstevel@tonic-gate object_p)); 8887c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_RSA_COEF( 8897c478bd9Sstevel@tonic-gate object_p)); 8907c478bd9Sstevel@tonic-gate break; 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate case CKK_DSA: 8937c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_PRIME( 8947c478bd9Sstevel@tonic-gate object_p)); 8957c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_SUBPRIME( 8967c478bd9Sstevel@tonic-gate object_p)); 8977c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_BASE( 8987c478bd9Sstevel@tonic-gate object_p)); 8997c478bd9Sstevel@tonic-gate bigint_attr_cleanup(OBJ_PRI_DSA_VALUE( 9007c478bd9Sstevel@tonic-gate object_p)); 9017c478bd9Sstevel@tonic-gate break; 902034448feSmcpowers 903034448feSmcpowers case CKK_DH: 904034448feSmcpowers bigint_attr_cleanup(OBJ_PRI_DH_PRIME(object_p)); 905034448feSmcpowers bigint_attr_cleanup(OBJ_PRI_DH_BASE(object_p)); 906034448feSmcpowers bigint_attr_cleanup(OBJ_PRI_DH_VALUE(object_p)); 907034448feSmcpowers break; 908034448feSmcpowers 909034448feSmcpowers case CKK_EC: 910034448feSmcpowers bigint_attr_cleanup(OBJ_PRI_EC_VALUE(object_p)); 911034448feSmcpowers break; 9127c478bd9Sstevel@tonic-gate } 9137c478bd9Sstevel@tonic-gate 9147c478bd9Sstevel@tonic-gate /* Release Private Key Object struct. */ 9157c478bd9Sstevel@tonic-gate free(OBJ_PRI(object_p)); 9167c478bd9Sstevel@tonic-gate OBJ_PRI(object_p) = NULL; 9177c478bd9Sstevel@tonic-gate } 9187c478bd9Sstevel@tonic-gate break; 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate } 9217c478bd9Sstevel@tonic-gate 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate /* 9247c478bd9Sstevel@tonic-gate * Parse the common attributes. Return to caller with appropriate return 9257c478bd9Sstevel@tonic-gate * value to indicate if the supplied template specifies a valid attribute 9267c478bd9Sstevel@tonic-gate * with a valid value. 9277c478bd9Sstevel@tonic-gate */ 9287c478bd9Sstevel@tonic-gate CK_RV 9297c478bd9Sstevel@tonic-gate kernel_parse_common_attrs(CK_ATTRIBUTE_PTR template, kernel_session_t *sp, 9307c478bd9Sstevel@tonic-gate uint64_t *attr_mask_p) 9317c478bd9Sstevel@tonic-gate { 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 9347c478bd9Sstevel@tonic-gate kernel_slot_t *pslot = slot_table[sp->ses_slotid]; 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate switch (template->type) { 9377c478bd9Sstevel@tonic-gate case CKA_CLASS: 9387c478bd9Sstevel@tonic-gate break; 9397c478bd9Sstevel@tonic-gate 9407c478bd9Sstevel@tonic-gate /* default boolean attributes */ 9417c478bd9Sstevel@tonic-gate case CKA_TOKEN: 9427c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == TRUE) { 9437c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 9447c478bd9Sstevel@tonic-gate } 9457c478bd9Sstevel@tonic-gate break; 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate case CKA_PRIVATE: 9487c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == TRUE) { 9497c478bd9Sstevel@tonic-gate /* 950034448feSmcpowers * Cannot create a private object if the token 951034448feSmcpowers * has a keystore and the user isn't logged in. 9527c478bd9Sstevel@tonic-gate */ 953034448feSmcpowers if (pslot->sl_func_list.fl_object_create && 954034448feSmcpowers pslot->sl_state != CKU_USER) { 9557c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 9567c478bd9Sstevel@tonic-gate } else { 9577c478bd9Sstevel@tonic-gate *attr_mask_p |= PRIVATE_BOOL_ON; 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate break; 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE: 9637c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == FALSE) { 9647c478bd9Sstevel@tonic-gate *attr_mask_p &= ~MODIFIABLE_BOOL_ON; 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate break; 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate case CKA_LABEL: 9697c478bd9Sstevel@tonic-gate break; 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate default: 9727c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 9737c478bd9Sstevel@tonic-gate } 9747c478bd9Sstevel@tonic-gate 9757c478bd9Sstevel@tonic-gate return (rv); 9767c478bd9Sstevel@tonic-gate } 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate /* 9827c478bd9Sstevel@tonic-gate * Build a Public Key Object. 9837c478bd9Sstevel@tonic-gate * 9847c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as 9857c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return 9867c478bd9Sstevel@tonic-gate * with appropriate return value. 9877c478bd9Sstevel@tonic-gate * - Set up attribute mask field in the object for the supplied common 9887c478bd9Sstevel@tonic-gate * attributes that have boolean type. 9897c478bd9Sstevel@tonic-gate * - Build the attribute_info struct to hold the value of each supplied 9907c478bd9Sstevel@tonic-gate * attribute that has byte array type. Link attribute_info structs 9917c478bd9Sstevel@tonic-gate * together to form the extra attribute list of the object. 9927c478bd9Sstevel@tonic-gate * - Allocate storage for the Public Key object. 9937c478bd9Sstevel@tonic-gate * - Build the Public Key object according to the key type. Allocate 9947c478bd9Sstevel@tonic-gate * storage to hold the big integer value for the supplied attributes 9957c478bd9Sstevel@tonic-gate * that are required for a certain key type. 9967c478bd9Sstevel@tonic-gate * 9977c478bd9Sstevel@tonic-gate */ 9987c478bd9Sstevel@tonic-gate CK_RV 9997c478bd9Sstevel@tonic-gate kernel_build_public_key_object(CK_ATTRIBUTE_PTR template, 1000034448feSmcpowers CK_ULONG ulAttrNum, kernel_object_t *new_object, kernel_session_t *sp, 1001034448feSmcpowers uint_t mode) 10027c478bd9Sstevel@tonic-gate { 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate int i; 10057c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL; 10067c478bd9Sstevel@tonic-gate uint64_t attr_mask = PUBLIC_KEY_DEFAULT; 10077c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 10087c478bd9Sstevel@tonic-gate int isLabel = 0; 10097c478bd9Sstevel@tonic-gate /* Must set flags */ 10107c478bd9Sstevel@tonic-gate int isModulus = 0; 10117c478bd9Sstevel@tonic-gate int isPubExpo = 0; 10127c478bd9Sstevel@tonic-gate int isPrime = 0; 10137c478bd9Sstevel@tonic-gate int isSubprime = 0; 10147c478bd9Sstevel@tonic-gate int isBase = 0; 10157c478bd9Sstevel@tonic-gate int isValue = 0; 1016034448feSmcpowers int isPoint = 0; 1017034448feSmcpowers int isParams = 0; 10187c478bd9Sstevel@tonic-gate /* Must not set flags */ 10197c478bd9Sstevel@tonic-gate int isModulusBits = 0; 10207c478bd9Sstevel@tonic-gate CK_ULONG modulus_bits = 0; 10217c478bd9Sstevel@tonic-gate 10227c478bd9Sstevel@tonic-gate biginteger_t modulus; 10237c478bd9Sstevel@tonic-gate biginteger_t pubexpo; 10247c478bd9Sstevel@tonic-gate biginteger_t prime; 10257c478bd9Sstevel@tonic-gate biginteger_t subprime; 10267c478bd9Sstevel@tonic-gate biginteger_t base; 10277c478bd9Sstevel@tonic-gate biginteger_t value; 1028034448feSmcpowers biginteger_t point; 10297c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp; 1030034448feSmcpowers CK_ATTRIBUTE param_tmp; 10317c478bd9Sstevel@tonic-gate 10327c478bd9Sstevel@tonic-gate public_key_obj_t *pbk; 10337c478bd9Sstevel@tonic-gate 10347c478bd9Sstevel@tonic-gate /* prevent bigint_attr_cleanup from freeing invalid attr value */ 10357c478bd9Sstevel@tonic-gate (void) memset(&modulus, 0x0, sizeof (biginteger_t)); 10367c478bd9Sstevel@tonic-gate (void) memset(&pubexpo, 0x0, sizeof (biginteger_t)); 10377c478bd9Sstevel@tonic-gate (void) memset(&prime, 0x0, sizeof (biginteger_t)); 10387c478bd9Sstevel@tonic-gate (void) memset(&subprime, 0x0, sizeof (biginteger_t)); 10397c478bd9Sstevel@tonic-gate (void) memset(&base, 0x0, sizeof (biginteger_t)); 10407c478bd9Sstevel@tonic-gate (void) memset(&value, 0x0, sizeof (biginteger_t)); 1041034448feSmcpowers (void) memset(&point, 0x0, sizeof (biginteger_t)); 10427c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL; 1043034448feSmcpowers param_tmp.pValue = NULL; 10447c478bd9Sstevel@tonic-gate 10457c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) { 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate /* Public Key Object Attributes */ 10487c478bd9Sstevel@tonic-gate switch (template[i].type) { 10497c478bd9Sstevel@tonic-gate 10507c478bd9Sstevel@tonic-gate /* common key attributes */ 10517c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 10527c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue); 10537c478bd9Sstevel@tonic-gate break; 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate case CKA_ID: 10567c478bd9Sstevel@tonic-gate case CKA_START_DATE: 10577c478bd9Sstevel@tonic-gate case CKA_END_DATE: 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate /* common public key attribute */ 10607c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 10617c478bd9Sstevel@tonic-gate /* 10627c478bd9Sstevel@tonic-gate * Allocate storage to hold the attribute 10637c478bd9Sstevel@tonic-gate * value with byte array type, and add it to 10647c478bd9Sstevel@tonic-gate * the extra attribute list of the object. 10657c478bd9Sstevel@tonic-gate */ 10667c478bd9Sstevel@tonic-gate rv = kernel_add_extra_attr(&template[i], 10677c478bd9Sstevel@tonic-gate new_object); 10687c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 10697c478bd9Sstevel@tonic-gate goto fail_cleanup; 10707c478bd9Sstevel@tonic-gate } 10717c478bd9Sstevel@tonic-gate break; 10727c478bd9Sstevel@tonic-gate 10737c478bd9Sstevel@tonic-gate /* 10747c478bd9Sstevel@tonic-gate * The following key related attribute types must 10757c478bd9Sstevel@tonic-gate * not be specified by C_CreateObject. 10767c478bd9Sstevel@tonic-gate */ 10777c478bd9Sstevel@tonic-gate case CKA_LOCAL: 10787c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM: 10797c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 10807c478bd9Sstevel@tonic-gate goto fail_cleanup; 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 10837c478bd9Sstevel@tonic-gate case CKA_DERIVE: 10847c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 10857c478bd9Sstevel@tonic-gate attr_mask |= DERIVE_BOOL_ON; 10867c478bd9Sstevel@tonic-gate break; 10877c478bd9Sstevel@tonic-gate 10887c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 10897c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 10907c478bd9Sstevel@tonic-gate attr_mask |= ENCRYPT_BOOL_ON; 10917c478bd9Sstevel@tonic-gate else 10927c478bd9Sstevel@tonic-gate attr_mask &= ~ENCRYPT_BOOL_ON; 10937c478bd9Sstevel@tonic-gate break; 10947c478bd9Sstevel@tonic-gate 10957c478bd9Sstevel@tonic-gate case CKA_VERIFY: 10967c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 10977c478bd9Sstevel@tonic-gate attr_mask |= VERIFY_BOOL_ON; 10987c478bd9Sstevel@tonic-gate else 10997c478bd9Sstevel@tonic-gate attr_mask &= ~VERIFY_BOOL_ON; 11007c478bd9Sstevel@tonic-gate break; 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER: 11037c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 11047c478bd9Sstevel@tonic-gate attr_mask |= VERIFY_RECOVER_BOOL_ON; 11057c478bd9Sstevel@tonic-gate else 11067c478bd9Sstevel@tonic-gate attr_mask &= ~VERIFY_RECOVER_BOOL_ON; 11077c478bd9Sstevel@tonic-gate break; 11087c478bd9Sstevel@tonic-gate 11097c478bd9Sstevel@tonic-gate case CKA_WRAP: 11107c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 11117c478bd9Sstevel@tonic-gate attr_mask |= WRAP_BOOL_ON; 11127c478bd9Sstevel@tonic-gate break; 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate case CKA_TRUSTED: 11157c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 11167c478bd9Sstevel@tonic-gate attr_mask |= TRUSTED_BOOL_ON; 11177c478bd9Sstevel@tonic-gate break; 11187c478bd9Sstevel@tonic-gate 11197c478bd9Sstevel@tonic-gate /* 11207c478bd9Sstevel@tonic-gate * The following key related attribute types must 11217c478bd9Sstevel@tonic-gate * be specified according to the key type by 11227c478bd9Sstevel@tonic-gate * C_CreateObject. 11237c478bd9Sstevel@tonic-gate */ 11247c478bd9Sstevel@tonic-gate case CKA_MODULUS: 11257c478bd9Sstevel@tonic-gate isModulus = 1; 11267c478bd9Sstevel@tonic-gate /* 11277c478bd9Sstevel@tonic-gate * Copyin big integer attribute from template 11287c478bd9Sstevel@tonic-gate * to a local variable. 11297c478bd9Sstevel@tonic-gate */ 11307c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&modulus, 11317c478bd9Sstevel@tonic-gate &template[i]); 11327c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11337c478bd9Sstevel@tonic-gate goto fail_cleanup; 11347c478bd9Sstevel@tonic-gate break; 11357c478bd9Sstevel@tonic-gate 11367c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 11377c478bd9Sstevel@tonic-gate isPubExpo = 1; 11387c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&pubexpo, 11397c478bd9Sstevel@tonic-gate &template[i]); 11407c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11417c478bd9Sstevel@tonic-gate goto fail_cleanup; 11427c478bd9Sstevel@tonic-gate break; 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate case CKA_PRIME: 11457c478bd9Sstevel@tonic-gate isPrime = 1; 11467c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime, 11477c478bd9Sstevel@tonic-gate &template[i]); 11487c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11497c478bd9Sstevel@tonic-gate goto fail_cleanup; 11507c478bd9Sstevel@tonic-gate break; 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 11537c478bd9Sstevel@tonic-gate isSubprime = 1; 11547c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&subprime, 11557c478bd9Sstevel@tonic-gate &template[i]); 11567c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11577c478bd9Sstevel@tonic-gate goto fail_cleanup; 11587c478bd9Sstevel@tonic-gate break; 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate case CKA_BASE: 11617c478bd9Sstevel@tonic-gate isBase = 1; 11627c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&base, 11637c478bd9Sstevel@tonic-gate &template[i]); 11647c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11657c478bd9Sstevel@tonic-gate goto fail_cleanup; 11667c478bd9Sstevel@tonic-gate break; 11677c478bd9Sstevel@tonic-gate 11687c478bd9Sstevel@tonic-gate case CKA_VALUE: 11697c478bd9Sstevel@tonic-gate isValue = 1; 11707c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&value, 11717c478bd9Sstevel@tonic-gate &template[i]); 11727c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11737c478bd9Sstevel@tonic-gate goto fail_cleanup; 11747c478bd9Sstevel@tonic-gate break; 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS: 11777c478bd9Sstevel@tonic-gate isModulusBits = 1; 11787c478bd9Sstevel@tonic-gate get_ulong_attr_from_template(&modulus_bits, 11797c478bd9Sstevel@tonic-gate &template[i]); 11807c478bd9Sstevel@tonic-gate break; 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate case CKA_LABEL: 11837c478bd9Sstevel@tonic-gate isLabel = 1; 11847c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp, 11857c478bd9Sstevel@tonic-gate &template[i]); 11867c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 11877c478bd9Sstevel@tonic-gate goto fail_cleanup; 11887c478bd9Sstevel@tonic-gate break; 11897c478bd9Sstevel@tonic-gate 1190034448feSmcpowers case CKA_EC_POINT: 1191034448feSmcpowers isPoint = 1; 1192034448feSmcpowers rv = get_bigint_attr_from_template(&point, 1193034448feSmcpowers &template[i]); 1194034448feSmcpowers if (rv != CKR_OK) 1195034448feSmcpowers goto fail_cleanup; 1196034448feSmcpowers break; 1197034448feSmcpowers 1198034448feSmcpowers case CKA_EC_PARAMS: 1199034448feSmcpowers isParams = 1; 1200034448feSmcpowers rv = get_string_from_template(¶m_tmp, 1201034448feSmcpowers &template[i]); 1202034448feSmcpowers if (rv != CKR_OK) 1203034448feSmcpowers goto fail_cleanup; 1204034448feSmcpowers break; 1205034448feSmcpowers 12067c478bd9Sstevel@tonic-gate default: 12077c478bd9Sstevel@tonic-gate rv = kernel_parse_common_attrs(&template[i], sp, 12087c478bd9Sstevel@tonic-gate &attr_mask); 12097c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 12107c478bd9Sstevel@tonic-gate goto fail_cleanup; 12117c478bd9Sstevel@tonic-gate break; 12127c478bd9Sstevel@tonic-gate } 12137c478bd9Sstevel@tonic-gate } /* For */ 12147c478bd9Sstevel@tonic-gate 12157c478bd9Sstevel@tonic-gate /* Allocate storage for Public Key Object. */ 12167c478bd9Sstevel@tonic-gate pbk = calloc(1, sizeof (public_key_obj_t)); 12177c478bd9Sstevel@tonic-gate if (pbk == NULL) { 12187c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY; 12197c478bd9Sstevel@tonic-gate goto fail_cleanup; 12207c478bd9Sstevel@tonic-gate } 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate new_object->object_class_u.public_key = pbk; 12237c478bd9Sstevel@tonic-gate new_object->class = CKO_PUBLIC_KEY; 12247c478bd9Sstevel@tonic-gate 12257c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) { 12267c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 12277c478bd9Sstevel@tonic-gate goto fail_cleanup; 12287c478bd9Sstevel@tonic-gate } 12297c478bd9Sstevel@tonic-gate new_object->key_type = keytype; 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate /* Supported key types of the Public Key Object */ 12327c478bd9Sstevel@tonic-gate switch (keytype) { 12337c478bd9Sstevel@tonic-gate case CKK_RSA: 1234034448feSmcpowers if (mode == KERNEL_CREATE_OBJ) { 12357c478bd9Sstevel@tonic-gate if (isModulusBits || isPrime || isSubprime || 12367c478bd9Sstevel@tonic-gate isBase|| isValue) { 12377c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 12387c478bd9Sstevel@tonic-gate goto fail_cleanup; 12397c478bd9Sstevel@tonic-gate } 1240034448feSmcpowers } 12417c478bd9Sstevel@tonic-gate 12427c478bd9Sstevel@tonic-gate if (isModulus && isPubExpo) { 12437c478bd9Sstevel@tonic-gate /* 12447c478bd9Sstevel@tonic-gate * Copy big integer attribute value to the 12457c478bd9Sstevel@tonic-gate * designated place in the public key object. 12467c478bd9Sstevel@tonic-gate */ 1247034448feSmcpowers copy_bigint_attr(&modulus, 1248034448feSmcpowers KEY_PUB_RSA_MOD(pbk)); 12497c478bd9Sstevel@tonic-gate 1250034448feSmcpowers copy_bigint_attr(&pubexpo, 1251034448feSmcpowers KEY_PUB_RSA_PUBEXPO(pbk)); 12527c478bd9Sstevel@tonic-gate } else { 12537c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 12547c478bd9Sstevel@tonic-gate goto fail_cleanup; 12557c478bd9Sstevel@tonic-gate } 1256034448feSmcpowers 1257034448feSmcpowers /* must be generating a RSA key pair by value */ 1258034448feSmcpowers if (isModulusBits) { 1259034448feSmcpowers KEY_PUB_RSA_MOD_BITS(pbk) = modulus_bits; 1260034448feSmcpowers } 12617c478bd9Sstevel@tonic-gate break; 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate case CKK_DSA: 12647c478bd9Sstevel@tonic-gate if (isModulusBits || isModulus || isPubExpo) { 12657c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 12667c478bd9Sstevel@tonic-gate goto fail_cleanup; 12677c478bd9Sstevel@tonic-gate } 12687c478bd9Sstevel@tonic-gate 12697c478bd9Sstevel@tonic-gate if (!(isPrime && isSubprime && isBase && isValue)) { 12707c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 12717c478bd9Sstevel@tonic-gate goto fail_cleanup; 12727c478bd9Sstevel@tonic-gate } 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PUB_DSA_PRIME(pbk)); 12757c478bd9Sstevel@tonic-gate 12767c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime, KEY_PUB_DSA_SUBPRIME(pbk)); 12777c478bd9Sstevel@tonic-gate 12787c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PUB_DSA_BASE(pbk)); 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate copy_bigint_attr(&value, KEY_PUB_DSA_VALUE(pbk)); 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate break; 1283034448feSmcpowers 1284034448feSmcpowers case CKK_DH: 1285034448feSmcpowers if (!(isPrime && isBase && isValue)) { 1286034448feSmcpowers rv = CKR_TEMPLATE_INCOMPLETE; 1287034448feSmcpowers goto fail_cleanup; 1288034448feSmcpowers } 1289034448feSmcpowers 1290034448feSmcpowers copy_bigint_attr(&prime, KEY_PUB_DH_PRIME(pbk)); 1291034448feSmcpowers 1292034448feSmcpowers copy_bigint_attr(&base, KEY_PUB_DH_BASE(pbk)); 1293034448feSmcpowers 1294034448feSmcpowers copy_bigint_attr(&value, KEY_PUB_DH_VALUE(pbk)); 1295034448feSmcpowers 1296034448feSmcpowers break; 1297034448feSmcpowers 1298034448feSmcpowers case CKK_EC: 1299034448feSmcpowers if (!isPoint || !isParams) { 1300034448feSmcpowers rv = CKR_TEMPLATE_INCOMPLETE; 1301034448feSmcpowers goto fail_cleanup; 1302034448feSmcpowers } 1303034448feSmcpowers 1304034448feSmcpowers copy_bigint_attr(&point, KEY_PUB_EC_POINT(pbk)); 1305034448feSmcpowers rv = kernel_add_extra_attr(¶m_tmp, new_object); 1306034448feSmcpowers if (rv != CKR_OK) 1307034448feSmcpowers goto fail_cleanup; 1308034448feSmcpowers string_attr_cleanup(¶m_tmp); 1309034448feSmcpowers break; 13107c478bd9Sstevel@tonic-gate default: 13117c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 13127c478bd9Sstevel@tonic-gate goto fail_cleanup; 13137c478bd9Sstevel@tonic-gate } 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate /* Set up object. */ 13167c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask; 13177c478bd9Sstevel@tonic-gate if (isLabel) { 13187c478bd9Sstevel@tonic-gate rv = kernel_add_extra_attr(&string_tmp, new_object); 13197c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 13207c478bd9Sstevel@tonic-gate goto fail_cleanup; 13217c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp); 13227c478bd9Sstevel@tonic-gate } 13237c478bd9Sstevel@tonic-gate 13247c478bd9Sstevel@tonic-gate return (rv); 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate fail_cleanup: 13277c478bd9Sstevel@tonic-gate /* 13287c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables. 13297c478bd9Sstevel@tonic-gate */ 13307c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&modulus); 13317c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&pubexpo); 13327c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime); 13337c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&subprime); 13347c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&base); 13357c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&value); 1336034448feSmcpowers bigint_attr_cleanup(&point); 13377c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp); 1338034448feSmcpowers string_attr_cleanup(¶m_tmp); 13397c478bd9Sstevel@tonic-gate 13407c478bd9Sstevel@tonic-gate /* 13417c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself. 13427c478bd9Sstevel@tonic-gate */ 13437c478bd9Sstevel@tonic-gate kernel_cleanup_object(new_object); 13447c478bd9Sstevel@tonic-gate 13457c478bd9Sstevel@tonic-gate return (rv); 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate /* 13507c478bd9Sstevel@tonic-gate * Build a Private Key Object. 13517c478bd9Sstevel@tonic-gate * 13527c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as 13537c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return 13547c478bd9Sstevel@tonic-gate * with appropriate return value. 13557c478bd9Sstevel@tonic-gate * - Set up attribute mask field in the object for the supplied common 13567c478bd9Sstevel@tonic-gate * attributes that have boolean type. 13577c478bd9Sstevel@tonic-gate * - Build the attribute_info struct to hold the value of each supplied 13587c478bd9Sstevel@tonic-gate * attribute that has byte array type. Link attribute_info structs 13597c478bd9Sstevel@tonic-gate * together to form the extra attribute list of the object. 13607c478bd9Sstevel@tonic-gate * - Allocate storage for the Private Key object. 13617c478bd9Sstevel@tonic-gate * - Build the Private Key object according to the key type. Allocate 13627c478bd9Sstevel@tonic-gate * storage to hold the big integer value for the supplied attributes 13637c478bd9Sstevel@tonic-gate * that are required for a certain key type. 13647c478bd9Sstevel@tonic-gate * 13657c478bd9Sstevel@tonic-gate */ 13667c478bd9Sstevel@tonic-gate CK_RV 13677c478bd9Sstevel@tonic-gate kernel_build_private_key_object(CK_ATTRIBUTE_PTR template, 1368034448feSmcpowers CK_ULONG ulAttrNum, kernel_object_t *new_object, kernel_session_t *sp, 1369034448feSmcpowers uint_t mode) 13707c478bd9Sstevel@tonic-gate { 13717c478bd9Sstevel@tonic-gate ulong_t i; 13727c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL; 13737c478bd9Sstevel@tonic-gate uint64_t attr_mask = PRIVATE_KEY_DEFAULT; 13747c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 13757c478bd9Sstevel@tonic-gate int isLabel = 0; 13767c478bd9Sstevel@tonic-gate /* Must set flags */ 13777c478bd9Sstevel@tonic-gate int isModulus = 0; 13787c478bd9Sstevel@tonic-gate int isPriExpo = 0; 13797c478bd9Sstevel@tonic-gate int isPrime = 0; 13807c478bd9Sstevel@tonic-gate int isSubprime = 0; 13817c478bd9Sstevel@tonic-gate int isBase = 0; 13827c478bd9Sstevel@tonic-gate int isValue = 0; 1383034448feSmcpowers int isParams = 0; 13847c478bd9Sstevel@tonic-gate /* Must not set flags */ 13857c478bd9Sstevel@tonic-gate int isValueBits = 0; 13867c478bd9Sstevel@tonic-gate CK_ULONG value_bits = 0; 13877c478bd9Sstevel@tonic-gate 13887c478bd9Sstevel@tonic-gate /* Private Key RSA optional */ 13897c478bd9Sstevel@tonic-gate int isPubExpo = 0; 13907c478bd9Sstevel@tonic-gate int isPrime1 = 0; 13917c478bd9Sstevel@tonic-gate int isPrime2 = 0; 13927c478bd9Sstevel@tonic-gate int isExpo1 = 0; 13937c478bd9Sstevel@tonic-gate int isExpo2 = 0; 13947c478bd9Sstevel@tonic-gate int isCoef = 0; 13957c478bd9Sstevel@tonic-gate 13967c478bd9Sstevel@tonic-gate biginteger_t modulus; 13977c478bd9Sstevel@tonic-gate biginteger_t priexpo; 13987c478bd9Sstevel@tonic-gate biginteger_t prime; 13997c478bd9Sstevel@tonic-gate biginteger_t subprime; 14007c478bd9Sstevel@tonic-gate biginteger_t base; 14017c478bd9Sstevel@tonic-gate biginteger_t value; 14027c478bd9Sstevel@tonic-gate 14037c478bd9Sstevel@tonic-gate biginteger_t pubexpo; 14047c478bd9Sstevel@tonic-gate biginteger_t prime1; 14057c478bd9Sstevel@tonic-gate biginteger_t prime2; 14067c478bd9Sstevel@tonic-gate biginteger_t expo1; 14077c478bd9Sstevel@tonic-gate biginteger_t expo2; 14087c478bd9Sstevel@tonic-gate biginteger_t coef; 14097c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp; 1410034448feSmcpowers CK_ATTRIBUTE param_tmp; 14117c478bd9Sstevel@tonic-gate 14127c478bd9Sstevel@tonic-gate private_key_obj_t *pvk; 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate /* prevent bigint_attr_cleanup from freeing invalid attr value */ 14157c478bd9Sstevel@tonic-gate (void) memset(&modulus, 0x0, sizeof (biginteger_t)); 14167c478bd9Sstevel@tonic-gate (void) memset(&priexpo, 0x0, sizeof (biginteger_t)); 14177c478bd9Sstevel@tonic-gate (void) memset(&prime, 0x0, sizeof (biginteger_t)); 14187c478bd9Sstevel@tonic-gate (void) memset(&subprime, 0x0, sizeof (biginteger_t)); 14197c478bd9Sstevel@tonic-gate (void) memset(&base, 0x0, sizeof (biginteger_t)); 14207c478bd9Sstevel@tonic-gate (void) memset(&value, 0x0, sizeof (biginteger_t)); 14217c478bd9Sstevel@tonic-gate (void) memset(&pubexpo, 0x0, sizeof (biginteger_t)); 14227c478bd9Sstevel@tonic-gate (void) memset(&prime1, 0x0, sizeof (biginteger_t)); 14237c478bd9Sstevel@tonic-gate (void) memset(&prime2, 0x0, sizeof (biginteger_t)); 14247c478bd9Sstevel@tonic-gate (void) memset(&expo1, 0x0, sizeof (biginteger_t)); 14257c478bd9Sstevel@tonic-gate (void) memset(&expo2, 0x0, sizeof (biginteger_t)); 14267c478bd9Sstevel@tonic-gate (void) memset(&coef, 0x0, sizeof (biginteger_t)); 14277c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL; 1428034448feSmcpowers param_tmp.pValue = NULL; 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) { 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate /* Private Key Object Attributes */ 14337c478bd9Sstevel@tonic-gate switch (template[i].type) { 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate /* common key attributes */ 14367c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 14377c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue); 14387c478bd9Sstevel@tonic-gate break; 14397c478bd9Sstevel@tonic-gate 14407c478bd9Sstevel@tonic-gate case CKA_ID: 14417c478bd9Sstevel@tonic-gate case CKA_START_DATE: 14427c478bd9Sstevel@tonic-gate case CKA_END_DATE: 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate /* common private key attribute */ 14457c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 14467c478bd9Sstevel@tonic-gate /* 14477c478bd9Sstevel@tonic-gate * Allocate storage to hold the attribute 14487c478bd9Sstevel@tonic-gate * value with byte array type, and add it to 14497c478bd9Sstevel@tonic-gate * the extra attribute list of the object. 14507c478bd9Sstevel@tonic-gate */ 14517c478bd9Sstevel@tonic-gate rv = kernel_add_extra_attr(&template[i], 14527c478bd9Sstevel@tonic-gate new_object); 14537c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 14547c478bd9Sstevel@tonic-gate goto fail_cleanup; 14557c478bd9Sstevel@tonic-gate } 14567c478bd9Sstevel@tonic-gate break; 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate /* 14597c478bd9Sstevel@tonic-gate * The following key related attribute types must 14607c478bd9Sstevel@tonic-gate * not be specified by C_CreateObject. 14617c478bd9Sstevel@tonic-gate */ 14627c478bd9Sstevel@tonic-gate case CKA_LOCAL: 14637c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM: 14647c478bd9Sstevel@tonic-gate case CKA_AUTH_PIN_FLAGS: 14657c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE: 14667c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE: 14677c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 14687c478bd9Sstevel@tonic-gate goto fail_cleanup; 14697c478bd9Sstevel@tonic-gate 14707c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 14717c478bd9Sstevel@tonic-gate case CKA_DERIVE: 14727c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 14737c478bd9Sstevel@tonic-gate attr_mask |= DERIVE_BOOL_ON; 14747c478bd9Sstevel@tonic-gate break; 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 14777c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 14787c478bd9Sstevel@tonic-gate attr_mask |= SENSITIVE_BOOL_ON; 14797c478bd9Sstevel@tonic-gate break; 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate case CKA_SECONDARY_AUTH: 14827c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) { 14837c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 14847c478bd9Sstevel@tonic-gate goto fail_cleanup; 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate break; 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 14897c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 14907c478bd9Sstevel@tonic-gate attr_mask |= DECRYPT_BOOL_ON; 14917c478bd9Sstevel@tonic-gate else 14927c478bd9Sstevel@tonic-gate attr_mask &= ~DECRYPT_BOOL_ON; 14937c478bd9Sstevel@tonic-gate break; 14947c478bd9Sstevel@tonic-gate 14957c478bd9Sstevel@tonic-gate case CKA_SIGN: 14967c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 14977c478bd9Sstevel@tonic-gate attr_mask |= SIGN_BOOL_ON; 14987c478bd9Sstevel@tonic-gate else 14997c478bd9Sstevel@tonic-gate attr_mask &= ~SIGN_BOOL_ON; 15007c478bd9Sstevel@tonic-gate break; 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER: 15037c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 15047c478bd9Sstevel@tonic-gate attr_mask |= SIGN_RECOVER_BOOL_ON; 15057c478bd9Sstevel@tonic-gate else 15067c478bd9Sstevel@tonic-gate attr_mask &= ~SIGN_RECOVER_BOOL_ON; 15077c478bd9Sstevel@tonic-gate break; 15087c478bd9Sstevel@tonic-gate 15097c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 15107c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 15117c478bd9Sstevel@tonic-gate attr_mask |= UNWRAP_BOOL_ON; 15127c478bd9Sstevel@tonic-gate break; 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 15157c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 15167c478bd9Sstevel@tonic-gate attr_mask |= EXTRACTABLE_BOOL_ON; 15177c478bd9Sstevel@tonic-gate else 15187c478bd9Sstevel@tonic-gate attr_mask &= ~EXTRACTABLE_BOOL_ON; 15197c478bd9Sstevel@tonic-gate break; 15207c478bd9Sstevel@tonic-gate 15217c478bd9Sstevel@tonic-gate /* 15227c478bd9Sstevel@tonic-gate * The following key related attribute types must 15237c478bd9Sstevel@tonic-gate * be specified according to the key type by 15247c478bd9Sstevel@tonic-gate * C_CreateObject. 15257c478bd9Sstevel@tonic-gate */ 15267c478bd9Sstevel@tonic-gate case CKA_MODULUS: 15277c478bd9Sstevel@tonic-gate isModulus = 1; 15287c478bd9Sstevel@tonic-gate /* 15297c478bd9Sstevel@tonic-gate * Copyin big integer attribute from template 15307c478bd9Sstevel@tonic-gate * to a local variable. 15317c478bd9Sstevel@tonic-gate */ 15327c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&modulus, 15337c478bd9Sstevel@tonic-gate &template[i]); 15347c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15357c478bd9Sstevel@tonic-gate goto fail_cleanup; 15367c478bd9Sstevel@tonic-gate break; 15377c478bd9Sstevel@tonic-gate 15387c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 15397c478bd9Sstevel@tonic-gate isPubExpo = 1; 15407c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&pubexpo, 15417c478bd9Sstevel@tonic-gate &template[i]); 15427c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15437c478bd9Sstevel@tonic-gate goto fail_cleanup; 15447c478bd9Sstevel@tonic-gate break; 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT: 15477c478bd9Sstevel@tonic-gate isPriExpo = 1; 15487c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&priexpo, 15497c478bd9Sstevel@tonic-gate &template[i]); 15507c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15517c478bd9Sstevel@tonic-gate goto fail_cleanup; 15527c478bd9Sstevel@tonic-gate break; 15537c478bd9Sstevel@tonic-gate 15547c478bd9Sstevel@tonic-gate case CKA_PRIME_1: 15557c478bd9Sstevel@tonic-gate isPrime1 = 1; 15567c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime1, 15577c478bd9Sstevel@tonic-gate &template[i]); 15587c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15597c478bd9Sstevel@tonic-gate goto fail_cleanup; 15607c478bd9Sstevel@tonic-gate break; 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate case CKA_PRIME_2: 15637c478bd9Sstevel@tonic-gate isPrime2 = 1; 15647c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime2, 15657c478bd9Sstevel@tonic-gate &template[i]); 15667c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15677c478bd9Sstevel@tonic-gate goto fail_cleanup; 15687c478bd9Sstevel@tonic-gate break; 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1: 15717c478bd9Sstevel@tonic-gate isExpo1 = 1; 15727c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&expo1, 15737c478bd9Sstevel@tonic-gate &template[i]); 15747c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15757c478bd9Sstevel@tonic-gate goto fail_cleanup; 15767c478bd9Sstevel@tonic-gate break; 15777c478bd9Sstevel@tonic-gate 15787c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2: 15797c478bd9Sstevel@tonic-gate isExpo2 = 1; 15807c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&expo2, 15817c478bd9Sstevel@tonic-gate &template[i]); 15827c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15837c478bd9Sstevel@tonic-gate goto fail_cleanup; 15847c478bd9Sstevel@tonic-gate break; 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT: 15877c478bd9Sstevel@tonic-gate isCoef = 1; 15887c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&coef, 15897c478bd9Sstevel@tonic-gate &template[i]); 15907c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15917c478bd9Sstevel@tonic-gate goto fail_cleanup; 15927c478bd9Sstevel@tonic-gate break; 15937c478bd9Sstevel@tonic-gate 15947c478bd9Sstevel@tonic-gate case CKA_PRIME: 15957c478bd9Sstevel@tonic-gate isPrime = 1; 15967c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&prime, 15977c478bd9Sstevel@tonic-gate &template[i]); 15987c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 15997c478bd9Sstevel@tonic-gate goto fail_cleanup; 16007c478bd9Sstevel@tonic-gate break; 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 16037c478bd9Sstevel@tonic-gate isSubprime = 1; 16047c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&subprime, 16057c478bd9Sstevel@tonic-gate &template[i]); 16067c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 16077c478bd9Sstevel@tonic-gate goto fail_cleanup; 16087c478bd9Sstevel@tonic-gate break; 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate case CKA_BASE: 16117c478bd9Sstevel@tonic-gate isBase = 1; 16127c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&base, 16137c478bd9Sstevel@tonic-gate &template[i]); 16147c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 16157c478bd9Sstevel@tonic-gate goto fail_cleanup; 16167c478bd9Sstevel@tonic-gate break; 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate case CKA_VALUE: 16197c478bd9Sstevel@tonic-gate isValue = 1; 16207c478bd9Sstevel@tonic-gate rv = get_bigint_attr_from_template(&value, 16217c478bd9Sstevel@tonic-gate &template[i]); 16227c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 16237c478bd9Sstevel@tonic-gate goto fail_cleanup; 16247c478bd9Sstevel@tonic-gate break; 16257c478bd9Sstevel@tonic-gate 16267c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS: 16277c478bd9Sstevel@tonic-gate isValueBits = 1; 16287c478bd9Sstevel@tonic-gate get_ulong_attr_from_template(&value_bits, 16297c478bd9Sstevel@tonic-gate &template[i]); 16307c478bd9Sstevel@tonic-gate break; 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate case CKA_LABEL: 16337c478bd9Sstevel@tonic-gate isLabel = 1; 16347c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp, 16357c478bd9Sstevel@tonic-gate &template[i]); 16367c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 16377c478bd9Sstevel@tonic-gate goto fail_cleanup; 16387c478bd9Sstevel@tonic-gate break; 16397c478bd9Sstevel@tonic-gate 1640034448feSmcpowers case CKA_EC_PARAMS: 1641034448feSmcpowers isParams = 1; 1642034448feSmcpowers rv = get_string_from_template(¶m_tmp, 1643034448feSmcpowers &template[i]); 1644034448feSmcpowers if (rv != CKR_OK) 1645034448feSmcpowers goto fail_cleanup; 1646034448feSmcpowers break; 1647034448feSmcpowers 16487c478bd9Sstevel@tonic-gate default: 16497c478bd9Sstevel@tonic-gate rv = kernel_parse_common_attrs(&template[i], sp, 16507c478bd9Sstevel@tonic-gate &attr_mask); 16517c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 16527c478bd9Sstevel@tonic-gate goto fail_cleanup; 16537c478bd9Sstevel@tonic-gate break; 16547c478bd9Sstevel@tonic-gate 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate } /* For */ 16577c478bd9Sstevel@tonic-gate 16587c478bd9Sstevel@tonic-gate /* Allocate storage for Private Key Object. */ 16597c478bd9Sstevel@tonic-gate pvk = calloc(1, sizeof (private_key_obj_t)); 16607c478bd9Sstevel@tonic-gate if (pvk == NULL) { 16617c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY; 16627c478bd9Sstevel@tonic-gate goto fail_cleanup; 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate new_object->object_class_u.private_key = pvk; 16667c478bd9Sstevel@tonic-gate new_object->class = CKO_PRIVATE_KEY; 16677c478bd9Sstevel@tonic-gate 16687c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) { 16697c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 16707c478bd9Sstevel@tonic-gate goto fail_cleanup; 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate new_object->key_type = keytype; 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate /* Supported key types of the Private Key Object */ 16767c478bd9Sstevel@tonic-gate switch (keytype) { 16777c478bd9Sstevel@tonic-gate case CKK_RSA: 16787c478bd9Sstevel@tonic-gate if (isPrime || isSubprime || isBase || isValue || 16797c478bd9Sstevel@tonic-gate isValueBits) { 16807c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 16817c478bd9Sstevel@tonic-gate goto fail_cleanup; 16827c478bd9Sstevel@tonic-gate } 16837c478bd9Sstevel@tonic-gate 16847c478bd9Sstevel@tonic-gate if (isModulus && isPriExpo) { 16857c478bd9Sstevel@tonic-gate /* 16867c478bd9Sstevel@tonic-gate * Copy big integer attribute value to the 16877c478bd9Sstevel@tonic-gate * designated place in the Private Key object. 16887c478bd9Sstevel@tonic-gate */ 16897c478bd9Sstevel@tonic-gate copy_bigint_attr(&modulus, KEY_PRI_RSA_MOD(pvk)); 16907c478bd9Sstevel@tonic-gate 16917c478bd9Sstevel@tonic-gate copy_bigint_attr(&priexpo, KEY_PRI_RSA_PRIEXPO(pvk)); 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate } else { 16947c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 16957c478bd9Sstevel@tonic-gate goto fail_cleanup; 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate /* The following attributes are optional. */ 16997c478bd9Sstevel@tonic-gate if (isPubExpo) { 17007c478bd9Sstevel@tonic-gate copy_bigint_attr(&pubexpo, KEY_PRI_RSA_PUBEXPO(pvk)); 17017c478bd9Sstevel@tonic-gate } 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate if (isPrime1) { 17047c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime1, KEY_PRI_RSA_PRIME1(pvk)); 17057c478bd9Sstevel@tonic-gate } 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate if (isPrime2) { 17087c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime2, KEY_PRI_RSA_PRIME2(pvk)); 17097c478bd9Sstevel@tonic-gate } 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate if (isExpo1) { 17127c478bd9Sstevel@tonic-gate copy_bigint_attr(&expo1, KEY_PRI_RSA_EXPO1(pvk)); 17137c478bd9Sstevel@tonic-gate } 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate if (isExpo2) { 17167c478bd9Sstevel@tonic-gate copy_bigint_attr(&expo2, KEY_PRI_RSA_EXPO2(pvk)); 17177c478bd9Sstevel@tonic-gate } 17187c478bd9Sstevel@tonic-gate 17197c478bd9Sstevel@tonic-gate if (isCoef) { 17207c478bd9Sstevel@tonic-gate copy_bigint_attr(&coef, KEY_PRI_RSA_COEF(pvk)); 17217c478bd9Sstevel@tonic-gate } 17227c478bd9Sstevel@tonic-gate break; 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate case CKK_DSA: 17257c478bd9Sstevel@tonic-gate if (isModulus || isPubExpo || isPriExpo || isPrime1 || 17267c478bd9Sstevel@tonic-gate isPrime2 || isExpo1 || isExpo2 || isCoef || 17277c478bd9Sstevel@tonic-gate isValueBits) { 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 rv = CKR_TEMPLATE_INCOMPLETE; 17347c478bd9Sstevel@tonic-gate goto fail_cleanup; 17357c478bd9Sstevel@tonic-gate } 17367c478bd9Sstevel@tonic-gate 17377c478bd9Sstevel@tonic-gate copy_bigint_attr(&prime, KEY_PRI_DSA_PRIME(pvk)); 17387c478bd9Sstevel@tonic-gate 17397c478bd9Sstevel@tonic-gate copy_bigint_attr(&subprime, KEY_PRI_DSA_SUBPRIME(pvk)); 17407c478bd9Sstevel@tonic-gate 17417c478bd9Sstevel@tonic-gate copy_bigint_attr(&base, KEY_PRI_DSA_BASE(pvk)); 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate copy_bigint_attr(&value, KEY_PRI_DSA_VALUE(pvk)); 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate break; 17467c478bd9Sstevel@tonic-gate 1747034448feSmcpowers case CKK_DH: 1748034448feSmcpowers if (mode == KERNEL_CREATE_OBJ && isValueBits) { 1749034448feSmcpowers rv = CKR_TEMPLATE_INCONSISTENT; 1750034448feSmcpowers goto fail_cleanup; 1751034448feSmcpowers } 1752034448feSmcpowers if (!(isPrime && isBase && isValue)) { 1753034448feSmcpowers rv = CKR_TEMPLATE_INCOMPLETE; 1754034448feSmcpowers goto fail_cleanup; 1755034448feSmcpowers } 1756034448feSmcpowers 1757034448feSmcpowers copy_bigint_attr(&prime, KEY_PRI_DH_PRIME(pvk)); 1758034448feSmcpowers 1759034448feSmcpowers copy_bigint_attr(&base, KEY_PRI_DH_BASE(pvk)); 1760034448feSmcpowers 1761034448feSmcpowers copy_bigint_attr(&value, KEY_PRI_DH_VALUE(pvk)); 1762034448feSmcpowers 1763034448feSmcpowers KEY_PRI_DH_VAL_BITS(pvk) = (isValueBits) ? value_bits : 0; 1764034448feSmcpowers 1765034448feSmcpowers break; 1766034448feSmcpowers 1767034448feSmcpowers case CKK_EC: 1768034448feSmcpowers if (!isValue || !isParams) { 1769034448feSmcpowers rv = CKR_TEMPLATE_INCOMPLETE; 1770034448feSmcpowers goto fail_cleanup; 1771034448feSmcpowers } 1772034448feSmcpowers 1773034448feSmcpowers copy_bigint_attr(&value, KEY_PRI_EC_VALUE(pvk)); 1774034448feSmcpowers rv = kernel_add_extra_attr(¶m_tmp, new_object); 1775034448feSmcpowers if (rv != CKR_OK) 1776034448feSmcpowers goto fail_cleanup; 1777034448feSmcpowers string_attr_cleanup(¶m_tmp); 1778034448feSmcpowers break; 17797c478bd9Sstevel@tonic-gate default: 17807c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 17817c478bd9Sstevel@tonic-gate goto fail_cleanup; 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate 17847c478bd9Sstevel@tonic-gate /* Set up object. */ 17857c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask; 17867c478bd9Sstevel@tonic-gate if (isLabel) { 17877c478bd9Sstevel@tonic-gate rv = kernel_add_extra_attr(&string_tmp, new_object); 17887c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 17897c478bd9Sstevel@tonic-gate goto fail_cleanup; 17907c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp); 17917c478bd9Sstevel@tonic-gate } 17927c478bd9Sstevel@tonic-gate 17937c478bd9Sstevel@tonic-gate return (rv); 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate fail_cleanup: 17967c478bd9Sstevel@tonic-gate /* 17977c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables. 17987c478bd9Sstevel@tonic-gate */ 17997c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&modulus); 18007c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&priexpo); 18017c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime); 18027c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&subprime); 18037c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&base); 18047c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&value); 18057c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&pubexpo); 18067c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime1); 18077c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&prime2); 18087c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&expo1); 18097c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&expo2); 18107c478bd9Sstevel@tonic-gate bigint_attr_cleanup(&coef); 18117c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp); 1812034448feSmcpowers string_attr_cleanup(¶m_tmp); 18137c478bd9Sstevel@tonic-gate 18147c478bd9Sstevel@tonic-gate /* 18157c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself. 18167c478bd9Sstevel@tonic-gate */ 18177c478bd9Sstevel@tonic-gate kernel_cleanup_object(new_object); 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate return (rv); 18207c478bd9Sstevel@tonic-gate } 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate 18237c478bd9Sstevel@tonic-gate /* 18247c478bd9Sstevel@tonic-gate * Build a Secret Key Object. 18257c478bd9Sstevel@tonic-gate * 18267c478bd9Sstevel@tonic-gate * - Parse the object's template, and when an error is detected such as 18277c478bd9Sstevel@tonic-gate * invalid attribute type, invalid attribute value, etc., return 18287c478bd9Sstevel@tonic-gate * with appropriate return value. 18297c478bd9Sstevel@tonic-gate * - Set up attribute mask field in the object for the supplied common 18307c478bd9Sstevel@tonic-gate * attributes that have boolean type. 18317c478bd9Sstevel@tonic-gate * - Build the attribute_info struct to hold the value of each supplied 18327c478bd9Sstevel@tonic-gate * attribute that has byte array type. Link attribute_info structs 18337c478bd9Sstevel@tonic-gate * together to form the extra attribute list of the object. 18347c478bd9Sstevel@tonic-gate * - Allocate storage for the Secret Key object. 18357c478bd9Sstevel@tonic-gate * - Build the Secret Key object. Allocate storage to hold the big integer 18367c478bd9Sstevel@tonic-gate * value for the attribute CKA_VALUE that is required for all the key 18377c478bd9Sstevel@tonic-gate * types supported by secret key object. 18387c478bd9Sstevel@tonic-gate * 18397c478bd9Sstevel@tonic-gate */ 18407c478bd9Sstevel@tonic-gate CK_RV 18417c478bd9Sstevel@tonic-gate kernel_build_secret_key_object(CK_ATTRIBUTE_PTR template, 18427c478bd9Sstevel@tonic-gate CK_ULONG ulAttrNum, kernel_object_t *new_object, kernel_session_t *sp) 18437c478bd9Sstevel@tonic-gate { 18447c478bd9Sstevel@tonic-gate 18457c478bd9Sstevel@tonic-gate int i; 18467c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = (CK_KEY_TYPE)~0UL; 18477c478bd9Sstevel@tonic-gate uint64_t attr_mask = SECRET_KEY_DEFAULT; 18487c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 18497c478bd9Sstevel@tonic-gate int isLabel = 0; 18507c478bd9Sstevel@tonic-gate /* Must set flags */ 18517c478bd9Sstevel@tonic-gate int isValue = 0; 18527c478bd9Sstevel@tonic-gate /* Must not set flags */ 18537c478bd9Sstevel@tonic-gate int isValueLen = 0; 18547c478bd9Sstevel@tonic-gate 18557c478bd9Sstevel@tonic-gate CK_ATTRIBUTE string_tmp; 18567c478bd9Sstevel@tonic-gate 18577c478bd9Sstevel@tonic-gate secret_key_obj_t *sck; 18587c478bd9Sstevel@tonic-gate 18597c478bd9Sstevel@tonic-gate string_tmp.pValue = NULL; 18607c478bd9Sstevel@tonic-gate 18617c478bd9Sstevel@tonic-gate /* Allocate storage for Secret Key Object. */ 18627c478bd9Sstevel@tonic-gate sck = calloc(1, sizeof (secret_key_obj_t)); 18637c478bd9Sstevel@tonic-gate if (sck == NULL) { 18647c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY; 18657c478bd9Sstevel@tonic-gate goto fail_cleanup; 18667c478bd9Sstevel@tonic-gate } 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate new_object->object_class_u.secret_key = sck; 18697c478bd9Sstevel@tonic-gate new_object->class = CKO_SECRET_KEY; 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate for (i = 0; i < ulAttrNum; i++) { 18727c478bd9Sstevel@tonic-gate 18737c478bd9Sstevel@tonic-gate /* Secret Key Object Attributes */ 18747c478bd9Sstevel@tonic-gate switch (template[i].type) { 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate /* common key attributes */ 18777c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 18787c478bd9Sstevel@tonic-gate keytype = *((CK_KEY_TYPE*)template[i].pValue); 18797c478bd9Sstevel@tonic-gate break; 18807c478bd9Sstevel@tonic-gate 18817c478bd9Sstevel@tonic-gate case CKA_ID: 18827c478bd9Sstevel@tonic-gate case CKA_START_DATE: 18837c478bd9Sstevel@tonic-gate case CKA_END_DATE: 18847c478bd9Sstevel@tonic-gate /* 18857c478bd9Sstevel@tonic-gate * Allocate storage to hold the attribute 18867c478bd9Sstevel@tonic-gate * value with byte array type, and add it to 18877c478bd9Sstevel@tonic-gate * the extra attribute list of the object. 18887c478bd9Sstevel@tonic-gate */ 18897c478bd9Sstevel@tonic-gate rv = kernel_add_extra_attr(&template[i], 18907c478bd9Sstevel@tonic-gate new_object); 18917c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 18927c478bd9Sstevel@tonic-gate goto fail_cleanup; 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate break; 18957c478bd9Sstevel@tonic-gate 18967c478bd9Sstevel@tonic-gate /* 18977c478bd9Sstevel@tonic-gate * The following key related attribute types must 18987c478bd9Sstevel@tonic-gate * not be specified by C_CreateObject. 18997c478bd9Sstevel@tonic-gate */ 19007c478bd9Sstevel@tonic-gate case CKA_LOCAL: 19017c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM: 19027c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE: 19037c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE: 19047c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 19057c478bd9Sstevel@tonic-gate goto fail_cleanup; 19067c478bd9Sstevel@tonic-gate 19077c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 19087c478bd9Sstevel@tonic-gate case CKA_DERIVE: 19097c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19107c478bd9Sstevel@tonic-gate attr_mask |= DERIVE_BOOL_ON; 19117c478bd9Sstevel@tonic-gate break; 19127c478bd9Sstevel@tonic-gate 19137c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 19147c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19157c478bd9Sstevel@tonic-gate attr_mask |= SENSITIVE_BOOL_ON; 19167c478bd9Sstevel@tonic-gate break; 19177c478bd9Sstevel@tonic-gate 19187c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 19197c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19207c478bd9Sstevel@tonic-gate attr_mask |= ENCRYPT_BOOL_ON; 19217c478bd9Sstevel@tonic-gate else 19227c478bd9Sstevel@tonic-gate attr_mask &= ~ENCRYPT_BOOL_ON; 19237c478bd9Sstevel@tonic-gate break; 19247c478bd9Sstevel@tonic-gate 19257c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 19267c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19277c478bd9Sstevel@tonic-gate attr_mask |= DECRYPT_BOOL_ON; 19287c478bd9Sstevel@tonic-gate else 19297c478bd9Sstevel@tonic-gate attr_mask &= ~DECRYPT_BOOL_ON; 19307c478bd9Sstevel@tonic-gate break; 19317c478bd9Sstevel@tonic-gate 19327c478bd9Sstevel@tonic-gate case CKA_SIGN: 19337c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19347c478bd9Sstevel@tonic-gate attr_mask |= SIGN_BOOL_ON; 19357c478bd9Sstevel@tonic-gate else 19367c478bd9Sstevel@tonic-gate attr_mask &= ~SIGN_BOOL_ON; 19377c478bd9Sstevel@tonic-gate break; 19387c478bd9Sstevel@tonic-gate 19397c478bd9Sstevel@tonic-gate case CKA_VERIFY: 19407c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19417c478bd9Sstevel@tonic-gate attr_mask |= VERIFY_BOOL_ON; 19427c478bd9Sstevel@tonic-gate else 19437c478bd9Sstevel@tonic-gate attr_mask &= ~VERIFY_BOOL_ON; 19447c478bd9Sstevel@tonic-gate break; 19457c478bd9Sstevel@tonic-gate 19467c478bd9Sstevel@tonic-gate case CKA_WRAP: 19477c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19487c478bd9Sstevel@tonic-gate attr_mask |= WRAP_BOOL_ON; 19497c478bd9Sstevel@tonic-gate break; 19507c478bd9Sstevel@tonic-gate 19517c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 19527c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19537c478bd9Sstevel@tonic-gate attr_mask |= UNWRAP_BOOL_ON; 19547c478bd9Sstevel@tonic-gate break; 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 19577c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template[i].pValue) 19587c478bd9Sstevel@tonic-gate attr_mask |= EXTRACTABLE_BOOL_ON; 19597c478bd9Sstevel@tonic-gate else 19607c478bd9Sstevel@tonic-gate attr_mask &= ~EXTRACTABLE_BOOL_ON; 19617c478bd9Sstevel@tonic-gate break; 19627c478bd9Sstevel@tonic-gate 19637c478bd9Sstevel@tonic-gate case CKA_VALUE: 19647c478bd9Sstevel@tonic-gate isValue = 1; 19657c478bd9Sstevel@tonic-gate if ((template[i].ulValueLen == 0) || 19667c478bd9Sstevel@tonic-gate (template[i].pValue == NULL)) { 19677c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 19687c478bd9Sstevel@tonic-gate goto fail_cleanup; 19697c478bd9Sstevel@tonic-gate } 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate /* 19727c478bd9Sstevel@tonic-gate * Copyin attribute from template 19737c478bd9Sstevel@tonic-gate * to a local variable. 19747c478bd9Sstevel@tonic-gate */ 19757c478bd9Sstevel@tonic-gate sck->sk_value = malloc(template[i].ulValueLen); 19767c478bd9Sstevel@tonic-gate if (sck->sk_value == NULL) { 19777c478bd9Sstevel@tonic-gate rv = CKR_HOST_MEMORY; 19787c478bd9Sstevel@tonic-gate goto fail_cleanup; 19797c478bd9Sstevel@tonic-gate } 19807c478bd9Sstevel@tonic-gate (void) memcpy(sck->sk_value, template[i].pValue, 19817c478bd9Sstevel@tonic-gate template[i].ulValueLen); 19827c478bd9Sstevel@tonic-gate sck->sk_value_len = template[i].ulValueLen; 19837c478bd9Sstevel@tonic-gate break; 19847c478bd9Sstevel@tonic-gate 19857c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN: 19867c478bd9Sstevel@tonic-gate isValueLen = 1; 19877c478bd9Sstevel@tonic-gate break; 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate case CKA_LABEL: 19907c478bd9Sstevel@tonic-gate isLabel = 1; 19917c478bd9Sstevel@tonic-gate rv = get_string_from_template(&string_tmp, 19927c478bd9Sstevel@tonic-gate &template[i]); 19937c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 19947c478bd9Sstevel@tonic-gate goto fail_cleanup; 19957c478bd9Sstevel@tonic-gate break; 19967c478bd9Sstevel@tonic-gate 19977c478bd9Sstevel@tonic-gate default: 19987c478bd9Sstevel@tonic-gate rv = kernel_parse_common_attrs(&template[i], sp, 19997c478bd9Sstevel@tonic-gate &attr_mask); 20007c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 20017c478bd9Sstevel@tonic-gate goto fail_cleanup; 20027c478bd9Sstevel@tonic-gate break; 20037c478bd9Sstevel@tonic-gate 20047c478bd9Sstevel@tonic-gate } 20057c478bd9Sstevel@tonic-gate } /* For */ 20067c478bd9Sstevel@tonic-gate 20077c478bd9Sstevel@tonic-gate if (keytype == (CK_KEY_TYPE)~0UL) { 20087c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20097c478bd9Sstevel@tonic-gate goto fail_cleanup; 20107c478bd9Sstevel@tonic-gate } 20117c478bd9Sstevel@tonic-gate 20127c478bd9Sstevel@tonic-gate new_object->key_type = keytype; 20137c478bd9Sstevel@tonic-gate 20147c478bd9Sstevel@tonic-gate /* Supported key types of the Secret Key Object */ 20157c478bd9Sstevel@tonic-gate switch (keytype) { 20167c478bd9Sstevel@tonic-gate case CKK_RC4: 20177c478bd9Sstevel@tonic-gate if (!isValue) { 20187c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20197c478bd9Sstevel@tonic-gate goto fail_cleanup; 20207c478bd9Sstevel@tonic-gate } 20217c478bd9Sstevel@tonic-gate if ((sck->sk_value_len < ARCFOUR_MIN_KEY_BYTES) || 20227c478bd9Sstevel@tonic-gate (sck->sk_value_len > ARCFOUR_MAX_KEY_BYTES)) { 20237c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 20247c478bd9Sstevel@tonic-gate goto fail_cleanup; 20257c478bd9Sstevel@tonic-gate } 20267c478bd9Sstevel@tonic-gate break; 20277c478bd9Sstevel@tonic-gate 20287c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET: 20297c478bd9Sstevel@tonic-gate if (!isValue) { 20307c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20317c478bd9Sstevel@tonic-gate goto fail_cleanup; 20327c478bd9Sstevel@tonic-gate } 20337c478bd9Sstevel@tonic-gate break; 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate case CKK_AES: 20367c478bd9Sstevel@tonic-gate if (!isValue) { 20377c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20387c478bd9Sstevel@tonic-gate goto fail_cleanup; 20397c478bd9Sstevel@tonic-gate } 20407c478bd9Sstevel@tonic-gate if (sck->sk_value_len < AES_MIN_KEY_BYTES) { 20417c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 20427c478bd9Sstevel@tonic-gate goto fail_cleanup; 20437c478bd9Sstevel@tonic-gate } 20447c478bd9Sstevel@tonic-gate break; 20457c478bd9Sstevel@tonic-gate 2046f66d273dSizick case CKK_BLOWFISH: 2047f66d273dSizick if (!isValue) { 2048f66d273dSizick rv = CKR_TEMPLATE_INCOMPLETE; 2049f66d273dSizick goto fail_cleanup; 2050f66d273dSizick } 2051f66d273dSizick if (sck->sk_value_len < BLOWFISH_MINBYTES) { 2052f66d273dSizick rv = CKR_ATTRIBUTE_VALUE_INVALID; 2053f66d273dSizick goto fail_cleanup; 2054f66d273dSizick } 2055f66d273dSizick break; 2056f66d273dSizick 20577c478bd9Sstevel@tonic-gate case CKK_DES: 20587c478bd9Sstevel@tonic-gate if (!isValue) { 20597c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20607c478bd9Sstevel@tonic-gate goto fail_cleanup; 20617c478bd9Sstevel@tonic-gate } 20627c478bd9Sstevel@tonic-gate if (sck->sk_value_len != DES_KEYSIZE) { 20637c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 20647c478bd9Sstevel@tonic-gate goto fail_cleanup; 20657c478bd9Sstevel@tonic-gate } 20667c478bd9Sstevel@tonic-gate break; 20677c478bd9Sstevel@tonic-gate 20687c478bd9Sstevel@tonic-gate case CKK_DES2: 20697c478bd9Sstevel@tonic-gate if (!isValue) { 20707c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20717c478bd9Sstevel@tonic-gate goto fail_cleanup; 20727c478bd9Sstevel@tonic-gate } 20737c478bd9Sstevel@tonic-gate if (sck->sk_value_len != DES2_KEYSIZE) { 20747c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 20757c478bd9Sstevel@tonic-gate goto fail_cleanup; 20767c478bd9Sstevel@tonic-gate } 20777c478bd9Sstevel@tonic-gate break; 20787c478bd9Sstevel@tonic-gate 20797c478bd9Sstevel@tonic-gate case CKK_DES3: 20807c478bd9Sstevel@tonic-gate if (!isValue) { 20817c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCOMPLETE; 20827c478bd9Sstevel@tonic-gate goto fail_cleanup; 20837c478bd9Sstevel@tonic-gate } 20847c478bd9Sstevel@tonic-gate if (sck->sk_value_len != DES3_KEYSIZE) { 20857c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_VALUE_INVALID; 20867c478bd9Sstevel@tonic-gate goto fail_cleanup; 20877c478bd9Sstevel@tonic-gate } 20887c478bd9Sstevel@tonic-gate break; 20897c478bd9Sstevel@tonic-gate 20907c478bd9Sstevel@tonic-gate default: 20917c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 20927c478bd9Sstevel@tonic-gate goto fail_cleanup; 20937c478bd9Sstevel@tonic-gate } 20947c478bd9Sstevel@tonic-gate 20957c478bd9Sstevel@tonic-gate if (isValueLen) { 20967c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 20977c478bd9Sstevel@tonic-gate goto fail_cleanup; 20987c478bd9Sstevel@tonic-gate } 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate /* Set up object. */ 21017c478bd9Sstevel@tonic-gate new_object->bool_attr_mask = attr_mask; 21027c478bd9Sstevel@tonic-gate if (isLabel) { 21037c478bd9Sstevel@tonic-gate rv = kernel_add_extra_attr(&string_tmp, new_object); 21047c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 21057c478bd9Sstevel@tonic-gate goto fail_cleanup; 21067c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp); 21077c478bd9Sstevel@tonic-gate } 21087c478bd9Sstevel@tonic-gate 21097c478bd9Sstevel@tonic-gate return (rv); 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate fail_cleanup: 21127c478bd9Sstevel@tonic-gate /* 21137c478bd9Sstevel@tonic-gate * cleanup the storage allocated to the local variables. 21147c478bd9Sstevel@tonic-gate */ 21157c478bd9Sstevel@tonic-gate string_attr_cleanup(&string_tmp); 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate /* 21187c478bd9Sstevel@tonic-gate * cleanup the storage allocated inside the object itself. 21197c478bd9Sstevel@tonic-gate */ 21207c478bd9Sstevel@tonic-gate kernel_cleanup_object(new_object); 21217c478bd9Sstevel@tonic-gate 21227c478bd9Sstevel@tonic-gate return (rv); 21237c478bd9Sstevel@tonic-gate } 21247c478bd9Sstevel@tonic-gate 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate /* 21277c478bd9Sstevel@tonic-gate * Validate the attribute types in the object's template. Then, 21287c478bd9Sstevel@tonic-gate * call the appropriate build function according to the class of 21297c478bd9Sstevel@tonic-gate * the object specified in the template. 21307c478bd9Sstevel@tonic-gate * 21317c478bd9Sstevel@tonic-gate * Note: The following classes of objects are supported: 21327c478bd9Sstevel@tonic-gate * - CKO_SECRET_KEY 21337c478bd9Sstevel@tonic-gate * - CKO_PUBLIC_KEY 21347c478bd9Sstevel@tonic-gate * - CKO_PRIVATE_KEY 21357c478bd9Sstevel@tonic-gate */ 21367c478bd9Sstevel@tonic-gate CK_RV 21377c478bd9Sstevel@tonic-gate kernel_build_object(CK_ATTRIBUTE_PTR template, CK_ULONG ulAttrNum, 2138034448feSmcpowers kernel_object_t *new_object, kernel_session_t *sp, uint_t mode) 21397c478bd9Sstevel@tonic-gate { 21407c478bd9Sstevel@tonic-gate 21417c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = (CK_OBJECT_CLASS)~0UL; 21427c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate if (template == NULL) { 21457c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD); 21467c478bd9Sstevel@tonic-gate } 21477c478bd9Sstevel@tonic-gate 21487c478bd9Sstevel@tonic-gate /* Validate the attribute type in the template. */ 21497c478bd9Sstevel@tonic-gate rv = kernel_validate_attr(template, ulAttrNum, &class); 21507c478bd9Sstevel@tonic-gate if (rv != CKR_OK) 21517c478bd9Sstevel@tonic-gate return (rv); 21527c478bd9Sstevel@tonic-gate 21537c478bd9Sstevel@tonic-gate if (class == (CK_OBJECT_CLASS)~0UL) 21547c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCOMPLETE); 21557c478bd9Sstevel@tonic-gate 21567c478bd9Sstevel@tonic-gate /* 21577c478bd9Sstevel@tonic-gate * Call the appropriate function based on the supported class 21587c478bd9Sstevel@tonic-gate * of the object. 21597c478bd9Sstevel@tonic-gate */ 21607c478bd9Sstevel@tonic-gate switch (class) { 21617c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY: 21627c478bd9Sstevel@tonic-gate rv = kernel_build_public_key_object(template, ulAttrNum, 2163034448feSmcpowers new_object, sp, mode); 21647c478bd9Sstevel@tonic-gate break; 21657c478bd9Sstevel@tonic-gate 21667c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY: 21677c478bd9Sstevel@tonic-gate rv = kernel_build_private_key_object(template, ulAttrNum, 2168034448feSmcpowers new_object, sp, mode); 21697c478bd9Sstevel@tonic-gate break; 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY: 21727c478bd9Sstevel@tonic-gate rv = kernel_build_secret_key_object(template, ulAttrNum, 21737c478bd9Sstevel@tonic-gate new_object, sp); 21747c478bd9Sstevel@tonic-gate break; 21757c478bd9Sstevel@tonic-gate 21767c478bd9Sstevel@tonic-gate case CKO_DOMAIN_PARAMETERS: 21777c478bd9Sstevel@tonic-gate case CKO_DATA: 21787c478bd9Sstevel@tonic-gate case CKO_CERTIFICATE: 21797c478bd9Sstevel@tonic-gate case CKO_HW_FEATURE: 21807c478bd9Sstevel@tonic-gate case CKO_VENDOR_DEFINED: 21817c478bd9Sstevel@tonic-gate default: 21827c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_VALUE_INVALID); 21837c478bd9Sstevel@tonic-gate } 21847c478bd9Sstevel@tonic-gate 21857c478bd9Sstevel@tonic-gate return (rv); 21867c478bd9Sstevel@tonic-gate } 21877c478bd9Sstevel@tonic-gate 21887c478bd9Sstevel@tonic-gate 21897c478bd9Sstevel@tonic-gate /* 21907c478bd9Sstevel@tonic-gate * Get the value of a requested attribute that is common to all supported 21917c478bd9Sstevel@tonic-gate * classes (i.e. public key, private key, secret key classes). 21927c478bd9Sstevel@tonic-gate */ 21937c478bd9Sstevel@tonic-gate CK_RV 21947c478bd9Sstevel@tonic-gate kernel_get_common_attrs(kernel_object_t *object_p, CK_ATTRIBUTE_PTR template) 21957c478bd9Sstevel@tonic-gate { 21967c478bd9Sstevel@tonic-gate 21977c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 21987c478bd9Sstevel@tonic-gate 21997c478bd9Sstevel@tonic-gate switch (template->type) { 22007c478bd9Sstevel@tonic-gate 22017c478bd9Sstevel@tonic-gate case CKA_CLASS: 22027c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(object_p->class, 22037c478bd9Sstevel@tonic-gate template)); 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate /* default boolean attributes */ 22067c478bd9Sstevel@tonic-gate case CKA_TOKEN: 22077c478bd9Sstevel@tonic-gate 22087c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL); 22097c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 22107c478bd9Sstevel@tonic-gate return (CKR_OK); 22117c478bd9Sstevel@tonic-gate } 22127c478bd9Sstevel@tonic-gate 22137c478bd9Sstevel@tonic-gate /* 22147c478bd9Sstevel@tonic-gate * A token object will not be created in the library, so we 22157c478bd9Sstevel@tonic-gate * return FALSE. 22167c478bd9Sstevel@tonic-gate */ 22177c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE; 22187c478bd9Sstevel@tonic-gate break; 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate case CKA_PRIVATE: 22217c478bd9Sstevel@tonic-gate 22227c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL); 22237c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 22247c478bd9Sstevel@tonic-gate return (CKR_OK); 22257c478bd9Sstevel@tonic-gate } 22267c478bd9Sstevel@tonic-gate if (object_p->bool_attr_mask & PRIVATE_BOOL_ON) { 22277c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE; 22287c478bd9Sstevel@tonic-gate } else { 22297c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE; 22307c478bd9Sstevel@tonic-gate } 22317c478bd9Sstevel@tonic-gate break; 22327c478bd9Sstevel@tonic-gate 22337c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE: 22347c478bd9Sstevel@tonic-gate template->ulValueLen = sizeof (CK_BBOOL); 22357c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 22367c478bd9Sstevel@tonic-gate return (CKR_OK); 22377c478bd9Sstevel@tonic-gate } 22387c478bd9Sstevel@tonic-gate if ((object_p->bool_attr_mask) & MODIFIABLE_BOOL_ON) 22397c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_TRUE; 22407c478bd9Sstevel@tonic-gate else 22417c478bd9Sstevel@tonic-gate *((CK_BBOOL *)template->pValue) = B_FALSE; 22427c478bd9Sstevel@tonic-gate break; 22437c478bd9Sstevel@tonic-gate 22447c478bd9Sstevel@tonic-gate case CKA_LABEL: 22457c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p, 22467c478bd9Sstevel@tonic-gate template)); 22477c478bd9Sstevel@tonic-gate 22487c478bd9Sstevel@tonic-gate default: 22497c478bd9Sstevel@tonic-gate /* 22507c478bd9Sstevel@tonic-gate * The specified attribute for the object is invalid. 22517c478bd9Sstevel@tonic-gate * (the object does not possess such an attribute.) 22527c478bd9Sstevel@tonic-gate */ 22537c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 22547c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 22557c478bd9Sstevel@tonic-gate } 22567c478bd9Sstevel@tonic-gate 22577c478bd9Sstevel@tonic-gate return (rv); 22587c478bd9Sstevel@tonic-gate } 22597c478bd9Sstevel@tonic-gate 22607c478bd9Sstevel@tonic-gate /* 22617c478bd9Sstevel@tonic-gate * Get the value of a requested attribute that is common to all key objects 22627c478bd9Sstevel@tonic-gate * (i.e. public key, private key and secret key). 22637c478bd9Sstevel@tonic-gate */ 22647c478bd9Sstevel@tonic-gate CK_RV 22657c478bd9Sstevel@tonic-gate kernel_get_common_key_attrs(kernel_object_t *object_p, 22667c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 22677c478bd9Sstevel@tonic-gate { 22687c478bd9Sstevel@tonic-gate 22697c478bd9Sstevel@tonic-gate switch (template->type) { 22707c478bd9Sstevel@tonic-gate 22717c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 22727c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(object_p->key_type, 22737c478bd9Sstevel@tonic-gate template)); 22747c478bd9Sstevel@tonic-gate 22757c478bd9Sstevel@tonic-gate case CKA_ID: 22767c478bd9Sstevel@tonic-gate case CKA_START_DATE: 22777c478bd9Sstevel@tonic-gate case CKA_END_DATE: 22787c478bd9Sstevel@tonic-gate /* 22797c478bd9Sstevel@tonic-gate * The above extra attributes have byte array type. 22807c478bd9Sstevel@tonic-gate */ 22817c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p, 22827c478bd9Sstevel@tonic-gate template)); 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 22857c478bd9Sstevel@tonic-gate case CKA_LOCAL: 22867c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 22877c478bd9Sstevel@tonic-gate LOCAL_BOOL_ON, template)); 22887c478bd9Sstevel@tonic-gate 22897c478bd9Sstevel@tonic-gate case CKA_DERIVE: 22907c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 22917c478bd9Sstevel@tonic-gate DERIVE_BOOL_ON, template)); 22927c478bd9Sstevel@tonic-gate 22937c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM: 22947c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(object_p->mechanism, 22957c478bd9Sstevel@tonic-gate template)); 22967c478bd9Sstevel@tonic-gate 22977c478bd9Sstevel@tonic-gate default: 22987c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 22997c478bd9Sstevel@tonic-gate } 23007c478bd9Sstevel@tonic-gate } 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate 23037c478bd9Sstevel@tonic-gate /* 23047c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Public Key Object. 23057c478bd9Sstevel@tonic-gate * 23067c478bd9Sstevel@tonic-gate * Rule: All the attributes in the public key object can be revealed. 23077c478bd9Sstevel@tonic-gate */ 23087c478bd9Sstevel@tonic-gate CK_RV 23097c478bd9Sstevel@tonic-gate kernel_get_public_key_attribute(kernel_object_t *object_p, 23107c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 23117c478bd9Sstevel@tonic-gate { 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 23147c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate switch (template->type) { 23177c478bd9Sstevel@tonic-gate 23187c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 2319034448feSmcpowers case CKA_EC_PARAMS: 23207c478bd9Sstevel@tonic-gate /* 23217c478bd9Sstevel@tonic-gate * The above extra attributes have byte array type. 23227c478bd9Sstevel@tonic-gate */ 23237c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p, 23247c478bd9Sstevel@tonic-gate template)); 23257c478bd9Sstevel@tonic-gate 23267c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 23277c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 23287c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 23297c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template)); 23307c478bd9Sstevel@tonic-gate 23317c478bd9Sstevel@tonic-gate case CKA_VERIFY: 23327c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 23337c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template)); 23347c478bd9Sstevel@tonic-gate 23357c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER: 23367c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 23377c478bd9Sstevel@tonic-gate VERIFY_RECOVER_BOOL_ON, template)); 23387c478bd9Sstevel@tonic-gate 23397c478bd9Sstevel@tonic-gate case CKA_WRAP: 23407c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 23417c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template)); 23427c478bd9Sstevel@tonic-gate 23437c478bd9Sstevel@tonic-gate case CKA_TRUSTED: 23447c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 23457c478bd9Sstevel@tonic-gate TRUSTED_BOOL_ON, template)); 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate case CKA_MODULUS: 23487c478bd9Sstevel@tonic-gate /* 23497c478bd9Sstevel@tonic-gate * This attribute is valid only for RSA public key 23507c478bd9Sstevel@tonic-gate * object. 23517c478bd9Sstevel@tonic-gate */ 23527c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 23537c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 23547c478bd9Sstevel@tonic-gate OBJ_PUB_RSA_MOD(object_p), template)); 23557c478bd9Sstevel@tonic-gate } else { 23567c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 23577c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 23587c478bd9Sstevel@tonic-gate } 23597c478bd9Sstevel@tonic-gate 23607c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 23617c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 23627c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 23637c478bd9Sstevel@tonic-gate OBJ_PUB_RSA_PUBEXPO(object_p), template)); 23647c478bd9Sstevel@tonic-gate } else { 23657c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 23667c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 23677c478bd9Sstevel@tonic-gate } 23687c478bd9Sstevel@tonic-gate 23697c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS: 23707c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 23717c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object( 23727c478bd9Sstevel@tonic-gate OBJ_PUB_RSA_MOD_BITS(object_p), template)); 23737c478bd9Sstevel@tonic-gate } else { 23747c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 23757c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 23767c478bd9Sstevel@tonic-gate } 23777c478bd9Sstevel@tonic-gate 23787c478bd9Sstevel@tonic-gate case CKA_PRIME: 23797c478bd9Sstevel@tonic-gate switch (keytype) { 23807c478bd9Sstevel@tonic-gate case CKK_DSA: 23817c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 23827c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_PRIME(object_p), template)); 2383034448feSmcpowers case CKK_DH: 2384034448feSmcpowers return (get_bigint_attr_from_object( 2385034448feSmcpowers OBJ_PUB_DH_PRIME(object_p), template)); 23867c478bd9Sstevel@tonic-gate default: 23877c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 23887c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 23897c478bd9Sstevel@tonic-gate } 23907c478bd9Sstevel@tonic-gate 23917c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 23927c478bd9Sstevel@tonic-gate switch (keytype) { 23937c478bd9Sstevel@tonic-gate case CKK_DSA: 23947c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 23957c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_SUBPRIME(object_p), template)); 23967c478bd9Sstevel@tonic-gate default: 23977c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 23987c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 23997c478bd9Sstevel@tonic-gate } 24007c478bd9Sstevel@tonic-gate 24017c478bd9Sstevel@tonic-gate case CKA_BASE: 24027c478bd9Sstevel@tonic-gate switch (keytype) { 24037c478bd9Sstevel@tonic-gate case CKK_DSA: 24047c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 24057c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_BASE(object_p), template)); 2406034448feSmcpowers case CKK_DH: 2407034448feSmcpowers return (get_bigint_attr_from_object( 2408034448feSmcpowers OBJ_PUB_DH_BASE(object_p), template)); 24097c478bd9Sstevel@tonic-gate default: 24107c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 24117c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 24127c478bd9Sstevel@tonic-gate } 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate case CKA_VALUE: 24157c478bd9Sstevel@tonic-gate switch (keytype) { 24167c478bd9Sstevel@tonic-gate case CKK_DSA: 24177c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 24187c478bd9Sstevel@tonic-gate OBJ_PUB_DSA_VALUE(object_p), template)); 2419034448feSmcpowers case CKK_DH: 2420034448feSmcpowers return (get_bigint_attr_from_object( 2421034448feSmcpowers OBJ_PUB_DH_VALUE(object_p), template)); 24227c478bd9Sstevel@tonic-gate default: 24237c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 24247c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 24257c478bd9Sstevel@tonic-gate } 24267c478bd9Sstevel@tonic-gate 2427034448feSmcpowers case CKA_EC_POINT: 2428034448feSmcpowers switch (keytype) { 2429034448feSmcpowers case CKK_EC: 2430034448feSmcpowers return (get_bigint_attr_from_object( 2431034448feSmcpowers OBJ_PUB_EC_POINT(object_p), template)); 2432034448feSmcpowers default: 2433034448feSmcpowers template->ulValueLen = (CK_ULONG)-1; 2434034448feSmcpowers return (CKR_ATTRIBUTE_TYPE_INVALID); 2435034448feSmcpowers } 24367c478bd9Sstevel@tonic-gate default: 24377c478bd9Sstevel@tonic-gate /* 24387c478bd9Sstevel@tonic-gate * First, get the value of the request attribute defined 24397c478bd9Sstevel@tonic-gate * in the list of common key attributes. If the request 24407c478bd9Sstevel@tonic-gate * attribute is not found in that list, then get the 24417c478bd9Sstevel@tonic-gate * attribute from the list of common attributes. 24427c478bd9Sstevel@tonic-gate */ 24437c478bd9Sstevel@tonic-gate rv = kernel_get_common_key_attrs(object_p, template); 24447c478bd9Sstevel@tonic-gate if (rv == CKR_ATTRIBUTE_TYPE_INVALID) { 24457c478bd9Sstevel@tonic-gate rv = kernel_get_common_attrs(object_p, template); 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate break; 24487c478bd9Sstevel@tonic-gate } 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate return (rv); 24517c478bd9Sstevel@tonic-gate } 24527c478bd9Sstevel@tonic-gate 24537c478bd9Sstevel@tonic-gate 24547c478bd9Sstevel@tonic-gate /* 24557c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Private Key Object. 24567c478bd9Sstevel@tonic-gate * 24577c478bd9Sstevel@tonic-gate * Rule: All the attributes in the private key object can be revealed 24587c478bd9Sstevel@tonic-gate * except those marked with footnote number "7" when the object 24597c478bd9Sstevel@tonic-gate * has its CKA_SENSITIVE attribute set to TRUE or its 24607c478bd9Sstevel@tonic-gate * CKA_EXTRACTABLE attribute set to FALSE (p.88 in PKCS11 spec.). 24617c478bd9Sstevel@tonic-gate */ 24627c478bd9Sstevel@tonic-gate CK_RV 24637c478bd9Sstevel@tonic-gate kernel_get_private_key_attribute(kernel_object_t *object_p, 24647c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 24657c478bd9Sstevel@tonic-gate { 24667c478bd9Sstevel@tonic-gate 24677c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 24687c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 24697c478bd9Sstevel@tonic-gate 24707c478bd9Sstevel@tonic-gate 24717c478bd9Sstevel@tonic-gate /* 24727c478bd9Sstevel@tonic-gate * If the following specified attributes for the private key 24737c478bd9Sstevel@tonic-gate * object cannot be revealed because the object is sensitive 24747c478bd9Sstevel@tonic-gate * or unextractable, then the ulValueLen is set to -1. 24757c478bd9Sstevel@tonic-gate */ 24767c478bd9Sstevel@tonic-gate if ((object_p->bool_attr_mask & SENSITIVE_BOOL_ON) || 24777c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) { 24787c478bd9Sstevel@tonic-gate 24797c478bd9Sstevel@tonic-gate switch (template->type) { 24807c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT: 24817c478bd9Sstevel@tonic-gate case CKA_PRIME_1: 24827c478bd9Sstevel@tonic-gate case CKA_PRIME_2: 24837c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1: 24847c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2: 24857c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT: 24867c478bd9Sstevel@tonic-gate case CKA_VALUE: 24877c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 24887c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_SENSITIVE); 24897c478bd9Sstevel@tonic-gate } 24907c478bd9Sstevel@tonic-gate } 24917c478bd9Sstevel@tonic-gate 24927c478bd9Sstevel@tonic-gate switch (template->type) { 24937c478bd9Sstevel@tonic-gate 24947c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 2495034448feSmcpowers case CKA_EC_PARAMS: 24967c478bd9Sstevel@tonic-gate /* 24977c478bd9Sstevel@tonic-gate * The above extra attributes have byte array type. 24987c478bd9Sstevel@tonic-gate */ 24997c478bd9Sstevel@tonic-gate return (get_extra_attr_from_object(object_p, 25007c478bd9Sstevel@tonic-gate template)); 25017c478bd9Sstevel@tonic-gate 25027c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 25037c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 25047c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25057c478bd9Sstevel@tonic-gate SENSITIVE_BOOL_ON, template)); 25067c478bd9Sstevel@tonic-gate 25077c478bd9Sstevel@tonic-gate case CKA_SECONDARY_AUTH: 25087c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25097c478bd9Sstevel@tonic-gate SECONDARY_AUTH_BOOL_ON, template)); 25107c478bd9Sstevel@tonic-gate 25117c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 25127c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25137c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template)); 25147c478bd9Sstevel@tonic-gate 25157c478bd9Sstevel@tonic-gate case CKA_SIGN: 25167c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25177c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template)); 25187c478bd9Sstevel@tonic-gate 25197c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER: 25207c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25217c478bd9Sstevel@tonic-gate SIGN_RECOVER_BOOL_ON, template)); 25227c478bd9Sstevel@tonic-gate 25237c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 25247c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25257c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template)); 25267c478bd9Sstevel@tonic-gate 25277c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 25287c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25297c478bd9Sstevel@tonic-gate EXTRACTABLE_BOOL_ON, template)); 25307c478bd9Sstevel@tonic-gate 25317c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE: 25327c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25337c478bd9Sstevel@tonic-gate ALWAYS_SENSITIVE_BOOL_ON, template)); 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE: 25367c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 25377c478bd9Sstevel@tonic-gate NEVER_EXTRACTABLE_BOOL_ON, template)); 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate case CKA_MODULUS: 25407c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 25417c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 25427c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_MOD(object_p), template)); 25437c478bd9Sstevel@tonic-gate } else { 25447c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 25457c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 25467c478bd9Sstevel@tonic-gate break; 25477c478bd9Sstevel@tonic-gate } 25487c478bd9Sstevel@tonic-gate 25497c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 25507c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 25517c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 25527c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PUBEXPO(object_p), template)); 25537c478bd9Sstevel@tonic-gate } else { 25547c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 25557c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 25567c478bd9Sstevel@tonic-gate break; 25577c478bd9Sstevel@tonic-gate } 25587c478bd9Sstevel@tonic-gate 25597c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT: 25607c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 25617c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 25627c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PRIEXPO(object_p), template)); 25637c478bd9Sstevel@tonic-gate } else { 25647c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 25657c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 25667c478bd9Sstevel@tonic-gate break; 25677c478bd9Sstevel@tonic-gate } 25687c478bd9Sstevel@tonic-gate 25697c478bd9Sstevel@tonic-gate case CKA_PRIME_1: 25707c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 25717c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 25727c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PRIME1(object_p), template)); 25737c478bd9Sstevel@tonic-gate } else { 25747c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 25757c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 25767c478bd9Sstevel@tonic-gate break; 25777c478bd9Sstevel@tonic-gate } 25787c478bd9Sstevel@tonic-gate 25797c478bd9Sstevel@tonic-gate case CKA_PRIME_2: 25807c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 25817c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 25827c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_PRIME2(object_p), template)); 25837c478bd9Sstevel@tonic-gate } else { 25847c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 25857c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 25867c478bd9Sstevel@tonic-gate break; 25877c478bd9Sstevel@tonic-gate } 25887c478bd9Sstevel@tonic-gate 25897c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1: 25907c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 25917c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 25927c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_EXPO1(object_p), template)); 25937c478bd9Sstevel@tonic-gate } else { 25947c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 25957c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 25967c478bd9Sstevel@tonic-gate break; 25977c478bd9Sstevel@tonic-gate } 25987c478bd9Sstevel@tonic-gate 25997c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2: 26007c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 26017c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 26027c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_EXPO2(object_p), template)); 26037c478bd9Sstevel@tonic-gate } else { 26047c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26057c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 26067c478bd9Sstevel@tonic-gate break; 26077c478bd9Sstevel@tonic-gate } 26087c478bd9Sstevel@tonic-gate 26097c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT: 26107c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 26117c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 26127c478bd9Sstevel@tonic-gate OBJ_PRI_RSA_COEF(object_p), template)); 26137c478bd9Sstevel@tonic-gate } else { 26147c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26157c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 26167c478bd9Sstevel@tonic-gate break; 26177c478bd9Sstevel@tonic-gate } 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS: 2620034448feSmcpowers if (keytype == CKK_DH) { 2621034448feSmcpowers return (get_ulong_attr_from_object( 2622034448feSmcpowers OBJ_PRI_DH_VAL_BITS(object_p), template)); 2623034448feSmcpowers } else { 26247c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26257c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 26267c478bd9Sstevel@tonic-gate break; 2627034448feSmcpowers } 2628034448feSmcpowers 26297c478bd9Sstevel@tonic-gate case CKA_PRIME: 26307c478bd9Sstevel@tonic-gate switch (keytype) { 26317c478bd9Sstevel@tonic-gate case CKK_DSA: 26327c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 26337c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_PRIME(object_p), template)); 2634034448feSmcpowers case CKK_DH: 2635034448feSmcpowers return (get_bigint_attr_from_object( 2636034448feSmcpowers OBJ_PRI_DH_PRIME(object_p), template)); 26377c478bd9Sstevel@tonic-gate default: 26387c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26397c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 26407c478bd9Sstevel@tonic-gate } 26417c478bd9Sstevel@tonic-gate 26427c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 26437c478bd9Sstevel@tonic-gate switch (keytype) { 26447c478bd9Sstevel@tonic-gate case CKK_DSA: 26457c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 26467c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_SUBPRIME(object_p), template)); 26477c478bd9Sstevel@tonic-gate default: 26487c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26497c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 26507c478bd9Sstevel@tonic-gate } 26517c478bd9Sstevel@tonic-gate 26527c478bd9Sstevel@tonic-gate case CKA_BASE: 26537c478bd9Sstevel@tonic-gate switch (keytype) { 26547c478bd9Sstevel@tonic-gate case CKK_DSA: 26557c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 26567c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_BASE(object_p), template)); 2657034448feSmcpowers case CKK_DH: 2658034448feSmcpowers return (get_bigint_attr_from_object( 2659034448feSmcpowers OBJ_PRI_DH_BASE(object_p), template)); 26607c478bd9Sstevel@tonic-gate default: 26617c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26627c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 26637c478bd9Sstevel@tonic-gate } 26647c478bd9Sstevel@tonic-gate 26657c478bd9Sstevel@tonic-gate case CKA_VALUE: 26667c478bd9Sstevel@tonic-gate switch (keytype) { 26677c478bd9Sstevel@tonic-gate case CKK_DSA: 26687c478bd9Sstevel@tonic-gate return (get_bigint_attr_from_object( 26697c478bd9Sstevel@tonic-gate OBJ_PRI_DSA_VALUE(object_p), template)); 2670034448feSmcpowers case CKK_DH: 2671034448feSmcpowers return (get_bigint_attr_from_object( 2672034448feSmcpowers OBJ_PRI_DH_VALUE(object_p), template)); 2673034448feSmcpowers case CKK_EC: 2674034448feSmcpowers return (get_bigint_attr_from_object( 2675034448feSmcpowers OBJ_PRI_EC_VALUE(object_p), template)); 26767c478bd9Sstevel@tonic-gate default: 26777c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 26787c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 26797c478bd9Sstevel@tonic-gate } 26807c478bd9Sstevel@tonic-gate 26817c478bd9Sstevel@tonic-gate default: 26827c478bd9Sstevel@tonic-gate /* 26837c478bd9Sstevel@tonic-gate * First, get the value of the request attribute defined 26847c478bd9Sstevel@tonic-gate * in the list of common key attributes. If the request 26857c478bd9Sstevel@tonic-gate * attribute is not found in that list, then get the 26867c478bd9Sstevel@tonic-gate * attribute from the list of common attributes. 26877c478bd9Sstevel@tonic-gate */ 26887c478bd9Sstevel@tonic-gate rv = kernel_get_common_key_attrs(object_p, template); 26897c478bd9Sstevel@tonic-gate if (rv == CKR_ATTRIBUTE_TYPE_INVALID) { 26907c478bd9Sstevel@tonic-gate rv = kernel_get_common_attrs(object_p, template); 26917c478bd9Sstevel@tonic-gate } 26927c478bd9Sstevel@tonic-gate break; 26937c478bd9Sstevel@tonic-gate } 26947c478bd9Sstevel@tonic-gate 26957c478bd9Sstevel@tonic-gate return (rv); 26967c478bd9Sstevel@tonic-gate } 26977c478bd9Sstevel@tonic-gate 26987c478bd9Sstevel@tonic-gate 26997c478bd9Sstevel@tonic-gate /* 27007c478bd9Sstevel@tonic-gate * Get the value of a requested attribute of a Secret Key Object. 27017c478bd9Sstevel@tonic-gate * 27027c478bd9Sstevel@tonic-gate * Rule: All the attributes in the secret key object can be revealed 27037c478bd9Sstevel@tonic-gate * except those marked with footnote number "7" when the object 27047c478bd9Sstevel@tonic-gate * has its CKA_SENSITIVE attribute set to TRUE or its 27057c478bd9Sstevel@tonic-gate * CKA_EXTRACTABLE attribute set to FALSE (p.88 in PKCS11 spec.). 27067c478bd9Sstevel@tonic-gate */ 27077c478bd9Sstevel@tonic-gate CK_RV 27087c478bd9Sstevel@tonic-gate kernel_get_secret_key_attribute(kernel_object_t *object_p, 27097c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template) 27107c478bd9Sstevel@tonic-gate { 27117c478bd9Sstevel@tonic-gate 27127c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 27137c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 27147c478bd9Sstevel@tonic-gate 27157c478bd9Sstevel@tonic-gate switch (template->type) { 27167c478bd9Sstevel@tonic-gate 27177c478bd9Sstevel@tonic-gate /* Key related boolean attributes */ 27187c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 27197c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27207c478bd9Sstevel@tonic-gate SENSITIVE_BOOL_ON, template)); 27217c478bd9Sstevel@tonic-gate 27227c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 27237c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27247c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template)); 27257c478bd9Sstevel@tonic-gate 27267c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 27277c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27287c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template)); 27297c478bd9Sstevel@tonic-gate 27307c478bd9Sstevel@tonic-gate case CKA_SIGN: 27317c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27327c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template)); 27337c478bd9Sstevel@tonic-gate 27347c478bd9Sstevel@tonic-gate case CKA_VERIFY: 27357c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27367c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template)); 27377c478bd9Sstevel@tonic-gate 27387c478bd9Sstevel@tonic-gate case CKA_WRAP: 27397c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27407c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template)); 27417c478bd9Sstevel@tonic-gate 27427c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 27437c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27447c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template)); 27457c478bd9Sstevel@tonic-gate 27467c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 27477c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27487c478bd9Sstevel@tonic-gate EXTRACTABLE_BOOL_ON, template)); 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE: 27517c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27527c478bd9Sstevel@tonic-gate ALWAYS_SENSITIVE_BOOL_ON, template)); 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE: 27557c478bd9Sstevel@tonic-gate return (get_bool_attr_from_object(object_p, 27567c478bd9Sstevel@tonic-gate NEVER_EXTRACTABLE_BOOL_ON, template)); 27577c478bd9Sstevel@tonic-gate 27587c478bd9Sstevel@tonic-gate case CKA_VALUE: 27597c478bd9Sstevel@tonic-gate /* 27607c478bd9Sstevel@tonic-gate * If the specified attribute for the secret key object 27617c478bd9Sstevel@tonic-gate * cannot be revealed because the object is sensitive 27627c478bd9Sstevel@tonic-gate * or unextractable, then the ulValueLen is set to -1. 27637c478bd9Sstevel@tonic-gate */ 27647c478bd9Sstevel@tonic-gate if ((object_p->bool_attr_mask & SENSITIVE_BOOL_ON) || 27657c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) { 27667c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 27677c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_SENSITIVE); 27687c478bd9Sstevel@tonic-gate } 27697c478bd9Sstevel@tonic-gate 27707c478bd9Sstevel@tonic-gate switch (keytype) { 27717c478bd9Sstevel@tonic-gate case CKK_RC4: 27727c478bd9Sstevel@tonic-gate case CKK_GENERIC_SECRET: 27737c478bd9Sstevel@tonic-gate case CKK_RC5: 27747c478bd9Sstevel@tonic-gate case CKK_DES: 27757c478bd9Sstevel@tonic-gate case CKK_DES2: 27767c478bd9Sstevel@tonic-gate case CKK_DES3: 27777c478bd9Sstevel@tonic-gate case CKK_CDMF: 27787c478bd9Sstevel@tonic-gate case CKK_AES: 2779f66d273dSizick case CKK_BLOWFISH: 27807c478bd9Sstevel@tonic-gate /* 27817c478bd9Sstevel@tonic-gate * Copy secret key object attributes to template. 27827c478bd9Sstevel@tonic-gate */ 27837c478bd9Sstevel@tonic-gate if (template->pValue == NULL) { 27847c478bd9Sstevel@tonic-gate template->ulValueLen = 27857c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p); 27867c478bd9Sstevel@tonic-gate return (CKR_OK); 27877c478bd9Sstevel@tonic-gate } 27887c478bd9Sstevel@tonic-gate 27897c478bd9Sstevel@tonic-gate if (OBJ_SEC_VALUE(object_p) == NULL) { 27907c478bd9Sstevel@tonic-gate template->ulValueLen = 0; 27917c478bd9Sstevel@tonic-gate return (CKR_OK); 27927c478bd9Sstevel@tonic-gate } 27937c478bd9Sstevel@tonic-gate 27947c478bd9Sstevel@tonic-gate if (template->ulValueLen >= 27957c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p)) { 27967c478bd9Sstevel@tonic-gate (void) memcpy(template->pValue, 27977c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE(object_p), 27987c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p)); 27997c478bd9Sstevel@tonic-gate template->ulValueLen = 28007c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(object_p); 28017c478bd9Sstevel@tonic-gate return (CKR_OK); 28027c478bd9Sstevel@tonic-gate } else { 28037c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 28047c478bd9Sstevel@tonic-gate return (CKR_BUFFER_TOO_SMALL); 28057c478bd9Sstevel@tonic-gate } 28067c478bd9Sstevel@tonic-gate 28077c478bd9Sstevel@tonic-gate default: 28087c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 28097c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_TYPE_INVALID; 28107c478bd9Sstevel@tonic-gate break; 28117c478bd9Sstevel@tonic-gate } 28127c478bd9Sstevel@tonic-gate break; 28137c478bd9Sstevel@tonic-gate 28147c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN: 28157c478bd9Sstevel@tonic-gate return (get_ulong_attr_from_object(OBJ_SEC_VALUE_LEN(object_p), 28167c478bd9Sstevel@tonic-gate template)); 28177c478bd9Sstevel@tonic-gate 28187c478bd9Sstevel@tonic-gate default: 28197c478bd9Sstevel@tonic-gate /* 28207c478bd9Sstevel@tonic-gate * First, get the value of the request attribute defined 28217c478bd9Sstevel@tonic-gate * in the list of common key attributes. If the request 28227c478bd9Sstevel@tonic-gate * attribute is not found in that list, then get the 28237c478bd9Sstevel@tonic-gate * attribute from the list of common attributes. 28247c478bd9Sstevel@tonic-gate */ 28257c478bd9Sstevel@tonic-gate rv = kernel_get_common_key_attrs(object_p, template); 28267c478bd9Sstevel@tonic-gate if (rv == CKR_ATTRIBUTE_TYPE_INVALID) { 28277c478bd9Sstevel@tonic-gate rv = kernel_get_common_attrs(object_p, template); 28287c478bd9Sstevel@tonic-gate } 28297c478bd9Sstevel@tonic-gate break; 28307c478bd9Sstevel@tonic-gate } 28317c478bd9Sstevel@tonic-gate 28327c478bd9Sstevel@tonic-gate return (rv); 28337c478bd9Sstevel@tonic-gate 28347c478bd9Sstevel@tonic-gate } 28357c478bd9Sstevel@tonic-gate 28367c478bd9Sstevel@tonic-gate 28377c478bd9Sstevel@tonic-gate 28387c478bd9Sstevel@tonic-gate 28397c478bd9Sstevel@tonic-gate /* 28407c478bd9Sstevel@tonic-gate * Call the appropriate get attribute function according to the class 28417c478bd9Sstevel@tonic-gate * of object. 28427c478bd9Sstevel@tonic-gate * 28437c478bd9Sstevel@tonic-gate * The caller of this function holds the lock on the object. 28447c478bd9Sstevel@tonic-gate */ 28457c478bd9Sstevel@tonic-gate CK_RV 28467c478bd9Sstevel@tonic-gate kernel_get_attribute(kernel_object_t *object_p, CK_ATTRIBUTE_PTR template) 28477c478bd9Sstevel@tonic-gate { 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 28507c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = object_p->class; 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate switch (class) { 28537c478bd9Sstevel@tonic-gate 28547c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY: 28557c478bd9Sstevel@tonic-gate rv = kernel_get_public_key_attribute(object_p, template); 28567c478bd9Sstevel@tonic-gate break; 28577c478bd9Sstevel@tonic-gate 28587c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY: 28597c478bd9Sstevel@tonic-gate rv = kernel_get_private_key_attribute(object_p, template); 28607c478bd9Sstevel@tonic-gate break; 28617c478bd9Sstevel@tonic-gate 28627c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY: 28637c478bd9Sstevel@tonic-gate rv = kernel_get_secret_key_attribute(object_p, template); 28647c478bd9Sstevel@tonic-gate break; 28657c478bd9Sstevel@tonic-gate 28667c478bd9Sstevel@tonic-gate default: 28677c478bd9Sstevel@tonic-gate /* 28687c478bd9Sstevel@tonic-gate * If the specified attribute for the object is invalid 28697c478bd9Sstevel@tonic-gate * (the object does not possess such as attribute), then 28707c478bd9Sstevel@tonic-gate * the ulValueLen is modified to hold the value -1. 28717c478bd9Sstevel@tonic-gate */ 28727c478bd9Sstevel@tonic-gate template->ulValueLen = (CK_ULONG)-1; 28737c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 28747c478bd9Sstevel@tonic-gate } 28757c478bd9Sstevel@tonic-gate 28767c478bd9Sstevel@tonic-gate return (rv); 28777c478bd9Sstevel@tonic-gate 28787c478bd9Sstevel@tonic-gate } 28797c478bd9Sstevel@tonic-gate 28807c478bd9Sstevel@tonic-gate /* 28817c478bd9Sstevel@tonic-gate * Set the value of an attribute that is common to all key objects 28827c478bd9Sstevel@tonic-gate * (i.e. public key, private key and secret key). 28837c478bd9Sstevel@tonic-gate */ 28847c478bd9Sstevel@tonic-gate CK_RV 28857c478bd9Sstevel@tonic-gate kernel_set_common_key_attribute(kernel_object_t *object_p, 28867c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy, kernel_session_t *sp) 28877c478bd9Sstevel@tonic-gate { 28887c478bd9Sstevel@tonic-gate 28897c478bd9Sstevel@tonic-gate kernel_slot_t *pslot = slot_table[sp->ses_slotid]; 28907c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 28917c478bd9Sstevel@tonic-gate 28927c478bd9Sstevel@tonic-gate switch (template->type) { 28937c478bd9Sstevel@tonic-gate 28947c478bd9Sstevel@tonic-gate case CKA_LABEL: 28957c478bd9Sstevel@tonic-gate /* 28967c478bd9Sstevel@tonic-gate * Only the LABEL can be modified in the common storage 28977c478bd9Sstevel@tonic-gate * object attributes after the object is created. 28987c478bd9Sstevel@tonic-gate */ 28997c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p, 29007c478bd9Sstevel@tonic-gate CKA_LABEL, template)); 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate case CKA_ID: 29037c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p, 29047c478bd9Sstevel@tonic-gate CKA_ID, template)); 29057c478bd9Sstevel@tonic-gate 29067c478bd9Sstevel@tonic-gate case CKA_START_DATE: 29077c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p, 29087c478bd9Sstevel@tonic-gate CKA_START_DATE, template)); 29097c478bd9Sstevel@tonic-gate 29107c478bd9Sstevel@tonic-gate case CKA_END_DATE: 29117c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p, 29127c478bd9Sstevel@tonic-gate CKA_END_DATE, template)); 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate case CKA_DERIVE: 29157c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 29167c478bd9Sstevel@tonic-gate DERIVE_BOOL_ON, template)); 29177c478bd9Sstevel@tonic-gate 29187c478bd9Sstevel@tonic-gate case CKA_CLASS: 29197c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 29207c478bd9Sstevel@tonic-gate case CKA_LOCAL: 29217c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 29227c478bd9Sstevel@tonic-gate 29237c478bd9Sstevel@tonic-gate case CKA_PRIVATE: 29247c478bd9Sstevel@tonic-gate if (!copy) { 29257c478bd9Sstevel@tonic-gate /* called from C_SetAttributeValue() */ 29267c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 29277c478bd9Sstevel@tonic-gate } 29287c478bd9Sstevel@tonic-gate 29297c478bd9Sstevel@tonic-gate /* called from C_CopyObject() */ 29307c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) != B_TRUE) { 29317c478bd9Sstevel@tonic-gate return (CKR_OK); 29327c478bd9Sstevel@tonic-gate } 29337c478bd9Sstevel@tonic-gate 29347c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&pslot->sl_mutex); 2935034448feSmcpowers /* 2936034448feSmcpowers * Cannot create a private object if the token 2937034448feSmcpowers * has a keystore and the user isn't logged in. 2938034448feSmcpowers */ 2939034448feSmcpowers if (pslot->sl_func_list.fl_object_create && 2940034448feSmcpowers pslot->sl_state != CKU_USER) { 29417c478bd9Sstevel@tonic-gate rv = CKR_USER_NOT_LOGGED_IN; 29427c478bd9Sstevel@tonic-gate } else { 29437c478bd9Sstevel@tonic-gate rv = set_bool_attr_to_object(object_p, 29447c478bd9Sstevel@tonic-gate PRIVATE_BOOL_ON, template); 29457c478bd9Sstevel@tonic-gate } 29467c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&pslot->sl_mutex); 29477c478bd9Sstevel@tonic-gate return (rv); 29487c478bd9Sstevel@tonic-gate 29497c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE: 29507c478bd9Sstevel@tonic-gate if (copy) { 29517c478bd9Sstevel@tonic-gate rv = set_bool_attr_to_object(object_p, 29527c478bd9Sstevel@tonic-gate MODIFIABLE_BOOL_ON, template); 29537c478bd9Sstevel@tonic-gate } else { 29547c478bd9Sstevel@tonic-gate rv = CKR_ATTRIBUTE_READ_ONLY; 29557c478bd9Sstevel@tonic-gate } 29567c478bd9Sstevel@tonic-gate return (rv); 29577c478bd9Sstevel@tonic-gate 29587c478bd9Sstevel@tonic-gate default: 29597c478bd9Sstevel@tonic-gate return (CKR_TEMPLATE_INCONSISTENT); 29607c478bd9Sstevel@tonic-gate } 29617c478bd9Sstevel@tonic-gate 29627c478bd9Sstevel@tonic-gate } 29637c478bd9Sstevel@tonic-gate 29647c478bd9Sstevel@tonic-gate 29657c478bd9Sstevel@tonic-gate /* 29667c478bd9Sstevel@tonic-gate * Set the value of an attribute of a Public Key Object. 29677c478bd9Sstevel@tonic-gate * 29687c478bd9Sstevel@tonic-gate * Rule: The attributes marked with footnote number "8" in the PKCS11 29697c478bd9Sstevel@tonic-gate * spec may be modified (p.88 in PKCS11 spec.). 29707c478bd9Sstevel@tonic-gate */ 29717c478bd9Sstevel@tonic-gate CK_RV 29727c478bd9Sstevel@tonic-gate kernel_set_public_key_attribute(kernel_object_t *object_p, 29737c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy, kernel_session_t *sp) 29747c478bd9Sstevel@tonic-gate { 29757c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 29767c478bd9Sstevel@tonic-gate 29777c478bd9Sstevel@tonic-gate switch (template->type) { 29787c478bd9Sstevel@tonic-gate 29797c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 29807c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p, 29817c478bd9Sstevel@tonic-gate CKA_SUBJECT, template)); 29827c478bd9Sstevel@tonic-gate 29837c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 29847c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 29857c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template)); 29867c478bd9Sstevel@tonic-gate 29877c478bd9Sstevel@tonic-gate case CKA_VERIFY: 29887c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 29897c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template)); 29907c478bd9Sstevel@tonic-gate 29917c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER: 29927c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 29937c478bd9Sstevel@tonic-gate VERIFY_RECOVER_BOOL_ON, template)); 29947c478bd9Sstevel@tonic-gate 29957c478bd9Sstevel@tonic-gate case CKA_WRAP: 29967c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 29977c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template)); 29987c478bd9Sstevel@tonic-gate 29997c478bd9Sstevel@tonic-gate case CKA_MODULUS: 30007c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS: 30017c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 30027c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) 30037c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 30047c478bd9Sstevel@tonic-gate break; 30057c478bd9Sstevel@tonic-gate 30067c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 30077c478bd9Sstevel@tonic-gate case CKA_PRIME: 30087c478bd9Sstevel@tonic-gate case CKA_BASE: 30097c478bd9Sstevel@tonic-gate case CKA_VALUE: 30107c478bd9Sstevel@tonic-gate if (keytype == CKK_DSA) 30117c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 30127c478bd9Sstevel@tonic-gate break; 30137c478bd9Sstevel@tonic-gate 30147c478bd9Sstevel@tonic-gate default: 30157c478bd9Sstevel@tonic-gate /* 30167c478bd9Sstevel@tonic-gate * Set the value of a common key attribute. 30177c478bd9Sstevel@tonic-gate */ 30187c478bd9Sstevel@tonic-gate return (kernel_set_common_key_attribute(object_p, 30197c478bd9Sstevel@tonic-gate template, copy, sp)); 30207c478bd9Sstevel@tonic-gate 30217c478bd9Sstevel@tonic-gate } 30227c478bd9Sstevel@tonic-gate 30237c478bd9Sstevel@tonic-gate /* 30247c478bd9Sstevel@tonic-gate * If we got this far, then the combination of key type 30257c478bd9Sstevel@tonic-gate * and requested attribute is invalid. 30267c478bd9Sstevel@tonic-gate */ 30277c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 30287c478bd9Sstevel@tonic-gate } 30297c478bd9Sstevel@tonic-gate 30307c478bd9Sstevel@tonic-gate 30317c478bd9Sstevel@tonic-gate /* 30327c478bd9Sstevel@tonic-gate * Set the value of an attribute of a Private Key Object. 30337c478bd9Sstevel@tonic-gate * 30347c478bd9Sstevel@tonic-gate * Rule: The attributes marked with footnote number "8" in the PKCS11 30357c478bd9Sstevel@tonic-gate * spec may be modified (p.88 in PKCS11 spec.). 30367c478bd9Sstevel@tonic-gate */ 30377c478bd9Sstevel@tonic-gate CK_RV 30387c478bd9Sstevel@tonic-gate kernel_set_private_key_attribute(kernel_object_t *object_p, 30397c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy, kernel_session_t *sp) 30407c478bd9Sstevel@tonic-gate { 30417c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 30427c478bd9Sstevel@tonic-gate 30437c478bd9Sstevel@tonic-gate switch (template->type) { 30447c478bd9Sstevel@tonic-gate 30457c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 30467c478bd9Sstevel@tonic-gate return (set_extra_attr_to_object(object_p, 30477c478bd9Sstevel@tonic-gate CKA_SUBJECT, template)); 30487c478bd9Sstevel@tonic-gate 30497c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 30507c478bd9Sstevel@tonic-gate /* 30517c478bd9Sstevel@tonic-gate * Cannot set SENSITIVE to FALSE if it is already ON. 30527c478bd9Sstevel@tonic-gate */ 30537c478bd9Sstevel@tonic-gate if (((*(CK_BBOOL *)template->pValue) == B_FALSE) && 30547c478bd9Sstevel@tonic-gate (object_p->bool_attr_mask & SENSITIVE_BOOL_ON)) { 30557c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 30567c478bd9Sstevel@tonic-gate } 30577c478bd9Sstevel@tonic-gate 30587c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template->pValue) 30597c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |= SENSITIVE_BOOL_ON; 30607c478bd9Sstevel@tonic-gate return (CKR_OK); 30617c478bd9Sstevel@tonic-gate 30627c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 30637c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 30647c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template)); 30657c478bd9Sstevel@tonic-gate 30667c478bd9Sstevel@tonic-gate case CKA_SIGN: 30677c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 30687c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template)); 30697c478bd9Sstevel@tonic-gate 30707c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER: 30717c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 30727c478bd9Sstevel@tonic-gate SIGN_RECOVER_BOOL_ON, template)); 30737c478bd9Sstevel@tonic-gate 30747c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 30757c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 30767c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template)); 30777c478bd9Sstevel@tonic-gate 30787c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 30797c478bd9Sstevel@tonic-gate /* 30807c478bd9Sstevel@tonic-gate * Cannot set EXTRACTABLE to TRUE if it is already OFF. 30817c478bd9Sstevel@tonic-gate */ 30827c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) && 30837c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) { 30847c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 30857c478bd9Sstevel@tonic-gate } 30867c478bd9Sstevel@tonic-gate 30877c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_FALSE) 30887c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &= ~EXTRACTABLE_BOOL_ON; 30897c478bd9Sstevel@tonic-gate return (CKR_OK); 30907c478bd9Sstevel@tonic-gate 30917c478bd9Sstevel@tonic-gate case CKA_MODULUS: 30927c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 30937c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT: 30947c478bd9Sstevel@tonic-gate case CKA_PRIME_1: 30957c478bd9Sstevel@tonic-gate case CKA_PRIME_2: 30967c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1: 30977c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2: 30987c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT: 30997c478bd9Sstevel@tonic-gate if (keytype == CKK_RSA) { 31007c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 31017c478bd9Sstevel@tonic-gate } 31027c478bd9Sstevel@tonic-gate break; 31037c478bd9Sstevel@tonic-gate 31047c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 31057c478bd9Sstevel@tonic-gate case CKA_PRIME: 31067c478bd9Sstevel@tonic-gate case CKA_BASE: 31077c478bd9Sstevel@tonic-gate case CKA_VALUE: 31087c478bd9Sstevel@tonic-gate if (keytype == CKK_DSA) 31097c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 31107c478bd9Sstevel@tonic-gate break; 31117c478bd9Sstevel@tonic-gate 31127c478bd9Sstevel@tonic-gate default: 31137c478bd9Sstevel@tonic-gate /* 31147c478bd9Sstevel@tonic-gate * Set the value of a common key attribute. 31157c478bd9Sstevel@tonic-gate */ 31167c478bd9Sstevel@tonic-gate return (kernel_set_common_key_attribute(object_p, 31177c478bd9Sstevel@tonic-gate template, copy, sp)); 31187c478bd9Sstevel@tonic-gate } 31197c478bd9Sstevel@tonic-gate 31207c478bd9Sstevel@tonic-gate /* 31217c478bd9Sstevel@tonic-gate * If we got this far, then the combination of key type 31227c478bd9Sstevel@tonic-gate * and requested attribute is invalid. 31237c478bd9Sstevel@tonic-gate */ 31247c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 31257c478bd9Sstevel@tonic-gate } 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate 31287c478bd9Sstevel@tonic-gate 31297c478bd9Sstevel@tonic-gate /* 31307c478bd9Sstevel@tonic-gate * Set the value of an attribute of a Secret Key Object. 31317c478bd9Sstevel@tonic-gate * 31327c478bd9Sstevel@tonic-gate * Rule: The attributes marked with footnote number "8" in the PKCS11 31337c478bd9Sstevel@tonic-gate * spec may be modified (p.88 in PKCS11 spec.). 31347c478bd9Sstevel@tonic-gate */ 31357c478bd9Sstevel@tonic-gate CK_RV 31367c478bd9Sstevel@tonic-gate kernel_set_secret_key_attribute(kernel_object_t *object_p, 31377c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR template, boolean_t copy, kernel_session_t *sp) 31387c478bd9Sstevel@tonic-gate { 31397c478bd9Sstevel@tonic-gate CK_KEY_TYPE keytype = object_p->key_type; 31407c478bd9Sstevel@tonic-gate 31417c478bd9Sstevel@tonic-gate switch (template->type) { 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 31447c478bd9Sstevel@tonic-gate /* 31457c478bd9Sstevel@tonic-gate * Cannot set SENSITIVE to FALSE if it is already ON. 31467c478bd9Sstevel@tonic-gate */ 31477c478bd9Sstevel@tonic-gate if (((*(CK_BBOOL *)template->pValue) == B_FALSE) && 31487c478bd9Sstevel@tonic-gate (object_p->bool_attr_mask & SENSITIVE_BOOL_ON)) { 31497c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 31507c478bd9Sstevel@tonic-gate } 31517c478bd9Sstevel@tonic-gate 31527c478bd9Sstevel@tonic-gate if (*(CK_BBOOL *)template->pValue) 31537c478bd9Sstevel@tonic-gate object_p->bool_attr_mask |= SENSITIVE_BOOL_ON; 31547c478bd9Sstevel@tonic-gate return (CKR_OK); 31557c478bd9Sstevel@tonic-gate 31567c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 31577c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 31587c478bd9Sstevel@tonic-gate ENCRYPT_BOOL_ON, template)); 31597c478bd9Sstevel@tonic-gate 31607c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 31617c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 31627c478bd9Sstevel@tonic-gate DECRYPT_BOOL_ON, template)); 31637c478bd9Sstevel@tonic-gate 31647c478bd9Sstevel@tonic-gate case CKA_SIGN: 31657c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 31667c478bd9Sstevel@tonic-gate SIGN_BOOL_ON, template)); 31677c478bd9Sstevel@tonic-gate 31687c478bd9Sstevel@tonic-gate case CKA_VERIFY: 31697c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 31707c478bd9Sstevel@tonic-gate VERIFY_BOOL_ON, template)); 31717c478bd9Sstevel@tonic-gate 31727c478bd9Sstevel@tonic-gate case CKA_WRAP: 31737c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 31747c478bd9Sstevel@tonic-gate WRAP_BOOL_ON, template)); 31757c478bd9Sstevel@tonic-gate 31767c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 31777c478bd9Sstevel@tonic-gate return (set_bool_attr_to_object(object_p, 31787c478bd9Sstevel@tonic-gate UNWRAP_BOOL_ON, template)); 31797c478bd9Sstevel@tonic-gate 31807c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 31817c478bd9Sstevel@tonic-gate /* 31827c478bd9Sstevel@tonic-gate * Cannot set EXTRACTABLE to TRUE if it is already OFF. 31837c478bd9Sstevel@tonic-gate */ 31847c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) && 31857c478bd9Sstevel@tonic-gate !(object_p->bool_attr_mask & EXTRACTABLE_BOOL_ON)) { 31867c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 31877c478bd9Sstevel@tonic-gate } 31887c478bd9Sstevel@tonic-gate 31897c478bd9Sstevel@tonic-gate if ((*(CK_BBOOL *)template->pValue) == B_FALSE) 31907c478bd9Sstevel@tonic-gate object_p->bool_attr_mask &= ~EXTRACTABLE_BOOL_ON; 31917c478bd9Sstevel@tonic-gate return (CKR_OK); 31927c478bd9Sstevel@tonic-gate 31937c478bd9Sstevel@tonic-gate case CKA_VALUE: 31947c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 31957c478bd9Sstevel@tonic-gate 31967c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN: 31977c478bd9Sstevel@tonic-gate if ((keytype == CKK_RC4) || 31987c478bd9Sstevel@tonic-gate (keytype == CKK_GENERIC_SECRET) || 3199f66d273dSizick (keytype == CKK_AES) || 3200f66d273dSizick (keytype == CKK_BLOWFISH)) 32017c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_READ_ONLY); 32027c478bd9Sstevel@tonic-gate break; 32037c478bd9Sstevel@tonic-gate 32047c478bd9Sstevel@tonic-gate default: 32057c478bd9Sstevel@tonic-gate /* 32067c478bd9Sstevel@tonic-gate * Set the value of a common key attribute. 32077c478bd9Sstevel@tonic-gate */ 32087c478bd9Sstevel@tonic-gate return (kernel_set_common_key_attribute(object_p, 32097c478bd9Sstevel@tonic-gate template, copy, sp)); 32107c478bd9Sstevel@tonic-gate } 32117c478bd9Sstevel@tonic-gate 32127c478bd9Sstevel@tonic-gate /* 32137c478bd9Sstevel@tonic-gate * If we got this far, then the combination of key type 32147c478bd9Sstevel@tonic-gate * and requested attribute is invalid. 32157c478bd9Sstevel@tonic-gate */ 32167c478bd9Sstevel@tonic-gate return (CKR_ATTRIBUTE_TYPE_INVALID); 32177c478bd9Sstevel@tonic-gate } 32187c478bd9Sstevel@tonic-gate 32197c478bd9Sstevel@tonic-gate 32207c478bd9Sstevel@tonic-gate /* 32217c478bd9Sstevel@tonic-gate * Call the appropriate set attribute function according to the class 32227c478bd9Sstevel@tonic-gate * of object. 32237c478bd9Sstevel@tonic-gate * 32247c478bd9Sstevel@tonic-gate * The caller of this function does not hold the lock on the original 32257c478bd9Sstevel@tonic-gate * object, since this function is setting the attribute on the new object 32267c478bd9Sstevel@tonic-gate * that is being modified. 32277c478bd9Sstevel@tonic-gate * 32287c478bd9Sstevel@tonic-gate */ 32297c478bd9Sstevel@tonic-gate CK_RV 32307c478bd9Sstevel@tonic-gate kernel_set_attribute(kernel_object_t *object_p, CK_ATTRIBUTE_PTR template, 32317c478bd9Sstevel@tonic-gate boolean_t copy, kernel_session_t *sp) 32327c478bd9Sstevel@tonic-gate { 32337c478bd9Sstevel@tonic-gate 32347c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 32357c478bd9Sstevel@tonic-gate CK_OBJECT_CLASS class = object_p->class; 32367c478bd9Sstevel@tonic-gate 32377c478bd9Sstevel@tonic-gate switch (class) { 32387c478bd9Sstevel@tonic-gate 32397c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY: 32407c478bd9Sstevel@tonic-gate rv = kernel_set_public_key_attribute(object_p, template, 32417c478bd9Sstevel@tonic-gate copy, sp); 32427c478bd9Sstevel@tonic-gate break; 32437c478bd9Sstevel@tonic-gate 32447c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY: 32457c478bd9Sstevel@tonic-gate rv = kernel_set_private_key_attribute(object_p, template, 32467c478bd9Sstevel@tonic-gate copy, sp); 32477c478bd9Sstevel@tonic-gate break; 32487c478bd9Sstevel@tonic-gate 32497c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY: 32507c478bd9Sstevel@tonic-gate rv = kernel_set_secret_key_attribute(object_p, template, 32517c478bd9Sstevel@tonic-gate copy, sp); 32527c478bd9Sstevel@tonic-gate break; 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate default: 32557c478bd9Sstevel@tonic-gate /* 32567c478bd9Sstevel@tonic-gate * If the template specifies a value of an attribute 32577c478bd9Sstevel@tonic-gate * which is incompatible with other existing attributes 32587c478bd9Sstevel@tonic-gate * of the object, then fails with return code 32597c478bd9Sstevel@tonic-gate * CKR_TEMPLATE_INCONSISTENT. 32607c478bd9Sstevel@tonic-gate */ 32617c478bd9Sstevel@tonic-gate rv = CKR_TEMPLATE_INCONSISTENT; 32627c478bd9Sstevel@tonic-gate break; 32637c478bd9Sstevel@tonic-gate } 32647c478bd9Sstevel@tonic-gate 32657c478bd9Sstevel@tonic-gate return (rv); 32667c478bd9Sstevel@tonic-gate } 32677c478bd9Sstevel@tonic-gate 32687c478bd9Sstevel@tonic-gate 32697c478bd9Sstevel@tonic-gate static CK_RV 32707c478bd9Sstevel@tonic-gate copy_bigint(biginteger_t *new_bigint, biginteger_t *old_bigint) 32717c478bd9Sstevel@tonic-gate { 32727c478bd9Sstevel@tonic-gate new_bigint->big_value = 32737c478bd9Sstevel@tonic-gate malloc((sizeof (CK_BYTE) * new_bigint->big_value_len)); 32747c478bd9Sstevel@tonic-gate 32757c478bd9Sstevel@tonic-gate if (new_bigint->big_value == NULL) { 32767c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 32777c478bd9Sstevel@tonic-gate } 32787c478bd9Sstevel@tonic-gate 32797c478bd9Sstevel@tonic-gate (void) memcpy(new_bigint->big_value, old_bigint->big_value, 32807c478bd9Sstevel@tonic-gate (sizeof (CK_BYTE) * new_bigint->big_value_len)); 32817c478bd9Sstevel@tonic-gate 32827c478bd9Sstevel@tonic-gate return (CKR_OK); 32837c478bd9Sstevel@tonic-gate } 32847c478bd9Sstevel@tonic-gate 32857c478bd9Sstevel@tonic-gate static void 32867c478bd9Sstevel@tonic-gate free_public_key_attr(public_key_obj_t *pbk, CK_KEY_TYPE key_type) 32877c478bd9Sstevel@tonic-gate { 32887c478bd9Sstevel@tonic-gate if (pbk == NULL) { 32897c478bd9Sstevel@tonic-gate return; 32907c478bd9Sstevel@tonic-gate } 32917c478bd9Sstevel@tonic-gate 32927c478bd9Sstevel@tonic-gate switch (key_type) { 32937c478bd9Sstevel@tonic-gate case CKK_RSA: 32947c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_RSA_MOD(pbk)); 32957c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_RSA_PUBEXPO(pbk)); 32967c478bd9Sstevel@tonic-gate break; 32977c478bd9Sstevel@tonic-gate case CKK_DSA: 32987c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_PRIME(pbk)); 32997c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_SUBPRIME(pbk)); 33007c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_BASE(pbk)); 33017c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PUB_DSA_VALUE(pbk)); 33027c478bd9Sstevel@tonic-gate break; 33037c478bd9Sstevel@tonic-gate default: 33047c478bd9Sstevel@tonic-gate break; 33057c478bd9Sstevel@tonic-gate } 33067c478bd9Sstevel@tonic-gate free(pbk); 33077c478bd9Sstevel@tonic-gate } 33087c478bd9Sstevel@tonic-gate 33097c478bd9Sstevel@tonic-gate 33107c478bd9Sstevel@tonic-gate CK_RV 33117c478bd9Sstevel@tonic-gate kernel_copy_public_key_attr(public_key_obj_t *old_pub_key_obj_p, 33127c478bd9Sstevel@tonic-gate public_key_obj_t **new_pub_key_obj_p, CK_KEY_TYPE key_type) 33137c478bd9Sstevel@tonic-gate { 33147c478bd9Sstevel@tonic-gate 33157c478bd9Sstevel@tonic-gate public_key_obj_t *pbk; 33167c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 33177c478bd9Sstevel@tonic-gate 33187c478bd9Sstevel@tonic-gate pbk = calloc(1, sizeof (public_key_obj_t)); 33197c478bd9Sstevel@tonic-gate if (pbk == NULL) { 33207c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 33217c478bd9Sstevel@tonic-gate } 33227c478bd9Sstevel@tonic-gate 33237c478bd9Sstevel@tonic-gate switch (key_type) { 33247c478bd9Sstevel@tonic-gate case CKK_RSA: 33257c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PUB_RSA(pbk), 33267c478bd9Sstevel@tonic-gate KEY_PUB_RSA(old_pub_key_obj_p), 33277c478bd9Sstevel@tonic-gate sizeof (rsa_pub_key_t)); 33287c478bd9Sstevel@tonic-gate /* copy modulus */ 33297c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_RSA_MOD(pbk), 33307c478bd9Sstevel@tonic-gate KEY_PUB_RSA_MOD(old_pub_key_obj_p)); 33317c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 33327c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type); 33337c478bd9Sstevel@tonic-gate return (rv); 33347c478bd9Sstevel@tonic-gate } 33357c478bd9Sstevel@tonic-gate /* copy public exponent */ 33367c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_RSA_PUBEXPO(pbk), 33377c478bd9Sstevel@tonic-gate KEY_PUB_RSA_PUBEXPO(old_pub_key_obj_p)); 33387c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 33397c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type); 33407c478bd9Sstevel@tonic-gate return (rv); 33417c478bd9Sstevel@tonic-gate } 33427c478bd9Sstevel@tonic-gate break; 33437c478bd9Sstevel@tonic-gate case CKK_DSA: 33447c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PUB_DSA(pbk), 33457c478bd9Sstevel@tonic-gate KEY_PUB_DSA(old_pub_key_obj_p), 33467c478bd9Sstevel@tonic-gate sizeof (dsa_pub_key_t)); 33477c478bd9Sstevel@tonic-gate 33487c478bd9Sstevel@tonic-gate /* copy prime */ 33497c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_PRIME(pbk), 33507c478bd9Sstevel@tonic-gate KEY_PUB_DSA_PRIME(old_pub_key_obj_p)); 33517c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 33527c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type); 33537c478bd9Sstevel@tonic-gate return (rv); 33547c478bd9Sstevel@tonic-gate } 33557c478bd9Sstevel@tonic-gate 33567c478bd9Sstevel@tonic-gate /* copy subprime */ 33577c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_SUBPRIME(pbk), 33587c478bd9Sstevel@tonic-gate KEY_PUB_DSA_SUBPRIME(old_pub_key_obj_p)); 33597c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 33607c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type); 33617c478bd9Sstevel@tonic-gate return (rv); 33627c478bd9Sstevel@tonic-gate } 33637c478bd9Sstevel@tonic-gate 33647c478bd9Sstevel@tonic-gate /* copy base */ 33657c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_BASE(pbk), 33667c478bd9Sstevel@tonic-gate KEY_PUB_DSA_BASE(old_pub_key_obj_p)); 33677c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 33687c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type); 33697c478bd9Sstevel@tonic-gate return (rv); 33707c478bd9Sstevel@tonic-gate } 33717c478bd9Sstevel@tonic-gate 33727c478bd9Sstevel@tonic-gate /* copy value */ 33737c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PUB_DSA_VALUE(pbk), 33747c478bd9Sstevel@tonic-gate KEY_PUB_DSA_VALUE(old_pub_key_obj_p)); 33757c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 33767c478bd9Sstevel@tonic-gate free_public_key_attr(pbk, key_type); 33777c478bd9Sstevel@tonic-gate return (rv); 33787c478bd9Sstevel@tonic-gate } 33797c478bd9Sstevel@tonic-gate break; 33807c478bd9Sstevel@tonic-gate default: 33817c478bd9Sstevel@tonic-gate break; 33827c478bd9Sstevel@tonic-gate } 33837c478bd9Sstevel@tonic-gate *new_pub_key_obj_p = pbk; 33847c478bd9Sstevel@tonic-gate return (rv); 33857c478bd9Sstevel@tonic-gate } 33867c478bd9Sstevel@tonic-gate 33877c478bd9Sstevel@tonic-gate 33887c478bd9Sstevel@tonic-gate static void 33897c478bd9Sstevel@tonic-gate free_private_key_attr(private_key_obj_t *pbk, CK_KEY_TYPE key_type) 33907c478bd9Sstevel@tonic-gate { 33917c478bd9Sstevel@tonic-gate if (pbk == NULL) { 33927c478bd9Sstevel@tonic-gate return; 33937c478bd9Sstevel@tonic-gate } 33947c478bd9Sstevel@tonic-gate 33957c478bd9Sstevel@tonic-gate switch (key_type) { 33967c478bd9Sstevel@tonic-gate case CKK_RSA: 33977c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_MOD(pbk)); 33987c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PUBEXPO(pbk)); 33997c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PRIEXPO(pbk)); 34007c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PRIME1(pbk)); 34017c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_PRIME2(pbk)); 34027c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_EXPO1(pbk)); 34037c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_EXPO2(pbk)); 34047c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_RSA_COEF(pbk)); 34057c478bd9Sstevel@tonic-gate break; 34067c478bd9Sstevel@tonic-gate case CKK_DSA: 34077c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_PRIME(pbk)); 34087c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_SUBPRIME(pbk)); 34097c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_BASE(pbk)); 34107c478bd9Sstevel@tonic-gate bigint_attr_cleanup(KEY_PRI_DSA_VALUE(pbk)); 34117c478bd9Sstevel@tonic-gate break; 34127c478bd9Sstevel@tonic-gate default: 34137c478bd9Sstevel@tonic-gate break; 34147c478bd9Sstevel@tonic-gate } 34157c478bd9Sstevel@tonic-gate free(pbk); 34167c478bd9Sstevel@tonic-gate } 34177c478bd9Sstevel@tonic-gate 34187c478bd9Sstevel@tonic-gate CK_RV 34197c478bd9Sstevel@tonic-gate kernel_copy_private_key_attr(private_key_obj_t *old_pri_key_obj_p, 34207c478bd9Sstevel@tonic-gate private_key_obj_t **new_pri_key_obj_p, CK_KEY_TYPE key_type) 34217c478bd9Sstevel@tonic-gate { 34227c478bd9Sstevel@tonic-gate CK_RV rv = CKR_OK; 34237c478bd9Sstevel@tonic-gate private_key_obj_t *pbk; 34247c478bd9Sstevel@tonic-gate 34257c478bd9Sstevel@tonic-gate pbk = calloc(1, sizeof (private_key_obj_t)); 34267c478bd9Sstevel@tonic-gate if (pbk == NULL) { 34277c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 34287c478bd9Sstevel@tonic-gate } 34297c478bd9Sstevel@tonic-gate 34307c478bd9Sstevel@tonic-gate switch (key_type) { 34317c478bd9Sstevel@tonic-gate case CKK_RSA: 34327c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PRI_RSA(pbk), 34337c478bd9Sstevel@tonic-gate KEY_PRI_RSA(old_pri_key_obj_p), 34347c478bd9Sstevel@tonic-gate sizeof (rsa_pri_key_t)); 34357c478bd9Sstevel@tonic-gate /* copy modulus */ 34367c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_MOD(pbk), 34377c478bd9Sstevel@tonic-gate KEY_PRI_RSA_MOD(old_pri_key_obj_p)); 34387c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34397c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34407c478bd9Sstevel@tonic-gate return (rv); 34417c478bd9Sstevel@tonic-gate } 34427c478bd9Sstevel@tonic-gate /* copy public exponent */ 34437c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PUBEXPO(pbk), 34447c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PUBEXPO(old_pri_key_obj_p)); 34457c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34467c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34477c478bd9Sstevel@tonic-gate return (rv); 34487c478bd9Sstevel@tonic-gate } 34497c478bd9Sstevel@tonic-gate /* copy private exponent */ 34507c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PRIEXPO(pbk), 34517c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PRIEXPO(old_pri_key_obj_p)); 34527c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34537c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34547c478bd9Sstevel@tonic-gate return (rv); 34557c478bd9Sstevel@tonic-gate } 34567c478bd9Sstevel@tonic-gate /* copy prime_1 */ 34577c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PRIME1(pbk), 34587c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PRIME1(old_pri_key_obj_p)); 34597c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34607c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34617c478bd9Sstevel@tonic-gate return (rv); 34627c478bd9Sstevel@tonic-gate } 34637c478bd9Sstevel@tonic-gate /* copy prime_2 */ 34647c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_PRIME2(pbk), 34657c478bd9Sstevel@tonic-gate KEY_PRI_RSA_PRIME2(old_pri_key_obj_p)); 34667c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34677c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34687c478bd9Sstevel@tonic-gate return (rv); 34697c478bd9Sstevel@tonic-gate } 34707c478bd9Sstevel@tonic-gate /* copy exponent_1 */ 34717c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_EXPO1(pbk), 34727c478bd9Sstevel@tonic-gate KEY_PRI_RSA_EXPO1(old_pri_key_obj_p)); 34737c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34747c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34757c478bd9Sstevel@tonic-gate return (rv); 34767c478bd9Sstevel@tonic-gate } 34777c478bd9Sstevel@tonic-gate /* copy exponent_2 */ 34787c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_EXPO2(pbk), 34797c478bd9Sstevel@tonic-gate KEY_PRI_RSA_EXPO2(old_pri_key_obj_p)); 34807c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34817c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34827c478bd9Sstevel@tonic-gate return (rv); 34837c478bd9Sstevel@tonic-gate } 34847c478bd9Sstevel@tonic-gate /* copy coefficient */ 34857c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_RSA_COEF(pbk), 34867c478bd9Sstevel@tonic-gate KEY_PRI_RSA_COEF(old_pri_key_obj_p)); 34877c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 34887c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 34897c478bd9Sstevel@tonic-gate return (rv); 34907c478bd9Sstevel@tonic-gate } 34917c478bd9Sstevel@tonic-gate break; 34927c478bd9Sstevel@tonic-gate case CKK_DSA: 34937c478bd9Sstevel@tonic-gate (void) memcpy(KEY_PRI_DSA(pbk), 34947c478bd9Sstevel@tonic-gate KEY_PRI_DSA(old_pri_key_obj_p), 34957c478bd9Sstevel@tonic-gate sizeof (dsa_pri_key_t)); 34967c478bd9Sstevel@tonic-gate 34977c478bd9Sstevel@tonic-gate /* copy prime */ 34987c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_PRIME(pbk), 34997c478bd9Sstevel@tonic-gate KEY_PRI_DSA_PRIME(old_pri_key_obj_p)); 35007c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 35017c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 35027c478bd9Sstevel@tonic-gate return (rv); 35037c478bd9Sstevel@tonic-gate } 35047c478bd9Sstevel@tonic-gate 35057c478bd9Sstevel@tonic-gate /* copy subprime */ 35067c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_SUBPRIME(pbk), 35077c478bd9Sstevel@tonic-gate KEY_PRI_DSA_SUBPRIME(old_pri_key_obj_p)); 35087c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 35097c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 35107c478bd9Sstevel@tonic-gate return (rv); 35117c478bd9Sstevel@tonic-gate } 35127c478bd9Sstevel@tonic-gate 35137c478bd9Sstevel@tonic-gate /* copy base */ 35147c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_BASE(pbk), 35157c478bd9Sstevel@tonic-gate KEY_PRI_DSA_BASE(old_pri_key_obj_p)); 35167c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 35177c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 35187c478bd9Sstevel@tonic-gate return (rv); 35197c478bd9Sstevel@tonic-gate } 35207c478bd9Sstevel@tonic-gate 35217c478bd9Sstevel@tonic-gate /* copy value */ 35227c478bd9Sstevel@tonic-gate rv = copy_bigint(KEY_PRI_DSA_VALUE(pbk), 35237c478bd9Sstevel@tonic-gate KEY_PRI_DSA_VALUE(old_pri_key_obj_p)); 35247c478bd9Sstevel@tonic-gate if (rv != CKR_OK) { 35257c478bd9Sstevel@tonic-gate free_private_key_attr(pbk, key_type); 35267c478bd9Sstevel@tonic-gate return (rv); 35277c478bd9Sstevel@tonic-gate } 35287c478bd9Sstevel@tonic-gate break; 35297c478bd9Sstevel@tonic-gate default: 35307c478bd9Sstevel@tonic-gate break; 35317c478bd9Sstevel@tonic-gate } 35327c478bd9Sstevel@tonic-gate *new_pri_key_obj_p = pbk; 35337c478bd9Sstevel@tonic-gate return (rv); 35347c478bd9Sstevel@tonic-gate } 35357c478bd9Sstevel@tonic-gate 35367c478bd9Sstevel@tonic-gate 35377c478bd9Sstevel@tonic-gate CK_RV 35387c478bd9Sstevel@tonic-gate kernel_copy_secret_key_attr(secret_key_obj_t *old_secret_key_obj_p, 35397c478bd9Sstevel@tonic-gate secret_key_obj_t **new_secret_key_obj_p) 35407c478bd9Sstevel@tonic-gate { 35417c478bd9Sstevel@tonic-gate secret_key_obj_t *sk; 35427c478bd9Sstevel@tonic-gate 35437c478bd9Sstevel@tonic-gate sk = malloc(sizeof (secret_key_obj_t)); 35447c478bd9Sstevel@tonic-gate if (sk == NULL) { 35457c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 35467c478bd9Sstevel@tonic-gate } 35477c478bd9Sstevel@tonic-gate (void) memcpy(sk, old_secret_key_obj_p, sizeof (secret_key_obj_t)); 35487c478bd9Sstevel@tonic-gate 35497c478bd9Sstevel@tonic-gate /* copy the secret key value */ 35507c478bd9Sstevel@tonic-gate sk->sk_value = malloc((sizeof (CK_BYTE) * sk->sk_value_len)); 35517c478bd9Sstevel@tonic-gate if (sk->sk_value == NULL) { 35527c478bd9Sstevel@tonic-gate free(sk); 35537c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY); 35547c478bd9Sstevel@tonic-gate } 35557c478bd9Sstevel@tonic-gate (void) memcpy(sk->sk_value, old_secret_key_obj_p->sk_value, 35567c478bd9Sstevel@tonic-gate (sizeof (CK_BYTE) * sk->sk_value_len)); 35577c478bd9Sstevel@tonic-gate 35587c478bd9Sstevel@tonic-gate *new_secret_key_obj_p = sk; 35597c478bd9Sstevel@tonic-gate 35607c478bd9Sstevel@tonic-gate return (CKR_OK); 35617c478bd9Sstevel@tonic-gate } 35627c478bd9Sstevel@tonic-gate 35637c478bd9Sstevel@tonic-gate 35647c478bd9Sstevel@tonic-gate 35657c478bd9Sstevel@tonic-gate /* 35667c478bd9Sstevel@tonic-gate * If CKA_CLASS not given, guess CKA_CLASS using 35677c478bd9Sstevel@tonic-gate * attributes on template . 35687c478bd9Sstevel@tonic-gate * 35697c478bd9Sstevel@tonic-gate * Some attributes are specific to an object class. If one or more 35707c478bd9Sstevel@tonic-gate * of these attributes are in the template, make a list of classes 35717c478bd9Sstevel@tonic-gate * that can have these attributes. This would speed up the search later, 35727c478bd9Sstevel@tonic-gate * because we can immediately skip an object if the class of that 3573c2e31228SViswanathan Kannappan * object can not possibly contain one of the attributes. 35747c478bd9Sstevel@tonic-gate * 35757c478bd9Sstevel@tonic-gate */ 35767c478bd9Sstevel@tonic-gate void 35777c478bd9Sstevel@tonic-gate kernel_process_find_attr(CK_OBJECT_CLASS *pclasses, 35787c478bd9Sstevel@tonic-gate CK_ULONG *num_result_pclasses, CK_ATTRIBUTE_PTR pTemplate, 35797c478bd9Sstevel@tonic-gate CK_ULONG ulCount) 35807c478bd9Sstevel@tonic-gate { 35817c478bd9Sstevel@tonic-gate ulong_t i; 35827c478bd9Sstevel@tonic-gate int j; 35837c478bd9Sstevel@tonic-gate boolean_t pub_found = B_FALSE, 35847c478bd9Sstevel@tonic-gate priv_found = B_FALSE, 35857c478bd9Sstevel@tonic-gate secret_found = B_FALSE, 35867c478bd9Sstevel@tonic-gate domain_found = B_FALSE, 35877c478bd9Sstevel@tonic-gate hardware_found = B_FALSE, 35887c478bd9Sstevel@tonic-gate cert_found = B_FALSE; 35897c478bd9Sstevel@tonic-gate int num_pub_key_attrs, num_priv_key_attrs, 35907c478bd9Sstevel@tonic-gate num_secret_key_attrs, num_domain_attrs, 35917c478bd9Sstevel@tonic-gate num_hardware_attrs, num_cert_attrs; 35927c478bd9Sstevel@tonic-gate int num_pclasses = 0; 35937c478bd9Sstevel@tonic-gate 35947c478bd9Sstevel@tonic-gate for (i = 0; i < ulCount; i++) { 35957c478bd9Sstevel@tonic-gate if (pTemplate[i].type == CKA_CLASS) { 35967c478bd9Sstevel@tonic-gate /* 35977c478bd9Sstevel@tonic-gate * don't need to guess the class, it is specified. 35987c478bd9Sstevel@tonic-gate * Just record the class, and return. 35997c478bd9Sstevel@tonic-gate */ 36007c478bd9Sstevel@tonic-gate pclasses[0] = 36017c478bd9Sstevel@tonic-gate (*((CK_OBJECT_CLASS *)pTemplate[i].pValue)); 36027c478bd9Sstevel@tonic-gate *num_result_pclasses = 1; 36037c478bd9Sstevel@tonic-gate return; 36047c478bd9Sstevel@tonic-gate } 36057c478bd9Sstevel@tonic-gate } 36067c478bd9Sstevel@tonic-gate 36077c478bd9Sstevel@tonic-gate num_pub_key_attrs = 36087c478bd9Sstevel@tonic-gate sizeof (PUB_KEY_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE); 36097c478bd9Sstevel@tonic-gate num_priv_key_attrs = 36107c478bd9Sstevel@tonic-gate sizeof (PRIV_KEY_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE); 36117c478bd9Sstevel@tonic-gate num_secret_key_attrs = 36127c478bd9Sstevel@tonic-gate sizeof (SECRET_KEY_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE); 36137c478bd9Sstevel@tonic-gate num_domain_attrs = 36147c478bd9Sstevel@tonic-gate sizeof (DOMAIN_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE); 36157c478bd9Sstevel@tonic-gate num_hardware_attrs = 36167c478bd9Sstevel@tonic-gate sizeof (HARDWARE_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE); 36177c478bd9Sstevel@tonic-gate num_cert_attrs = 36187c478bd9Sstevel@tonic-gate sizeof (CERT_ATTRS) / sizeof (CK_ATTRIBUTE_TYPE); 36197c478bd9Sstevel@tonic-gate 36207c478bd9Sstevel@tonic-gate /* 36217c478bd9Sstevel@tonic-gate * Get the list of objects class that might contain 36227c478bd9Sstevel@tonic-gate * some attributes. 36237c478bd9Sstevel@tonic-gate */ 36247c478bd9Sstevel@tonic-gate for (i = 0; i < ulCount; i++) { 36257c478bd9Sstevel@tonic-gate /* 36267c478bd9Sstevel@tonic-gate * only check if this attribute can belong to public key object 36277c478bd9Sstevel@tonic-gate * class if public key object isn't already in the list 36287c478bd9Sstevel@tonic-gate */ 36297c478bd9Sstevel@tonic-gate if (!pub_found) { 36307c478bd9Sstevel@tonic-gate for (j = 0; j < num_pub_key_attrs; j++) { 36317c478bd9Sstevel@tonic-gate if (pTemplate[i].type == PUB_KEY_ATTRS[j]) { 36327c478bd9Sstevel@tonic-gate pub_found = B_TRUE; 36337c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] = 36347c478bd9Sstevel@tonic-gate CKO_PUBLIC_KEY; 36357c478bd9Sstevel@tonic-gate break; 36367c478bd9Sstevel@tonic-gate } 36377c478bd9Sstevel@tonic-gate } 36387c478bd9Sstevel@tonic-gate } 36397c478bd9Sstevel@tonic-gate 36407c478bd9Sstevel@tonic-gate if (!priv_found) { 36417c478bd9Sstevel@tonic-gate for (j = 0; j < num_priv_key_attrs; j++) { 36427c478bd9Sstevel@tonic-gate if (pTemplate[i].type == PRIV_KEY_ATTRS[j]) { 36437c478bd9Sstevel@tonic-gate priv_found = B_TRUE; 36447c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] = 36457c478bd9Sstevel@tonic-gate CKO_PRIVATE_KEY; 36467c478bd9Sstevel@tonic-gate break; 36477c478bd9Sstevel@tonic-gate } 36487c478bd9Sstevel@tonic-gate } 36497c478bd9Sstevel@tonic-gate } 36507c478bd9Sstevel@tonic-gate 36517c478bd9Sstevel@tonic-gate if (!secret_found) { 36527c478bd9Sstevel@tonic-gate for (j = 0; j < num_secret_key_attrs; j++) { 36537c478bd9Sstevel@tonic-gate if (pTemplate[i].type == SECRET_KEY_ATTRS[j]) { 36547c478bd9Sstevel@tonic-gate secret_found = B_TRUE; 36557c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] = 36567c478bd9Sstevel@tonic-gate CKO_SECRET_KEY; 36577c478bd9Sstevel@tonic-gate break; 36587c478bd9Sstevel@tonic-gate } 36597c478bd9Sstevel@tonic-gate } 36607c478bd9Sstevel@tonic-gate } 36617c478bd9Sstevel@tonic-gate 36627c478bd9Sstevel@tonic-gate if (!domain_found) { 36637c478bd9Sstevel@tonic-gate for (j = 0; j < num_domain_attrs; j++) { 36647c478bd9Sstevel@tonic-gate if (pTemplate[i].type == DOMAIN_ATTRS[j]) { 36657c478bd9Sstevel@tonic-gate domain_found = B_TRUE; 36667c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] = 36677c478bd9Sstevel@tonic-gate CKO_DOMAIN_PARAMETERS; 36687c478bd9Sstevel@tonic-gate break; 36697c478bd9Sstevel@tonic-gate } 36707c478bd9Sstevel@tonic-gate } 36717c478bd9Sstevel@tonic-gate } 36727c478bd9Sstevel@tonic-gate 36737c478bd9Sstevel@tonic-gate if (!hardware_found) { 36747c478bd9Sstevel@tonic-gate for (j = 0; j < num_hardware_attrs; j++) { 36757c478bd9Sstevel@tonic-gate if (pTemplate[i].type == HARDWARE_ATTRS[j]) { 36767c478bd9Sstevel@tonic-gate hardware_found = B_TRUE; 36777c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] = 36787c478bd9Sstevel@tonic-gate CKO_HW_FEATURE; 36797c478bd9Sstevel@tonic-gate break; 36807c478bd9Sstevel@tonic-gate } 36817c478bd9Sstevel@tonic-gate } 36827c478bd9Sstevel@tonic-gate } 36837c478bd9Sstevel@tonic-gate 36847c478bd9Sstevel@tonic-gate if (!cert_found) { 36857c478bd9Sstevel@tonic-gate for (j = 0; j < num_cert_attrs; j++) { 36867c478bd9Sstevel@tonic-gate if (pTemplate[i].type == CERT_ATTRS[j]) { 36877c478bd9Sstevel@tonic-gate cert_found = B_TRUE; 36887c478bd9Sstevel@tonic-gate pclasses[num_pclasses++] = 36897c478bd9Sstevel@tonic-gate CKO_CERTIFICATE; 36907c478bd9Sstevel@tonic-gate break; 36917c478bd9Sstevel@tonic-gate } 36927c478bd9Sstevel@tonic-gate } 36937c478bd9Sstevel@tonic-gate } 36947c478bd9Sstevel@tonic-gate } 36957c478bd9Sstevel@tonic-gate *num_result_pclasses = num_pclasses; 36967c478bd9Sstevel@tonic-gate } 36977c478bd9Sstevel@tonic-gate 36987c478bd9Sstevel@tonic-gate 36997c478bd9Sstevel@tonic-gate boolean_t 37007c478bd9Sstevel@tonic-gate kernel_find_match_attrs(kernel_object_t *obj, CK_OBJECT_CLASS *pclasses, 37017c478bd9Sstevel@tonic-gate CK_ULONG num_pclasses, CK_ATTRIBUTE *template, CK_ULONG num_attr) 37027c478bd9Sstevel@tonic-gate { 37037c478bd9Sstevel@tonic-gate ulong_t i; 37047c478bd9Sstevel@tonic-gate CK_ATTRIBUTE *tmpl_attr, *obj_attr; 37057c478bd9Sstevel@tonic-gate uint64_t attr_mask; 37067c478bd9Sstevel@tonic-gate biginteger_t *bigint; 37077c478bd9Sstevel@tonic-gate boolean_t compare_attr, compare_bigint, compare_boolean; 37087c478bd9Sstevel@tonic-gate 37097c478bd9Sstevel@tonic-gate /* 37107c478bd9Sstevel@tonic-gate * Check if the class of this object match with any 3711c2e31228SViswanathan Kannappan * of object classes that can possibly contain the 37127c478bd9Sstevel@tonic-gate * requested attributes. 37137c478bd9Sstevel@tonic-gate */ 37147c478bd9Sstevel@tonic-gate if (num_pclasses > 0) { 37157c478bd9Sstevel@tonic-gate for (i = 0; i < num_pclasses; i++) { 37167c478bd9Sstevel@tonic-gate if (obj->class == pclasses[i]) { 37177c478bd9Sstevel@tonic-gate break; 37187c478bd9Sstevel@tonic-gate } 37197c478bd9Sstevel@tonic-gate } 37207c478bd9Sstevel@tonic-gate if (i == num_pclasses) { 37217c478bd9Sstevel@tonic-gate /* 3722c2e31228SViswanathan Kannappan * this object can't possibly contain one or 37237c478bd9Sstevel@tonic-gate * more attributes, don't need to check this object 37247c478bd9Sstevel@tonic-gate */ 37257c478bd9Sstevel@tonic-gate return (B_FALSE); 37267c478bd9Sstevel@tonic-gate } 37277c478bd9Sstevel@tonic-gate } 37287c478bd9Sstevel@tonic-gate 37297c478bd9Sstevel@tonic-gate /* need to examine everything */ 37307c478bd9Sstevel@tonic-gate for (i = 0; i < num_attr; i++) { 37317c478bd9Sstevel@tonic-gate tmpl_attr = &(template[i]); 37327c478bd9Sstevel@tonic-gate compare_attr = B_FALSE; 37337c478bd9Sstevel@tonic-gate compare_bigint = B_FALSE; 37347c478bd9Sstevel@tonic-gate compare_boolean = B_FALSE; 37357c478bd9Sstevel@tonic-gate switch (tmpl_attr->type) { 37367c478bd9Sstevel@tonic-gate /* First, check the most common attributes */ 37377c478bd9Sstevel@tonic-gate case CKA_CLASS: 37387c478bd9Sstevel@tonic-gate if (*((CK_OBJECT_CLASS *)tmpl_attr->pValue) != 37397c478bd9Sstevel@tonic-gate obj->class) { 37407c478bd9Sstevel@tonic-gate return (B_FALSE); 37417c478bd9Sstevel@tonic-gate } 37427c478bd9Sstevel@tonic-gate break; 37437c478bd9Sstevel@tonic-gate case CKA_KEY_TYPE: 37447c478bd9Sstevel@tonic-gate if (*((CK_KEY_TYPE *)tmpl_attr->pValue) != 37457c478bd9Sstevel@tonic-gate obj->key_type) { 37467c478bd9Sstevel@tonic-gate return (B_FALSE); 37477c478bd9Sstevel@tonic-gate } 37487c478bd9Sstevel@tonic-gate break; 37497c478bd9Sstevel@tonic-gate case CKA_ENCRYPT: 37507c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & ENCRYPT_BOOL_ON; 37517c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37527c478bd9Sstevel@tonic-gate break; 37537c478bd9Sstevel@tonic-gate case CKA_DECRYPT: 37547c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & DECRYPT_BOOL_ON; 37557c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37567c478bd9Sstevel@tonic-gate break; 37577c478bd9Sstevel@tonic-gate case CKA_WRAP: 37587c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & WRAP_BOOL_ON; 37597c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37607c478bd9Sstevel@tonic-gate break; 37617c478bd9Sstevel@tonic-gate case CKA_UNWRAP: 37627c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & UNWRAP_BOOL_ON; 37637c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37647c478bd9Sstevel@tonic-gate break; 37657c478bd9Sstevel@tonic-gate case CKA_SIGN: 37667c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & SIGN_BOOL_ON; 37677c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37687c478bd9Sstevel@tonic-gate break; 37697c478bd9Sstevel@tonic-gate case CKA_SIGN_RECOVER: 37707c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & 37717c478bd9Sstevel@tonic-gate SIGN_RECOVER_BOOL_ON; 37727c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37737c478bd9Sstevel@tonic-gate break; 37747c478bd9Sstevel@tonic-gate case CKA_VERIFY: 37757c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & VERIFY_BOOL_ON; 37767c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37777c478bd9Sstevel@tonic-gate break; 37787c478bd9Sstevel@tonic-gate case CKA_VERIFY_RECOVER: 37797c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & 37807c478bd9Sstevel@tonic-gate VERIFY_RECOVER_BOOL_ON; 37817c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37827c478bd9Sstevel@tonic-gate break; 37837c478bd9Sstevel@tonic-gate case CKA_DERIVE: 37847c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & DERIVE_BOOL_ON; 37857c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37867c478bd9Sstevel@tonic-gate break; 37877c478bd9Sstevel@tonic-gate case CKA_LOCAL: 37887c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & LOCAL_BOOL_ON; 37897c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37907c478bd9Sstevel@tonic-gate break; 37917c478bd9Sstevel@tonic-gate case CKA_SENSITIVE: 37927c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & SENSITIVE_BOOL_ON; 37937c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37947c478bd9Sstevel@tonic-gate break; 37957c478bd9Sstevel@tonic-gate case CKA_SECONDARY_AUTH: 37967c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & 37977c478bd9Sstevel@tonic-gate SECONDARY_AUTH_BOOL_ON; 37987c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 37997c478bd9Sstevel@tonic-gate break; 38007c478bd9Sstevel@tonic-gate case CKA_TRUSTED: 38017c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & TRUSTED_BOOL_ON; 38027c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38037c478bd9Sstevel@tonic-gate break; 38047c478bd9Sstevel@tonic-gate case CKA_EXTRACTABLE: 38057c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & 38067c478bd9Sstevel@tonic-gate EXTRACTABLE_BOOL_ON; 38077c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38087c478bd9Sstevel@tonic-gate break; 38097c478bd9Sstevel@tonic-gate case CKA_ALWAYS_SENSITIVE: 38107c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & 38117c478bd9Sstevel@tonic-gate ALWAYS_SENSITIVE_BOOL_ON; 38127c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38137c478bd9Sstevel@tonic-gate break; 38147c478bd9Sstevel@tonic-gate case CKA_NEVER_EXTRACTABLE: 38157c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & 38167c478bd9Sstevel@tonic-gate NEVER_EXTRACTABLE_BOOL_ON; 38177c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38187c478bd9Sstevel@tonic-gate break; 38197c478bd9Sstevel@tonic-gate case CKA_TOKEN: 38207c478bd9Sstevel@tonic-gate /* 38217c478bd9Sstevel@tonic-gate * CKA_TOKEN value is not applicable to an object 38227c478bd9Sstevel@tonic-gate * created in the library, it should only contain 38237c478bd9Sstevel@tonic-gate * the default value FALSE 38247c478bd9Sstevel@tonic-gate */ 38257c478bd9Sstevel@tonic-gate attr_mask = 0; 38267c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38277c478bd9Sstevel@tonic-gate break; 38287c478bd9Sstevel@tonic-gate case CKA_PRIVATE: 38297c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & PRIVATE_BOOL_ON; 38307c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38317c478bd9Sstevel@tonic-gate break; 38327c478bd9Sstevel@tonic-gate case CKA_MODIFIABLE: 38337c478bd9Sstevel@tonic-gate attr_mask = (obj->bool_attr_mask) & MODIFIABLE_BOOL_ON; 38347c478bd9Sstevel@tonic-gate compare_boolean = B_TRUE; 38357c478bd9Sstevel@tonic-gate break; 38367c478bd9Sstevel@tonic-gate case CKA_SUBJECT: 38377c478bd9Sstevel@tonic-gate case CKA_ID: 38387c478bd9Sstevel@tonic-gate case CKA_START_DATE: 38397c478bd9Sstevel@tonic-gate case CKA_END_DATE: 38407c478bd9Sstevel@tonic-gate case CKA_KEY_GEN_MECHANISM: 38417c478bd9Sstevel@tonic-gate case CKA_LABEL: 38427c478bd9Sstevel@tonic-gate /* find these attributes from extra_attrlistp */ 38437c478bd9Sstevel@tonic-gate obj_attr = get_extra_attr(tmpl_attr->type, obj); 38447c478bd9Sstevel@tonic-gate compare_attr = B_TRUE; 38457c478bd9Sstevel@tonic-gate break; 38467c478bd9Sstevel@tonic-gate case CKA_VALUE_LEN: 38477c478bd9Sstevel@tonic-gate /* only secret key has this attribute */ 38487c478bd9Sstevel@tonic-gate if (obj->class == CKO_SECRET_KEY) { 38497c478bd9Sstevel@tonic-gate if (*((CK_ULONG *)tmpl_attr->pValue) != 38507c478bd9Sstevel@tonic-gate OBJ_SEC_VALUE_LEN(obj)) { 38517c478bd9Sstevel@tonic-gate return (B_FALSE); 38527c478bd9Sstevel@tonic-gate } 38537c478bd9Sstevel@tonic-gate } else { 38547c478bd9Sstevel@tonic-gate return (B_FALSE); 38557c478bd9Sstevel@tonic-gate } 38567c478bd9Sstevel@tonic-gate break; 38577c478bd9Sstevel@tonic-gate case CKA_VALUE: 38587c478bd9Sstevel@tonic-gate switch (obj->class) { 38597c478bd9Sstevel@tonic-gate case CKO_SECRET_KEY: 38607c478bd9Sstevel@tonic-gate /* 38617c478bd9Sstevel@tonic-gate * secret_key_obj_t is the same as 38627c478bd9Sstevel@tonic-gate * biginteger_t 38637c478bd9Sstevel@tonic-gate */ 38647c478bd9Sstevel@tonic-gate bigint = (biginteger_t *)OBJ_SEC(obj); 38657c478bd9Sstevel@tonic-gate break; 38667c478bd9Sstevel@tonic-gate case CKO_PRIVATE_KEY: 38677c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_DSA) { 38687c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_VALUE(obj); 38697c478bd9Sstevel@tonic-gate } else { 38707c478bd9Sstevel@tonic-gate return (B_FALSE); 38717c478bd9Sstevel@tonic-gate } 38727c478bd9Sstevel@tonic-gate break; 38737c478bd9Sstevel@tonic-gate case CKO_PUBLIC_KEY: 38747c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_DSA) { 38757c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_VALUE(obj); 38767c478bd9Sstevel@tonic-gate } else { 38777c478bd9Sstevel@tonic-gate return (B_FALSE); 38787c478bd9Sstevel@tonic-gate } 38797c478bd9Sstevel@tonic-gate break; 38807c478bd9Sstevel@tonic-gate default: 38817c478bd9Sstevel@tonic-gate return (B_FALSE); 38827c478bd9Sstevel@tonic-gate } 38837c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 38847c478bd9Sstevel@tonic-gate break; 38857c478bd9Sstevel@tonic-gate case CKA_MODULUS: 38867c478bd9Sstevel@tonic-gate /* only RSA public and private key have this attr */ 38877c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_RSA) { 38887c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) { 38897c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_RSA_MOD(obj); 38907c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) { 38917c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_MOD(obj); 38927c478bd9Sstevel@tonic-gate } else { 38937c478bd9Sstevel@tonic-gate return (B_FALSE); 38947c478bd9Sstevel@tonic-gate } 38957c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 38967c478bd9Sstevel@tonic-gate } else { 38977c478bd9Sstevel@tonic-gate return (B_FALSE); 38987c478bd9Sstevel@tonic-gate } 38997c478bd9Sstevel@tonic-gate break; 39007c478bd9Sstevel@tonic-gate case CKA_MODULUS_BITS: 39017c478bd9Sstevel@tonic-gate /* only RSA public key has this attribute */ 39027c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39037c478bd9Sstevel@tonic-gate (obj->class == CKO_PUBLIC_KEY)) { 39047c478bd9Sstevel@tonic-gate CK_ULONG mod_bits = OBJ_PUB_RSA_MOD_BITS(obj); 39057c478bd9Sstevel@tonic-gate if (mod_bits != 39067c478bd9Sstevel@tonic-gate *((CK_ULONG *)tmpl_attr->pValue)) { 39077c478bd9Sstevel@tonic-gate return (B_FALSE); 39087c478bd9Sstevel@tonic-gate } 39097c478bd9Sstevel@tonic-gate } else { 39107c478bd9Sstevel@tonic-gate return (B_FALSE); 39117c478bd9Sstevel@tonic-gate } 39127c478bd9Sstevel@tonic-gate break; 39137c478bd9Sstevel@tonic-gate case CKA_PUBLIC_EXPONENT: 39147c478bd9Sstevel@tonic-gate /* only RSA public and private key have this attr */ 39157c478bd9Sstevel@tonic-gate if (obj->key_type == CKK_RSA) { 39167c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) { 39177c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_RSA_PUBEXPO(obj); 39187c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) { 39197c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PUBEXPO(obj); 39207c478bd9Sstevel@tonic-gate } else { 39217c478bd9Sstevel@tonic-gate return (B_FALSE); 39227c478bd9Sstevel@tonic-gate } 39237c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39247c478bd9Sstevel@tonic-gate } else { 39257c478bd9Sstevel@tonic-gate return (B_FALSE); 39267c478bd9Sstevel@tonic-gate } 39277c478bd9Sstevel@tonic-gate break; 39287c478bd9Sstevel@tonic-gate case CKA_PRIVATE_EXPONENT: 39297c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */ 39307c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39317c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) { 39327c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PRIEXPO(obj); 39337c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39347c478bd9Sstevel@tonic-gate } else { 39357c478bd9Sstevel@tonic-gate return (B_FALSE); 39367c478bd9Sstevel@tonic-gate } 39377c478bd9Sstevel@tonic-gate break; 39387c478bd9Sstevel@tonic-gate case CKA_PRIME_1: 39397c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */ 39407c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39417c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) { 39427c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PRIME1(obj); 39437c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39447c478bd9Sstevel@tonic-gate } else { 39457c478bd9Sstevel@tonic-gate return (B_FALSE); 39467c478bd9Sstevel@tonic-gate } 39477c478bd9Sstevel@tonic-gate break; 39487c478bd9Sstevel@tonic-gate case CKA_PRIME_2: 39497c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */ 39507c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39517c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) { 39527c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_PRIME2(obj); 39537c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39547c478bd9Sstevel@tonic-gate } else { 39557c478bd9Sstevel@tonic-gate return (B_FALSE); 39567c478bd9Sstevel@tonic-gate } 39577c478bd9Sstevel@tonic-gate break; 39587c478bd9Sstevel@tonic-gate case CKA_EXPONENT_1: 39597c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */ 39607c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39617c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) { 39627c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_EXPO1(obj); 39637c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39647c478bd9Sstevel@tonic-gate } else { 39657c478bd9Sstevel@tonic-gate return (B_FALSE); 39667c478bd9Sstevel@tonic-gate } 39677c478bd9Sstevel@tonic-gate break; 39687c478bd9Sstevel@tonic-gate case CKA_EXPONENT_2: 39697c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */ 39707c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39717c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) { 39727c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_EXPO2(obj); 39737c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39747c478bd9Sstevel@tonic-gate } else { 39757c478bd9Sstevel@tonic-gate return (B_FALSE); 39767c478bd9Sstevel@tonic-gate } 39777c478bd9Sstevel@tonic-gate break; 39787c478bd9Sstevel@tonic-gate case CKA_COEFFICIENT: 39797c478bd9Sstevel@tonic-gate /* only RSA private key has this attribute */ 39807c478bd9Sstevel@tonic-gate if ((obj->key_type == CKK_RSA) && 39817c478bd9Sstevel@tonic-gate (obj->class == CKO_PRIVATE_KEY)) { 39827c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_RSA_COEF(obj); 39837c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 39847c478bd9Sstevel@tonic-gate } else { 39857c478bd9Sstevel@tonic-gate return (B_FALSE); 39867c478bd9Sstevel@tonic-gate } 39877c478bd9Sstevel@tonic-gate break; 39887c478bd9Sstevel@tonic-gate case CKA_VALUE_BITS: 39897c478bd9Sstevel@tonic-gate return (B_FALSE); 39907c478bd9Sstevel@tonic-gate case CKA_PRIME: 39917c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) { 39927c478bd9Sstevel@tonic-gate switch (obj->key_type) { 39937c478bd9Sstevel@tonic-gate case CKK_DSA: 39947c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_PRIME(obj); 39957c478bd9Sstevel@tonic-gate break; 39967c478bd9Sstevel@tonic-gate default: 39977c478bd9Sstevel@tonic-gate return (B_FALSE); 39987c478bd9Sstevel@tonic-gate } 39997c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) { 40007c478bd9Sstevel@tonic-gate switch (obj->key_type) { 40017c478bd9Sstevel@tonic-gate case CKK_DSA: 40027c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_PRIME(obj); 40037c478bd9Sstevel@tonic-gate break; 40047c478bd9Sstevel@tonic-gate default: 40057c478bd9Sstevel@tonic-gate return (B_FALSE); 40067c478bd9Sstevel@tonic-gate } 40077c478bd9Sstevel@tonic-gate } else { 40087c478bd9Sstevel@tonic-gate return (B_FALSE); 40097c478bd9Sstevel@tonic-gate } 40107c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 40117c478bd9Sstevel@tonic-gate break; 40127c478bd9Sstevel@tonic-gate case CKA_SUBPRIME: 40137c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) { 40147c478bd9Sstevel@tonic-gate switch (obj->key_type) { 40157c478bd9Sstevel@tonic-gate case CKK_DSA: 40167c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_SUBPRIME(obj); 40177c478bd9Sstevel@tonic-gate break; 40187c478bd9Sstevel@tonic-gate default: 40197c478bd9Sstevel@tonic-gate return (B_FALSE); 40207c478bd9Sstevel@tonic-gate } 40217c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) { 40227c478bd9Sstevel@tonic-gate switch (obj->key_type) { 40237c478bd9Sstevel@tonic-gate case CKK_DSA: 40247c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_SUBPRIME(obj); 40257c478bd9Sstevel@tonic-gate break; 40267c478bd9Sstevel@tonic-gate default: 40277c478bd9Sstevel@tonic-gate return (B_FALSE); 40287c478bd9Sstevel@tonic-gate } 40297c478bd9Sstevel@tonic-gate } else { 40307c478bd9Sstevel@tonic-gate return (B_FALSE); 40317c478bd9Sstevel@tonic-gate } 40327c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 40337c478bd9Sstevel@tonic-gate break; 40347c478bd9Sstevel@tonic-gate case CKA_BASE: 40357c478bd9Sstevel@tonic-gate if (obj->class == CKO_PUBLIC_KEY) { 40367c478bd9Sstevel@tonic-gate switch (obj->key_type) { 40377c478bd9Sstevel@tonic-gate case CKK_DSA: 40387c478bd9Sstevel@tonic-gate bigint = OBJ_PUB_DSA_BASE(obj); 40397c478bd9Sstevel@tonic-gate break; 40407c478bd9Sstevel@tonic-gate default: 40417c478bd9Sstevel@tonic-gate return (B_FALSE); 40427c478bd9Sstevel@tonic-gate } 40437c478bd9Sstevel@tonic-gate } else if (obj->class == CKO_PRIVATE_KEY) { 40447c478bd9Sstevel@tonic-gate switch (obj->key_type) { 40457c478bd9Sstevel@tonic-gate case CKK_DSA: 40467c478bd9Sstevel@tonic-gate bigint = OBJ_PRI_DSA_BASE(obj); 40477c478bd9Sstevel@tonic-gate break; 40487c478bd9Sstevel@tonic-gate default: 40497c478bd9Sstevel@tonic-gate return (B_FALSE); 40507c478bd9Sstevel@tonic-gate } 40517c478bd9Sstevel@tonic-gate } else { 40527c478bd9Sstevel@tonic-gate return (B_FALSE); 40537c478bd9Sstevel@tonic-gate } 40547c478bd9Sstevel@tonic-gate compare_bigint = B_TRUE; 40557c478bd9Sstevel@tonic-gate break; 40567c478bd9Sstevel@tonic-gate case CKA_PRIME_BITS: 40577c478bd9Sstevel@tonic-gate return (B_FALSE); 40587c478bd9Sstevel@tonic-gate case CKA_SUBPRIME_BITS: 40597c478bd9Sstevel@tonic-gate return (B_FALSE); 40607c478bd9Sstevel@tonic-gate default: 40617c478bd9Sstevel@tonic-gate /* 40627c478bd9Sstevel@tonic-gate * any other attributes are currently not supported. 40637c478bd9Sstevel@tonic-gate * so, it's not possible for them to be in the 40647c478bd9Sstevel@tonic-gate * object 40657c478bd9Sstevel@tonic-gate */ 40667c478bd9Sstevel@tonic-gate return (B_FALSE); 40677c478bd9Sstevel@tonic-gate } 40687c478bd9Sstevel@tonic-gate if (compare_boolean) { 40697c478bd9Sstevel@tonic-gate CK_BBOOL bval; 40707c478bd9Sstevel@tonic-gate 40717c478bd9Sstevel@tonic-gate if (attr_mask) { 40727c478bd9Sstevel@tonic-gate bval = TRUE; 40737c478bd9Sstevel@tonic-gate } else { 40747c478bd9Sstevel@tonic-gate bval = FALSE; 40757c478bd9Sstevel@tonic-gate } 40767c478bd9Sstevel@tonic-gate if (bval != *((CK_BBOOL *)tmpl_attr->pValue)) { 40777c478bd9Sstevel@tonic-gate return (B_FALSE); 40787c478bd9Sstevel@tonic-gate } 40797c478bd9Sstevel@tonic-gate } else if (compare_bigint) { 40807c478bd9Sstevel@tonic-gate if (bigint == NULL) { 40817c478bd9Sstevel@tonic-gate return (B_FALSE); 40827c478bd9Sstevel@tonic-gate } 40837c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen != bigint->big_value_len) { 40847c478bd9Sstevel@tonic-gate return (B_FALSE); 40857c478bd9Sstevel@tonic-gate } 40867c478bd9Sstevel@tonic-gate if (memcmp(tmpl_attr->pValue, bigint->big_value, 40877c478bd9Sstevel@tonic-gate tmpl_attr->ulValueLen) != 0) { 40887c478bd9Sstevel@tonic-gate return (B_FALSE); 40897c478bd9Sstevel@tonic-gate } 40907c478bd9Sstevel@tonic-gate } else if (compare_attr) { 40917c478bd9Sstevel@tonic-gate if (obj_attr == NULL) { 40927c478bd9Sstevel@tonic-gate /* 40937c478bd9Sstevel@tonic-gate * The attribute type is valid, and its value 40947c478bd9Sstevel@tonic-gate * has not been initialized in the object. In 40957c478bd9Sstevel@tonic-gate * this case, it only matches the template's 40967c478bd9Sstevel@tonic-gate * attribute if the template's value length 40977c478bd9Sstevel@tonic-gate * is 0. 40987c478bd9Sstevel@tonic-gate */ 40997c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen != 0) 41007c478bd9Sstevel@tonic-gate return (B_FALSE); 41017c478bd9Sstevel@tonic-gate } else { 41027c478bd9Sstevel@tonic-gate if (tmpl_attr->ulValueLen != 41037c478bd9Sstevel@tonic-gate obj_attr->ulValueLen) { 41047c478bd9Sstevel@tonic-gate return (B_FALSE); 41057c478bd9Sstevel@tonic-gate } 41067c478bd9Sstevel@tonic-gate if (memcmp(tmpl_attr->pValue, obj_attr->pValue, 41077c478bd9Sstevel@tonic-gate tmpl_attr->ulValueLen) != 0) { 41087c478bd9Sstevel@tonic-gate return (B_FALSE); 41097c478bd9Sstevel@tonic-gate } 41107c478bd9Sstevel@tonic-gate } 41117c478bd9Sstevel@tonic-gate } 41127c478bd9Sstevel@tonic-gate } 41137c478bd9Sstevel@tonic-gate return (B_TRUE); 41147c478bd9Sstevel@tonic-gate } 41157c478bd9Sstevel@tonic-gate 41167c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_PTR 41177c478bd9Sstevel@tonic-gate get_extra_attr(CK_ATTRIBUTE_TYPE type, kernel_object_t *obj) 41187c478bd9Sstevel@tonic-gate { 41197c478bd9Sstevel@tonic-gate CK_ATTRIBUTE_INFO_PTR tmp; 41207c478bd9Sstevel@tonic-gate 41217c478bd9Sstevel@tonic-gate tmp = obj->extra_attrlistp; 41227c478bd9Sstevel@tonic-gate while (tmp != NULL) { 41237c478bd9Sstevel@tonic-gate if (tmp->attr.type == type) { 41247c478bd9Sstevel@tonic-gate return (&(tmp->attr)); 41257c478bd9Sstevel@tonic-gate } 41267c478bd9Sstevel@tonic-gate tmp = tmp->next; 41277c478bd9Sstevel@tonic-gate } 41287c478bd9Sstevel@tonic-gate /* if get there, the specified attribute is not found */ 41297c478bd9Sstevel@tonic-gate return (NULL); 41307c478bd9Sstevel@tonic-gate } 4131