Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. 3 : : * Copyright (C) 2016 Intel Corporation. 4 : : * All rights reserved. 5 : : */ 6 : : 7 : : #include "spdk/stdinc.h" 8 : : #include "iscsi/md5.h" 9 : : 10 : : int 11 : 344 : md5init(struct spdk_md5ctx *md5ctx) 12 : : { 13 : : int rc; 14 : : 15 [ - + ]: 344 : if (md5ctx == NULL) { 16 : 0 : return -1; 17 : : } 18 : : 19 : 344 : md5ctx->md5ctx = EVP_MD_CTX_create(); 20 [ - + ]: 344 : if (md5ctx->md5ctx == NULL) { 21 : 0 : return -1; 22 : : } 23 : : 24 : 344 : rc = EVP_DigestInit_ex(md5ctx->md5ctx, EVP_md5(), NULL); 25 : : /* For EVP_DigestInit_ex, 1 == success, 0 == failure. */ 26 [ - + ]: 344 : if (rc == 0) { 27 : 0 : EVP_MD_CTX_destroy(md5ctx->md5ctx); 28 : 0 : md5ctx->md5ctx = NULL; 29 : : } 30 : 344 : return rc; 31 : : } 32 : : 33 : : int 34 : 344 : md5final(void *md5, struct spdk_md5ctx *md5ctx) 35 : : { 36 : : int rc; 37 : : 38 [ + - - + ]: 344 : if (md5ctx == NULL || md5 == NULL) { 39 : 0 : return -1; 40 : : } 41 : 344 : rc = EVP_DigestFinal_ex(md5ctx->md5ctx, md5, NULL); 42 : 344 : EVP_MD_CTX_destroy(md5ctx->md5ctx); 43 : 344 : md5ctx->md5ctx = NULL; 44 : 344 : return rc; 45 : : } 46 : : 47 : : int 48 : 1032 : md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len) 49 : : { 50 : : int rc; 51 : : 52 [ - + ]: 1032 : if (md5ctx == NULL) { 53 : 0 : return -1; 54 : : } 55 [ + - - + ]: 1032 : if (data == NULL || len == 0) { 56 : 0 : return 0; 57 : : } 58 : 1032 : rc = EVP_DigestUpdate(md5ctx->md5ctx, data, len); 59 : 1032 : return rc; 60 : : }