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