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 "spdk/md5.h" 9 : : #include "spdk/likely.h" 10 : : 11 : : int 12 : 179 : spdk_md5init(struct spdk_md5ctx *md5ctx) 13 : : { 14 : : int rc; 15 : : 16 [ - + ]: 179 : if (spdk_unlikely(md5ctx == NULL)) { 17 : 0 : return -1; 18 : : } 19 : : 20 [ # # # # ]: 179 : md5ctx->md5ctx = EVP_MD_CTX_create(); 21 [ - + # # : 179 : if (spdk_unlikely(md5ctx->md5ctx == NULL)) { # # ] 22 : 0 : return -1; 23 : : } 24 : : 25 [ # # # # ]: 179 : rc = EVP_DigestInit_ex(md5ctx->md5ctx, EVP_md5(), NULL); 26 : : /* For EVP_DigestInit_ex, 1 == success, 0 == failure. */ 27 [ - + ]: 179 : if (spdk_unlikely(rc == 0)) { 28 [ # # # # ]: 0 : EVP_MD_CTX_destroy(md5ctx->md5ctx); 29 [ # # # # ]: 0 : md5ctx->md5ctx = NULL; 30 : 0 : rc = -1; 31 : 0 : } 32 : 179 : return rc; 33 : 0 : } 34 : : 35 : : int 36 : 179 : spdk_md5final(void *md5, struct spdk_md5ctx *md5ctx) 37 : : { 38 : : int rc; 39 : : 40 [ + - - + ]: 179 : if (spdk_unlikely(md5ctx == NULL || md5 == NULL)) { 41 : 0 : return -1; 42 : : } 43 [ # # # # ]: 179 : rc = EVP_DigestFinal_ex(md5ctx->md5ctx, md5, NULL); 44 [ # # # # ]: 179 : EVP_MD_CTX_destroy(md5ctx->md5ctx); 45 [ # # # # ]: 179 : md5ctx->md5ctx = NULL; 46 : 179 : return rc; 47 : 0 : } 48 : : 49 : : int 50 : 537 : spdk_md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len) 51 : : { 52 : : int rc; 53 : : 54 [ - + ]: 537 : if (spdk_unlikely(md5ctx == NULL)) { 55 : 0 : return -1; 56 : : } 57 [ + - - + ]: 537 : if (spdk_unlikely(data == NULL || len == 0)) { 58 : 0 : return 0; 59 : : } 60 [ # # # # ]: 537 : rc = EVP_DigestUpdate(md5ctx->md5ctx, data, len); 61 : 537 : return rc; 62 : 0 : }