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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*904Smcpowers * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/errno.h> 300Sstevel@tonic-gate #include <sys/types.h> 310Sstevel@tonic-gate #include <sys/kmem.h> 32*904Smcpowers #include <sys/sysmacros.h> 330Sstevel@tonic-gate #include <sys/crypto/common.h> 340Sstevel@tonic-gate #include <sys/crypto/impl.h> 350Sstevel@tonic-gate #include <sys/crypto/api.h> 360Sstevel@tonic-gate #include <sys/crypto/spi.h> 370Sstevel@tonic-gate #include <sys/crypto/sched_impl.h> 380Sstevel@tonic-gate 39*904Smcpowers #define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f) 40*904Smcpowers #define CRYPTO_VERIFY_OFFSET(f) offsetof(crypto_verify_ops_t, f) 41*904Smcpowers 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * Verify entry points. 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * See comments for crypto_digest_init_prov(). 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate int 50*904Smcpowers crypto_verify_init_prov(crypto_provider_t provider, crypto_session_id_t sid, 510Sstevel@tonic-gate crypto_mechanism_t *mech, crypto_key_t *key, crypto_ctx_template_t tmpl, 520Sstevel@tonic-gate crypto_context_t *ctxp, crypto_call_req_t *crq) 530Sstevel@tonic-gate { 54*904Smcpowers int rv; 550Sstevel@tonic-gate crypto_ctx_t *ctx; 560Sstevel@tonic-gate kcf_req_params_t params; 57*904Smcpowers kcf_provider_desc_t *pd = provider; 58*904Smcpowers kcf_provider_desc_t *real_provider = pd; 590Sstevel@tonic-gate 60*904Smcpowers ASSERT(KCF_PROV_REFHELD(pd)); 61*904Smcpowers 62*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 63*904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 64*904Smcpowers CRYPTO_MECH_INVALID, CRYPTO_OPS_OFFSET(verify_ops), 65*904Smcpowers CRYPTO_VERIFY_OFFSET(verify_init), 66*904Smcpowers CHECK_RESTRICT(crq), pd, &real_provider); 67*904Smcpowers 68*904Smcpowers if (rv != CRYPTO_SUCCESS) 69*904Smcpowers return (rv); 70*904Smcpowers } 71*904Smcpowers 72*904Smcpowers /* Allocate and initialize the canonical context */ 73*904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 74*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 75*904Smcpowers KCF_PROV_REFRELE(real_provider); 760Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 77*904Smcpowers } 780Sstevel@tonic-gate 790Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_INIT, sid, mech, 800Sstevel@tonic-gate key, NULL, NULL, tmpl); 81*904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, B_FALSE); 82*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 83*904Smcpowers KCF_PROV_REFRELE(real_provider); 840Sstevel@tonic-gate 85*904Smcpowers if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED)) 860Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 870Sstevel@tonic-gate else { 880Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 890Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 900Sstevel@tonic-gate } 910Sstevel@tonic-gate 92*904Smcpowers return (rv); 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate 960Sstevel@tonic-gate int 970Sstevel@tonic-gate crypto_verify_init(crypto_mechanism_t *mech, crypto_key_t *key, 980Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq) 990Sstevel@tonic-gate { 1000Sstevel@tonic-gate int error; 1010Sstevel@tonic-gate kcf_mech_entry_t *me; 1020Sstevel@tonic-gate kcf_provider_desc_t *pd; 1030Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 1040Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl; 1050Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate retry: 1080Sstevel@tonic-gate /* The pd is returned held */ 1090Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, 1100Sstevel@tonic-gate list, CRYPTO_FG_VERIFY, CHECK_RESTRICT(crq), 0)) == NULL) { 1110Sstevel@tonic-gate if (list != NULL) 1120Sstevel@tonic-gate kcf_free_triedlist(list); 1130Sstevel@tonic-gate return (error); 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * For SW providers, check the validity of the context template 1180Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so 1190Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by 1200Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW 1210Sstevel@tonic-gate * provider. 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) && 1240Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) { 1250Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) { 1260Sstevel@tonic-gate if (list != NULL) 1270Sstevel@tonic-gate kcf_free_triedlist(list); 1280Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1290Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE); 1300Sstevel@tonic-gate } else { 1310Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl; 1320Sstevel@tonic-gate } 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate error = crypto_verify_init_prov(pd, pd->pd_sid, mech, key, spi_ctx_tmpl, 1360Sstevel@tonic-gate ctxp, crq); 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 1390Sstevel@tonic-gate IS_RECOVERABLE(error)) { 1400Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 1410Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 1420Sstevel@tonic-gate goto retry; 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate if (list != NULL) 1460Sstevel@tonic-gate kcf_free_triedlist(list); 1470Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1480Sstevel@tonic-gate return (error); 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate int 1520Sstevel@tonic-gate crypto_verify_single(crypto_context_t context, crypto_data_t *data, 1530Sstevel@tonic-gate crypto_data_t *signature, crypto_call_req_t *cr) 1540Sstevel@tonic-gate { 1550Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 1560Sstevel@tonic-gate kcf_context_t *kcf_ctx; 1570Sstevel@tonic-gate kcf_provider_desc_t *pd; 1580Sstevel@tonic-gate int error; 1590Sstevel@tonic-gate kcf_req_params_t params; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate if ((ctx == NULL) || 1620Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 1630Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 1640Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 1650Sstevel@tonic-gate } 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 1680Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_SINGLE, 0, NULL, 1690Sstevel@tonic-gate NULL, data, signature, NULL); 1700Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 1710Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 1740Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 1750Sstevel@tonic-gate return (error); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * See comments for crypto_digest_update(). 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate int 1820Sstevel@tonic-gate crypto_verify_update(crypto_context_t context, crypto_data_t *data, 1830Sstevel@tonic-gate crypto_call_req_t *cr) 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate { 1860Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 1870Sstevel@tonic-gate kcf_context_t *kcf_ctx; 1880Sstevel@tonic-gate kcf_provider_desc_t *pd; 1890Sstevel@tonic-gate kcf_req_params_t params; 190*904Smcpowers int rv; 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if ((ctx == NULL) || 1930Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 1940Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 1950Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate 198*904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 1990Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 200*904Smcpowers KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_UPDATE, ctx->cc_session, 201*904Smcpowers NULL, NULL, data, NULL, NULL); 202*904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 2030Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2040Sstevel@tonic-gate 205*904Smcpowers return (rv); 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * See comments for crypto_digest_final(). 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate int 2120Sstevel@tonic-gate crypto_verify_final(crypto_context_t context, crypto_data_t *signature, 2130Sstevel@tonic-gate crypto_call_req_t *cr) 2140Sstevel@tonic-gate { 2150Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 2160Sstevel@tonic-gate kcf_context_t *kcf_ctx; 2170Sstevel@tonic-gate kcf_provider_desc_t *pd; 2180Sstevel@tonic-gate kcf_req_params_t params; 219*904Smcpowers int rv; 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate if ((ctx == NULL) || 2220Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 2230Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 2240Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate 227*904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 2280Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 229*904Smcpowers KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_FINAL, ctx->cc_session, 230*904Smcpowers NULL, NULL, NULL, signature, NULL); 231*904Smcpowers rv = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 2320Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 235*904Smcpowers KCF_CONTEXT_COND_RELEASE(rv, kcf_ctx); 236*904Smcpowers return (rv); 2370Sstevel@tonic-gate } 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate int 240*904Smcpowers crypto_verify_prov(crypto_provider_t provider, crypto_session_id_t sid, 241*904Smcpowers crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 242*904Smcpowers crypto_ctx_template_t tmpl, crypto_data_t *signature, 2430Sstevel@tonic-gate crypto_call_req_t *crq) 2440Sstevel@tonic-gate { 2450Sstevel@tonic-gate kcf_req_params_t params; 246*904Smcpowers kcf_provider_desc_t *pd = provider; 247*904Smcpowers kcf_provider_desc_t *real_provider = pd; 248*904Smcpowers int rv; 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 251*904Smcpowers 252*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 253*904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 254*904Smcpowers CRYPTO_MECH_INVALID, CRYPTO_OPS_OFFSET(verify_ops), 255*904Smcpowers CRYPTO_VERIFY_OFFSET(verify_atomic), CHECK_RESTRICT(crq), 256*904Smcpowers pd, &real_provider); 257*904Smcpowers 258*904Smcpowers if (rv != CRYPTO_SUCCESS) 259*904Smcpowers return (rv); 260*904Smcpowers } 2610Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech, 2620Sstevel@tonic-gate key, data, signature, tmpl); 263*904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 264*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 265*904Smcpowers KCF_PROV_REFRELE(real_provider); 2660Sstevel@tonic-gate 267*904Smcpowers return (rv); 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate static int 2710Sstevel@tonic-gate verify_vr_atomic_common(crypto_mechanism_t *mech, crypto_key_t *key, 2720Sstevel@tonic-gate crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature, 2730Sstevel@tonic-gate crypto_call_req_t *crq, crypto_func_group_t fg) 2740Sstevel@tonic-gate { 2750Sstevel@tonic-gate int error; 2760Sstevel@tonic-gate kcf_mech_entry_t *me; 2770Sstevel@tonic-gate kcf_provider_desc_t *pd; 2780Sstevel@tonic-gate kcf_req_params_t params; 2790Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 2800Sstevel@tonic-gate kcf_ctx_template_t *ctx_tmpl; 2810Sstevel@tonic-gate crypto_spi_ctx_template_t spi_ctx_tmpl = NULL; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate retry: 2840Sstevel@tonic-gate /* The pd is returned held */ 2850Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, &me, &error, list, fg, 2860Sstevel@tonic-gate CHECK_RESTRICT(crq), data->cd_length)) == NULL) { 2870Sstevel@tonic-gate if (list != NULL) 2880Sstevel@tonic-gate kcf_free_triedlist(list); 2890Sstevel@tonic-gate return (error); 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate /* 2930Sstevel@tonic-gate * For SW providers, check the validity of the context template 2940Sstevel@tonic-gate * It is very rare that the generation number mis-matches, so 2950Sstevel@tonic-gate * it is acceptable to fail here, and let the consumer recover by 2960Sstevel@tonic-gate * freeing this tmpl and create a new one for the key and new SW 2970Sstevel@tonic-gate * provider. 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate if ((pd->pd_prov_type == CRYPTO_SW_PROVIDER) && 3000Sstevel@tonic-gate ((ctx_tmpl = (kcf_ctx_template_t *)tmpl) != NULL)) { 3010Sstevel@tonic-gate if (ctx_tmpl->ct_generation != me->me_gen_swprov) { 3020Sstevel@tonic-gate if (list != NULL) 3030Sstevel@tonic-gate kcf_free_triedlist(list); 3040Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3050Sstevel@tonic-gate return (CRYPTO_OLD_CTX_TEMPLATE); 3060Sstevel@tonic-gate } else { 3070Sstevel@tonic-gate spi_ctx_tmpl = ctx_tmpl->ct_prov_tmpl; 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate /* The fast path for SW providers. */ 3120Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 3130Sstevel@tonic-gate crypto_mechanism_t lmech; 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate lmech = *mech; 3160Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech); 3170Sstevel@tonic-gate if (fg == CRYPTO_FG_VERIFY_ATOMIC) 3180Sstevel@tonic-gate error = KCF_PROV_VERIFY_ATOMIC(pd, pd->pd_sid, &lmech, 3190Sstevel@tonic-gate key, data, spi_ctx_tmpl, signature, 3200Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 3210Sstevel@tonic-gate else 3220Sstevel@tonic-gate /* Note: The argument order is different from above */ 3230Sstevel@tonic-gate error = KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, pd->pd_sid, 3240Sstevel@tonic-gate &lmech, key, signature, spi_ctx_tmpl, data, 3250Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 3260Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3270Sstevel@tonic-gate } else { 3280Sstevel@tonic-gate kcf_op_type_t op = ((fg == CRYPTO_FG_VERIFY_ATOMIC) ? 3290Sstevel@tonic-gate KCF_OP_ATOMIC : KCF_OP_VERIFY_RECOVER_ATOMIC); 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, op, pd->pd_sid, 3320Sstevel@tonic-gate mech, key, data, signature, spi_ctx_tmpl); 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 3350Sstevel@tonic-gate error = kcf_submit_request(pd, NULL, crq, ¶ms, B_FALSE); 3360Sstevel@tonic-gate } 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 3390Sstevel@tonic-gate IS_RECOVERABLE(error)) { 3400Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 3410Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 3420Sstevel@tonic-gate goto retry; 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate if (list != NULL) 3460Sstevel@tonic-gate kcf_free_triedlist(list); 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3490Sstevel@tonic-gate return (error); 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate int 3530Sstevel@tonic-gate crypto_verify(crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *data, 3540Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_data_t *signature, 3550Sstevel@tonic-gate crypto_call_req_t *crq) 3560Sstevel@tonic-gate { 3570Sstevel@tonic-gate return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq, 3580Sstevel@tonic-gate CRYPTO_FG_VERIFY_ATOMIC)); 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate int 362*904Smcpowers crypto_verify_recover_prov(crypto_provider_t provider, crypto_session_id_t sid, 363*904Smcpowers crypto_mechanism_t *mech, crypto_key_t *key, crypto_data_t *signature, 364*904Smcpowers crypto_ctx_template_t tmpl, crypto_data_t *data, crypto_call_req_t *crq) 3650Sstevel@tonic-gate { 3660Sstevel@tonic-gate kcf_req_params_t params; 367*904Smcpowers kcf_provider_desc_t *pd = provider; 368*904Smcpowers kcf_provider_desc_t *real_provider = pd; 369*904Smcpowers int rv; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 372*904Smcpowers 373*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 374*904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 375*904Smcpowers CRYPTO_MECH_INVALID, CRYPTO_OPS_OFFSET(verify_ops), 376*904Smcpowers CRYPTO_VERIFY_OFFSET(verify_recover_atomic), 377*904Smcpowers CHECK_RESTRICT(crq), pd, &real_provider); 378*904Smcpowers 379*904Smcpowers if (rv != CRYPTO_SUCCESS) 380*904Smcpowers return (rv); 381*904Smcpowers } 3820Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_VERIFY_RECOVER_ATOMIC, 3830Sstevel@tonic-gate sid, mech, key, data, signature, tmpl); 384*904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 385*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 386*904Smcpowers KCF_PROV_REFRELE(real_provider); 3870Sstevel@tonic-gate 388*904Smcpowers return (rv); 3890Sstevel@tonic-gate } 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate int 3920Sstevel@tonic-gate crypto_verify_recover(crypto_mechanism_t *mech, crypto_key_t *key, 3930Sstevel@tonic-gate crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data, 3940Sstevel@tonic-gate crypto_call_req_t *crq) 3950Sstevel@tonic-gate { 3960Sstevel@tonic-gate return (verify_vr_atomic_common(mech, key, data, tmpl, signature, crq, 3970Sstevel@tonic-gate CRYPTO_FG_VERIFY_RECOVER_ATOMIC)); 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate int 401*904Smcpowers crypto_verify_recover_init_prov(crypto_provider_t provider, 4020Sstevel@tonic-gate crypto_session_id_t sid, crypto_mechanism_t *mech, crypto_key_t *key, 4030Sstevel@tonic-gate crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *crq) 4040Sstevel@tonic-gate { 405*904Smcpowers int rv; 4060Sstevel@tonic-gate crypto_ctx_t *ctx; 4070Sstevel@tonic-gate kcf_req_params_t params; 408*904Smcpowers kcf_provider_desc_t *pd = provider; 409*904Smcpowers kcf_provider_desc_t *real_provider = pd; 4100Sstevel@tonic-gate 411*904Smcpowers ASSERT(KCF_PROV_REFHELD(pd)); 412*904Smcpowers 413*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 414*904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 415*904Smcpowers CRYPTO_MECH_INVALID, CRYPTO_OPS_OFFSET(verify_ops), 416*904Smcpowers CRYPTO_VERIFY_OFFSET(verify_recover_init), 417*904Smcpowers CHECK_RESTRICT(crq), pd, &real_provider); 418*904Smcpowers 419*904Smcpowers if (rv != CRYPTO_SUCCESS) 420*904Smcpowers return (rv); 421*904Smcpowers } 422*904Smcpowers 423*904Smcpowers /* Allocate and initialize the canonical context */ 424*904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 425*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 426*904Smcpowers KCF_PROV_REFRELE(real_provider); 4270Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 428*904Smcpowers } 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_VERIFY_RECOVER_INIT, 4310Sstevel@tonic-gate sid, mech, key, NULL, NULL, tmpl); 432*904Smcpowers rv = kcf_submit_request(real_provider, ctx, crq, ¶ms, B_FALSE); 433*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 434*904Smcpowers KCF_PROV_REFRELE(real_provider); 4350Sstevel@tonic-gate 436*904Smcpowers if ((rv == CRYPTO_SUCCESS) || (rv == CRYPTO_QUEUED)) 4370Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 4380Sstevel@tonic-gate else { 4390Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 4400Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate 443*904Smcpowers return (rv); 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate int 4470Sstevel@tonic-gate crypto_verify_recover_single(crypto_context_t context, crypto_data_t *signature, 4480Sstevel@tonic-gate crypto_data_t *data, crypto_call_req_t *cr) 4490Sstevel@tonic-gate { 4500Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4510Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4520Sstevel@tonic-gate kcf_provider_desc_t *pd; 4530Sstevel@tonic-gate int error; 4540Sstevel@tonic-gate kcf_req_params_t params; 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate if ((ctx == NULL) || 4570Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4580Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4590Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4630Sstevel@tonic-gate KCF_WRAP_VERIFY_OPS_PARAMS(¶ms, KCF_OP_VERIFY_RECOVER, 0, NULL, 4640Sstevel@tonic-gate NULL, data, signature, NULL); 4650Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4660Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4690Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4700Sstevel@tonic-gate return (error); 4710Sstevel@tonic-gate } 472