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 5*1808Smcpowers * Common Development and Distribution License (the "License"). 6*1808Smcpowers * 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*1808Smcpowers * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/errno.h> 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/kmem.h> 31904Smcpowers #include <sys/sysmacros.h> 320Sstevel@tonic-gate #include <sys/crypto/common.h> 330Sstevel@tonic-gate #include <sys/crypto/impl.h> 340Sstevel@tonic-gate #include <sys/crypto/api.h> 350Sstevel@tonic-gate #include <sys/crypto/spi.h> 360Sstevel@tonic-gate #include <sys/crypto/sched_impl.h> 370Sstevel@tonic-gate 38904Smcpowers #define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f) 39904Smcpowers #define CRYPTO_SIGN_OFFSET(f) offsetof(crypto_sign_ops_t, f) 40904Smcpowers 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * Sign entry points. 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * See comments for crypto_digest_init_prov(). 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate int 49904Smcpowers crypto_sign_init_prov(crypto_provider_t provider, crypto_session_id_t sid, 500Sstevel@tonic-gate crypto_mechanism_t *mech, crypto_key_t *key, crypto_ctx_template_t tmpl, 510Sstevel@tonic-gate crypto_context_t *ctxp, crypto_call_req_t *crq) 520Sstevel@tonic-gate { 53904Smcpowers int rv; 540Sstevel@tonic-gate crypto_ctx_t *ctx; 550Sstevel@tonic-gate kcf_req_params_t params; 56904Smcpowers kcf_provider_desc_t *pd = provider; 57904Smcpowers kcf_provider_desc_t *real_provider = pd; 580Sstevel@tonic-gate 59904Smcpowers ASSERT(KCF_PROV_REFHELD(pd)); 60904Smcpowers 61904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 62904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 63*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), pd, 64*1808Smcpowers &real_provider, CRYPTO_FG_SIGN); 65904Smcpowers 66904Smcpowers if (rv != CRYPTO_SUCCESS) 67904Smcpowers return (rv); 68904Smcpowers } 69904Smcpowers 70904Smcpowers /* Allocate and initialize the canonical context */ 71904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 72904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 73904Smcpowers KCF_PROV_REFRELE(real_provider); 740Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 75904Smcpowers } 760Sstevel@tonic-gate 770Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_INIT, sid, mech, 780Sstevel@tonic-gate key, NULL, NULL, tmpl); 79904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, B_FALSE); 80904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 81904Smcpowers KCF_PROV_REFRELE(real_provider); 820Sstevel@tonic-gate 83904Smcpowers if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED)) 840Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 850Sstevel@tonic-gate else { 860Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 870Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 90904Smcpowers return (rv); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate int 940Sstevel@tonic-gate crypto_sign_init(crypto_mechanism_t *mech, crypto_key_t *key, 950Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq) 960Sstevel@tonic-gate { 970Sstevel@tonic-gate int error; 980Sstevel@tonic-gate kcf_mech_entry_t *me; 990Sstevel@tonic-gate kcf_provider_desc_t *pd; 1000Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 1010Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl; 1020Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate retry: 1050Sstevel@tonic-gate /* The pd is returned held */ 1060Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, 1070Sstevel@tonic-gate list, CRYPTO_FG_SIGN, CHECK_RESTRICT(crq), 0)) == NULL) { 1080Sstevel@tonic-gate if (list != NULL) 1090Sstevel@tonic-gate kcf_free_triedlist(list); 1100Sstevel@tonic-gate return (error); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* 1140Sstevel@tonic-gate * For SW providers, check the validity of the context template 1150Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so 1160Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by 1170Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW 1180Sstevel@tonic-gate * provider. 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) && 1210Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) { 1220Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) { 1230Sstevel@tonic-gate if (list != NULL) 1240Sstevel@tonic-gate kcf_free_triedlist(list); 1250Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1260Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE); 1270Sstevel@tonic-gate } else { 1280Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl; 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate error = crypto_sign_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl, 1330Sstevel@tonic-gate ctxp, crq); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 1360Sstevel@tonic-gate IS_RECOVERABLE(error)) { 1370Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 1380Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 1390Sstevel@tonic-gate goto retry; 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate if (list != NULL) 1430Sstevel@tonic-gate kcf_free_triedlist(list); 1440Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1450Sstevel@tonic-gate return (error); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate int 1490Sstevel@tonic-gate crypto_sign_single(crypto_context_t context, crypto_data_t *data, 1500Sstevel@tonic-gate crypto_data_t *signature, crypto_call_req_t *cr) 1510Sstevel@tonic-gate { 1520Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 1530Sstevel@tonic-gate kcf_context_t *kcf_ctx; 1540Sstevel@tonic-gate kcf_provider_desc_t *pd; 1550Sstevel@tonic-gate int error; 1560Sstevel@tonic-gate kcf_req_params_t params; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate if ((ctx == NULL) || 1590Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 1600Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 1610Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 1650Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SINGLE, 0, NULL, 1660Sstevel@tonic-gate NULL, data, signature, NULL); 1670Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 1680Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 1710Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 1720Sstevel@tonic-gate return (error); 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 1760Sstevel@tonic-gate * See comments for crypto_digest_update(). 1770Sstevel@tonic-gate */ 1780Sstevel@tonic-gate int 1790Sstevel@tonic-gate crypto_sign_update(crypto_context_t context, crypto_data_t *data, 1800Sstevel@tonic-gate crypto_call_req_t *cr) 1810Sstevel@tonic-gate { 1820Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 1830Sstevel@tonic-gate kcf_context_t *kcf_ctx; 1840Sstevel@tonic-gate kcf_provider_desc_t *pd; 1850Sstevel@tonic-gate kcf_req_params_t params; 186904Smcpowers int rv; 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate if ((ctx == NULL) || 1890Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 1900Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 1910Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 194904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 1950Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 196904Smcpowers KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_UPDATE, ctx->cc_session, NULL, 1970Sstevel@tonic-gate NULL, data, NULL, NULL); 198904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 1990Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2000Sstevel@tonic-gate 201904Smcpowers return (rv); 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * See comments for crypto_digest_final(). 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate int 2080Sstevel@tonic-gate crypto_sign_final(crypto_context_t context, crypto_data_t *signature, 2090Sstevel@tonic-gate crypto_call_req_t *cr) 2100Sstevel@tonic-gate { 2110Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 2120Sstevel@tonic-gate kcf_context_t *kcf_ctx; 2130Sstevel@tonic-gate kcf_provider_desc_t *pd; 214904Smcpowers int rv; 2150Sstevel@tonic-gate kcf_req_params_t params; 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate if ((ctx == NULL) || 2180Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 2190Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 2200Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 223904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 2240Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 225904Smcpowers KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_FINAL, ctx->cc_session, NULL, 2260Sstevel@tonic-gate NULL, NULL, signature, NULL); 227904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 2280Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 231904Smcpowers KCF_CONTEXT_COND_RELEASE(rv, kcf_ctx); 232904Smcpowers return (rv); 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate int 236904Smcpowers crypto_sign_prov(crypto_provider_t provider, crypto_session_id_t sid, 2370Sstevel@tonic-gate crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 2380Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_data_t *signature, 2390Sstevel@tonic-gate crypto_call_req_t *crq) 2400Sstevel@tonic-gate { 2410Sstevel@tonic-gate kcf_req_params_t params; 242904Smcpowers kcf_provider_desc_t *pd = provider; 243904Smcpowers kcf_provider_desc_t *real_provider = pd; 244904Smcpowers int rv; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 247904Smcpowers 248904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 249904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 250*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), 251*1808Smcpowers pd, &real_provider, CRYPTO_FG_SIGN_ATOMIC); 252904Smcpowers 253904Smcpowers if (rv != CRYPTO_SUCCESS) 254904Smcpowers return (rv); 255904Smcpowers } 2560Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech, 2570Sstevel@tonic-gate key, data, signature, tmpl); 258904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 259904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 260904Smcpowers KCF_PROV_REFRELE(real_provider); 2610Sstevel@tonic-gate 262904Smcpowers return (rv); 2630Sstevel@tonic-gate } 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate static int 2660Sstevel@tonic-gate sign_sr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key, 2670Sstevel@tonic-gate crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature, 2680Sstevel@tonic-gate crypto_call_req_t *crq, crypto_func_group_t fg) 2690Sstevel@tonic-gate { 2700Sstevel@tonic-gate int error; 2710Sstevel@tonic-gate kcf_mech_entry_t *me; 2720Sstevel@tonic-gate kcf_provider_desc_t *pd; 2730Sstevel@tonic-gate kcf_req_params_t params; 2740Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 2750Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl; 2760Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate retry: 2790Sstevel@tonic-gate /* The pd is returned held */ 2800Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, list, fg, 2810Sstevel@tonic-gate CHECK_RESTRICT(crq), data->cd_length)) == NULL) { 2820Sstevel@tonic-gate if (list != NULL) 2830Sstevel@tonic-gate kcf_free_triedlist(list); 2840Sstevel@tonic-gate return (error); 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate /* 2880Sstevel@tonic-gate * For SW providers, check the validity of the context template 2890Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so 2900Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by 2910Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW 2920Sstevel@tonic-gate * provider. 2930Sstevel@tonic-gate */ 2940Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) && 2950Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) { 2960Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) { 2970Sstevel@tonic-gate if (list != NULL) 2980Sstevel@tonic-gate kcf_free_triedlist(list); 2990Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3000Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE); 3010Sstevel@tonic-gate } else { 3020Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl; 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate /* The fast path for SW providers. */ 3070Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 3080Sstevel@tonic-gate crypto_mechanism_t lmech; 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate lmech = *mech; 3110Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech); 3120Sstevel@tonic-gate if (fg == CRYPTO_FG_SIGN_ATOMIC) 3130Sstevel@tonic-gate error = KCF_PROV_SIGN_ATOMIC(pd, pd->pd_sid, &lmech, 3140Sstevel@tonic-gate key, data, spi_ctx_tmpl, signature, 3150Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 3160Sstevel@tonic-gate else 3170Sstevel@tonic-gate error = KCF_PROV_SIGN_RECOVER_ATOMIC(pd, pd->pd_sid, 3180Sstevel@tonic-gate &lmech, key, data, spi_ctx_tmpl, signature, 3190Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 3200Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3210Sstevel@tonic-gate } else { 3220Sstevel@tonic-gate kcf_op_type_t op = ((fg == CRYPTO_FG_SIGN_ATOMIC) ? 3230Sstevel@tonic-gate KCF_OP_ATOMIC : KCF_OP_SIGN_RECOVER_ATOMIC); 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, op, pd->pd_sid, 3260Sstevel@tonic-gate mech, key, data, signature, spi_ctx_tmpl); 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 3290Sstevel@tonic-gate error = kcf_submit_request(pd, NULL, crq, ¶ms, B_FALSE); 3300Sstevel@tonic-gate } 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 3330Sstevel@tonic-gate IS_RECOVERABLE(error)) { 3340Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 3350Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 3360Sstevel@tonic-gate goto retry; 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate if (list != NULL) 3400Sstevel@tonic-gate kcf_free_triedlist(list); 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3430Sstevel@tonic-gate return (error); 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate int 3470Sstevel@tonic-gate crypto_sign(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 3480Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_data_t *signature, 3490Sstevel@tonic-gate crypto_call_req_t *crq) 3500Sstevel@tonic-gate { 3510Sstevel@tonic-gate return (sign_sr_atomic_common(mech, key, data, tmpl, signature, crq, 3520Sstevel@tonic-gate CRYPTO_FG_SIGN_ATOMIC)); 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate int 356904Smcpowers crypto_sign_recover_prov(crypto_provider_t provider, crypto_session_id_t sid, 357904Smcpowers crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 358904Smcpowers crypto_ctx_template_t tmpl, crypto_data_t *signature, 3590Sstevel@tonic-gate crypto_call_req_t *crq) 3600Sstevel@tonic-gate { 3610Sstevel@tonic-gate kcf_req_params_t params; 362904Smcpowers kcf_provider_desc_t *pd = provider; 363904Smcpowers kcf_provider_desc_t *real_provider = pd; 364904Smcpowers int rv; 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 367904Smcpowers 368904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 369904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 370*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), pd, 371*1808Smcpowers &real_provider, CRYPTO_FG_SIGN_RECOVER_ATOMIC); 372904Smcpowers 373904Smcpowers if (rv != CRYPTO_SUCCESS) 374904Smcpowers return (rv); 375904Smcpowers } 3760Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SIGN_RECOVER_ATOMIC, sid, mech, 3770Sstevel@tonic-gate key, data, signature, tmpl); 378904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 379904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 380904Smcpowers KCF_PROV_REFRELE(real_provider); 3810Sstevel@tonic-gate 382904Smcpowers return (rv); 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate int 3860Sstevel@tonic-gate crypto_sign_recover(crypto_mechanism_t *mech, crypto_key_t *key, 3870Sstevel@tonic-gate crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature, 3880Sstevel@tonic-gate crypto_call_req_t *crq) 3890Sstevel@tonic-gate { 3900Sstevel@tonic-gate return (sign_sr_atomic_common(mech, key, data, tmpl, signature, crq, 3910Sstevel@tonic-gate CRYPTO_FG_SIGN_RECOVER_ATOMIC)); 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate int 395904Smcpowers crypto_sign_recover_init_prov(crypto_provider_t provider, 396904Smcpowers crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key, 397904Smcpowers crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq) 3980Sstevel@tonic-gate { 399904Smcpowers int rv; 4000Sstevel@tonic-gate crypto_ctx_t *ctx; 4010Sstevel@tonic-gate kcf_req_params_t params; 402904Smcpowers kcf_provider_desc_t *pd = provider; 403904Smcpowers kcf_provider_desc_t *real_provider = pd; 4040Sstevel@tonic-gate 405904Smcpowers ASSERT(KCF_PROV_REFHELD(pd)); 406904Smcpowers 407904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 408904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 409*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), pd, 410*1808Smcpowers &real_provider, CRYPTO_FG_SIGN_RECOVER); 411904Smcpowers 412904Smcpowers if (rv != CRYPTO_SUCCESS) 413904Smcpowers return (rv); 414904Smcpowers } 415904Smcpowers 416904Smcpowers /* Allocate and initialize the canonical context */ 417904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 418904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 419904Smcpowers KCF_PROV_REFRELE(real_provider); 4200Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 421904Smcpowers } 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SIGN_RECOVER_INIT, sid, mech, 4240Sstevel@tonic-gate key, NULL, NULL, tmpl); 425904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, B_FALSE); 426904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 427904Smcpowers KCF_PROV_REFRELE(real_provider); 4280Sstevel@tonic-gate 429904Smcpowers if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED)) 4300Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 4310Sstevel@tonic-gate else { 4320Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 4330Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 436904Smcpowers return (rv); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate int 4400Sstevel@tonic-gate crypto_sign_recover_single(crypto_context_t context, crypto_data_t *data, 4410Sstevel@tonic-gate crypto_data_t *signature, crypto_call_req_t *cr) 4420Sstevel@tonic-gate { 4430Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4440Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4450Sstevel@tonic-gate kcf_provider_desc_t *pd; 4460Sstevel@tonic-gate int error; 4470Sstevel@tonic-gate kcf_req_params_t params; 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate if ((ctx == NULL) || 4500Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4510Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4520Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4560Sstevel@tonic-gate KCF_WRAP_SIGN_OPS_PARAMS(¶ms, KCF_OP_SIGN_RECOVER, 0, NULL, 4570Sstevel@tonic-gate NULL, data, signature, NULL); 4580Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4590Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4620Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4630Sstevel@tonic-gate return (error); 4640Sstevel@tonic-gate } 465