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