jpayne@69: /* SPDX-License-Identifier: 0BSD */ jpayne@69: jpayne@69: /** jpayne@69: * \file lzma/index_hash.h jpayne@69: * \brief Validate Index by using a hash function jpayne@69: * \note Never include this file directly. Use instead. jpayne@69: * jpayne@69: * Hashing makes it possible to use constant amount of memory to validate jpayne@69: * Index of arbitrary size. jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * Author: Lasse Collin jpayne@69: */ jpayne@69: jpayne@69: #ifndef LZMA_H_INTERNAL jpayne@69: # error Never include this file directly. Use instead. jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * \brief Opaque data type to hold the Index hash jpayne@69: */ jpayne@69: typedef struct lzma_index_hash_s lzma_index_hash; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Allocate and initialize a new lzma_index_hash structure jpayne@69: * jpayne@69: * If index_hash is NULL, this function allocates and initializes a new jpayne@69: * lzma_index_hash structure and returns a pointer to it. If allocation jpayne@69: * fails, NULL is returned. jpayne@69: * jpayne@69: * If index_hash is non-NULL, this function reinitializes the lzma_index_hash jpayne@69: * structure and returns the same pointer. In this case, return value cannot jpayne@69: * be NULL or a different pointer than the index_hash that was given as jpayne@69: * an argument. jpayne@69: * jpayne@69: * \param index_hash Pointer to a lzma_index_hash structure or NULL. jpayne@69: * \param allocator lzma_allocator for custom allocator functions. jpayne@69: * Set to NULL to use malloc() and free(). jpayne@69: * jpayne@69: * \return Initialized lzma_index_hash structure on success or jpayne@69: * NULL on failure. jpayne@69: */ jpayne@69: extern LZMA_API(lzma_index_hash *) lzma_index_hash_init( jpayne@69: lzma_index_hash *index_hash, const lzma_allocator *allocator) jpayne@69: lzma_nothrow lzma_attr_warn_unused_result; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Deallocate lzma_index_hash structure jpayne@69: * jpayne@69: * \param index_hash Pointer to a lzma_index_hash structure to free. jpayne@69: * \param allocator lzma_allocator for custom allocator functions. jpayne@69: * Set to NULL to use malloc() and free(). jpayne@69: */ jpayne@69: extern LZMA_API(void) lzma_index_hash_end( jpayne@69: lzma_index_hash *index_hash, const lzma_allocator *allocator) jpayne@69: lzma_nothrow; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Add a new Record to an Index hash jpayne@69: * jpayne@69: * \param index_hash Pointer to a lzma_index_hash structure jpayne@69: * \param unpadded_size Unpadded Size of a Block jpayne@69: * \param uncompressed_size Uncompressed Size of a Block jpayne@69: * jpayne@69: * \return Possible lzma_ret values: jpayne@69: * - LZMA_OK jpayne@69: * - LZMA_DATA_ERROR: Compressed or uncompressed size of the jpayne@69: * Stream or size of the Index field would grow too big. jpayne@69: * - LZMA_PROG_ERROR: Invalid arguments or this function is being jpayne@69: * used when lzma_index_hash_decode() has already been used. jpayne@69: */ jpayne@69: extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash, jpayne@69: lzma_vli unpadded_size, lzma_vli uncompressed_size) jpayne@69: lzma_nothrow lzma_attr_warn_unused_result; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Decode and validate the Index field jpayne@69: * jpayne@69: * After telling the sizes of all Blocks with lzma_index_hash_append(), jpayne@69: * the actual Index field is decoded with this function. Specifically, jpayne@69: * once decoding of the Index field has been started, no more Records jpayne@69: * can be added using lzma_index_hash_append(). jpayne@69: * jpayne@69: * This function doesn't use lzma_stream structure to pass the input data. jpayne@69: * Instead, the input buffer is specified using three arguments. This is jpayne@69: * because it matches better the internal APIs of liblzma. jpayne@69: * jpayne@69: * \param index_hash Pointer to a lzma_index_hash structure jpayne@69: * \param in Pointer to the beginning of the input buffer jpayne@69: * \param[out] in_pos in[*in_pos] is the next byte to process jpayne@69: * \param in_size in[in_size] is the first byte not to process jpayne@69: * jpayne@69: * \return Possible lzma_ret values: jpayne@69: * - LZMA_OK: So far good, but more input is needed. jpayne@69: * - LZMA_STREAM_END: Index decoded successfully and it matches jpayne@69: * the Records given with lzma_index_hash_append(). jpayne@69: * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the jpayne@69: * information given with lzma_index_hash_append(). jpayne@69: * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size. jpayne@69: * - LZMA_PROG_ERROR jpayne@69: */ jpayne@69: extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash, jpayne@69: const uint8_t *in, size_t *in_pos, size_t in_size) jpayne@69: lzma_nothrow lzma_attr_warn_unused_result; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * \brief Get the size of the Index field as bytes jpayne@69: * jpayne@69: * This is needed to verify the Backward Size field in the Stream Footer. jpayne@69: * jpayne@69: * \param index_hash Pointer to a lzma_index_hash structure jpayne@69: * jpayne@69: * \return Size of the Index field in bytes. jpayne@69: */ jpayne@69: extern LZMA_API(lzma_vli) lzma_index_hash_size( jpayne@69: const lzma_index_hash *index_hash) jpayne@69: lzma_nothrow lzma_attr_pure;