xref: /illumos-gate/usr/src/uts/common/crypto/core/kcf.c (revision 717fae56)
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
56a1073f8Skrishna  * Common Development and Distribution License (the "License").
66a1073f8Skrishna  * 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  */
219b009fc1SValerie Bubb Fenwick 
227c478bd9Sstevel@tonic-gate /*
239b009fc1SValerie Bubb Fenwick  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
25*6ea3c060SGarrett D'Amore /*
26*6ea3c060SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
27*6ea3c060SGarrett D'Amore  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Core KCF (Kernel Cryptographic Framework). This file implements
317c478bd9Sstevel@tonic-gate  * the loadable module entry points and module verification routines.
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
387c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
397c478bd9Sstevel@tonic-gate #include <sys/errno.h>
407c478bd9Sstevel@tonic-gate #include <sys/rwlock.h>
417c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
427c478bd9Sstevel@tonic-gate #include <sys/door.h>
437c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <sys/crypto/common.h>
467c478bd9Sstevel@tonic-gate #include <sys/crypto/api.h>
477c478bd9Sstevel@tonic-gate #include <sys/crypto/spi.h>
487c478bd9Sstevel@tonic-gate #include <sys/crypto/impl.h>
497c478bd9Sstevel@tonic-gate #include <sys/crypto/sched_impl.h>
507c478bd9Sstevel@tonic-gate #include <sys/crypto/elfsign.h>
5173556491SAnthony Scarpino #include <sys/crypto/ioctladmin.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #ifdef DEBUG
547c478bd9Sstevel@tonic-gate int kcf_frmwrk_debug = 0;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	KCF_FRMWRK_DEBUG(l, x)	if (kcf_frmwrk_debug >= l) printf x
577c478bd9Sstevel@tonic-gate #else	/* DEBUG */
587c478bd9Sstevel@tonic-gate #define	KCF_FRMWRK_DEBUG(l, x)
597c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = {
62d2b32306Smcpowers 	&mod_miscops, "Kernel Crypto Framework"
637c478bd9Sstevel@tonic-gate };
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
667c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modlmisc, NULL
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
69d3b2efc7SAnthony Scarpino extern int sys_shutdown;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate int
_init()727c478bd9Sstevel@tonic-gate _init()
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	/* initialize the mechanisms tables supported out-of-the-box */
757c478bd9Sstevel@tonic-gate 	kcf_init_mech_tabs();
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	/* initialize the providers tables */
787c478bd9Sstevel@tonic-gate 	kcf_prov_tab_init();
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/* initialize the policy table */
817c478bd9Sstevel@tonic-gate 	kcf_policy_tab_init();
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	/* initialize soft_config_list */
847c478bd9Sstevel@tonic-gate 	kcf_soft_config_init();
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	/*
877c478bd9Sstevel@tonic-gate 	 * Initialize scheduling structures. Note that this does NOT
887c478bd9Sstevel@tonic-gate 	 * start any threads since it might not be safe to do so.
897c478bd9Sstevel@tonic-gate 	 */
907c478bd9Sstevel@tonic-gate 	kcf_sched_init();
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	/* initialize the RNG support structures */
937c478bd9Sstevel@tonic-gate 	kcf_rnd_init();
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)997c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * We do not allow kcf to unload.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate int
_fini(void)1087c478bd9Sstevel@tonic-gate _fini(void)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate 	return (EBUSY);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
11373556491SAnthony Scarpino 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * Return a pointer to the modctl structure of the
1167c478bd9Sstevel@tonic-gate  * provider's module.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate struct modctl *
kcf_get_modctl(crypto_provider_info_t * pinfo)1197c478bd9Sstevel@tonic-gate kcf_get_modctl(crypto_provider_info_t *pinfo)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	struct modctl *mctlp;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	/* Get the modctl struct for this module */
1247c478bd9Sstevel@tonic-gate 	if (pinfo->pi_provider_type == CRYPTO_SW_PROVIDER)
1257c478bd9Sstevel@tonic-gate 		mctlp = mod_getctl(pinfo->pi_provider_dev.pd_sw);
1267c478bd9Sstevel@tonic-gate 	else {
1277c478bd9Sstevel@tonic-gate 		major_t major;
1287c478bd9Sstevel@tonic-gate 		char *drvmod;
1297c478bd9Sstevel@tonic-gate 
13095014fbbSDan OpenSolaris Anderson 		if ((major = ddi_driver_major(pinfo->pi_provider_dev.pd_hw))
13195014fbbSDan OpenSolaris Anderson 		    != DDI_MAJOR_T_NONE) {
1327c478bd9Sstevel@tonic-gate 			drvmod = ddi_major_to_name(major);
1337c478bd9Sstevel@tonic-gate 			mctlp = mod_find_by_filename("drv", drvmod);
1347c478bd9Sstevel@tonic-gate 		} else
1357c478bd9Sstevel@tonic-gate 			return (NULL);
1367c478bd9Sstevel@tonic-gate 	}
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	return (mctlp);
1397c478bd9Sstevel@tonic-gate }
140