Print this page
6414175 kcf.conf's supportedlist not providing much usefulness

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/crypto/core/kcf_prov_tabs.c
          +++ new/usr/src/uts/common/crypto/core/kcf_prov_tabs.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22      - * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
       22 + * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  27      -
  28   26  /*
  29   27   * This file is part of the core Kernel Cryptographic Framework.
  30   28   * It implements the management of tables of Providers. Entries to
  31   29   * added and removed when cryptographic providers register with
  32   30   * and unregister from the framework, respectively. The KCF scheduler
  33   31   * and ioctl pseudo driver call this function to obtain the list
  34   32   * of available providers.
  35   33   *
  36   34   * The provider table is indexed by crypto_provider_id_t. Each
  37   35   * element of the table contains a pointer to a provider descriptor,
↓ open down ↓ 9 lines elided ↑ open up ↑
  47   45  #include <sys/ddi.h>
  48   46  #include <sys/sunddi.h>
  49   47  #include <sys/ksynch.h>
  50   48  #include <sys/crypto/common.h>
  51   49  #include <sys/crypto/impl.h>
  52   50  #include <sys/crypto/sched_impl.h>
  53   51  #include <sys/crypto/spi.h>
  54   52  
  55   53  #define KCF_MAX_PROVIDERS       512     /* max number of providers */
  56   54  
  57      -static kmutex_t prov_tab_mutex; /* ensure exclusive access to the table */
       55 +/*
       56 + * Prov_tab is an array of providers which is updated when
       57 + * a crypto provider registers with kcf. The provider calls the
       58 + * SPI routine, crypto_register_provider(), which in turn calls
       59 + * kcf_prov_tab_add_provider().
       60 + *
       61 + * A provider unregisters by calling crypto_unregister_provider()
       62 + * which triggers the removal of the prov_tab entry.
       63 + * It also calls kcf_remove_mech_provider().
       64 + *
       65 + * prov_tab entries are not updated from kcf.conf or by cryptoadm(1M).
       66 + */
  58   67  static kcf_provider_desc_t **prov_tab = NULL;
       68 +static kmutex_t prov_tab_mutex; /* ensure exclusive access to the table */
  59   69  static uint_t prov_tab_num = 0; /* number of providers in table */
  60   70  static uint_t prov_tab_max = KCF_MAX_PROVIDERS;
  61   71  
  62   72  #if DEBUG
  63   73  extern int kcf_frmwrk_debug;
  64      -static void kcf_prov_tab_dump(void);
       74 +static void kcf_prov_tab_dump(char *message);
  65   75  #endif /* DEBUG */
  66   76  
       77 +
  67   78  /*
  68      - * Initialize the providers table. The providers table is dynamically
  69      - * allocated with prov_tab_max entries.
       79 + * Initialize a mutex and the KCF providers table, prov_tab.
       80 + * The providers table is dynamically allocated with prov_tab_max entries.
       81 + * Called from kcf module _init().
  70   82   */
  71   83  void
  72   84  kcf_prov_tab_init(void)
  73   85  {
  74   86          mutex_init(&prov_tab_mutex, NULL, MUTEX_DRIVER, NULL);
  75   87  
  76   88          prov_tab = kmem_zalloc(prov_tab_max * sizeof (kcf_provider_desc_t *),
  77   89              KM_SLEEP);
  78   90  }
  79   91  
↓ open down ↓ 37 lines elided ↑ open up ↑
 117  129  
 118  130          /*
 119  131           * The KCF-private provider handle is defined as the internal
 120  132           * provider id.
 121  133           */
 122  134          prov_desc->pd_kcf_prov_handle =
 123  135              (crypto_kcf_provider_handle_t)prov_desc->pd_prov_id;
 124  136  
 125  137  #if DEBUG
 126  138          if (kcf_frmwrk_debug >= 1)
 127      -                kcf_prov_tab_dump();
      139 +                kcf_prov_tab_dump("kcf_prov_tab_add_provider");
 128  140  #endif /* DEBUG */
 129  141  
 130  142          return (CRYPTO_SUCCESS);
 131  143  }
 132  144  
 133  145  /*
 134  146   * Remove the provider specified by its id. A REFRELE is done on the
 135  147   * corresponding provider descriptor before this function returns.
 136  148   * Returns CRYPTO_UNKNOWN_PROVIDER if the provider id is not valid.
 137  149   */
↓ open down ↓ 25 lines elided ↑ open up ↑
 163  175           * reaches zero, kcf_free_provider_desc() will be invoked and
 164  176           * the associated entry in the providers table will be released
 165  177           * at that time.
 166  178           */
 167  179  
 168  180          KCF_PROV_REFRELE(prov_desc);
 169  181          KCF_PROV_IREFRELE(prov_desc);
 170  182  
 171  183  #if DEBUG
 172  184          if (kcf_frmwrk_debug >= 1)
 173      -                kcf_prov_tab_dump();
      185 +                kcf_prov_tab_dump("kcf_prov_tab_rem_provider");
 174  186  #endif /* DEBUG */
 175  187  
 176  188          return (CRYPTO_SUCCESS);
 177  189  }
 178  190  
 179  191  /*
 180  192   * Returns the provider descriptor corresponding to the specified
 181  193   * provider id. A REFHOLD is done on the descriptor before it is
 182  194   * returned to the caller. It is the responsibility of the caller
 183  195   * to do a REFRELE once it is done with the provider descriptor.
↓ open down ↓ 626 lines elided ↑ open up ↑
 810  822          KCF_PROV_REFHOLD(*pd);
 811  823          mutex_exit(&me->me_mutex);
 812  824  
 813  825          if (mep != NULL)
 814  826                  *mep = me;
 815  827  
 816  828          return (CRYPTO_SUCCESS);
 817  829  }
 818  830  
 819  831  #if DEBUG
 820      -
      832 +/*
      833 + * Dump the Kernel crypto providers table, prov_tab.
      834 + * If kcf_frmwrk_debug is >=2, also dump the mechanism lists.
      835 + */
 821  836  static void
 822      -kcf_prov_tab_dump(void)
      837 +kcf_prov_tab_dump(char *message)
 823  838  {
 824      -        uint_t i;
      839 +        uint_t i, j;
 825  840  
 826  841          mutex_enter(&prov_tab_mutex);
      842 +        printf("Providers table prov_tab at %s:\n",
      843 +            message != NULL ? message : "");
 827  844  
 828      -        printf("Providers table:\n");
 829  845          for (i = 0; i < KCF_MAX_PROVIDERS; i++) {
 830      -                if (prov_tab[i] != NULL) {
 831      -                        printf("[%d]: (%s) %s\n",
 832      -                            i, (prov_tab[i]->pd_prov_type ==
 833      -                            CRYPTO_HW_PROVIDER) ? "HW" : "SW",
 834      -                            prov_tab[i]->pd_description);
      846 +                kcf_provider_desc_t *p = prov_tab[i];
      847 +                if (p != NULL) {
      848 +                        printf("[%d]: (%s) %d mechanisms, %s\n", i,
      849 +                            (p->pd_prov_type == CRYPTO_HW_PROVIDER) ?
      850 +                            "HW" : "SW",
      851 +                            p->pd_mech_list_count, p->pd_description);
      852 +                        if (kcf_frmwrk_debug >= 2) {
      853 +                                printf("\tpd_mechanisms: ");
      854 +                                for (j = 0; j < p->pd_mech_list_count; ++j) {
      855 +                                        printf("%s \n",
      856 +                                            p->pd_mechanisms[j].cm_mech_name);
      857 +                                }
      858 +                                printf("\n");
      859 +                        }
 835  860                  }
 836  861          }
 837  862          printf("(end of providers table)\n");
 838  863  
 839  864          mutex_exit(&prov_tab_mutex);
 840  865  }
 841  866  
 842  867  #endif /* DEBUG */
 843  868  
 844  869  /*
↓ open down ↓ 48 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX