1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Single API to access different integrity checks
6 // This code has been put into the public domain.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 ///////////////////////////////////////////////////////////////////////////////
17 extern LZMA_API(lzma_bool)
18 lzma_check_is_supported(lzma_check type)
20 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
23 static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
24 true, // LZMA_CHECK_NONE
26 #ifdef HAVE_CHECK_CRC32
35 #ifdef HAVE_CHECK_CRC64
47 #ifdef HAVE_CHECK_SHA256
60 return available_checks[(unsigned int)(type)];
64 extern LZMA_API(uint32_t)
65 lzma_check_size(lzma_check type)
67 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
70 // See file-format.txt section 2.1.1.2.
71 static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
80 return check_sizes[(unsigned int)(type)];
85 lzma_check_init(lzma_check_state *check, lzma_check type)
91 #ifdef HAVE_CHECK_CRC32
92 case LZMA_CHECK_CRC32:
93 check->state.crc32 = 0;
97 #ifdef HAVE_CHECK_CRC64
98 case LZMA_CHECK_CRC64:
99 check->state.crc64 = 0;
103 #ifdef HAVE_CHECK_SHA256
104 case LZMA_CHECK_SHA256:
105 lzma_sha256_init(check);
118 lzma_check_update(lzma_check_state *check, lzma_check type,
119 const uint8_t *buf, size_t size)
122 #ifdef HAVE_CHECK_CRC32
123 case LZMA_CHECK_CRC32:
124 check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
128 #ifdef HAVE_CHECK_CRC64
129 case LZMA_CHECK_CRC64:
130 check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
134 #ifdef HAVE_CHECK_SHA256
135 case LZMA_CHECK_SHA256:
136 lzma_sha256_update(buf, size, check);
149 lzma_check_finish(lzma_check_state *check, lzma_check type)
152 #ifdef HAVE_CHECK_CRC32
153 case LZMA_CHECK_CRC32:
154 check->buffer.u32[0] = integer_le_32(check->state.crc32);
158 #ifdef HAVE_CHECK_CRC64
159 case LZMA_CHECK_CRC64:
160 check->buffer.u64[0] = integer_le_64(check->state.crc64);
164 #ifdef HAVE_CHECK_SHA256
165 case LZMA_CHECK_SHA256:
166 lzma_sha256_finish(check);