]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/check/check.h
Remove lzma_init() and other init functions from liblzma API.
[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 /// lzma_crc32_table[0] is needed by LZ encoder so we need to keep
61 /// the array two-dimensional.
62 #ifdef HAVE_SMALL
63 extern uint32_t lzma_crc32_table[1][256];
64 #else
65 extern const uint32_t lzma_crc32_table[8][256];
66 extern const uint64_t lzma_crc64_table[4][256];
67 #endif
68
69
70 /// \brief      Initialize *check depending on type
71 ///
72 /// \return     LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
73 ///             supported by the current version or build of liblzma.
74 ///             LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
75 extern void lzma_check_init(lzma_check_state *check, lzma_check type);
76
77 /// Update the check state
78 extern void lzma_check_update(lzma_check_state *check, lzma_check type,
79                 const uint8_t *buf, size_t size);
80
81 /// Finish the check calculation and store the result to check->buffer.u8.
82 extern void lzma_check_finish(lzma_check_state *check, lzma_check type);
83
84
85 /// Prepare SHA-256 state for new input.
86 extern void lzma_sha256_init(lzma_check_state *check);
87
88 /// Update the SHA-256 hash state
89 extern void lzma_sha256_update(
90                 const uint8_t *buf, size_t size, lzma_check_state *check);
91
92 /// Finish the SHA-256 calculation and store the result to check->buffer.u8.
93 extern void lzma_sha256_finish(lzma_check_state *check);
94
95 #endif