894b27768c68091df4918b3219c91ed77d2d4054mcpowers/*
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * CDDL HEADER START
894b27768c68091df4918b3219c91ed77d2d4054mcpowers *
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * The contents of this file are subject to the terms of the
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick * Common Development and Distribution License (the "License").
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick * You may not use this file except in compliance with the License.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers *
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * or http://www.opensolaris.org/os/licensing.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * See the License for the specific language governing permissions
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * and limitations under the License.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers *
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * When distributing Covered Code, include this CDDL HEADER in each
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * If applicable, add the following below this CDDL HEADER, with the
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * fields enclosed by brackets "[]" replaced with your own identifying
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * information: Portions Copyright [yyyy] [name of copyright owner]
894b27768c68091df4918b3219c91ed77d2d4054mcpowers *
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * CDDL HEADER END
894b27768c68091df4918b3219c91ed77d2d4054mcpowers */
894b27768c68091df4918b3219c91ed77d2d4054mcpowers/*
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers */
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/errno.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/types.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/kmem.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/cmn_err.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/sysmacros.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/crypto/common.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/crypto/impl.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/crypto/api.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/crypto/spi.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#include <sys/crypto/sched_impl.h>
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define CRYPTO_OPS_OFFSET(f) offsetof(crypto_ops_t, co_##f)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define CRYPTO_OBJECT_OFFSET(f) offsetof(crypto_object_ops_t, f)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define CRYPTO_SESSION_OFFSET(f) offsetof(crypto_session_ops_t, f)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint
894b27768c68091df4918b3219c91ed77d2d4054mcpowerscrypto_session_open(crypto_provider_t provider, crypto_session_id_t *sidp,
894b27768c68091df4918b3219c91ed77d2d4054mcpowerscrypto_call_req_t *crq)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers{
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_req_params_t params;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *real_provider;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *pd = provider;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers ASSERT(KCF_PROV_REFHELD(pd));
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /* find a provider that supports session ops */
894b27768c68091df4918b3219c91ed77d2d4054mcpowers (void) kcf_get_hardware_provider_nomech(CRYPTO_OPS_OFFSET(session_ops),
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick CRYPTO_SESSION_OFFSET(session_open), pd, &real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (real_provider != NULL) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers int rv;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers ASSERT(real_provider == pd ||
894b27768c68091df4918b3219c91ed77d2d4054mcpowers pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (CHECK_FASTPATH(crq, pd)) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = KCF_PROV_SESSION_OPEN(real_provider, sidp,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_SWFP_RHNDL(crq), pd);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_INCRSTATS(pd, rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers } else {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_WRAP_SESSION_OPS_PARAMS(&params,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_OP_SESSION_OPEN, sidp, 0, CRYPTO_USER, NULL,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers 0, pd);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = kcf_submit_request(real_provider, NULL, crq,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers &params, B_FALSE);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_REFRELE(real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (rv != CRYPTO_SUCCESS) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (CRYPTO_SUCCESS);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers}
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint
894b27768c68091df4918b3219c91ed77d2d4054mcpowerscrypto_session_close(crypto_provider_t provider, crypto_session_id_t sid,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers crypto_call_req_t *crq)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers{
894b27768c68091df4918b3219c91ed77d2d4054mcpowers int rv;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_req_params_t params;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *real_provider;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *pd = provider;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (pd == NULL)
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick return (CRYPTO_ARGUMENTS_BAD);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers ASSERT(KCF_PROV_REFHELD(pd));
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /* find a provider that supports session ops */
894b27768c68091df4918b3219c91ed77d2d4054mcpowers (void) kcf_get_hardware_provider_nomech(CRYPTO_OPS_OFFSET(session_ops),
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick CRYPTO_SESSION_OFFSET(session_close), pd, &real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers ASSERT(real_provider == pd ||
894b27768c68091df4918b3219c91ed77d2d4054mcpowers pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /* edge case is where the logical provider has no members */
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (real_provider != NULL) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /* The fast path for SW providers. */
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (CHECK_FASTPATH(crq, pd)) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = KCF_PROV_SESSION_CLOSE(real_provider,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers sid, KCF_SWFP_RHNDL(crq), pd);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_INCRSTATS(pd, rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers } else {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_WRAP_SESSION_OPS_PARAMS(&params,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_OP_SESSION_CLOSE, NULL, sid,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers CRYPTO_USER, NULL, 0, pd);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = kcf_submit_request(real_provider, NULL, crq,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers &params, B_FALSE);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_REFRELE(real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (CRYPTO_SUCCESS);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers}
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint
894b27768c68091df4918b3219c91ed77d2d4054mcpowerscrypto_session_login(crypto_provider_t provider, crypto_session_id_t sid,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers crypto_user_type_t type, char *pin, ulong_t len, crypto_call_req_t *crq)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers{
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_req_params_t params;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *pd = provider;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *real_provider = pd;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers int rv;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers ASSERT(KCF_PROV_REFHELD(pd));
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = kcf_get_hardware_provider_nomech(CRYPTO_OPS_OFFSET(
894b27768c68091df4918b3219c91ed77d2d4054mcpowers session_ops), CRYPTO_SESSION_OFFSET(session_login),
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick pd, &real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (rv != CRYPTO_SUCCESS)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (CHECK_FASTPATH(crq, real_provider)) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = KCF_PROV_SESSION_LOGIN(real_provider, sid,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers type, pin, len, KCF_SWFP_RHNDL(crq));
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_INCRSTATS(pd, rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers } else {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_WRAP_SESSION_OPS_PARAMS(&params, KCF_OP_SESSION_LOGIN,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers NULL, sid, type, pin, len, real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = kcf_submit_request(real_provider, NULL, crq,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers &params, B_FALSE);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_REFRELE(real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers}
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint
894b27768c68091df4918b3219c91ed77d2d4054mcpowerscrypto_session_logout(crypto_provider_t provider, crypto_session_id_t sid,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers crypto_call_req_t *crq)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers{
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_req_params_t params;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *pd = provider;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers kcf_provider_desc_t *real_provider = pd;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers int rv;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers ASSERT(KCF_PROV_REFHELD(pd));
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = kcf_get_hardware_provider_nomech(CRYPTO_OPS_OFFSET(
894b27768c68091df4918b3219c91ed77d2d4054mcpowers session_ops), CRYPTO_SESSION_OFFSET(session_logout),
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick pd, &real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (rv != CRYPTO_SUCCESS)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (CHECK_FASTPATH(crq, real_provider)) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = KCF_PROV_SESSION_LOGOUT(real_provider, sid,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_SWFP_RHNDL(crq));
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_INCRSTATS(pd, rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers } else {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_WRAP_SESSION_OPS_PARAMS(&params, KCF_OP_SESSION_LOGOUT,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers NULL, sid, 0, NULL, 0, real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = kcf_submit_request(real_provider, NULL, crq,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers &params, B_FALSE);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers }
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (pd->pd_prov_type == CRYPTO_LOGICAL_PROVIDER)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers KCF_PROV_REFRELE(real_provider);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers
894b27768c68091df4918b3219c91ed77d2d4054mcpowers return (rv);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers}