check.h revision 207753
1207753Smm/** 2207753Smm * \file lzma/check.h 3207753Smm * \brief Integrity checks 4207753Smm */ 5207753Smm 6207753Smm/* 7207753Smm * Author: Lasse Collin 8207753Smm * 9207753Smm * This file has been put into the public domain. 10207753Smm * You can do whatever you want with this file. 11207753Smm * 12207753Smm * See ../lzma.h for information about liblzma as a whole. 13207753Smm */ 14207753Smm 15207753Smm#ifndef LZMA_H_INTERNAL 16207753Smm# error Never include this file directly. Use <lzma.h> instead. 17207753Smm#endif 18207753Smm 19207753Smm 20207753Smm/** 21207753Smm * \brief Type of the integrity check (Check ID) 22207753Smm * 23207753Smm * The .xz format supports multiple types of checks that are calculated 24207753Smm * from the uncompressed data. They vary in both speed and ability to 25207753Smm * detect errors. 26207753Smm */ 27207753Smmtypedef enum { 28207753Smm LZMA_CHECK_NONE = 0, 29207753Smm /**< 30207753Smm * No Check is calculated. 31207753Smm * 32207753Smm * Size of the Check field: 0 bytes 33207753Smm */ 34207753Smm 35207753Smm LZMA_CHECK_CRC32 = 1, 36207753Smm /**< 37207753Smm * CRC32 using the polynomial from the IEEE 802.3 standard 38207753Smm * 39207753Smm * Size of the Check field: 4 bytes 40207753Smm */ 41207753Smm 42207753Smm LZMA_CHECK_CRC64 = 4, 43207753Smm /**< 44207753Smm * CRC64 using the polynomial from the ECMA-182 standard 45207753Smm * 46207753Smm * Size of the Check field: 8 bytes 47207753Smm */ 48207753Smm 49207753Smm LZMA_CHECK_SHA256 = 10 50207753Smm /**< 51207753Smm * SHA-256 52207753Smm * 53207753Smm * Size of the Check field: 32 bytes 54207753Smm */ 55207753Smm} lzma_check; 56207753Smm 57207753Smm 58207753Smm/** 59207753Smm * \brief Maximum valid Check ID 60207753Smm * 61207753Smm * The .xz file format specification specifies 16 Check IDs (0-15). Some 62207753Smm * of them are only reserved, that is, no actual Check algorithm has been 63207753Smm * assigned. When decoding, liblzma still accepts unknown Check IDs for 64207753Smm * future compatibility. If a valid but unsupported Check ID is detected, 65207753Smm * liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK, 66207753Smm * LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h. 67207753Smm */ 68207753Smm#define LZMA_CHECK_ID_MAX 15 69207753Smm 70207753Smm 71207753Smm/** 72207753Smm * \brief Test if the given Check ID is supported 73207753Smm * 74207753Smm * Return true if the given Check ID is supported by this liblzma build. 75207753Smm * Otherwise false is returned. It is safe to call this with a value that 76207753Smm * is not in the range [0, 15]; in that case the return value is always false. 77207753Smm * 78207753Smm * You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always 79207753Smm * supported (even if liblzma is built with limited features). 80207753Smm */ 81207753Smmextern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check) 82207753Smm lzma_nothrow lzma_attr_const; 83207753Smm 84207753Smm 85207753Smm/** 86207753Smm * \brief Get the size of the Check field with the given Check ID 87207753Smm * 88207753Smm * Although not all Check IDs have a check algorithm associated, the size of 89207753Smm * every Check is already frozen. This function returns the size (in bytes) of 90207753Smm * the Check field with the specified Check ID. The values are: 91207753Smm * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 } 92207753Smm * 93207753Smm * If the argument is not in the range [0, 15], UINT32_MAX is returned. 94207753Smm */ 95207753Smmextern LZMA_API(uint32_t) lzma_check_size(lzma_check check) 96207753Smm lzma_nothrow lzma_attr_const; 97207753Smm 98207753Smm 99207753Smm/** 100207753Smm * \brief Maximum size of a Check field 101207753Smm */ 102207753Smm#define LZMA_CHECK_SIZE_MAX 64 103207753Smm 104207753Smm 105207753Smm/** 106207753Smm * \brief Calculate CRC32 107207753Smm * 108207753Smm * Calculate CRC32 using the polynomial from the IEEE 802.3 standard. 109207753Smm * 110207753Smm * \param buf Pointer to the input buffer 111207753Smm * \param size Size of the input buffer 112207753Smm * \param crc Previously returned CRC value. This is used to 113207753Smm * calculate the CRC of a big buffer in smaller chunks. 114207753Smm * Set to zero when starting a new calculation. 115207753Smm * 116207753Smm * \return Updated CRC value, which can be passed to this function 117207753Smm * again to continue CRC calculation. 118207753Smm */ 119207753Smmextern LZMA_API(uint32_t) lzma_crc32( 120207753Smm const uint8_t *buf, size_t size, uint32_t crc) 121207753Smm lzma_nothrow lzma_attr_pure; 122207753Smm 123207753Smm 124207753Smm/** 125207753Smm * \brief Calculate CRC64 126207753Smm * 127207753Smm * Calculate CRC64 using the polynomial from the ECMA-182 standard. 128207753Smm * 129207753Smm * This function is used similarly to lzma_crc32(). See its documentation. 130207753Smm */ 131207753Smmextern LZMA_API(uint64_t) lzma_crc64( 132207753Smm const uint8_t *buf, size_t size, uint64_t crc) 133207753Smm lzma_nothrow lzma_attr_pure; 134207753Smm 135207753Smm 136207753Smm/* 137207753Smm * SHA-256 functions are currently not exported to public API. 138207753Smm * Contact Lasse Collin if you think it should be. 139207753Smm */ 140207753Smm 141207753Smm 142207753Smm/** 143207753Smm * \brief Get the type of the integrity check 144207753Smm * 145207753Smm * This function can be called only immediately after lzma_code() has 146207753Smm * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK. 147207753Smm * Calling this function in any other situation has undefined behavior. 148207753Smm */ 149207753Smmextern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm) 150207753Smm lzma_nothrow; 151