Print this page
5031131 perf: pkcs11_kernel can benefit from a more efficient pkcs11_mech2str()

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-crypto/cryptoadm/adm_metaslot.c
          +++ new/usr/src/cmd/cmd-crypto/cryptoadm/adm_metaslot.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5      - * Common Development and Distribution License, Version 1.0 only
   6      - * (the "License").  You may not use this file except in compliance
   7      - * with the License.
        5 + * Common Development and Distribution License (the "License").
        6 + * You may not use this file except in compliance with the License.
   8    7   *
   9    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10    9   * or http://www.opensolaris.org/os/licensing.
  11   10   * See the License for the specific language governing permissions
  12   11   * and limitations under the License.
  13   12   *
  14   13   * When distributing Covered Code, include this CDDL HEADER in each
  15   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   15   * If applicable, add the following below this CDDL HEADER, with the
  17   16   * fields enclosed by brackets "[]" replaced with your own identifying
  18   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   18   *
  20   19   * CDDL HEADER END
  21   20   */
  22   21  /*
  23      - * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
       22 + * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   23   * Use is subject to license terms.
  25   24   */
  26   25  
  27      -#pragma ident   "@(#)adm_metaslot.c     1.3     05/06/08 SMI"
       26 +#pragma ident   "@(#)adm_metaslot.c     1.4     08/06/27 SMI"
  28   27  
  29   28  /*
  30   29   * Administration for metaslot
  31   30   *
  32   31   * All the "list" operations will call functions in libpkcs11.so
  33   32   * Normally, it doesn't make sense to call functions in libpkcs11.so directly
  34   33   * because libpkcs11.so depends on the configuration file (pkcs11.conf) the
  35   34   * cryptoadm command is trying to administer.  However, since metaslot
  36   35   * is part of the framework, it is not possible to get information about
  37   36   * it without actually calling functions in libpkcs11.so.
↓ open down ↓ 124 lines elided ↑ open up ↑
 162  161                  cryptodebug("C_Initialize failed with error code 0x%x\n", rv);
 163  162                  rc = FAILURE;
 164  163                  goto finish;
 165  164          } else {
 166  165                  lib_initialized = B_TRUE;
 167  166          }
 168  167  
 169  168          /*
 170  169           * We know for sure that metaslot is slot 0 in the framework,
 171  170           * so, we will do a C_GetSlotInfo() trying to see if it works.
 172      -         * If it failes with CKR_SLOT_ID_INVALID, we know that metaslot
      171 +         * If it fails with CKR_SLOT_ID_INVALID, we know that metaslot
 173  172           * is not really enabled.
 174  173           */
 175  174          rv = funcs->C_GetSlotInfo(METASLOT_ID, &slot_info);
 176  175          if (rv == CKR_SLOT_ID_INVALID) {
 177  176                  (void) printf(gettext("actual status: disabled.\n"));
 178  177                  /*
 179  178                   * Even if the -m and -v flag is supplied, there's nothing
 180  179                   * interesting to display about metaslot since it is disabled,
 181  180                   * so, just stop right here.
 182  181                   */
↓ open down ↓ 94 lines elided ↑ open up ↑
 277  276          if (mech_count == 0) {
 278  277                  /* should never be this case */
 279  278                  (void) printf(gettext("No mechanisms\n"));
 280  279                  goto finish;
 281  280          }
 282  281          if (verbose) {
 283  282                  display_verbose_mech_header();
 284  283          }
 285  284  
 286  285          for (i = 0; i < mech_count; i++) {
 287      -                (void) printf("%-29s", pkcs11_mech2str(pmech_list[i]));
      286 +                CK_MECHANISM_TYPE       mech = pmech_list[i];
      287 +
      288 +                if (mech > CKM_VENDOR_DEFINED) {
      289 +                        (void) printf("%#lx", mech);
      290 +                } else {
      291 +                        (void) printf("%-29s", pkcs11_mech2str(mech));
      292 +                }
      293 +
 288  294                  if (verbose) {
 289  295                          CK_MECHANISM_INFO mech_info;
 290  296                          rv = funcs->C_GetMechanismInfo(METASLOT_ID,
 291      -                            pmech_list[i], &mech_info);
      297 +                            mech, &mech_info);
 292  298                          if (rv != CKR_OK) {
 293  299                                  cryptodebug("C_GetMechanismInfo failed with "
 294  300                                      "error code 0x%x\n", rv);
 295  301                                  rc = FAILURE;
 296  302                                  goto finish;
 297  303                          }
 298  304                          display_mech_info(&mech_info);
 299  305                  }
 300  306                  (void) printf("\n");
 301  307          }
↓ open down ↓ 234 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX