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 51808Smcpowers * Common Development and Distribution License (the "License"). 61808Smcpowers * 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*10444SVladimir.Kotal@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <sys/errno.h> 270Sstevel@tonic-gate #include <sys/types.h> 280Sstevel@tonic-gate #include <sys/kmem.h> 290Sstevel@tonic-gate #include <sys/cmn_err.h> 30904Smcpowers #include <sys/sysmacros.h> 310Sstevel@tonic-gate #include <sys/crypto/common.h> 320Sstevel@tonic-gate #include <sys/crypto/impl.h> 330Sstevel@tonic-gate #include <sys/crypto/api.h> 340Sstevel@tonic-gate #include <sys/crypto/spi.h> 350Sstevel@tonic-gate #include <sys/crypto/sched_impl.h> 360Sstevel@tonic-gate 37904Smcpowers #define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f) 38904Smcpowers #define CRYPTO_DIGEST_OFFSET(f) offsetof(crypto_digest_ops_t, f) 39904Smcpowers 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * Message digest routines 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * The following are the possible returned values common to all the routines 460Sstevel@tonic-gate * below. The applicability of some of these return values depends on the 470Sstevel@tonic-gate * presence of the arguments. 480Sstevel@tonic-gate * 490Sstevel@tonic-gate * CRYPTO_SUCCESS: The operation completed successfully. 500Sstevel@tonic-gate * CRYPTO_QUEUED: A request was submitted successfully. The callback 510Sstevel@tonic-gate * routine will be called when the operation is done. 520Sstevel@tonic-gate * CRYPTO_MECHANISM_INVALID or CRYPTO_INVALID_MECH_PARAM 530Sstevel@tonic-gate * for problems with the 'mech'. 540Sstevel@tonic-gate * CRYPTO_INVALID_DATA for bogus 'data' 550Sstevel@tonic-gate * CRYPTO_HOST_MEMORY for failure to allocate memory to handle this work. 560Sstevel@tonic-gate * CRYPTO_INVALID_CONTEXT: Not a valid context. 570Sstevel@tonic-gate * CRYPTO_BUSY: Cannot process the request now. Schedule a 580Sstevel@tonic-gate * crypto_bufcall(), or try later. 590Sstevel@tonic-gate * CRYPTO_NOT_SUPPORTED and CRYPTO_MECH_NOT_SUPPORTED: 600Sstevel@tonic-gate * No provider is capable of a function or a mechanism. 610Sstevel@tonic-gate */ 620Sstevel@tonic-gate 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * crypto_digest_prov() 660Sstevel@tonic-gate * 670Sstevel@tonic-gate * Arguments: 680Sstevel@tonic-gate * pd: pointer to the descriptor of the provider to use for this 690Sstevel@tonic-gate * operation. 700Sstevel@tonic-gate * sid: provider session id. 710Sstevel@tonic-gate * mech: crypto_mechanism_t pointer. 720Sstevel@tonic-gate * mech_type is a valid value previously returned by 730Sstevel@tonic-gate * crypto_mech2id(); 740Sstevel@tonic-gate * When the mech's parameter is not NULL, its definition depends 750Sstevel@tonic-gate * on the standard definition of the mechanism. 760Sstevel@tonic-gate * data: The message to be digested. 770Sstevel@tonic-gate * digest: Storage for the digest. The length needed depends on the 780Sstevel@tonic-gate * mechanism. 790Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 800Sstevel@tonic-gate * 810Sstevel@tonic-gate * Description: 820Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 830Sstevel@tonic-gate * digesting operation of 'data' on the specified 840Sstevel@tonic-gate * provider with the specified session. 850Sstevel@tonic-gate * When complete and successful, 'digest' will contain the digest value. 860Sstevel@tonic-gate * The caller should hold a reference on the specified provider 870Sstevel@tonic-gate * descriptor before calling this function. 880Sstevel@tonic-gate * 890Sstevel@tonic-gate * Context: 900Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * Returns: 930Sstevel@tonic-gate * See comment in the beginning of the file. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate int 96904Smcpowers crypto_digest_prov(crypto_provider_t provider, crypto_session_id_t sid, 97904Smcpowers crypto_mechanism_t *mech, crypto_data_t *data, crypto_data_t *digest, 98904Smcpowers crypto_call_req_t *crq) 990Sstevel@tonic-gate { 1000Sstevel@tonic-gate kcf_req_params_t params; 101904Smcpowers kcf_provider_desc_t *pd = provider; 102904Smcpowers kcf_provider_desc_t *real_provider = pd; 103904Smcpowers int rv; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 106904Smcpowers 107904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 108*10444SVladimir.Kotal@Sun.COM rv = kcf_get_hardware_provider(mech->cm_type, NULL, 109*10444SVladimir.Kotal@Sun.COM CRYPTO_MECH_INVALID, NULL, CHECK_RESTRICT(crq), 1101808Smcpowers pd, &real_provider, CRYPTO_FG_DIGEST_ATOMIC); 111904Smcpowers 112904Smcpowers if (rv != CRYPTO_SUCCESS) 113904Smcpowers return (rv); 114904Smcpowers } 1150Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, sid, mech, NULL, 1160Sstevel@tonic-gate data, digest); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* no crypto context to carry between multiple parts. */ 119904Smcpowers rv = kcf_submit_request(real_provider, NULL, crq, ¶ms, B_FALSE); 120904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 121904Smcpowers KCF_PROV_REFRELE(real_provider); 122904Smcpowers 123904Smcpowers return (rv); 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* 1270Sstevel@tonic-gate * Same as crypto_digest_prov(), but relies on the KCF scheduler to 1280Sstevel@tonic-gate * choose a provider. See crypto_digest_prov() comments for more information. 1290Sstevel@tonic-gate */ 1300Sstevel@tonic-gate int 1310Sstevel@tonic-gate crypto_digest(crypto_mechanism_t *mech, crypto_data_t *data, 1320Sstevel@tonic-gate crypto_data_t *digest, crypto_call_req_t *crq) 1330Sstevel@tonic-gate { 1340Sstevel@tonic-gate int error; 1350Sstevel@tonic-gate kcf_provider_desc_t *pd; 1360Sstevel@tonic-gate kcf_req_params_t params; 1370Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate retry: 1400Sstevel@tonic-gate /* The pd is returned held */ 141*10444SVladimir.Kotal@Sun.COM if ((pd = kcf_get_mech_provider(mech->cm_type, NULL, NULL, &error, 142*10444SVladimir.Kotal@Sun.COM list, CRYPTO_FG_DIGEST_ATOMIC, CHECK_RESTRICT(crq), 1430Sstevel@tonic-gate data->cd_length)) == NULL) { 1440Sstevel@tonic-gate if (list != NULL) 1450Sstevel@tonic-gate kcf_free_triedlist(list); 1460Sstevel@tonic-gate return (error); 1470Sstevel@tonic-gate } 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* The fast path for SW providers. */ 1500Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 1510Sstevel@tonic-gate crypto_mechanism_t lmech; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate lmech = *mech; 1540Sstevel@tonic-gate KCF_SET_PROVIDER_MECHNUM(mech->cm_type, pd, &lmech); 1550Sstevel@tonic-gate error = KCF_PROV_DIGEST_ATOMIC(pd, pd->pd_sid, &lmech, data, 1560Sstevel@tonic-gate digest, KCF_SWFP_RHNDL(crq)); 1570Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 1580Sstevel@tonic-gate } else { 1594072Skrishna if (pd->pd_prov_type == CRYPTO_HW_PROVIDER && 1604072Skrishna (pd->pd_flags & CRYPTO_HASH_NO_UPDATE) && 1614072Skrishna (data->cd_length > pd->pd_hash_limit)) { 1624072Skrishna error = CRYPTO_BUFFER_TOO_BIG; 1634072Skrishna } else { 1644072Skrishna KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_ATOMIC, 1654072Skrishna pd->pd_sid, mech, NULL, data, digest); 1660Sstevel@tonic-gate 1674072Skrishna /* no crypto context to carry between multiple parts. */ 1684072Skrishna error = kcf_submit_request(pd, NULL, crq, ¶ms, 1694072Skrishna B_FALSE); 1704072Skrishna } 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 1740Sstevel@tonic-gate IS_RECOVERABLE(error)) { 1750Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 1760Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 1770Sstevel@tonic-gate goto retry; 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate if (list != NULL) 1810Sstevel@tonic-gate kcf_free_triedlist(list); 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 1840Sstevel@tonic-gate return (error); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * crypto_digest_init_prov() 1890Sstevel@tonic-gate * 1900Sstevel@tonic-gate * pd: pointer to the descriptor of the provider to use for this 1910Sstevel@tonic-gate * operation. 1920Sstevel@tonic-gate * sid: provider session id. 1930Sstevel@tonic-gate * mech: crypto_mechanism_t pointer. 1940Sstevel@tonic-gate * mech_type is a valid value previously returned by 1950Sstevel@tonic-gate * crypto_mech2id(); 1960Sstevel@tonic-gate * When the mech's parameter is not NULL, its definition depends 1970Sstevel@tonic-gate * on the standard definition of the mechanism. 1980Sstevel@tonic-gate * ctxp: Pointer to a crypto_context_t. 1990Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 2000Sstevel@tonic-gate * 2010Sstevel@tonic-gate * Description: 2020Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 2030Sstevel@tonic-gate * initialization of a message digest operation on the specified 2040Sstevel@tonic-gate * provider with the specified session. 2050Sstevel@tonic-gate * When complete and successful, 'ctxp' will contain a crypto_context_t 2060Sstevel@tonic-gate * valid for later calls to digest_update() and digest_final(). 2070Sstevel@tonic-gate * The caller should hold a reference on the specified provider 2080Sstevel@tonic-gate * descriptor before calling this function. 2090Sstevel@tonic-gate */ 2100Sstevel@tonic-gate int 211904Smcpowers crypto_digest_init_prov(crypto_provider_t provider, crypto_session_id_t sid, 212904Smcpowers crypto_mechanism_t *mech, crypto_context_t *ctxp, crypto_call_req_t *crq) 2130Sstevel@tonic-gate { 2140Sstevel@tonic-gate int error; 2150Sstevel@tonic-gate crypto_ctx_t *ctx; 2160Sstevel@tonic-gate kcf_req_params_t params; 217904Smcpowers kcf_provider_desc_t *pd = provider; 218904Smcpowers kcf_provider_desc_t *real_provider = pd; 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate ASSERT(KCF_PROV_REFHELD(pd)); 2210Sstevel@tonic-gate 222904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) { 223*10444SVladimir.Kotal@Sun.COM error = kcf_get_hardware_provider(mech->cm_type, NULL, 224*10444SVladimir.Kotal@Sun.COM CRYPTO_MECH_INVALID, NULL, CHECK_RESTRICT(crq), pd, 2251808Smcpowers &real_provider, CRYPTO_FG_DIGEST); 226904Smcpowers 227904Smcpowers if (error != CRYPTO_SUCCESS) 228904Smcpowers return (error); 229904Smcpowers } 230904Smcpowers 231904Smcpowers /* Allocate and initialize the canonical context */ 232904Smcpowers if ((ctx = kcf_new_ctx(crq, real_provider, sid)) == NULL) { 233904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 234904Smcpowers KCF_PROV_REFRELE(real_provider); 2350Sstevel@tonic-gate return (CRYPTO_HOST_MEMORY); 236904Smcpowers } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate /* The fast path for SW providers. */ 2390Sstevel@tonic-gate if (CHECK_FASTPATH(crq, pd)) { 2400Sstevel@tonic-gate crypto_mechanism_t lmech; 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate lmech = *mech; 243904Smcpowers KCF_SET_PROVIDER_MECHNUM(mech->cm_type, real_provider, &lmech); 244904Smcpowers error = KCF_PROV_DIGEST_INIT(real_provider, ctx, &lmech, 2450Sstevel@tonic-gate KCF_SWFP_RHNDL(crq)); 2460Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 2470Sstevel@tonic-gate } else { 2480Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_INIT, sid, 2490Sstevel@tonic-gate mech, NULL, NULL, NULL); 250904Smcpowers error = kcf_submit_request(real_provider, ctx, crq, ¶ms, 251904Smcpowers B_FALSE); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 254904Smcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) 255904Smcpowers KCF_PROV_REFRELE(real_provider); 256904Smcpowers 2570Sstevel@tonic-gate if ((error == CRYPTO_SUCCESS) || (error == CRYPTO_QUEUED)) 2580Sstevel@tonic-gate *ctxp = (crypto_context_t)ctx; 2590Sstevel@tonic-gate else { 2600Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx(). */ 2610Sstevel@tonic-gate KCF_CONTEXT_REFRELE((kcf_context_t *)ctx->cc_framework_private); 2620Sstevel@tonic-gate } 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate return (error); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate /* 2690Sstevel@tonic-gate * Same as crypto_digest_init_prov(), but relies on the KCF scheduler 2700Sstevel@tonic-gate * to choose a provider. See crypto_digest_init_prov() comments for 2710Sstevel@tonic-gate * more information. 2720Sstevel@tonic-gate */ 2730Sstevel@tonic-gate int 2740Sstevel@tonic-gate crypto_digest_init(crypto_mechanism_t *mech, crypto_context_t *ctxp, 2750Sstevel@tonic-gate crypto_call_req_t *crq) 2760Sstevel@tonic-gate { 2770Sstevel@tonic-gate int error; 2780Sstevel@tonic-gate kcf_provider_desc_t *pd; 2790Sstevel@tonic-gate kcf_prov_tried_t *list = NULL; 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate retry: 2820Sstevel@tonic-gate /* The pd is returned held */ 283*10444SVladimir.Kotal@Sun.COM if ((pd = kcf_get_mech_provider(mech->cm_type, NULL, NULL, &error, 2840Sstevel@tonic-gate list, CRYPTO_FG_DIGEST, CHECK_RESTRICT(crq), 0)) == NULL) { 2850Sstevel@tonic-gate if (list != NULL) 2860Sstevel@tonic-gate kcf_free_triedlist(list); 2870Sstevel@tonic-gate return (error); 2880Sstevel@tonic-gate } 2890Sstevel@tonic-gate 2904072Skrishna if (pd->pd_prov_type == CRYPTO_HW_PROVIDER && 2914072Skrishna (pd->pd_flags & CRYPTO_HASH_NO_UPDATE)) { 2924072Skrishna /* 2934072Skrishna * The hardware provider has limited digest support. 2944072Skrishna * So, we fallback early here to using a software provider. 2954072Skrishna * 2964072Skrishna * XXX - need to enhance to do the fallback later in 2974072Skrishna * crypto_digest_update() if the size of accumulated input data 2984072Skrishna * exceeds the maximum size digestable by hardware provider. 2994072Skrishna */ 3004072Skrishna error = CRYPTO_BUFFER_TOO_BIG; 3014072Skrishna } else { 3024072Skrishna error = crypto_digest_init_prov(pd, pd->pd_sid, 3034072Skrishna mech, ctxp, crq); 3044072Skrishna } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED && 3070Sstevel@tonic-gate IS_RECOVERABLE(error)) { 3080Sstevel@tonic-gate /* Add pd to the linked list of providers tried. */ 3090Sstevel@tonic-gate if (kcf_insert_triedlist(&list, pd, KCF_KMFLAG(crq)) != NULL) 3100Sstevel@tonic-gate goto retry; 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate if (list != NULL) 3140Sstevel@tonic-gate kcf_free_triedlist(list); 3150Sstevel@tonic-gate KCF_PROV_REFRELE(pd); 3160Sstevel@tonic-gate return (error); 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* 3200Sstevel@tonic-gate * crypto_digest_update() 3210Sstevel@tonic-gate * 3220Sstevel@tonic-gate * Arguments: 3230Sstevel@tonic-gate * context: A crypto_context_t initialized by digest_init(). 3240Sstevel@tonic-gate * data: The part of message to be digested. 3250Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 3260Sstevel@tonic-gate * 3270Sstevel@tonic-gate * Description: 3280Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs a 3290Sstevel@tonic-gate * part of a message digest operation. 3300Sstevel@tonic-gate * 3310Sstevel@tonic-gate * Context: 3320Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 3330Sstevel@tonic-gate * 3340Sstevel@tonic-gate * Returns: 3350Sstevel@tonic-gate * See comment in the beginning of the file. 3360Sstevel@tonic-gate */ 3370Sstevel@tonic-gate int 3380Sstevel@tonic-gate crypto_digest_update(crypto_context_t context, crypto_data_t *data, 3390Sstevel@tonic-gate crypto_call_req_t *cr) 3400Sstevel@tonic-gate { 3410Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 3420Sstevel@tonic-gate kcf_context_t *kcf_ctx; 3430Sstevel@tonic-gate kcf_provider_desc_t *pd; 3440Sstevel@tonic-gate int error; 3450Sstevel@tonic-gate kcf_req_params_t params; 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate if ((ctx == NULL) || 3480Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 3490Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 3500Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 3510Sstevel@tonic-gate } 3520Sstevel@tonic-gate 353904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate /* The fast path for SW providers. */ 3560Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 3570Sstevel@tonic-gate error = KCF_PROV_DIGEST_UPDATE(pd, ctx, data, NULL); 3580Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 3590Sstevel@tonic-gate } else { 360904Smcpowers KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_UPDATE, 361904Smcpowers ctx->cc_session, NULL, NULL, data, NULL); 3620Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate return (error); 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /* 3690Sstevel@tonic-gate * crypto_digest_final() 3700Sstevel@tonic-gate * 3710Sstevel@tonic-gate * Arguments: 3720Sstevel@tonic-gate * context: A crypto_context_t initialized by digest_init(). 3730Sstevel@tonic-gate * digest: The storage for the digest. 3740Sstevel@tonic-gate * cr: crypto_call_req_t calling conditions and call back info. 3750Sstevel@tonic-gate * 3760Sstevel@tonic-gate * Description: 3770Sstevel@tonic-gate * Asynchronously submits a request for, or synchronously performs the 3780Sstevel@tonic-gate * final part of a message digest operation. 3790Sstevel@tonic-gate * 3800Sstevel@tonic-gate * Context: 3810Sstevel@tonic-gate * Process or interrupt, according to the semantics dictated by the 'cr'. 3820Sstevel@tonic-gate * 3830Sstevel@tonic-gate * Returns: 3840Sstevel@tonic-gate * See comment in the beginning of the file. 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate int 3870Sstevel@tonic-gate crypto_digest_final(crypto_context_t context, crypto_data_t *digest, 3880Sstevel@tonic-gate crypto_call_req_t *cr) 3890Sstevel@tonic-gate { 3900Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 3910Sstevel@tonic-gate kcf_context_t *kcf_ctx; 3920Sstevel@tonic-gate kcf_provider_desc_t *pd; 3930Sstevel@tonic-gate int error; 3940Sstevel@tonic-gate kcf_req_params_t params; 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate if ((ctx == NULL) || 3970Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 3980Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 3990Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4000Sstevel@tonic-gate } 4010Sstevel@tonic-gate 402904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate /* The fast path for SW providers. */ 4050Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4060Sstevel@tonic-gate error = KCF_PROV_DIGEST_FINAL(pd, ctx, digest, NULL); 4070Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4080Sstevel@tonic-gate } else { 409904Smcpowers KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_FINAL, 410904Smcpowers ctx->cc_session, NULL, NULL, NULL, digest); 4110Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4150Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4160Sstevel@tonic-gate return (error); 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate /* 4200Sstevel@tonic-gate * Performs a digest update on the specified key. Note that there is 4210Sstevel@tonic-gate * no k-API crypto_digest_key() equivalent of this function. 4220Sstevel@tonic-gate */ 4230Sstevel@tonic-gate int 4240Sstevel@tonic-gate crypto_digest_key_prov(crypto_context_t context, crypto_key_t *key, 4250Sstevel@tonic-gate crypto_call_req_t *cr) 4260Sstevel@tonic-gate { 4270Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4280Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4290Sstevel@tonic-gate kcf_provider_desc_t *pd; 4300Sstevel@tonic-gate int error; 4310Sstevel@tonic-gate kcf_req_params_t params; 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate if ((ctx == NULL) || 4340Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4350Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4360Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 439904Smcpowers ASSERT(pd->pd_prov_type != CRYPTO_LOGICAL_PROVIDER); 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* The fast path for SW providers. */ 4420Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4430Sstevel@tonic-gate error = KCF_PROV_DIGEST_KEY(pd, ctx, key, NULL); 4440Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4450Sstevel@tonic-gate } else { 4460Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_DIGEST_KEY, 447904Smcpowers ctx->cc_session, NULL, key, NULL, NULL); 4480Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate return (error); 4520Sstevel@tonic-gate } 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* 4550Sstevel@tonic-gate * See comments for crypto_digest_update() and crypto_digest_final(). 4560Sstevel@tonic-gate */ 4570Sstevel@tonic-gate int 4580Sstevel@tonic-gate crypto_digest_single(crypto_context_t context, crypto_data_t *data, 4590Sstevel@tonic-gate crypto_data_t *digest, crypto_call_req_t *cr) 4600Sstevel@tonic-gate { 4610Sstevel@tonic-gate crypto_ctx_t *ctx = (crypto_ctx_t *)context; 4620Sstevel@tonic-gate kcf_context_t *kcf_ctx; 4630Sstevel@tonic-gate kcf_provider_desc_t *pd; 4640Sstevel@tonic-gate int error; 4650Sstevel@tonic-gate kcf_req_params_t params; 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate if ((ctx == NULL) || 4680Sstevel@tonic-gate ((kcf_ctx = (kcf_context_t *)ctx->cc_framework_private) == NULL) || 4690Sstevel@tonic-gate ((pd = kcf_ctx->kc_prov_desc) == NULL)) { 4700Sstevel@tonic-gate return (CRYPTO_INVALID_CONTEXT); 4710Sstevel@tonic-gate } 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate /* The fast path for SW providers. */ 4750Sstevel@tonic-gate if (CHECK_FASTPATH(cr, pd)) { 4760Sstevel@tonic-gate error = KCF_PROV_DIGEST(pd, ctx, data, digest, NULL); 4770Sstevel@tonic-gate KCF_PROV_INCRSTATS(pd, error); 4780Sstevel@tonic-gate } else { 4790Sstevel@tonic-gate KCF_WRAP_DIGEST_OPS_PARAMS(¶ms, KCF_OP_SINGLE, pd->pd_sid, 4800Sstevel@tonic-gate NULL, NULL, data, digest); 4810Sstevel@tonic-gate error = kcf_submit_request(pd, ctx, cr, ¶ms, B_FALSE); 4820Sstevel@tonic-gate } 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate /* Release the hold done in kcf_new_ctx() during init step. */ 4850Sstevel@tonic-gate KCF_CONTEXT_COND_RELEASE(error, kcf_ctx); 4860Sstevel@tonic-gate return (error); 4870Sstevel@tonic-gate } 488