Spdk/lib/iscsi/md5.c
Ben Walker 8dd1cd2104 check_format: For C files only, fix return type breaks
In SPDK, declarations have the return type on the same line. Definitions
have the return type on a separate line. Astyle has an option for
enforcing this. Unfortunately, it seems to have two bugs:

1) It doesn't work correctly at all on C++ files.
2) It often fails on functions that return enums, or long type names

Deal with 1) by adjusting the check_format.sh script to only tell astyle
to fix return type line breaks for C files and not C++. Deal with 2) by
adding a few typedefs to work around the problem.

Change-Id: Idf28281466cab8411ce252d5f02ab384166790c6
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13437
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
2022-06-27 09:33:48 +00:00

61 lines
1.1 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk/stdinc.h"
#include "iscsi/md5.h"
int
md5init(struct spdk_md5ctx *md5ctx)
{
int rc;
if (md5ctx == NULL) {
return -1;
}
md5ctx->md5ctx = EVP_MD_CTX_create();
if (md5ctx->md5ctx == NULL) {
return -1;
}
rc = EVP_DigestInit_ex(md5ctx->md5ctx, EVP_md5(), NULL);
/* For EVP_DigestInit_ex, 1 == success, 0 == failure. */
if (rc == 0) {
EVP_MD_CTX_destroy(md5ctx->md5ctx);
md5ctx->md5ctx = NULL;
}
return rc;
}
int
md5final(void *md5, struct spdk_md5ctx *md5ctx)
{
int rc;
if (md5ctx == NULL || md5 == NULL) {
return -1;
}
rc = EVP_DigestFinal_ex(md5ctx->md5ctx, md5, NULL);
EVP_MD_CTX_destroy(md5ctx->md5ctx);
md5ctx->md5ctx = NULL;
return rc;
}
int
md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len)
{
int rc;
if (md5ctx == NULL) {
return -1;
}
if (data == NULL || len == 0) {
return 0;
}
rc = EVP_DigestUpdate(md5ctx->md5ctx, data, len);
return rc;
}