1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Internal API to different integrity check functions
6 // This code has been put into the public domain.
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.
12 ///////////////////////////////////////////////////////////////////////////////
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
27 # define LZMA_CHECK_BEST LZMA_CHECK_CRC32
31 /// \brief Structure to hold internal state of the check being calculated
33 /// \note This is not in the public API because this structure may
34 /// change in future if new integrity check algorithms are added.
36 /// Buffer to hold the final result and a temporary buffer for SHA256.
43 /// Check-specific data
52 /// Size of the message excluding padding
60 /// lzma_crc32_table[0] is needed by LZ encoder so we need to keep
61 /// the array two-dimensional.
63 extern uint32_t lzma_crc32_table[1][256];
64 extern void lzma_crc32_init(void);
66 extern const uint32_t lzma_crc32_table[8][256];
67 extern const uint64_t lzma_crc64_table[4][256];
71 /// \brief Initialize *check depending on type
73 /// \return LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
74 /// supported by the current version or build of liblzma.
75 /// LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
76 extern void lzma_check_init(lzma_check_state *check, lzma_check type);
78 /// Update the check state
79 extern void lzma_check_update(lzma_check_state *check, lzma_check type,
80 const uint8_t *buf, size_t size);
82 /// Finish the check calculation and store the result to check->buffer.u8.
83 extern void lzma_check_finish(lzma_check_state *check, lzma_check type);
86 /// Prepare SHA-256 state for new input.
87 extern void lzma_sha256_init(lzma_check_state *check);
89 /// Update the SHA-256 hash state
90 extern void lzma_sha256_update(
91 const uint8_t *buf, size_t size, lzma_check_state *check);
93 /// Finish the SHA-256 calculation and store the result to check->buffer.u8.
94 extern void lzma_sha256_finish(lzma_check_state *check);