xref: /titanic_50/usr/src/uts/common/sys/crypto/impl.h (revision b6c3f7863936abeae522e48a13887dddeb691a45)
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_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 	crypto_ctx_t			*sd_digest_ctx;
487 	crypto_ctx_t			*sd_encr_ctx;
488 	crypto_ctx_t			*sd_decr_ctx;
489 	crypto_ctx_t			*sd_sign_ctx;
490 	crypto_ctx_t			*sd_verify_ctx;
491 	crypto_ctx_t			*sd_sign_recover_ctx;
492 	crypto_ctx_t			*sd_verify_recover_ctx;
493 	kcf_provider_desc_t		*sd_provider;
494 	void				*sd_find_init_cookie;
495 	crypto_provider_session_t	*sd_provider_session;
496 } crypto_session_data_t;
497 
498 #define	CRYPTO_SESSION_IN_USE		0x00000001
499 #define	CRYPTO_SESSION_IS_BUSY		0x00000002
500 #define	CRYPTO_SESSION_IS_CLOSED	0x00000004
501 
502 #define	KCF_MAX_PIN_LEN			1024
503 
504 /*
505  * Per-minor info.
506  *
507  * cm_lock protects everything in this structure except for cm_refcnt.
508  */
509 typedef struct crypto_minor {
510 	uint_t				cm_refcnt;
511 	kmutex_t			cm_lock;
512 	kcondvar_t			cm_cv;
513 	crypto_session_data_t		**cm_session_table;
514 	uint_t				cm_session_table_count;
515 	kcf_provider_desc_t		**cm_provider_array;
516 	uint_t				cm_provider_count;
517 	crypto_provider_session_t	*cm_provider_session;
518 } crypto_minor_t;
519 
520 /* resource control framework handle used by /dev/crypto */
521 extern rctl_hndl_t rc_project_crypto_mem;
522 /*
523  * Return codes for internal functions
524  */
525 #define	KCF_SUCCESS		0x0	/* Successful call */
526 #define	KCF_INVALID_MECH_NUMBER	0x1	/* invalid mechanism number */
527 #define	KCF_INVALID_MECH_NAME	0x2	/* invalid mechanism name */
528 #define	KCF_INVALID_MECH_CLASS	0x3	/* invalid mechanism class */
529 #define	KCF_MECH_TAB_FULL	0x4	/* Need more room in the mech tabs. */
530 #define	KCF_INVALID_INDX	((ushort_t)-1)
531 
532 /*
533  * kCF internal mechanism and function group for tracking RNG providers.
534  */
535 #define	SUN_RANDOM		"random"
536 #define	CRYPTO_FG_RANDOM	0x80000000	/* generate_random() */
537 
538 /*
539  * Wrappers for ops vectors. In the wrapper definitions below, the pd
540  * argument always corresponds to a pointer to a provider descriptor
541  * of type kcf_prov_desc_t.
542  */
543 
544 #define	KCF_PROV_CONTROL_OPS(pd)	((pd)->pd_ops_vector->co_control_ops)
545 #define	KCF_PROV_CTX_OPS(pd)		((pd)->pd_ops_vector->co_ctx_ops)
546 #define	KCF_PROV_DIGEST_OPS(pd)		((pd)->pd_ops_vector->co_digest_ops)
547 #define	KCF_PROV_CIPHER_OPS(pd)		((pd)->pd_ops_vector->co_cipher_ops)
548 #define	KCF_PROV_MAC_OPS(pd)		((pd)->pd_ops_vector->co_mac_ops)
549 #define	KCF_PROV_SIGN_OPS(pd)		((pd)->pd_ops_vector->co_sign_ops)
550 #define	KCF_PROV_VERIFY_OPS(pd)		((pd)->pd_ops_vector->co_verify_ops)
551 #define	KCF_PROV_DUAL_OPS(pd)		((pd)->pd_ops_vector->co_dual_ops)
552 #define	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) \
553 	((pd)->pd_ops_vector->co_dual_cipher_mac_ops)
554 #define	KCF_PROV_RANDOM_OPS(pd)		((pd)->pd_ops_vector->co_random_ops)
555 #define	KCF_PROV_SESSION_OPS(pd)	((pd)->pd_ops_vector->co_session_ops)
556 #define	KCF_PROV_OBJECT_OPS(pd)		((pd)->pd_ops_vector->co_object_ops)
557 #define	KCF_PROV_KEY_OPS(pd)		((pd)->pd_ops_vector->co_key_ops)
558 #define	KCF_PROV_PROVIDER_OPS(pd)	((pd)->pd_ops_vector->co_provider_ops)
559 #define	KCF_PROV_MECH_OPS(pd)		((pd)->pd_ops_vector->co_mech_ops)
560 #define	KCF_PROV_NOSTORE_KEY_OPS(pd)	\
561 	((pd)->pd_ops_vector->co_nostore_key_ops)
562 
563 /*
564  * Wrappers for crypto_control_ops(9S) entry points.
565  */
566 
567 #define	KCF_PROV_STATUS(pd, status) ( \
568 	(KCF_PROV_CONTROL_OPS(pd) && \
569 	KCF_PROV_CONTROL_OPS(pd)->provider_status) ? \
570 	KCF_PROV_CONTROL_OPS(pd)->provider_status( \
571 	    (pd)->pd_prov_handle, status) : \
572 	CRYPTO_NOT_SUPPORTED)
573 
574 /*
575  * Wrappers for crypto_ctx_ops(9S) entry points.
576  */
577 
578 #define	KCF_PROV_CREATE_CTX_TEMPLATE(pd, mech, key, template, size, req) ( \
579 	(KCF_PROV_CTX_OPS(pd) && KCF_PROV_CTX_OPS(pd)->create_ctx_template) ? \
580 	KCF_PROV_CTX_OPS(pd)->create_ctx_template( \
581 	    (pd)->pd_prov_handle, mech, key, template, size, req) : \
582 	CRYPTO_NOT_SUPPORTED)
583 
584 #define	KCF_PROV_FREE_CONTEXT(pd, ctx) ( \
585 	(KCF_PROV_CTX_OPS(pd) && KCF_PROV_CTX_OPS(pd)->free_context) ? \
586 	KCF_PROV_CTX_OPS(pd)->free_context(ctx) : CRYPTO_NOT_SUPPORTED)
587 
588 #define	KCF_PROV_COPYIN_MECH(pd, umech, kmech, errorp, mode) ( \
589 	(KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->copyin_mechanism) ? \
590 	KCF_PROV_MECH_OPS(pd)->copyin_mechanism( \
591 	    (pd)->pd_prov_handle, umech, kmech, errorp, mode) : \
592 	CRYPTO_NOT_SUPPORTED)
593 
594 #define	KCF_PROV_COPYOUT_MECH(pd, kmech, umech, errorp, mode) ( \
595 	(KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->copyout_mechanism) ? \
596 	KCF_PROV_MECH_OPS(pd)->copyout_mechanism( \
597 	    (pd)->pd_prov_handle, kmech, umech, errorp, mode) : \
598 	CRYPTO_NOT_SUPPORTED)
599 
600 #define	KCF_PROV_FREE_MECH(pd, prov_mech) ( \
601 	(KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->free_mechanism) ? \
602 	KCF_PROV_MECH_OPS(pd)->free_mechanism( \
603 	    (pd)->pd_prov_handle, prov_mech) : CRYPTO_NOT_SUPPORTED)
604 
605 /*
606  * Wrappers for crypto_digest_ops(9S) entry points.
607  */
608 
609 #define	KCF_PROV_DIGEST_INIT(pd, ctx, mech, req) ( \
610 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_init) ? \
611 	KCF_PROV_DIGEST_OPS(pd)->digest_init(ctx, mech, req) : \
612 	CRYPTO_NOT_SUPPORTED)
613 
614 /*
615  * The _ (underscore) in _digest is needed to avoid replacing the
616  * function digest().
617  */
618 #define	KCF_PROV_DIGEST(pd, ctx, data, _digest, req) ( \
619 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest) ? \
620 	KCF_PROV_DIGEST_OPS(pd)->digest(ctx, data, _digest, req) : \
621 	CRYPTO_NOT_SUPPORTED)
622 
623 #define	KCF_PROV_DIGEST_UPDATE(pd, ctx, data, req) ( \
624 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_update) ? \
625 	KCF_PROV_DIGEST_OPS(pd)->digest_update(ctx, data, req) : \
626 	CRYPTO_NOT_SUPPORTED)
627 
628 #define	KCF_PROV_DIGEST_KEY(pd, ctx, key, req) ( \
629 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_key) ? \
630 	KCF_PROV_DIGEST_OPS(pd)->digest_key(ctx, key, req) : \
631 	CRYPTO_NOT_SUPPORTED)
632 
633 #define	KCF_PROV_DIGEST_FINAL(pd, ctx, digest, req) ( \
634 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_final) ? \
635 	KCF_PROV_DIGEST_OPS(pd)->digest_final(ctx, digest, req) : \
636 	CRYPTO_NOT_SUPPORTED)
637 
638 #define	KCF_PROV_DIGEST_ATOMIC(pd, session, mech, data, digest, req) ( \
639 	(KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_atomic) ? \
640 	KCF_PROV_DIGEST_OPS(pd)->digest_atomic( \
641 	    (pd)->pd_prov_handle, session, mech, data, digest, req) : \
642 	CRYPTO_NOT_SUPPORTED)
643 
644 /*
645  * Wrappers for crypto_cipher_ops(9S) entry points.
646  */
647 
648 #define	KCF_PROV_ENCRYPT_INIT(pd, ctx, mech, key, template, req) ( \
649 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_init) ? \
650 	KCF_PROV_CIPHER_OPS(pd)->encrypt_init(ctx, mech, key, template, \
651 	    req) : \
652 	CRYPTO_NOT_SUPPORTED)
653 
654 #define	KCF_PROV_ENCRYPT(pd, ctx, plaintext, ciphertext, req) ( \
655 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt) ? \
656 	KCF_PROV_CIPHER_OPS(pd)->encrypt(ctx, plaintext, ciphertext, req) : \
657 	CRYPTO_NOT_SUPPORTED)
658 
659 #define	KCF_PROV_ENCRYPT_UPDATE(pd, ctx, plaintext, ciphertext, req) ( \
660 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_update) ? \
661 	KCF_PROV_CIPHER_OPS(pd)->encrypt_update(ctx, plaintext, \
662 	    ciphertext, req) : \
663 	CRYPTO_NOT_SUPPORTED)
664 
665 #define	KCF_PROV_ENCRYPT_FINAL(pd, ctx, ciphertext, req) ( \
666 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_final) ? \
667 	KCF_PROV_CIPHER_OPS(pd)->encrypt_final(ctx, ciphertext, req) : \
668 	CRYPTO_NOT_SUPPORTED)
669 
670 #define	KCF_PROV_ENCRYPT_ATOMIC(pd, session, mech, key, plaintext, ciphertext, \
671 	    template, req) ( \
672 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_atomic) ? \
673 	KCF_PROV_CIPHER_OPS(pd)->encrypt_atomic( \
674 	    (pd)->pd_prov_handle, session, mech, key, plaintext, ciphertext, \
675 	    template, req) : \
676 	CRYPTO_NOT_SUPPORTED)
677 
678 #define	KCF_PROV_DECRYPT_INIT(pd, ctx, mech, key, template, req) ( \
679 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_init) ? \
680 	KCF_PROV_CIPHER_OPS(pd)->decrypt_init(ctx, mech, key, template, \
681 	    req) : \
682 	CRYPTO_NOT_SUPPORTED)
683 
684 #define	KCF_PROV_DECRYPT(pd, ctx, ciphertext, plaintext, req) ( \
685 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt) ? \
686 	KCF_PROV_CIPHER_OPS(pd)->decrypt(ctx, ciphertext, plaintext, req) : \
687 	CRYPTO_NOT_SUPPORTED)
688 
689 #define	KCF_PROV_DECRYPT_UPDATE(pd, ctx, ciphertext, plaintext, req) ( \
690 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_update) ? \
691 	KCF_PROV_CIPHER_OPS(pd)->decrypt_update(ctx, ciphertext, \
692 	    plaintext, req) : \
693 	CRYPTO_NOT_SUPPORTED)
694 
695 #define	KCF_PROV_DECRYPT_FINAL(pd, ctx, plaintext, req) ( \
696 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_final) ? \
697 	KCF_PROV_CIPHER_OPS(pd)->decrypt_final(ctx, plaintext, req) : \
698 	CRYPTO_NOT_SUPPORTED)
699 
700 #define	KCF_PROV_DECRYPT_ATOMIC(pd, session, mech, key, ciphertext, plaintext, \
701 	    template, req) ( \
702 	(KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_atomic) ? \
703 	KCF_PROV_CIPHER_OPS(pd)->decrypt_atomic( \
704 	    (pd)->pd_prov_handle, session, mech, key, ciphertext, plaintext, \
705 	    template, req) : \
706 	CRYPTO_NOT_SUPPORTED)
707 
708 /*
709  * Wrappers for crypto_mac_ops(9S) entry points.
710  */
711 
712 #define	KCF_PROV_MAC_INIT(pd, ctx, mech, key, template, req) ( \
713 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_init) ? \
714 	KCF_PROV_MAC_OPS(pd)->mac_init(ctx, mech, key, template, req) \
715 	: CRYPTO_NOT_SUPPORTED)
716 
717 /*
718  * The _ (underscore) in _mac is needed to avoid replacing the
719  * function mac().
720  */
721 #define	KCF_PROV_MAC(pd, ctx, data, _mac, req) ( \
722 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac) ? \
723 	KCF_PROV_MAC_OPS(pd)->mac(ctx, data, _mac, req) : \
724 	CRYPTO_NOT_SUPPORTED)
725 
726 #define	KCF_PROV_MAC_UPDATE(pd, ctx, data, req) ( \
727 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_update) ? \
728 	KCF_PROV_MAC_OPS(pd)->mac_update(ctx, data, req) : \
729 	CRYPTO_NOT_SUPPORTED)
730 
731 #define	KCF_PROV_MAC_FINAL(pd, ctx, mac, req) ( \
732 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_final) ? \
733 	KCF_PROV_MAC_OPS(pd)->mac_final(ctx, mac, req) : \
734 	CRYPTO_NOT_SUPPORTED)
735 
736 #define	KCF_PROV_MAC_ATOMIC(pd, session, mech, key, data, mac, template, \
737 	    req) ( \
738 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_atomic) ? \
739 	KCF_PROV_MAC_OPS(pd)->mac_atomic( \
740 	    (pd)->pd_prov_handle, session, mech, key, data, mac, template, \
741 	    req) : \
742 	CRYPTO_NOT_SUPPORTED)
743 
744 #define	KCF_PROV_MAC_VERIFY_ATOMIC(pd, session, mech, key, data, mac, \
745 	    template, req) ( \
746 	(KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_verify_atomic) ? \
747 	KCF_PROV_MAC_OPS(pd)->mac_verify_atomic( \
748 	    (pd)->pd_prov_handle, session, mech, key, data, mac, template, \
749 	    req) : \
750 	CRYPTO_NOT_SUPPORTED)
751 
752 /*
753  * Wrappers for crypto_sign_ops(9S) entry points.
754  */
755 
756 #define	KCF_PROV_SIGN_INIT(pd, ctx, mech, key, template, req) ( \
757 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_init) ? \
758 	KCF_PROV_SIGN_OPS(pd)->sign_init( \
759 	    ctx, mech, key, template, req) : CRYPTO_NOT_SUPPORTED)
760 
761 #define	KCF_PROV_SIGN(pd, ctx, data, sig, req) ( \
762 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign) ? \
763 	KCF_PROV_SIGN_OPS(pd)->sign(ctx, data, sig, req) : \
764 	CRYPTO_NOT_SUPPORTED)
765 
766 #define	KCF_PROV_SIGN_UPDATE(pd, ctx, data, req) ( \
767 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_update) ? \
768 	KCF_PROV_SIGN_OPS(pd)->sign_update(ctx, data, req) : \
769 	CRYPTO_NOT_SUPPORTED)
770 
771 #define	KCF_PROV_SIGN_FINAL(pd, ctx, sig, req) ( \
772 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_final) ? \
773 	KCF_PROV_SIGN_OPS(pd)->sign_final(ctx, sig, req) : \
774 	CRYPTO_NOT_SUPPORTED)
775 
776 #define	KCF_PROV_SIGN_ATOMIC(pd, session, mech, key, data, template, \
777 	    sig, req) ( \
778 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_atomic) ? \
779 	KCF_PROV_SIGN_OPS(pd)->sign_atomic( \
780 	    (pd)->pd_prov_handle, session, mech, key, data, sig, template, \
781 	    req) : CRYPTO_NOT_SUPPORTED)
782 
783 #define	KCF_PROV_SIGN_RECOVER_INIT(pd, ctx, mech, key, template, \
784 	    req) ( \
785 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_recover_init) ? \
786 	KCF_PROV_SIGN_OPS(pd)->sign_recover_init(ctx, mech, key, template, \
787 	    req) : CRYPTO_NOT_SUPPORTED)
788 
789 #define	KCF_PROV_SIGN_RECOVER(pd, ctx, data, sig, req) ( \
790 	(KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_recover) ? \
791 	KCF_PROV_SIGN_OPS(pd)->sign_recover(ctx, data, sig, req) : \
792 	CRYPTO_NOT_SUPPORTED)
793 
794 #define	KCF_PROV_SIGN_RECOVER_ATOMIC(pd, session, mech, key, data, template, \
795 	    sig, req) ( \
796 	(KCF_PROV_SIGN_OPS(pd) && \
797 	KCF_PROV_SIGN_OPS(pd)->sign_recover_atomic) ? \
798 	KCF_PROV_SIGN_OPS(pd)->sign_recover_atomic( \
799 	    (pd)->pd_prov_handle, session, mech, key, data, sig, template, \
800 	    req) : CRYPTO_NOT_SUPPORTED)
801 
802 /*
803  * Wrappers for crypto_verify_ops(9S) entry points.
804  */
805 
806 #define	KCF_PROV_VERIFY_INIT(pd, ctx, mech, key, template, req) ( \
807 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_init) ? \
808 	KCF_PROV_VERIFY_OPS(pd)->verify_init(ctx, mech, key, template, \
809 	    req) : CRYPTO_NOT_SUPPORTED)
810 
811 #define	KCF_PROV_VERIFY(pd, ctx, data, sig, req) ( \
812 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify) ? \
813 	KCF_PROV_VERIFY_OPS(pd)->verify(ctx, data, sig, req) : \
814 	CRYPTO_NOT_SUPPORTED)
815 
816 #define	KCF_PROV_VERIFY_UPDATE(pd, ctx, data, req) ( \
817 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_update) ? \
818 	KCF_PROV_VERIFY_OPS(pd)->verify_update(ctx, data, req) : \
819 	CRYPTO_NOT_SUPPORTED)
820 
821 #define	KCF_PROV_VERIFY_FINAL(pd, ctx, sig, req) ( \
822 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_final) ? \
823 	KCF_PROV_VERIFY_OPS(pd)->verify_final(ctx, sig, req) : \
824 	CRYPTO_NOT_SUPPORTED)
825 
826 #define	KCF_PROV_VERIFY_ATOMIC(pd, session, mech, key, data, template, sig, \
827 	    req) ( \
828 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_atomic) ? \
829 	KCF_PROV_VERIFY_OPS(pd)->verify_atomic( \
830 	    (pd)->pd_prov_handle, session, mech, key, data, sig, template, \
831 	    req) : CRYPTO_NOT_SUPPORTED)
832 
833 #define	KCF_PROV_VERIFY_RECOVER_INIT(pd, ctx, mech, key, template, \
834 	    req) ( \
835 	(KCF_PROV_VERIFY_OPS(pd) && \
836 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_init) ? \
837 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_init(ctx, mech, key, \
838 	    template, req) : CRYPTO_NOT_SUPPORTED)
839 
840 /* verify_recover() CSPI routine has different argument order than verify() */
841 #define	KCF_PROV_VERIFY_RECOVER(pd, ctx, sig, data, req) ( \
842 	(KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_recover) ? \
843 	KCF_PROV_VERIFY_OPS(pd)->verify_recover(ctx, sig, data, req) : \
844 	CRYPTO_NOT_SUPPORTED)
845 
846 /*
847  * verify_recover_atomic() CSPI routine has different argument order
848  * than verify_atomic().
849  */
850 #define	KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, session, mech, key, sig, \
851 	    template, data,  req) ( \
852 	(KCF_PROV_VERIFY_OPS(pd) && \
853 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_atomic) ? \
854 	KCF_PROV_VERIFY_OPS(pd)->verify_recover_atomic( \
855 	    (pd)->pd_prov_handle, session, mech, key, sig, data, template, \
856 	    req) : CRYPTO_NOT_SUPPORTED)
857 
858 /*
859  * Wrappers for crypto_dual_ops(9S) entry points.
860  */
861 
862 #define	KCF_PROV_DIGEST_ENCRYPT_UPDATE(digest_ctx, encrypt_ctx, plaintext, \
863 	    ciphertext, req) ( \
864 	(KCF_PROV_DUAL_OPS(pd) && \
865 	KCF_PROV_DUAL_OPS(pd)->digest_encrypt_update) ? \
866 	KCF_PROV_DUAL_OPS(pd)->digest_encrypt_update( \
867 	    digest_ctx, encrypt_ctx, plaintext, ciphertext, req) : \
868 	CRYPTO_NOT_SUPPORTED)
869 
870 #define	KCF_PROV_DECRYPT_DIGEST_UPDATE(decrypt_ctx, digest_ctx, ciphertext, \
871 	    plaintext, req) ( \
872 	(KCF_PROV_DUAL_OPS(pd) && \
873 	KCF_PROV_DUAL_OPS(pd)->decrypt_digest_update) ? \
874 	KCF_PROV_DUAL_OPS(pd)->decrypt_digest_update( \
875 	    decrypt_ctx, digest_ctx, ciphertext, plaintext, req) : \
876 	CRYPTO_NOT_SUPPORTED)
877 
878 #define	KCF_PROV_SIGN_ENCRYPT_UPDATE(sign_ctx, encrypt_ctx, plaintext, \
879 	    ciphertext, req) ( \
880 	(KCF_PROV_DUAL_OPS(pd) && \
881 	KCF_PROV_DUAL_OPS(pd)->sign_encrypt_update) ? \
882 	KCF_PROV_DUAL_OPS(pd)->sign_encrypt_update( \
883 	    sign_ctx, encrypt_ctx, plaintext, ciphertext, req) : \
884 	CRYPTO_NOT_SUPPORTED)
885 
886 #define	KCF_PROV_DECRYPT_VERIFY_UPDATE(decrypt_ctx, verify_ctx, ciphertext, \
887 	    plaintext, req) ( \
888 	(KCF_PROV_DUAL_OPS(pd) && \
889 	KCF_PROV_DUAL_OPS(pd)->decrypt_verify_update) ? \
890 	KCF_PROV_DUAL_OPS(pd)->decrypt_verify_update( \
891 	    decrypt_ctx, verify_ctx, ciphertext, plaintext, req) : \
892 	CRYPTO_NOT_SUPPORTED)
893 
894 /*
895  * Wrappers for crypto_dual_cipher_mac_ops(9S) entry points.
896  */
897 
898 #define	KCF_PROV_ENCRYPT_MAC_INIT(pd, ctx, encr_mech, encr_key, mac_mech, \
899 	    mac_key, encr_ctx_template, mac_ctx_template, req) ( \
900 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
901 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_init) ? \
902 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_init( \
903 	    ctx, encr_mech, encr_key, mac_mech, mac_key, encr_ctx_template, \
904 	    mac_ctx_template, req) : \
905 	CRYPTO_NOT_SUPPORTED)
906 
907 #define	KCF_PROV_ENCRYPT_MAC(pd, ctx, plaintext, ciphertext, mac, req) ( \
908 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
909 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac) ? \
910 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac( \
911 	    ctx, plaintext, ciphertext, mac, req) : \
912 	CRYPTO_NOT_SUPPORTED)
913 
914 #define	KCF_PROV_ENCRYPT_MAC_UPDATE(pd, ctx, plaintext, ciphertext, req) ( \
915 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
916 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_update) ? \
917 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_update( \
918 	    ctx, plaintext, ciphertext, req) : \
919 	CRYPTO_NOT_SUPPORTED)
920 
921 #define	KCF_PROV_ENCRYPT_MAC_FINAL(pd, ctx, ciphertext, mac, req) ( \
922 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
923 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_final) ? \
924 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_final( \
925 	    ctx, ciphertext, mac, req) : \
926 	CRYPTO_NOT_SUPPORTED)
927 
928 #define	KCF_PROV_ENCRYPT_MAC_ATOMIC(pd, session, encr_mech, encr_key, \
929 	    mac_mech, mac_key, plaintext, ciphertext, mac, \
930 	    encr_ctx_template, mac_ctx_template, req) ( \
931 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
932 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_atomic) ? \
933 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_atomic( \
934 	    (pd)->pd_prov_handle, session, encr_mech, encr_key, \
935 	    mac_mech, mac_key, plaintext, ciphertext, mac, \
936 	    encr_ctx_template, mac_ctx_template, req) : \
937 	CRYPTO_NOT_SUPPORTED)
938 
939 #define	KCF_PROV_MAC_DECRYPT_INIT(pd, ctx, mac_mech, mac_key, decr_mech, \
940 	    decr_key, mac_ctx_template, decr_ctx_template, req) ( \
941 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
942 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_init) ? \
943 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_init( \
944 	    ctx, mac_mech, mac_key, decr_mech, decr_key, mac_ctx_template, \
945 	    decr_ctx_template, req) : \
946 	CRYPTO_NOT_SUPPORTED)
947 
948 #define	KCF_PROV_MAC_DECRYPT(pd, ctx, ciphertext, mac, plaintext, req) ( \
949 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
950 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt) ? \
951 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt( \
952 	    ctx, ciphertext, mac, plaintext, req) : \
953 	CRYPTO_NOT_SUPPORTED)
954 
955 #define	KCF_PROV_MAC_DECRYPT_UPDATE(pd, ctx, ciphertext, plaintext, req) ( \
956 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
957 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_update) ? \
958 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_update( \
959 	    ctx, ciphertext, plaintext, req) : \
960 	CRYPTO_NOT_SUPPORTED)
961 
962 #define	KCF_PROV_MAC_DECRYPT_FINAL(pd, ctx, mac, plaintext, req) ( \
963 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
964 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_final) ? \
965 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_final( \
966 	    ctx, mac, plaintext, req) : \
967 	CRYPTO_NOT_SUPPORTED)
968 
969 #define	KCF_PROV_MAC_DECRYPT_ATOMIC(pd, session, mac_mech, mac_key, \
970 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
971 	    mac_ctx_template, decr_ctx_template, req) ( \
972 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
973 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_atomic) ? \
974 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_atomic( \
975 	    (pd)->pd_prov_handle, session, mac_mech, mac_key, \
976 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
977 	    mac_ctx_template, decr_ctx_template, req) : \
978 	CRYPTO_NOT_SUPPORTED)
979 
980 #define	KCF_PROV_MAC_VERIFY_DECRYPT_ATOMIC(pd, session, mac_mech, mac_key, \
981 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
982 	    mac_ctx_template, decr_ctx_template, req) ( \
983 	(KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \
984 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_verify_decrypt_atomic \
985 	    != NULL) ? \
986 	KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_verify_decrypt_atomic( \
987 	    (pd)->pd_prov_handle, session, mac_mech, mac_key, \
988 	    decr_mech, decr_key, ciphertext, mac, plaintext, \
989 	    mac_ctx_template, decr_ctx_template, req) : \
990 	CRYPTO_NOT_SUPPORTED)
991 
992 /*
993  * Wrappers for crypto_random_number_ops(9S) entry points.
994  */
995 
996 #define	KCF_PROV_SEED_RANDOM(pd, session, buf, len, est, flags, req) ( \
997 	(KCF_PROV_RANDOM_OPS(pd) && KCF_PROV_RANDOM_OPS(pd)->seed_random) ? \
998 	KCF_PROV_RANDOM_OPS(pd)->seed_random((pd)->pd_prov_handle, \
999 	    session, buf, len, est, flags, req) : CRYPTO_NOT_SUPPORTED)
1000 
1001 #define	KCF_PROV_GENERATE_RANDOM(pd, session, buf, len, req) ( \
1002 	(KCF_PROV_RANDOM_OPS(pd) && \
1003 	KCF_PROV_RANDOM_OPS(pd)->generate_random) ? \
1004 	KCF_PROV_RANDOM_OPS(pd)->generate_random((pd)->pd_prov_handle, \
1005 	    session, buf, len, req) : CRYPTO_NOT_SUPPORTED)
1006 
1007 /*
1008  * Wrappers for crypto_session_ops(9S) entry points.
1009  *
1010  * ops_pd is the provider descriptor that supplies the ops_vector.
1011  * pd is the descriptor that supplies the provider handle.
1012  * Only session open/close needs two handles.
1013  */
1014 
1015 #define	KCF_PROV_SESSION_OPEN(ops_pd, session, req, pd) ( \
1016 	(KCF_PROV_SESSION_OPS(ops_pd) && \
1017 	KCF_PROV_SESSION_OPS(ops_pd)->session_open) ? \
1018 	KCF_PROV_SESSION_OPS(ops_pd)->session_open((pd)->pd_prov_handle, \
1019 	    session, req) : CRYPTO_NOT_SUPPORTED)
1020 
1021 #define	KCF_PROV_SESSION_CLOSE(ops_pd, session, req, pd) ( \
1022 	(KCF_PROV_SESSION_OPS(ops_pd) && \
1023 	KCF_PROV_SESSION_OPS(ops_pd)->session_close) ? \
1024 	KCF_PROV_SESSION_OPS(ops_pd)->session_close((pd)->pd_prov_handle, \
1025 	    session, req) : CRYPTO_NOT_SUPPORTED)
1026 
1027 #define	KCF_PROV_SESSION_LOGIN(pd, session, user_type, pin, len, req) ( \
1028 	(KCF_PROV_SESSION_OPS(pd) && \
1029 	KCF_PROV_SESSION_OPS(pd)->session_login) ? \
1030 	KCF_PROV_SESSION_OPS(pd)->session_login((pd)->pd_prov_handle, \
1031 	    session, user_type, pin, len, req) : CRYPTO_NOT_SUPPORTED)
1032 
1033 #define	KCF_PROV_SESSION_LOGOUT(pd, session, req) ( \
1034 	(KCF_PROV_SESSION_OPS(pd) && \
1035 	KCF_PROV_SESSION_OPS(pd)->session_logout) ? \
1036 	KCF_PROV_SESSION_OPS(pd)->session_logout((pd)->pd_prov_handle, \
1037 	    session, req) : CRYPTO_NOT_SUPPORTED)
1038 
1039 /*
1040  * Wrappers for crypto_object_ops(9S) entry points.
1041  */
1042 
1043 #define	KCF_PROV_OBJECT_CREATE(pd, session, template, count, object, req) ( \
1044 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_create) ? \
1045 	KCF_PROV_OBJECT_OPS(pd)->object_create((pd)->pd_prov_handle, \
1046 	    session, template, count, object, req) : CRYPTO_NOT_SUPPORTED)
1047 
1048 #define	KCF_PROV_OBJECT_COPY(pd, session, object, template, count, \
1049 	    new_object, req) ( \
1050 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_copy) ? \
1051 	KCF_PROV_OBJECT_OPS(pd)->object_copy((pd)->pd_prov_handle, \
1052 	session, object, template, count, new_object, req) : \
1053 	    CRYPTO_NOT_SUPPORTED)
1054 
1055 #define	KCF_PROV_OBJECT_DESTROY(pd, session, object, req) ( \
1056 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_destroy) ? \
1057 	KCF_PROV_OBJECT_OPS(pd)->object_destroy((pd)->pd_prov_handle, \
1058 	    session, object, req) : CRYPTO_NOT_SUPPORTED)
1059 
1060 #define	KCF_PROV_OBJECT_GET_SIZE(pd, session, object, size, req) ( \
1061 	(KCF_PROV_OBJECT_OPS(pd) && \
1062 	KCF_PROV_OBJECT_OPS(pd)->object_get_size) ? \
1063 	KCF_PROV_OBJECT_OPS(pd)->object_get_size((pd)->pd_prov_handle, \
1064 	    session, object, size, req) : CRYPTO_NOT_SUPPORTED)
1065 
1066 #define	KCF_PROV_OBJECT_GET_ATTRIBUTE_VALUE(pd, session, object, template, \
1067 	    count, req) ( \
1068 	(KCF_PROV_OBJECT_OPS(pd) && \
1069 	KCF_PROV_OBJECT_OPS(pd)->object_get_attribute_value) ? \
1070 	KCF_PROV_OBJECT_OPS(pd)->object_get_attribute_value( \
1071 	(pd)->pd_prov_handle, session, object, template, count, req) : \
1072 	    CRYPTO_NOT_SUPPORTED)
1073 
1074 #define	KCF_PROV_OBJECT_SET_ATTRIBUTE_VALUE(pd, session, object, template, \
1075 	    count, req) ( \
1076 	(KCF_PROV_OBJECT_OPS(pd) && \
1077 	KCF_PROV_OBJECT_OPS(pd)->object_set_attribute_value) ? \
1078 	KCF_PROV_OBJECT_OPS(pd)->object_set_attribute_value( \
1079 	(pd)->pd_prov_handle, session, object, template, count, req) : \
1080 	    CRYPTO_NOT_SUPPORTED)
1081 
1082 #define	KCF_PROV_OBJECT_FIND_INIT(pd, session, template, count, ppriv, \
1083 	    req) ( \
1084 	(KCF_PROV_OBJECT_OPS(pd) && \
1085 	KCF_PROV_OBJECT_OPS(pd)->object_find_init) ? \
1086 	KCF_PROV_OBJECT_OPS(pd)->object_find_init((pd)->pd_prov_handle, \
1087 	session, template, count, ppriv, req) : CRYPTO_NOT_SUPPORTED)
1088 
1089 #define	KCF_PROV_OBJECT_FIND(pd, ppriv, objects, max_objects, object_count, \
1090 	    req) ( \
1091 	(KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_find) ? \
1092 	KCF_PROV_OBJECT_OPS(pd)->object_find( \
1093 	(pd)->pd_prov_handle, ppriv, objects, max_objects, object_count, \
1094 	req) : CRYPTO_NOT_SUPPORTED)
1095 
1096 #define	KCF_PROV_OBJECT_FIND_FINAL(pd, ppriv, req) ( \
1097 	(KCF_PROV_OBJECT_OPS(pd) && \
1098 	KCF_PROV_OBJECT_OPS(pd)->object_find_final) ? \
1099 	KCF_PROV_OBJECT_OPS(pd)->object_find_final( \
1100 	    (pd)->pd_prov_handle, ppriv, req) : CRYPTO_NOT_SUPPORTED)
1101 
1102 /*
1103  * Wrappers for crypto_key_ops(9S) entry points.
1104  */
1105 
1106 #define	KCF_PROV_KEY_GENERATE(pd, session, mech, template, count, object, \
1107 	    req) ( \
1108 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_generate) ? \
1109 	KCF_PROV_KEY_OPS(pd)->key_generate((pd)->pd_prov_handle, \
1110 	    session, mech, template, count, object, req) : \
1111 	CRYPTO_NOT_SUPPORTED)
1112 
1113 #define	KCF_PROV_KEY_GENERATE_PAIR(pd, session, mech, pub_template, \
1114 	    pub_count, priv_template, priv_count, pub_key, priv_key, req) ( \
1115 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_generate_pair) ? \
1116 	KCF_PROV_KEY_OPS(pd)->key_generate_pair((pd)->pd_prov_handle, \
1117 	    session, mech, pub_template, pub_count, priv_template, \
1118 	    priv_count, pub_key, priv_key, req) : \
1119 	CRYPTO_NOT_SUPPORTED)
1120 
1121 #define	KCF_PROV_KEY_WRAP(pd, session, mech, wrapping_key, key, wrapped_key, \
1122 	    wrapped_key_len, req) ( \
1123 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_wrap) ? \
1124 	KCF_PROV_KEY_OPS(pd)->key_wrap((pd)->pd_prov_handle, \
1125 	    session, mech, wrapping_key, key, wrapped_key, wrapped_key_len, \
1126 	    req) : \
1127 	CRYPTO_NOT_SUPPORTED)
1128 
1129 #define	KCF_PROV_KEY_UNWRAP(pd, session, mech, unwrapping_key, wrapped_key, \
1130 	    wrapped_key_len, template, count, key, req) ( \
1131 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_unwrap) ? \
1132 	KCF_PROV_KEY_OPS(pd)->key_unwrap((pd)->pd_prov_handle, \
1133 	    session, mech, unwrapping_key, wrapped_key, wrapped_key_len, \
1134 	    template, count, key, req) : \
1135 	CRYPTO_NOT_SUPPORTED)
1136 
1137 #define	KCF_PROV_KEY_DERIVE(pd, session, mech, base_key, template, count, \
1138 	    key, req) ( \
1139 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_derive) ? \
1140 	KCF_PROV_KEY_OPS(pd)->key_derive((pd)->pd_prov_handle, \
1141 	    session, mech, base_key, template, count, key, req) : \
1142 	CRYPTO_NOT_SUPPORTED)
1143 
1144 #define	KCF_PROV_KEY_CHECK(pd, mech, key) ( \
1145 	(KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_check) ? \
1146 	KCF_PROV_KEY_OPS(pd)->key_check((pd)->pd_prov_handle, mech, key) : \
1147 	CRYPTO_NOT_SUPPORTED)
1148 
1149 /*
1150  * Wrappers for crypto_provider_management_ops(9S) entry points.
1151  *
1152  * ops_pd is the provider descriptor that supplies the ops_vector.
1153  * pd is the descriptor that supplies the provider handle.
1154  * Only ext_info needs two handles.
1155  */
1156 
1157 #define	KCF_PROV_EXT_INFO(ops_pd, provext_info, req, pd) ( \
1158 	(KCF_PROV_PROVIDER_OPS(ops_pd) && \
1159 	KCF_PROV_PROVIDER_OPS(ops_pd)->ext_info) ? \
1160 	KCF_PROV_PROVIDER_OPS(ops_pd)->ext_info((pd)->pd_prov_handle, \
1161 	    provext_info, req) : CRYPTO_NOT_SUPPORTED)
1162 
1163 #define	KCF_PROV_INIT_TOKEN(pd, pin, pin_len, label, req) ( \
1164 	(KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->init_token) ? \
1165 	KCF_PROV_PROVIDER_OPS(pd)->init_token((pd)->pd_prov_handle, \
1166 	    pin, pin_len, label, req) : CRYPTO_NOT_SUPPORTED)
1167 
1168 #define	KCF_PROV_INIT_PIN(pd, session, pin, pin_len, req) ( \
1169 	(KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->init_pin) ? \
1170 	KCF_PROV_PROVIDER_OPS(pd)->init_pin((pd)->pd_prov_handle, \
1171 	    session, pin, pin_len, req) : CRYPTO_NOT_SUPPORTED)
1172 
1173 #define	KCF_PROV_SET_PIN(pd, session, old_pin, old_len, new_pin, new_len, \
1174 	    req) ( \
1175 	(KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->set_pin) ? \
1176 	KCF_PROV_PROVIDER_OPS(pd)->set_pin((pd)->pd_prov_handle, \
1177 	session, old_pin, old_len, new_pin, new_len, req) : \
1178 	    CRYPTO_NOT_SUPPORTED)
1179 
1180 /*
1181  * Wrappers for crypto_nostore_key_ops(9S) entry points.
1182  */
1183 
1184 #define	KCF_PROV_NOSTORE_KEY_GENERATE(pd, session, mech, template, count, \
1185 	    out_template, out_count, req) ( \
1186 	(KCF_PROV_NOSTORE_KEY_OPS(pd) && \
1187 	    KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate) ? \
1188 	KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate( \
1189 	    (pd)->pd_prov_handle, session, mech, template, count, \
1190 	    out_template, out_count, req) : CRYPTO_NOT_SUPPORTED)
1191 
1192 #define	KCF_PROV_NOSTORE_KEY_GENERATE_PAIR(pd, session, mech, pub_template, \
1193 	    pub_count, priv_template, priv_count, out_pub_template, \
1194 	    out_pub_count, out_priv_template, out_priv_count, req) ( \
1195 	(KCF_PROV_NOSTORE_KEY_OPS(pd) && \
1196 	    KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate_pair) ? \
1197 	KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate_pair( \
1198 	    (pd)->pd_prov_handle, session, mech, pub_template, pub_count, \
1199 	    priv_template, priv_count, out_pub_template, out_pub_count, \
1200 	    out_priv_template, out_priv_count, req) : CRYPTO_NOT_SUPPORTED)
1201 
1202 #define	KCF_PROV_NOSTORE_KEY_DERIVE(pd, session, mech, base_key, template, \
1203 	    count, out_template, out_count, req) ( \
1204 	(KCF_PROV_NOSTORE_KEY_OPS(pd) && \
1205 	    KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_derive) ? \
1206 	KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_derive( \
1207 	    (pd)->pd_prov_handle, session, mech, base_key, template, count, \
1208 	    out_template, out_count, req) : CRYPTO_NOT_SUPPORTED)
1209 
1210 /*
1211  * The following routines are exported by the kcf module (/kernel/misc/kcf)
1212  * to the crypto and cryptoadmin modules.
1213  */
1214 
1215 /* Digest/mac/cipher entry points that take a provider descriptor and session */
1216 extern int crypto_digest_single(crypto_context_t, crypto_data_t *,
1217     crypto_data_t *, crypto_call_req_t *);
1218 
1219 extern int crypto_mac_single(crypto_context_t, crypto_data_t *,
1220     crypto_data_t *, crypto_call_req_t *);
1221 
1222 extern int crypto_encrypt_single(crypto_context_t, crypto_data_t *,
1223     crypto_data_t *, crypto_call_req_t *);
1224 
1225 extern int crypto_decrypt_single(crypto_context_t, crypto_data_t *,
1226     crypto_data_t *, crypto_call_req_t *);
1227 
1228 
1229 /* Other private digest/mac/cipher entry points not exported through k-API */
1230 extern int crypto_digest_key_prov(crypto_context_t, crypto_key_t *,
1231     crypto_call_req_t *);
1232 
1233 /* Private sign entry points exported by KCF */
1234 extern int crypto_sign_single(crypto_context_t, crypto_data_t *,
1235     crypto_data_t *, crypto_call_req_t *);
1236 
1237 extern int crypto_sign_recover_single(crypto_context_t, crypto_data_t *,
1238     crypto_data_t *, crypto_call_req_t *);
1239 
1240 /* Private verify entry points exported by KCF */
1241 extern int crypto_verify_single(crypto_context_t, crypto_data_t *,
1242     crypto_data_t *, crypto_call_req_t *);
1243 
1244 extern int crypto_verify_recover_single(crypto_context_t, crypto_data_t *,
1245     crypto_data_t *, crypto_call_req_t *);
1246 
1247 /* Private dual operations entry points exported by KCF */
1248 extern int crypto_digest_encrypt_update(crypto_context_t, crypto_context_t,
1249     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1250 extern int crypto_decrypt_digest_update(crypto_context_t, crypto_context_t,
1251     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1252 extern int crypto_sign_encrypt_update(crypto_context_t, crypto_context_t,
1253     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1254 extern int crypto_decrypt_verify_update(crypto_context_t, crypto_context_t,
1255     crypto_data_t *, crypto_data_t *, crypto_call_req_t *);
1256 
1257 /* Random Number Generation */
1258 int crypto_seed_random(crypto_provider_handle_t provider, uchar_t *buf,
1259     size_t len, crypto_call_req_t *req);
1260 int crypto_generate_random(crypto_provider_handle_t provider, uchar_t *buf,
1261     size_t len, crypto_call_req_t *req);
1262 
1263 /* Provider Management */
1264 int crypto_get_provider_info(crypto_provider_id_t id,
1265     crypto_provider_info_t **info, crypto_call_req_t *req);
1266 int crypto_get_provider_mechanisms(crypto_minor_t *, crypto_provider_id_t id,
1267     uint_t *count, crypto_mech_name_t **list);
1268 int crypto_init_token(crypto_provider_handle_t provider, char *pin,
1269     size_t pin_len, char *label, crypto_call_req_t *);
1270 int crypto_init_pin(crypto_provider_handle_t provider, char *pin,
1271     size_t pin_len, crypto_call_req_t *req);
1272 int crypto_set_pin(crypto_provider_handle_t provider, char *old_pin,
1273     size_t old_len, char *new_pin, size_t new_len, crypto_call_req_t *req);
1274 void crypto_free_provider_list(crypto_provider_entry_t *list, uint_t count);
1275 void crypto_free_provider_info(crypto_provider_info_t *info);
1276 
1277 /* Administrative */
1278 int crypto_get_dev_list(uint_t *count, crypto_dev_list_entry_t **list);
1279 int crypto_get_soft_list(uint_t *count, char **list, size_t *len);
1280 int crypto_get_dev_info(char *name, uint_t instance, uint_t *count,
1281     crypto_mech_name_t **list);
1282 int crypto_get_soft_info(caddr_t name, uint_t *count,
1283     crypto_mech_name_t **list);
1284 int crypto_load_dev_disabled(char *name, uint_t instance, uint_t count,
1285     crypto_mech_name_t *list);
1286 int crypto_load_soft_disabled(caddr_t name, uint_t count,
1287     crypto_mech_name_t *list);
1288 int crypto_unload_soft_module(caddr_t path);
1289 int crypto_load_soft_config(caddr_t name, uint_t count,
1290     crypto_mech_name_t *list);
1291 int crypto_load_door(uint_t did);
1292 void crypto_free_mech_list(crypto_mech_name_t *list, uint_t count);
1293 void crypto_free_dev_list(crypto_dev_list_entry_t *list, uint_t count);
1294 
1295 /* Miscellaneous */
1296 int crypto_get_mechanism_number(caddr_t name, crypto_mech_type_t *number);
1297 int crypto_get_function_list(crypto_provider_id_t id,
1298     crypto_function_list_t **list, int kmflag);
1299 void crypto_free_function_list(crypto_function_list_t *list);
1300 int crypto_build_permitted_mech_names(kcf_provider_desc_t *,
1301     crypto_mech_name_t **, uint_t *, int);
1302 extern void kcf_init_mech_tabs(void);
1303 extern int kcf_add_mech_provider(short, kcf_provider_desc_t *,
1304     kcf_prov_mech_desc_t **);
1305 extern void kcf_remove_mech_provider(char *, kcf_provider_desc_t *);
1306 extern int kcf_get_mech_entry(crypto_mech_type_t, kcf_mech_entry_t **);
1307 extern kcf_provider_desc_t *kcf_alloc_provider_desc(crypto_provider_info_t *);
1308 extern void kcf_provider_zero_refcnt(kcf_provider_desc_t *);
1309 extern void kcf_free_provider_desc(kcf_provider_desc_t *);
1310 extern void kcf_soft_config_init(void);
1311 extern int get_sw_provider_for_mech(crypto_mech_name_t, char **);
1312 extern void kcf_dup_mech(crypto_mechanism_t *, crypto_mechanism_t *,
1313     crypto_mech_type_t *);
1314 extern crypto_mech_type_t crypto_mech2id_common(char *, boolean_t);
1315 extern void undo_register_provider(kcf_provider_desc_t *, boolean_t);
1316 extern void redo_register_provider(kcf_provider_desc_t *);
1317 extern void kcf_rnd_init();
1318 extern boolean_t kcf_rngprov_check(void);
1319 extern int kcf_rnd_get_pseudo_bytes(uint8_t *, size_t);
1320 extern int kcf_rnd_get_bytes(uint8_t *, size_t, boolean_t, boolean_t);
1321 extern int random_add_pseudo_entropy(uint8_t *, size_t, uint_t);
1322 extern void kcf_rnd_chpoll(int, short *, struct pollhead **);
1323 extern void kcf_rnd_schedule_timeout(boolean_t);
1324 
1325 /* Access to the provider's table */
1326 extern void kcf_prov_tab_init(void);
1327 extern int kcf_prov_tab_add_provider(kcf_provider_desc_t *);
1328 extern int kcf_prov_tab_rem_provider(crypto_provider_id_t);
1329 extern kcf_provider_desc_t *kcf_prov_tab_lookup_by_name(char *);
1330 extern kcf_provider_desc_t *kcf_prov_tab_lookup_by_dev(char *, uint_t);
1331 extern int kcf_get_hw_prov_tab(uint_t *, kcf_provider_desc_t ***, int,
1332     char *, uint_t, boolean_t);
1333 extern int kcf_get_slot_list(uint_t *, kcf_provider_desc_t ***, boolean_t);
1334 extern void kcf_free_provider_tab(uint_t, kcf_provider_desc_t **);
1335 extern kcf_provider_desc_t *kcf_prov_tab_lookup(crypto_provider_id_t);
1336 extern int kcf_get_sw_prov(crypto_mech_type_t, kcf_provider_desc_t **,
1337     kcf_mech_entry_t **, boolean_t);
1338 
1339 /* Access to the policy table */
1340 extern boolean_t is_mech_disabled(kcf_provider_desc_t *, crypto_mech_name_t);
1341 extern boolean_t is_mech_disabled_byname(crypto_provider_type_t, char *,
1342     uint_t, crypto_mech_name_t);
1343 extern void kcf_policy_tab_init(void);
1344 extern void kcf_policy_free_desc(kcf_policy_desc_t *);
1345 extern void kcf_policy_remove_by_name(char *, uint_t *, crypto_mech_name_t **);
1346 extern void kcf_policy_remove_by_dev(char *, uint_t, uint_t *,
1347     crypto_mech_name_t **);
1348 extern kcf_policy_desc_t *kcf_policy_lookup_by_name(char *);
1349 extern kcf_policy_desc_t *kcf_policy_lookup_by_dev(char *, uint_t);
1350 extern int kcf_policy_load_soft_disabled(char *, uint_t, crypto_mech_name_t *,
1351     uint_t *, crypto_mech_name_t **);
1352 extern int kcf_policy_load_dev_disabled(char *, uint_t, uint_t,
1353     crypto_mech_name_t *, uint_t *, crypto_mech_name_t **);
1354 extern boolean_t in_soft_config_list(char *);
1355 
1356 #endif	/* _KERNEL */
1357 
1358 #ifdef	__cplusplus
1359 }
1360 #endif
1361 
1362 #endif	/* _SYS_CRYPTO_IMPL_H */
1363