]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/check/check.h
Sort of garbage collection commit. :-| Many things are still
[icculus/xz.git] / src / liblzma / check / check.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       check.h
4 /// \brief      Internal API to different integrity 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 needs the best possible hash function (preferably
21 // a cryptographic hash) for maximum reliability.
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 /// \brief      Structure to hold internal state of the check being calculated
32 ///
33 /// \note       This is not in the public API because this structure may
34 ///             change in future if new integrity check algorithms are added.
35 typedef struct {
36         /// Buffer to hold the final result and a temporary buffer for SHA256.
37         union {
38                 uint8_t u8[64];
39                 uint32_t u32[16];
40                 uint64_t u64[8];
41         } buffer;
42
43         /// Check-specific data
44         union {
45                 uint32_t crc32;
46                 uint64_t crc64;
47
48                 struct {
49                         /// Internal state
50                         uint32_t state[8];
51
52                         /// Size of the message excluding padding
53                         uint64_t size;
54                 } sha256;
55         } state;
56
57 } lzma_check_state;
58
59
60 #ifdef HAVE_SMALL
61 extern uint32_t lzma_crc32_table[8][256];
62 extern uint64_t lzma_crc64_table[4][256];
63 #else
64 extern const uint32_t lzma_crc32_table[8][256];
65 extern const uint64_t lzma_crc64_table[4][256];
66 #endif
67
68
69 /// \brief      Initializes *check depending on type
70 ///
71 /// \return     LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
72 ///             supported by the current version or build of liblzma.
73 ///             LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
74 ///
75 extern void lzma_check_init(lzma_check_state *check, lzma_check type);
76
77
78 /// \brief      Updates *check
79 ///
80 extern void lzma_check_update(lzma_check_state *check, lzma_check type,
81                 const uint8_t *buf, size_t size);
82
83
84 /// \brief      Finishes *check
85 ///
86 extern void lzma_check_finish(lzma_check_state *check, lzma_check type);
87
88
89 extern void lzma_crc32_init(void);
90
91
92 extern void lzma_crc64_init(void);
93
94
95 extern void lzma_sha256_init(lzma_check_state *check);
96
97 extern void lzma_sha256_update(
98                 const uint8_t *buf, size_t size, lzma_check_state *check);
99
100 extern void lzma_sha256_finish(lzma_check_state *check);
101
102 #endif