LCOV - code coverage report
Current view: top level - spdk/lib/util - md5.c (source / functions) Hit Total Coverage
Test: Combined Lines: 18 30 60.0 %
Date: 2024-11-20 17:25:31 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 52 15.4 %

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

Generated by: LCOV version 1.15