Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libewf/libewf/libewf_checksum.c
Line
Count
Source
1
/*
2
 * Checksum functions
3
 *
4
 * Copyright (C) 2006-2026, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <byte_stream.h>
24
#include <types.h>
25
26
#if defined( HAVE_ZLIB ) || defined( ZLIB_DLL )
27
#include <zlib.h>
28
#endif
29
30
#include "libewf_checksum.h"
31
#include "libewf_libcerror.h"
32
#include "libewf_types.h"
33
34
#if defined( HAVE_ZLIB_ADLER32 ) && ( defined( HAVE_ZLIB ) || defined( ZLIB_DLL ) )
35
36
/* Calculates the little-endian Adler-32 of a buffer
37
 * It uses the initial value to calculate a new Adler-32
38
 * Returns 1 if successful or -1 on error
39
 */
40
int libewf_checksum_calculate_adler32(
41
     uint32_t *checksum_value,
42
     const uint8_t *buffer,
43
     size_t size,
44
     uint32_t initial_value,
45
     libcerror_error_t **error )
46
69.2k
{
47
69.2k
  static char *function = "libewf_checksum_calculate_adler32";
48
49
69.2k
  if( checksum_value == NULL )
50
0
  {
51
0
    libcerror_error_set(
52
0
     error,
53
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
54
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
55
0
     "%s: invalid checksum value.",
56
0
     function );
57
58
0
    return( -1 );
59
0
  }
60
69.2k
  if( buffer == NULL )
61
0
  {
62
0
    libcerror_error_set(
63
0
     error,
64
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
65
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
66
0
     "%s: invalid buffer.",
67
0
     function );
68
69
0
    return( -1 );
70
0
  }
71
69.2k
  if( ( size > (size_t) UINT_MAX )
72
69.2k
   || ( size > (size_t) SSIZE_MAX ) )
73
0
  {
74
0
    libcerror_error_set(
75
0
     error,
76
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
77
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
78
0
     "%s: invalid size value exceeds maximum.",
79
0
     function );
80
81
0
    return( -1 );
82
0
  }
83
69.2k
  *checksum_value = adler32(
84
69.2k
                     (uLong) initial_value,
85
69.2k
                     (const Bytef *) buffer,
86
69.2k
                     (uInt) size );
87
88
69.2k
  return( 1 );
89
69.2k
}
90
91
#endif /* defined( HAVE_ZLIB_ADLER32 ) && ( defined( HAVE_ZLIB ) || defined( ZLIB_DLL ) ) */
92