xref: /onnv-gate/usr/src/uts/common/crypto/api/kcf_verify.c (revision 10444:713f936eb685)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51808Smcpowers  * Common Development and Distribution License (the "License").
61808Smcpowers  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10444SVladimir.Kotal@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/errno.h>
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/kmem.h>
29904Smcpowers #include <sys/sysmacros.h>
300Sstevel@tonic-gate #include <sys/crypto/common.h>
310Sstevel@tonic-gate #include <sys/crypto/impl.h>
320Sstevel@tonic-gate #include <sys/crypto/api.h>
330Sstevel@tonic-gate #include <sys/crypto/spi.h>
340Sstevel@tonic-gate #include <sys/crypto/sched_impl.h>
350Sstevel@tonic-gate 
36904Smcpowers #define	CRYPTO_OPS_OFFSET(f)		offsetof(crypto_ops_t, co_##f)
37904Smcpowers #define	CRYPTO_VERIFY_OFFSET(f)		offsetof(crypto_verify_ops_t, f)
38904Smcpowers 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Verify entry points.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * See comments for crypto_digest_init_prov().
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate int
47904Smcpowers crypto_verify_init_prov(crypto_provider_t provider, crypto_session_id_t sid,
480Sstevel@tonic-gate     crypto_mechanism_t *mech, crypto_key_t *key, crypto_ctx_template_t tmpl,
490Sstevel@tonic-gate     crypto_context_t *ctxp, crypto_call_req_t *crq)
500Sstevel@tonic-gate {
51904Smcpowers 	int rv;
520Sstevel@tonic-gate 	crypto_ctx_t *ctx;
530Sstevel@tonic-gate 	kcf_req_params_t params;
54904Smcpowers 	kcf_provider_desc_t *pd = provider;
55904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
560Sstevel@tonic-gate 
57904Smcpowers 	ASSERT(KCF_PROV_REFHELD(pd));
58904Smcpowers 
59904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
60*10444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
61*10444SVladimir.Kotal@Sun.COM 		    CRYPTO_MECH_INVALID, NULL, CHECK_RESTRICT(crq), pd,
621808Smcpowers 		    &real_provider, CRYPTO_FG_VERIFY);
63904Smcpowers 
64904Smcpowers 		if (rv != CRYPTO_SUCCESS)
65904Smcpowers 			return (rv);
66904Smcpowers 	}
67904Smcpowers 
68904Smcpowers 	/* Allocate and initialize the canonical context */
69904Smcpowers 	if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) {
70904Smcpowers 		if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
71904Smcpowers 			KCF_PROV_REFRELE(real_provider);
720Sstevel@tonic-gate 		return (CRYPTO_HOST_MEMORY);
73904Smcpowers 	}
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_INIT, sid, mech,
760Sstevel@tonic-gate 	    key, NULL, NULL, tmpl);
77904Smcpowers 	rv = kcf_submit_request(real_provider, ctx, crq, &params, B_FALSE);
78904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
79904Smcpowers 		KCF_PROV_REFRELE(real_provider);
800Sstevel@tonic-gate 
81904Smcpowers 	if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED))
820Sstevel@tonic-gate 		*ctxp = (crypto_context_t)ctx;
830Sstevel@tonic-gate 	else {
840Sstevel@tonic-gate 		/* Release the hold done in kcf_new_ctx(). */
850Sstevel@tonic-gate 		KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 
88904Smcpowers 	return (rv);
890Sstevel@tonic-gate }
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 
920Sstevel@tonic-gate int
930Sstevel@tonic-gate crypto_verify_init(crypto_mechanism_t *mech, crypto_key_t *key,
940Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 	int error;
970Sstevel@tonic-gate 	kcf_mech_entry_t *me;
980Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
990Sstevel@tonic-gate 	kcf_prov_tried_t *list = NULL;
1000Sstevel@tonic-gate 	kcf_ctx_template_t *ctx_tmpl;
1010Sstevel@tonic-gate 	crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate retry:
1040Sstevel@tonic-gate 	/* The pd is returned held */
105*10444SVladimir.Kotal@Sun.COM 	if ((pd = kcf_get_mech_provider(mech->cm_type, key, &me, &error,
1060Sstevel@tonic-gate 	    list, CRYPTO_FG_VERIFY, CHECK_RESTRICT(crq), 0)) == NULL) {
1070Sstevel@tonic-gate 		if (list != NULL)
1080Sstevel@tonic-gate 			kcf_free_triedlist(list);
1090Sstevel@tonic-gate 		return (error);
1100Sstevel@tonic-gate 	}
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	/*
1130Sstevel@tonic-gate 	 * For SW providers, check the validity of the context template
1140Sstevel@tonic-gate 	 * It is very rare that the generation number mis-matches, so
1150Sstevel@tonic-gate 	 * it is acceptable to fail here, and let the consumer recover by
1160Sstevel@tonic-gate 	 * freeing this tmpl and create a new one for the key and new SW
1170Sstevel@tonic-gate 	 * provider.
1180Sstevel@tonic-gate 	 */
1190Sstevel@tonic-gate 	if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
1200Sstevel@tonic-gate 	    ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
1210Sstevel@tonic-gate 		if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
1220Sstevel@tonic-gate 			if (list != NULL)
1230Sstevel@tonic-gate 				kcf_free_triedlist(list);
1240Sstevel@tonic-gate 			KCF_PROV_REFRELE(pd);
1250Sstevel@tonic-gate 			return (CRYPTO_OLD_CTX_TEMPLATE);
1260Sstevel@tonic-gate 		} else {
1270Sstevel@tonic-gate 			spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
1280Sstevel@tonic-gate 		}
1290Sstevel@tonic-gate 	}
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	error = crypto_verify_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl,
1320Sstevel@tonic-gate 	    ctxp, crq);
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
1350Sstevel@tonic-gate 	    IS_RECOVERABLE(error)) {
1360Sstevel@tonic-gate 		/* Add pd to the linked list of providers tried. */
1370Sstevel@tonic-gate 		if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
1380Sstevel@tonic-gate 			goto retry;
1390Sstevel@tonic-gate 	}
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	if (list != NULL)
1420Sstevel@tonic-gate 		kcf_free_triedlist(list);
1430Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
1440Sstevel@tonic-gate 	return (error);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate int
1480Sstevel@tonic-gate crypto_verify_single(crypto_context_t context, crypto_data_t *data,
1490Sstevel@tonic-gate     crypto_data_t *signature, crypto_call_req_t *cr)
1500Sstevel@tonic-gate {
1510Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
1520Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
1530Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
1540Sstevel@tonic-gate 	int error;
1550Sstevel@tonic-gate 	kcf_req_params_t params;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	if ((ctx == NULL) ||
1580Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
1590Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
1600Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_SINGLE, 0, NULL,
1640Sstevel@tonic-gate 	    NULL, data, signature, NULL);
1650Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
1680Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
1690Sstevel@tonic-gate 	return (error);
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate  * See comments for crypto_digest_update().
1740Sstevel@tonic-gate  */
1750Sstevel@tonic-gate int
1760Sstevel@tonic-gate crypto_verify_update(crypto_context_t context, crypto_data_t *data,
1770Sstevel@tonic-gate     crypto_call_req_t *cr)
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
1810Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
1820Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
1830Sstevel@tonic-gate 	kcf_req_params_t params;
184904Smcpowers 	int rv;
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	if ((ctx == NULL) ||
1870Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
1880Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
1890Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
1900Sstevel@tonic-gate 	}
1910Sstevel@tonic-gate 
192904Smcpowers 	ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER);
193904Smcpowers 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_UPDATE, ctx->cc_session,
194904Smcpowers 	    NULL, NULL, data, NULL, NULL);
195904Smcpowers 	rv = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
1960Sstevel@tonic-gate 
197904Smcpowers 	return (rv);
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * See comments for crypto_digest_final().
2020Sstevel@tonic-gate  */
2030Sstevel@tonic-gate int
2040Sstevel@tonic-gate crypto_verify_final(crypto_context_t context, crypto_data_t *signature,
2050Sstevel@tonic-gate     crypto_call_req_t *cr)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
2080Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
2090Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
2100Sstevel@tonic-gate 	kcf_req_params_t params;
211904Smcpowers 	int rv;
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	if ((ctx == NULL) ||
2140Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
2150Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
2160Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
2170Sstevel@tonic-gate 	}
2180Sstevel@tonic-gate 
219904Smcpowers 	ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER);
220904Smcpowers 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_FINAL, ctx->cc_session,
221904Smcpowers 	    NULL, NULL, NULL, signature, NULL);
222904Smcpowers 	rv = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
225904Smcpowers 	KCF_CONTEXT_COND_RELEASE(rv, kcf_ctx);
226904Smcpowers 	return (rv);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate int
230904Smcpowers crypto_verify_prov(crypto_provider_t provider, crypto_session_id_t sid,
231904Smcpowers     crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
232904Smcpowers     crypto_ctx_template_t tmpl, crypto_data_t *signature,
2330Sstevel@tonic-gate     crypto_call_req_t *crq)
2340Sstevel@tonic-gate {
2350Sstevel@tonic-gate 	kcf_req_params_t params;
236904Smcpowers 	kcf_provider_desc_t *pd = provider;
237904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
238904Smcpowers 	int rv;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	ASSERT(KCF_PROV_REFHELD(pd));
241904Smcpowers 
242904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
243*10444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
244*10444SVladimir.Kotal@Sun.COM 		    CRYPTO_MECH_INVALID, NULL, CHECK_RESTRICT(crq),
2451808Smcpowers 		    pd, &real_provider, CRYPTO_FG_VERIFY_ATOMIC);
246904Smcpowers 
247904Smcpowers 		if (rv != CRYPTO_SUCCESS)
248904Smcpowers 			return (rv);
249904Smcpowers 	}
2500Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_ATOMIC, sid, mech,
2510Sstevel@tonic-gate 	    key, data, signature, tmpl);
252904Smcpowers 	rv = kcf_submit_request(real_provider, NULL, crq, &params, B_FALSE);
253904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
254904Smcpowers 		KCF_PROV_REFRELE(real_provider);
2550Sstevel@tonic-gate 
256904Smcpowers 	return (rv);
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate static int
2600Sstevel@tonic-gate verify_vr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key,
2610Sstevel@tonic-gate     crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
2620Sstevel@tonic-gate     crypto_call_req_t *crq, crypto_func_group_t fg)
2630Sstevel@tonic-gate {
2640Sstevel@tonic-gate 	int error;
2650Sstevel@tonic-gate 	kcf_mech_entry_t *me;
2660Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
2670Sstevel@tonic-gate 	kcf_req_params_t params;
2680Sstevel@tonic-gate 	kcf_prov_tried_t *list = NULL;
2690Sstevel@tonic-gate 	kcf_ctx_template_t *ctx_tmpl;
2700Sstevel@tonic-gate 	crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate retry:
2730Sstevel@tonic-gate 	/* The pd is returned held */
274*10444SVladimir.Kotal@Sun.COM 	if ((pd = kcf_get_mech_provider(mech->cm_type, key, &me, &error,
275*10444SVladimir.Kotal@Sun.COM 	    list, fg, CHECK_RESTRICT(crq), data->cd_length)) == NULL) {
2760Sstevel@tonic-gate 		if (list != NULL)
2770Sstevel@tonic-gate 			kcf_free_triedlist(list);
2780Sstevel@tonic-gate 		return (error);
2790Sstevel@tonic-gate 	}
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	/*
2820Sstevel@tonic-gate 	 * For SW providers, check the validity of the context template
2830Sstevel@tonic-gate 	 * It is very rare that the generation number mis-matches, so
2840Sstevel@tonic-gate 	 * it is acceptable to fail here, and let the consumer recover by
2850Sstevel@tonic-gate 	 * freeing this tmpl and create a new one for the key and new SW
2860Sstevel@tonic-gate 	 * provider.
2870Sstevel@tonic-gate 	 */
2880Sstevel@tonic-gate 	if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
2890Sstevel@tonic-gate 	    ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
2900Sstevel@tonic-gate 		if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
2910Sstevel@tonic-gate 			if (list != NULL)
2920Sstevel@tonic-gate 				kcf_free_triedlist(list);
2930Sstevel@tonic-gate 			KCF_PROV_REFRELE(pd);
2940Sstevel@tonic-gate 			return (CRYPTO_OLD_CTX_TEMPLATE);
2950Sstevel@tonic-gate 		} else {
2960Sstevel@tonic-gate 			spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
2970Sstevel@tonic-gate 		}
2980Sstevel@tonic-gate 	}
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	/* The fast path for SW providers. */
3010Sstevel@tonic-gate 	if (CHECK_FASTPATH(crq, pd)) {
3020Sstevel@tonic-gate 		crypto_mechanism_t lmech;
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate 		lmech = *mech;
3050Sstevel@tonic-gate 		KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech);
3060Sstevel@tonic-gate 		if (fg == CRYPTO_FG_VERIFY_ATOMIC)
3070Sstevel@tonic-gate 			error = KCF_PROV_VERIFY_ATOMIC(pd, pd->pd_sid, &lmech,
3080Sstevel@tonic-gate 			    key, data, spi_ctx_tmpl, signature,
3090Sstevel@tonic-gate 			    KCF_SWFP_RHNDL(crq));
3100Sstevel@tonic-gate 		else
3110Sstevel@tonic-gate 			/* Note: The argument order is different from above */
3120Sstevel@tonic-gate 			error = KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, pd->pd_sid,
3130Sstevel@tonic-gate 			    &lmech, key, signature, spi_ctx_tmpl, data,
3140Sstevel@tonic-gate 			    KCF_SWFP_RHNDL(crq));
3150Sstevel@tonic-gate 		KCF_PROV_INCRSTATS(pd, error);
3160Sstevel@tonic-gate 	} else {
3170Sstevel@tonic-gate 		kcf_op_type_t op = ((fg == CRYPTO_FG_VERIFY_ATOMIC) ?
3180Sstevel@tonic-gate 		    KCF_OP_ATOMIC : KCF_OP_VERIFY_RECOVER_ATOMIC);
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 		KCF_WRAP_VERIFY_OPS_PARAMS(&params, op, pd->pd_sid,
3210Sstevel@tonic-gate 		    mech, key, data, signature, spi_ctx_tmpl);
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 		/* no crypto context to carry between multiple parts. */
3240Sstevel@tonic-gate 		error = kcf_submit_request(pd, NULL, crq, &params, B_FALSE);
3250Sstevel@tonic-gate 	}
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 	if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
3280Sstevel@tonic-gate 	    IS_RECOVERABLE(error)) {
3290Sstevel@tonic-gate 		/* Add pd to the linked list of providers tried. */
3300Sstevel@tonic-gate 		if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
3310Sstevel@tonic-gate 			goto retry;
3320Sstevel@tonic-gate 	}
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	if (list != NULL)
3350Sstevel@tonic-gate 		kcf_free_triedlist(list);
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
3380Sstevel@tonic-gate 	return (error);
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate int
3420Sstevel@tonic-gate crypto_verify(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
3430Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_data_t *signature,
3440Sstevel@tonic-gate     crypto_call_req_t *crq)
3450Sstevel@tonic-gate {
3460Sstevel@tonic-gate 	return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq,
3470Sstevel@tonic-gate 	    CRYPTO_FG_VERIFY_ATOMIC));
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate int
351904Smcpowers crypto_verify_recover_prov(crypto_provider_t provider, crypto_session_id_t sid,
352904Smcpowers     crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *signature,
353904Smcpowers     crypto_ctx_template_t tmpl, crypto_data_t *data, crypto_call_req_t *crq)
3540Sstevel@tonic-gate {
3550Sstevel@tonic-gate 	kcf_req_params_t params;
356904Smcpowers 	kcf_provider_desc_t *pd = provider;
357904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
358904Smcpowers 	int rv;
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	ASSERT(KCF_PROV_REFHELD(pd));
361904Smcpowers 
362904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
363*10444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
364*10444SVladimir.Kotal@Sun.COM 		    CRYPTO_MECH_INVALID, NULL, CHECK_RESTRICT(crq), pd,
3651808Smcpowers 		    &real_provider, CRYPTO_FG_VERIFY_RECOVER_ATOMIC);
366904Smcpowers 
367904Smcpowers 		if (rv != CRYPTO_SUCCESS)
368904Smcpowers 			return (rv);
369904Smcpowers 	}
3700Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER_ATOMIC,
3710Sstevel@tonic-gate 	    sid, mech, key, data, signature, tmpl);
372904Smcpowers 	rv = kcf_submit_request(real_provider, NULL, crq, &params, B_FALSE);
373904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
374904Smcpowers 		KCF_PROV_REFRELE(real_provider);
3750Sstevel@tonic-gate 
376904Smcpowers 	return (rv);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate int
3800Sstevel@tonic-gate crypto_verify_recover(crypto_mechanism_t *mech, crypto_key_t *key,
3810Sstevel@tonic-gate     crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data,
3820Sstevel@tonic-gate     crypto_call_req_t *crq)
3830Sstevel@tonic-gate {
3840Sstevel@tonic-gate 	return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq,
3850Sstevel@tonic-gate 	    CRYPTO_FG_VERIFY_RECOVER_ATOMIC));
3860Sstevel@tonic-gate }
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate int
389904Smcpowers crypto_verify_recover_init_prov(crypto_provider_t provider,
3900Sstevel@tonic-gate     crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key,
3910Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
3920Sstevel@tonic-gate {
393904Smcpowers 	int rv;
3940Sstevel@tonic-gate 	crypto_ctx_t *ctx;
3950Sstevel@tonic-gate 	kcf_req_params_t params;
396904Smcpowers 	kcf_provider_desc_t *pd = provider;
397904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
3980Sstevel@tonic-gate 
399904Smcpowers 	ASSERT(KCF_PROV_REFHELD(pd));
400904Smcpowers 
401904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
402*10444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
403*10444SVladimir.Kotal@Sun.COM 		    CRYPTO_MECH_INVALID, NULL, CHECK_RESTRICT(crq), pd,
4041808Smcpowers 		    &real_provider, CRYPTO_FG_VERIFY_RECOVER);
405904Smcpowers 
406904Smcpowers 		if (rv != CRYPTO_SUCCESS)
407904Smcpowers 			return (rv);
408904Smcpowers 	}
409904Smcpowers 
410904Smcpowers 	/* Allocate and initialize the canonical context */
411904Smcpowers 	if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) {
412904Smcpowers 		if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
413904Smcpowers 			KCF_PROV_REFRELE(real_provider);
4140Sstevel@tonic-gate 		return (CRYPTO_HOST_MEMORY);
415904Smcpowers 	}
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER_INIT,
4180Sstevel@tonic-gate 	    sid, mech, key, NULL, NULL, tmpl);
419904Smcpowers 	rv = kcf_submit_request(real_provider, ctx, crq, &params, B_FALSE);
420904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
421904Smcpowers 		KCF_PROV_REFRELE(real_provider);
4220Sstevel@tonic-gate 
423904Smcpowers 	if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED))
4240Sstevel@tonic-gate 		*ctxp = (crypto_context_t)ctx;
4250Sstevel@tonic-gate 	else {
4260Sstevel@tonic-gate 		/* Release the hold done in kcf_new_ctx(). */
4270Sstevel@tonic-gate 		KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
4280Sstevel@tonic-gate 	}
4290Sstevel@tonic-gate 
430904Smcpowers 	return (rv);
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate int
4340Sstevel@tonic-gate crypto_verify_recover_single(crypto_context_t context, crypto_data_t *signature,
4350Sstevel@tonic-gate     crypto_data_t *data, crypto_call_req_t *cr)
4360Sstevel@tonic-gate {
4370Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
4380Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
4390Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
4400Sstevel@tonic-gate 	int error;
4410Sstevel@tonic-gate 	kcf_req_params_t params;
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate 	if ((ctx == NULL) ||
4440Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
4450Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
4460Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
4470Sstevel@tonic-gate 	}
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER, 0, NULL,
4500Sstevel@tonic-gate 	    NULL, data, signature, NULL);
4510Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
4540Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
4550Sstevel@tonic-gate 	return (error);
4560Sstevel@tonic-gate }
457