fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2000 by Cisco Systems, Inc. All rights reserved.
1a1a84a324206b6b1f5f704ab166c4ebf78aed76Peter Dunlap * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI Pseudo HBA Driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/random.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "chap.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi.h"
1a1a84a324206b6b1f5f704ab166c4ebf78aed76Peter Dunlap#include <sys/iscsi_protocol.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsiAuthClient.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "persistent.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Authenticate a target's CHAP response.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * username - Incoming username from the the target.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * responseData - Incoming response data from the target.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthClientChapAuthRequest(IscsiAuthClient *client,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *username, unsigned int id, uchar_t *challengeData,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int challengeLength, uchar_t *responseData,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int responseLength)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = (iscsi_sess_t *)client->userHandle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IscsiAuthMd5Context context;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t verifyData[16];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_radius_props_t p_radius_cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the expected credentials are in the session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_auth.username_in == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi session(%u) failed authentication, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "no incoming username configured to authenticate target",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(username, isp->sess_auth.username_in) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi session(%u) failed authentication, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "received incorrect username from target",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if RADIUS access is enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_radius_get(&p_radius_cfg) == ISCSI_NVFILE_SUCCESS &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_radius_cfg.r_radius_access == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap_validation_status_type chap_valid_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int authStatus;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RADIUS_CONFIG radius_cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p_radius_cfg.r_radius_config_valid == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Radius enabled but configuration invalid -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invalid condition
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Use RADIUS server to authentication target */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p_radius_cfg.r_insize == sizeof (in_addr_t)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv4 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_addr.i_addr.in4.s_addr =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_radius_cfg.r_addr.u_in4.s_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_addr.i_insize
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte = sizeof (in_addr_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (p_radius_cfg.r_insize == sizeof (in6_addr_t)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(p_radius_cfg.r_addr.u_in6.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_addr.i_addr.in6.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_addr.i_insize = sizeof (in6_addr_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_port = p_radius_cfg.r_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(p_radius_cfg.r_shared_secret,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_shared_secret,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RAD_SHARED_SECRET_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte radius_cfg.rad_svr_shared_secret_len =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_radius_cfg.r_shared_secret_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Entry point to the CHAP authentication module. */
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China chap_valid_status = chap_validate_tgt(
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China isp->sess_auth.username_in,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China isp->sess_auth.username,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China challengeData,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China challengeLength,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China responseData,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China responseLength,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China id,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China RADIUS_AUTHENTICATION,
5df5713f81d69c1a0797f99b13e95e220da00ef9bing zhao - Sun Microsystems - Beijing China (void *)&radius_cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (chap_valid_status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CHAP_VALIDATION_PASSED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authStatus = iscsiAuthStatusPass;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CHAP_VALIDATION_INVALID_RESPONSE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authStatus = iscsiAuthStatusFail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CHAP_VALIDATION_DUP_SECRET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authStatus = iscsiAuthStatusFail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CHAP_VALIDATION_RADIUS_ACCESS_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authStatus = iscsiAuthStatusFail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CHAP_VALIDATION_BAD_RADIUS_SECRET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authStatus = iscsiAuthStatusFail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authStatus = iscsiAuthStatusFail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (authStatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Use target secret (if defined) to authenticate target */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((isp->sess_auth.password_length_in < 1) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isp->sess_auth.password_in == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isp->sess_auth.password_in[0] == '\0')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No target secret defined - invalid condition */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * challenge length is I->T, and shouldn't need to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be checked
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (responseLength != sizeof (verifyData)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi session(%u) failed "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "authentication, received incorrect CHAP response "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "from target", isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsiAuthMd5Init(&context);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * id byte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verifyData[0] = id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsiAuthMd5Update(&context, verifyData, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * shared secret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsiAuthMd5Update(&context,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)isp->sess_auth.password_in,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.password_length_in);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * challenge value
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsiAuthMd5Update(&context,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)challengeData,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte challengeLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsiAuthMd5Final(verifyData, &context);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(responseData, verifyData,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (verifyData)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusPass);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi session(%u) failed authentication, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "received incorrect CHAP response from target",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iscsiAuthStatusFail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthClientChapAuthCancel(IscsiAuthClient * client)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthClientTextToNumber(const char *text, unsigned long *pNumber)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *pEnd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned long number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (text[0] == '0' && (text[1] == 'x' || text[1] == 'X')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_strtoul(text + 2, &pEnd, 16, &number) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* Error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_strtoul(text, &pEnd, 10, &number) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* Error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*text != '\0' && *pEnd == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pNumber = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* No error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* Error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthClientNumberToText(unsigned long number, char *text,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int length)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(text, "%lu", number);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthRandomSetData(uchar_t *data, unsigned int length)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) random_get_pseudo_bytes(data, length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthMd5Init(IscsiAuthMd5Context * context)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MD5Init(context);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthMd5Update(IscsiAuthMd5Context *context, uchar_t *data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int length)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MD5Update(context, data, length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthMd5Final(uchar_t *hash, IscsiAuthMd5Context *context)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MD5Final(hash, context);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiscsiAuthClientData(uchar_t *outData, unsigned int *outLength,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *inData, unsigned int inLength)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*outLength < inLength) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(inData, outData, inLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *outLength = inLength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* no error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}