jpayne@69: /* SPDX-License-Identifier: 0BSD */ jpayne@69: jpayne@69: /** jpayne@69: * \file lzma/check.h jpayne@69: * \brief Integrity checks jpayne@69: * \note Never include this file directly. Use instead. jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * Author: Lasse Collin jpayne@69: */ jpayne@69: jpayne@69: #ifndef LZMA_H_INTERNAL jpayne@69: # error Never include this file directly. Use instead. jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Type of the integrity check (Check ID) jpayne@69: * jpayne@69: * The .xz format supports multiple types of checks that are calculated jpayne@69: * from the uncompressed data. They vary in both speed and ability to jpayne@69: * detect errors. jpayne@69: */ jpayne@69: typedef enum { jpayne@69: LZMA_CHECK_NONE = 0, jpayne@69: /**< jpayne@69: * No Check is calculated. jpayne@69: * jpayne@69: * Size of the Check field: 0 bytes jpayne@69: */ jpayne@69: jpayne@69: LZMA_CHECK_CRC32 = 1, jpayne@69: /**< jpayne@69: * CRC32 using the polynomial from the IEEE 802.3 standard jpayne@69: * jpayne@69: * Size of the Check field: 4 bytes jpayne@69: */ jpayne@69: jpayne@69: LZMA_CHECK_CRC64 = 4, jpayne@69: /**< jpayne@69: * CRC64 using the polynomial from the ECMA-182 standard jpayne@69: * jpayne@69: * Size of the Check field: 8 bytes jpayne@69: */ jpayne@69: jpayne@69: LZMA_CHECK_SHA256 = 10 jpayne@69: /**< jpayne@69: * SHA-256 jpayne@69: * jpayne@69: * Size of the Check field: 32 bytes jpayne@69: */ jpayne@69: } lzma_check; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Maximum valid Check ID jpayne@69: * jpayne@69: * The .xz file format specification specifies 16 Check IDs (0-15). Some jpayne@69: * of them are only reserved, that is, no actual Check algorithm has been jpayne@69: * assigned. When decoding, liblzma still accepts unknown Check IDs for jpayne@69: * future compatibility. If a valid but unsupported Check ID is detected, jpayne@69: * liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK, jpayne@69: * LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h. jpayne@69: */ jpayne@69: #define LZMA_CHECK_ID_MAX 15 jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Test if the given Check ID is supported jpayne@69: * jpayne@69: * LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always supported (even if jpayne@69: * liblzma is built with limited features). jpayne@69: * jpayne@69: * \note It is safe to call this with a value that is not in the jpayne@69: * range [0, 15]; in that case the return value is always false. jpayne@69: * jpayne@69: * \param check Check ID jpayne@69: * jpayne@69: * \return lzma_bool: jpayne@69: * - true if Check ID is supported by this liblzma build. jpayne@69: * - false otherwise. jpayne@69: */ jpayne@69: extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check) jpayne@69: lzma_nothrow lzma_attr_const; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Get the size of the Check field with the given Check ID jpayne@69: * jpayne@69: * Although not all Check IDs have a check algorithm associated, the size of jpayne@69: * every Check is already frozen. This function returns the size (in bytes) of jpayne@69: * the Check field with the specified Check ID. The values are: jpayne@69: * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 } jpayne@69: * jpayne@69: * \param check Check ID jpayne@69: * jpayne@69: * \return Size of the Check field in bytes. If the argument is not in jpayne@69: * the range [0, 15], UINT32_MAX is returned. jpayne@69: */ jpayne@69: extern LZMA_API(uint32_t) lzma_check_size(lzma_check check) jpayne@69: lzma_nothrow lzma_attr_const; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Maximum size of a Check field jpayne@69: */ jpayne@69: #define LZMA_CHECK_SIZE_MAX 64 jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Calculate CRC32 jpayne@69: * jpayne@69: * Calculate CRC32 using the polynomial from the IEEE 802.3 standard. jpayne@69: * jpayne@69: * \param buf Pointer to the input buffer jpayne@69: * \param size Size of the input buffer jpayne@69: * \param crc Previously returned CRC value. This is used to jpayne@69: * calculate the CRC of a big buffer in smaller chunks. jpayne@69: * Set to zero when starting a new calculation. jpayne@69: * jpayne@69: * \return Updated CRC value, which can be passed to this function jpayne@69: * again to continue CRC calculation. jpayne@69: */ jpayne@69: extern LZMA_API(uint32_t) lzma_crc32( jpayne@69: const uint8_t *buf, size_t size, uint32_t crc) jpayne@69: lzma_nothrow lzma_attr_pure; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Calculate CRC64 jpayne@69: * jpayne@69: * Calculate CRC64 using the polynomial from the ECMA-182 standard. jpayne@69: * jpayne@69: * This function is used similarly to lzma_crc32(). jpayne@69: * jpayne@69: * \param buf Pointer to the input buffer jpayne@69: * \param size Size of the input buffer jpayne@69: * \param crc Previously returned CRC value. This is used to jpayne@69: * calculate the CRC of a big buffer in smaller chunks. jpayne@69: * Set to zero when starting a new calculation. jpayne@69: * jpayne@69: * \return Updated CRC value, which can be passed to this function jpayne@69: * again to continue CRC calculation. jpayne@69: */ jpayne@69: extern LZMA_API(uint64_t) lzma_crc64( jpayne@69: const uint8_t *buf, size_t size, uint64_t crc) jpayne@69: lzma_nothrow lzma_attr_pure; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Get the type of the integrity check jpayne@69: * jpayne@69: * This function can be called only immediately after lzma_code() has jpayne@69: * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK. jpayne@69: * Calling this function in any other situation has undefined behavior. jpayne@69: * jpayne@69: * \param strm Pointer to lzma_stream meeting the above conditions. jpayne@69: * jpayne@69: * \return Check ID in the lzma_stream, or undefined if called improperly. jpayne@69: */ jpayne@69: extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm) jpayne@69: lzma_nothrow;