1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Single API to access different integrity checks
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
16 extern LZMA_API(lzma_bool)
17 lzma_check_is_supported(lzma_check type)
19 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
22 static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
23 true, // LZMA_CHECK_NONE
25 #ifdef HAVE_CHECK_CRC32
34 #ifdef HAVE_CHECK_CRC64
46 #ifdef HAVE_CHECK_SHA256
59 return available_checks[(unsigned int)(type)];
63 extern LZMA_API(uint32_t)
64 lzma_check_size(lzma_check type)
66 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
69 // See file-format.txt section 2.1.1.2.
70 static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
79 return check_sizes[(unsigned int)(type)];
84 lzma_check_init(lzma_check_state *check, lzma_check type)
90 #ifdef HAVE_CHECK_CRC32
91 case LZMA_CHECK_CRC32:
92 check->state.crc32 = 0;
96 #ifdef HAVE_CHECK_CRC64
97 case LZMA_CHECK_CRC64:
98 check->state.crc64 = 0;
102 #ifdef HAVE_CHECK_SHA256
103 case LZMA_CHECK_SHA256:
104 lzma_sha256_init(check);
117 lzma_check_update(lzma_check_state *check, lzma_check type,
118 const uint8_t *buf, size_t size)
121 #ifdef HAVE_CHECK_CRC32
122 case LZMA_CHECK_CRC32:
123 check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
127 #ifdef HAVE_CHECK_CRC64
128 case LZMA_CHECK_CRC64:
129 check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
133 #ifdef HAVE_CHECK_SHA256
134 case LZMA_CHECK_SHA256:
135 lzma_sha256_update(buf, size, check);
148 lzma_check_finish(lzma_check_state *check, lzma_check type)
151 #ifdef HAVE_CHECK_CRC32
152 case LZMA_CHECK_CRC32:
153 check->buffer.u32[0] = conv32le(check->state.crc32);
157 #ifdef HAVE_CHECK_CRC64
158 case LZMA_CHECK_CRC64:
159 check->buffer.u64[0] = conv64le(check->state.crc64);
163 #ifdef HAVE_CHECK_SHA256
164 case LZMA_CHECK_SHA256:
165 lzma_sha256_finish(check);