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