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_VERIFY_OFFSET(f) offsetof(crypto_verify_ops_t, f) 40904Smcpowers 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * Verify 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_verify_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_VERIFY); 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_VERIFY_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 940Sstevel@tonic-gate int 950Sstevel@tonic-gate crypto_verify_init(crypto_mechanism_t *mech, crypto_key_t *key, 960Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq) 970Sstevel@tonic-gate { 980Sstevel@tonic-gate int error; 990Sstevel@tonic-gate kcf_mech_entry_t *me; 1000Sstevel@tonic-gate kcf_provider_desc_t *pd; 1010Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 1020Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl; 1030Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate retry: 1060Sstevel@tonic-gate /* The pd is returned held */ 1070Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, 1080Sstevel@tonic-gate list, CRYPTO_FG_VERIFY, CHECK_RESTRICT(crq), 0)) == NULL) { 1090Sstevel@tonic-gate if (list != NULL) 1100Sstevel@tonic-gate kcf_free_triedlist(list); 1110Sstevel@tonic-gate return (error); 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate /* 1150Sstevel@tonic-gate * For SW providers, check the validity of the context template 1160Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so 1170Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by 1180Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW 1190Sstevel@tonic-gate * provider. 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) && 1220Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) { 1230Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) { 1240Sstevel@tonic-gate if (list != NULL) 1250Sstevel@tonic-gate kcf_free_triedlist(list); 1260Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1270Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE); 1280Sstevel@tonic-gate } else { 1290Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl; 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate } 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate error = crypto_verify_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl, 1340Sstevel@tonic-gate ctxp, crq); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 1370Sstevel@tonic-gate IS_RECOVERABLE(error)) { 1380Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 1390Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 1400Sstevel@tonic-gate goto retry; 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate if (list != NULL) 1440Sstevel@tonic-gate kcf_free_triedlist(list); 1450Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1460Sstevel@tonic-gate return (error); 1470Sstevel@tonic-gate } 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate int 1500Sstevel@tonic-gate crypto_verify_single(crypto_context_t context, crypto_data_t *data, 1510Sstevel@tonic-gate crypto_data_t *signature, crypto_call_req_t *cr) 1520Sstevel@tonic-gate { 1530Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 1540Sstevel@tonic-gate kcf_context_t *kcf_ctx; 1550Sstevel@tonic-gate kcf_provider_desc_t *pd; 1560Sstevel@tonic-gate int error; 1570Sstevel@tonic-gate kcf_req_params_t params; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate if ((ctx == NULL) || 1600Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 1610Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 1620Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 1660Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_SINGLE, 0, NULL, 1670Sstevel@tonic-gate NULL, data, signature, NULL); 1680Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 1690Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 1720Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 1730Sstevel@tonic-gate return (error); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * See comments for crypto_digest_update(). 1780Sstevel@tonic-gate */ 1790Sstevel@tonic-gate int 1800Sstevel@tonic-gate crypto_verify_update(crypto_context_t context, crypto_data_t *data, 1810Sstevel@tonic-gate crypto_call_req_t *cr) 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate { 1840Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 1850Sstevel@tonic-gate kcf_context_t *kcf_ctx; 1860Sstevel@tonic-gate kcf_provider_desc_t *pd; 1870Sstevel@tonic-gate kcf_req_params_t params; 188904Smcpowers int rv; 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate if ((ctx == NULL) || 1910Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 1920Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 1930Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 1940Sstevel@tonic-gate } 1950Sstevel@tonic-gate 196904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 1970Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 198904Smcpowers KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_UPDATE, ctx->cc_session, 199904Smcpowers NULL, NULL, data, NULL, NULL); 200904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 2010Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2020Sstevel@tonic-gate 203904Smcpowers return (rv); 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate * See comments for crypto_digest_final(). 2080Sstevel@tonic-gate */ 2090Sstevel@tonic-gate int 2100Sstevel@tonic-gate crypto_verify_final(crypto_context_t context, crypto_data_t *signature, 2110Sstevel@tonic-gate crypto_call_req_t *cr) 2120Sstevel@tonic-gate { 2130Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 2140Sstevel@tonic-gate kcf_context_t *kcf_ctx; 2150Sstevel@tonic-gate kcf_provider_desc_t *pd; 2160Sstevel@tonic-gate kcf_req_params_t params; 217904Smcpowers int rv; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate if ((ctx == NULL) || 2200Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 2210Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 2220Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate 225904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 2260Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 227904Smcpowers KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_FINAL, ctx->cc_session, 228904Smcpowers NULL, NULL, NULL, signature, NULL); 229904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 2300Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 233904Smcpowers KCF_CONTEXT_COND_RELEASE(rv, kcf_ctx); 234904Smcpowers return (rv); 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate int 238904Smcpowers crypto_verify_prov(crypto_provider_t provider, crypto_session_id_t sid, 239904Smcpowers crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 240904Smcpowers crypto_ctx_template_t tmpl, crypto_data_t *signature, 2410Sstevel@tonic-gate crypto_call_req_t *crq) 2420Sstevel@tonic-gate { 2430Sstevel@tonic-gate kcf_req_params_t params; 244904Smcpowers kcf_provider_desc_t *pd = provider; 245904Smcpowers kcf_provider_desc_t *real_provider = pd; 246904Smcpowers int rv; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 249904Smcpowers 250904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 251904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 252*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), 253*1808Smcpowers pd, &real_provider, CRYPTO_FG_VERIFY_ATOMIC); 254904Smcpowers 255904Smcpowers if (rv != CRYPTO_SUCCESS) 256904Smcpowers return (rv); 257904Smcpowers } 2580Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech, 2590Sstevel@tonic-gate key, data, signature, tmpl); 260904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 261904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 262904Smcpowers KCF_PROV_REFRELE(real_provider); 2630Sstevel@tonic-gate 264904Smcpowers return (rv); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate static int 2680Sstevel@tonic-gate verify_vr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key, 2690Sstevel@tonic-gate crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature, 2700Sstevel@tonic-gate crypto_call_req_t *crq, crypto_func_group_t fg) 2710Sstevel@tonic-gate { 2720Sstevel@tonic-gate int error; 2730Sstevel@tonic-gate kcf_mech_entry_t *me; 2740Sstevel@tonic-gate kcf_provider_desc_t *pd; 2750Sstevel@tonic-gate kcf_req_params_t params; 2760Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 2770Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl; 2780Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL; 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate retry: 2810Sstevel@tonic-gate /* The pd is returned held */ 2820Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, list, fg, 2830Sstevel@tonic-gate CHECK_RESTRICT(crq), data->cd_length)) == NULL) { 2840Sstevel@tonic-gate if (list != NULL) 2850Sstevel@tonic-gate kcf_free_triedlist(list); 2860Sstevel@tonic-gate return (error); 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate /* 2900Sstevel@tonic-gate * For SW providers, check the validity of the context template 2910Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so 2920Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by 2930Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW 2940Sstevel@tonic-gate * provider. 2950Sstevel@tonic-gate */ 2960Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) && 2970Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) { 2980Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) { 2990Sstevel@tonic-gate if (list != NULL) 3000Sstevel@tonic-gate kcf_free_triedlist(list); 3010Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3020Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE); 3030Sstevel@tonic-gate } else { 3040Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl; 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate /* The fast path for SW providers. */ 3090Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 3100Sstevel@tonic-gate crypto_mechanism_t lmech; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate lmech = *mech; 3130Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech); 3140Sstevel@tonic-gate if (fg == CRYPTO_FG_VERIFY_ATOMIC) 3150Sstevel@tonic-gate error = KCF_PROV_VERIFY_ATOMIC(pd, pd->pd_sid, &lmech, 3160Sstevel@tonic-gate key, data, spi_ctx_tmpl, signature, 3170Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 3180Sstevel@tonic-gate else 3190Sstevel@tonic-gate /* Note: The argument order is different from above */ 3200Sstevel@tonic-gate error = KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, pd->pd_sid, 3210Sstevel@tonic-gate &lmech, key, signature, spi_ctx_tmpl, data, 3220Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 3230Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3240Sstevel@tonic-gate } else { 3250Sstevel@tonic-gate kcf_op_type_t op = ((fg == CRYPTO_FG_VERIFY_ATOMIC) ? 3260Sstevel@tonic-gate KCF_OP_ATOMIC : KCF_OP_VERIFY_RECOVER_ATOMIC); 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, op, pd->pd_sid, 3290Sstevel@tonic-gate mech, key, data, signature, spi_ctx_tmpl); 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 3320Sstevel@tonic-gate error = kcf_submit_request(pd, NULL, crq, ¶ms, B_FALSE); 3330Sstevel@tonic-gate } 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 3360Sstevel@tonic-gate IS_RECOVERABLE(error)) { 3370Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 3380Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 3390Sstevel@tonic-gate goto retry; 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate if (list != NULL) 3430Sstevel@tonic-gate kcf_free_triedlist(list); 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3460Sstevel@tonic-gate return (error); 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate int 3500Sstevel@tonic-gate crypto_verify(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 3510Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_data_t *signature, 3520Sstevel@tonic-gate crypto_call_req_t *crq) 3530Sstevel@tonic-gate { 3540Sstevel@tonic-gate return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq, 3550Sstevel@tonic-gate CRYPTO_FG_VERIFY_ATOMIC)); 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate int 359904Smcpowers crypto_verify_recover_prov(crypto_provider_t provider, crypto_session_id_t sid, 360904Smcpowers crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *signature, 361904Smcpowers crypto_ctx_template_t tmpl, crypto_data_t *data, crypto_call_req_t *crq) 3620Sstevel@tonic-gate { 3630Sstevel@tonic-gate kcf_req_params_t params; 364904Smcpowers kcf_provider_desc_t *pd = provider; 365904Smcpowers kcf_provider_desc_t *real_provider = pd; 366904Smcpowers int rv; 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 369904Smcpowers 370904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 371904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 372*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), pd, 373*1808Smcpowers &real_provider, CRYPTO_FG_VERIFY_RECOVER_ATOMIC); 374904Smcpowers 375904Smcpowers if (rv != CRYPTO_SUCCESS) 376904Smcpowers return (rv); 377904Smcpowers } 3780Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_VERIFY_RECOVER_ATOMIC, 3790Sstevel@tonic-gate sid, mech, key, data, signature, tmpl); 380904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 381904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 382904Smcpowers KCF_PROV_REFRELE(real_provider); 3830Sstevel@tonic-gate 384904Smcpowers return (rv); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate int 3880Sstevel@tonic-gate crypto_verify_recover(crypto_mechanism_t *mech, crypto_key_t *key, 3890Sstevel@tonic-gate crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data, 3900Sstevel@tonic-gate crypto_call_req_t *crq) 3910Sstevel@tonic-gate { 3920Sstevel@tonic-gate return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq, 3930Sstevel@tonic-gate CRYPTO_FG_VERIFY_RECOVER_ATOMIC)); 3940Sstevel@tonic-gate } 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate int 397904Smcpowers crypto_verify_recover_init_prov(crypto_provider_t provider, 3980Sstevel@tonic-gate crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key, 3990Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq) 4000Sstevel@tonic-gate { 401904Smcpowers int rv; 4020Sstevel@tonic-gate crypto_ctx_t *ctx; 4030Sstevel@tonic-gate kcf_req_params_t params; 404904Smcpowers kcf_provider_desc_t *pd = provider; 405904Smcpowers kcf_provider_desc_t *real_provider = pd; 4060Sstevel@tonic-gate 407904Smcpowers ASSERT(KCF_PROV_REFHELD(pd)); 408904Smcpowers 409904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 410904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 411*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), pd, 412*1808Smcpowers &real_provider, CRYPTO_FG_VERIFY_RECOVER); 413904Smcpowers 414904Smcpowers if (rv != CRYPTO_SUCCESS) 415904Smcpowers return (rv); 416904Smcpowers } 417904Smcpowers 418904Smcpowers /* Allocate and initialize the canonical context */ 419904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 420904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 421904Smcpowers KCF_PROV_REFRELE(real_provider); 4220Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 423904Smcpowers } 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_VERIFY_RECOVER_INIT, 4260Sstevel@tonic-gate sid, mech, key, NULL, NULL, tmpl); 427904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, B_FALSE); 428904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 429904Smcpowers KCF_PROV_REFRELE(real_provider); 4300Sstevel@tonic-gate 431904Smcpowers if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED)) 4320Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 4330Sstevel@tonic-gate else { 4340Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 4350Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 4360Sstevel@tonic-gate } 4370Sstevel@tonic-gate 438904Smcpowers return (rv); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate int 4420Sstevel@tonic-gate crypto_verify_recover_single(crypto_context_t context, crypto_data_t *signature, 4430Sstevel@tonic-gate crypto_data_t *data, crypto_call_req_t *cr) 4440Sstevel@tonic-gate { 4450Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4460Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4470Sstevel@tonic-gate kcf_provider_desc_t *pd; 4480Sstevel@tonic-gate int error; 4490Sstevel@tonic-gate kcf_req_params_t params; 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate if ((ctx == NULL) || 4520Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4530Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4540Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4580Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_VERIFY_RECOVER, 0, NULL, 4590Sstevel@tonic-gate NULL, data, signature, NULL); 4600Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4610Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4640Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4650Sstevel@tonic-gate return (error); 4660Sstevel@tonic-gate } 467