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> 310Sstevel@tonic-gate #include <sys/cmn_err.h> 32904Smcpowers #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 39904Smcpowers #define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f) 40904Smcpowers #define CRYPTO_DIGEST_OFFSET(f) offsetof(crypto_digest_ops_t, f) 41904Smcpowers 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * Message digest routines 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * The following are the possible returned values common to all the routines 480Sstevel@tonic-gate * below. The applicability of some of these return values depends on the 490Sstevel@tonic-gate * presence of the arguments. 500Sstevel@tonic-gate * 510Sstevel@tonic-gate * CRYPTO_SUCCESS: The operation completed successfully. 520Sstevel@tonic-gate * CRYPTO_QUEUED: A request was submitted successfully. The callback 530Sstevel@tonic-gate * routine will be called when the operation is done. 540Sstevel@tonic-gate * CRYPTO_MECHANISM_INVALID or CRYPTO_INVALID_MECH_PARAM 550Sstevel@tonic-gate * for problems with the 'mech'. 560Sstevel@tonic-gate * CRYPTO_INVALID_DATA for bogus 'data' 570Sstevel@tonic-gate * CRYPTO_HOST_MEMORY for failure to allocate memory to handle this work. 580Sstevel@tonic-gate * CRYPTO_INVALID_CONTEXT: Not a valid context. 590Sstevel@tonic-gate * CRYPTO_BUSY: Cannot process the request now. Schedule a 600Sstevel@tonic-gate * crypto_bufcall(), or try later. 610Sstevel@tonic-gate * CRYPTO_NOT_SUPPORTED and CRYPTO_MECH_NOT_SUPPORTED: 620Sstevel@tonic-gate * No provider is capable of a function or a mechanism. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * crypto_digest_prov() 680Sstevel@tonic-gate * 690Sstevel@tonic-gate * Arguments: 700Sstevel@tonic-gate * pd: pointer to the descriptor of the provider to use for this 710Sstevel@tonic-gate * operation. 720Sstevel@tonic-gate * sid: provider session id. 730Sstevel@tonic-gate * mech: crypto_mechanism_t pointer. 740Sstevel@tonic-gate * mech_type is a valid value previously returned by 750Sstevel@tonic-gate * crypto_mech2id(); 760Sstevel@tonic-gate * When the mech's parameter is not NULL, its definition depends 770Sstevel@tonic-gate * on the standard definition of the mechanism. 780Sstevel@tonic-gate * data: The message to be digested. 790Sstevel@tonic-gate * digest: Storage for the digest. The length needed depends on the 800Sstevel@tonic-gate * mechanism. 810Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * Description: 840Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 850Sstevel@tonic-gate * digesting operation of 'data' on the specified 860Sstevel@tonic-gate * provider with the specified session. 870Sstevel@tonic-gate * When complete and successful, 'digest' will contain the digest value. 880Sstevel@tonic-gate * The caller should hold a reference on the specified provider 890Sstevel@tonic-gate * descriptor before calling this function. 900Sstevel@tonic-gate * 910Sstevel@tonic-gate * Context: 920Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * Returns: 950Sstevel@tonic-gate * See comment in the beginning of the file. 960Sstevel@tonic-gate */ 970Sstevel@tonic-gate int 98904Smcpowers crypto_digest_prov(crypto_provider_t provider, crypto_session_id_t sid, 99904Smcpowers crypto_mechanism_t *mech, crypto_data_t *data, crypto_data_t *digest, 100904Smcpowers crypto_call_req_t *crq) 1010Sstevel@tonic-gate { 1020Sstevel@tonic-gate kcf_req_params_t params; 103904Smcpowers kcf_provider_desc_t *pd = provider; 104904Smcpowers kcf_provider_desc_t *real_provider = pd; 105904Smcpowers int rv; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 108904Smcpowers 109904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 110904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 111*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), 112*1808Smcpowers pd, &real_provider, CRYPTO_FG_DIGEST_ATOMIC); 113904Smcpowers 114904Smcpowers if (rv != CRYPTO_SUCCESS) 115904Smcpowers return (rv); 116904Smcpowers } 1170Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech, NULL, 1180Sstevel@tonic-gate data, digest); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 121904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 122904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 123904Smcpowers KCF_PROV_REFRELE(real_provider); 124904Smcpowers 125904Smcpowers return (rv); 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * Same as crypto_digest_prov(), but relies on the KCF scheduler to 1300Sstevel@tonic-gate * choose a provider. See crypto_digest_prov() comments for more information. 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate int 1330Sstevel@tonic-gate crypto_digest(crypto_mechanism_t *mech, crypto_data_t *data, 1340Sstevel@tonic-gate crypto_data_t *digest, crypto_call_req_t *crq) 1350Sstevel@tonic-gate { 1360Sstevel@tonic-gate int error; 1370Sstevel@tonic-gate kcf_provider_desc_t *pd; 1380Sstevel@tonic-gate kcf_req_params_t params; 1390Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate retry: 1420Sstevel@tonic-gate /* The pd is returned held */ 1430Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, NULL, &error, list, 1440Sstevel@tonic-gate CRYPTO_FG_DIGEST_ATOMIC, CHECK_RESTRICT(crq), 1450Sstevel@tonic-gate data->cd_length)) == NULL) { 1460Sstevel@tonic-gate if (list != NULL) 1470Sstevel@tonic-gate kcf_free_triedlist(list); 1480Sstevel@tonic-gate return (error); 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* The fast path for SW providers. */ 1520Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 1530Sstevel@tonic-gate crypto_mechanism_t lmech; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate lmech = *mech; 1560Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech); 1570Sstevel@tonic-gate error = KCF_PROV_DIGEST_ATOMIC(pd, pd->pd_sid, &lmech, data, 1580Sstevel@tonic-gate digest, KCF_SWFP_RHNDL(crq)); 1590Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 1600Sstevel@tonic-gate } else { 1610Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, pd->pd_sid, 1620Sstevel@tonic-gate mech, NULL, data, digest); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 1650Sstevel@tonic-gate error = kcf_submit_request(pd, NULL, crq, ¶ms, B_FALSE); 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 1690Sstevel@tonic-gate IS_RECOVERABLE(error)) { 1700Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 1710Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 1720Sstevel@tonic-gate goto retry; 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate if (list != NULL) 1760Sstevel@tonic-gate kcf_free_triedlist(list); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1790Sstevel@tonic-gate return (error); 1800Sstevel@tonic-gate } 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * crypto_digest_init_prov() 1840Sstevel@tonic-gate * 1850Sstevel@tonic-gate * pd: pointer to the descriptor of the provider to use for this 1860Sstevel@tonic-gate * operation. 1870Sstevel@tonic-gate * sid: provider session id. 1880Sstevel@tonic-gate * mech: crypto_mechanism_t pointer. 1890Sstevel@tonic-gate * mech_type is a valid value previously returned by 1900Sstevel@tonic-gate * crypto_mech2id(); 1910Sstevel@tonic-gate * When the mech's parameter is not NULL, its definition depends 1920Sstevel@tonic-gate * on the standard definition of the mechanism. 1930Sstevel@tonic-gate * ctxp: Pointer to a crypto_context_t. 1940Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 1950Sstevel@tonic-gate * 1960Sstevel@tonic-gate * Description: 1970Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 1980Sstevel@tonic-gate * initialization of a message digest operation on the specified 1990Sstevel@tonic-gate * provider with the specified session. 2000Sstevel@tonic-gate * When complete and successful, 'ctxp' will contain a crypto_context_t 2010Sstevel@tonic-gate * valid for later calls to digest_update() and digest_final(). 2020Sstevel@tonic-gate * The caller should hold a reference on the specified provider 2030Sstevel@tonic-gate * descriptor before calling this function. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate int 206904Smcpowers crypto_digest_init_prov(crypto_provider_t provider, crypto_session_id_t sid, 207904Smcpowers crypto_mechanism_t *mech, crypto_context_t *ctxp, crypto_call_req_t *crq) 2080Sstevel@tonic-gate { 2090Sstevel@tonic-gate int error; 2100Sstevel@tonic-gate crypto_ctx_t *ctx; 2110Sstevel@tonic-gate kcf_req_params_t params; 212904Smcpowers kcf_provider_desc_t *pd = provider; 213904Smcpowers kcf_provider_desc_t *real_provider = pd; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 2160Sstevel@tonic-gate 217904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 218904Smcpowers error = kcf_get_hardware_provider(mech->cm_type, 219*1808Smcpowers CRYPTO_MECH_INVALID, CHECK_RESTRICT(crq), pd, 220*1808Smcpowers &real_provider, CRYPTO_FG_DIGEST); 221904Smcpowers 222904Smcpowers if (error != CRYPTO_SUCCESS) 223904Smcpowers return (error); 224904Smcpowers } 225904Smcpowers 226904Smcpowers /* Allocate and initialize the canonical context */ 227904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 228904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 229904Smcpowers KCF_PROV_REFRELE(real_provider); 2300Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 231904Smcpowers } 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* The fast path for SW providers. */ 2340Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 2350Sstevel@tonic-gate crypto_mechanism_t lmech; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate lmech = *mech; 238904Smcpowers KCF_SET_PROVIDER_MECHNUM(mech->cm_type, real_provider, &lmech); 239904Smcpowers error = KCF_PROV_DIGEST_INIT(real_provider, ctx, &lmech, 2400Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 2410Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 2420Sstevel@tonic-gate } else { 2430Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_INIT, sid, 2440Sstevel@tonic-gate mech, NULL, NULL, NULL); 245904Smcpowers error = kcf_submit_request(real_provider, ctx, crq, ¶ms, 246904Smcpowers B_FALSE); 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate 249904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 250904Smcpowers KCF_PROV_REFRELE(real_provider); 251904Smcpowers 2520Sstevel@tonic-gate if ((error == CRYPTO_SUCCESS) || (error == CRYPTO_QUEUED)) 2530Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 2540Sstevel@tonic-gate else { 2550Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 2560Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate return (error); 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate /* 2640Sstevel@tonic-gate * Same as crypto_digest_init_prov(), but relies on the KCF scheduler 2650Sstevel@tonic-gate * to choose a provider. See crypto_digest_init_prov() comments for 2660Sstevel@tonic-gate * more information. 2670Sstevel@tonic-gate */ 2680Sstevel@tonic-gate int 2690Sstevel@tonic-gate crypto_digest_init(crypto_mechanism_t *mech, crypto_context_t *ctxp, 2700Sstevel@tonic-gate crypto_call_req_t *crq) 2710Sstevel@tonic-gate { 2720Sstevel@tonic-gate int error; 2730Sstevel@tonic-gate kcf_provider_desc_t *pd; 2740Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate retry: 2770Sstevel@tonic-gate /* The pd is returned held */ 2780Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, NULL, &error, 2790Sstevel@tonic-gate list, CRYPTO_FG_DIGEST, CHECK_RESTRICT(crq), 0)) == NULL) { 2800Sstevel@tonic-gate if (list != NULL) 2810Sstevel@tonic-gate kcf_free_triedlist(list); 2820Sstevel@tonic-gate return (error); 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate error = crypto_digest_init_prov(pd, pd->pd_sid, mech, ctxp, crq); 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 2880Sstevel@tonic-gate IS_RECOVERABLE(error)) { 2890Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 2900Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 2910Sstevel@tonic-gate goto retry; 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate if (list != NULL) 2950Sstevel@tonic-gate kcf_free_triedlist(list); 2960Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 2970Sstevel@tonic-gate return (error); 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate /* 3010Sstevel@tonic-gate * crypto_digest_update() 3020Sstevel@tonic-gate * 3030Sstevel@tonic-gate * Arguments: 3040Sstevel@tonic-gate * context: A crypto_context_t initialized by digest_init(). 3050Sstevel@tonic-gate * data: The part of message to be digested. 3060Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 3070Sstevel@tonic-gate * 3080Sstevel@tonic-gate * Description: 3090Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs a 3100Sstevel@tonic-gate * part of a message digest operation. 3110Sstevel@tonic-gate * 3120Sstevel@tonic-gate * Context: 3130Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 3140Sstevel@tonic-gate * 3150Sstevel@tonic-gate * Returns: 3160Sstevel@tonic-gate * See comment in the beginning of the file. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate int 3190Sstevel@tonic-gate crypto_digest_update(crypto_context_t context, crypto_data_t *data, 3200Sstevel@tonic-gate crypto_call_req_t *cr) 3210Sstevel@tonic-gate { 3220Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 3230Sstevel@tonic-gate kcf_context_t *kcf_ctx; 3240Sstevel@tonic-gate kcf_provider_desc_t *pd; 3250Sstevel@tonic-gate int error; 3260Sstevel@tonic-gate kcf_req_params_t params; 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate if ((ctx == NULL) || 3290Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 3300Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 3310Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 3320Sstevel@tonic-gate } 3330Sstevel@tonic-gate 334904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 3350Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate /* The fast path for SW providers. */ 3380Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 3390Sstevel@tonic-gate error = KCF_PROV_DIGEST_UPDATE(pd, ctx, data, NULL); 3400Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3410Sstevel@tonic-gate } else { 342904Smcpowers KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_UPDATE, 343904Smcpowers ctx->cc_session, NULL, NULL, data, NULL); 3440Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3480Sstevel@tonic-gate return (error); 3490Sstevel@tonic-gate } 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 3520Sstevel@tonic-gate * crypto_digest_final() 3530Sstevel@tonic-gate * 3540Sstevel@tonic-gate * Arguments: 3550Sstevel@tonic-gate * context: A crypto_context_t initialized by digest_init(). 3560Sstevel@tonic-gate * digest: The storage for the digest. 3570Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 3580Sstevel@tonic-gate * 3590Sstevel@tonic-gate * Description: 3600Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 3610Sstevel@tonic-gate * final part of a message digest operation. 3620Sstevel@tonic-gate * 3630Sstevel@tonic-gate * Context: 3640Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 3650Sstevel@tonic-gate * 3660Sstevel@tonic-gate * Returns: 3670Sstevel@tonic-gate * See comment in the beginning of the file. 3680Sstevel@tonic-gate */ 3690Sstevel@tonic-gate int 3700Sstevel@tonic-gate crypto_digest_final(crypto_context_t context, crypto_data_t *digest, 3710Sstevel@tonic-gate crypto_call_req_t *cr) 3720Sstevel@tonic-gate { 3730Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 3740Sstevel@tonic-gate kcf_context_t *kcf_ctx; 3750Sstevel@tonic-gate kcf_provider_desc_t *pd; 3760Sstevel@tonic-gate int error; 3770Sstevel@tonic-gate kcf_req_params_t params; 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate if ((ctx == NULL) || 3800Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 3810Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 3820Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate 385904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 3860Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /* The fast path for SW providers. */ 3890Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 3900Sstevel@tonic-gate error = KCF_PROV_DIGEST_FINAL(pd, ctx, digest, NULL); 3910Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3920Sstevel@tonic-gate } else { 393904Smcpowers KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_FINAL, 394904Smcpowers ctx->cc_session, NULL, NULL, NULL, digest); 3950Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 3960Sstevel@tonic-gate } 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3990Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4000Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4010Sstevel@tonic-gate return (error); 4020Sstevel@tonic-gate } 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate /* 4050Sstevel@tonic-gate * Performs a digest update on the specified key. Note that there is 4060Sstevel@tonic-gate * no k-API crypto_digest_key() equivalent of this function. 4070Sstevel@tonic-gate */ 4080Sstevel@tonic-gate int 4090Sstevel@tonic-gate crypto_digest_key_prov(crypto_context_t context, crypto_key_t *key, 4100Sstevel@tonic-gate crypto_call_req_t *cr) 4110Sstevel@tonic-gate { 4120Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4130Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4140Sstevel@tonic-gate kcf_provider_desc_t *pd; 4150Sstevel@tonic-gate int error; 4160Sstevel@tonic-gate kcf_req_params_t params; 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate if ((ctx == NULL) || 4190Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4200Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4210Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4220Sstevel@tonic-gate } 4230Sstevel@tonic-gate 424904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 4250Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate /* The fast path for SW providers. */ 4280Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4290Sstevel@tonic-gate error = KCF_PROV_DIGEST_KEY(pd, ctx, key, NULL); 4300Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4310Sstevel@tonic-gate } else { 4320Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_DIGEST_KEY, 433904Smcpowers ctx->cc_session, NULL, key, NULL, NULL); 4340Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4350Sstevel@tonic-gate } 436904Smcpowers KCF_PROV_REFRELE(pd); 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate return (error); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* 4420Sstevel@tonic-gate * See comments for crypto_digest_update() and crypto_digest_final(). 4430Sstevel@tonic-gate */ 4440Sstevel@tonic-gate int 4450Sstevel@tonic-gate crypto_digest_single(crypto_context_t context, crypto_data_t *data, 4460Sstevel@tonic-gate crypto_data_t *digest, crypto_call_req_t *cr) 4470Sstevel@tonic-gate { 4480Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4490Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4500Sstevel@tonic-gate kcf_provider_desc_t *pd; 4510Sstevel@tonic-gate int error; 4520Sstevel@tonic-gate kcf_req_params_t params; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate if ((ctx == NULL) || 4550Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4560Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4570Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate /* The fast path for SW providers. */ 4630Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4640Sstevel@tonic-gate error = KCF_PROV_DIGEST(pd, ctx, data, digest, NULL); 4650Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4660Sstevel@tonic-gate } else { 4670Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_SINGLE, pd->pd_sid, 4680Sstevel@tonic-gate NULL, NULL, data, digest); 4690Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 4730Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4740Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4750Sstevel@tonic-gate return (error); 4760Sstevel@tonic-gate } 477