Move the iSCSI code over to use the endian neutral md5 code,
originally from Poul-Henning Kamp, as found in pkgsrc/pkgtools/digest. This should address some of the MD5 problems that are being seen on some hosts at login time. Re-run autoconf, autoheader and configure.
This commit is contained in:
parent
df4b4cffe4
commit
4ed8885f3b
|
@ -13,6 +13,9 @@
|
|||
/* Define to 1 if you have the `asprintf' function. */
|
||||
#define HAVE_ASPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `bcopy' function. */
|
||||
#define HAVE_BCOPY 1
|
||||
|
||||
/* Define to 1 if you have the `bswap64' function. */
|
||||
#define HAVE_BSWAP64 1
|
||||
|
||||
|
@ -67,6 +70,9 @@
|
|||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#define HAVE_NETDB_H 1
|
||||
|
||||
|
@ -194,13 +200,13 @@
|
|||
#define PACKAGE_NAME "netbsd-iscsi"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "netbsd-iscsi 20071206"
|
||||
#define PACKAGE_STRING "netbsd-iscsi 20071208"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "netbsd-iscsi"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "20071206"
|
||||
#define PACKAGE_VERSION "20071208"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
/* Define to 1 if you have the `asprintf' function. */
|
||||
#undef HAVE_ASPRINTF
|
||||
|
||||
/* Define to 1 if you have the `bcopy' function. */
|
||||
#undef HAVE_BCOPY
|
||||
|
||||
/* Define to 1 if you have the `bswap64' function. */
|
||||
#undef HAVE_BSWAP64
|
||||
|
||||
|
@ -66,6 +69,9 @@
|
|||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#undef HAVE_NETDB_H
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/* $NetBSD: iscsi-md5.h,v 1.1 2007/12/09 09:21:04 agc Exp $ */
|
||||
|
||||
/*
|
||||
* This file is derived from the RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm and has been modified by Jason R. Thorpe <thorpej@NetBSD.ORG>
|
||||
* for portability and formatting.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
* rights reserved.
|
||||
*
|
||||
* License to copy and use this software is granted provided that it
|
||||
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm" in all material mentioning or referencing this software
|
||||
* or this function.
|
||||
*
|
||||
* License is also granted to make and use derivative works provided
|
||||
* that such works are identified as "derived from the RSA Data
|
||||
* Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
* mentioning or referencing the derived work.
|
||||
*
|
||||
* RSA Data Security, Inc. makes no representations concerning either
|
||||
* the merchantability of this software or the suitability of this
|
||||
* software for any particular purpose. It is provided "as is"
|
||||
* without express or implied warranty of any kind.
|
||||
*
|
||||
* These notices must be retained in any copies of any part of this
|
||||
* documentation and/or software.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_MD5_H_
|
||||
#define _SYS_MD5_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* iSCSI_MD5 context. */
|
||||
typedef struct iSCSI_MD5Context {
|
||||
uint32_t state[4]; /* state (ABCD) */
|
||||
uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
|
||||
unsigned char buffer[64]; /* input buffer */
|
||||
} iSCSI_MD5_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void iSCSI_MD5Init(iSCSI_MD5_CTX *);
|
||||
void iSCSI_MD5Update(iSCSI_MD5_CTX *, const uint8_t *, size_t);
|
||||
void iSCSI_MD5Final(unsigned char[16], iSCSI_MD5_CTX *);
|
||||
#ifndef _KERNEL
|
||||
char *iSCSI_MD5End(iSCSI_MD5_CTX *, char *);
|
||||
char *iSCSI_MD5File(const char *, char *);
|
||||
char *iSCSI_MD5Data(const uint8_t *, size_t, char *);
|
||||
#endif /* _KERNEL */
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _SYS_MD5_H_ */
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* This is the header file for the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
* This code is in the public domain; do with it what you wish.
|
||||
*
|
||||
* Equivalent code is available from RSA Data Security, Inc.
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*
|
||||
* To compute the message digest of a chunk of bytes, declare an
|
||||
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||
* needed on buffers full of bytes, and then call MD5Final, which
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*
|
||||
* Changed so as no longer to depend on Colin Plumb's `usual.h'
|
||||
* header definitions; now uses stuff from dpkg's config.h
|
||||
* - Ian Jackson <ijackson@nyx.cs.du.edu>.
|
||||
* Still in the public domain.
|
||||
*/
|
||||
|
||||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
|
||||
|
||||
|
||||
typedef uint32_t UWORD32;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define md5byte uint8_t
|
||||
|
||||
|
||||
struct MD5Context {
|
||||
UWORD32 buf[4];
|
||||
UWORD32 bytes[2];
|
||||
UWORD32 in[16];
|
||||
};
|
||||
|
||||
void MD5Init(struct MD5Context *context);
|
||||
void MD5Update(struct MD5Context *context, void const *vbuf, uint32_t len);
|
||||
void MD5Final(uint8_t digest[16], struct MD5Context *context);
|
||||
void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MD5_H */
|
|
@ -45,7 +45,7 @@ all-initiator: ${INITIATORS}
|
|||
#
|
||||
COMPATOBJS= strlcpy.o snprintf.o strtoll.o uuid.o
|
||||
|
||||
USER_TARGET_OBJS = target.o iscsi.o util.o parameters.o netmask.o conffile.o storage.o ${COMPATOBJS}
|
||||
USER_TARGET_OBJS = target.o iscsi.o util.o parameters.o netmask.o conffile.o storage.o md5c.o md5hl.c ${COMPATOBJS}
|
||||
iscsi-target: iscsi-target.c disk.c $(USER_TARGET_OBJS)
|
||||
$(CC) $(CFLAGS) iscsi-target.c disk.c $(USER_TARGET_OBJS) ${PTHREAD_LDFLAGS} ${PTHREAD_LIBS} ${LIBS} -o iscsi-target
|
||||
osd: osd-target.c osd.c $(USER_TARGET_OBJS)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.61 for netbsd-iscsi 20071206.
|
||||
# Generated by GNU Autoconf 2.61 for netbsd-iscsi 20071208.
|
||||
#
|
||||
# Report bugs to <Alistair Crooks <agc@NetBSD.org>>.
|
||||
#
|
||||
|
@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
|
|||
# Identity of this package.
|
||||
PACKAGE_NAME='netbsd-iscsi'
|
||||
PACKAGE_TARNAME='netbsd-iscsi'
|
||||
PACKAGE_VERSION='20071206'
|
||||
PACKAGE_STRING='netbsd-iscsi 20071206'
|
||||
PACKAGE_VERSION='20071208'
|
||||
PACKAGE_STRING='netbsd-iscsi 20071208'
|
||||
PACKAGE_BUGREPORT='Alistair Crooks <agc@NetBSD.org>'
|
||||
|
||||
ac_unique_file="iscsi.c"
|
||||
|
@ -1180,7 +1180,7 @@ if test "$ac_init_help" = "long"; then
|
|||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures netbsd-iscsi 20071206 to adapt to many kinds of systems.
|
||||
\`configure' configures netbsd-iscsi 20071208 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
|
@ -1241,7 +1241,7 @@ fi
|
|||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of netbsd-iscsi 20071206:";;
|
||||
short | recursive ) echo "Configuration of netbsd-iscsi 20071208:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
|
@ -1319,7 +1319,7 @@ fi
|
|||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
netbsd-iscsi configure 20071206
|
||||
netbsd-iscsi configure 20071208
|
||||
generated by GNU Autoconf 2.61
|
||||
|
||||
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
|
||||
|
@ -1333,7 +1333,7 @@ cat >config.log <<_ACEOF
|
|||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by netbsd-iscsi $as_me 20071206, which was
|
||||
It was created by netbsd-iscsi $as_me 20071208, which was
|
||||
generated by GNU Autoconf 2.61. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
|
@ -4670,7 +4670,9 @@ fi
|
|||
|
||||
|
||||
|
||||
for ac_func in __bswap64 asprintf asnprintf bswap64 daemon fsync_range getaddrinfo getnameinfo htobe64 poll snprintf strlcpy strtoll syslog uuid_create uuid_to_string vasprintf vasnprintf vsnprintf
|
||||
|
||||
|
||||
for ac_func in __bswap64 asprintf asnprintf bswap64 daemon fsync_range getaddrinfo getnameinfo htobe64 memset bcopy poll snprintf strlcpy strtoll syslog uuid_create uuid_to_string vasprintf vasnprintf vsnprintf
|
||||
do
|
||||
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||
|
@ -5162,7 +5164,7 @@ exec 6>&1
|
|||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by netbsd-iscsi $as_me 20071206, which was
|
||||
This file was extended by netbsd-iscsi $as_me 20071208, which was
|
||||
generated by GNU Autoconf 2.61. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
|
@ -5211,7 +5213,7 @@ Report bugs to <bug-autoconf@gnu.org>."
|
|||
_ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF
|
||||
ac_cs_version="\\
|
||||
netbsd-iscsi config.status 20071206
|
||||
netbsd-iscsi config.status 20071208
|
||||
configured by $0, generated by GNU Autoconf 2.61,
|
||||
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([netbsd-iscsi],[20071206],[Alistair Crooks <agc@NetBSD.org>])
|
||||
AC_INIT([netbsd-iscsi],[20071208],[Alistair Crooks <agc@NetBSD.org>])
|
||||
AC_CONFIG_SRCDIR([iscsi.c])
|
||||
AC_CONFIG_HEADER(../include/config.h)
|
||||
|
||||
|
@ -34,7 +34,7 @@ AC_CHECK_LIB(socket, connect)
|
|||
AC_CHECK_LIB(resolv, inet_aton)
|
||||
|
||||
dnl Check for functionality
|
||||
AC_CHECK_FUNCS(__bswap64 asprintf asnprintf bswap64 daemon fsync_range getaddrinfo getnameinfo htobe64 poll snprintf strlcpy strtoll syslog uuid_create uuid_to_string vasprintf vasnprintf vsnprintf)
|
||||
AC_CHECK_FUNCS(__bswap64 asprintf asnprintf bswap64 daemon fsync_range getaddrinfo getnameinfo htobe64 memset bcopy poll snprintf strlcpy strtoll syslog uuid_create uuid_to_string vasprintf vasnprintf vsnprintf)
|
||||
|
||||
dnl that's it for now...
|
||||
AC_OUTPUT(Makefile)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: disk.c,v 1.35 2007/12/04 16:25:37 oster Exp $ */
|
||||
/* $NetBSD: disk.c,v 1.36 2007/12/09 09:21:05 agc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright © 2006 Alistair Crooks. All rights reserved.
|
||||
|
@ -142,7 +142,7 @@ enum {
|
|||
|
||||
#define MB(x) ((x) * 1024 * 1024)
|
||||
|
||||
/* this struct describes an iscsi disk */
|
||||
/* this struct describes an iscsi LUN */
|
||||
typedef struct iscsi_disk_t {
|
||||
int type; /* type of disk - fs/mmap and fs */
|
||||
char filename[MAXPATHLEN]; /* filename for the disk itself */
|
||||
|
@ -626,101 +626,6 @@ de_getsize(disc_de_t *dp)
|
|||
}
|
||||
}
|
||||
|
||||
/* mmap on the extent */
|
||||
static void *
|
||||
extent_mmap(void *addr, size_t len, int prot, int flags, disc_extent_t *xp, off_t offset)
|
||||
{
|
||||
return mmap(addr, len, prot, flags, xp->fd, (off_t)(xp->sacred + offset));
|
||||
}
|
||||
|
||||
/* (recursively) mmap on the device's devices */
|
||||
static void *
|
||||
device_mmap(void *addr, size_t len, int prot, int flags, disc_device_t *dp, off_t offset)
|
||||
{
|
||||
void *ret;
|
||||
int i;
|
||||
|
||||
for (ret = MAP_FAILED, i = 0 ; i < dp->c ; i++) {
|
||||
switch (dp->xv[i].type) {
|
||||
case DE_DEVICE:
|
||||
if ((ret = device_mmap(addr, len, prot, flags, dp->xv[i].u.dp, offset)) == MAP_FAILED) {
|
||||
return MAP_FAILED;
|
||||
}
|
||||
break;
|
||||
case DE_EXTENT:
|
||||
if ((ret = extent_mmap(addr, len, prot, flags, dp->xv[i].u.xp, offset)) == MAP_FAILED) {
|
||||
return MAP_FAILED;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* and for the undecided... */
|
||||
static void *
|
||||
de_mmap(void *addr, size_t len, int prot, int flags, disc_de_t *dp, off_t offset)
|
||||
{
|
||||
switch(dp->type) {
|
||||
case DE_DEVICE:
|
||||
return device_mmap(addr, len, prot, flags, dp->u.dp, offset);
|
||||
case DE_EXTENT:
|
||||
return extent_mmap(addr, len, prot, flags, dp->u.xp, offset);
|
||||
default:
|
||||
return MAP_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
/* munmap the extent's device */
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
extent_munmap(disc_extent_t *xp, void *addr, size_t len)
|
||||
{
|
||||
return munmap(addr, len);
|
||||
}
|
||||
|
||||
/* (recursively) munmap the device's devices */
|
||||
static int
|
||||
device_munmap(disc_device_t *dp, void *addr, size_t len)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
for (ret = -1, i = 0 ; i < dp->c ; i++) {
|
||||
switch (dp->xv[i].type) {
|
||||
case DE_DEVICE:
|
||||
if ((ret = device_munmap(dp->xv[i].u.dp, addr, len)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case DE_EXTENT:
|
||||
if ((ret = extent_munmap(dp->xv[i].u.xp, addr, len)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* and for the undecided... */
|
||||
static int
|
||||
de_munmap(disc_de_t *dp, void *addr, size_t len)
|
||||
{
|
||||
switch(dp->type) {
|
||||
case DE_DEVICE:
|
||||
return device_munmap(dp->u.dp, addr, len);
|
||||
case DE_EXTENT:
|
||||
return extent_munmap(dp->u.xp, addr, len);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* return a filename for the device or extent */
|
||||
static char *
|
||||
disc_get_filename(disc_de_t *de)
|
||||
|
@ -888,31 +793,23 @@ device_init(globals_t *gp __attribute__((__unused__)), targv_t *tvp, disc_target
|
|||
iscsi_trace_error(__FILE__, __LINE__, "Invalid block len %" PRIu64 ". Choose one of 512, 1024, 2048, 4096.\n", disks.v[disks.c].blocklen);
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
disks.v[disks.c].type = (disks.v[disks.c].size > MB(100)) ?
|
||||
ISCSI_FS : (disks.v[disks.c].size > MB(50)) ?
|
||||
ISCSI_FS_MMAP : ISCSI_RAMDISK;
|
||||
#else
|
||||
disks.v[disks.c].type = ISCSI_FS;
|
||||
#endif
|
||||
printf("DISK: %" PRIu64 " logical unit%s (%" PRIu64 " blocks, %" PRIu64 " bytes/block), type %s\n",
|
||||
disks.v[disks.c].luns,
|
||||
(disks.v[disks.c].luns == 1) ? "" : "s",
|
||||
disks.v[disks.c].blockc, disks.v[disks.c].blocklen,
|
||||
(disks.v[disks.c].type == ISCSI_FS) ? "iscsi fs" : "iscsi fs mmap");
|
||||
for (i = 0; i < disks.v[disks.c].luns; i++) {
|
||||
printf("DISK: LUN %d: ", i);
|
||||
(void) strlcpy(disks.v[disks.c].filename, disc_get_filename(&tp->de), sizeof(disks.v[disks.c].filename));
|
||||
if (de_open(&tp->de, O_CREAT | O_RDWR, 0666) == -1) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "error opening \"%s\"\n", disks.v[disks.c].filename);
|
||||
return -1;
|
||||
}
|
||||
if (!allocate_space(tp)) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "error allocating space for \"%s\"", tp->target);
|
||||
return -1;
|
||||
}
|
||||
printf("%" PRIu64 " MB disk storage for \"%s\"\n", (de_getsize(&tp->de) / MB(1)), tp->target);
|
||||
printf("DISK: LUN %d: ", i);
|
||||
(void) strlcpy(disks.v[disks.c].filename, disc_get_filename(&tp->de), sizeof(disks.v[disks.c].filename));
|
||||
if (de_open(&tp->de, O_CREAT | O_RDWR, 0666) == -1) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "error opening \"%s\"\n", disks.v[disks.c].filename);
|
||||
return -1;
|
||||
}
|
||||
if (!allocate_space(tp)) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "error allocating space for \"%s\"", tp->target);
|
||||
return -1;
|
||||
}
|
||||
printf("%" PRIu64 " MB disk storage for \"%s\"\n", (de_getsize(&tp->de) / MB(1)), tp->target);
|
||||
return disks.c++;
|
||||
}
|
||||
|
||||
|
@ -931,26 +828,6 @@ device_command(target_session_t * sess, target_cmd_t * cmd)
|
|||
uint8_t lun = (uint8_t) (args->lun >> 32);
|
||||
size_t mode_data_len;
|
||||
|
||||
#if (CONFIG_DISK_INITIAL_CHECK_CONDITION==1)
|
||||
static int initialized = 0;
|
||||
static int flag[disks.v[sess->d].luns];
|
||||
int i;
|
||||
|
||||
if (!initialized) {
|
||||
for (i = 0; i < disks.v[sess->d].luns; i++) {
|
||||
flag[i] = 0;
|
||||
}
|
||||
initialized = 1;
|
||||
}
|
||||
if (!flag[lun]) {
|
||||
printf("DISK: Simulating CHECK CONDITION with sense data (cdb %#x, lun %d)\n", cdb[0], lun);
|
||||
flag[lun]++;
|
||||
args->status = SCSI_CHECK_CONDITION;
|
||||
args->length = 1024;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
totsize = &cdb[4];
|
||||
|
||||
/*
|
||||
|
@ -961,8 +838,7 @@ device_command(target_session_t * sess, target_cmd_t * cmd)
|
|||
data = args->send_data;
|
||||
(void) memset(data, 0x0, (size_t) *totsize);
|
||||
/*
|
||||
* data[0] = 0x7F;
|
||||
* / no device
|
||||
* data[0] = 0x7F; means no device
|
||||
*/
|
||||
data[0] = 0x1F; /* device type */
|
||||
data[0] |= 0x60;/* peripheral qualifier */
|
||||
|
@ -972,7 +848,7 @@ device_command(target_session_t * sess, target_cmd_t * cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
lun = sess->d;
|
||||
lun = (uint8_t) sess->d;
|
||||
iscsi_trace(TRACE_SCSI_CMD, __FILE__, __LINE__, "SCSI op %#x (lun %d): \n", cdb[0], lun);
|
||||
|
||||
switch (cdb[0]) {
|
||||
|
@ -1316,26 +1192,13 @@ disk_write(target_session_t *sess, iscsi_scsi_cmd_args_t *args, uint8_t lun, uin
|
|||
uint64_t num_bytes = len * disks.v[sess->d].blocklen;
|
||||
uint8_t *ptr = NULL;
|
||||
struct iovec sg;
|
||||
uint64_t extra = 0;
|
||||
|
||||
iscsi_trace(TRACE_SCSI_DATA, __FILE__, __LINE__, "writing %" PRIu64 " bytes from socket into device at byte offset %" PRIu64 "\n", num_bytes, byte_offset);
|
||||
|
||||
/* Assign ptr for write data */
|
||||
|
||||
switch(disks.v[sess->d].type) {
|
||||
case ISCSI_FS:
|
||||
RETURN_GREATER("num_bytes (FIX ME)", (unsigned) num_bytes, MB(1), NO_CLEANUP, -1);
|
||||
ptr = disks.v[sess->d].buffer[lun];
|
||||
break;
|
||||
case ISCSI_FS_MMAP:
|
||||
extra = byte_offset % 4096;
|
||||
if ((ptr = de_mmap(0, (size_t) (num_bytes + extra), PROT_WRITE, MAP_SHARED, &disks.v[sess->d].tv->v[lun].de, (off_t)(byte_offset - extra))) == NULL) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "mmap() failed\n");
|
||||
return -1;
|
||||
} else {
|
||||
ptr += (uint32_t) extra;
|
||||
}
|
||||
}
|
||||
RETURN_GREATER("num_bytes (FIX ME)", (unsigned) num_bytes, MB(1), NO_CLEANUP, -1);
|
||||
ptr = disks.v[sess->d].buffer[lun];
|
||||
|
||||
/* Have target do data transfer */
|
||||
|
||||
|
@ -1345,27 +1208,17 @@ disk_write(target_session_t *sess, iscsi_scsi_cmd_args_t *args, uint8_t lun, uin
|
|||
iscsi_trace_error(__FILE__, __LINE__, "target_transfer_data() failed\n");
|
||||
}
|
||||
/* Finish up write */
|
||||
switch(disks.v[sess->d].type) {
|
||||
case ISCSI_FS:
|
||||
if (de_lseek(&disks.v[sess->d].tv->v[lun].de, (off_t) byte_offset, SEEK_SET) == -1) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "lseek() to offset %" PRIu64 " failed\n", byte_offset);
|
||||
return -1;
|
||||
}
|
||||
if (!target_writable(&disks.v[sess->d].tv->v[lun])) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "write() of %" PRIu64 " bytes failed at offset %" PRIu64 ", size %" PRIu64 "[READONLY TARGET]\n", num_bytes, byte_offset, de_getsize(&disks.v[sess->d].tv->v[lun].de));
|
||||
return -1;
|
||||
}
|
||||
if (de_write(&disks.v[sess->d].tv->v[lun].de, ptr, (unsigned) num_bytes) != num_bytes) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "write() of %" PRIu64 " bytes failed at offset %" PRIu64 ", size %" PRIu64 "\n", num_bytes, byte_offset, de_getsize(&disks.v[sess->d].tv->v[lun].de));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case ISCSI_FS_MMAP:
|
||||
ptr -= (uint32_t) extra;
|
||||
if (de_munmap(&disks.v[sess->d].tv->v[lun].de, ptr, (size_t)(num_bytes + extra)) != 0) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "munmap() failed\n");
|
||||
return -1;
|
||||
}
|
||||
if (de_lseek(&disks.v[sess->d].tv->v[lun].de, (off_t) byte_offset, SEEK_SET) == -1) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "lseek() to offset %" PRIu64 " failed\n", byte_offset);
|
||||
return -1;
|
||||
}
|
||||
if (!target_writable(&disks.v[sess->d].tv->v[lun])) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "write() of %" PRIu64 " bytes failed at offset %" PRIu64 ", size %" PRIu64 "[READONLY TARGET]\n", num_bytes, byte_offset, de_getsize(&disks.v[sess->d].tv->v[lun].de));
|
||||
return -1;
|
||||
}
|
||||
if (de_write(&disks.v[sess->d].tv->v[lun].de, ptr, (unsigned) num_bytes) != num_bytes) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "write() of %" PRIu64 " bytes failed at offset %" PRIu64 ", size %" PRIu64 "\n", num_bytes, byte_offset, de_getsize(&disks.v[sess->d].tv->v[lun].de));
|
||||
return -1;
|
||||
}
|
||||
iscsi_trace(TRACE_SCSI_DATA, __FILE__, __LINE__, "wrote %" PRIu64 " bytes to device OK\n", num_bytes);
|
||||
return 0;
|
||||
|
@ -1404,50 +1257,24 @@ disk_read(target_session_t * sess, iscsi_scsi_cmd_args_t * args, uint32_t lba, u
|
|||
iscsi_trace_error(__FILE__, __LINE__, "max_lba = %" PRIu64 ", requested lba = %u, len = %u\n", disks.v[sess->d].blockc - 1, lba, len);
|
||||
return -1;
|
||||
}
|
||||
switch (disks.v[sess->d].type) {
|
||||
case ISCSI_FS:
|
||||
RETURN_GREATER("num_bytes (FIX ME)", (unsigned) num_bytes, MB(1), NO_CLEANUP, -1);
|
||||
ptr = disks.v[sess->d].buffer[lun];
|
||||
n = 0;
|
||||
do {
|
||||
if (de_lseek(&disks.v[sess->d].tv->v[lun].de, (off_t)(n + byte_offset), SEEK_SET) == -1) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "lseek() failed\n");
|
||||
return -1;
|
||||
}
|
||||
rc = de_read(&disks.v[sess->d].tv->v[lun].de, ptr + n, (size_t)(num_bytes - n));
|
||||
if (rc <= 0) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "read() failed: rc %d errno %d\n", rc, errno);
|
||||
return -1;
|
||||
}
|
||||
n += rc;
|
||||
if (n < num_bytes) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "Got partial file read: %d bytes of %" PRIu64 "\n", rc, num_bytes - n + rc);
|
||||
}
|
||||
} while (n < num_bytes);
|
||||
break;
|
||||
case ISCSI_FS_MMAP:
|
||||
if (last_ptr[lun]) {
|
||||
if (de_munmap(&disks.v[sess->d].tv->v[lun].de, last_ptr[lun], (unsigned)(last_extra[lun] + last_num_bytes[lun])) != 0) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "munmap() failed\n");
|
||||
return -1;
|
||||
}
|
||||
last_ptr[lun] = NULL;
|
||||
last_num_bytes[lun] = 0;
|
||||
last_extra[lun] = 0;
|
||||
}
|
||||
extra = byte_offset % 4096;
|
||||
if ((ptr = de_mmap(0, (size_t)(num_bytes + extra), PROT_READ, MAP_SHARED, &disks.v[sess->d].tv->v[lun].de, (off_t)(byte_offset - extra))) == NULL) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "mmap() failed\n");
|
||||
RETURN_GREATER("num_bytes (FIX ME)", (unsigned) num_bytes, MB(1), NO_CLEANUP, -1);
|
||||
ptr = disks.v[sess->d].buffer[lun];
|
||||
n = 0;
|
||||
do {
|
||||
if (de_lseek(&disks.v[sess->d].tv->v[lun].de, (off_t)(n + byte_offset), SEEK_SET) == -1) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "lseek() failed\n");
|
||||
return -1;
|
||||
}
|
||||
/* Need to replace this with a callback */
|
||||
|
||||
last_ptr[lun] = ptr;
|
||||
last_num_bytes[lun] = num_bytes;
|
||||
last_extra[lun] = extra;
|
||||
break;
|
||||
}
|
||||
|
||||
rc = de_read(&disks.v[sess->d].tv->v[lun].de, ptr + n, (size_t)(num_bytes - n));
|
||||
if (rc <= 0) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "read() failed: rc %d errno %d\n", rc, errno);
|
||||
return -1;
|
||||
}
|
||||
n += rc;
|
||||
if (n < num_bytes) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "Got partial file read: %d bytes of %" PRIu64 "\n", rc, num_bytes - n + rc);
|
||||
}
|
||||
} while (n < num_bytes);
|
||||
|
||||
((struct iovec *) (void *)args->send_data)[0].iov_base = ptr + (unsigned) extra;
|
||||
((struct iovec *) (void *)args->send_data)[0].iov_len = (unsigned) num_bytes;
|
||||
|
|
|
@ -1,243 +0,0 @@
|
|||
/*
|
||||
* This code implements the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
* This code is in the public domain; do with it what you wish.
|
||||
*
|
||||
* Equivalent code is available from RSA Data Security, Inc.
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*
|
||||
* To compute the message digest of a chunk of bytes, declare an
|
||||
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||
* needed on buffers full of bytes, and then call MD5Final, which
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*
|
||||
* Changed so as no longer to depend on Colin Plumb's `usual.h' header
|
||||
* definitions; now uses stuff from dpkg's config.h.
|
||||
* - Ian Jackson <ijackson@nyx.cs.du.edu>.
|
||||
* Still in the public domain.
|
||||
*/
|
||||
#ifndef __KERNEL__
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
static void
|
||||
byteSwap(UWORD32 *buf, uint32_t words)
|
||||
{
|
||||
md5byte *p = (md5byte *)buf;
|
||||
int indian = 1;
|
||||
|
||||
if (*(char *) (void *) &indian) {
|
||||
/* little endian */
|
||||
/* nothing needed */
|
||||
} else {
|
||||
do {
|
||||
*buf++ = (UWORD32)((uint32_t)p[3] << 8 | p[2]) << 16 |
|
||||
((uint32_t)p[1] << 8 | p[0]);
|
||||
p += 4;
|
||||
} while (--words);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||
* initialization constants.
|
||||
*/
|
||||
void
|
||||
MD5Init(struct MD5Context *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
|
||||
ctx->bytes[0] = 0;
|
||||
ctx->bytes[1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update context to reflect the concatenation of another buffer full
|
||||
* of bytes.
|
||||
*/
|
||||
void
|
||||
MD5Update(struct MD5Context *ctx, void const *vbuf, uint32_t len)
|
||||
{
|
||||
md5byte const *buf = vbuf;
|
||||
UWORD32 t;
|
||||
|
||||
/* Update byte count */
|
||||
|
||||
t = ctx->bytes[0];
|
||||
if ((ctx->bytes[0] = t + len) < t)
|
||||
ctx->bytes[1]++; /* Carry from low to high */
|
||||
|
||||
t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
|
||||
if (t > len) {
|
||||
memcpy((md5byte *)ctx->in + 64 - t, buf, len);
|
||||
return;
|
||||
}
|
||||
/* First chunk is an odd size */
|
||||
memcpy((md5byte *)ctx->in + 64 - t, buf, t);
|
||||
byteSwap(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
|
||||
/* Process data in 64-byte chunks */
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteSwap(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
* 1 0* (64-bit count of bits processed, MSB-first)
|
||||
*/
|
||||
void
|
||||
MD5Final(md5byte digest[16], struct MD5Context *ctx)
|
||||
{
|
||||
int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
|
||||
md5byte *p = (md5byte *)ctx->in + count;
|
||||
|
||||
/* Set the first char of padding to 0x80. There is always room. */
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 56 bytes (-8..55) */
|
||||
count = 56 - 1 - count;
|
||||
|
||||
if (count < 0) { /* Padding forces an extra block */
|
||||
memset(p, 0, count + 8);
|
||||
byteSwap(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
p = (md5byte *)ctx->in;
|
||||
count = 56;
|
||||
}
|
||||
memset(p, 0, count);
|
||||
byteSwap(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
ctx->in[14] = ctx->bytes[0] << 3;
|
||||
ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
|
||||
byteSwap(ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
#ifndef ASM_MD5
|
||||
|
||||
/* The four core functions - F1 is optimized somewhat */
|
||||
|
||||
/* #define F1(x, y, z) (x & y | ~x & z) */
|
||||
#define F1(x, y, z) (z ^ (x & (y ^ z)))
|
||||
#define F2(x, y, z) F1(z, x, y)
|
||||
#define F3(x, y, z) (x ^ y ^ z)
|
||||
#define F4(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
/* This is the central step in the MD5 algorithm. */
|
||||
#define MD5STEP(f,w,x,y,z,in,s) \
|
||||
(w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
|
||||
|
||||
/*
|
||||
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
||||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
void
|
||||
MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
|
||||
{
|
||||
register UWORD32 a, b, c, d;
|
||||
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,368 @@
|
|||
/* $NetBSD: md5c.c,v 1.1 2007/12/09 09:21:06 agc Exp $ */
|
||||
|
||||
/*
|
||||
* This file is derived from the RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm and has been modifed by Jason R. Thorpe <thorpej@NetBSD.ORG>
|
||||
* for portability and formatting.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
* rights reserved.
|
||||
*
|
||||
* License to copy and use this software is granted provided that it
|
||||
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm" in all material mentioning or referencing this software
|
||||
* or this function.
|
||||
*
|
||||
* License is also granted to make and use derivative works provided
|
||||
* that such works are identified as "derived from the RSA Data
|
||||
* Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
* mentioning or referencing the derived work.
|
||||
*
|
||||
* RSA Data Security, Inc. makes no representations concerning either
|
||||
* the merchantability of this software or the suitability of this
|
||||
* software for any particular purpose. It is provided "as is"
|
||||
* without express or implied warranty of any kind.
|
||||
*
|
||||
* These notices must be retained in any copies of any part of this
|
||||
* documentation and/or software.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
#include <lib/libkern/libkern.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/md5.h>
|
||||
#define _DIAGASSERT(x) (void)0
|
||||
#else
|
||||
/* #include "namespace.h" */
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "iscsi-md5.h"
|
||||
#endif /* _KERNEL || _STANDALONE */
|
||||
|
||||
#if defined(HAVE_MEMSET)
|
||||
#define ZEROIZE(d, l) memset((d), 0, (l))
|
||||
#else
|
||||
# if defined(HAVE_BZERO)
|
||||
#define ZEROIZE(d, l) bzero((d), (l))
|
||||
# else
|
||||
#error You need either memset or bzero
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char *POINTER;
|
||||
typedef uint16_t UINT2;
|
||||
typedef uint32_t UINT4;
|
||||
|
||||
/*
|
||||
* Constants for MD5Transform routine.
|
||||
*/
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
#if 0
|
||||
#if !defined(_KERNEL) && !defined(_STANDALONE) && defined(__weak_alias)
|
||||
__weak_alias(iSCSI_MD5Init,_MD5Init)
|
||||
__weak_alias(iSCSI_MD5Update,_MD5Update)
|
||||
__weak_alias(iSCSI_MD5Final,_MD5Final)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _DIAGASSERT
|
||||
#define _DIAGASSERT(cond) assert(cond)
|
||||
#endif
|
||||
|
||||
static void iSCSI_MD5Transform(UINT4 [4], const unsigned char [64]);
|
||||
|
||||
static void Encode(unsigned char *, UINT4 *, unsigned int);
|
||||
static void Decode(UINT4 *, const unsigned char *, unsigned int);
|
||||
|
||||
/*
|
||||
* Encodes input (UINT4) into output (unsigned char). Assumes len is
|
||||
* a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
Encode (output, input, len)
|
||||
unsigned char *output;
|
||||
UINT4 *input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (unsigned char)(input[i] & 0xff);
|
||||
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Decodes input (unsigned char) into output (UINT4). Assumes len is
|
||||
* a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
Decode (output, input, len)
|
||||
UINT4 *output;
|
||||
const unsigned char *input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
|
||||
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
static const unsigned char PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* F, G, H and I are basic MD5 functions.
|
||||
*/
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/*
|
||||
* ROTATE_LEFT rotates x left n bits.
|
||||
*/
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/*
|
||||
* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
* Rotation is separate from addition to prevent recomputation.
|
||||
*/
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 initialization. Begins an MD5 operation, writing a new context.
|
||||
*/
|
||||
void
|
||||
iSCSI_MD5Init(iSCSI_MD5_CTX *context)
|
||||
{
|
||||
|
||||
_DIAGASSERT(context != 0);
|
||||
|
||||
context->count[0] = context->count[1] = 0;
|
||||
|
||||
/* Load magic initialization constants. */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 block update operation. Continues an MD5 message-digest
|
||||
* operation, processing another message block, and updating the
|
||||
* context.
|
||||
*/
|
||||
void
|
||||
iSCSI_MD5Update(iSCSI_MD5_CTX *context, const uint8_t *input, size_t inputLen)
|
||||
{
|
||||
unsigned int i, idx, partLen;
|
||||
|
||||
_DIAGASSERT(context != 0);
|
||||
_DIAGASSERT(input != 0);
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((UINT4)inputLen << 3))
|
||||
< ((UINT4)inputLen << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += ((UINT4)inputLen >> 29);
|
||||
|
||||
partLen = 64 - idx;
|
||||
|
||||
/* Transform as many times as possible. */
|
||||
if (inputLen >= partLen) {
|
||||
/* LINTED const castaway ok */
|
||||
memcpy((POINTER)&context->buffer[idx],
|
||||
input, partLen);
|
||||
iSCSI_MD5Transform(context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
iSCSI_MD5Transform(context->state, &input[i]);
|
||||
|
||||
idx = 0;
|
||||
} else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
/* LINTED const castaway ok */
|
||||
memcpy((POINTER)&context->buffer[idx], &input[i],
|
||||
inputLen - i);
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 finalization. Ends an MD5 message-digest operation, writing the
|
||||
* message digest and zeroing the context.
|
||||
*/
|
||||
void
|
||||
iSCSI_MD5Final(unsigned char digest[16], iSCSI_MD5_CTX *context)
|
||||
{
|
||||
unsigned char bits[8];
|
||||
unsigned int idx;
|
||||
size_t padLen;
|
||||
|
||||
_DIAGASSERT(digest != 0);
|
||||
_DIAGASSERT(context != 0);
|
||||
|
||||
/* Save number of bits */
|
||||
Encode(bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64. */
|
||||
idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (idx < 56) ? (56 - idx) : (120 - idx);
|
||||
iSCSI_MD5Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
iSCSI_MD5Update(context, bits, 8);
|
||||
|
||||
/* Store state in digest */
|
||||
Encode(digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
ZEROIZE((POINTER)(void *)context, sizeof(*context));
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 basic transformation. Transforms state based on block.
|
||||
*/
|
||||
static void
|
||||
iSCSI_MD5Transform(state, block)
|
||||
UINT4 state[4];
|
||||
const unsigned char block[64];
|
||||
{
|
||||
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode(x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
ZEROIZE((POINTER)(void *)x, sizeof (x));
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/* $NetBSD: md5hl.c,v 1.1 2007/12/09 09:21:06 agc Exp $ */
|
||||
|
||||
/*
|
||||
* Written by Jason R. Thorpe <thorpej@netbsd.org>, April 29, 1997.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#define MDALGORITHM iSCSI_MD5
|
||||
|
||||
/* #include "namespace.h" */
|
||||
#include "iscsi-md5.h"
|
||||
|
||||
#ifndef _DIAGASSERT
|
||||
#define _DIAGASSERT(cond) assert(cond)
|
||||
#endif
|
||||
|
||||
/* $NetBSD: md5hl.c,v 1.1 2007/12/09 09:21:06 agc Exp $ */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* from FreeBSD Id: mdXhl.c,v 1.8 1996/10/25 06:48:12 bde Exp
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modifed April 29, 1997 by Jason R. Thorpe <thorpej@netbsd.org>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define CONCAT(x,y) __CONCAT(x,y)
|
||||
#define MDNAME(x) CONCAT(MDALGORITHM,x)
|
||||
|
||||
char *
|
||||
MDNAME(End)(MDNAME(_CTX) *ctx, char *buf)
|
||||
{
|
||||
int i;
|
||||
unsigned char digest[16];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
_DIAGASSERT(ctx != 0);
|
||||
|
||||
if (buf == NULL)
|
||||
buf = malloc(33);
|
||||
if (buf == NULL)
|
||||
return (NULL);
|
||||
|
||||
MDNAME(Final)(digest, ctx);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
buf[i+i] = hex[(uint32_t)digest[i] >> 4];
|
||||
buf[i+i+1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
|
||||
buf[i+i] = '\0';
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
MDNAME(File)(filename, buf)
|
||||
const char *filename;
|
||||
char *buf;
|
||||
{
|
||||
unsigned char buffer[BUFSIZ];
|
||||
MDNAME(_CTX) ctx;
|
||||
int f, j;
|
||||
size_t i;
|
||||
|
||||
_DIAGASSERT(filename != 0);
|
||||
/* buf may be NULL */
|
||||
|
||||
MDNAME(Init)(&ctx);
|
||||
f = open(filename, O_RDONLY, 0666);
|
||||
if (f < 0)
|
||||
return NULL;
|
||||
|
||||
while ((i = read(f, buffer, sizeof(buffer))) > 0)
|
||||
MDNAME(Update)(&ctx, buffer, (size_t)i);
|
||||
|
||||
j = errno;
|
||||
close(f);
|
||||
errno = j;
|
||||
|
||||
#if 0
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
return (MDNAME(End)(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
MDNAME(Data)(const uint8_t *data, size_t len, char *buf)
|
||||
{
|
||||
MDNAME(_CTX) ctx;
|
||||
|
||||
_DIAGASSERT(data != 0);
|
||||
|
||||
MDNAME(Init)(&ctx);
|
||||
MDNAME(Update)(&ctx, data, len);
|
||||
return (MDNAME(End)(&ctx, buf));
|
||||
}
|
|
@ -47,10 +47,10 @@
|
|||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "iscsi-md5.h"
|
||||
#include "iscsiutil.h"
|
||||
#include "parameters.h"
|
||||
#include "conffile.h"
|
||||
#include "md5.c"
|
||||
|
||||
|
||||
int
|
||||
|
@ -458,7 +458,7 @@ param_parse_security(iscsi_parameter_t * head,
|
|||
static uint8_t chapdata[ISCSI_CHAP_DATA_LENGTH];
|
||||
static uint8_t respdata[ISCSI_CHAP_DATA_LENGTH];
|
||||
char *chapstring = NULL;
|
||||
MD5Context_t *context = NULL;
|
||||
iSCSI_MD5_CTX *context = NULL;
|
||||
iscsi_parameter_t *param = NULL;
|
||||
int ret = 1;
|
||||
|
||||
|
@ -466,7 +466,7 @@ param_parse_security(iscsi_parameter_t * head,
|
|||
iscsi_trace_error(__FILE__, __LINE__, "iscsi_malloc() failed\n");
|
||||
return -1;
|
||||
}
|
||||
if ((context = iscsi_malloc(sizeof(MD5Context_t))) == NULL) {
|
||||
if ((context = iscsi_malloc(sizeof(*context))) == NULL) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "iscsi_malloc() failed\n");
|
||||
if (chapstring != NULL)
|
||||
iscsi_free(chapstring);
|
||||
|
@ -561,20 +561,20 @@ param_parse_security(iscsi_parameter_t * head,
|
|||
}
|
||||
param->tx_offer = 1; /* sending an offer */
|
||||
param->rx_offer = 0; /* reset */
|
||||
MD5Init(context);
|
||||
MD5Update(context, &idData, 1);
|
||||
iSCSI_MD5Init(context);
|
||||
iSCSI_MD5Update(context, &idData, 1);
|
||||
|
||||
if (cred->shared_secret == NULL) {
|
||||
iscsi_trace_error(__FILE__, __LINE__, "null shared secret\n");
|
||||
PPS_ERROR;
|
||||
} else {
|
||||
MD5Update(context, cred->shared_secret, strlen(cred->shared_secret));
|
||||
iSCSI_MD5Update(context, (const uint8_t *)cred->shared_secret, strlen(cred->shared_secret));
|
||||
}
|
||||
|
||||
HexDataToText(chapdata, ISCSI_CHAP_DATA_LENGTH,
|
||||
param->offer_tx, ISCSI_CHAP_STRING_LENGTH);
|
||||
MD5Update(context, chapdata, ISCSI_CHAP_DATA_LENGTH);
|
||||
MD5Final(chapdata, context);
|
||||
iSCSI_MD5Update(context, chapdata, ISCSI_CHAP_DATA_LENGTH);
|
||||
iSCSI_MD5Final(chapdata, context);
|
||||
HexDataToText(chapdata, ISCSI_CHAP_DATA_LENGTH,
|
||||
param->offer_tx, ISCSI_CHAP_STRING_LENGTH);
|
||||
|
||||
|
@ -620,9 +620,9 @@ param_parse_security(iscsi_parameter_t * head,
|
|||
|
||||
} else if (strcmp(param_in->key, "CHAP_R") == 0) {
|
||||
|
||||
MD5Init(context);
|
||||
iSCSI_MD5Init(context);
|
||||
|
||||
MD5Update(context, &idData, 1);
|
||||
iSCSI_MD5Update(context, &idData, 1);
|
||||
|
||||
HexDataToText(&idData, 1, param_in->offer_tx, ISCSI_CHAP_STRING_LENGTH);
|
||||
HexDataToText(chapdata, ISCSI_CHAP_DATA_LENGTH,
|
||||
|
@ -632,11 +632,11 @@ param_parse_security(iscsi_parameter_t * head,
|
|||
iscsi_trace_error(__FILE__, __LINE__, "Null shared secret in initiator\n");
|
||||
PPS_ERROR;
|
||||
} else {
|
||||
MD5Update(context, cred->shared_secret, strlen(cred->shared_secret));
|
||||
iSCSI_MD5Update(context, (const uint8_t *)cred->shared_secret, strlen(cred->shared_secret));
|
||||
}
|
||||
|
||||
MD5Update(context, chapdata, ISCSI_CHAP_DATA_LENGTH);
|
||||
MD5Final(chapdata, context);
|
||||
iSCSI_MD5Update(context, chapdata, ISCSI_CHAP_DATA_LENGTH);
|
||||
iSCSI_MD5Final(chapdata, context);
|
||||
|
||||
HexTextToData((param_in->rx_offer) ? param_in->offer_rx : param_in->answer_rx, ISCSI_CHAP_STRING_LENGTH,
|
||||
respdata, ISCSI_CHAP_DATA_LENGTH);
|
||||
|
|
Loading…
Reference in New Issue