LCOV - code coverage report
Current view: top level - src - md5.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 19 22 86.4 %
Date: 2025-12-23 21:59:50 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "alloc.h"
       3             : #include "conf.h"
       4             : #include "log.h"
       5             : #include "md5.h"
       6             : 
       7             : #if OPENSSL_VERSION_NUMBER < 0x30000000L
       8             : 
       9             : struct md5 *md5_alloc(
      10             :         const char *func
      11             : ) {
      12             :         struct md5 *md5;
      13             :         if(!(md5=(struct md5 *)calloc_w(1, sizeof(struct md5), func)))
      14             :                 return NULL;
      15             :         if(!(md5->ctx=(MD5_CTX *)calloc_w(1, sizeof(MD5_CTX), func)))
      16             :                 md5_free(&md5);
      17             :         return md5;
      18             : }
      19             : 
      20             : void md5_free(
      21             :         struct md5 **md5
      22             : ) {
      23             :         if(!md5 || !*md5)
      24             :                 return;
      25             :         free_v((void **)&(*md5)->ctx);
      26             :         free_v((void **)md5);
      27             : }
      28             : 
      29             : int md5_init(
      30             :         struct md5 *md5
      31             : ) {
      32             :         return MD5_Init(md5->ctx);
      33             : }
      34             : 
      35             : int md5_update(
      36             :         struct md5 *md5,
      37             :         const void *data,
      38             :         unsigned long len
      39             : ) {
      40             :         return MD5_Update(md5->ctx, data, len);
      41             : }
      42             : 
      43             : int md5_final(
      44             :         struct md5 *md5,
      45             :         unsigned char *md
      46             : ) {
      47             :         return MD5_Final(md, md5->ctx);
      48             : }
      49             : 
      50             : #else
      51             : 
      52          47 : struct md5 *md5_alloc(
      53             :         const char *func
      54             : ) {
      55          47 :         struct md5 *md5;
      56          47 :         if(!(md5=(struct md5 *)calloc_w(1, sizeof(struct md5), func)))
      57             :                 return NULL;
      58          47 :         if((md5->ctx=EVP_MD_CTX_create()))
      59             :         {
      60             : #ifdef UTEST
      61          47 :                 alloc_count++;
      62             : #endif
      63          47 :                 return md5;
      64             :         }
      65           0 :         log_oom_w(__func__, func);
      66           0 :         md5_free(&md5);
      67           0 :         return NULL;
      68             : }
      69             : 
      70          47 : void md5_free(
      71             :         struct md5 **md5
      72             : ) {
      73          47 :         if(!md5 || !*md5)
      74             :                 return;
      75          47 :         if ((*md5)->ctx)
      76             :         {
      77          47 :                 EVP_MD_CTX_free((*md5)->ctx);
      78             : #ifdef UTEST
      79          47 :                 free_count++;
      80             : #endif
      81             :         }
      82          47 :         free_v((void **)md5);
      83          47 :         *md5=NULL;
      84             : }
      85             : 
      86          47 : int md5_init(
      87             :         struct md5 *md5
      88             : ) {
      89          47 :         return EVP_DigestInit_ex(md5->ctx, EVP_md5(), NULL);
      90             : }
      91             : 
      92          18 : int md5_update(
      93             :         struct md5 *md5,
      94             :         const void *data,
      95             :         unsigned long len
      96             : ) {
      97          18 :         return EVP_DigestUpdate(md5->ctx, data, len);
      98             : }
      99             : 
     100          24 : int md5_final(
     101             :         struct md5 *md5,
     102             :         unsigned char *md
     103             : ) {
     104          24 :         return EVP_DigestFinal_ex(md5->ctx, md, NULL);
     105             : }
     106             : 
     107             : #endif

Generated by: LCOV version 1.16