186d7f5d3SJohn Marino /** 286d7f5d3SJohn Marino * \file lzma/check.h 386d7f5d3SJohn Marino * \brief Integrity checks 486d7f5d3SJohn Marino */ 586d7f5d3SJohn Marino 686d7f5d3SJohn Marino /* 786d7f5d3SJohn Marino * Author: Lasse Collin 886d7f5d3SJohn Marino * 986d7f5d3SJohn Marino * This file has been put into the public domain. 1086d7f5d3SJohn Marino * You can do whatever you want with this file. 1186d7f5d3SJohn Marino * 1286d7f5d3SJohn Marino * See ../lzma.h for information about liblzma as a whole. 1386d7f5d3SJohn Marino */ 1486d7f5d3SJohn Marino 1586d7f5d3SJohn Marino #ifndef LZMA_H_INTERNAL 1686d7f5d3SJohn Marino # error Never include this file directly. Use <lzma.h> instead. 1786d7f5d3SJohn Marino #endif 1886d7f5d3SJohn Marino 1986d7f5d3SJohn Marino 2086d7f5d3SJohn Marino /** 2186d7f5d3SJohn Marino * \brief Type of the integrity check (Check ID) 2286d7f5d3SJohn Marino * 2386d7f5d3SJohn Marino * The .xz format supports multiple types of checks that are calculated 2486d7f5d3SJohn Marino * from the uncompressed data. They vary in both speed and ability to 2586d7f5d3SJohn Marino * detect errors. 2686d7f5d3SJohn Marino */ 2786d7f5d3SJohn Marino typedef enum { 2886d7f5d3SJohn Marino LZMA_CHECK_NONE = 0, 2986d7f5d3SJohn Marino /**< 3086d7f5d3SJohn Marino * No Check is calculated. 3186d7f5d3SJohn Marino * 3286d7f5d3SJohn Marino * Size of the Check field: 0 bytes 3386d7f5d3SJohn Marino */ 3486d7f5d3SJohn Marino 3586d7f5d3SJohn Marino LZMA_CHECK_CRC32 = 1, 3686d7f5d3SJohn Marino /**< 3786d7f5d3SJohn Marino * CRC32 using the polynomial from the IEEE 802.3 standard 3886d7f5d3SJohn Marino * 3986d7f5d3SJohn Marino * Size of the Check field: 4 bytes 4086d7f5d3SJohn Marino */ 4186d7f5d3SJohn Marino 4286d7f5d3SJohn Marino LZMA_CHECK_CRC64 = 4, 4386d7f5d3SJohn Marino /**< 4486d7f5d3SJohn Marino * CRC64 using the polynomial from the ECMA-182 standard 4586d7f5d3SJohn Marino * 4686d7f5d3SJohn Marino * Size of the Check field: 8 bytes 4786d7f5d3SJohn Marino */ 4886d7f5d3SJohn Marino 4986d7f5d3SJohn Marino LZMA_CHECK_SHA256 = 10 5086d7f5d3SJohn Marino /**< 5186d7f5d3SJohn Marino * SHA-256 5286d7f5d3SJohn Marino * 5386d7f5d3SJohn Marino * Size of the Check field: 32 bytes 5486d7f5d3SJohn Marino */ 5586d7f5d3SJohn Marino } lzma_check; 5686d7f5d3SJohn Marino 5786d7f5d3SJohn Marino 5886d7f5d3SJohn Marino /** 5986d7f5d3SJohn Marino * \brief Maximum valid Check ID 6086d7f5d3SJohn Marino * 6186d7f5d3SJohn Marino * The .xz file format specification specifies 16 Check IDs (0-15). Some 6286d7f5d3SJohn Marino * of them are only reserved, that is, no actual Check algorithm has been 6386d7f5d3SJohn Marino * assigned. When decoding, liblzma still accepts unknown Check IDs for 6486d7f5d3SJohn Marino * future compatibility. If a valid but unsupported Check ID is detected, 6586d7f5d3SJohn Marino * liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK, 6686d7f5d3SJohn Marino * LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h. 6786d7f5d3SJohn Marino */ 6886d7f5d3SJohn Marino #define LZMA_CHECK_ID_MAX 15 6986d7f5d3SJohn Marino 7086d7f5d3SJohn Marino 7186d7f5d3SJohn Marino /** 7286d7f5d3SJohn Marino * \brief Test if the given Check ID is supported 7386d7f5d3SJohn Marino * 7486d7f5d3SJohn Marino * Return true if the given Check ID is supported by this liblzma build. 7586d7f5d3SJohn Marino * Otherwise false is returned. It is safe to call this with a value that 7686d7f5d3SJohn Marino * is not in the range [0, 15]; in that case the return value is always false. 7786d7f5d3SJohn Marino * 7886d7f5d3SJohn Marino * You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always 7986d7f5d3SJohn Marino * supported (even if liblzma is built with limited features). 8086d7f5d3SJohn Marino */ 8186d7f5d3SJohn Marino extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check) 8286d7f5d3SJohn Marino lzma_nothrow lzma_attr_const; 8386d7f5d3SJohn Marino 8486d7f5d3SJohn Marino 8586d7f5d3SJohn Marino /** 8686d7f5d3SJohn Marino * \brief Get the size of the Check field with the given Check ID 8786d7f5d3SJohn Marino * 8886d7f5d3SJohn Marino * Although not all Check IDs have a check algorithm associated, the size of 8986d7f5d3SJohn Marino * every Check is already frozen. This function returns the size (in bytes) of 9086d7f5d3SJohn Marino * the Check field with the specified Check ID. The values are: 9186d7f5d3SJohn Marino * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 } 9286d7f5d3SJohn Marino * 9386d7f5d3SJohn Marino * If the argument is not in the range [0, 15], UINT32_MAX is returned. 9486d7f5d3SJohn Marino */ 9586d7f5d3SJohn Marino extern LZMA_API(uint32_t) lzma_check_size(lzma_check check) 9686d7f5d3SJohn Marino lzma_nothrow lzma_attr_const; 9786d7f5d3SJohn Marino 9886d7f5d3SJohn Marino 9986d7f5d3SJohn Marino /** 10086d7f5d3SJohn Marino * \brief Maximum size of a Check field 10186d7f5d3SJohn Marino */ 10286d7f5d3SJohn Marino #define LZMA_CHECK_SIZE_MAX 64 10386d7f5d3SJohn Marino 10486d7f5d3SJohn Marino 10586d7f5d3SJohn Marino /** 10686d7f5d3SJohn Marino * \brief Calculate CRC32 10786d7f5d3SJohn Marino * 10886d7f5d3SJohn Marino * Calculate CRC32 using the polynomial from the IEEE 802.3 standard. 10986d7f5d3SJohn Marino * 11086d7f5d3SJohn Marino * \param buf Pointer to the input buffer 11186d7f5d3SJohn Marino * \param size Size of the input buffer 11286d7f5d3SJohn Marino * \param crc Previously returned CRC value. This is used to 11386d7f5d3SJohn Marino * calculate the CRC of a big buffer in smaller chunks. 11486d7f5d3SJohn Marino * Set to zero when starting a new calculation. 11586d7f5d3SJohn Marino * 11686d7f5d3SJohn Marino * \return Updated CRC value, which can be passed to this function 11786d7f5d3SJohn Marino * again to continue CRC calculation. 11886d7f5d3SJohn Marino */ 11986d7f5d3SJohn Marino extern LZMA_API(uint32_t) lzma_crc32( 12086d7f5d3SJohn Marino const uint8_t *buf, size_t size, uint32_t crc) 12186d7f5d3SJohn Marino lzma_nothrow lzma_attr_pure; 12286d7f5d3SJohn Marino 12386d7f5d3SJohn Marino 12486d7f5d3SJohn Marino /** 12586d7f5d3SJohn Marino * \brief Calculate CRC64 12686d7f5d3SJohn Marino * 12786d7f5d3SJohn Marino * Calculate CRC64 using the polynomial from the ECMA-182 standard. 12886d7f5d3SJohn Marino * 12986d7f5d3SJohn Marino * This function is used similarly to lzma_crc32(). See its documentation. 13086d7f5d3SJohn Marino */ 13186d7f5d3SJohn Marino extern LZMA_API(uint64_t) lzma_crc64( 13286d7f5d3SJohn Marino const uint8_t *buf, size_t size, uint64_t crc) 13386d7f5d3SJohn Marino lzma_nothrow lzma_attr_pure; 13486d7f5d3SJohn Marino 13586d7f5d3SJohn Marino 13686d7f5d3SJohn Marino /* 13786d7f5d3SJohn Marino * SHA-256 functions are currently not exported to public API. 13886d7f5d3SJohn Marino * Contact Lasse Collin if you think it should be. 13986d7f5d3SJohn Marino */ 14086d7f5d3SJohn Marino 14186d7f5d3SJohn Marino 14286d7f5d3SJohn Marino /** 14386d7f5d3SJohn Marino * \brief Get the type of the integrity check 14486d7f5d3SJohn Marino * 14586d7f5d3SJohn Marino * This function can be called only immediately after lzma_code() has 14686d7f5d3SJohn Marino * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK. 14786d7f5d3SJohn Marino * Calling this function in any other situation has undefined behavior. 14886d7f5d3SJohn Marino */ 14986d7f5d3SJohn Marino extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm) 15086d7f5d3SJohn Marino lzma_nothrow; 151