]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma/check.h
Sort of garbage collection commit. :-| Many things are still
[icculus/xz.git] / src / liblzma / api / lzma / check.h
1 /**
2  * \file        lzma/check.h
3  * \brief       Integrity checks
4  *
5  * \author      Copyright (C) 1999-2006 Igor Pavlov
6  * \author      Copyright (C) 2007 Lasse Collin
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  */
18
19 #ifndef LZMA_H_INTERNAL
20 #       error Never include this file directly. Use <lzma.h> instead.
21 #endif
22
23
24 /**
25  * \brief       Type of the Check
26  *
27  * The .lzma format supports multiple types of Checks that are calculated
28  * from the uncompressed data (unless it is empty; then it's calculated
29  * from Block Header).
30  */
31 typedef enum {
32         LZMA_CHECK_NONE     = 0,
33                 /**<
34                  * No Check is calculated.
35                  *
36                  * Size of the Check field: 0 bytes
37                  */
38
39         LZMA_CHECK_CRC32    = 1,
40                 /**<
41                  * CRC32 using the polynomial from the IEEE 802.3 standard
42                  *
43                  * Size of the Check field: 4 bytes
44                  */
45
46         LZMA_CHECK_CRC64    = 4,
47                 /**<
48                  * CRC64 using the polynomial from the ECMA-182 standard
49                  *
50                  * Size of the Check field: 8 bytes
51                  */
52
53         LZMA_CHECK_SHA256   = 10
54                 /**<
55                  * SHA-256
56                  *
57                  * Size of the Check field: 32 bytes
58                  */
59 } lzma_check;
60
61
62 /**
63  * \brief       Maximum valid Check ID
64  *
65  * The .lzma file format specification specifies eight Check IDs (0-15). Some
66  * of them are only reserved i.e. no actual Check algorithm has been assigned.
67  * Still liblzma accepts any of these eight IDs for future compatibility
68  * when decoding files. If a valid but unsupported Check ID is detected,
69  * liblzma indicates a warning with LZMA_UNSUPPORTED_CHECK.
70  *
71  * FIXME bad desc
72  */
73 #define LZMA_CHECK_ID_MAX 15
74
75
76 /**
77  * \brief       Maximum size of a Check field
78  */
79 #define LZMA_CHECK_SIZE_MAX 64
80
81
82 /**
83  * \brief       Test if the given Check ID is supported
84  *
85  * Returns true if the given Check ID is supported by this liblzma build.
86  * Otherwise false is returned. It is safe to call this with a value that
87  * is not in the range [0, 15]; in that case the return value is always false.
88  */
89 extern lzma_bool lzma_check_is_supported(lzma_check check)
90                 lzma_attr_const;
91
92
93 /**
94  * \brief       Get the size of the Check field with given Check ID
95  *
96  * Although not all Check IDs have a check algorithm associated, the size of
97  * every Check is already frozen. This function returns the size (in bytes) of
98  * the Check field with the specified Check ID. The values are taken from the
99  * section 2.1.1.2 of the .lzma file format specification:
100  * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
101  *
102  * If the argument is not in the range [0, 15], UINT32_MAX is returned.
103  */
104 extern uint32_t lzma_check_size(lzma_check check) lzma_attr_const;
105
106
107 /**
108  * \brief       Calculate CRC32
109  *
110  * Calculates CRC32 using the polynomial from the IEEE 802.3 standard.
111  *
112  * \param       buf     Pointer to the input buffer
113  * \param       size    Size of the input buffer
114  * \param       crc     Previously returned CRC value. This is used to
115  *                      calculate the CRC of a big buffer in smaller chunks.
116  *                      Set to zero when there is no previous value.
117  *
118  * \return      Updated CRC value, which can be passed to this function
119  *              again to continue CRC calculation.
120  */
121 extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
122                 lzma_attr_pure;
123
124
125 /**
126  * \brief       Calculate CRC64
127  *
128  * Calculates CRC64 using the polynomial from the ECMA-182 standard.
129  *
130  * This function is used similarly to lzma_crc32(). See its documentation.
131  */
132 extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
133                 lzma_attr_pure;
134
135
136 /*
137  * SHA256 functions are currently not exported to public API.
138  * Contact the author if you think it should be.
139  */