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