Commit 53be3bd8 authored by Alexey Marchuk's avatar Alexey Marchuk Committed by Konrad Sztyber
Browse files

lib/util: Make md5 API public



Make md5 realted functions in iscsi lib public.
Interface remained unchaged except of spdk_ prefix
added to func names. Implementation slightly updated
with unlikely() hints.

Signed-off-by: default avatarAlexey Marchuk <alexeymar@nvidia.com>
Change-Id: I8bff008aad0c44b639b9249e1b48f3a6f9421f74
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23133


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
parent 15e9c8ba
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -31,12 +31,6 @@ Support implemented only for the POSIX and SSL sockets.
New function `spdk_interrupt_register_for_events()` build on top of `spdk_fd_group_add_for_events()`.
See below for details.

### util

New function `spdk_fd_group_add_for_events()` was added alongside the existing `spdk_fd_group_add()`.
Difference is that new API allows for specifying a set of events to be monitored instead of default
SPDK_INTERRUPT_EVENT_IN.

### env

Added `spdk_env_core_get_smt_cpuset()` API to get the list of SMT sibling
@@ -73,6 +67,14 @@ of the Protection Information Format in the NVMe specification. This is necessar
but breaks ABI compatibility. Please recompile your application if you added code using
this enum of older SPDK.

### util

New function `spdk_fd_group_add_for_events()` was added alongside the existing `spdk_fd_group_add()`.
Difference is that new API allows for specifying a set of events to be monitored instead of default
SPDK_INTERRUPT_EVENT_IN.

Added API to calculate md5 hash.

## v24.05

### accel

include/spdk/md5.h

0 → 100644
+62 −0
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
 *   Copyright (C) 2016 Intel Corporation.
 *   Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
 *   All rights reserved.
 */

#ifndef SPDK_MD5_H
#define SPDK_MD5_H

#include "spdk/stdinc.h"

#include <openssl/md5.h>
#include <openssl/evp.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SPDK_MD5DIGEST_LEN MD5_DIGEST_LENGTH

struct spdk_md5ctx {
	EVP_MD_CTX *md5ctx;
};

/**
 * Init md5 context
 *
 * \param md5ctx context
 * \return 0 on success, -1 on failure
 */
int spdk_md5init(struct spdk_md5ctx *md5ctx);

/**
 * Update \b md5ctx digest with hash of \b len bytes of \b data.
 *
 * This function can be called several times on the same md5ctx to hash additional data
 *
 * \param md5ctx context
 * \param data data pointer
 * \param len length of data buffer in bytes
 * \return 0 on success, -1 on failure
 */
int spdk_md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len);

/**
 * Retrieves the digest from \b ctx and places it in \b md5 buffer.
 *
 * \b md5 buffer must be \b SPDK_MD5DIGEST_LEN bytes length. \b md5ctx is released, it can be used again after
 * initialization via \ref spdk_md5init
 *
 * \param md5
 * \param md5ctx
 * \return 0 on success, -1 on failure
 */
int spdk_md5final(void *md5, struct spdk_md5ctx *md5ctx);

#ifdef __cplusplus
}
#endif

#endif /* SPDK_MD5_H */
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ SO_MINOR := 0

CFLAGS += -I$(SPDK_ROOT_DIR)/lib
C_SRCS = conn.c \
	 init_grp.c iscsi.c md5.c param.c portal_grp.c \
	 init_grp.c iscsi.c param.c portal_grp.c \
	 tgt_node.c iscsi_subsystem.c \
	 iscsi_rpc.c task.c
LIBNAME = iscsi
+15 −15
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
#include "spdk/sock.h"
#include "spdk/string.h"
#include "spdk/queue.h"
#include "spdk/md5.h"

#include "iscsi/md5.h"
#include "iscsi/iscsi.h"
#include "iscsi/param.h"
#include "iscsi/tgt_node.h"
@@ -904,17 +904,17 @@ iscsi_auth_params(struct spdk_iscsi_conn *conn,
			goto error_return;
		}

		md5init(&md5ctx);
		spdk_md5init(&md5ctx);
		/* Identifier */
		md5update(&md5ctx, conn->auth.chap_id, 1);
		spdk_md5update(&md5ctx, conn->auth.chap_id, 1);
		/* followed by secret */
		md5update(&md5ctx, conn->auth.secret,
		spdk_md5update(&md5ctx, conn->auth.secret,
			       strlen(conn->auth.secret));
		/* followed by Challenge Value */
		md5update(&md5ctx, conn->auth.chap_challenge,
		spdk_md5update(&md5ctx, conn->auth.chap_challenge,
			       conn->auth.chap_challenge_len);
		/* tgtmd5 is expecting Response Value */
		md5final(tgtmd5, &md5ctx);
		spdk_md5final(tgtmd5, &md5ctx);

		bin2hex(in_val, ISCSI_TEXT_MAX_VAL_LEN, tgtmd5, SPDK_MD5DIGEST_LEN);

@@ -983,17 +983,17 @@ iscsi_auth_params(struct spdk_iscsi_conn *conn,
				goto error_return;
			}

			md5init(&md5ctx);
			spdk_md5init(&md5ctx);
			/* Identifier */
			md5update(&md5ctx, conn->auth.chap_mid, 1);
			spdk_md5update(&md5ctx, conn->auth.chap_mid, 1);
			/* followed by secret */
			md5update(&md5ctx, conn->auth.msecret,
			spdk_md5update(&md5ctx, conn->auth.msecret,
				       strlen(conn->auth.msecret));
			/* followed by Challenge Value */
			md5update(&md5ctx, conn->auth.chap_mchallenge,
			spdk_md5update(&md5ctx, conn->auth.chap_mchallenge,
				       conn->auth.chap_mchallenge_len);
			/* tgtmd5 is Response Value */
			md5final(tgtmd5, &md5ctx);
			spdk_md5final(tgtmd5, &md5ctx);

			bin2hex(in_val, ISCSI_TEXT_MAX_VAL_LEN, tgtmd5, SPDK_MD5DIGEST_LEN);

lib/iscsi/md5.h

deleted100644 → 0
+0 −25
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
 *   Copyright (C) 2016 Intel Corporation.
 *   All rights reserved.
 */

#ifndef SPDK_MD5_H
#define SPDK_MD5_H

#include "spdk/stdinc.h"

#include <openssl/md5.h>
#include <openssl/evp.h>

#define SPDK_MD5DIGEST_LEN MD5_DIGEST_LENGTH

struct spdk_md5ctx {
	EVP_MD_CTX *md5ctx;
};

int md5init(struct spdk_md5ctx *md5ctx);
int md5final(void *md5, struct spdk_md5ctx *md5ctx);
int md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len);

#endif /* SPDK_MD5_H */
Loading