1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
6 /// \brief Single API to access different integrity checks
8 // Author: Lasse Collin
10 ///////////////////////////////////////////////////////////////////////////////
15 extern LZMA_API(lzma_bool
)
16 lzma_check_is_supported(lzma_check type
)
18 if ((unsigned int)(type
) > LZMA_CHECK_ID_MAX
)
21 static const lzma_bool available_checks
[LZMA_CHECK_ID_MAX
+ 1] = {
22 true, // LZMA_CHECK_NONE
24 #ifdef HAVE_CHECK_CRC32
33 #ifdef HAVE_CHECK_CRC64
45 #ifdef HAVE_CHECK_SHA256
58 return available_checks
[(unsigned int)(type
)];
62 extern LZMA_API(uint32_t)
63 lzma_check_size(lzma_check type
)
65 if ((unsigned int)(type
) > LZMA_CHECK_ID_MAX
)
68 // See file-format.txt section 2.1.1.2.
69 static const uint8_t check_sizes
[LZMA_CHECK_ID_MAX
+ 1] = {
78 return check_sizes
[(unsigned int)(type
)];
83 lzma_check_init(lzma_check_state
*check
, lzma_check type
)
89 #ifdef HAVE_CHECK_CRC32
90 case LZMA_CHECK_CRC32
:
91 check
->state
.crc32
= 0;
95 #ifdef HAVE_CHECK_CRC64
96 case LZMA_CHECK_CRC64
:
97 check
->state
.crc64
= 0;
101 #ifdef HAVE_CHECK_SHA256
102 case LZMA_CHECK_SHA256
:
103 lzma_sha256_init(check
);
116 lzma_check_update(lzma_check_state
*check
, lzma_check type
,
117 const uint8_t *buf
, size_t size
)
120 #ifdef HAVE_CHECK_CRC32
121 case LZMA_CHECK_CRC32
:
122 check
->state
.crc32
= lzma_crc32(buf
, size
, check
->state
.crc32
);
126 #ifdef HAVE_CHECK_CRC64
127 case LZMA_CHECK_CRC64
:
128 check
->state
.crc64
= lzma_crc64(buf
, size
, check
->state
.crc64
);
132 #ifdef HAVE_CHECK_SHA256
133 case LZMA_CHECK_SHA256
:
134 lzma_sha256_update(buf
, size
, check
);
147 lzma_check_finish(lzma_check_state
*check
, lzma_check type
)
150 #ifdef HAVE_CHECK_CRC32
151 case LZMA_CHECK_CRC32
:
152 check
->buffer
.u32
[0] = conv32le(check
->state
.crc32
);
156 #ifdef HAVE_CHECK_CRC64
157 case LZMA_CHECK_CRC64
:
158 check
->buffer
.u64
[0] = conv64le(check
->state
.crc64
);
162 #ifdef HAVE_CHECK_SHA256
163 case LZMA_CHECK_SHA256
:
164 lzma_sha256_finish(check
);