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