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