3 * \brief Integrity checks
4 * \note Never include this file directly. Use <lzma.h> instead.
10 * This file has been put into the public domain.
11 * You can do whatever you want with this file.
14 #ifndef LZMA_H_INTERNAL
15 # error Never include this file directly. Use <lzma.h> instead.
20 * \brief Type of the integrity check (Check ID)
22 * The .xz format supports multiple types of checks that are calculated
23 * from the uncompressed data. They vary in both speed and ability to
29 * No Check is calculated.
31 * Size of the Check field: 0 bytes
36 * CRC32 using the polynomial from the IEEE 802.3 standard
38 * Size of the Check field: 4 bytes
43 * CRC64 using the polynomial from the ECMA-182 standard
45 * Size of the Check field: 8 bytes
48 LZMA_CHECK_SHA256
= 10
52 * Size of the Check field: 32 bytes
58 * \brief Maximum valid Check ID
60 * The .xz file format specification specifies 16 Check IDs (0-15). Some
61 * of them are only reserved, that is, no actual Check algorithm has been
62 * assigned. When decoding, liblzma still accepts unknown Check IDs for
63 * future compatibility. If a valid but unsupported Check ID is detected,
64 * liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK,
65 * LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h.
67 #define LZMA_CHECK_ID_MAX 15
71 * \brief Test if the given Check ID is supported
73 * LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always supported (even if
74 * liblzma is built with limited features).
76 * \note It is safe to call this with a value that is not in the
77 * range [0, 15]; in that case the return value is always false.
79 * \param check Check ID
82 * - true if Check ID is supported by this liblzma build.
85 extern LZMA_API(lzma_bool
) lzma_check_is_supported(lzma_check check
)
86 lzma_nothrow lzma_attr_const
;
90 * \brief Get the size of the Check field with the given Check ID
92 * Although not all Check IDs have a check algorithm associated, the size of
93 * every Check is already frozen. This function returns the size (in bytes) of
94 * the Check field with the specified Check ID. The values are:
95 * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
97 * \param check Check ID
99 * \return Size of the Check field in bytes. If the argument is not in
100 * the range [0, 15], UINT32_MAX is returned.
102 extern LZMA_API(uint32_t) lzma_check_size(lzma_check check
)
103 lzma_nothrow lzma_attr_const
;
107 * \brief Maximum size of a Check field
109 #define LZMA_CHECK_SIZE_MAX 64
113 * \brief Calculate CRC32
115 * Calculate CRC32 using the polynomial from the IEEE 802.3 standard.
117 * \param buf Pointer to the input buffer
118 * \param size Size of the input buffer
119 * \param crc Previously returned CRC value. This is used to
120 * calculate the CRC of a big buffer in smaller chunks.
121 * Set to zero when starting a new calculation.
123 * \return Updated CRC value, which can be passed to this function
124 * again to continue CRC calculation.
126 extern LZMA_API(uint32_t) lzma_crc32(
127 const uint8_t *buf
, size_t size
, uint32_t crc
)
128 lzma_nothrow lzma_attr_pure
;
132 * \brief Calculate CRC64
134 * Calculate CRC64 using the polynomial from the ECMA-182 standard.
136 * This function is used similarly to lzma_crc32().
138 * \param buf Pointer to the input buffer
139 * \param size Size of the input buffer
140 * \param crc Previously returned CRC value. This is used to
141 * calculate the CRC of a big buffer in smaller chunks.
142 * Set to zero when starting a new calculation.
144 * \return Updated CRC value, which can be passed to this function
145 * again to continue CRC calculation.
147 extern LZMA_API(uint64_t) lzma_crc64(
148 const uint8_t *buf
, size_t size
, uint64_t crc
)
149 lzma_nothrow lzma_attr_pure
;
153 * \brief Get the type of the integrity check
155 * This function can be called only immediately after lzma_code() has
156 * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK.
157 * Calling this function in any other situation has undefined behavior.
159 * \param strm Pointer to lzma_stream meeting the above conditions.
161 * \return Check ID in the lzma_stream, or undefined if called improperly.
163 extern LZMA_API(lzma_check
) lzma_get_check(const lzma_stream
*strm
)