xref: /onnv-gate/usr/src/uts/common/crypto/api/kcf_verify.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/errno.h>
30*0Sstevel@tonic-gate #include <sys/types.h>
31*0Sstevel@tonic-gate #include <sys/kmem.h>
32*0Sstevel@tonic-gate #include <sys/crypto/common.h>
33*0Sstevel@tonic-gate #include <sys/crypto/impl.h>
34*0Sstevel@tonic-gate #include <sys/crypto/api.h>
35*0Sstevel@tonic-gate #include <sys/crypto/spi.h>
36*0Sstevel@tonic-gate #include <sys/crypto/sched_impl.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * Verify entry points.
40*0Sstevel@tonic-gate  */
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * See comments for crypto_digest_init_prov().
44*0Sstevel@tonic-gate  */
45*0Sstevel@tonic-gate int
46*0Sstevel@tonic-gate crypto_verify_init_prov(kcf_provider_desc_t *pd, crypto_session_id_t sid,
47*0Sstevel@tonic-gate     crypto_mechanism_t *mech, crypto_key_t *key, crypto_ctx_template_t tmpl,
48*0Sstevel@tonic-gate     crypto_context_t *ctxp, crypto_call_req_t *crq)
49*0Sstevel@tonic-gate {
50*0Sstevel@tonic-gate 	int error;
51*0Sstevel@tonic-gate 	crypto_ctx_t *ctx;
52*0Sstevel@tonic-gate 	kcf_req_params_t params;
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate 	/* First, allocate and initialize the canonical context */
55*0Sstevel@tonic-gate 	if ((ctx = kcf_new_ctx(crq, pd, sid)) == NULL)
56*0Sstevel@tonic-gate 		return (CRYPTO_HOST_MEMORY);
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_INIT, sid, mech,
59*0Sstevel@tonic-gate 	    key, NULL, NULL, tmpl);
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, crq, &params, B_FALSE);
62*0Sstevel@tonic-gate 	if ((error == CRYPTO_SUCCESS) || (error == CRYPTO_QUEUED))
63*0Sstevel@tonic-gate 		*ctxp = (crypto_context_t)ctx;
64*0Sstevel@tonic-gate 	else {
65*0Sstevel@tonic-gate 		/* Release the hold done in kcf_new_ctx(). */
66*0Sstevel@tonic-gate 		KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
67*0Sstevel@tonic-gate 	}
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate 	return (error);
70*0Sstevel@tonic-gate }
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate int
74*0Sstevel@tonic-gate crypto_verify_init(crypto_mechanism_t *mech, crypto_key_t *key,
75*0Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
76*0Sstevel@tonic-gate {
77*0Sstevel@tonic-gate 	int error;
78*0Sstevel@tonic-gate 	kcf_mech_entry_t *me;
79*0Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
80*0Sstevel@tonic-gate 	kcf_prov_tried_t *list = NULL;
81*0Sstevel@tonic-gate 	kcf_ctx_template_t *ctx_tmpl;
82*0Sstevel@tonic-gate 	crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate retry:
85*0Sstevel@tonic-gate 	/* The pd is returned held */
86*0Sstevel@tonic-gate 	if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error,
87*0Sstevel@tonic-gate 	    list, CRYPTO_FG_VERIFY, CHECK_RESTRICT(crq), 0)) == NULL) {
88*0Sstevel@tonic-gate 		if (list != NULL)
89*0Sstevel@tonic-gate 			kcf_free_triedlist(list);
90*0Sstevel@tonic-gate 		return (error);
91*0Sstevel@tonic-gate 	}
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 	/*
94*0Sstevel@tonic-gate 	 * For SW providers, check the validity of the context template
95*0Sstevel@tonic-gate 	 * It is very rare that the generation number mis-matches, so
96*0Sstevel@tonic-gate 	 * it is acceptable to fail here, and let the consumer recover by
97*0Sstevel@tonic-gate 	 * freeing this tmpl and create a new one for the key and new SW
98*0Sstevel@tonic-gate 	 * provider.
99*0Sstevel@tonic-gate 	 */
100*0Sstevel@tonic-gate 	if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
101*0Sstevel@tonic-gate 	    ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
102*0Sstevel@tonic-gate 		if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
103*0Sstevel@tonic-gate 			if (list != NULL)
104*0Sstevel@tonic-gate 				kcf_free_triedlist(list);
105*0Sstevel@tonic-gate 			KCF_PROV_REFRELE(pd);
106*0Sstevel@tonic-gate 			return (CRYPTO_OLD_CTX_TEMPLATE);
107*0Sstevel@tonic-gate 		} else {
108*0Sstevel@tonic-gate 			spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
109*0Sstevel@tonic-gate 		}
110*0Sstevel@tonic-gate 	}
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 	error = crypto_verify_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl,
113*0Sstevel@tonic-gate 	    ctxp, crq);
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
116*0Sstevel@tonic-gate 	    IS_RECOVERABLE(error)) {
117*0Sstevel@tonic-gate 		/* Add pd to the linked list of providers tried. */
118*0Sstevel@tonic-gate 		if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
119*0Sstevel@tonic-gate 			goto retry;
120*0Sstevel@tonic-gate 	}
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate 	if (list != NULL)
123*0Sstevel@tonic-gate 		kcf_free_triedlist(list);
124*0Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
125*0Sstevel@tonic-gate 	return (error);
126*0Sstevel@tonic-gate }
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate int
129*0Sstevel@tonic-gate crypto_verify_single(crypto_context_t context, crypto_data_t *data,
130*0Sstevel@tonic-gate     crypto_data_t *signature, crypto_call_req_t *cr)
131*0Sstevel@tonic-gate {
132*0Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
133*0Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
134*0Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
135*0Sstevel@tonic-gate 	int error;
136*0Sstevel@tonic-gate 	kcf_req_params_t params;
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 	if ((ctx == NULL) ||
139*0Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
140*0Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
141*0Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
142*0Sstevel@tonic-gate 	}
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate 	KCF_PROV_REFHOLD(pd);
145*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_SINGLE, 0, NULL,
146*0Sstevel@tonic-gate 	    NULL, data, signature, NULL);
147*0Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
148*0Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
151*0Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
152*0Sstevel@tonic-gate 	return (error);
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate /*
156*0Sstevel@tonic-gate  * See comments for crypto_digest_update().
157*0Sstevel@tonic-gate  */
158*0Sstevel@tonic-gate int
159*0Sstevel@tonic-gate crypto_verify_update(crypto_context_t context, crypto_data_t *data,
160*0Sstevel@tonic-gate     crypto_call_req_t *cr)
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate {
163*0Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
164*0Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
165*0Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
166*0Sstevel@tonic-gate 	int error;
167*0Sstevel@tonic-gate 	kcf_req_params_t params;
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 	if ((ctx == NULL) ||
170*0Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
171*0Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
172*0Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
173*0Sstevel@tonic-gate 	}
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	KCF_PROV_REFHOLD(pd);
176*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_UPDATE, 0, NULL,
177*0Sstevel@tonic-gate 	    NULL, data, NULL, NULL);
178*0Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
179*0Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate 	return (error);
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate /*
185*0Sstevel@tonic-gate  * See comments for crypto_digest_final().
186*0Sstevel@tonic-gate  */
187*0Sstevel@tonic-gate int
188*0Sstevel@tonic-gate crypto_verify_final(crypto_context_t context, crypto_data_t *signature,
189*0Sstevel@tonic-gate     crypto_call_req_t *cr)
190*0Sstevel@tonic-gate {
191*0Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
192*0Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
193*0Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
194*0Sstevel@tonic-gate 	int error;
195*0Sstevel@tonic-gate 	kcf_req_params_t params;
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 	if ((ctx == NULL) ||
198*0Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
199*0Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
200*0Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
201*0Sstevel@tonic-gate 	}
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 	KCF_PROV_REFHOLD(pd);
204*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_FINAL, 0, NULL,
205*0Sstevel@tonic-gate 	    NULL, NULL, signature, NULL);
206*0Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
207*0Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
210*0Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
211*0Sstevel@tonic-gate 	return (error);
212*0Sstevel@tonic-gate }
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate int
215*0Sstevel@tonic-gate crypto_verify_prov(kcf_provider_desc_t *pd,
216*0Sstevel@tonic-gate     crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key,
217*0Sstevel@tonic-gate     crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
218*0Sstevel@tonic-gate     crypto_call_req_t *crq)
219*0Sstevel@tonic-gate {
220*0Sstevel@tonic-gate 	kcf_req_params_t params;
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 	ASSERT(KCF_PROV_REFHELD(pd));
223*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_ATOMIC, sid, mech,
224*0Sstevel@tonic-gate 	    key, data, signature, tmpl);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	return (kcf_submit_request(pd, NULL, crq, &params, B_FALSE));
227*0Sstevel@tonic-gate }
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate static int
230*0Sstevel@tonic-gate verify_vr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key,
231*0Sstevel@tonic-gate     crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
232*0Sstevel@tonic-gate     crypto_call_req_t *crq, crypto_func_group_t fg)
233*0Sstevel@tonic-gate {
234*0Sstevel@tonic-gate 	int error;
235*0Sstevel@tonic-gate 	kcf_mech_entry_t *me;
236*0Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
237*0Sstevel@tonic-gate 	kcf_req_params_t params;
238*0Sstevel@tonic-gate 	kcf_prov_tried_t *list = NULL;
239*0Sstevel@tonic-gate 	kcf_ctx_template_t *ctx_tmpl;
240*0Sstevel@tonic-gate 	crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate retry:
243*0Sstevel@tonic-gate 	/* The pd is returned held */
244*0Sstevel@tonic-gate 	if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, list, fg,
245*0Sstevel@tonic-gate 	    CHECK_RESTRICT(crq), data->cd_length)) == NULL) {
246*0Sstevel@tonic-gate 		if (list != NULL)
247*0Sstevel@tonic-gate 			kcf_free_triedlist(list);
248*0Sstevel@tonic-gate 		return (error);
249*0Sstevel@tonic-gate 	}
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 	/*
252*0Sstevel@tonic-gate 	 * For SW providers, check the validity of the context template
253*0Sstevel@tonic-gate 	 * It is very rare that the generation number mis-matches, so
254*0Sstevel@tonic-gate 	 * it is acceptable to fail here, and let the consumer recover by
255*0Sstevel@tonic-gate 	 * freeing this tmpl and create a new one for the key and new SW
256*0Sstevel@tonic-gate 	 * provider.
257*0Sstevel@tonic-gate 	 */
258*0Sstevel@tonic-gate 	if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
259*0Sstevel@tonic-gate 	    ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
260*0Sstevel@tonic-gate 		if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
261*0Sstevel@tonic-gate 			if (list != NULL)
262*0Sstevel@tonic-gate 				kcf_free_triedlist(list);
263*0Sstevel@tonic-gate 			KCF_PROV_REFRELE(pd);
264*0Sstevel@tonic-gate 			return (CRYPTO_OLD_CTX_TEMPLATE);
265*0Sstevel@tonic-gate 		} else {
266*0Sstevel@tonic-gate 			spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
267*0Sstevel@tonic-gate 		}
268*0Sstevel@tonic-gate 	}
269*0Sstevel@tonic-gate 
270*0Sstevel@tonic-gate 	/* The fast path for SW providers. */
271*0Sstevel@tonic-gate 	if (CHECK_FASTPATH(crq, pd)) {
272*0Sstevel@tonic-gate 		crypto_mechanism_t lmech;
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate 		lmech = *mech;
275*0Sstevel@tonic-gate 		KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech);
276*0Sstevel@tonic-gate 		if (fg == CRYPTO_FG_VERIFY_ATOMIC)
277*0Sstevel@tonic-gate 			error = KCF_PROV_VERIFY_ATOMIC(pd, pd->pd_sid, &lmech,
278*0Sstevel@tonic-gate 			    key, data, spi_ctx_tmpl, signature,
279*0Sstevel@tonic-gate 			    KCF_SWFP_RHNDL(crq));
280*0Sstevel@tonic-gate 		else
281*0Sstevel@tonic-gate 			/* Note: The argument order is different from above */
282*0Sstevel@tonic-gate 			error = KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, pd->pd_sid,
283*0Sstevel@tonic-gate 			    &lmech, key, signature, spi_ctx_tmpl, data,
284*0Sstevel@tonic-gate 			    KCF_SWFP_RHNDL(crq));
285*0Sstevel@tonic-gate 		KCF_PROV_INCRSTATS(pd, error);
286*0Sstevel@tonic-gate 	} else {
287*0Sstevel@tonic-gate 		kcf_op_type_t op = ((fg == CRYPTO_FG_VERIFY_ATOMIC) ?
288*0Sstevel@tonic-gate 		    KCF_OP_ATOMIC : KCF_OP_VERIFY_RECOVER_ATOMIC);
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 		KCF_WRAP_VERIFY_OPS_PARAMS(&params, op, pd->pd_sid,
291*0Sstevel@tonic-gate 		    mech, key, data, signature, spi_ctx_tmpl);
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate 		/* no crypto context to carry between multiple parts. */
294*0Sstevel@tonic-gate 		error = kcf_submit_request(pd, NULL, crq, &params, B_FALSE);
295*0Sstevel@tonic-gate 	}
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
298*0Sstevel@tonic-gate 	    IS_RECOVERABLE(error)) {
299*0Sstevel@tonic-gate 		/* Add pd to the linked list of providers tried. */
300*0Sstevel@tonic-gate 		if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
301*0Sstevel@tonic-gate 			goto retry;
302*0Sstevel@tonic-gate 	}
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate 	if (list != NULL)
305*0Sstevel@tonic-gate 		kcf_free_triedlist(list);
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
308*0Sstevel@tonic-gate 	return (error);
309*0Sstevel@tonic-gate }
310*0Sstevel@tonic-gate 
311*0Sstevel@tonic-gate int
312*0Sstevel@tonic-gate crypto_verify(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
313*0Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_data_t *signature,
314*0Sstevel@tonic-gate     crypto_call_req_t *crq)
315*0Sstevel@tonic-gate {
316*0Sstevel@tonic-gate 	return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq,
317*0Sstevel@tonic-gate 	    CRYPTO_FG_VERIFY_ATOMIC));
318*0Sstevel@tonic-gate }
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate int
321*0Sstevel@tonic-gate crypto_verify_recover_prov(kcf_provider_desc_t *pd,
322*0Sstevel@tonic-gate     crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key,
323*0Sstevel@tonic-gate     crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data,
324*0Sstevel@tonic-gate     crypto_call_req_t *crq)
325*0Sstevel@tonic-gate {
326*0Sstevel@tonic-gate 	kcf_req_params_t params;
327*0Sstevel@tonic-gate 
328*0Sstevel@tonic-gate 	ASSERT(KCF_PROV_REFHELD(pd));
329*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER_ATOMIC,
330*0Sstevel@tonic-gate 	    sid, mech, key, data, signature, tmpl);
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	return (kcf_submit_request(pd, NULL, crq, &params, B_FALSE));
333*0Sstevel@tonic-gate }
334*0Sstevel@tonic-gate 
335*0Sstevel@tonic-gate int
336*0Sstevel@tonic-gate crypto_verify_recover(crypto_mechanism_t *mech, crypto_key_t *key,
337*0Sstevel@tonic-gate     crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data,
338*0Sstevel@tonic-gate     crypto_call_req_t *crq)
339*0Sstevel@tonic-gate {
340*0Sstevel@tonic-gate 	return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq,
341*0Sstevel@tonic-gate 	    CRYPTO_FG_VERIFY_RECOVER_ATOMIC));
342*0Sstevel@tonic-gate }
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate int
345*0Sstevel@tonic-gate crypto_verify_recover_init_prov(kcf_provider_desc_t *pd,
346*0Sstevel@tonic-gate     crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key,
347*0Sstevel@tonic-gate     crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
348*0Sstevel@tonic-gate {
349*0Sstevel@tonic-gate 	int error;
350*0Sstevel@tonic-gate 	crypto_ctx_t *ctx;
351*0Sstevel@tonic-gate 	kcf_req_params_t params;
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate 	/* First, allocate and initialize the canonical context */
354*0Sstevel@tonic-gate 	if ((ctx = kcf_new_ctx(crq, pd, sid)) == NULL)
355*0Sstevel@tonic-gate 		return (CRYPTO_HOST_MEMORY);
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER_INIT,
358*0Sstevel@tonic-gate 	    sid, mech, key, NULL, NULL, tmpl);
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, crq, &params, B_FALSE);
361*0Sstevel@tonic-gate 	if ((error == CRYPTO_SUCCESS) || (error == CRYPTO_QUEUED))
362*0Sstevel@tonic-gate 		*ctxp = (crypto_context_t)ctx;
363*0Sstevel@tonic-gate 	else {
364*0Sstevel@tonic-gate 		/* Release the hold done in kcf_new_ctx(). */
365*0Sstevel@tonic-gate 		KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
366*0Sstevel@tonic-gate 	}
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate 	return (error);
369*0Sstevel@tonic-gate }
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate int
372*0Sstevel@tonic-gate crypto_verify_recover_single(crypto_context_t context, crypto_data_t *signature,
373*0Sstevel@tonic-gate     crypto_data_t *data, crypto_call_req_t *cr)
374*0Sstevel@tonic-gate {
375*0Sstevel@tonic-gate 	crypto_ctx_t *ctx = (crypto_ctx_t *)context;
376*0Sstevel@tonic-gate 	kcf_context_t *kcf_ctx;
377*0Sstevel@tonic-gate 	kcf_provider_desc_t *pd;
378*0Sstevel@tonic-gate 	int error;
379*0Sstevel@tonic-gate 	kcf_req_params_t params;
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 	if ((ctx == NULL) ||
382*0Sstevel@tonic-gate 	    ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
383*0Sstevel@tonic-gate 	    ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
384*0Sstevel@tonic-gate 		return (CRYPTO_INVALID_CONTEXT);
385*0Sstevel@tonic-gate 	}
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate 	KCF_PROV_REFHOLD(pd);
388*0Sstevel@tonic-gate 	KCF_WRAP_VERIFY_OPS_PARAMS(&params, KCF_OP_VERIFY_RECOVER, 0, NULL,
389*0Sstevel@tonic-gate 	    NULL, data, signature, NULL);
390*0Sstevel@tonic-gate 	error = kcf_submit_request(pd, ctx, cr, &params, B_FALSE);
391*0Sstevel@tonic-gate 	KCF_PROV_REFRELE(pd);
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate 	/* Release the hold done in kcf_new_ctx() during init step. */
394*0Sstevel@tonic-gate 	KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
395*0Sstevel@tonic-gate 	return (error);
396*0Sstevel@tonic-gate }
397