xref: /onnv-gate/usr/src/uts/common/crypto/api/kcf_verify.c (revision 12304:bcfa0838b31e)
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*12304SValerie.Fenwick@Oracle.COM  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #include <sys/errno.h>
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/kmem.h>
28904Smcpowers #include <sys/sysmacros.h>
290Sstevel@tonic-gate #include <sys/crypto/common.h>
300Sstevel@tonic-gate #include <sys/crypto/impl.h>
310Sstevel@tonic-gate #include <sys/crypto/api.h>
320Sstevel@tonic-gate #include <sys/crypto/spi.h>
330Sstevel@tonic-gate #include <sys/crypto/sched_impl.h>
340Sstevel@tonic-gate 
35904Smcpowers #define	CRYPTO_OPS_OFFSET(f)		offsetof(crypto_ops_t, co_##f)
36904Smcpowers #define	CRYPTO_VERIFY_OFFSET(f)		offsetof(crypto_verify_ops_t, f)
37904Smcpowers 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * Verify entry points.
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * See comments for crypto_digest_init_prov().
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate int
crypto_verify_init_prov(crypto_provider_t provider,crypto_session_id_t sid,crypto_mechanism_t * mech,crypto_key_t * key,crypto_ctx_template_t tmpl,crypto_context_t * ctxp,crypto_call_req_t * crq)46904Smcpowers crypto_verify_init_prov(crypto_provider_t provider, crypto_session_id_t sid,
470Sstevel@tonic-gate     crypto_mechanism_t *mech, crypto_key_t *key, crypto_ctx_template_t tmpl,
480Sstevel@tonic-gate     crypto_context_t *ctxp, crypto_call_req_t *crq)
490Sstevel@tonic-gate {
50904Smcpowers 	int rv;
510Sstevel@tonic-gate 	crypto_ctx_t *ctx;
520Sstevel@tonic-gate 	kcf_req_params_t params;
53904Smcpowers 	kcf_provider_desc_t *pd = provider;
54904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
550Sstevel@tonic-gate 
56904Smcpowers 	ASSERT(KCF_PROV_REFHELD(pd));
57904Smcpowers 
58904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
5910444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
60*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
61*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_FG_VERIFY);
62904Smcpowers 
63904Smcpowers 		if (rv != CRYPTO_SUCCESS)
64904Smcpowers 			return (rv);
65904Smcpowers 	}
66904Smcpowers 
67904Smcpowers 	/* Allocate and initialize the canonical context */
68904Smcpowers 	if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) {
69904Smcpowers 		if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
70904Smcpowers 			KCF_PROV_REFRELE(real_provider);
710Sstevel@tonic-gate 		return (CRYPTO_HOST_MEMORY);
72904Smcpowers 	}
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_INIT, sid, mech,
750Sstevel@tonic-gate 	    key, NULL, NULL, tmpl);
76904Smcpowers 	rv = kcf_submit_request(real_provider, ctx, crq, &params, B_FALSE);
77904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
78904Smcpowers 		KCF_PROV_REFRELE(real_provider);
790Sstevel@tonic-gate 
80904Smcpowers 	if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED))
810Sstevel@tonic-gate 		*ctxp = (crypto_context_t)ctx;
820Sstevel@tonic-gate 	else {
830Sstevel@tonic-gate 		/* Release the hold done in kcf_new_ctx(). */
840Sstevel@tonic-gate 		KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate 
87904Smcpowers 	return (rv);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 
910Sstevel@tonic-gate int
crypto_verify_init(crypto_mechanism_t * mech,crypto_key_t * key,crypto_ctx_template_t tmpl,crypto_context_t * ctxp,crypto_call_req_t * crq)920Sstevel@tonic-gate crypto_verify_init(crypto_mechanism_t *mech, crypto_key_t *key,
930Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	int error;
960Sstevel@tonic-gate 	kcf_mech_entry_t *me;
970Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
980Sstevel@tonic-gate 	kcf_prov_tried_t *list = NULL;
990Sstevel@tonic-gate 	kcf_ctx_template_t *ctx_tmpl;
1000Sstevel@tonic-gate 	crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate retry:
1030Sstevel@tonic-gate 	/* The pd is returned held */
10410444SVladimir.Kotal@Sun.COM 	if ((pd = kcf_get_mech_provider(mech->cm_type, key, &me, &error,
105*12304SValerie.Fenwick@Oracle.COM 	    list, CRYPTO_FG_VERIFY, 0)) == NULL) {
1060Sstevel@tonic-gate 		if (list != NULL)
1070Sstevel@tonic-gate 			kcf_free_triedlist(list);
1080Sstevel@tonic-gate 		return (error);
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	/*
1120Sstevel@tonic-gate 	 * For SW providers, check the validity of the context template
1130Sstevel@tonic-gate 	 * It is very rare that the generation number mis-matches, so
1140Sstevel@tonic-gate 	 * it is acceptable to fail here, and let the consumer recover by
1150Sstevel@tonic-gate 	 * freeing this tmpl and create a new one for the key and new SW
1160Sstevel@tonic-gate 	 * provider.
1170Sstevel@tonic-gate 	 */
1180Sstevel@tonic-gate 	if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
1190Sstevel@tonic-gate 	    ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
1200Sstevel@tonic-gate 		if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
1210Sstevel@tonic-gate 			if (list != NULL)
1220Sstevel@tonic-gate 				kcf_free_triedlist(list);
1230Sstevel@tonic-gate 			KCF_PROV_REFRELE(pd);
1240Sstevel@tonic-gate 			return (CRYPTO_OLD_CTX_TEMPLATE);
1250Sstevel@tonic-gate 		} else {
1260Sstevel@tonic-gate 			spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
1270Sstevel@tonic-gate 		}
1280Sstevel@tonic-gate 	}
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	error = crypto_verify_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl,
1310Sstevel@tonic-gate 	    ctxp, crq);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
1340Sstevel@tonic-gate 	    IS_RECOVERABLE(error)) {
1350Sstevel@tonic-gate 		/* Add pd to the linked list of providers tried. */
1360Sstevel@tonic-gate 		if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
1370Sstevel@tonic-gate 			goto retry;
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	if (list != NULL)
1410Sstevel@tonic-gate 		kcf_free_triedlist(list);
1420Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
1430Sstevel@tonic-gate 	return (error);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate int
crypto_verify_single(crypto_context_t context,crypto_data_t * data,crypto_data_t * signature,crypto_call_req_t * cr)1470Sstevel@tonic-gate crypto_verify_single(crypto_context_t context, crypto_data_t *data,
1480Sstevel@tonic-gate     crypto_data_t *signature, crypto_call_req_t *cr)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
1510Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
1520Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
1530Sstevel@tonic-gate 	int error;
1540Sstevel@tonic-gate 	kcf_req_params_t params;
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	if ((ctx == NULL) ||
1570Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
1580Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
1590Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
1600Sstevel@tonic-gate 	}
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_SINGLE, 0, NULL,
1630Sstevel@tonic-gate 	    NULL, data, signature, NULL);
1640Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
1670Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
1680Sstevel@tonic-gate 	return (error);
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * See comments for crypto_digest_update().
1730Sstevel@tonic-gate  */
1740Sstevel@tonic-gate int
crypto_verify_update(crypto_context_t context,crypto_data_t * data,crypto_call_req_t * cr)1750Sstevel@tonic-gate crypto_verify_update(crypto_context_t context, crypto_data_t *data,
1760Sstevel@tonic-gate     crypto_call_req_t *cr)
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate {
1790Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
1800Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
1810Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
1820Sstevel@tonic-gate 	kcf_req_params_t params;
183904Smcpowers 	int rv;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	if ((ctx == NULL) ||
1860Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
1870Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
1880Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
1890Sstevel@tonic-gate 	}
1900Sstevel@tonic-gate 
191904Smcpowers 	ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER);
192904Smcpowers 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_UPDATE, ctx->cc_session,
193904Smcpowers 	    NULL, NULL, data, NULL, NULL);
194904Smcpowers 	rv = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
1950Sstevel@tonic-gate 
196904Smcpowers 	return (rv);
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate  * See comments for crypto_digest_final().
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate int
crypto_verify_final(crypto_context_t context,crypto_data_t * signature,crypto_call_req_t * cr)2030Sstevel@tonic-gate crypto_verify_final(crypto_context_t context, crypto_data_t *signature,
2040Sstevel@tonic-gate     crypto_call_req_t *cr)
2050Sstevel@tonic-gate {
2060Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
2070Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
2080Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
2090Sstevel@tonic-gate 	kcf_req_params_t params;
210904Smcpowers 	int rv;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	if ((ctx == NULL) ||
2130Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
2140Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
2150Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
2160Sstevel@tonic-gate 	}
2170Sstevel@tonic-gate 
218904Smcpowers 	ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER);
219904Smcpowers 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_FINAL, ctx->cc_session,
220904Smcpowers 	    NULL, NULL, NULL, signature, NULL);
221904Smcpowers 	rv = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
224904Smcpowers 	KCF_CONTEXT_COND_RELEASE(rv, kcf_ctx);
225904Smcpowers 	return (rv);
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate int
crypto_verify_prov(crypto_provider_t provider,crypto_session_id_t sid,crypto_mechanism_t * mech,crypto_key_t * key,crypto_data_t * data,crypto_ctx_template_t tmpl,crypto_data_t * signature,crypto_call_req_t * crq)229904Smcpowers crypto_verify_prov(crypto_provider_t provider, crypto_session_id_t sid,
230904Smcpowers     crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
231904Smcpowers     crypto_ctx_template_t tmpl, crypto_data_t *signature,
2320Sstevel@tonic-gate     crypto_call_req_t *crq)
2330Sstevel@tonic-gate {
2340Sstevel@tonic-gate 	kcf_req_params_t params;
235904Smcpowers 	kcf_provider_desc_t *pd = provider;
236904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
237904Smcpowers 	int rv;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	ASSERT(KCF_PROV_REFHELD(pd));
240904Smcpowers 
241904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
24210444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
243*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
244*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_FG_VERIFY_ATOMIC);
245904Smcpowers 
246904Smcpowers 		if (rv != CRYPTO_SUCCESS)
247904Smcpowers 			return (rv);
248904Smcpowers 	}
2490Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_ATOMIC, sid, mech,
2500Sstevel@tonic-gate 	    key, data, signature, tmpl);
251904Smcpowers 	rv = kcf_submit_request(real_provider, NULL, crq, &params, B_FALSE);
252904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
253904Smcpowers 		KCF_PROV_REFRELE(real_provider);
2540Sstevel@tonic-gate 
255904Smcpowers 	return (rv);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate static int
verify_vr_atomic_common(crypto_mechanism_t * mech,crypto_key_t * key,crypto_data_t * data,crypto_ctx_template_t tmpl,crypto_data_t * signature,crypto_call_req_t * crq,crypto_func_group_t fg)2590Sstevel@tonic-gate verify_vr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key,
2600Sstevel@tonic-gate     crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
2610Sstevel@tonic-gate     crypto_call_req_t *crq, crypto_func_group_t fg)
2620Sstevel@tonic-gate {
2630Sstevel@tonic-gate 	int error;
2640Sstevel@tonic-gate 	kcf_mech_entry_t *me;
2650Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
2660Sstevel@tonic-gate 	kcf_req_params_t params;
2670Sstevel@tonic-gate 	kcf_prov_tried_t *list = NULL;
2680Sstevel@tonic-gate 	kcf_ctx_template_t *ctx_tmpl;
2690Sstevel@tonic-gate 	crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate retry:
2720Sstevel@tonic-gate 	/* The pd is returned held */
27310444SVladimir.Kotal@Sun.COM 	if ((pd = kcf_get_mech_provider(mech->cm_type, key, &me, &error,
274*12304SValerie.Fenwick@Oracle.COM 	    list, fg, data->cd_length)) == NULL) {
2750Sstevel@tonic-gate 		if (list != NULL)
2760Sstevel@tonic-gate 			kcf_free_triedlist(list);
2770Sstevel@tonic-gate 		return (error);
2780Sstevel@tonic-gate 	}
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 	/*
2810Sstevel@tonic-gate 	 * For SW providers, check the validity of the context template
2820Sstevel@tonic-gate 	 * It is very rare that the generation number mis-matches, so
2830Sstevel@tonic-gate 	 * it is acceptable to fail here, and let the consumer recover by
2840Sstevel@tonic-gate 	 * freeing this tmpl and create a new one for the key and new SW
2850Sstevel@tonic-gate 	 * provider.
2860Sstevel@tonic-gate 	 */
2870Sstevel@tonic-gate 	if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
2880Sstevel@tonic-gate 	    ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
2890Sstevel@tonic-gate 		if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
2900Sstevel@tonic-gate 			if (list != NULL)
2910Sstevel@tonic-gate 				kcf_free_triedlist(list);
2920Sstevel@tonic-gate 			KCF_PROV_REFRELE(pd);
2930Sstevel@tonic-gate 			return (CRYPTO_OLD_CTX_TEMPLATE);
2940Sstevel@tonic-gate 		} else {
2950Sstevel@tonic-gate 			spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
2960Sstevel@tonic-gate 		}
2970Sstevel@tonic-gate 	}
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate 	/* The fast path for SW providers. */
3000Sstevel@tonic-gate 	if (CHECK_FASTPATH(crq, pd)) {
3010Sstevel@tonic-gate 		crypto_mechanism_t lmech;
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate 		lmech = *mech;
3040Sstevel@tonic-gate 		KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech);
3050Sstevel@tonic-gate 		if (fg == CRYPTO_FG_VERIFY_ATOMIC)
3060Sstevel@tonic-gate 			error = KCF_PROV_VERIFY_ATOMIC(pd, pd->pd_sid, &lmech,
3070Sstevel@tonic-gate 			    key, data, spi_ctx_tmpl, signature,
3080Sstevel@tonic-gate 			    KCF_SWFP_RHNDL(crq));
3090Sstevel@tonic-gate 		else
3100Sstevel@tonic-gate 			/* Note: The argument order is different from above */
3110Sstevel@tonic-gate 			error = KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, pd->pd_sid,
3120Sstevel@tonic-gate 			    &lmech, key, signature, spi_ctx_tmpl, data,
3130Sstevel@tonic-gate 			    KCF_SWFP_RHNDL(crq));
3140Sstevel@tonic-gate 		KCF_PROV_INCRSTATS(pd, error);
3150Sstevel@tonic-gate 	} else {
3160Sstevel@tonic-gate 		kcf_op_type_t op = ((fg == CRYPTO_FG_VERIFY_ATOMIC) ?
3170Sstevel@tonic-gate 		    KCF_OP_ATOMIC : KCF_OP_VERIFY_RECOVER_ATOMIC);
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 		KCF_WRAP_VERIFY_OPS_PARAMS(&params, op, pd->pd_sid,
3200Sstevel@tonic-gate 		    mech, key, data, signature, spi_ctx_tmpl);
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 		/* no crypto context to carry between multiple parts. */
3230Sstevel@tonic-gate 		error = kcf_submit_request(pd, NULL, crq, &params, B_FALSE);
3240Sstevel@tonic-gate 	}
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
3270Sstevel@tonic-gate 	    IS_RECOVERABLE(error)) {
3280Sstevel@tonic-gate 		/* Add pd to the linked list of providers tried. */
3290Sstevel@tonic-gate 		if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
3300Sstevel@tonic-gate 			goto retry;
3310Sstevel@tonic-gate 	}
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	if (list != NULL)
3340Sstevel@tonic-gate 		kcf_free_triedlist(list);
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
3370Sstevel@tonic-gate 	return (error);
3380Sstevel@tonic-gate }
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate int
crypto_verify(crypto_mechanism_t * mech,crypto_key_t * key,crypto_data_t * data,crypto_ctx_template_t tmpl,crypto_data_t * signature,crypto_call_req_t * crq)3410Sstevel@tonic-gate crypto_verify(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
3420Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_data_t *signature,
3430Sstevel@tonic-gate     crypto_call_req_t *crq)
3440Sstevel@tonic-gate {
3450Sstevel@tonic-gate 	return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq,
3460Sstevel@tonic-gate 	    CRYPTO_FG_VERIFY_ATOMIC));
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate int
crypto_verify_recover_prov(crypto_provider_t provider,crypto_session_id_t sid,crypto_mechanism_t * mech,crypto_key_t * key,crypto_data_t * signature,crypto_ctx_template_t tmpl,crypto_data_t * data,crypto_call_req_t * crq)350904Smcpowers crypto_verify_recover_prov(crypto_provider_t provider, crypto_session_id_t sid,
351904Smcpowers     crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *signature,
352904Smcpowers     crypto_ctx_template_t tmpl, crypto_data_t *data, crypto_call_req_t *crq)
3530Sstevel@tonic-gate {
3540Sstevel@tonic-gate 	kcf_req_params_t params;
355904Smcpowers 	kcf_provider_desc_t *pd = provider;
356904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
357904Smcpowers 	int rv;
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	ASSERT(KCF_PROV_REFHELD(pd));
360904Smcpowers 
361904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
36210444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
363*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
364*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_FG_VERIFY_RECOVER_ATOMIC);
365904Smcpowers 
366904Smcpowers 		if (rv != CRYPTO_SUCCESS)
367904Smcpowers 			return (rv);
368904Smcpowers 	}
3690Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER_ATOMIC,
3700Sstevel@tonic-gate 	    sid, mech, key, data, signature, tmpl);
371904Smcpowers 	rv = kcf_submit_request(real_provider, NULL, crq, &params, B_FALSE);
372904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
373904Smcpowers 		KCF_PROV_REFRELE(real_provider);
3740Sstevel@tonic-gate 
375904Smcpowers 	return (rv);
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate int
crypto_verify_recover(crypto_mechanism_t * mech,crypto_key_t * key,crypto_data_t * signature,crypto_ctx_template_t tmpl,crypto_data_t * data,crypto_call_req_t * crq)3790Sstevel@tonic-gate crypto_verify_recover(crypto_mechanism_t *mech, crypto_key_t *key,
3800Sstevel@tonic-gate     crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data,
3810Sstevel@tonic-gate     crypto_call_req_t *crq)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate 	return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq,
3840Sstevel@tonic-gate 	    CRYPTO_FG_VERIFY_RECOVER_ATOMIC));
3850Sstevel@tonic-gate }
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate int
crypto_verify_recover_init_prov(crypto_provider_t provider,crypto_session_id_t sid,crypto_mechanism_t * mech,crypto_key_t * key,crypto_ctx_template_t tmpl,crypto_context_t * ctxp,crypto_call_req_t * crq)388904Smcpowers crypto_verify_recover_init_prov(crypto_provider_t provider,
3890Sstevel@tonic-gate     crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key,
3900Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
3910Sstevel@tonic-gate {
392904Smcpowers 	int rv;
3930Sstevel@tonic-gate 	crypto_ctx_t *ctx;
3940Sstevel@tonic-gate 	kcf_req_params_t params;
395904Smcpowers 	kcf_provider_desc_t *pd = provider;
396904Smcpowers 	kcf_provider_desc_t *real_provider = pd;
3970Sstevel@tonic-gate 
398904Smcpowers 	ASSERT(KCF_PROV_REFHELD(pd));
399904Smcpowers 
400904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
40110444SVladimir.Kotal@Sun.COM 		rv = kcf_get_hardware_provider(mech->cm_type, key,
402*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
403*12304SValerie.Fenwick@Oracle.COM 		    CRYPTO_FG_VERIFY_RECOVER);
404904Smcpowers 
405904Smcpowers 		if (rv != CRYPTO_SUCCESS)
406904Smcpowers 			return (rv);
407904Smcpowers 	}
408904Smcpowers 
409904Smcpowers 	/* Allocate and initialize the canonical context */
410904Smcpowers 	if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) {
411904Smcpowers 		if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
412904Smcpowers 			KCF_PROV_REFRELE(real_provider);
4130Sstevel@tonic-gate 		return (CRYPTO_HOST_MEMORY);
414904Smcpowers 	}
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER_INIT,
4170Sstevel@tonic-gate 	    sid, mech, key, NULL, NULL, tmpl);
418904Smcpowers 	rv = kcf_submit_request(real_provider, ctx, crq, &params, B_FALSE);
419904Smcpowers 	if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
420904Smcpowers 		KCF_PROV_REFRELE(real_provider);
4210Sstevel@tonic-gate 
422904Smcpowers 	if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED))
4230Sstevel@tonic-gate 		*ctxp = (crypto_context_t)ctx;
4240Sstevel@tonic-gate 	else {
4250Sstevel@tonic-gate 		/* Release the hold done in kcf_new_ctx(). */
4260Sstevel@tonic-gate 		KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
4270Sstevel@tonic-gate 	}
4280Sstevel@tonic-gate 
429904Smcpowers 	return (rv);
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate int
crypto_verify_recover_single(crypto_context_t context,crypto_data_t * signature,crypto_data_t * data,crypto_call_req_t * cr)4330Sstevel@tonic-gate crypto_verify_recover_single(crypto_context_t context, crypto_data_t *signature,
4340Sstevel@tonic-gate     crypto_data_t *data, crypto_call_req_t *cr)
4350Sstevel@tonic-gate {
4360Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
4370Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
4380Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
4390Sstevel@tonic-gate 	int error;
4400Sstevel@tonic-gate 	kcf_req_params_t params;
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate 	if ((ctx == NULL) ||
4430Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
4440Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
4450Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
4460Sstevel@tonic-gate 	}
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER, 0, NULL,
4490Sstevel@tonic-gate 	    NULL, data, signature, NULL);
4500Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
4530Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
4540Sstevel@tonic-gate 	return (error);
4550Sstevel@tonic-gate }
456