Unleashed v1.4
[unleashed.git] / usr / src / uts / common / crypto / core / kcf.c
blob8735e714438489bd2574dcb1498fa39331884263
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
30 * Core KCF (Kernel Cryptographic Framework). This file implements
31 * the loadable module entry points and module verification routines.
34 #include <sys/systm.h>
35 #include <sys/cmn_err.h>
36 #include <sys/ddi.h>
37 #include <sys/sunddi.h>
38 #include <sys/modctl.h>
39 #include <sys/errno.h>
40 #include <sys/rwlock.h>
41 #include <sys/kmem.h>
42 #include <sys/door.h>
43 #include <sys/kobj.h>
45 #include <sys/crypto/common.h>
46 #include <sys/crypto/api.h>
47 #include <sys/crypto/spi.h>
48 #include <sys/crypto/impl.h>
49 #include <sys/crypto/sched_impl.h>
50 #include <sys/crypto/elfsign.h>
51 #include <sys/crypto/ioctladmin.h>
53 #ifdef DEBUG
54 int kcf_frmwrk_debug = 0;
56 #define KCF_FRMWRK_DEBUG(l, x) if (kcf_frmwrk_debug >= l) printf x
57 #else /* DEBUG */
58 #define KCF_FRMWRK_DEBUG(l, x)
59 #endif /* DEBUG */
61 static struct modlmisc modlmisc = {
62 &mod_miscops, "Kernel Crypto Framework"
65 static struct modlinkage modlinkage = {
66 MODREV_1, (void *)&modlmisc, NULL
69 extern int sys_shutdown;
71 int
72 _init()
74 /* initialize the mechanisms tables supported out-of-the-box */
75 kcf_init_mech_tabs();
77 /* initialize the providers tables */
78 kcf_prov_tab_init();
80 /* initialize the policy table */
81 kcf_policy_tab_init();
83 /* initialize soft_config_list */
84 kcf_soft_config_init();
87 * Initialize scheduling structures. Note that this does NOT
88 * start any threads since it might not be safe to do so.
90 kcf_sched_init();
92 /* initialize the RNG support structures */
93 kcf_rnd_init();
95 return (mod_install(&modlinkage));
98 int
99 _info(struct modinfo *modinfop)
101 return (mod_info(&modlinkage, modinfop));
105 * We do not allow kcf to unload.
108 _fini(void)
110 return (EBUSY);
115 * Return a pointer to the modctl structure of the
116 * provider's module.
118 struct modctl *
119 kcf_get_modctl(crypto_provider_info_t *pinfo)
121 struct modctl *mctlp;
123 /* Get the modctl struct for this module */
124 if (pinfo->pi_provider_type == CRYPTO_SW_PROVIDER)
125 mctlp = mod_getctl(pinfo->pi_provider_dev.pd_sw);
126 else {
127 major_t major;
128 char *drvmod;
130 if ((major = ddi_driver_major(pinfo->pi_provider_dev.pd_hw))
131 != DDI_MAJOR_T_NONE) {
132 drvmod = ddi_major_to_name(major);
133 mctlp = mod_find_by_filename("drv", drvmod);
134 } else
135 return (NULL);
138 return (mctlp);