Print this page
6723237 libcryptoutil should allow mechanism number "0x80000000" (the value of marker CKM_VENDOR_DEFINED)


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "@(#)kernelUtil.c       1.17    08/06/30 SMI"
  27 
  28 #include <stdlib.h>
  29 #include <string.h>
  30 #include <strings.h>
  31 #include <stdio.h>
  32 #include <cryptoutil.h>
  33 #include <errno.h>
  34 #include <security/cryptoki.h>
  35 #include <sys/crypto/common.h>
  36 #include <sys/crypto/ioctl.h>
  37 #include "kernelGlobal.h"
  38 #include "kernelObject.h"
  39 #include "kernelSlot.h"
  40 
  41 #define ENCODE_ATTR(type, value, len) {         \
  42         cur_attr->oa_type = type;            \
  43         (void) memcpy(ptr, value, len);         \
  44         cur_attr->oa_value = ptr;            \
  45         cur_attr->oa_value_len = len;                \
  46         cur_attr++;                             \


 195         crypto_get_mechanism_number_t get_number;
 196         const char *string;
 197         CK_RV rv;
 198         int r;
 199         kmh_elem_t *elem;
 200         uint_t h;
 201         char buf[11];   /* Num chars for representing ulong in ASCII */
 202 
 203         /*
 204          * Search for an existing entry. No need to lock since we are
 205          * just a reader and we never free the entries in the hash table.
 206          */
 207         h = MECH_HASH(type);
 208         for (elem = kernel_mechhash[h]; elem != NULL; elem = elem->knext) {
 209                 if (type == elem->type) {
 210                         *k_number = elem->kmech;
 211                         return (CKR_OK);
 212                 }
 213         }
 214 
 215         if (type > CKM_VENDOR_DEFINED) {
 216                 (void) snprintf(buf, sizeof (buf), "%#lx", type);
 217                 string = buf;
 218         } else {
 219                 string = pkcs11_mech2str(type);
 220         }
 221 
 222         if (string == NULL)
 223                 return (CKR_MECHANISM_INVALID);
 224 
 225         get_number.pn_mechanism_string = (char *)string;
 226         get_number.pn_mechanism_len = strlen(string) + 1;
 227 
 228         while ((r = ioctl(kernel_fd, CRYPTO_GET_MECHANISM_NUMBER,
 229             &get_number)) < 0) {
 230                 if (errno != EINTR)
 231                         break;
 232         }
 233         if (r < 0) {
 234                 rv = CKR_MECHANISM_INVALID;
 235         } else {


1217 
1218         if (rv == CKR_OK) {
1219                 *is_pri_obj = *(CK_BBOOL *)obj_attr.oa_value;
1220         }
1221 
1222         return (rv);
1223 }
1224 
1225 
1226 CK_RV
1227 get_mechanism_info(kernel_slot_t *pslot, CK_MECHANISM_TYPE type,
1228     CK_MECHANISM_INFO_PTR pInfo, uint32_t *k_mi_flags)
1229 {
1230         crypto_get_provider_mechanism_info_t mechanism_info;
1231         const char *string;
1232         CK_FLAGS flags, mi_flags;
1233         CK_RV rv;
1234         int r;
1235         char buf[11];   /* Num chars for representing ulong in ASCII */
1236 
1237         if (type > CKM_VENDOR_DEFINED) {
1238                 /* allocate/build a string containing the mechanism number */
1239                 (void) snprintf(buf, sizeof (buf), "%#lx", type);
1240                 string = buf;
1241         } else {
1242                 string = pkcs11_mech2str(type);
1243         }
1244 
1245         if (string == NULL)
1246                 return (CKR_MECHANISM_INVALID);
1247 
1248         (void) strcpy(mechanism_info.mi_mechanism_name, string);
1249         mechanism_info.mi_provider_id = pslot->sl_provider_id;
1250 
1251         while ((r = ioctl(kernel_fd, CRYPTO_GET_PROVIDER_MECHANISM_INFO,
1252             &mechanism_info)) < 0) {
1253                 if (errno != EINTR)
1254                         break;
1255         }
1256         if (r < 0) {
1257                 rv = CKR_FUNCTION_FAILED;




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "@(#)kernelUtil.c       1.18    08/07/07 SMI"
  27 
  28 #include <stdlib.h>
  29 #include <string.h>
  30 #include <strings.h>
  31 #include <stdio.h>
  32 #include <cryptoutil.h>
  33 #include <errno.h>
  34 #include <security/cryptoki.h>
  35 #include <sys/crypto/common.h>
  36 #include <sys/crypto/ioctl.h>
  37 #include "kernelGlobal.h"
  38 #include "kernelObject.h"
  39 #include "kernelSlot.h"
  40 
  41 #define ENCODE_ATTR(type, value, len) {         \
  42         cur_attr->oa_type = type;            \
  43         (void) memcpy(ptr, value, len);         \
  44         cur_attr->oa_value = ptr;            \
  45         cur_attr->oa_value_len = len;                \
  46         cur_attr++;                             \


 195         crypto_get_mechanism_number_t get_number;
 196         const char *string;
 197         CK_RV rv;
 198         int r;
 199         kmh_elem_t *elem;
 200         uint_t h;
 201         char buf[11];   /* Num chars for representing ulong in ASCII */
 202 
 203         /*
 204          * Search for an existing entry. No need to lock since we are
 205          * just a reader and we never free the entries in the hash table.
 206          */
 207         h = MECH_HASH(type);
 208         for (elem = kernel_mechhash[h]; elem != NULL; elem = elem->knext) {
 209                 if (type == elem->type) {
 210                         *k_number = elem->kmech;
 211                         return (CKR_OK);
 212                 }
 213         }
 214 
 215         if (type >= CKM_VENDOR_DEFINED) {
 216                 (void) snprintf(buf, sizeof (buf), "%#lx", type);
 217                 string = buf;
 218         } else {
 219                 string = pkcs11_mech2str(type);
 220         }
 221 
 222         if (string == NULL)
 223                 return (CKR_MECHANISM_INVALID);
 224 
 225         get_number.pn_mechanism_string = (char *)string;
 226         get_number.pn_mechanism_len = strlen(string) + 1;
 227 
 228         while ((r = ioctl(kernel_fd, CRYPTO_GET_MECHANISM_NUMBER,
 229             &get_number)) < 0) {
 230                 if (errno != EINTR)
 231                         break;
 232         }
 233         if (r < 0) {
 234                 rv = CKR_MECHANISM_INVALID;
 235         } else {


1217 
1218         if (rv == CKR_OK) {
1219                 *is_pri_obj = *(CK_BBOOL *)obj_attr.oa_value;
1220         }
1221 
1222         return (rv);
1223 }
1224 
1225 
1226 CK_RV
1227 get_mechanism_info(kernel_slot_t *pslot, CK_MECHANISM_TYPE type,
1228     CK_MECHANISM_INFO_PTR pInfo, uint32_t *k_mi_flags)
1229 {
1230         crypto_get_provider_mechanism_info_t mechanism_info;
1231         const char *string;
1232         CK_FLAGS flags, mi_flags;
1233         CK_RV rv;
1234         int r;
1235         char buf[11];   /* Num chars for representing ulong in ASCII */
1236 
1237         if (type >= CKM_VENDOR_DEFINED) {
1238                 /* allocate/build a string containing the mechanism number */
1239                 (void) snprintf(buf, sizeof (buf), "%#lx", type);
1240                 string = buf;
1241         } else {
1242                 string = pkcs11_mech2str(type);
1243         }
1244 
1245         if (string == NULL)
1246                 return (CKR_MECHANISM_INVALID);
1247 
1248         (void) strcpy(mechanism_info.mi_mechanism_name, string);
1249         mechanism_info.mi_provider_id = pslot->sl_provider_id;
1250 
1251         while ((r = ioctl(kernel_fd, CRYPTO_GET_PROVIDER_MECHANISM_INFO,
1252             &mechanism_info)) < 0) {
1253                 if (errno != EINTR)
1254                         break;
1255         }
1256         if (r < 0) {
1257                 rv = CKR_FUNCTION_FAILED;