]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/check/check.h
Update the code to mostly match the new simpler file format
[icculus/xz.git] / src / liblzma / check / check.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       check.h
4 /// \brief      Prototypes for different check functions
5 //
6 //  This code has been put into the public domain.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 //
12 ///////////////////////////////////////////////////////////////////////////////
13
14 #ifndef LZMA_CHECK_H
15 #define LZMA_CHECK_H
16
17 #include "common.h"
18
19
20 // Index hashing used to verify the Index with O(1) memory usage needs
21 // a good hash function.
22 #if defined(HAVE_CHECK_SHA256)
23 #       define LZMA_CHECK_BEST LZMA_CHECK_SHA256
24 #elif defined(HAVE_CHECK_CRC64)
25 #       define LZMA_CHECK_BEST LZMA_CHECK_CRC64
26 #else
27 #       define LZMA_CHECK_BEST LZMA_CHECK_CRC32
28 #endif
29
30
31 typedef struct {
32         /// Internal state
33         uint32_t state[8];
34
35         /// Size of the message excluding padding
36         uint64_t size;
37
38 } lzma_sha256;
39
40
41 /// \note       This is not in the public API because this structure will
42 ///             change in future.
43 typedef struct {
44         // FIXME Guarantee 8-byte alignment
45
46         /// Buffer to hold the final result; this is also used as a temporary
47         /// buffer in SHA256. Note that this buffer must be 8-byte aligned.
48         uint8_t buffer[64];
49
50         /// Check-specific data
51         union {
52                 uint32_t crc32;
53                 uint64_t crc64;
54
55                 struct {
56                         /// Internal state
57                         uint32_t state[8];
58
59                         /// Size of the message excluding padding
60                         uint64_t size;
61                 } sha256;
62         } state;
63
64 } lzma_check;
65
66
67 #ifdef HAVE_SMALL
68 extern uint32_t lzma_crc32_table[8][256];
69 extern uint64_t lzma_crc64_table[4][256];
70 #else
71 extern const uint32_t lzma_crc32_table[8][256];
72 extern const uint64_t lzma_crc64_table[4][256];
73 #endif
74
75 // Generic
76
77 /// \brief      Initializes *check depending on type
78 ///
79 /// \return     LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
80 ///             supported by the current version or build of liblzma.
81 ///             LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
82 ///
83 extern lzma_ret lzma_check_init(lzma_check *check, lzma_check_type type);
84
85 /// \brief      Updates *check
86 ///
87 extern void lzma_check_update(lzma_check *check, lzma_check_type type,
88                 const uint8_t *buf, size_t size);
89
90 /// \brief      Finishes *check
91 ///
92 extern void lzma_check_finish(lzma_check *check, lzma_check_type type);
93
94
95 /*
96 /// \brief      Compare two checks
97 ///
98 /// \return     false if the checks are identical; true if they differ.
99 ///
100 extern bool lzma_check_compare(
101                 lzma_check *check1, lzma_check *check2, lzma_check_type type);
102 */
103
104
105 // CRC32
106
107 extern void lzma_crc32_init(void);
108
109
110 // CRC64
111
112 extern void lzma_crc64_init(void);
113
114
115 // SHA256
116
117 extern void lzma_sha256_init(lzma_check *check);
118
119 extern void lzma_sha256_update(
120                 const uint8_t *buf, size_t size, lzma_check *check);
121
122 extern void lzma_sha256_finish(lzma_check *check);
123
124
125 #endif