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_SIGN_OFFSET(f) offsetof(crypto_sign_ops_t, f)
37904Smcpowers
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate * Sign 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_sign_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_sign_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_SIGN);
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_SIGN_OPS_PARAMS(¶ms, KCF_OP_INIT, sid, mech,
750Sstevel@tonic-gate key, NULL, NULL, tmpl);
76904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, 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 int
crypto_sign_init(crypto_mechanism_t * mech,crypto_key_t * key,crypto_ctx_template_t tmpl,crypto_context_t * ctxp,crypto_call_req_t * crq)910Sstevel@tonic-gate crypto_sign_init(crypto_mechanism_t *mech, crypto_key_t *key,
920Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate int error;
950Sstevel@tonic-gate kcf_mech_entry_t *me;
960Sstevel@tonic-gate kcf_provider_desc_t *pd;
970Sstevel@tonic-gate kcf_prov_tried_t *list = NULL;
980Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl;
990Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate retry:
1020Sstevel@tonic-gate /* The pd is returned held */
10310444SVladimir.Kotal@Sun.COM if ((pd = kcf_get_mech_provider(mech->cm_type, key, &me, &error,
104*12304SValerie.Fenwick@Oracle.COM list, CRYPTO_FG_SIGN, 0)) == NULL) {
1050Sstevel@tonic-gate if (list != NULL)
1060Sstevel@tonic-gate kcf_free_triedlist(list);
1070Sstevel@tonic-gate return (error);
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * For SW providers, check the validity of the context template
1120Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so
1130Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by
1140Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW
1150Sstevel@tonic-gate * provider.
1160Sstevel@tonic-gate */
1170Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
1180Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
1190Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
1200Sstevel@tonic-gate if (list != NULL)
1210Sstevel@tonic-gate kcf_free_triedlist(list);
1220Sstevel@tonic-gate KCF_PROV_REFRELE(pd);
1230Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE);
1240Sstevel@tonic-gate } else {
1250Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate error = crypto_sign_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl,
1300Sstevel@tonic-gate ctxp, crq);
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
1330Sstevel@tonic-gate IS_RECOVERABLE(error)) {
1340Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */
1350Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
1360Sstevel@tonic-gate goto retry;
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate if (list != NULL)
1400Sstevel@tonic-gate kcf_free_triedlist(list);
1410Sstevel@tonic-gate KCF_PROV_REFRELE(pd);
1420Sstevel@tonic-gate return (error);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate int
crypto_sign_single(crypto_context_t context,crypto_data_t * data,crypto_data_t * signature,crypto_call_req_t * cr)1460Sstevel@tonic-gate crypto_sign_single(crypto_context_t context, crypto_data_t *data,
1470Sstevel@tonic-gate crypto_data_t *signature, crypto_call_req_t *cr)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context;
1500Sstevel@tonic-gate kcf_context_t *kcf_ctx;
1510Sstevel@tonic-gate kcf_provider_desc_t *pd;
1520Sstevel@tonic-gate int error;
1530Sstevel@tonic-gate kcf_req_params_t params;
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate if ((ctx == NULL) ||
1560Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
1570Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
1580Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SINGLE, 0, NULL,
1620Sstevel@tonic-gate NULL, data, signature, NULL);
1630Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE);
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */
1660Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
1670Sstevel@tonic-gate return (error);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate * See comments for crypto_digest_update().
1720Sstevel@tonic-gate */
1730Sstevel@tonic-gate int
crypto_sign_update(crypto_context_t context,crypto_data_t * data,crypto_call_req_t * cr)1740Sstevel@tonic-gate crypto_sign_update(crypto_context_t context, crypto_data_t *data,
1750Sstevel@tonic-gate crypto_call_req_t *cr)
1760Sstevel@tonic-gate {
1770Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context;
1780Sstevel@tonic-gate kcf_context_t *kcf_ctx;
1790Sstevel@tonic-gate kcf_provider_desc_t *pd;
1800Sstevel@tonic-gate kcf_req_params_t params;
181904Smcpowers int rv;
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate if ((ctx == NULL) ||
1840Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
1850Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
1860Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT);
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
189904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER);
190904Smcpowers KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_UPDATE, ctx->cc_session, NULL,
1910Sstevel@tonic-gate NULL, data, NULL, NULL);
192904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE);
1930Sstevel@tonic-gate
194904Smcpowers return (rv);
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate * See comments for crypto_digest_final().
1990Sstevel@tonic-gate */
2000Sstevel@tonic-gate int
crypto_sign_final(crypto_context_t context,crypto_data_t * signature,crypto_call_req_t * cr)2010Sstevel@tonic-gate crypto_sign_final(crypto_context_t context, crypto_data_t *signature,
2020Sstevel@tonic-gate crypto_call_req_t *cr)
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context;
2050Sstevel@tonic-gate kcf_context_t *kcf_ctx;
2060Sstevel@tonic-gate kcf_provider_desc_t *pd;
207904Smcpowers int rv;
2080Sstevel@tonic-gate kcf_req_params_t params;
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate if ((ctx == NULL) ||
2110Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
2120Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
2130Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT);
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
216904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER);
217904Smcpowers KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_FINAL, ctx->cc_session, NULL,
2180Sstevel@tonic-gate NULL, NULL, signature, NULL);
219904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE);
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */
222904Smcpowers KCF_CONTEXT_COND_RELEASE(rv, kcf_ctx);
223904Smcpowers return (rv);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate int
crypto_sign_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)227904Smcpowers crypto_sign_prov(crypto_provider_t provider, crypto_session_id_t sid,
2280Sstevel@tonic-gate crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
2290Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_data_t *signature,
2300Sstevel@tonic-gate crypto_call_req_t *crq)
2310Sstevel@tonic-gate {
2320Sstevel@tonic-gate kcf_req_params_t params;
233904Smcpowers kcf_provider_desc_t *pd = provider;
234904Smcpowers kcf_provider_desc_t *real_provider = pd;
235904Smcpowers int rv;
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd));
238904Smcpowers
239904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
24010444SVladimir.Kotal@Sun.COM rv = kcf_get_hardware_provider(mech->cm_type, key,
241*12304SValerie.Fenwick@Oracle.COM CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
242*12304SValerie.Fenwick@Oracle.COM CRYPTO_FG_SIGN_ATOMIC);
243904Smcpowers
244904Smcpowers if (rv != CRYPTO_SUCCESS)
245904Smcpowers return (rv);
246904Smcpowers }
2470Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech,
2480Sstevel@tonic-gate key, data, signature, tmpl);
249904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE);
250904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
251904Smcpowers KCF_PROV_REFRELE(real_provider);
2520Sstevel@tonic-gate
253904Smcpowers return (rv);
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate static int
sign_sr_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)2570Sstevel@tonic-gate sign_sr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key,
2580Sstevel@tonic-gate crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
2590Sstevel@tonic-gate crypto_call_req_t *crq, crypto_func_group_t fg)
2600Sstevel@tonic-gate {
2610Sstevel@tonic-gate int error;
2620Sstevel@tonic-gate kcf_mech_entry_t *me;
2630Sstevel@tonic-gate kcf_provider_desc_t *pd;
2640Sstevel@tonic-gate kcf_req_params_t params;
2650Sstevel@tonic-gate kcf_prov_tried_t *list = NULL;
2660Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl;
2670Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL;
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate retry:
2700Sstevel@tonic-gate /* The pd is returned held */
27110444SVladimir.Kotal@Sun.COM if ((pd = kcf_get_mech_provider(mech->cm_type, key, &me, &error,
272*12304SValerie.Fenwick@Oracle.COM list, fg, data->cd_length)) == NULL) {
2730Sstevel@tonic-gate if (list != NULL)
2740Sstevel@tonic-gate kcf_free_triedlist(list);
2750Sstevel@tonic-gate return (error);
2760Sstevel@tonic-gate }
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate /*
2790Sstevel@tonic-gate * For SW providers, check the validity of the context template
2800Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so
2810Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by
2820Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW
2830Sstevel@tonic-gate * provider.
2840Sstevel@tonic-gate */
2850Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) &&
2860Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) {
2870Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) {
2880Sstevel@tonic-gate if (list != NULL)
2890Sstevel@tonic-gate kcf_free_triedlist(list);
2900Sstevel@tonic-gate KCF_PROV_REFRELE(pd);
2910Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE);
2920Sstevel@tonic-gate } else {
2930Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl;
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate /* The fast path for SW providers. */
2980Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) {
2990Sstevel@tonic-gate crypto_mechanism_t lmech;
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate lmech = *mech;
3020Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech);
3030Sstevel@tonic-gate if (fg == CRYPTO_FG_SIGN_ATOMIC)
3040Sstevel@tonic-gate error = KCF_PROV_SIGN_ATOMIC(pd, pd->pd_sid, &lmech,
3050Sstevel@tonic-gate key, data, spi_ctx_tmpl, signature,
3060Sstevel@tonic-gate KCF_SWFP_RHNDL(crq));
3070Sstevel@tonic-gate else
3080Sstevel@tonic-gate error = KCF_PROV_SIGN_RECOVER_ATOMIC(pd, pd->pd_sid,
3090Sstevel@tonic-gate &lmech, key, data, spi_ctx_tmpl, signature,
3100Sstevel@tonic-gate KCF_SWFP_RHNDL(crq));
3110Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error);
3120Sstevel@tonic-gate } else {
3130Sstevel@tonic-gate kcf_op_type_t op = ((fg == CRYPTO_FG_SIGN_ATOMIC) ?
3140Sstevel@tonic-gate KCF_OP_ATOMIC : KCF_OP_SIGN_RECOVER_ATOMIC);
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, op, pd->pd_sid,
3170Sstevel@tonic-gate mech, key, data, signature, spi_ctx_tmpl);
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */
3200Sstevel@tonic-gate error = kcf_submit_request(pd, NULL, crq, ¶ms, B_FALSE);
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED &&
3240Sstevel@tonic-gate IS_RECOVERABLE(error)) {
3250Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */
3260Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL)
3270Sstevel@tonic-gate goto retry;
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate if (list != NULL)
3310Sstevel@tonic-gate kcf_free_triedlist(list);
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate KCF_PROV_REFRELE(pd);
3340Sstevel@tonic-gate return (error);
3350Sstevel@tonic-gate }
3360Sstevel@tonic-gate
3370Sstevel@tonic-gate int
crypto_sign(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)3380Sstevel@tonic-gate crypto_sign(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
3390Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_data_t *signature,
3400Sstevel@tonic-gate crypto_call_req_t *crq)
3410Sstevel@tonic-gate {
3420Sstevel@tonic-gate return (sign_sr_atomic_common(mech, key, data, tmpl, signature, crq,
3430Sstevel@tonic-gate CRYPTO_FG_SIGN_ATOMIC));
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate int
crypto_sign_recover_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)347904Smcpowers crypto_sign_recover_prov(crypto_provider_t provider, crypto_session_id_t sid,
348904Smcpowers crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data,
349904Smcpowers crypto_ctx_template_t tmpl, crypto_data_t *signature,
3500Sstevel@tonic-gate crypto_call_req_t *crq)
3510Sstevel@tonic-gate {
3520Sstevel@tonic-gate kcf_req_params_t params;
353904Smcpowers kcf_provider_desc_t *pd = provider;
354904Smcpowers kcf_provider_desc_t *real_provider = pd;
355904Smcpowers int rv;
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd));
358904Smcpowers
359904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
36010444SVladimir.Kotal@Sun.COM rv = kcf_get_hardware_provider(mech->cm_type, key,
361*12304SValerie.Fenwick@Oracle.COM CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
362*12304SValerie.Fenwick@Oracle.COM CRYPTO_FG_SIGN_RECOVER_ATOMIC);
363904Smcpowers
364904Smcpowers if (rv != CRYPTO_SUCCESS)
365904Smcpowers return (rv);
366904Smcpowers }
3670Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SIGN_RECOVER_ATOMIC, sid, mech,
3680Sstevel@tonic-gate key, data, signature, tmpl);
369904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE);
370904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
371904Smcpowers KCF_PROV_REFRELE(real_provider);
3720Sstevel@tonic-gate
373904Smcpowers return (rv);
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate int
crypto_sign_recover(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)3770Sstevel@tonic-gate crypto_sign_recover(crypto_mechanism_t *mech, crypto_key_t *key,
3780Sstevel@tonic-gate crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
3790Sstevel@tonic-gate crypto_call_req_t *crq)
3800Sstevel@tonic-gate {
3810Sstevel@tonic-gate return (sign_sr_atomic_common(mech, key, data, tmpl, signature, crq,
3820Sstevel@tonic-gate CRYPTO_FG_SIGN_RECOVER_ATOMIC));
3830Sstevel@tonic-gate }
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate int
crypto_sign_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)386904Smcpowers crypto_sign_recover_init_prov(crypto_provider_t provider,
387904Smcpowers crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key,
388904Smcpowers crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq)
3890Sstevel@tonic-gate {
390904Smcpowers int rv;
3910Sstevel@tonic-gate crypto_ctx_t *ctx;
3920Sstevel@tonic-gate kcf_req_params_t params;
393904Smcpowers kcf_provider_desc_t *pd = provider;
394904Smcpowers kcf_provider_desc_t *real_provider = pd;
3950Sstevel@tonic-gate
396904Smcpowers ASSERT(KCF_PROV_REFHELD(pd));
397904Smcpowers
398904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
39910444SVladimir.Kotal@Sun.COM rv = kcf_get_hardware_provider(mech->cm_type, key,
400*12304SValerie.Fenwick@Oracle.COM CRYPTO_MECH_INVALID, NULL, pd, &real_provider,
401*12304SValerie.Fenwick@Oracle.COM CRYPTO_FG_SIGN_RECOVER);
402904Smcpowers
403904Smcpowers if (rv != CRYPTO_SUCCESS)
404904Smcpowers return (rv);
405904Smcpowers }
406904Smcpowers
407904Smcpowers /* Allocate and initialize the canonical context */
408904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) {
409904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
410904Smcpowers KCF_PROV_REFRELE(real_provider);
4110Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY);
412904Smcpowers }
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SIGN_RECOVER_INIT, sid, mech,
4150Sstevel@tonic-gate key, NULL, NULL, tmpl);
416904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, B_FALSE);
417904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
418904Smcpowers KCF_PROV_REFRELE(real_provider);
4190Sstevel@tonic-gate
420904Smcpowers if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED))
4210Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx;
4220Sstevel@tonic-gate else {
4230Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */
4240Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private);
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate
427904Smcpowers return (rv);
4280Sstevel@tonic-gate }
4290Sstevel@tonic-gate
4300Sstevel@tonic-gate int
crypto_sign_recover_single(crypto_context_t context,crypto_data_t * data,crypto_data_t * signature,crypto_call_req_t * cr)4310Sstevel@tonic-gate crypto_sign_recover_single(crypto_context_t context, crypto_data_t *data,
4320Sstevel@tonic-gate crypto_data_t *signature, crypto_call_req_t *cr)
4330Sstevel@tonic-gate {
4340Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context;
4350Sstevel@tonic-gate kcf_context_t *kcf_ctx;
4360Sstevel@tonic-gate kcf_provider_desc_t *pd;
4370Sstevel@tonic-gate int error;
4380Sstevel@tonic-gate kcf_req_params_t params;
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate if ((ctx == NULL) ||
4410Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) ||
4420Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) {
4430Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT);
4440Sstevel@tonic-gate }
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SIGN_RECOVER, 0, NULL,
4470Sstevel@tonic-gate NULL, data, signature, NULL);
4480Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE);
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */
4510Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx);
4520Sstevel@tonic-gate return (error);
4530Sstevel@tonic-gate }
454