md5_mod.c revision 5b675b316486993a90722f1a7ec08ce857ef7af7
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * CDDL HEADER START
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The contents of this file are subject to the terms of the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Common Development and Distribution License (the "License").
734b6a94890be549309b21156f8ed6d4561cac51darrenm * You may not use this file except in compliance with the License.
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
734b6a94890be549309b21156f8ed6d4561cac51darrenm * or http://www.opensolaris.org/os/licensing.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * See the License for the specific language governing permissions
734b6a94890be549309b21156f8ed6d4561cac51darrenm * and limitations under the License.
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * When distributing Covered Code, include this CDDL HEADER in each
734b6a94890be549309b21156f8ed6d4561cac51darrenm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * If applicable, add the following below this CDDL HEADER, with the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * fields enclosed by brackets "[]" replaced with your own identifying
734b6a94890be549309b21156f8ed6d4561cac51darrenm * information: Portions Copyright [yyyy] [name of copyright owner]
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * CDDL HEADER END
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Use is subject to license terms.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * In kernel module, the md5 module is created with two modlinkages:
734b6a94890be549309b21156f8ed6d4561cac51darrenm * - a modlmisc that allows consumers to directly call the entry points
734b6a94890be549309b21156f8ed6d4561cac51darrenm * MD5Init, MD5Update, and MD5Final.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * - a modlcrypto that allows the module to register with the Kernel
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Cryptographic Framework (KCF) as a software provider for the MD5
734b6a94890be549309b21156f8ed6d4561cac51darrenm * mechanisms.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/types.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/systm.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/modctl.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/cmn_err.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/ddi.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/crypto/common.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/crypto/spi.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/sysmacros.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/strsun.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/note.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <sys/md5.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmextern struct mod_ops mod_miscops;
734b6a94890be549309b21156f8ed6d4561cac51darrenmextern struct mod_ops mod_cryptoops;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Module linkage information for the kernel.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic struct modlmisc modlmisc = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm &mod_miscops,
734b6a94890be549309b21156f8ed6d4561cac51darrenm "MD5 Message-Digest Algorithm"
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic struct modlcrypto modlcrypto = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm &mod_cryptoops,
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers "MD5 Kernel SW Provider"
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic struct modlinkage modlinkage = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm MODREV_1,
734b6a94890be549309b21156f8ed6d4561cac51darrenm (void *)&modlmisc,
734b6a94890be549309b21156f8ed6d4561cac51darrenm (void *)&modlcrypto,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * CSPI information (entry points, provider info, etc.)
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef enum md5_mech_type {
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_MECH_INFO_TYPE, /* SUN_CKM_MD5 */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_HMAC_MECH_INFO_TYPE, /* SUN_CKM_MD5_HMAC */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_HMAC_GEN_MECH_INFO_TYPE /* SUN_CKM_MD5_HMAC_GENERAL */
734b6a94890be549309b21156f8ed6d4561cac51darrenm} md5_mech_type_t;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define MD5_DIGEST_LENGTH 16 /* MD5 digest length in bytes */
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define MD5_HMAC_BLOCK_SIZE 64 /* MD5 block size */
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal#define MD5_HMAC_MIN_KEY_LEN 1 /* MD5-HMAC min key length in bytes */
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal#define MD5_HMAC_MAX_KEY_LEN INT_MAX /* MD5-HMAC max key length in bytes */
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define MD5_HMAC_INTS_PER_BLOCK (MD5_HMAC_BLOCK_SIZE/sizeof (uint32_t))
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Context for MD5 mechanism.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct md5_ctx {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mech_type_t mc_mech_type; /* type of context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_CTX mc_md5_ctx; /* MD5 context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm} md5_ctx_t;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Context for MD5-HMAC and MD5-HMAC-GENERAL mechanisms.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct md5_hmac_ctx {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mech_type_t hc_mech_type; /* type of context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t hc_digest_len; /* digest len in bytes */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_CTX hc_icontext; /* inner MD5 context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_CTX hc_ocontext; /* outer MD5 context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm} md5_hmac_ctx_t;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Macros to access the MD5 or MD5-HMAC contexts from a context passed
734b6a94890be549309b21156f8ed6d4561cac51darrenm * by KCF to one of the entry points.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define PROV_MD5_CTX(ctx) ((md5_ctx_t *)(ctx)->cc_provider_private)
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define PROV_MD5_HMAC_CTX(ctx) ((md5_hmac_ctx_t *)(ctx)->cc_provider_private)
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* to extract the digest length passed as mechanism parameter */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define PROV_MD5_GET_DIGEST_LEN(m, len) { \
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (IS_P2ALIGNED((m)->cm_param, sizeof (ulong_t))) \
734b6a94890be549309b21156f8ed6d4561cac51darrenm (len) = (uint32_t)*((ulong_t *)mechanism->cm_param); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm else { \
734b6a94890be549309b21156f8ed6d4561cac51darrenm ulong_t tmp_ulong; \
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy((m)->cm_param, &tmp_ulong, sizeof (ulong_t)); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm (len) = (uint32_t)tmp_ulong; \
734b6a94890be549309b21156f8ed6d4561cac51darrenm } \
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define PROV_MD5_DIGEST_KEY(ctx, key, len, digest) { \
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Init(ctx); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(ctx, key, len); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest, ctx); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Mechanism info structure passed to KCF during registration.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_mech_info_t md5_mech_info_tab[] = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* MD5 */
734b6a94890be549309b21156f8ed6d4561cac51darrenm {SUN_CKM_MD5, MD5_MECH_INFO_TYPE,
734b6a94890be549309b21156f8ed6d4561cac51darrenm CRYPTO_FG_DIGEST | CRYPTO_FG_DIGEST_ATOMIC,
734b6a94890be549309b21156f8ed6d4561cac51darrenm 0, 0, CRYPTO_KEYSIZE_UNIT_IN_BITS},
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* MD5-HMAC */
734b6a94890be549309b21156f8ed6d4561cac51darrenm {SUN_CKM_MD5_HMAC, MD5_HMAC_MECH_INFO_TYPE,
734b6a94890be549309b21156f8ed6d4561cac51darrenm CRYPTO_FG_MAC | CRYPTO_FG_MAC_ATOMIC,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_HMAC_MIN_KEY_LEN, MD5_HMAC_MAX_KEY_LEN,
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal CRYPTO_KEYSIZE_UNIT_IN_BYTES},
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* MD5-HMAC GENERAL */
734b6a94890be549309b21156f8ed6d4561cac51darrenm {SUN_CKM_MD5_HMAC_GENERAL, MD5_HMAC_GEN_MECH_INFO_TYPE,
734b6a94890be549309b21156f8ed6d4561cac51darrenm CRYPTO_FG_MAC | CRYPTO_FG_MAC_ATOMIC,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_HMAC_MIN_KEY_LEN, MD5_HMAC_MAX_KEY_LEN,
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal CRYPTO_KEYSIZE_UNIT_IN_BYTES}
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic void md5_provider_status(crypto_provider_handle_t, uint_t *);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_control_ops_t md5_control_ops = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_provider_status
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_digest_init(crypto_ctx_t *, crypto_mechanism_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_digest(crypto_ctx_t *, crypto_data_t *, crypto_data_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_digest_update(crypto_ctx_t *, crypto_data_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_digest_final(crypto_ctx_t *, crypto_data_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_digest_atomic(crypto_provider_handle_t, crypto_session_id_t,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_mechanism_t *, crypto_data_t *, crypto_data_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_digest_ops_t md5_digest_ops = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_digest_init,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_digest_update,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_digest_final,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_digest_atomic
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_mac_init(crypto_ctx_t *, crypto_mechanism_t *, crypto_key_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_spi_ctx_template_t, crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_mac_update(crypto_ctx_t *, crypto_data_t *, crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_mac_final(crypto_ctx_t *, crypto_data_t *, crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_mac_atomic(crypto_provider_handle_t, crypto_session_id_t,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_mechanism_t *, crypto_key_t *, crypto_data_t *, crypto_data_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_spi_ctx_template_t, crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_mac_verify_atomic(crypto_provider_handle_t, crypto_session_id_t,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_mechanism_t *, crypto_key_t *, crypto_data_t *, crypto_data_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_spi_ctx_template_t, crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_mac_ops_t md5_mac_ops = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_update,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_final,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_atomic,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_verify_atomic
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_create_ctx_template(crypto_provider_handle_t,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_mechanism_t *, crypto_key_t *, crypto_spi_ctx_template_t *,
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t *, crypto_req_handle_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int md5_free_context(crypto_ctx_t *);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_ctx_ops_t md5_ctx_ops = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_create_ctx_template,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_free_context
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_ops_t md5_crypto_ops = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm &md5_control_ops,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &md5_digest_ops,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &md5_mac_ops,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &md5_ctx_ops
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_provider_info_t md5_prov_info = {
734b6a94890be549309b21156f8ed6d4561cac51darrenm CRYPTO_SPI_VERSION_1,
734b6a94890be549309b21156f8ed6d4561cac51darrenm "MD5 Software Provider",
734b6a94890be549309b21156f8ed6d4561cac51darrenm CRYPTO_SW_PROVIDER,
734b6a94890be549309b21156f8ed6d4561cac51darrenm {&modlinkage},
734b6a94890be549309b21156f8ed6d4561cac51darrenm NULL,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &md5_crypto_ops,
734b6a94890be549309b21156f8ed6d4561cac51darrenm sizeof (md5_mech_info_tab)/sizeof (crypto_mech_info_t),
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mech_info_tab
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic crypto_kcf_provider_handle_t md5_prov_handle = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmint
734b6a94890be549309b21156f8ed6d4561cac51darrenm_init(void)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((ret = mod_install(&modlinkage)) != 0)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Register with KCF. If the registration fails, log an
734b6a94890be549309b21156f8ed6d4561cac51darrenm * error but do not uninstall the module, since the functionality
734b6a94890be549309b21156f8ed6d4561cac51darrenm * provided by misc/md5 should still be available.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((ret = crypto_register_provider(&md5_prov_info,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &md5_prov_handle)) != CRYPTO_SUCCESS)
734b6a94890be549309b21156f8ed6d4561cac51darrenm cmn_err(CE_WARN, "md5 _init: "
734b6a94890be549309b21156f8ed6d4561cac51darrenm "crypto_register_provider() failed (0x%x)", ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (0);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmint
734b6a94890be549309b21156f8ed6d4561cac51darrenm_fini(void)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Unregister from KCF if previous registration succeeded.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (md5_prov_handle != NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((ret = crypto_unregister_provider(md5_prov_handle)) !=
734b6a94890be549309b21156f8ed6d4561cac51darrenm CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cmn_err(CE_WARN, "md5 _fini: "
734b6a94890be549309b21156f8ed6d4561cac51darrenm "crypto_unregister_provider() failed (0x%x)", ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (EBUSY);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_prov_handle = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (mod_remove(&modlinkage));
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmint
734b6a94890be549309b21156f8ed6d4561cac51darrenm_info(struct modinfo *modinfop)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (mod_info(&modlinkage, modinfop));
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * KCF software provider control entry points.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic void
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_provider_status(crypto_provider_handle_t provider, uint_t *status)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm *status = CRYPTO_PROVIDER_READY;
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * KCF software provider digest entry points.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type != MD5_MECH_INFO_TYPE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_MECHANISM_INVALID);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Allocate and initialize MD5 context.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = kmem_alloc(sizeof (md5_ctx_t),
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_kmflag(req));
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ctx->cc_provider_private == NULL)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_HOST_MEMORY);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_CTX(ctx)->mc_mech_type = MD5_MECH_INFO_TYPE;
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Init(&PROV_MD5_CTX(ctx)->mc_md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Helper MD5 digest update function for uio data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_update_uio(MD5_CTX *md5_ctx, crypto_data_t *data)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t offset = data->cd_offset;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t length = data->cd_length;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t vec_idx;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* we support only kernel buffer */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (data->cd_uio->uio_segflg != UIO_SYSSPACE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Jump to the first iovec containing data to be
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digested.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (vec_idx = 0; vec_idx < data->cd_uio->uio_iovcnt &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset >= data->cd_uio->uio_iov[vec_idx].iov_len;
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers offset -= data->cd_uio->uio_iov[vec_idx++].iov_len)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers ;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (vec_idx == data->cd_uio->uio_iovcnt) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller specified an offset that is larger than the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * total size of the buffers it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Now do the digesting on the iovecs.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm while (vec_idx < data->cd_uio->uio_iovcnt && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len = MIN(data->cd_uio->uio_iov[vec_idx].iov_len -
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset, length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(md5_ctx, data->cd_uio->uio_iov[vec_idx].iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset, cur_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm length -= cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm vec_idx++;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (vec_idx == data->cd_uio->uio_iovcnt && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The end of the specified iovec's was reached but
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the length requested could not be processed, i.e.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested to digest more data than it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Helper MD5 digest final function for uio data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest_len is the length of the desired digest. If digest_len
734b6a94890be549309b21156f8ed6d4561cac51darrenm * is smaller than the default MD5 digest length, the caller
734b6a94890be549309b21156f8ed6d4561cac51darrenm * must pass a scratch buffer, digest_scratch, which must
734b6a94890be549309b21156f8ed6d4561cac51darrenm * be at least MD5_DIGEST_LENGTH bytes.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_final_uio(MD5_CTX *md5_ctx, crypto_data_t *digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm ulong_t digest_len, uchar_t *digest_scratch)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t offset = digest->cd_offset;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t vec_idx;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* we support only kernel buffer */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest->cd_uio->uio_segflg != UIO_SYSSPACE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Jump to the first iovec containing ptr to the digest to
734b6a94890be549309b21156f8ed6d4561cac51darrenm * be returned.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (vec_idx = 0; offset >= digest->cd_uio->uio_iov[vec_idx].iov_len &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm vec_idx < digest->cd_uio->uio_iovcnt;
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers offset -= digest->cd_uio->uio_iov[vec_idx++].iov_len)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers ;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (vec_idx == digest->cd_uio->uio_iovcnt) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller specified an offset that is
734b6a94890be549309b21156f8ed6d4561cac51darrenm * larger than the total size of the buffers
734b6a94890be549309b21156f8ed6d4561cac51darrenm * it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (offset + digest_len <=
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_uio->uio_iov[vec_idx].iov_len) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The computed MD5 digest will fit in the current
734b6a94890be549309b21156f8ed6d4561cac51darrenm * iovec.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest_len != MD5_DIGEST_LENGTH) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested a short digest. Digest
734b6a94890be549309b21156f8ed6d4561cac51darrenm * into a scratch buffer and return to
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the user only what was requested.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest_scratch, md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(digest_scratch, (uchar_t *)digest->
734b6a94890be549309b21156f8ed6d4561cac51darrenm cd_uio->uio_iov[vec_idx].iov_base + offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final((uchar_t *)digest->
734b6a94890be549309b21156f8ed6d4561cac51darrenm cd_uio->uio_iov[vec_idx].iov_base + offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The computed digest will be crossing one or more iovec's.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * This is bad performance-wise but we need to support it.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Allocate a small scratch buffer on the stack and
734b6a94890be549309b21156f8ed6d4561cac51darrenm * copy it piece meal to the specified digest iovec's.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digest_tmp[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t scratch_offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest_tmp, md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm while (vec_idx < digest->cd_uio->uio_iovcnt && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len = MIN(digest->cd_uio->uio_iov[vec_idx].iov_len -
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset, length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(digest_tmp + scratch_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_uio->uio_iov[vec_idx].iov_base + offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm length -= cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm vec_idx++;
734b6a94890be549309b21156f8ed6d4561cac51darrenm scratch_offset += cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (vec_idx == digest->cd_uio->uio_iovcnt && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The end of the specified iovec's was reached but
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the length requested could not be processed, i.e.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested to digest more data than it
734b6a94890be549309b21156f8ed6d4561cac51darrenm * provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Helper MD5 digest update for mblk's.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_update_mblk(MD5_CTX *md5_ctx, crypto_data_t *data)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t offset = data->cd_offset;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t length = data->cd_length;
734b6a94890be549309b21156f8ed6d4561cac51darrenm mblk_t *mp;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Jump to the first mblk_t containing data to be digested.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (mp = data->cd_mp; mp != NULL && offset >= MBLKL(mp);
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers offset -= MBLKL(mp), mp = mp->b_cont)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers ;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mp == NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller specified an offset that is larger than the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * total size of the buffers it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Now do the digesting on the mblk chain.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm while (mp != NULL && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len = MIN(MBLKL(mp) - offset, length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(md5_ctx, mp->b_rptr + offset, cur_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm length -= cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm mp = mp->b_cont;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mp == NULL && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The end of the mblk was reached but the length requested
734b6a94890be549309b21156f8ed6d4561cac51darrenm * could not be processed, i.e. The caller requested
734b6a94890be549309b21156f8ed6d4561cac51darrenm * to digest more data than it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Helper MD5 digest final for mblk's.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest_len is the length of the desired digest. If digest_len
734b6a94890be549309b21156f8ed6d4561cac51darrenm * is smaller than the default MD5 digest length, the caller
734b6a94890be549309b21156f8ed6d4561cac51darrenm * must pass a scratch buffer, digest_scratch, which must
734b6a94890be549309b21156f8ed6d4561cac51darrenm * be at least MD5_DIGEST_LENGTH bytes.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_final_mblk(MD5_CTX *md5_ctx, crypto_data_t *digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm ulong_t digest_len, uchar_t *digest_scratch)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t offset = digest->cd_offset;
734b6a94890be549309b21156f8ed6d4561cac51darrenm mblk_t *mp;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Jump to the first mblk_t that will be used to store the digest.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (mp = digest->cd_mp; mp != NULL && offset >= MBLKL(mp);
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers offset -= MBLKL(mp), mp = mp->b_cont)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers ;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mp == NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller specified an offset that is larger than the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * total size of the buffers it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (offset + digest_len <= MBLKL(mp)) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The computed MD5 digest will fit in the current mblk.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do the MD5Final() in-place.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest_len != MD5_DIGEST_LENGTH) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested a short digest. Digest
734b6a94890be549309b21156f8ed6d4561cac51darrenm * into a scratch buffer and return to
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the user only what was requested.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest_scratch, md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(digest_scratch, mp->b_rptr + offset, digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(mp->b_rptr + offset, md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The computed digest will be crossing one or more mblk's.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * This is bad performance-wise but we need to support it.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Allocate a small scratch buffer on the stack and
734b6a94890be549309b21156f8ed6d4561cac51darrenm * copy it piece meal to the specified digest iovec's.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digest_tmp[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t scratch_offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest_tmp, md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm while (mp != NULL && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len = MIN(MBLKL(mp) - offset, length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(digest_tmp + scratch_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm mp->b_rptr + offset, cur_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm length -= cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm mp = mp->b_cont;
734b6a94890be549309b21156f8ed6d4561cac51darrenm scratch_offset += cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mp == NULL && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The end of the specified mblk was reached but
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the length requested could not be processed, i.e.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested to digest more data than it
734b6a94890be549309b21156f8ed6d4561cac51darrenm * provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_DATA_LEN_RANGE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest(crypto_ctx_t *ctx, crypto_data_t *data, crypto_data_t *digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm ASSERT(ctx->cc_provider_private != NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We need to just return the length needed to store the output.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We should not destroy the context for the following cases.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((digest->cd_length == 0) ||
734b6a94890be549309b21156f8ed6d4561cac51darrenm (digest->cd_length < MD5_DIGEST_LENGTH)) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_BUFFER_TOO_SMALL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do the MD5 update on the specified input data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (data->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_raw.iov_base + data->cd_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_uio(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_mblk(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret != CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* the update failed, free context and bail */
734b6a94890be549309b21156f8ed6d4561cac51darrenm kmem_free(ctx->cc_provider_private, sizeof (md5_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final, must be done separately since the digest
734b6a94890be549309b21156f8ed6d4561cac51darrenm * type can be different than the input data type.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (digest->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final((unsigned char *)digest->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_offset, &PROV_MD5_CTX(ctx)->mc_md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_uio(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest, MD5_DIGEST_LENGTH, NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_mblk(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest, MD5_DIGEST_LENGTH, NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* all done, free context and return */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret == CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm kmem_free(ctx->cc_provider_private, sizeof (md5_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_update(crypto_ctx_t *ctx, crypto_data_t *data,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm ASSERT(ctx->cc_provider_private != NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do the MD5 update on the specified input data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (data->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_raw.iov_base + data->cd_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_uio(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_mblk(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_final(crypto_ctx_t *ctx, crypto_data_t *digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm ASSERT(ctx->cc_provider_private != NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We need to just return the length needed to store the output.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We should not destroy the context for the following cases.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((digest->cd_length == 0) ||
734b6a94890be549309b21156f8ed6d4561cac51darrenm (digest->cd_length < MD5_DIGEST_LENGTH)) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_BUFFER_TOO_SMALL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (digest->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final((unsigned char *)digest->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_offset, &PROV_MD5_CTX(ctx)->mc_md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_uio(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest, MD5_DIGEST_LENGTH, NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_mblk(&PROV_MD5_CTX(ctx)->mc_md5_ctx,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest, MD5_DIGEST_LENGTH, NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* all done, free context and return */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret == CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm kmem_free(ctx->cc_provider_private, sizeof (md5_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_digest_atomic(crypto_provider_handle_t provider,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_data_t *data, crypto_data_t *digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_CTX md5_ctx;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type != MD5_MECH_INFO_TYPE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_MECHANISM_INVALID);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do the MD5 init.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Init(&md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do the MD5 update on the specified input data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (data->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&md5_ctx, data->cd_raw.iov_base + data->cd_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_uio(&md5_ctx, data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_mblk(&md5_ctx, data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret != CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* the update failed, bail */
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final, must be done separately since the digest
734b6a94890be549309b21156f8ed6d4561cac51darrenm * type can be different than the input data type.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (digest->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final((unsigned char *)digest->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_offset, &md5_ctx);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_uio(&md5_ctx, digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH, NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_mblk(&md5_ctx, digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH, NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret == CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * KCF software provider mac entry points.
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * MD5 HMAC is: MD5(key XOR opad, MD5(key XOR ipad, text))
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Init:
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The initialization routine initializes what we denote
734b6a94890be549309b21156f8ed6d4561cac51darrenm * as the inner and outer contexts by doing
734b6a94890be549309b21156f8ed6d4561cac51darrenm * - for inner context: MD5(key XOR ipad)
734b6a94890be549309b21156f8ed6d4561cac51darrenm * - for outer context: MD5(key XOR opad)
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Update:
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Each subsequent MD5 HMAC update will result in an
734b6a94890be549309b21156f8ed6d4561cac51darrenm * update of the inner context with the specified data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Final:
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The MD5 HMAC final will do a MD5 final operation on the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * inner context, and the resulting digest will be used
734b6a94890be549309b21156f8ed6d4561cac51darrenm * as the data for an update on the outer context. Last
734b6a94890be549309b21156f8ed6d4561cac51darrenm * but not least, an MD5 final on the outer context will
734b6a94890be549309b21156f8ed6d4561cac51darrenm * be performed to obtain the MD5 HMAC digest to return
734b6a94890be549309b21156f8ed6d4561cac51darrenm * to the user.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Initialize a MD5-HMAC context.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic void
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_mac_init_ctx(md5_hmac_ctx_t *ctx, void *keyval, uint_t length_in_bytes)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t ipad[MD5_HMAC_INTS_PER_BLOCK];
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t opad[MD5_HMAC_INTS_PER_BLOCK];
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t i;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(ipad, MD5_HMAC_BLOCK_SIZE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(opad, MD5_HMAC_BLOCK_SIZE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(keyval, ipad, length_in_bytes);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(keyval, opad, length_in_bytes);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* XOR key with ipad (0x36) and opad (0x5c) */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (i = 0; i < MD5_HMAC_INTS_PER_BLOCK; i++) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ipad[i] ^= 0x36363636;
734b6a94890be549309b21156f8ed6d4561cac51darrenm opad[i] ^= 0x5c5c5c5c;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* perform MD5 on ipad */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Init(&ctx->hc_icontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&ctx->hc_icontext, ipad, MD5_HMAC_BLOCK_SIZE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* perform MD5 on opad */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Init(&ctx->hc_ocontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&ctx->hc_ocontext, opad, MD5_HMAC_BLOCK_SIZE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Initializes a multi-part MAC operation.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_mac_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t keylen_in_bytes = CRYPTO_BITS2BYTES(key->ck_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type != MD5_HMAC_MECH_INFO_TYPE &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm mechanism->cm_type != MD5_HMAC_GEN_MECH_INFO_TYPE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_MECHANISM_INVALID);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Add support for key by attributes (RFE 4706552) */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (key->ck_format != CRYPTO_KEY_RAW)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = kmem_alloc(sizeof (md5_hmac_ctx_t),
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_kmflag(req));
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ctx->cc_provider_private == NULL)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_HOST_MEMORY);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ctx_template != NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* reuse context template */
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(ctx_template, PROV_MD5_HMAC_CTX(ctx),
734b6a94890be549309b21156f8ed6d4561cac51darrenm sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* no context template, compute context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (keylen_in_bytes > MD5_HMAC_BLOCK_SIZE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digested_key[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_hmac_ctx_t *hmac_ctx = ctx->cc_provider_private;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Hash the passed-in key to get a smaller key.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The inner context is used since it hasn't been
734b6a94890be549309b21156f8ed6d4561cac51darrenm * initialized yet.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_DIGEST_KEY(&hmac_ctx->hc_icontext,
734b6a94890be549309b21156f8ed6d4561cac51darrenm key->ck_data, keylen_in_bytes, digested_key);
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(PROV_MD5_HMAC_CTX(ctx),
734b6a94890be549309b21156f8ed6d4561cac51darrenm digested_key, MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(PROV_MD5_HMAC_CTX(ctx),
734b6a94890be549309b21156f8ed6d4561cac51darrenm key->ck_data, keylen_in_bytes);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Get the mechanism parameters, if applicable.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_HMAC_CTX(ctx)->hc_mech_type = mechanism->cm_type;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type == MD5_HMAC_GEN_MECH_INFO_TYPE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_param == NULL ||
734b6a94890be549309b21156f8ed6d4561cac51darrenm mechanism->cm_param_len != sizeof (ulong_t))
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_MECHANISM_PARAM_INVALID;
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_GET_DIGEST_LEN(mechanism,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_HMAC_CTX(ctx)->hc_digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (PROV_MD5_HMAC_CTX(ctx)->hc_digest_len >
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH)
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_MECHANISM_PARAM_INVALID;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret != CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(ctx->cc_provider_private, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm kmem_free(ctx->cc_provider_private, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_mac_update(crypto_ctx_t *ctx, crypto_data_t *data, crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm ASSERT(ctx->cc_provider_private != NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 update of the inner context using the specified
734b6a94890be549309b21156f8ed6d4561cac51darrenm * data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (data->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&PROV_MD5_HMAC_CTX(ctx)->hc_icontext,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_raw.iov_base + data->cd_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_uio(
734b6a94890be549309b21156f8ed6d4561cac51darrenm &PROV_MD5_HMAC_CTX(ctx)->hc_icontext, data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_mblk(
734b6a94890be549309b21156f8ed6d4561cac51darrenm &PROV_MD5_HMAC_CTX(ctx)->hc_icontext, data);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_mac_final(crypto_ctx_t *ctx, crypto_data_t *mac, crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digest[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t digest_len = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm ASSERT(ctx->cc_provider_private != NULL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (PROV_MD5_HMAC_CTX(ctx)->hc_mech_type == MD5_HMAC_GEN_MECH_INFO_TYPE)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers digest_len = PROV_MD5_HMAC_CTX(ctx)->hc_digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We need to just return the length needed to store the output.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We should not destroy the context for the following cases.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((mac->cd_length == 0) || (mac->cd_length < digest_len)) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_BUFFER_TOO_SMALL);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final on the inner context.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest, &PROV_MD5_HMAC_CTX(ctx)->hc_icontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 update on the outer context, feeding the inner
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest as data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&PROV_MD5_HMAC_CTX(ctx)->hc_ocontext, digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final on the outer context, storing the computing
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest in the users buffer.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (mac->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest_len != MD5_DIGEST_LENGTH) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested a short digest. Digest
734b6a94890be549309b21156f8ed6d4561cac51darrenm * into a scratch buffer and return to
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the user only what was requested.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &PROV_MD5_HMAC_CTX(ctx)->hc_ocontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(digest, (unsigned char *)mac->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_offset, digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final((unsigned char *)mac->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm &PROV_MD5_HMAC_CTX(ctx)->hc_ocontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_uio(
734b6a94890be549309b21156f8ed6d4561cac51darrenm &PROV_MD5_HMAC_CTX(ctx)->hc_ocontext, mac,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest_len, digest);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_mblk(
734b6a94890be549309b21156f8ed6d4561cac51darrenm &PROV_MD5_HMAC_CTX(ctx)->hc_ocontext, mac,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest_len, digest);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret == CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(ctx->cc_provider_private, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm kmem_free(ctx->cc_provider_private, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define MD5_MAC_UPDATE(data, ctx, ret) { \
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (data->cd_format) { \
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW: \
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&(ctx).hc_icontext, \
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_raw.iov_base + data->cd_offset, \
734b6a94890be549309b21156f8ed6d4561cac51darrenm data->cd_length); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm break; \
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO: \
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_uio(&(ctx).hc_icontext, data); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm break; \
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK: \
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_update_mblk(&(ctx).hc_icontext, \
734b6a94890be549309b21156f8ed6d4561cac51darrenm data); \
734b6a94890be549309b21156f8ed6d4561cac51darrenm break; \
734b6a94890be549309b21156f8ed6d4561cac51darrenm default: \
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD; \
734b6a94890be549309b21156f8ed6d4561cac51darrenm } \
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_mac_atomic(crypto_provider_handle_t provider,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_key_t *key, crypto_data_t *data, crypto_data_t *mac,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digest[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_hmac_ctx_t md5_hmac_ctx;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t digest_len = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t keylen_in_bytes = CRYPTO_BITS2BYTES(key->ck_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type != MD5_HMAC_MECH_INFO_TYPE &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm mechanism->cm_type != MD5_HMAC_GEN_MECH_INFO_TYPE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_MECHANISM_INVALID);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Add support for key by attributes (RFE 4706552) */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (key->ck_format != CRYPTO_KEY_RAW)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ctx_template != NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* reuse context template */
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(ctx_template, &md5_hmac_ctx, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* no context template, compute context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (keylen_in_bytes > MD5_HMAC_BLOCK_SIZE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Hash the passed-in key to get a smaller key.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The inner context is used since it hasn't been
734b6a94890be549309b21156f8ed6d4561cac51darrenm * initialized yet.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_DIGEST_KEY(&md5_hmac_ctx.hc_icontext,
734b6a94890be549309b21156f8ed6d4561cac51darrenm key->ck_data, keylen_in_bytes, digest);
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(&md5_hmac_ctx, digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(&md5_hmac_ctx, key->ck_data,
734b6a94890be549309b21156f8ed6d4561cac51darrenm keylen_in_bytes);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Get the mechanism parameters, if applicable.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type == MD5_HMAC_GEN_MECH_INFO_TYPE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_param == NULL ||
734b6a94890be549309b21156f8ed6d4561cac51darrenm mechanism->cm_param_len != sizeof (ulong_t)) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_MECHANISM_PARAM_INVALID;
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_GET_DIGEST_LEN(mechanism, digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest_len > MD5_DIGEST_LENGTH) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_MECHANISM_PARAM_INVALID;
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* do an MD5 update of the inner context using the specified data */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_MAC_UPDATE(data, md5_hmac_ctx, ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret != CRYPTO_SUCCESS)
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* the update failed, free context and bail */
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* do an MD5 final on the inner context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest, &md5_hmac_ctx.hc_icontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 update on the outer context, feeding the inner
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest as data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&md5_hmac_ctx.hc_ocontext, digest, MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final on the outer context, storing the computed
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest in the users buffer.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (mac->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest_len != MD5_DIGEST_LENGTH) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller requested a short digest. Digest
734b6a94890be549309b21156f8ed6d4561cac51darrenm * into a scratch buffer and return to
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the user only what was requested.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest, &md5_hmac_ctx.hc_ocontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(digest, (unsigned char *)mac->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_offset, digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final((unsigned char *)mac->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_offset, &md5_hmac_ctx.hc_ocontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_uio(&md5_hmac_ctx.hc_ocontext, mac,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest_len, digest);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = md5_digest_final_mblk(&md5_hmac_ctx.hc_ocontext, mac,
734b6a94890be549309b21156f8ed6d4561cac51darrenm digest_len, digest);
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret == CRYPTO_SUCCESS) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Extra paranoia: zeroizing the local context on the stack */
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(&md5_hmac_ctx, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenmbail:
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(&md5_hmac_ctx, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_mac_verify_atomic(crypto_provider_handle_t provider,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_key_t *key, crypto_data_t *data, crypto_data_t *mac,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm int ret = CRYPTO_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digest[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_hmac_ctx_t md5_hmac_ctx;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t digest_len = MD5_DIGEST_LENGTH;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t keylen_in_bytes = CRYPTO_BITS2BYTES(key->ck_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type != MD5_HMAC_MECH_INFO_TYPE &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm mechanism->cm_type != MD5_HMAC_GEN_MECH_INFO_TYPE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_MECHANISM_INVALID);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Add support for key by attributes (RFE 4706552) */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (key->ck_format != CRYPTO_KEY_RAW)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ctx_template != NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* reuse context template */
734b6a94890be549309b21156f8ed6d4561cac51darrenm bcopy(ctx_template, &md5_hmac_ctx, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* no context template, compute context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (keylen_in_bytes > MD5_HMAC_BLOCK_SIZE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Hash the passed-in key to get a smaller key.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The inner context is used since it hasn't been
734b6a94890be549309b21156f8ed6d4561cac51darrenm * initialized yet.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_DIGEST_KEY(&md5_hmac_ctx.hc_icontext,
734b6a94890be549309b21156f8ed6d4561cac51darrenm key->ck_data, keylen_in_bytes, digest);
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(&md5_hmac_ctx, digest,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(&md5_hmac_ctx, key->ck_data,
734b6a94890be549309b21156f8ed6d4561cac51darrenm keylen_in_bytes);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Get the mechanism parameters, if applicable.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_type == MD5_HMAC_GEN_MECH_INFO_TYPE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mechanism->cm_param == NULL ||
734b6a94890be549309b21156f8ed6d4561cac51darrenm mechanism->cm_param_len != sizeof (ulong_t)) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_MECHANISM_PARAM_INVALID;
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_GET_DIGEST_LEN(mechanism, digest_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (digest_len > MD5_DIGEST_LENGTH) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_MECHANISM_PARAM_INVALID;
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mac->cd_length != digest_len) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_INVALID_MAC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* do an MD5 update of the inner context using the specified data */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_MAC_UPDATE(data, md5_hmac_ctx, ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ret != CRYPTO_SUCCESS)
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* the update failed, free context and bail */
734b6a94890be549309b21156f8ed6d4561cac51darrenm goto bail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* do an MD5 final on the inner context */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest, &md5_hmac_ctx.hc_icontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 update on the outer context, feeding the inner
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest as data.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Update(&md5_hmac_ctx.hc_ocontext, digest, MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Do an MD5 final on the outer context, storing the computed
734b6a94890be549309b21156f8ed6d4561cac51darrenm * digest in the local digest buffer.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5Final(digest, &md5_hmac_ctx.hc_ocontext);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Compare the computed digest against the expected digest passed
734b6a94890be549309b21156f8ed6d4561cac51darrenm * as argument.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm switch (mac->cd_format) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_RAW:
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (bcmp(digest, (unsigned char *)mac->cd_raw.iov_base +
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_offset, digest_len) != 0)
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_INVALID_MAC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_UIO: {
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t offset = mac->cd_offset;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t vec_idx;
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t scratch_offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* we support only kernel buffer */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mac->cd_uio->uio_segflg != UIO_SYSSPACE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* jump to the first iovec containing the expected digest */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (vec_idx = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset >= mac->cd_uio->uio_iov[vec_idx].iov_len &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm vec_idx < mac->cd_uio->uio_iovcnt;
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers offset -= mac->cd_uio->uio_iov[vec_idx++].iov_len)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers ;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (vec_idx == mac->cd_uio->uio_iovcnt) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller specified an offset that is
734b6a94890be549309b21156f8ed6d4561cac51darrenm * larger than the total size of the buffers
734b6a94890be549309b21156f8ed6d4561cac51darrenm * it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_DATA_LEN_RANGE;
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* do the comparison of computed digest vs specified one */
734b6a94890be549309b21156f8ed6d4561cac51darrenm while (vec_idx < mac->cd_uio->uio_iovcnt && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len = MIN(mac->cd_uio->uio_iov[vec_idx].iov_len -
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset, length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (bcmp(digest + scratch_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_uio->uio_iov[vec_idx].iov_base + offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len) != 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_INVALID_MAC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm length -= cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm vec_idx++;
734b6a94890be549309b21156f8ed6d4561cac51darrenm scratch_offset += cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm case CRYPTO_DATA_MBLK: {
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t offset = mac->cd_offset;
734b6a94890be549309b21156f8ed6d4561cac51darrenm mblk_t *mp;
734b6a94890be549309b21156f8ed6d4561cac51darrenm off_t scratch_offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t length = digest_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm size_t cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* jump to the first mblk_t containing the expected digest */
734b6a94890be549309b21156f8ed6d4561cac51darrenm for (mp = mac->cd_mp; mp != NULL && offset >= MBLKL(mp);
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers offset -= MBLKL(mp), mp = mp->b_cont)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers ;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mp == NULL) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The caller specified an offset that is larger than
734b6a94890be549309b21156f8ed6d4561cac51darrenm * the total size of the buffers it provided.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_DATA_LEN_RANGE;
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm while (mp != NULL && length > 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm cur_len = MIN(MBLKL(mp) - offset, length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (bcmp(digest + scratch_offset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm mp->b_rptr + offset, cur_len) != 0) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_INVALID_MAC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm length -= cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm mp = mp->b_cont;
734b6a94890be549309b21156f8ed6d4561cac51darrenm scratch_offset += cur_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm offset = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm break;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm default:
734b6a94890be549309b21156f8ed6d4561cac51darrenm ret = CRYPTO_ARGUMENTS_BAD;
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(&md5_hmac_ctx, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenmbail:
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(&md5_hmac_ctx, sizeof (md5_hmac_ctx_t));
734b6a94890be549309b21156f8ed6d4561cac51darrenm mac->cd_length = 0;
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (ret);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * KCF software provider context management entry points.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* ARGSUSED */
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_create_ctx_template(crypto_provider_handle_t provider,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_mechanism_t *mechanism, crypto_key_t *key,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_spi_ctx_template_t *ctx_template, size_t *ctx_template_size,
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_req_handle_t req)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_hmac_ctx_t *md5_hmac_ctx_tmpl;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t keylen_in_bytes = CRYPTO_BITS2BYTES(key->ck_length);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if ((mechanism->cm_type != MD5_HMAC_MECH_INFO_TYPE) &&
734b6a94890be549309b21156f8ed6d4561cac51darrenm (mechanism->cm_type != MD5_HMAC_GEN_MECH_INFO_TYPE))
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_MECHANISM_INVALID);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Add support for key by attributes (RFE 4706552) */
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (key->ck_format != CRYPTO_KEY_RAW)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_ARGUMENTS_BAD);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Allocate and initialize MD5 context.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_hmac_ctx_tmpl = kmem_alloc(sizeof (md5_hmac_ctx_t),
734b6a94890be549309b21156f8ed6d4561cac51darrenm crypto_kmflag(req));
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (md5_hmac_ctx_tmpl == NULL)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_HOST_MEMORY);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (keylen_in_bytes > MD5_HMAC_BLOCK_SIZE) {
734b6a94890be549309b21156f8ed6d4561cac51darrenm uchar_t digested_key[MD5_DIGEST_LENGTH];
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Hash the passed-in key to get a smaller key.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The inner context is used since it hasn't been
734b6a94890be549309b21156f8ed6d4561cac51darrenm * initialized yet.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PROV_MD5_DIGEST_KEY(&md5_hmac_ctx_tmpl->hc_icontext,
734b6a94890be549309b21156f8ed6d4561cac51darrenm key->ck_data, keylen_in_bytes, digested_key);
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(md5_hmac_ctx_tmpl, digested_key,
734b6a94890be549309b21156f8ed6d4561cac51darrenm MD5_DIGEST_LENGTH);
734b6a94890be549309b21156f8ed6d4561cac51darrenm } else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mac_init_ctx(md5_hmac_ctx_tmpl, key->ck_data,
734b6a94890be549309b21156f8ed6d4561cac51darrenm keylen_in_bytes);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_hmac_ctx_tmpl->hc_mech_type = mechanism->cm_type;
734b6a94890be549309b21156f8ed6d4561cac51darrenm *ctx_template = (crypto_spi_ctx_template_t)md5_hmac_ctx_tmpl;
734b6a94890be549309b21156f8ed6d4561cac51darrenm *ctx_template_size = sizeof (md5_hmac_ctx_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmstatic int
734b6a94890be549309b21156f8ed6d4561cac51darrenmmd5_free_context(crypto_ctx_t *ctx)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint_t ctx_len;
734b6a94890be549309b21156f8ed6d4561cac51darrenm md5_mech_type_t mech_type;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (ctx->cc_provider_private == NULL)
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * We have to free either MD5 or MD5-HMAC contexts, which
734b6a94890be549309b21156f8ed6d4561cac51darrenm * have different lengths.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm mech_type = PROV_MD5_CTX(ctx)->mc_mech_type;
734b6a94890be549309b21156f8ed6d4561cac51darrenm if (mech_type == MD5_MECH_INFO_TYPE)
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx_len = sizeof (md5_ctx_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenm else {
734b6a94890be549309b21156f8ed6d4561cac51darrenm ASSERT(mech_type == MD5_HMAC_MECH_INFO_TYPE ||
734b6a94890be549309b21156f8ed6d4561cac51darrenm mech_type == MD5_HMAC_GEN_MECH_INFO_TYPE);
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx_len = sizeof (md5_hmac_ctx_t);
734b6a94890be549309b21156f8ed6d4561cac51darrenm }
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm bzero(ctx->cc_provider_private, ctx_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm kmem_free(ctx->cc_provider_private, ctx_len);
734b6a94890be549309b21156f8ed6d4561cac51darrenm ctx->cc_provider_private = NULL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (CRYPTO_SUCCESS);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}