2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2016-08-02 16:34:45 +00:00
|
|
|
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2016 Intel Corporation.
|
2016-08-02 16:34:45 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-08-02 16:34:45 +00:00
|
|
|
#include "iscsi/md5.h"
|
|
|
|
|
2022-06-22 21:35:04 +00:00
|
|
|
int
|
|
|
|
md5init(struct spdk_md5ctx *md5ctx)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (md5ctx == NULL) {
|
2016-08-02 16:34:45 +00:00
|
|
|
return -1;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2022-04-09 11:22:59 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:35:04 +00:00
|
|
|
int
|
|
|
|
md5final(void *md5, struct spdk_md5ctx *md5ctx)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (md5ctx == NULL || md5 == NULL) {
|
2016-08-02 16:34:45 +00:00
|
|
|
return -1;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2022-04-09 11:22:59 +00:00
|
|
|
rc = EVP_DigestFinal_ex(md5ctx->md5ctx, md5, NULL);
|
|
|
|
EVP_MD_CTX_destroy(md5ctx->md5ctx);
|
|
|
|
md5ctx->md5ctx = NULL;
|
2016-08-02 16:34:45 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:35:04 +00:00
|
|
|
int
|
|
|
|
md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (md5ctx == NULL) {
|
2016-08-02 16:34:45 +00:00
|
|
|
return -1;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
|
|
|
if (data == NULL || len == 0) {
|
2016-08-02 16:34:45 +00:00
|
|
|
return 0;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2022-04-09 11:22:59 +00:00
|
|
|
rc = EVP_DigestUpdate(md5ctx->md5ctx, data, len);
|
2016-08-02 16:34:45 +00:00
|
|
|
return rc;
|
|
|
|
}
|