1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Internal API to different integrity check functions
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
19 // Index hashing needs the best possible hash function (preferably
20 // a cryptographic hash) for maximum reliability.
21 #if defined(HAVE_CHECK_SHA256)
22 # define LZMA_CHECK_BEST LZMA_CHECK_SHA256
23 #elif defined(HAVE_CHECK_CRC64)
24 # define LZMA_CHECK_BEST LZMA_CHECK_CRC64
26 # define LZMA_CHECK_BEST LZMA_CHECK_CRC32
30 /// \brief Structure to hold internal state of the check being calculated
32 /// \note This is not in the public API because this structure may
33 /// change in future if new integrity check algorithms are added.
35 /// Buffer to hold the final result and a temporary buffer for SHA256.
42 /// Check-specific data
51 /// Size of the message excluding padding
59 /// lzma_crc32_table[0] is needed by LZ encoder so we need to keep
60 /// the array two-dimensional.
62 extern uint32_t lzma_crc32_table[1][256];
63 extern void lzma_crc32_init(void);
65 extern const uint32_t lzma_crc32_table[8][256];
66 extern const uint64_t lzma_crc64_table[4][256];
70 /// \brief Initialize *check depending on type
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);
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);
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);
85 /// Prepare SHA-256 state for new input.
86 extern void lzma_sha256_init(lzma_check_state *check);
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);
92 /// Finish the SHA-256 calculation and store the result to check->buffer.u8.
93 extern void lzma_sha256_finish(lzma_check_state *check);