2007-12-08 17:42:33 -05:00
|
|
|
/**
|
|
|
|
* \file lzma/check.h
|
|
|
|
* \brief Integrity checks
|
|
|
|
*
|
|
|
|
* \author Copyright (C) 1999-2006 Igor Pavlov
|
|
|
|
* \author Copyright (C) 2007 Lasse Collin
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LZMA_H_INTERNAL
|
|
|
|
# error Never include this file directly. Use <lzma.h> instead.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 12:39:13 -05:00
|
|
|
* \brief Type of the integrity check (Check ID)
|
2007-12-08 17:42:33 -05:00
|
|
|
*
|
2008-12-15 12:39:13 -05:00
|
|
|
* The .xz format supports multiple types of checks that are calculated
|
|
|
|
* from the uncompressed data. They very in both speed and ability to
|
|
|
|
* detect errors.
|
2007-12-08 17:42:33 -05:00
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
LZMA_CHECK_NONE = 0,
|
|
|
|
/**<
|
|
|
|
* No Check is calculated.
|
|
|
|
*
|
|
|
|
* Size of the Check field: 0 bytes
|
|
|
|
*/
|
|
|
|
|
|
|
|
LZMA_CHECK_CRC32 = 1,
|
|
|
|
/**<
|
|
|
|
* CRC32 using the polynomial from the IEEE 802.3 standard
|
|
|
|
*
|
|
|
|
* Size of the Check field: 4 bytes
|
|
|
|
*/
|
|
|
|
|
2008-06-18 11:02:10 -04:00
|
|
|
LZMA_CHECK_CRC64 = 4,
|
2007-12-08 17:42:33 -05:00
|
|
|
/**<
|
|
|
|
* CRC64 using the polynomial from the ECMA-182 standard
|
|
|
|
*
|
|
|
|
* Size of the Check field: 8 bytes
|
|
|
|
*/
|
|
|
|
|
2008-06-18 11:02:10 -04:00
|
|
|
LZMA_CHECK_SHA256 = 10
|
2007-12-08 17:42:33 -05:00
|
|
|
/**<
|
|
|
|
* SHA-256
|
|
|
|
*
|
|
|
|
* Size of the Check field: 32 bytes
|
|
|
|
*/
|
2008-08-28 15:53:15 -04:00
|
|
|
} lzma_check;
|
2007-12-08 17:42:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Maximum valid Check ID
|
|
|
|
*
|
2008-12-15 12:39:13 -05:00
|
|
|
* The .xz file format specification specifies 16 Check IDs (0-15). Some
|
2008-12-31 10:15:03 -05:00
|
|
|
* of them are only reserved, that is, no actual Check algorithm has been
|
|
|
|
* assigned. When decoding, liblzma still accepts unknown Check IDs for
|
|
|
|
* future compatibility. If a valid but unsupported Check ID is detected,
|
|
|
|
* liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK,
|
|
|
|
* LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h.
|
2007-12-08 17:42:33 -05:00
|
|
|
*/
|
2008-06-18 11:02:10 -04:00
|
|
|
#define LZMA_CHECK_ID_MAX 15
|
2007-12-08 17:42:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-08-28 15:53:15 -04:00
|
|
|
* \brief Test if the given Check ID is supported
|
2007-12-08 17:42:33 -05:00
|
|
|
*
|
2008-08-28 15:53:15 -04:00
|
|
|
* Returns true if the given Check ID is supported by this liblzma build.
|
|
|
|
* Otherwise false is returned. It is safe to call this with a value that
|
|
|
|
* is not in the range [0, 15]; in that case the return value is always false.
|
2008-12-15 12:39:13 -05:00
|
|
|
*
|
|
|
|
* You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always
|
|
|
|
* supported (even if liblzma is built with limited features).
|
2007-12-08 17:42:33 -05:00
|
|
|
*/
|
2009-01-31 04:01:48 -05:00
|
|
|
extern LZMA_API lzma_bool lzma_check_is_supported(lzma_check check)
|
2008-08-28 15:53:15 -04:00
|
|
|
lzma_attr_const;
|
2007-12-08 17:42:33 -05:00
|
|
|
|
|
|
|
|
2008-06-18 11:02:10 -04:00
|
|
|
/**
|
2008-12-15 12:39:13 -05:00
|
|
|
* \brief Get the size of the Check field with the given Check ID
|
2008-08-28 15:53:15 -04:00
|
|
|
*
|
|
|
|
* Although not all Check IDs have a check algorithm associated, the size of
|
|
|
|
* every Check is already frozen. This function returns the size (in bytes) of
|
2008-12-15 12:39:13 -05:00
|
|
|
* the Check field with the specified Check ID. The values are:
|
2008-08-28 15:53:15 -04:00
|
|
|
* { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
|
|
|
|
*
|
|
|
|
* If the argument is not in the range [0, 15], UINT32_MAX is returned.
|
2008-06-18 11:02:10 -04:00
|
|
|
*/
|
2009-01-31 04:01:48 -05:00
|
|
|
extern LZMA_API uint32_t lzma_check_size(lzma_check check) lzma_attr_const;
|
2008-06-18 11:02:10 -04:00
|
|
|
|
|
|
|
|
2008-12-31 10:15:03 -05:00
|
|
|
/**
|
|
|
|
* \brief Maximum size of a Check field
|
|
|
|
*/
|
|
|
|
#define LZMA_CHECK_SIZE_MAX 64
|
|
|
|
|
|
|
|
|
2007-12-08 17:42:33 -05:00
|
|
|
/**
|
|
|
|
* \brief Calculate CRC32
|
|
|
|
*
|
|
|
|
* Calculates CRC32 using the polynomial from the IEEE 802.3 standard.
|
|
|
|
*
|
|
|
|
* \param buf Pointer to the input buffer
|
|
|
|
* \param size Size of the input buffer
|
|
|
|
* \param crc Previously returned CRC value. This is used to
|
|
|
|
* calculate the CRC of a big buffer in smaller chunks.
|
|
|
|
* Set to zero when there is no previous value.
|
|
|
|
*
|
|
|
|
* \return Updated CRC value, which can be passed to this function
|
|
|
|
* again to continue CRC calculation.
|
|
|
|
*/
|
2009-01-31 04:01:48 -05:00
|
|
|
extern LZMA_API uint32_t lzma_crc32(
|
|
|
|
const uint8_t *buf, size_t size, uint32_t crc)
|
2008-08-28 15:53:15 -04:00
|
|
|
lzma_attr_pure;
|
2007-12-08 17:42:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Calculate CRC64
|
|
|
|
*
|
|
|
|
* Calculates CRC64 using the polynomial from the ECMA-182 standard.
|
|
|
|
*
|
|
|
|
* This function is used similarly to lzma_crc32(). See its documentation.
|
|
|
|
*/
|
2009-01-31 04:01:48 -05:00
|
|
|
extern LZMA_API uint64_t lzma_crc64(
|
|
|
|
const uint8_t *buf, size_t size, uint64_t crc)
|
2008-08-28 15:53:15 -04:00
|
|
|
lzma_attr_pure;
|
2007-12-08 17:42:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-12-15 12:39:13 -05:00
|
|
|
* SHA-256 functions are currently not exported to public API.
|
|
|
|
* Contact Lasse Collin if you think it should be.
|
2007-12-08 17:42:33 -05:00
|
|
|
*/
|
2008-09-06 08:14:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the type of the integrity check
|
|
|
|
*
|
|
|
|
* This function can be called only immediatelly after lzma_code() has
|
|
|
|
* returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK.
|
|
|
|
* Calling this function in any other situation has undefined behavior.
|
|
|
|
*/
|
2009-01-31 04:01:48 -05:00
|
|
|
extern LZMA_API lzma_check lzma_get_check(const lzma_stream *strm);
|