LCOV - code coverage report
Current view: top level - spdk/lib/iscsi - md5.c (source / functions) Hit Total Coverage
Test: Combined Lines: 18 25 72.0 %
Date: 2024-07-10 18:23:29 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 16 50.0 %

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

Generated by: LCOV version 1.14