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> 320Sstevel@tonic-gate #include <sys/cmn_err.h> 33*904Smcpowers #include <sys/sysmacros.h> 340Sstevel@tonic-gate #include <sys/crypto/common.h> 350Sstevel@tonic-gate #include <sys/crypto/impl.h> 360Sstevel@tonic-gate #include <sys/crypto/api.h> 370Sstevel@tonic-gate #include <sys/crypto/spi.h> 380Sstevel@tonic-gate #include <sys/crypto/sched_impl.h> 390Sstevel@tonic-gate 40*904Smcpowers #define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f) 41*904Smcpowers #define CRYPTO_DIGEST_OFFSET(f) offsetof(crypto_digest_ops_t, f) 42*904Smcpowers 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * Message digest routines 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * The following are the possible returned values common to all the routines 490Sstevel@tonic-gate * below. The applicability of some of these return values depends on the 500Sstevel@tonic-gate * presence of the arguments. 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * CRYPTO_SUCCESS: The operation completed successfully. 530Sstevel@tonic-gate * CRYPTO_QUEUED: A request was submitted successfully. The callback 540Sstevel@tonic-gate * routine will be called when the operation is done. 550Sstevel@tonic-gate * CRYPTO_MECHANISM_INVALID or CRYPTO_INVALID_MECH_PARAM 560Sstevel@tonic-gate * for problems with the 'mech'. 570Sstevel@tonic-gate * CRYPTO_INVALID_DATA for bogus 'data' 580Sstevel@tonic-gate * CRYPTO_HOST_MEMORY for failure to allocate memory to handle this work. 590Sstevel@tonic-gate * CRYPTO_INVALID_CONTEXT: Not a valid context. 600Sstevel@tonic-gate * CRYPTO_BUSY: Cannot process the request now. Schedule a 610Sstevel@tonic-gate * crypto_bufcall(), or try later. 620Sstevel@tonic-gate * CRYPTO_NOT_SUPPORTED and CRYPTO_MECH_NOT_SUPPORTED: 630Sstevel@tonic-gate * No provider is capable of a function or a mechanism. 640Sstevel@tonic-gate */ 650Sstevel@tonic-gate 660Sstevel@tonic-gate 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * crypto_digest_prov() 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * Arguments: 710Sstevel@tonic-gate * pd: pointer to the descriptor of the provider to use for this 720Sstevel@tonic-gate * operation. 730Sstevel@tonic-gate * sid: provider session id. 740Sstevel@tonic-gate * mech: crypto_mechanism_t pointer. 750Sstevel@tonic-gate * mech_type is a valid value previously returned by 760Sstevel@tonic-gate * crypto_mech2id(); 770Sstevel@tonic-gate * When the mech's parameter is not NULL, its definition depends 780Sstevel@tonic-gate * on the standard definition of the mechanism. 790Sstevel@tonic-gate * data: The message to be digested. 800Sstevel@tonic-gate * digest: Storage for the digest. The length needed depends on the 810Sstevel@tonic-gate * mechanism. 820Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 830Sstevel@tonic-gate * 840Sstevel@tonic-gate * Description: 850Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 860Sstevel@tonic-gate * digesting operation of 'data' on the specified 870Sstevel@tonic-gate * provider with the specified session. 880Sstevel@tonic-gate * When complete and successful, 'digest' will contain the digest value. 890Sstevel@tonic-gate * The caller should hold a reference on the specified provider 900Sstevel@tonic-gate * descriptor before calling this function. 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * Context: 930Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * Returns: 960Sstevel@tonic-gate * See comment in the beginning of the file. 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate int 99*904Smcpowers crypto_digest_prov(crypto_provider_t provider, crypto_session_id_t sid, 100*904Smcpowers crypto_mechanism_t *mech, crypto_data_t *data, crypto_data_t *digest, 101*904Smcpowers crypto_call_req_t *crq) 1020Sstevel@tonic-gate { 1030Sstevel@tonic-gate kcf_req_params_t params; 104*904Smcpowers kcf_provider_desc_t *pd = provider; 105*904Smcpowers kcf_provider_desc_t *real_provider = pd; 106*904Smcpowers int rv; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 109*904Smcpowers 110*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 111*904Smcpowers rv = kcf_get_hardware_provider(mech->cm_type, 112*904Smcpowers CRYPTO_MECH_INVALID, CRYPTO_OPS_OFFSET(digest_ops), 113*904Smcpowers CRYPTO_DIGEST_OFFSET(digest_atomic), CHECK_RESTRICT(crq), 114*904Smcpowers pd, &real_provider); 115*904Smcpowers 116*904Smcpowers if (rv != CRYPTO_SUCCESS) 117*904Smcpowers return (rv); 118*904Smcpowers } 1190Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech, NULL, 1200Sstevel@tonic-gate data, digest); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 123*904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 124*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 125*904Smcpowers KCF_PROV_REFRELE(real_provider); 126*904Smcpowers 127*904Smcpowers return (rv); 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * Same as crypto_digest_prov(), but relies on the KCF scheduler to 1320Sstevel@tonic-gate * choose a provider. See crypto_digest_prov() comments for more information. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate int 1350Sstevel@tonic-gate crypto_digest(crypto_mechanism_t *mech, crypto_data_t *data, 1360Sstevel@tonic-gate crypto_data_t *digest, crypto_call_req_t *crq) 1370Sstevel@tonic-gate { 1380Sstevel@tonic-gate int error; 1390Sstevel@tonic-gate kcf_provider_desc_t *pd; 1400Sstevel@tonic-gate kcf_req_params_t params; 1410Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate retry: 1440Sstevel@tonic-gate /* The pd is returned held */ 1450Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, NULL, &error, list, 1460Sstevel@tonic-gate CRYPTO_FG_DIGEST_ATOMIC, CHECK_RESTRICT(crq), 1470Sstevel@tonic-gate data->cd_length)) == NULL) { 1480Sstevel@tonic-gate if (list != NULL) 1490Sstevel@tonic-gate kcf_free_triedlist(list); 1500Sstevel@tonic-gate return (error); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* The fast path for SW providers. */ 1540Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 1550Sstevel@tonic-gate crypto_mechanism_t lmech; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate lmech = *mech; 1580Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech); 1590Sstevel@tonic-gate error = KCF_PROV_DIGEST_ATOMIC(pd, pd->pd_sid, &lmech, data, 1600Sstevel@tonic-gate digest, KCF_SWFP_RHNDL(crq)); 1610Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 1620Sstevel@tonic-gate } else { 1630Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, pd->pd_sid, 1640Sstevel@tonic-gate mech, NULL, data, digest); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 1670Sstevel@tonic-gate error = kcf_submit_request(pd, NULL, crq, ¶ms, B_FALSE); 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 1710Sstevel@tonic-gate IS_RECOVERABLE(error)) { 1720Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 1730Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 1740Sstevel@tonic-gate goto retry; 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate if (list != NULL) 1780Sstevel@tonic-gate kcf_free_triedlist(list); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1810Sstevel@tonic-gate return (error); 1820Sstevel@tonic-gate } 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate /* 1850Sstevel@tonic-gate * crypto_digest_init_prov() 1860Sstevel@tonic-gate * 1870Sstevel@tonic-gate * pd: pointer to the descriptor of the provider to use for this 1880Sstevel@tonic-gate * operation. 1890Sstevel@tonic-gate * sid: provider session id. 1900Sstevel@tonic-gate * mech: crypto_mechanism_t pointer. 1910Sstevel@tonic-gate * mech_type is a valid value previously returned by 1920Sstevel@tonic-gate * crypto_mech2id(); 1930Sstevel@tonic-gate * When the mech's parameter is not NULL, its definition depends 1940Sstevel@tonic-gate * on the standard definition of the mechanism. 1950Sstevel@tonic-gate * ctxp: Pointer to a crypto_context_t. 1960Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 1970Sstevel@tonic-gate * 1980Sstevel@tonic-gate * Description: 1990Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 2000Sstevel@tonic-gate * initialization of a message digest operation on the specified 2010Sstevel@tonic-gate * provider with the specified session. 2020Sstevel@tonic-gate * When complete and successful, 'ctxp' will contain a crypto_context_t 2030Sstevel@tonic-gate * valid for later calls to digest_update() and digest_final(). 2040Sstevel@tonic-gate * The caller should hold a reference on the specified provider 2050Sstevel@tonic-gate * descriptor before calling this function. 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate int 208*904Smcpowers crypto_digest_init_prov(crypto_provider_t provider, crypto_session_id_t sid, 209*904Smcpowers crypto_mechanism_t *mech, crypto_context_t *ctxp, crypto_call_req_t *crq) 2100Sstevel@tonic-gate { 2110Sstevel@tonic-gate int error; 2120Sstevel@tonic-gate crypto_ctx_t *ctx; 2130Sstevel@tonic-gate kcf_req_params_t params; 214*904Smcpowers kcf_provider_desc_t *pd = provider; 215*904Smcpowers kcf_provider_desc_t *real_provider = pd; 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 2180Sstevel@tonic-gate 219*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 220*904Smcpowers error = kcf_get_hardware_provider(mech->cm_type, 221*904Smcpowers CRYPTO_MECH_INVALID, CRYPTO_OPS_OFFSET(digest_ops), 222*904Smcpowers CRYPTO_DIGEST_OFFSET(digest_init), 223*904Smcpowers CHECK_RESTRICT(crq), pd, &real_provider); 224*904Smcpowers 225*904Smcpowers if (error != CRYPTO_SUCCESS) 226*904Smcpowers return (error); 227*904Smcpowers } 228*904Smcpowers 229*904Smcpowers /* Allocate and initialize the canonical context */ 230*904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 231*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 232*904Smcpowers KCF_PROV_REFRELE(real_provider); 2330Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 234*904Smcpowers } 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate /* The fast path for SW providers. */ 2370Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 2380Sstevel@tonic-gate crypto_mechanism_t lmech; 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate lmech = *mech; 241*904Smcpowers KCF_SET_PROVIDER_MECHNUM(mech->cm_type, real_provider, &lmech); 242*904Smcpowers error = KCF_PROV_DIGEST_INIT(real_provider, ctx, &lmech, 2430Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 2440Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 2450Sstevel@tonic-gate } else { 2460Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_INIT, sid, 2470Sstevel@tonic-gate mech, NULL, NULL, NULL); 248*904Smcpowers error = kcf_submit_request(real_provider, ctx, crq, ¶ms, 249*904Smcpowers B_FALSE); 2500Sstevel@tonic-gate } 2510Sstevel@tonic-gate 252*904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 253*904Smcpowers KCF_PROV_REFRELE(real_provider); 254*904Smcpowers 2550Sstevel@tonic-gate if ((error == CRYPTO_SUCCESS) || (error == CRYPTO_QUEUED)) 2560Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 2570Sstevel@tonic-gate else { 2580Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 2590Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate return (error); 2630Sstevel@tonic-gate } 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Same as crypto_digest_init_prov(), but relies on the KCF scheduler 2680Sstevel@tonic-gate * to choose a provider. See crypto_digest_init_prov() comments for 2690Sstevel@tonic-gate * more information. 2700Sstevel@tonic-gate */ 2710Sstevel@tonic-gate int 2720Sstevel@tonic-gate crypto_digest_init(crypto_mechanism_t *mech, crypto_context_t *ctxp, 2730Sstevel@tonic-gate crypto_call_req_t *crq) 2740Sstevel@tonic-gate { 2750Sstevel@tonic-gate int error; 2760Sstevel@tonic-gate kcf_provider_desc_t *pd; 2770Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate retry: 2800Sstevel@tonic-gate /* The pd is returned held */ 2810Sstevel@tonic-gate if ((pd = kcf_get_mech_provider(mech->cm_type, NULL, &error, 2820Sstevel@tonic-gate list, CRYPTO_FG_DIGEST, CHECK_RESTRICT(crq), 0)) == NULL) { 2830Sstevel@tonic-gate if (list != NULL) 2840Sstevel@tonic-gate kcf_free_triedlist(list); 2850Sstevel@tonic-gate return (error); 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate error = crypto_digest_init_prov(pd, pd->pd_sid, mech, ctxp, crq); 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 2910Sstevel@tonic-gate IS_RECOVERABLE(error)) { 2920Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 2930Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 2940Sstevel@tonic-gate goto retry; 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate if (list != NULL) 2980Sstevel@tonic-gate kcf_free_triedlist(list); 2990Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3000Sstevel@tonic-gate return (error); 3010Sstevel@tonic-gate } 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* 3040Sstevel@tonic-gate * crypto_digest_update() 3050Sstevel@tonic-gate * 3060Sstevel@tonic-gate * Arguments: 3070Sstevel@tonic-gate * context: A crypto_context_t initialized by digest_init(). 3080Sstevel@tonic-gate * data: The part of message to be digested. 3090Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 3100Sstevel@tonic-gate * 3110Sstevel@tonic-gate * Description: 3120Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs a 3130Sstevel@tonic-gate * part of a message digest operation. 3140Sstevel@tonic-gate * 3150Sstevel@tonic-gate * Context: 3160Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 3170Sstevel@tonic-gate * 3180Sstevel@tonic-gate * Returns: 3190Sstevel@tonic-gate * See comment in the beginning of the file. 3200Sstevel@tonic-gate */ 3210Sstevel@tonic-gate int 3220Sstevel@tonic-gate crypto_digest_update(crypto_context_t context, crypto_data_t *data, 3230Sstevel@tonic-gate crypto_call_req_t *cr) 3240Sstevel@tonic-gate { 3250Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 3260Sstevel@tonic-gate kcf_context_t *kcf_ctx; 3270Sstevel@tonic-gate kcf_provider_desc_t *pd; 3280Sstevel@tonic-gate int error; 3290Sstevel@tonic-gate kcf_req_params_t params; 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate if ((ctx == NULL) || 3320Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 3330Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 3340Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate 337*904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 3380Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate /* The fast path for SW providers. */ 3410Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 3420Sstevel@tonic-gate error = KCF_PROV_DIGEST_UPDATE(pd, ctx, data, NULL); 3430Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3440Sstevel@tonic-gate } else { 345*904Smcpowers KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_UPDATE, 346*904Smcpowers ctx->cc_session, NULL, NULL, data, NULL); 3470Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3510Sstevel@tonic-gate return (error); 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate /* 3550Sstevel@tonic-gate * crypto_digest_final() 3560Sstevel@tonic-gate * 3570Sstevel@tonic-gate * Arguments: 3580Sstevel@tonic-gate * context: A crypto_context_t initialized by digest_init(). 3590Sstevel@tonic-gate * digest: The storage for the digest. 3600Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 3610Sstevel@tonic-gate * 3620Sstevel@tonic-gate * Description: 3630Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 3640Sstevel@tonic-gate * final part of a message digest operation. 3650Sstevel@tonic-gate * 3660Sstevel@tonic-gate * Context: 3670Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 3680Sstevel@tonic-gate * 3690Sstevel@tonic-gate * Returns: 3700Sstevel@tonic-gate * See comment in the beginning of the file. 3710Sstevel@tonic-gate */ 3720Sstevel@tonic-gate int 3730Sstevel@tonic-gate crypto_digest_final(crypto_context_t context, crypto_data_t *digest, 3740Sstevel@tonic-gate crypto_call_req_t *cr) 3750Sstevel@tonic-gate { 3760Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 3770Sstevel@tonic-gate kcf_context_t *kcf_ctx; 3780Sstevel@tonic-gate kcf_provider_desc_t *pd; 3790Sstevel@tonic-gate int error; 3800Sstevel@tonic-gate kcf_req_params_t params; 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate if ((ctx == NULL) || 3830Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 3840Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 3850Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 3860Sstevel@tonic-gate } 3870Sstevel@tonic-gate 388*904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 3890Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate /* The fast path for SW providers. */ 3920Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 3930Sstevel@tonic-gate error = KCF_PROV_DIGEST_FINAL(pd, ctx, digest, NULL); 3940Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3950Sstevel@tonic-gate } else { 396*904Smcpowers KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_FINAL, 397*904Smcpowers ctx->cc_session, NULL, NULL, NULL, digest); 3980Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 4020Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4030Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4040Sstevel@tonic-gate return (error); 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Performs a digest update on the specified key. Note that there is 4090Sstevel@tonic-gate * no k-API crypto_digest_key() equivalent of this function. 4100Sstevel@tonic-gate */ 4110Sstevel@tonic-gate int 4120Sstevel@tonic-gate crypto_digest_key_prov(crypto_context_t context, crypto_key_t *key, 4130Sstevel@tonic-gate crypto_call_req_t *cr) 4140Sstevel@tonic-gate { 4150Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4160Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4170Sstevel@tonic-gate kcf_provider_desc_t *pd; 4180Sstevel@tonic-gate int error; 4190Sstevel@tonic-gate kcf_req_params_t params; 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate if ((ctx == NULL) || 4220Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4230Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4240Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4250Sstevel@tonic-gate } 4260Sstevel@tonic-gate 427*904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 4280Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* The fast path for SW providers. */ 4310Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4320Sstevel@tonic-gate error = KCF_PROV_DIGEST_KEY(pd, ctx, key, NULL); 4330Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4340Sstevel@tonic-gate } else { 4350Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_DIGEST_KEY, 436*904Smcpowers ctx->cc_session, NULL, key, NULL, NULL); 4370Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4380Sstevel@tonic-gate } 439*904Smcpowers KCF_PROV_REFRELE(pd); 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate return (error); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate /* 4450Sstevel@tonic-gate * See comments for crypto_digest_update() and crypto_digest_final(). 4460Sstevel@tonic-gate */ 4470Sstevel@tonic-gate int 4480Sstevel@tonic-gate crypto_digest_single(crypto_context_t context, crypto_data_t *data, 4490Sstevel@tonic-gate crypto_data_t *digest, crypto_call_req_t *cr) 4500Sstevel@tonic-gate { 4510Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4520Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4530Sstevel@tonic-gate kcf_provider_desc_t *pd; 4540Sstevel@tonic-gate int error; 4550Sstevel@tonic-gate kcf_req_params_t params; 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate if ((ctx == NULL) || 4580Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4590Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4600Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate KCF_PROV_REFHOLD(pd); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* The fast path for SW providers. */ 4660Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4670Sstevel@tonic-gate error = KCF_PROV_DIGEST(pd, ctx, data, digest, NULL); 4680Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4690Sstevel@tonic-gate } else { 4700Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_SINGLE, pd->pd_sid, 4710Sstevel@tonic-gate NULL, NULL, data, digest); 4720Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 4760Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4770Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4780Sstevel@tonic-gate return (error); 4790Sstevel@tonic-gate } 480