xref: /illumos-gate/usr/src/uts/common/sys/crypto/impl.h (revision 150d2c5288c645a1c1a7d2bee61199a3729406c7)
1 /*
2  * CDDL HEADER START
3  *
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.
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_CRYPTO_IMPL_H
27 #define	_SYS_CRYPTO_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Kernel Cryptographic Framework private implementation definitions.
33  */
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 
38 #ifdef _KERNEL
39 #include <sys/crypto/common.h>
40 #include <sys/crypto/api.h>
41 #include <sys/crypto/spi.h>
42 #include <sys/crypto/ioctl.h>
43 #include <sys/tnf_probe.h>
44 #include <sys/atomic.h>
45 #include <sys/project.h>
46 #include <sys/taskq.h>
47 #include <sys/rctl.h>
48 #endif /* _KERNEL */
49 
50 #ifdef	__cplusplus
51 extern "C" {
52 #endif
53 
54 #ifdef _KERNEL
55 
56 #define	KCF_MODULE "kcf"
57 
58 /*
59  * Prefixes convention: structures internal to the kernel cryptographic
60  * framework start with 'kcf_'. Exposed structure start with 'crypto_'.
61  */
62 
63 /* Provider stats. Not protected. */
64 typedef	struct kcf_prov_stats {
65 	kstat_named_t	ps_ops_total;
66 	kstat_named_t	ps_ops_passed;
67 	kstat_named_t	ps_ops_failed;
68 	kstat_named_t	ps_ops_busy_rval;
69 } kcf_prov_stats_t;
70 
71 /* Various kcf stats. Not protected. */
72 typedef	struct kcf_stats {
73 	kstat_named_t	ks_thrs_in_pool;
74 	kstat_named_t	ks_idle_thrs;
75 	kstat_named_t	ks_minthrs;
76 	kstat_named_t	ks_maxthrs;
77 	kstat_named_t	ks_swq_njobs;
78 	kstat_named_t	ks_swq_maxjobs;
79 	kstat_named_t	ks_taskq_minalloc;
80 	kstat_named_t	ks_taskq_maxalloc;
81 } kcf_stats_t;
82 
83 /*
84  * Keep all the information needed by the scheduler from
85  * this provider.
86  */
87 typedef struct kcf_sched_info {
88 	/* The number of operations dispatched. */
89 	uint64_t	ks_ndispatches;
90 
91 	/* The number of operations that failed. */
92 	uint64_t	ks_nfails;
93 
94 	/* The number of operations that returned CRYPTO_BUSY. */
95 	uint64_t	ks_nbusy_rval;
96 
97 	/* taskq used to dispatch crypto requests */
98 	taskq_t	*ks_taskq;
99 } kcf_sched_info_t;
100 
101 #define	KCF_PROV_INCRSTATS(pd, error)	{				\
102 	(pd)->pd_sched_info.ks_ndispatches++;				\
103 	if (error == CRYPTO_BUSY)					\
104 		(pd)->pd_sched_info.ks_nbusy_rval++;			\
105 	else if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED)	\
106 		(pd)->pd_sched_info.ks_nfails++;			\
107 }
108 
109 
110 /*
111  * The following two macros should be
112  * #define KCF_OPS_CLASSSIZE (KCF_LAST_OPSCLASS - KCF_FIRST_OPSCLASS + 2)
113  * #define KCF_MAXMECHTAB KCF_MAXCIPHER
114  *
115  * However, doing that would involve reorganizing the header file a bit.
116  * When impl.h is broken up (bug# 4703218), this will be done. For now,
117  * we hardcode these values.
118  */
119 #define	KCF_OPS_CLASSSIZE	8
120 #define	KCF_MAXMECHTAB		32
121 
122 /*
123  * Valid values for the state of a provider. The order of
124  * the elements is important.
125  *
126  * Routines which get a provider or the list of providers
127  * should pick only those that are either in KCF_PROV_READY state
128  * or in KCF_PROV_BUSY state.
129  */
130 typedef enum {
131 	KCF_PROV_ALLOCATED = 1,
132 	KCF_PROV_UNVERIFIED,
133 	/*
134 	 * state < KCF_PROV_READY means the provider can not
135 	 * be used at all.
136 	 */
137 	KCF_PROV_READY,
138 	KCF_PROV_BUSY,
139 	/*
140 	 * state > KCF_PROV_BUSY means the provider can not
141 	 * be used for new requests.
142 	 */
143 	KCF_PROV_FAILED,
144 	/*
145 	 * Threads setting the following two states should do so only
146 	 * if the current state < KCF_PROV_DISABLED.
147 	 */
148 	KCF_PROV_DISABLED,
149 	KCF_PROV_REMOVED,
150 	KCF_PROV_FREED
151 } kcf_prov_state_t;
152 
153 #define	KCF_IS_PROV_UNVERIFIED(pd) ((pd)->pd_state == KCF_PROV_UNVERIFIED)
154 #define	KCF_IS_PROV_USABLE(pd) ((pd)->pd_state == KCF_PROV_READY || \
155 	(pd)->pd_state == KCF_PROV_BUSY)
156 #define	KCF_IS_PROV_REMOVED(pd)	((pd)->pd_state >= KCF_PROV_REMOVED)
157 
158 /*
159  * Internal flag set to indicate if a provider is a member of
160  * a logical provider.
161  */
162 #define	KCF_LPROV_MEMBER	0x80000000
163 
164 /*
165  * A provider descriptor structure. There is one such structure per
166  * provider. It is allocated and initialized at registration time and
167  * freed when the provider unregisters.
168  *
169  * pd_prov_type:	Provider type, hardware or software
170  * pd_prov_handle:	Provider handle specified by provider
171  * pd_kcf_prov_handle:	KCF-private handle assigned by KCF
172  * pd_prov_id:		Identification # assigned by KCF to provider
173  * pd_description:	Provider description string
174  * pd_ops_vector:	The ops vector specified by Provider
175  * pd_mech_list_count:	The number of entries in pi_mechanisms, specified
176  *			by the provider during registration
177  * pd_mechanisms:	Mechanisms supported by the provider, specified
178  *			by the provider during registration
179  * pd_map_mechnums:	Lookup table which maps a core framework mechanism
180  *			number to a number understood by this provider
181  * pd_ks_data:		kstat data
182  * pd_kstat:		kstat associated with the provider
183  * pd_sched_info:	Scheduling information associated with the provider
184  * pd_refcnt:		Reference counter to this provider descriptor
185  * pd_irefcnt:		References held by the framework internal structs
186  * pd_name:		Device name or module name
187  * pd_instance:		Device instance
188  * pd_module_id:	Module ID returned by modload
189  * pd_mctlp:		Pointer to modctl structure for this provider
190  * pd_sid:		Session ID of the provider used by kernel clients.
191  *			This is valid only for session-oriented providers.
192  * pd_lock:		lock protects pd_state and pd_real_provider_list
193  * pd_state:		State value of the provider
194  * pd_resume_cv:	cv to wait for state to change from KCF_PROV_BUSY
195  * pd_remove_cv:	cv to wait on while the provider queue drains
196  * pd_restricted:	true if this is an export restricted provider
197  * pd_provider_list:	Used to cross-reference logical providers and their
198  *			members. Not used for software providers.
199  * pd_flags		Could be CRYPTO_HIDE_PROVIDER from pi_flags
200  *			or KCF_LPROV_MEMBER set internally.
201  */
202 typedef struct kcf_provider_desc {
203 	crypto_provider_type_t		pd_prov_type;
204 	crypto_provider_handle_t	pd_prov_handle;
205 	crypto_kcf_provider_handle_t	pd_kcf_prov_handle;
206 	crypto_provider_id_t		pd_prov_id;
207 	char				*pd_description;
208 	crypto_ops_t			*pd_ops_vector;
209 	uint_t				pd_mech_list_count;
210 	crypto_mech_info_t		*pd_mechanisms;
211 	crypto_mech_type_t		pd_map_mechnums[KCF_OPS_CLASSSIZE]\
212 					    [KCF_MAXMECHTAB];
213 	kcf_stats_t			*pd_stats;
214 	kcf_prov_stats_t		pd_ks_data;
215 	kstat_t				*pd_kstat;
216 	kcf_sched_info_t		pd_sched_info;
217 	uint_t				pd_refcnt;
218 	uint_t				pd_irefcnt;
219 	char				*pd_name;
220 	uint_t				pd_instance;
221 	int				pd_module_id;
222 	struct modctl			*pd_mctlp;
223 	crypto_session_id_t		pd_sid;
224 	kmutex_t			pd_lock;
225 	kcf_prov_state_t		pd_state;
226 	kcondvar_t			pd_resume_cv;
227 	kcondvar_t			pd_remove_cv;
228 	boolean_t			pd_restricted;
229 	struct kcf_provider_list	*pd_provider_list;
230 	uint_t				pd_flags;
231 } kcf_provider_desc_t;
232 
233 /* useful for making a list of providers */
234 typedef struct kcf_provider_list {
235 	struct kcf_provider_list *pl_next;
236 	struct kcf_provider_desc *pl_provider;
237 } kcf_provider_list_t;
238 
239 /*
240  * If a component has a reference to a kcf_provider_desc_t,
241  * it REFHOLD()s. A new provider descriptor which is referenced only
242  * by the providers table has a reference counter of one.
243  */
244 #define	KCF_PROV_REFHOLD(desc) {		\
245 	atomic_add_32(&(desc)->pd_refcnt, 1);	\
246 	ASSERT((desc)->pd_refcnt != 0);		\
247 }
248 
249 #define	KCF_PROV_IREFHOLD(desc) {		\
250 	atomic_add_32(&(desc)->pd_irefcnt, 1);	\
251 	ASSERT((desc)->pd_irefcnt != 0);	\
252 }
253 
254 #define	KCF_PROV_IREFRELE(desc) {				\
255 	ASSERT((desc)->pd_irefcnt != 0);			\
256 	membar_exit();						\
257 	if (atomic_add_32_nv(&(desc)->pd_irefcnt, -1) == 0) {	\
258 		cv_broadcast(&(desc)->pd_remove_cv);		\
259 	}							\
260 }
261 
262 #define	KCF_PROV_REFHELD(desc)	((desc)->pd_refcnt >= 1)
263 
264 #define	KCF_PROV_REFRELE(desc) {				\
265 	ASSERT((desc)->pd_refcnt != 0);				\
266 	membar_exit();						\
267 	if (atomic_add_32_nv(&(desc)->pd_refcnt, -1) == 0) {	\
268 		kcf_provider_zero_refcnt((desc));		\
269 	}							\
270 }
271 
272 
273 /* list of crypto_mech_info_t valid as the second mech in a dual operation */
274 
275 typedef	struct crypto_mech_info_list {
276 	struct crypto_mech_info_list	*ml_next;
277 	crypto_mech_type_t		ml_kcf_mechid;	/* KCF's id */
278 	crypto_mech_info_t		ml_mech_info;
279 } crypto_mech_info_list_t;
280 
281 /*
282  * An element in a mechanism provider descriptors chain.
283  * The kcf_prov_mech_desc_t is duplicated in every chain the provider belongs
284  * to. This is a small tradeoff memory vs mutex spinning time to access the
285  * common provider field.
286  */
287 
288 typedef struct kcf_prov_mech_desc {
289 	struct kcf_mech_entry		*pm_me;		/* Back to the head */
290 	struct kcf_prov_mech_desc	*pm_next;	/* Next in the chain */
291 	crypto_mech_info_t		pm_mech_info;	/* Provider mech info */
292 	crypto_mech_info_list_t		*pm_mi_list;	/* list for duals */
293 	kcf_provider_desc_t		*pm_prov_desc;	/* Common desc. */
294 } kcf_prov_mech_desc_t;
295 
296 /* and the notation shortcuts ... */
297 #define	pm_provider_type	pm_prov_desc.pd_provider_type
298 #define	pm_provider_handle	pm_prov_desc.pd_provider_handle
299 #define	pm_ops_vector		pm_prov_desc.pd_ops_vector
300 
301 
302 #define	KCF_CPU_PAD (128 - sizeof (crypto_mech_name_t) - \
303     sizeof (crypto_mech_type_t) - \
304     sizeof (kmutex_t) - 2 * sizeof (kcf_prov_mech_desc_t *) - \
305     sizeof (int) - sizeof (uint32_t) - sizeof (size_t))
306 
307 /*
308  * A mechanism entry in an xxx_mech_tab[]. KCF_CPU_PAD needs
309  * to be adjusted if this structure is changed.
310  */
311 typedef	struct kcf_mech_entry {
312 	crypto_mech_name_t	me_name;	/* mechanism name */
313 	crypto_mech_type_t	me_mechid;	/* Internal id for mechanism */
314 	kmutex_t		me_mutex;	/* access protection	*/
315 	kcf_prov_mech_desc_t	*me_hw_prov_chain;  /* list of HW providers */
316 	kcf_prov_mech_desc_t	*me_sw_prov;    /* SW provider */
317 	/*
318 	 * Number of HW providers in the chain. There is only one
319 	 * SW provider. So, we need only a count of HW providers.
320 	 */
321 	int			me_num_hwprov;
322 	/*
323 	 * When a SW provider is present, this is the generation number that
324 	 * ensures no objects from old SW providers are used in the new one
325 	 */
326 	uint32_t		me_gen_swprov;
327 	/*
328 	 *  threshold for using hardware providers for this mech
329 	 */
330 	size_t			me_threshold;
331 	uint8_t			me_pad[KCF_CPU_PAD];
332 } kcf_mech_entry_t;
333 
334 /*
335  * A policy descriptor structure. It is allocated and initialized
336  * when administrative ioctls load disabled mechanisms.
337  *
338  * pd_prov_type:	Provider type, hardware or software
339  * pd_name:		Device name or module name.
340  * pd_instance:		Device instance.
341  * pd_refcnt:		Reference counter for this policy descriptor
342  * pd_mutex:		Protects array and count of disabled mechanisms.
343  * pd_disabled_count:	Count of disabled mechanisms.
344  * pd_disabled_mechs:	Array of disabled mechanisms.
345  */
346 typedef struct kcf_policy_desc {
347 	crypto_provider_type_t	pd_prov_type;
348 	char			*pd_name;
349 	uint_t			pd_instance;
350 	uint_t			pd_refcnt;
351 	kmutex_t		pd_mutex;
352 	uint_t			pd_disabled_count;
353 	crypto_mech_name_t	*pd_disabled_mechs;
354 } kcf_policy_desc_t;
355 
356 /*
357  * If a component has a reference to a kcf_policy_desc_t,
358  * it REFHOLD()s. A new policy descriptor which is referenced only
359  * by the policy table has a reference count of one.
360  */
361 #define	KCF_POLICY_REFHOLD(desc) {		\
362 	atomic_add_32(&(desc)->pd_refcnt, 1);	\
363 	ASSERT((desc)->pd_refcnt != 0);		\
364 }
365 
366 /*
367  * Releases a reference to a policy descriptor. When the last
368  * reference is released, the descriptor is freed.
369  */
370 #define	KCF_POLICY_REFRELE(desc) {				\
371 	ASSERT((desc)->pd_refcnt != 0);				\
372 	membar_exit();						\
373 	if (atomic_add_32_nv(&(desc)->pd_refcnt, -1) == 0)	\
374 		kcf_policy_free_desc(desc);			\
375 }
376 
377 /*
378  * This entry stores the name of a software module and its
379  * mechanisms.  The mechanisms are 'hints' that are used to
380  * trigger loading of the module.
381  */
382 typedef struct kcf_soft_conf_entry {
383 	struct kcf_soft_conf_entry	*ce_next;
384 	char				*ce_name;
385 	crypto_mech_name_t		*ce_mechs;
386 	uint_t				ce_count;
387 } kcf_soft_conf_entry_t;
388 
389 extern kmutex_t soft_config_mutex;
390 extern kcf_soft_conf_entry_t *soft_config_list;
391 
392 /*
393  * Global tables. The sizes are from the predefined PKCS#11 v2.20 mechanisms,
394  * with a margin of few extra empty entry points
395  */
396 
397 #define	KCF_MAXDIGEST		16	/* Digests */
398 #define	KCF_MAXCIPHER		64	/* Ciphers */
399 #define	KCF_MAXMAC		40	/* Message authentication codes */
400 #define	KCF_MAXSIGN		24	/* Sign/Verify */
401 #define	KCF_MAXKEYOPS		116	/* Key generation and derivation */
402 #define	KCF_MAXMISC		16	/* Others ... */
403 
404 #define	KCF_MAXMECHS		KCF_MAXDIGEST + KCF_MAXCIPHER + KCF_MAXMAC + \
405 				KCF_MAXSIGN + KCF_MAXKEYOPS + \
406 				KCF_MAXMISC
407 
408 extern kcf_mech_entry_t kcf_digest_mechs_tab[];
409 extern kcf_mech_entry_t kcf_cipher_mechs_tab[];
410 extern kcf_mech_entry_t kcf_mac_mechs_tab[];
411 extern kcf_mech_entry_t kcf_sign_mechs_tab[];
412 extern kcf_mech_entry_t kcf_keyops_mechs_tab[];
413 extern kcf_mech_entry_t kcf_misc_mechs_tab[];
414 
415 extern kmutex_t kcf_mech_tabs_lock;
416 
417 typedef	enum {
418 	KCF_DIGEST_CLASS = 1,
419 	KCF_CIPHER_CLASS,
420 	KCF_MAC_CLASS,
421 	KCF_SIGN_CLASS,
422 	KCF_KEYOPS_CLASS,
423 	KCF_MISC_CLASS
424 } kcf_ops_class_t;
425 
426 #define	KCF_FIRST_OPSCLASS	KCF_DIGEST_CLASS
427 #define	KCF_LAST_OPSCLASS	KCF_MISC_CLASS
428 
429 /* The table of all the kcf_xxx_mech_tab[]s, indexed by kcf_ops_class */
430 
431 typedef	struct kcf_mech_entry_tab {
432 	int			met_size;	/* Size of the met_tab[] */
433 	kcf_mech_entry_t	*met_tab;	/* the table		 */
434 } kcf_mech_entry_tab_t;
435 
436 extern kcf_mech_entry_tab_t kcf_mech_tabs_tab[];
437 
438 #define	KCF_MECHID(class, index)				\
439 	(((crypto_mech_type_t)(class) << 32) | (crypto_mech_type_t)(index))
440 
441 #define	KCF_MECH2CLASS(mech_type) ((kcf_ops_class_t)((mech_type) >> 32))
442 
443 #define	KCF_MECH2INDEX(mech_type) ((int)(mech_type))
444 
445 /* ps_refcnt is protected by cm_lock in the crypto_minor structure */
446 typedef struct crypto_provider_session {
447 	struct crypto_provider_session *ps_next;
448 	crypto_session_id_t		ps_session;
449 	kcf_provider_desc_t		*ps_provider;
450 	kcf_provider_desc_t		*ps_real_provider;
451 	uint_t				ps_refcnt;
452 } crypto_provider_session_t;
453 
454 typedef struct crypto_session_data {
455 	kmutex_t			sd_lock;
456 	kcondvar_t			sd_cv;
457 	uint32_t			sd_flags;
458 	crypto_ctx_t			*sd_digest_ctx;
459 	crypto_ctx_t			*sd_encr_ctx;
460 	crypto_ctx_t			*sd_decr_ctx;
461 	crypto_ctx_t			*sd_sign_ctx;
462 	crypto_ctx_t			*sd_verify_ctx;
463 	crypto_ctx_t			*sd_sign_recover_ctx;
464 	crypto_ctx_t			*sd_verify_recover_ctx;
465 	kcf_provider_desc_t		*sd_provider;
466 	void				*sd_find_init_cookie;
467 	crypto_provider_session_t	*sd_provider_session;
468 } crypto_session_data_t;
469 
470 #define	CRYPTO_SESSION_IN_USE		0x00000001
471 #define	CRYPTO_SESSION_IS_BUSY		0x00000002
472 #define	CRYPTO_SESSION_IS_CLOSED	0x00000004
473 
474 #define	KCF_MAX_PIN_LEN			1024
475 
476 /*
477  * Per-minor info.
478  *
479  * cm_lock protects everything in this structure except for cm_refcnt.
480  */
481 typedef struct crypto_minor {
482 	uint_t				cm_refcnt;
483 	kmutex_t			cm_lock;
484 	kcondvar_t			cm_cv;
485 	crypto_session_data_t		**cm_session_table;
486 	uint_t				cm_session_table_count;
487 	kcf_provider_desc_t		**cm_provider_array;
488 	uint_t				cm_provider_count;
489 	crypto_provider_session_t	*cm_provider_session;
490 	kproject_t			*cm_projp;
491 } crypto_minor_t;
492 
493 /* resource control framework handle used by /dev/crypto */
494 extern rctl_hndl_t rc_project_crypto_mem;
495 /*
496  * Return codes for internal functions
497  */
498 #define	KCF_SUCCESS		0x0	/* Successful call */
499 #define	KCF_INVALID_MECH_NUMBER	0x1	/* invalid mechanism number */
500 #define	KCF_INVALID_MECH_NAME	0x2	/* invalid mechanism name */
501 #define	KCF_INVALID_MECH_CLASS	0x3	/* invalid mechanism class */
502 #define	KCF_MECH_TAB_FULL	0x4	/* Need more room in the mech tabs. */
503 
504 /*
505  * kCF internal mechanism and function group for tracking RNG providers.
506  */
507 #define	SUN_RANDOM		"random"
508 #define	CRYPTO_FG_RANDOM	0x80000000	/* generate_random() */
509 
510 /*
511  * Wrappers for ops vectors. In the wrapper definitions below, the pd
512  * argument always corresponds to a pointer to a provider descriptor
513  * of type kcf_prov_desc_t.
514  */
515 
516 #define	KCF_PROV_CONTROL_OPS(pd)	((pd)->pd_ops_vector->co_control_ops)
517 #define	KCF_PROV_CTX_OPS(pd)		((pd)->pd_ops_vector->co_ctx_ops)
518 #define	KCF_PROV_DIGEST_OPS(pd)		((pd)->pd_ops_vector->co_digest_ops)
519 #define	KCF_PROV_CIPHER_OPS(pd)		((pd)->pd_ops_vector->co_cipher_ops)
520 #define	KCF_PROV_MAC_OPS(pd)		((pd)->pd_ops_vector->co_mac_ops)
521 #define	KCF_PROV_SIGN_OPS(pd)		((pd)->pd_ops_vector->co_sign_ops)
522 #define	KCF_PROV_VERIFY_OPS(pd)		((pd)->pd_ops_vector->co_verify_ops)
523 #define	KCF_PROV_DUAL_OPS(pd)		((pd)->pd_ops_vector->co_dual_ops)
524 #define	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) \
525 	((pd)->pd_ops_vector->co_dual_cipher_mac_ops)
526 #define	KCF_PROV_RANDOM_OPS(pd)		((pd)->pd_ops_vector->co_random_ops)
527 #define	KCF_PROV_SESSION_OPS(pd)	((pd)->pd_ops_vector->co_session_ops)
528 #define	KCF_PROV_OBJECT_OPS(pd)		((pd)->pd_ops_vector->co_object_ops)
529 #define	KCF_PROV_KEY_OPS(pd)		((pd)->pd_ops_vector->co_key_ops)
530 #define	KCF_PROV_PROVIDER_OPS(pd)	((pd)->pd_ops_vector->co_provider_ops)
531 #define	KCF_PROV_MECH_OPS(pd)		((pd)->pd_ops_vector->co_mech_ops)
532 
533 /*
534  * Wrappers for crypto_control_ops(9S) entry points.
535  */
536 
537 #define	KCF_PROV_STATUS(pd, status) ( \
538 	(KCF_PROV_CONTROL_OPS(pd) && \
539 	KCF_PROV_CONTROL_OPS(pd)->provider_status) ? \
540 	KCF_PROV_CONTROL_OPS(pd)->provider_status( \
541 	    (pd)->pd_prov_handle, status) : \
542 	CRYPTO_NOT_SUPPORTED)
543 
544 /*
545  * Wrappers for crypto_ctx_ops(9S) entry points.
546  */
547 
548 #define	KCF_PROV_CREATE_CTX_TEMPLATE(pd, mech, key, template, size, req) ( \
549 	(KCF_PROV_CTX_OPS(pd) && KCF_PROV_CTX_OPS(pd)->create_ctx_template) ? \
550 	KCF_PROV_CTX_OPS(pd)->create_ctx_template( \
551 	    (pd)->pd_prov_handle, mech, key, template, size, req) : \
552 	CRYPTO_NOT_SUPPORTED)
553 
554 #define	KCF_PROV_FREE_CONTEXT(pd, ctx) ( \
555 	(KCF_PROV_CTX_OPS(pd) && KCF_PROV_CTX_OPS(pd)->free_context) ? \
556 	KCF_PROV_CTX_OPS(pd)->free_context(ctx) : CRYPTO_NOT_SUPPORTED)
557 
558 #define	KCF_PROV_COPYIN_MECH(pd, umech, kmech, errorp, mode) ( \
559 	(KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->copyin_mechanism) ? \
560 	KCF_PROV_MECH_OPS(pd)->copyin_mechanism( \
561 	    (pd)->pd_prov_handle, umech, kmech, errorp, mode) : \
562 	CRYPTO_NOT_SUPPORTED)
563 
564 #define	KCF_PROV_COPYOUT_MECH(pd, kmech, umech, errorp, mode) ( \
565 	(KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->copyout_mechanism) ? \
566 	KCF_PROV_MECH_OPS(pd)->copyout_mechanism( \
567 	    (pd)->pd_prov_handle, kmech, umech, errorp, mode) : \
568 	CRYPTO_NOT_SUPPORTED)
569 
570 #define	KCF_PROV_FREE_MECH(pd, prov_mech) ( \
571 	(KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->free_mechanism) ? \
572 	KCF_PROV_MECH_OPS(pd)->free_mechanism( \
573 	    (pd)->pd_prov_handle, prov_mech) : CRYPTO_NOT_SUPPORTED)
574 
575 /*
576  * Wrappers for crypto_digest_ops(9S) entry points.
577  */
578 
579 #define	KCF_PROV_DIGEST_INIT(pd, ctx, mech, req) ( \
580 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_init) ? \
581 	KCF_PROV_DIGEST_OPS(pd)->digest_init(ctx, mech, req) : \
582 	CRYPTO_NOT_SUPPORTED)
583 
584 /*
585  * The _ (underscore) in _digest is needed to avoid replacing the
586  * function digest().
587  */
588 #define	KCF_PROV_DIGEST(pd, ctx, data, _digest, req) ( \
589 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest) ? \
590 	KCF_PROV_DIGEST_OPS(pd)->digest(ctx, data, _digest, req) : \
591 	CRYPTO_NOT_SUPPORTED)
592 
593 #define	KCF_PROV_DIGEST_UPDATE(pd, ctx, data, req) ( \
594 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_update) ? \
595 	KCF_PROV_DIGEST_OPS(pd)->digest_update(ctx, data, req) : \
596 	CRYPTO_NOT_SUPPORTED)
597 
598 #define	KCF_PROV_DIGEST_KEY(pd, ctx, key, req) ( \
599 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_key) ? \
600 	KCF_PROV_DIGEST_OPS(pd)->digest_key(ctx, key, req) : \
601 	CRYPTO_NOT_SUPPORTED)
602 
603 #define	KCF_PROV_DIGEST_FINAL(pd, ctx, digest, req) ( \
604 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_final) ? \
605 	KCF_PROV_DIGEST_OPS(pd)->digest_final(ctx, digest, req) : \
606 	CRYPTO_NOT_SUPPORTED)
607 
608 #define	KCF_PROV_DIGEST_ATOMIC(pd, session, mech, data, digest, req) ( \
609 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_atomic) ? \
610 	KCF_PROV_DIGEST_OPS(pd)->digest_atomic( \
611 	    (pd)->pd_prov_handle, session, mech, data, digest, req) : \
612 	CRYPTO_NOT_SUPPORTED)
613 
614 /*
615  * Wrappers for crypto_cipher_ops(9S) entry points.
616  */
617 
618 #define	KCF_PROV_ENCRYPT_INIT(pd, ctx, mech, key, template, req) ( \
619 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_init) ? \
620 	KCF_PROV_CIPHER_OPS(pd)->encrypt_init(ctx, mech, key, template, \
621 	    req) : \
622 	CRYPTO_NOT_SUPPORTED)
623 
624 #define	KCF_PROV_ENCRYPT(pd, ctx, plaintext, ciphertext, req) ( \
625 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt) ? \
626 	KCF_PROV_CIPHER_OPS(pd)->encrypt(ctx, plaintext, ciphertext, req) : \
627 	CRYPTO_NOT_SUPPORTED)
628 
629 #define	KCF_PROV_ENCRYPT_UPDATE(pd, ctx, plaintext, ciphertext, req) ( \
630 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_update) ? \
631 	KCF_PROV_CIPHER_OPS(pd)->encrypt_update(ctx, plaintext, \
632 	    ciphertext, req) : \
633 	CRYPTO_NOT_SUPPORTED)
634 
635 #define	KCF_PROV_ENCRYPT_FINAL(pd, ctx, ciphertext, req) ( \
636 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_final) ? \
637 	KCF_PROV_CIPHER_OPS(pd)->encrypt_final(ctx, ciphertext, req) : \
638 	CRYPTO_NOT_SUPPORTED)
639 
640 #define	KCF_PROV_ENCRYPT_ATOMIC(pd, session, mech, key, plaintext, ciphertext, \
641 	    template, req) ( \
642 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_atomic) ? \
643 	KCF_PROV_CIPHER_OPS(pd)->encrypt_atomic( \
644 	    (pd)->pd_prov_handle, session, mech, key, plaintext, ciphertext, \
645 	    template, req) : \
646 	CRYPTO_NOT_SUPPORTED)
647 
648 #define	KCF_PROV_DECRYPT_INIT(pd, ctx, mech, key, template, req) ( \
649 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_init) ? \
650 	KCF_PROV_CIPHER_OPS(pd)->decrypt_init(ctx, mech, key, template, \
651 	    req) : \
652 	CRYPTO_NOT_SUPPORTED)
653 
654 #define	KCF_PROV_DECRYPT(pd, ctx, ciphertext, plaintext, req) ( \
655 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt) ? \
656 	KCF_PROV_CIPHER_OPS(pd)->decrypt(ctx, ciphertext, plaintext, req) : \
657 	CRYPTO_NOT_SUPPORTED)
658 
659 #define	KCF_PROV_DECRYPT_UPDATE(pd, ctx, ciphertext, plaintext, req) ( \
660 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_update) ? \
661 	KCF_PROV_CIPHER_OPS(pd)->decrypt_update(ctx, ciphertext, \
662 	    plaintext, req) : \
663 	CRYPTO_NOT_SUPPORTED)
664 
665 #define	KCF_PROV_DECRYPT_FINAL(pd, ctx, plaintext, req) ( \
666 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_final) ? \
667 	KCF_PROV_CIPHER_OPS(pd)->decrypt_final(ctx, plaintext, req) : \
668 	CRYPTO_NOT_SUPPORTED)
669 
670 #define	KCF_PROV_DECRYPT_ATOMIC(pd, session, mech, key, ciphertext, plaintext, \
671 	    template, req) ( \
672 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_atomic) ? \
673 	KCF_PROV_CIPHER_OPS(pd)->decrypt_atomic( \
674 	    (pd)->pd_prov_handle, session, mech, key, ciphertext, plaintext, \
675 	    template, req) : \
676 	CRYPTO_NOT_SUPPORTED)
677 
678 /*
679  * Wrappers for crypto_mac_ops(9S) entry points.
680  */
681 
682 #define	KCF_PROV_MAC_INIT(pd, ctx, mech, key, template, req) ( \
683 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_init) ? \
684 	KCF_PROV_MAC_OPS(pd)->mac_init(ctx, mech, key, template, req) \
685 	: CRYPTO_NOT_SUPPORTED)
686 
687 /*
688  * The _ (underscore) in _mac is needed to avoid replacing the
689  * function mac().
690  */
691 #define	KCF_PROV_MAC(pd, ctx, data, _mac, req) ( \
692 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac) ? \
693 	KCF_PROV_MAC_OPS(pd)->mac(ctx, data, _mac, req) : \
694 	CRYPTO_NOT_SUPPORTED)
695 
696 #define	KCF_PROV_MAC_UPDATE(pd, ctx, data, req) ( \
697 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_update) ? \
698 	KCF_PROV_MAC_OPS(pd)->mac_update(ctx, data, req) : \
699 	CRYPTO_NOT_SUPPORTED)
700 
701 #define	KCF_PROV_MAC_FINAL(pd, ctx, mac, req) ( \
702 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_final) ? \
703 	KCF_PROV_MAC_OPS(pd)->mac_final(ctx, mac, req) : \
704 	CRYPTO_NOT_SUPPORTED)
705 
706 #define	KCF_PROV_MAC_ATOMIC(pd, session, mech, key, data, mac, template, \
707 	    req) ( \
708 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_atomic) ? \
709 	KCF_PROV_MAC_OPS(pd)->mac_atomic( \
710 	    (pd)->pd_prov_handle, session, mech, key, data, mac, template, \
711 	    req) : \
712 	CRYPTO_NOT_SUPPORTED)
713 
714 #define	KCF_PROV_MAC_VERIFY_ATOMIC(pd, session, mech, key, data, mac, \
715 	    template, req) ( \
716 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_verify_atomic) ? \
717 	KCF_PROV_MAC_OPS(pd)->mac_verify_atomic( \
718 	    (pd)->pd_prov_handle, session, mech, key, data, mac, template, \
719 	    req) : \
720 	CRYPTO_NOT_SUPPORTED)
721 
722 /*
723  * Wrappers for crypto_sign_ops(9S) entry points.
724  */
725 
726 #define	KCF_PROV_SIGN_INIT(pd, ctx, mech, key, template, req) ( \
727 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_init) ? \
728 	KCF_PROV_SIGN_OPS(pd)->sign_init( \
729 	    ctx, mech, key, template, req) : CRYPTO_NOT_SUPPORTED)
730 
731 #define	KCF_PROV_SIGN(pd, ctx, data, sig, req) ( \
732 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign) ? \
733 	KCF_PROV_SIGN_OPS(pd)->sign(ctx, data, sig, req) : \
734 	CRYPTO_NOT_SUPPORTED)
735 
736 #define	KCF_PROV_SIGN_UPDATE(pd, ctx, data, req) ( \
737 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_update) ? \
738 	KCF_PROV_SIGN_OPS(pd)->sign_update(ctx, data, req) : \
739 	CRYPTO_NOT_SUPPORTED)
740 
741 #define	KCF_PROV_SIGN_FINAL(pd, ctx, sig, req) ( \
742 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_final) ? \
743 	KCF_PROV_SIGN_OPS(pd)->sign_final(ctx, sig, req) : \
744 	CRYPTO_NOT_SUPPORTED)
745 
746 #define	KCF_PROV_SIGN_ATOMIC(pd, session, mech, key, data, template, \
747 	    sig, req) ( \
748 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_atomic) ? \
749 	KCF_PROV_SIGN_OPS(pd)->sign_atomic( \
750 	    (pd)->pd_prov_handle, session, mech, key, data, sig, template, \
751 	    req) : CRYPTO_NOT_SUPPORTED)
752 
753 #define	KCF_PROV_SIGN_RECOVER_INIT(pd, ctx, mech, key, template, \
754 	    req) ( \
755 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_recover_init) ? \
756 	KCF_PROV_SIGN_OPS(pd)->sign_recover_init(ctx, mech, key, template, \
757 	    req) : CRYPTO_NOT_SUPPORTED)
758 
759 #define	KCF_PROV_SIGN_RECOVER(pd, ctx, data, sig, req) ( \
760 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_recover) ? \
761 	KCF_PROV_SIGN_OPS(pd)->sign_recover(ctx, data, sig, req) : \
762 	CRYPTO_NOT_SUPPORTED)
763 
764 #define	KCF_PROV_SIGN_RECOVER_ATOMIC(pd, session, mech, key, data, template, \
765 	    sig, req) ( \
766 	(KCF_PROV_SIGN_OPS(pd) && \
767 	KCF_PROV_SIGN_OPS(pd)->sign_recover_atomic) ? \
768 	KCF_PROV_SIGN_OPS(pd)->sign_recover_atomic( \
769 	    (pd)->pd_prov_handle, session, mech, key, data, sig, template, \
770 	    req) : CRYPTO_NOT_SUPPORTED)
771 
772 /*
773  * Wrappers for crypto_verify_ops(9S) entry points.
774  */
775 
776 #define	KCF_PROV_VERIFY_INIT(pd, ctx, mech, key, template, req) ( \
777 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_init) ? \
778 	KCF_PROV_VERIFY_OPS(pd)->verify_init(ctx, mech, key, template, \
779 	    req) : CRYPTO_NOT_SUPPORTED)
780 
781 #define	KCF_PROV_VERIFY(pd, ctx, data, sig, req) ( \
782 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify) ? \
783 	KCF_PROV_VERIFY_OPS(pd)->verify(ctx, data, sig, req) : \
784 	CRYPTO_NOT_SUPPORTED)
785 
786 #define	KCF_PROV_VERIFY_UPDATE(pd, ctx, data, req) ( \
787 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_update) ? \
788 	KCF_PROV_VERIFY_OPS(pd)->verify_update(ctx, data, req) : \
789 	CRYPTO_NOT_SUPPORTED)
790 
791 #define	KCF_PROV_VERIFY_FINAL(pd, ctx, sig, req) ( \
792 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_final) ? \
793 	KCF_PROV_VERIFY_OPS(pd)->verify_final(ctx, sig, req) : \
794 	CRYPTO_NOT_SUPPORTED)
795 
796 #define	KCF_PROV_VERIFY_ATOMIC(pd, session, mech, key, data, template, sig, \
797 	    req) ( \
798 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_atomic) ? \
799 	KCF_PROV_VERIFY_OPS(pd)->verify_atomic( \
800 	    (pd)->pd_prov_handle, session, mech, key, data, sig, template, \
801 	    req) : CRYPTO_NOT_SUPPORTED)
802 
803 #define	KCF_PROV_VERIFY_RECOVER_INIT(pd, ctx, mech, key, template, \
804 	    req) ( \
805 	(KCF_PROV_VERIFY_OPS(pd) && \
806 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_init) ? \
807 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_init(ctx, mech, key, \
808 	    template, req) : CRYPTO_NOT_SUPPORTED)
809 
810 /* verify_recover() CSPI routine has different argument order than verify() */
811 #define	KCF_PROV_VERIFY_RECOVER(pd, ctx, sig, data, req) ( \
812 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_recover) ? \
813 	KCF_PROV_VERIFY_OPS(pd)->verify_recover(ctx, sig, data, req) : \
814 	CRYPTO_NOT_SUPPORTED)
815 
816 /*
817  * verify_recover_atomic() CSPI routine has different argument order
818  * than verify_atomic().
819  */
820 #define	KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, session, mech, key, sig, \
821 	    template, data,  req) ( \
822 	(KCF_PROV_VERIFY_OPS(pd) && \
823 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_atomic) ? \
824 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_atomic( \
825 	    (pd)->pd_prov_handle, session, mech, key, sig, data, template, \
826 	    req) : CRYPTO_NOT_SUPPORTED)
827 
828 /*
829  * Wrappers for crypto_dual_ops(9S) entry points.
830  */
831 
832 #define	KCF_PROV_DIGEST_ENCRYPT_UPDATE(digest_ctx, encrypt_ctx, plaintext, \
833 	    ciphertext, req) ( \
834 	(KCF_PROV_DUAL_OPS(pd) && \
835 	KCF_PROV_DUAL_OPS(pd)->digest_encrypt_update) ? \
836 	KCF_PROV_DUAL_OPS(pd)->digest_encrypt_update( \
837 	    digest_ctx, encrypt_ctx, plaintext, ciphertext, req) : \
838 	CRYPTO_NOT_SUPPORTED)
839 
840 #define	KCF_PROV_DECRYPT_DIGEST_UPDATE(decrypt_ctx, digest_ctx, ciphertext, \
841 	    plaintext, req) ( \
842 	(KCF_PROV_DUAL_OPS(pd) && \
843 	KCF_PROV_DUAL_OPS(pd)->decrypt_digest_update) ? \
844 	KCF_PROV_DUAL_OPS(pd)->decrypt_digest_update( \
845 	    decrypt_ctx, digest_ctx, ciphertext, plaintext, req) : \
846 	CRYPTO_NOT_SUPPORTED)
847 
848 #define	KCF_PROV_SIGN_ENCRYPT_UPDATE(sign_ctx, encrypt_ctx, plaintext, \
849 	    ciphertext, req) ( \
850 	(KCF_PROV_DUAL_OPS(pd) && \
851 	KCF_PROV_DUAL_OPS(pd)->sign_encrypt_update) ? \
852 	KCF_PROV_DUAL_OPS(pd)->sign_encrypt_update( \
853 	    sign_ctx, encrypt_ctx, plaintext, ciphertext, req) : \
854 	CRYPTO_NOT_SUPPORTED)
855 
856 #define	KCF_PROV_DECRYPT_VERIFY_UPDATE(decrypt_ctx, verify_ctx, ciphertext, \
857 	    plaintext, req) ( \
858 	(KCF_PROV_DUAL_OPS(pd) && \
859 	KCF_PROV_DUAL_OPS(pd)->decrypt_verify_update) ? \
860 	KCF_PROV_DUAL_OPS(pd)->decrypt_verify_update( \
861 	    decrypt_ctx, verify_ctx, ciphertext, plaintext, req) : \
862 	CRYPTO_NOT_SUPPORTED)
863 
864 /*
865  * Wrappers for crypto_dual_cipher_mac_ops(9S) entry points.
866  */
867 
868 #define	KCF_PROV_ENCRYPT_MAC_INIT(pd, ctx, encr_mech, encr_key, mac_mech, \
869 	    mac_key, encr_ctx_template, mac_ctx_template, req) ( \
870 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
871 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_init) ? \
872 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_init( \
873 	    ctx, encr_mech, encr_key, mac_mech, mac_key, encr_ctx_template, \
874 	    mac_ctx_template, req) : \
875 	CRYPTO_NOT_SUPPORTED)
876 
877 #define	KCF_PROV_ENCRYPT_MAC(pd, ctx, plaintext, ciphertext, mac, req) ( \
878 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
879 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac) ? \
880 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac( \
881 	    ctx, plaintext, ciphertext, mac, req) : \
882 	CRYPTO_NOT_SUPPORTED)
883 
884 #define	KCF_PROV_ENCRYPT_MAC_UPDATE(pd, ctx, plaintext, ciphertext, req) ( \
885 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
886 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_update) ? \
887 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_update( \
888 	    ctx, plaintext, ciphertext, req) : \
889 	CRYPTO_NOT_SUPPORTED)
890 
891 #define	KCF_PROV_ENCRYPT_MAC_FINAL(pd, ctx, ciphertext, mac, req) ( \
892 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
893 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_final) ? \
894 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_final( \
895 	    ctx, ciphertext, mac, req) : \
896 	CRYPTO_NOT_SUPPORTED)
897 
898 #define	KCF_PROV_ENCRYPT_MAC_ATOMIC(pd, session, encr_mech, encr_key, \
899 	    mac_mech, mac_key, plaintext, ciphertext, mac, \
900 	    encr_ctx_template, mac_ctx_template, req) ( \
901 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
902 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_atomic) ? \
903 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_atomic( \
904 	    (pd)->pd_prov_handle, session, encr_mech, encr_key, \
905 	    mac_mech, mac_key, plaintext, ciphertext, mac, \
906 	    encr_ctx_template, mac_ctx_template, req) : \
907 	CRYPTO_NOT_SUPPORTED)
908 
909 #define	KCF_PROV_MAC_DECRYPT_INIT(pd, ctx, mac_mech, mac_key, decr_mech, \
910 	    decr_key, mac_ctx_template, decr_ctx_template, req) ( \
911 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
912 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_init) ? \
913 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_init( \
914 	    ctx, mac_mech, mac_key, decr_mech, decr_key, mac_ctx_template, \
915 	    decr_ctx_template, req) : \
916 	CRYPTO_NOT_SUPPORTED)
917 
918 #define	KCF_PROV_MAC_DECRYPT(pd, ctx, ciphertext, mac, plaintext, req) ( \
919 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
920 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt) ? \
921 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt( \
922 	    ctx, ciphertext, mac, plaintext, req) : \
923 	CRYPTO_NOT_SUPPORTED)
924 
925 #define	KCF_PROV_MAC_DECRYPT_UPDATE(pd, ctx, ciphertext, plaintext, req) ( \
926 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
927 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_update) ? \
928 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_update( \
929 	    ctx, ciphertext, plaintext, req) : \
930 	CRYPTO_NOT_SUPPORTED)
931 
932 #define	KCF_PROV_MAC_DECRYPT_FINAL(pd, ctx, mac, plaintext, req) ( \
933 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
934 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_final) ? \
935 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_final( \
936 	    ctx, mac, plaintext, req) : \
937 	CRYPTO_NOT_SUPPORTED)
938 
939 #define	KCF_PROV_MAC_DECRYPT_ATOMIC(pd, session, mac_mech, mac_key, \
940 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
941 	    mac_ctx_template, decr_ctx_template, req) ( \
942 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
943 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_atomic) ? \
944 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_atomic( \
945 	    (pd)->pd_prov_handle, session, mac_mech, mac_key, \
946 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
947 	    mac_ctx_template, decr_ctx_template, req) : \
948 	CRYPTO_NOT_SUPPORTED)
949 
950 #define	KCF_PROV_MAC_VERIFY_DECRYPT_ATOMIC(pd, session, mac_mech, mac_key, \
951 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
952 	    mac_ctx_template, decr_ctx_template, req) ( \
953 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
954 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_verify_decrypt_atomic \
955 	    != NULL) ? \
956 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_verify_decrypt_atomic( \
957 	    (pd)->pd_prov_handle, session, mac_mech, mac_key, \
958 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
959 	    mac_ctx_template, decr_ctx_template, req) : \
960 	CRYPTO_NOT_SUPPORTED)
961 
962 /*
963  * Wrappers for crypto_random_number_ops(9S) entry points.
964  */
965 
966 #define	KCF_PROV_SEED_RANDOM(pd, session, buf, len, est, flags, req) ( \
967 	(KCF_PROV_RANDOM_OPS(pd) && KCF_PROV_RANDOM_OPS(pd)->seed_random) ? \
968 	KCF_PROV_RANDOM_OPS(pd)->seed_random((pd)->pd_prov_handle, \
969 	    session, buf, len, est, flags, req) : CRYPTO_NOT_SUPPORTED)
970 
971 #define	KCF_PROV_GENERATE_RANDOM(pd, session, buf, len, req) ( \
972 	(KCF_PROV_RANDOM_OPS(pd) && \
973 	KCF_PROV_RANDOM_OPS(pd)->generate_random) ? \
974 	KCF_PROV_RANDOM_OPS(pd)->generate_random((pd)->pd_prov_handle, \
975 	    session, buf, len, req) : CRYPTO_NOT_SUPPORTED)
976 
977 /*
978  * Wrappers for crypto_session_ops(9S) entry points.
979  *
980  * ops_pd is the provider descriptor that supplies the ops_vector.
981  * pd is the descriptor that supplies the provider handle.
982  * Only session open/close needs two handles.
983  */
984 
985 #define	KCF_PROV_SESSION_OPEN(ops_pd, session, req, pd) ( \
986 	(KCF_PROV_SESSION_OPS(ops_pd) && \
987 	KCF_PROV_SESSION_OPS(ops_pd)->session_open) ? \
988 	KCF_PROV_SESSION_OPS(ops_pd)->session_open((pd)->pd_prov_handle, \
989 	    session, req) : CRYPTO_NOT_SUPPORTED)
990 
991 #define	KCF_PROV_SESSION_CLOSE(ops_pd, session, req, pd) ( \
992 	(KCF_PROV_SESSION_OPS(ops_pd) && \
993 	KCF_PROV_SESSION_OPS(ops_pd)->session_close) ? \
994 	KCF_PROV_SESSION_OPS(ops_pd)->session_close((pd)->pd_prov_handle, \
995 	    session, req) : CRYPTO_NOT_SUPPORTED)
996 
997 #define	KCF_PROV_SESSION_LOGIN(pd, session, user_type, pin, len, req) ( \
998 	(KCF_PROV_SESSION_OPS(pd) && \
999 	KCF_PROV_SESSION_OPS(pd)->session_login) ? \
1000 	KCF_PROV_SESSION_OPS(pd)->session_login((pd)->pd_prov_handle, \
1001 	    session, user_type, pin, len, req) : CRYPTO_NOT_SUPPORTED)
1002 
1003 #define	KCF_PROV_SESSION_LOGOUT(pd, session, req) ( \
1004 	(KCF_PROV_SESSION_OPS(pd) && \
1005 	KCF_PROV_SESSION_OPS(pd)->session_logout) ? \
1006 	KCF_PROV_SESSION_OPS(pd)->session_logout((pd)->pd_prov_handle, \
1007 	    session, req) : CRYPTO_NOT_SUPPORTED)
1008 
1009 /*
1010  * Wrappers for crypto_object_ops(9S) entry points.
1011  */
1012 
1013 #define	KCF_PROV_OBJECT_CREATE(pd, session, template, count, object, req) ( \
1014 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_create) ? \
1015 	KCF_PROV_OBJECT_OPS(pd)->object_create((pd)->pd_prov_handle, \
1016 	    session, template, count, object, req) : CRYPTO_NOT_SUPPORTED)
1017 
1018 #define	KCF_PROV_OBJECT_COPY(pd, session, object, template, count, \
1019 	    new_object, req) ( \
1020 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_copy) ? \
1021 	KCF_PROV_OBJECT_OPS(pd)->object_copy((pd)->pd_prov_handle, \
1022 	session, object, template, count, new_object, req) : \
1023 	    CRYPTO_NOT_SUPPORTED)
1024 
1025 #define	KCF_PROV_OBJECT_DESTROY(pd, session, object, req) ( \
1026 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_destroy) ? \
1027 	KCF_PROV_OBJECT_OPS(pd)->object_destroy((pd)->pd_prov_handle, \
1028 	    session, object, req) : CRYPTO_NOT_SUPPORTED)
1029 
1030 #define	KCF_PROV_OBJECT_GET_SIZE(pd, session, object, size, req) ( \
1031 	(KCF_PROV_OBJECT_OPS(pd) && \
1032 	KCF_PROV_OBJECT_OPS(pd)->object_get_size) ? \
1033 	KCF_PROV_OBJECT_OPS(pd)->object_get_size((pd)->pd_prov_handle, \
1034 	    session, object, size, req) : CRYPTO_NOT_SUPPORTED)
1035 
1036 #define	KCF_PROV_OBJECT_GET_ATTRIBUTE_VALUE(pd, session, object, template, \
1037 	    count, req) ( \
1038 	(KCF_PROV_OBJECT_OPS(pd) && \
1039 	KCF_PROV_OBJECT_OPS(pd)->object_get_attribute_value) ? \
1040 	KCF_PROV_OBJECT_OPS(pd)->object_get_attribute_value( \
1041 	(pd)->pd_prov_handle, session, object, template, count, req) : \
1042 	    CRYPTO_NOT_SUPPORTED)
1043 
1044 #define	KCF_PROV_OBJECT_SET_ATTRIBUTE_VALUE(pd, session, object, template, \
1045 	    count, req) ( \
1046 	(KCF_PROV_OBJECT_OPS(pd) && \
1047 	KCF_PROV_OBJECT_OPS(pd)->object_set_attribute_value) ? \
1048 	KCF_PROV_OBJECT_OPS(pd)->object_set_attribute_value( \
1049 	(pd)->pd_prov_handle, session, object, template, count, req) : \
1050 	    CRYPTO_NOT_SUPPORTED)
1051 
1052 #define	KCF_PROV_OBJECT_FIND_INIT(pd, session, template, count, ppriv, \
1053 	    req) ( \
1054 	(KCF_PROV_OBJECT_OPS(pd) && \
1055 	KCF_PROV_OBJECT_OPS(pd)->object_find_init) ? \
1056 	KCF_PROV_OBJECT_OPS(pd)->object_find_init((pd)->pd_prov_handle, \
1057 	session, template, count, ppriv, req) : CRYPTO_NOT_SUPPORTED)
1058 
1059 #define	KCF_PROV_OBJECT_FIND(pd, ppriv, objects, max_objects, object_count, \
1060 	    req) ( \
1061 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_find) ? \
1062 	KCF_PROV_OBJECT_OPS(pd)->object_find( \
1063 	(pd)->pd_prov_handle, ppriv, objects, max_objects, object_count, \
1064 	req) : CRYPTO_NOT_SUPPORTED)
1065 
1066 #define	KCF_PROV_OBJECT_FIND_FINAL(pd, ppriv, req) ( \
1067 	(KCF_PROV_OBJECT_OPS(pd) && \
1068 	KCF_PROV_OBJECT_OPS(pd)->object_find_final) ? \
1069 	KCF_PROV_OBJECT_OPS(pd)->object_find_final( \
1070 	    (pd)->pd_prov_handle, ppriv, req) : CRYPTO_NOT_SUPPORTED)
1071 
1072 /*
1073  * Wrappers for crypto_key_ops(9S) entry points.
1074  */
1075 
1076 #define	KCF_PROV_KEY_GENERATE(pd, session, mech, template, count, object, \
1077 	    req) ( \
1078 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_generate) ? \
1079 	KCF_PROV_KEY_OPS(pd)->key_generate((pd)->pd_prov_handle, \
1080 	    session, mech, template, count, object, req) : \
1081 	CRYPTO_NOT_SUPPORTED)
1082 
1083 #define	KCF_PROV_KEY_GENERATE_PAIR(pd, session, mech, pub_template, \
1084 	    pub_count, priv_template, priv_count, pub_key, priv_key, req) ( \
1085 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_generate_pair) ? \
1086 	KCF_PROV_KEY_OPS(pd)->key_generate_pair((pd)->pd_prov_handle, \
1087 	    session, mech, pub_template, pub_count, priv_template, \
1088 	    priv_count, pub_key, priv_key, req) : \
1089 	CRYPTO_NOT_SUPPORTED)
1090 
1091 #define	KCF_PROV_KEY_WRAP(pd, session, mech, wrapping_key, key, wrapped_key, \
1092 	    wrapped_key_len, req) ( \
1093 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_wrap) ? \
1094 	KCF_PROV_KEY_OPS(pd)->key_wrap((pd)->pd_prov_handle, \
1095 	    session, mech, wrapping_key, key, wrapped_key, wrapped_key_len, \
1096 	    req) : \
1097 	CRYPTO_NOT_SUPPORTED)
1098 
1099 #define	KCF_PROV_KEY_UNWRAP(pd, session, mech, unwrapping_key, wrapped_key, \
1100 	    wrapped_key_len, template, count, key, req) ( \
1101 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_unwrap) ? \
1102 	KCF_PROV_KEY_OPS(pd)->key_unwrap((pd)->pd_prov_handle, \
1103 	    session, mech, unwrapping_key, wrapped_key, wrapped_key_len, \
1104 	    template, count, key, req) : \
1105 	CRYPTO_NOT_SUPPORTED)
1106 
1107 #define	KCF_PROV_KEY_DERIVE(pd, session, mech, base_key, template, count, \
1108 	    key, req) ( \
1109 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_derive) ? \
1110 	KCF_PROV_KEY_OPS(pd)->key_derive((pd)->pd_prov_handle, \
1111 	    session, mech, base_key, template, count, key, req) : \
1112 	CRYPTO_NOT_SUPPORTED)
1113 
1114 #define	KCF_PROV_KEY_CHECK(pd, mech, key) ( \
1115 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_check) ? \
1116 	KCF_PROV_KEY_OPS(pd)->key_check((pd)->pd_prov_handle, mech, key) : \
1117 	CRYPTO_NOT_SUPPORTED)
1118 
1119 /*
1120  * Wrappers for crypto_provider_management_ops(9S) entry points.
1121  *
1122  * ops_pd is the provider descriptor that supplies the ops_vector.
1123  * pd is the descriptor that supplies the provider handle.
1124  * Only ext_info needs two handles.
1125  */
1126 
1127 #define	KCF_PROV_EXT_INFO(ops_pd, provext_info, req, pd) ( \
1128 	(KCF_PROV_PROVIDER_OPS(ops_pd) && \
1129 	KCF_PROV_PROVIDER_OPS(ops_pd)->ext_info) ? \
1130 	KCF_PROV_PROVIDER_OPS(ops_pd)->ext_info((pd)->pd_prov_handle, \
1131 	    provext_info, req) : CRYPTO_NOT_SUPPORTED)
1132 
1133 #define	KCF_PROV_INIT_TOKEN(pd, pin, pin_len, label, req) ( \
1134 	(KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->init_token) ? \
1135 	KCF_PROV_PROVIDER_OPS(pd)->init_token((pd)->pd_prov_handle, \
1136 	    pin, pin_len, label, req) : CRYPTO_NOT_SUPPORTED)
1137 
1138 #define	KCF_PROV_INIT_PIN(pd, session, pin, pin_len, req) ( \
1139 	(KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->init_pin) ? \
1140 	KCF_PROV_PROVIDER_OPS(pd)->init_pin((pd)->pd_prov_handle, \
1141 	    session, pin, pin_len, req) : CRYPTO_NOT_SUPPORTED)
1142 
1143 #define	KCF_PROV_SET_PIN(pd, session, old_pin, old_len, new_pin, new_len, \
1144 	    req) ( \
1145 	(KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->set_pin) ? \
1146 	KCF_PROV_PROVIDER_OPS(pd)->set_pin((pd)->pd_prov_handle, \
1147 	session, old_pin, old_len, new_pin, new_len, req) : \
1148 	    CRYPTO_NOT_SUPPORTED)
1149 
1150 /*
1151  * The following routines are exported by the kcf module (/kernel/misc/kcf)
1152  * to the crypto and cryptoadmin modules.
1153  */
1154 
1155 /* Digest/mac/cipher entry points that take a provider descriptor and session */
1156 extern int crypto_digest_single(crypto_context_t, crypto_data_t *,
1157     crypto_data_t *, crypto_call_req_t *);
1158 
1159 extern int crypto_mac_single(crypto_context_t, crypto_data_t *,
1160     crypto_data_t *, crypto_call_req_t *);
1161 
1162 extern int crypto_encrypt_single(crypto_context_t, crypto_data_t *,
1163     crypto_data_t *, crypto_call_req_t *);
1164 
1165 extern int crypto_decrypt_single(crypto_context_t, crypto_data_t *,
1166     crypto_data_t *, crypto_call_req_t *);
1167 
1168 
1169 /* Other private digest/mac/cipher entry points not exported through k-API */
1170 extern int crypto_digest_key_prov(crypto_context_t, crypto_key_t *,
1171     crypto_call_req_t *);
1172 
1173 /* Private sign entry points exported by KCF */
1174 extern int crypto_sign_single(crypto_context_t, crypto_data_t *,
1175     crypto_data_t *, crypto_call_req_t *);
1176 
1177 extern int crypto_sign_recover_single(crypto_context_t, crypto_data_t *,
1178     crypto_data_t *, crypto_call_req_t *);
1179 
1180 /* Private verify entry points exported by KCF */
1181 extern int crypto_verify_single(crypto_context_t, crypto_data_t *,
1182     crypto_data_t *, crypto_call_req_t *);
1183 
1184 extern int crypto_verify_recover_single(crypto_context_t, crypto_data_t *,
1185     crypto_data_t *, crypto_call_req_t *);
1186 
1187 /* Private dual operations entry points exported by KCF */
1188 extern int crypto_digest_encrypt_update(crypto_context_t, crypto_context_t,
1189     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1190 extern int crypto_decrypt_digest_update(crypto_context_t, crypto_context_t,
1191     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1192 extern int crypto_sign_encrypt_update(crypto_context_t, crypto_context_t,
1193     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1194 extern int crypto_decrypt_verify_update(crypto_context_t, crypto_context_t,
1195     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1196 
1197 /* Random Number Generation */
1198 int crypto_seed_random(crypto_provider_handle_t provider, uchar_t *buf,
1199     size_t len, crypto_call_req_t *req);
1200 int crypto_generate_random(crypto_provider_handle_t provider, uchar_t *buf,
1201     size_t len, crypto_call_req_t *req);
1202 
1203 /* Provider Management */
1204 int crypto_get_provider_info(crypto_provider_id_t id,
1205     crypto_provider_info_t **info, crypto_call_req_t *req);
1206 int crypto_get_provider_mechanisms(crypto_minor_t *, crypto_provider_id_t id,
1207     uint_t *count, crypto_mech_name_t **list);
1208 int crypto_init_token(crypto_provider_handle_t provider, char *pin,
1209     size_t pin_len, char *label, crypto_call_req_t *);
1210 int crypto_init_pin(crypto_provider_handle_t provider, char *pin,
1211     size_t pin_len, crypto_call_req_t *req);
1212 int crypto_set_pin(crypto_provider_handle_t provider, char *old_pin,
1213     size_t old_len, char *new_pin, size_t new_len, crypto_call_req_t *req);
1214 void crypto_free_provider_list(crypto_provider_entry_t *list, uint_t count);
1215 void crypto_free_provider_info(crypto_provider_info_t *info);
1216 
1217 /* Administrative */
1218 int crypto_get_dev_list(uint_t *count, crypto_dev_list_entry_t **list);
1219 int crypto_get_soft_list(uint_t *count, char **list, size_t *len);
1220 int crypto_get_dev_info(char *name, uint_t instance, uint_t *count,
1221     crypto_mech_name_t **list);
1222 int crypto_get_soft_info(caddr_t name, uint_t *count,
1223     crypto_mech_name_t **list);
1224 int crypto_load_dev_disabled(char *name, uint_t instance, uint_t count,
1225     crypto_mech_name_t *list);
1226 int crypto_load_soft_disabled(caddr_t name, uint_t count,
1227     crypto_mech_name_t *list);
1228 int crypto_unload_soft_module(caddr_t path);
1229 int crypto_load_soft_config(caddr_t name, uint_t count,
1230     crypto_mech_name_t *list);
1231 int crypto_load_door(uint_t did);
1232 void crypto_free_mech_list(crypto_mech_name_t *list, uint_t count);
1233 void crypto_free_dev_list(crypto_dev_list_entry_t *list, uint_t count);
1234 
1235 /* Miscellaneous */
1236 int crypto_get_mechanism_number(caddr_t name, crypto_mech_type_t *number);
1237 int crypto_get_function_list(crypto_provider_id_t id,
1238     crypto_function_list_t **list, int kmflag);
1239 void crypto_free_function_list(crypto_function_list_t *list);
1240 int crypto_build_permitted_mech_names(kcf_provider_desc_t *,
1241     crypto_mech_name_t **, uint_t *, int);
1242 extern void kcf_init_mech_tabs(void);
1243 extern int kcf_add_mech_provider(crypto_mech_info_t *, kcf_provider_desc_t *,
1244     kcf_prov_mech_desc_t **);
1245 extern void kcf_remove_mech_provider(char *, kcf_provider_desc_t *);
1246 extern int kcf_get_mech_entry(crypto_mech_type_t, kcf_mech_entry_t **);
1247 extern kcf_provider_desc_t *kcf_alloc_provider_desc(crypto_provider_info_t *);
1248 extern void kcf_provider_zero_refcnt(kcf_provider_desc_t *);
1249 extern void kcf_free_provider_desc(kcf_provider_desc_t *);
1250 extern void kcf_soft_config_init(void);
1251 extern int get_sw_provider_for_mech(crypto_mech_name_t, char **);
1252 extern void kcf_dup_mech(crypto_mechanism_t *, crypto_mechanism_t *,
1253     crypto_mech_type_t *);
1254 extern crypto_mech_type_t crypto_mech2id_common(char *, boolean_t);
1255 extern void undo_register_provider(kcf_provider_desc_t *, boolean_t);
1256 extern void redo_register_provider(kcf_provider_desc_t *);
1257 extern void kcf_rnd_init();
1258 extern boolean_t kcf_rngprov_check(void);
1259 extern int kcf_rnd_get_pseudo_bytes(uint8_t *, size_t);
1260 extern int kcf_rnd_get_bytes(uint8_t *, size_t, boolean_t, boolean_t);
1261 extern int random_add_pseudo_entropy(uint8_t *, size_t, uint_t);
1262 extern void kcf_rnd_chpoll(int, short *, struct pollhead **);
1263 extern void kcf_rnd_schedule_timeout(boolean_t);
1264 
1265 /* Access to the provider's table */
1266 extern void kcf_prov_tab_init(void);
1267 extern int kcf_prov_tab_add_provider(kcf_provider_desc_t *);
1268 extern int kcf_prov_tab_rem_provider(crypto_provider_id_t);
1269 extern kcf_provider_desc_t *kcf_prov_tab_lookup_by_name(char *);
1270 extern kcf_provider_desc_t *kcf_prov_tab_lookup_by_dev(char *, uint_t);
1271 extern int kcf_get_hw_prov_tab(uint_t *, kcf_provider_desc_t ***, int,
1272     char *, uint_t, boolean_t);
1273 extern int kcf_get_slot_list(uint_t *, kcf_provider_desc_t ***, boolean_t);
1274 extern void kcf_free_provider_tab(uint_t, kcf_provider_desc_t **);
1275 extern kcf_provider_desc_t *kcf_prov_tab_lookup(crypto_provider_id_t);
1276 extern int kcf_get_sw_prov(crypto_mech_type_t, kcf_provider_desc_t **,
1277     boolean_t);
1278 
1279 /* Access to the policy table */
1280 extern boolean_t is_mech_disabled(kcf_provider_desc_t *, crypto_mech_name_t);
1281 extern boolean_t is_mech_disabled_byname(crypto_provider_type_t, char *,
1282     uint_t, crypto_mech_name_t);
1283 extern void kcf_policy_tab_init(void);
1284 extern void kcf_policy_free_desc(kcf_policy_desc_t *);
1285 extern void kcf_policy_remove_by_name(char *, uint_t *, crypto_mech_name_t **);
1286 extern void kcf_policy_remove_by_dev(char *, uint_t, uint_t *,
1287     crypto_mech_name_t **);
1288 extern kcf_policy_desc_t *kcf_policy_lookup_by_name(char *);
1289 extern kcf_policy_desc_t *kcf_policy_lookup_by_dev(char *, uint_t);
1290 extern int kcf_policy_load_soft_disabled(char *, uint_t, crypto_mech_name_t *,
1291     uint_t *, crypto_mech_name_t **);
1292 extern int kcf_policy_load_dev_disabled(char *, uint_t, uint_t,
1293     crypto_mech_name_t *, uint_t *, crypto_mech_name_t **);
1294 extern boolean_t in_soft_config_list(char *);
1295 
1296 #endif	/* _KERNEL */
1297 
1298 #ifdef	__cplusplus
1299 }
1300 #endif
1301 
1302 #endif	/* _SYS_CRYPTO_IMPL_H */
1303